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

📄 gftuple.m

📁 本书是电子通信类的本科、研究生辅助教材
💻 M
字号:
function [tp, idx] = gftuple(a, ord, p, prim_ck)
%GFTUPLE Converts GF(P) polynomial to GF(P^M) tuple and index presentation.
%       TP = GFTUPLE(A, M) converts GF(2) polynomial A to the M-tuple
%       representation TP in GF(2^M). A is a matrix with each row of A
%       representing an ascending order polynomial with 
%       A(i,:) = [a_0, a_1, ... a_n] representing
%          A_i(X) = a+0 + a_1 X + ... + a_n X^n
%       When A is a column vector or a scalar, each element represents the
%       index (logarithm number) of the power representation, i.e., 
%       A_i(X) = X^A_i. GF(2^M) is generated by the default M-degree
%       primitive polynomial, where M is a positive integer. A primitive
%       polynomial can be found by using command GFPRIMDF. When M is a 
%       binary vector instead of a positive number, M is considered as a
%       primitive polynomail in GF(2^DEG), where DEG is the degree of ORD(X).
%
%       TP = GFTUPLE(A, M, P) generates the M-tuple representation in GF(P).
%       
%       TP = GFTUPLE(A, M, P, PRIM_CK) checks the primitive of M before
%       processing.
%
%       Using [TP, IDX] = GFTUPLE([-1 : P^M-2]', M, P), you can generate a
%       matrix that contains all elements in GF(P^M) for any given M and P.
%
%       See also GFADD, GFMUL, GFDIV, GFPRIMCK, GFPRIMDF.

%       Wes Wang 6/8/94, 7/26/94, 10/7/95.
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 18:00:22 $

% input check up
if nargin < 2
    error('Not enough input parameters')
elseif nargin < 3
    p = 2;
end;

% clear the choice for ORD
if length(ord) < 1
    error('ORD is empty')
elseif length(ord) == 1
    ord = gfprimdf(ord, p);
end;
ord = gftrunc(ord(:)');
len_ord = length(ord);
len_tp = len_ord - 1;

% clear the choice for A
[m_a, n_a] = size(a);
if n_a < 1
    error('A is empty');
end;

aa= a(:)';
if ~isempty([find(ord ~= floor(ord)), find(ord < 0), find(ord >= p)])
     error('The polynomial coeficients must be in GF(P)');
elseif ~isempty(find(aa ~= floor(aa)))
     error('The polynomial coeficients must be in GF(P)');
elseif ~isempty([find(aa < 0), find(aa >= p)]) & (n_a > 1)
 error('The polynomial coeficients must be in GF(P)');
end;

% making ORD to be monic polynomial
if ord(len_ord) ~= 1
    if isprime(p)
        ord = rem(ord * ord(len_ord)^(p-2), p);
    else
        error('P must be a prime number');
    end;
end;

% check the primitive of a
if nargin > 3
    if (gfprimck(ord, p) ~= 1)
        error('ORD is not primitive, stop processing');
    end;
end;

% making the companion matrix
M = [[zeros(len_tp -1, 1), eye(len_tp - 1)]; rem(p - ord(1:len_tp), p)];

%constructing the power terms:
pw = zeros(2, len_tp);
pw(2,1) = 1;
MM = M;
p_len_tp = p^len_tp;
for i = 1 : p_len_tp - 2
    pw = [pw; MM(1,:)];
    MM = rem(MM * M, p);
end;

% double check if the calculation is right.
%if min(MM(1,:) == pw(2,:)) == 0
%    error ('Computation error');
%end;

tp = zeros(m_a, len_tp);
if n_a == 1
    % all power representation case
    for k = 1:m_a
        if a(k) == 0
            tp(k, 1) = 1;
        elseif a(k) > 0
            if a(k) > (p_len_tp-2)
                j = rem(a(k), p_len_tp - 1);
                tp(k, :) = pw(j+2,:);
            else
                tp(k, :) = pw(a(k)+2,:);
            end;
        end;
    end;
else
    % polynomial representation case
    for k = 1:m_a
        for i = 1 : n_a
            if a(k, i) ~= 0
                if i > (p_len_tp-1)
                    j = rem(i-1, p_len_tp-1)+1;
                else
                    j = i;
                end;
                tp(k,:) = rem(tp(k,:) + pw(j+1, :) * a(k, i), p);
            end;
        end;
    end;
end;
if nargout > 1
    for k = 1:m_a
        test = 1;
        i = 1;
        while (test) & (i <= p_len_tp)
            if min(tp(k,:) == pw(i, :)) == 1;
                if (i < 2)
                    idx(k) = -Inf;
                else
                    idx(k) = i - 2;
                end;
                test = 0;
            end;
            i = i + 1;
        end;    
    end;
    idx = idx(:);
end;

%--- end of gftuple --
    

⌨️ 快捷键说明

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