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

📄 gfconv.m

📁 数字通信第四版原书的例程
💻 M
字号:
function c = gfconv(a, b, p)
%GFCONV GF(P) polynomial convolution or GF(P^M) element multiplication.
%       C = GFCONV(A, B) computes the convolution between two GF(2)
%       polynomials A and B. The polynomial degree of the resulted GF(2)
%       polynomial C equals degree(A) + degree(B).
%
%       C = GFADD(A, B, P) computes the convolution between two GF(P)
%       polynomials when P is a scalar prime number.
%       When P is a matrix that contains the tuple of all elements in GF(Q^M),
%       this function takes A and B as indices (power number of the
%       exponential form) of GF(Q^M) elements. The output C is 
%       alpha^C = alpha^A * alpha^B in GF(Q^M). The computation is 
%       element-by-element computation. You can generate the tuple of all
%       elements in GF(Q^M) by P = GFTUPLE([-1:Q^M-2]', M, Q). 
%
%       In polynomial computation, A, B, and C are ascending ordered, i.e.,
%       A = [a_0, a_1, a_2,..., a_(n-1), a_n] represents
%       A(X) = a_0 + a_1 X + a_2 X^2 +...+ a_(n-1) X^(n-1) + a_n X^n
%       a_i must be a element in GF(P).
%
%       In power representation form, [-Inf, 0, 1, 2, ...] represents 
%       [0, 1, alpha, alpha^2, ...] in GF(p^m).
%
%       See also GFADD, GFDIV, GFTUPLE

%       Wes Wang 6/8/94, 10/5/95.
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:58:12 $

% input validation
if nargin < 2
  error('Not enough input for GFCONV')
elseif nargin < 3
   p = 2;
end

%input validation
a = gftrunc(a(:)', p);
b = gftrunc(b(:)', p);
na = length(a);
nb = length(b);

[n_p, m_p] = size(p);
if n_p <= 1
    %case of polynomial calculation
    if ~isempty([find(a~=floor(a)), find(a<0), find(a>=p)])
      error('The polynomial coeficients must be in GF(P)')
    elseif ~isempty([find(b~=floor(b)), find(b<0), find(b>=p)])
     error('The polynomial coeficients must be in GF(P)')
    end;

    %variable assignment
    a = fliplr(a);
    b = fliplr(b);

    %convolution computation
    if na > nb
        if nb > 1
            a(na+nb-1) = 0;
        end
        c = gffilter(b, 1, a, p);
    else
        if na > 1
            b(na+nb-1) = 0;
        end
        c = gffilter(a, 1, b, p);
    end
    c = fliplr(c);
else
    % computation in GF(p^m) field
    tp = p;
    p = max(max(tp)) + 1; % the prime number.
    [n_tp, m_tp] = size(tp);
    pow_dim = p^m_tp - 1;
    if pow_dim+1 ~= n_tp
        error('The given GF(P^M) M-tuple list is not a valid one');
    end;
    c = [0 : na + nb] - Inf;
    for i = 1 : na
        for j = 1 : nb
            k = i+j-1;
            if c(k) >= 0
                c(i+j-1) = gfadd(c(i+j-1), gfmul(a(i), b(j), tp), tp);
            else
                c(i+j-1) = gfmul(a(i), b(j), tp);
            end;
        end;
    end;
end;
%--end of GFCONV.M---

⌨️ 快捷键说明

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