📄 rspoly.m
字号:
function [pg, t] = rspoly(n, k, tp)
%RSPOLY Produces Reed-Solomon code generator polynomial.
% Pg = RSPOLY(N, K) outputs the generator polynomial of Reed-Solomon
% code with codeword length N, message length K. A valid N should be
% 2^M-1, where M is an integer no less than 3. K should be an odd
% positive number. The error-correction capability is (N - K) / 2. The
% output Pg is a polynomial in GF(2^M). Each element is represented by
% the power form.
%
% Pg = RSPOLY(N, K, TP) produces generator polynomials using the
% specified GF(2^M) element list. TP is a (N+1)-by-M matrix, where
% N = 2^M-1. When TP is a scalar, it specifies M. This form is suggested
% to speed up the calculation.
%
% [Pg, T] = RSPOLY(N, K) outputs the error-correction capability of the
% RS code.
%
% See also ENCODE, DECODE.
% Wes Wang 8/8/94, 10/11/95.
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 18:03:15 $
if nargin < 2
error('Not enough input variable')
end;
if nargin < 3
% find the m from n
dim = 3;
pow_dim = 2^dim -1;
while pow_dim < n
dim = dim + 1;
pow_dim = 2^dim - 1;
end;
tp = gftuple([-1:n-1]',dim);
else
if length(tp) == 1
dim = tp;
tp = gftuple([-1:n-1]',dim);
end
[n_tp, dim] = size(tp);
if n_tp ~= n+1
error('The input parameters N and TP conflict');
end;
pow_dim = 2^dim - 1;
end;
if n ~= pow_dim
error('The code word length N must be 2^M -1, where M is an integer');
end;
if (floor(n) ~= n) | (floor(k) ~= k)
error('The input dimension parameters must be integer')
end;
t2 = n - k;
%%% find the generator polynomial by multiply
% g(X) = (X + alpha)(X + alpha^2)(X + alpha^3)...(X + alpha^(2t-1))(X + alpha^(2t))
% = g_0 + g_1 X + g_2 X^2 + ... + g_(2t - 1) X^(2t - 1) + X^2t
%
% using the algorithm used in poly
pg = [0, -ones(1, t2)];
alpha = [1 : t2];
for i = 1 : t2
pg(2:(i+1)) = gfadd(pg(2:(i+1)), gfmul(pg(1:i), alpha(i), tp), tp);
end;
pg = fliplr(pg);
% finished pg built up
% error-correction capability
t = floor(t2/2);
% finished error-correction fingure.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -