📄 cyclpoly.m
字号:
function pr = cyclpoly(n, k, fd_flag)
%CYCLPOLY Finds cyclic generator polynomials in GF(2).
% PR = CYCLPOLY(N, K) finds one cyclic generator polynomial for a given
% codeword length N and message length K.
%
% PR = CYCLPOLY(N, K, FD_FLAG) finds cyclic generator polynomial(s) for
% a given code word length N and message length K. The flag FC_FLAG
% means:
% FD_FLAG = 'min' find the minimum degree cyclic generator polynomial.
% FD_FLAG = 'max' find the maximum degree cyclic generator polynomial.
% FD_FLAG = 'all' do an exhaustive search for all cyclic generator
% polynomials of the given degree.
% FD_FLAG = L find all cyclic generator polynomials with L terms.
%
% If no cyclic generator polynomial is found provided the given
% condition, PR is an empty output. A cyclic generator polynomial is
% an irreducible polynomial.
%
% See also HAMMGEN, GFPRIMFD, CYCLGEN.
% Wes Wang 6/23/94, 10/2/95
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 17:56:02 $
% with message length k and code word length n, the degree of the cyclic
% generator polynomial length is m = n-k.
m = n - k;
if m < 0
error('Message length cannot be shorter than code word length');
elseif m == 0
pr = 1;
elseif m == 1
pr = [1 1];
elseif m >= 2
pr = [];
nn = 2^(m-1) - 1;
pp = [1, zeros(1, n-1), 1];
if nargin < 3
% find one result and return
for i = 1 : nn
% try all of possibility
test_bed = [1, fliplr(de2bi(i, m-1)), 1];
[q, r] = gfdeconv(pp, test_bed);
if max(r) == 0
pr = [pr; test_bed];
return;
end;
end;
elseif isstr(fd_flag)
fd_flag = lower(fd_flag);
if fd_flag(1:2) == 'mi'
% minimum term
for j = 3 : m + 1
for i = 1 : nn
% try all of possibility
test_bed = [1, fliplr(de2bi(i, m-1)), 1];
if sum(test_bed) == j
[q, r] = gfdeconv(pp, test_bed);
if max(r) == 0
pr = test_bed;
return;
end;
end;
end;
end
elseif fd_flag(1:2) == 'ma'
% maximum term
for j = m+1 : -1 : 3
for i = 1 : nn
% try all of possibility
test_bed = [1, de2bi(i, m-1), 1];
if sum(test_bed) == j
[q, r] = gfdeconv(pp, test_bed);
if max(r) == 0
pr = test_bed;
return
end;
end;
end;
end
else
for i = 1 : nn
% exhaust search
test_bed = [1, fliplr(de2bi(i, m-1)), 1];
[q, r] = gfdeconv(pp, test_bed);
if max(r) == 0
pr = [pr; test_bed];
end;
end;
%sort based on the minimum number of terms
if ~isempty(pr)
[x, i] = sort(sum(pr'));
pr = pr(i, :);
end;
end;
else
% fd_flag is a number
for i = 1 : nn
% try all of possibility
test_bed = [1, fliplr(de2bi(i, m-1)), 1];
if sum(test_bed) == fd_flag
[q, r] = gfdeconv(pp, test_bed);
if max(r) == 0
pr = [pr; test_bed];
end;
end;
end;
end;
end;
if isempty(pr)
disp('No primitive polynomial has been found provided the given constrain');
end;
%--end of CYCLPOLY--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -