⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bchgenpoly.m

📁 产生BCH码多项式
💻 M
字号:
function [genpoly, t] = bchgenpoly(N,K,varargin);
%BCHGENPOLY  Generator polynomial of BCH code.
%   GENPOLY = BCHGENPOLY(N,K) returns the narrow-sense generator polynomial of a 
%   BCH 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 = BCHGENPOLY(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,T] = BCHGENPOLY(...) returns T, the error-correction capability of 
%   the code.
%
%   See also BCHENC, BCHDEC. 

% Copyright 1996-2003 The MathWorks, Inc.
% $Revision: 1.1.6.4 $  $ $ 


% Initial checks
error(nargchk(2,3,nargin));

t = bchnumerr(N,K);
t2 = 2*t;

prim_poly = 1;

m = log2(N+1);

if ~isempty(varargin)    
    prim_poly = varargin{1};    
    % Check prim_poly
    if isempty(prim_poly)
        if ~isnumeric(prim_poly)
            error('To use the default PRIM_POLY, it must be marked by [].');
        end
    else
        if ~isnumeric(prim_poly) || ~isscalar(prim_poly) || (floor(prim_poly) ~= prim_poly)
            error('PRIM_POLY must be a scalar integer.');
        end

        if ~isprimitive(prim_poly)
            error('PRIM_POLY must be a primitive polynomial.');
        end
    end
    
end

% Alpha is the primitive element of this GF(2^m) field
if prim_poly == 1
    alpha = gf(2,m);
else
    alpha = gf(2,m,prim_poly);
end

% genpoly = LCM([1 alpha.^k])... for  k = 1 : 2t-1)

% Find all the minimun polynomials, add them to list of minimum
% polynomials, if they're not there yet. Then convolve all the minimum
% polynomials to make the generator polynomial.

minpol_list = minpol(alpha);

for k=[1:t2-1]
    minpoly = minpol(alpha.^k);
    
    [len,w] = size(minpol_list); 
    minpol_mat = repmat(minpoly, [len 1]);
    
    eq = (minpol_mat == minpol_list);
    if(~any(sum(eq') == w))
        minpol_list = [minpol_list;minpoly];    
    end
end

% convolve all the rows of the minpol_list with each other.
len = size(minpol_list,1);
genpoly  = 1;
for(i = 1:len)
    genpoly = conv(genpoly,minpol_list(i,:));
end

% strip any leading zeros
% the size of the generator polynomial should be N-K+1
genpoly = genpoly( end-(N-K) :end);

% EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -