|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
- function [genpoly,t] = rsgenpoly(N, K, varargin)
- %RSGENPOLY Generator polynomial of Reed-Solomon code.
- % GENPOLY = RSGENPOLY(N,K) returns the narrow-sense generator polynomial of a
- % Reed-Solomon code with codeword length N and message length K. The codeword
- % length N must have the form 2^m-1 for some integer m between 3 and 16. The
- % output GENPOLY is a Galois row vector that represents the coefficients of
- % the generator polynomial in order of descending powers. The narrow-sense
- % generator polynomial is (X-alpha)*(X-alpha^2)*...*(X-alpha^(N-K)), where
- % alpha is a root of the default primitive polynomial for the field GF(N+1).
- %
- % GENPOLY = RSGENPOLY(N,K,PRIM_POLY) is the same as the syntax above, except
- % that PRIM_POLY specifies the primitive polynomial for GF(N+1) that has alpha
- % as a root. PRIM_POLY is an integer whose binary representation indicates
- % the coefficients of the primitive polynomial in order of descending powers.
- % To use the default primitive polynomial, set PRIM_POLY to [].
- %
- % GENPOLY = RSGENPOLY(N,K,PRIM_POLY,B) returns the generator polynomial
- % (X-alpha^B)*(X-alpha^(B+1))*...*(X-alpha^(B+N-K-1)), where B is an integer
- % and alpha is a root of PRIM_POLY.
- %
- % [GENPOLY,T] = RSGENPOLY(...) returns T, the error-correction capability of
- % the code.
- %
- % Examples:
- % g = rsgenpoly(7,3) % Narrow-sense generator polynomial
- % g2 = rsgenpoly(7,3,13) % Narrow-sense generator polynomial,
- % % with respect to primitive polynomial
- % % D^3+D^2+1
- % g3 = rsgenpoly(7,3,[],4) % Use b=4
- %
- % See also GF, RSENC, RSDEC.
- % Copyright 1996-2007 The MathWorks, Inc.
- % $Revision: 1.4.4.2 $ $Date: 2007/09/14 15:57:43 $
- % Initial checks
- error(nargchk(2,4,nargin,'struct'));
- % Number of optional input arguments
- nvarargin = nargin - 2;
- % Error-correcting capability
- t = floor((N-K)/2);
- t2 = N-K;
- m = log2(N+1);
- def_primpoly = 1;
- b = 1; % Default : narrow-sense
- if any([~isscalar(N) | ~isscalar(K) | floor(N)~=N | floor(K)~=K])
- error('comm:rsgenpoly:InvalidNK','N and K must be positive scalar integers.');
- end
- if t2<1
- error('comm:rsgenpoly:NLessThanK','N must be larger than K.');
- end
- if m~=floor(m) | m<3 | m>16
- error('comm:rsgenpoly:InvalidN','N must equal 2^m-1 for some integer m between 3 and 16.')
- end
- if ~isempty(varargin)
- prim_poly = varargin{1};
- % Check prim_poly
- if isempty(prim_poly)
- if ~isnumeric(prim_poly)
- error('comm:rsgenpoly:InvalidDefaultPrim_Poly','To use the default PRIM_POLY, it must be marked by [].');
- end
- else
- if ~isscalar(prim_poly)
- error('comm:rsgenpoly:Prim_PolyNotScalar','PRIM_POLY must be a scalar integer.');
- end
- % ZZZ add isprimitive once it's available
- def_primpoly = 0;
- end
- if nvarargin==2
- b = varargin{2};
- if ~isscalar(b) | floor(b)~=b
- error('comm:rsgenpoly:BNotAnInt','B must be an integer scalar.');
- end
- end
- end
- % Alpha is the primitive element of this GF(2^m) field
- if def_primpoly == 1
- alpha = gf(2,m);
- else
- alpha = gf(2,m,prim_poly);
- end
- genpoly = 1;
- for k=mod(b+[0:t2-1],N)
- evalc('genpoly = conv(genpoly,[1 alpha.^(k)]);');
- end
复制代码
大家帮忙看看
我想获得这个返回值,即将他赋给一个变量POLY
rsgenpoly(31,25)
POLY = [1 17 26 30 27 30 24];
试了改了一下没有成功
多谢啊
|
|