📄 cyclgen.m
字号:
function [h, g, k] = cyclgen(n, p, opt)
%CYCLGEN Produces cyclic code generator matrix in GF(2).
% H = CYCLGEN(N, P) produces the parity-check matrix for a given
% codeword length N and generates polynomial P. Polynomial P can
% generate a cyclic code only if P is a factor of polynomial X^N-1.
% The message length of the coding is K = N - M where M is the degree
% of P. The parity-check matrix is an M-by-N matrix.
%
% H = CYCLGEN(N, P, OPT) produces the parity-check matrix based on the
% instruction given in OPT. When
% OPT = 'nonsys', the function produces a non-systematic cyclic parity-
% check matrix;
% OPT = 'system', the function produces a systematic cyclic parity-check
% matrix. This option is the default.
%
% [H, G] = CYCLGEN(...) produces the generator matrix G as well as the
% generator matrix G. The parity-check matrix is an K-by-N matrix,
% where K = N - M;
%
% [H, G, K] = CYCLGEN(...) outputs the message length K.
%
% See also ENCODE, DECODE, BCHPOLY, CYCLPOLY.
% Wes Wang 6/23/94
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 17:55:55 $
if nargin < 2
error('Not enough input parameters')
elseif nargin < 3
opt = 'system';
else
opt = lower(opt);
end;
p = p(:)';
m = length(p) - 1;
k = n - m;
% verify if the polynomial is a irreducible
[pc, r] = gfdeconv([1 zeros(1, n-1) 1], p);
if max(r) ~= 0
error('Generator polynomial P cannot produce cyclic code generator matrix');
end;
if ~isempty(findstr(opt, 'no'))
% generate the regular cyclic code matrices
% parity-check matrix
tmp = [fliplr(pc), zeros(1, n-k-1)];
h = [];
for i = 1 : n-k
h = [h; tmp];
tmp = [tmp(n), tmp(1:n-1)];
end;
% generator matrix
if nargin > 1
tmp = [p(:)', zeros(1,n-m-1)];
g = [];
for i=1:k
g = [g; tmp];
tmp = [tmp(n), tmp(1:n-1)];
end;
end;
else
% generate systematic cyclic code matrices
% parity check matrix
b = [];
for i = 0 : k-1
[q, tmp] = gfdeconv([zeros(1, n-k+i), 1], p);
tmp = [tmp zeros(1, m-length(tmp))];
b = [b; tmp];
end;
h = [eye(n-k), b'];
% generator matrix
g = [b eye(k)];
end
%--end of cyclgen--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -