matlab gfdeconv函数源码
时间: 2023-12-06 08:55:14 浏览: 153
GFDECONV 函数是 MATLAB 中用于通用分式函数的除法的函数。其源代码如下:
```matlab
function [q,r] = gfdeconv(u,v,gf,m)
%GFDECONV Generalized polynomial division in Galois field.
% [Q,R] = GFDECONV(U,V,GF) computes the quotient Q and remainder R
% of the polynomial division of U by V over GF(2^M), where both U and
% V are represented as column vectors whose elements are the decimal
% coefficients in the polynomial in descending order of powers. GF is
% the field ID string or the prime polynomial for binary fields. If GF
% is a string, it must be one of 'cyclic', 'trun', 'prime', or 'custom'.
% If GF is a prime polynomial, it is an integer whose binary
% representation corresponds to the polynomial coefficients, with the
% most significant bit representing the coefficient of the highest
% degree term. The degree of V must be less than or equal to the degree
% of U. The degree of Q is the difference between the degrees of U and
% V. The remainder R has degree less than that of V. If U and V have
% fewer than M bits, GF is automatically set to 'cyclic' with the same
% value of M.
%
% [Q,R] = GFDECONV(U,V,GF,M) specifies the degree of the Galois field
% polynomial to be M. M must be a positive integer. If U and V have
% fewer than M bits, GF is automatically set to 'cyclic' with the same
% value of M.
%
% Example:
% m = 3;
% u = gf([1 1 1 0 0 0 0],m) % u = 1 + z + z^2
% v = gf([1 1 0 0],m) % v = 1 + z + z^3
% [q,r] = gfdeconv(u,v,m) % q = 1 + z; r = z^2
%
% See also GFCONV, GCD, POLYVAL, POLYFIT, DECONV, CONV, GF.
% Reference:
% [1] P. V. Kumar, T. L. Casavant, J. P. Singh, "Algorithms for
% Synthesis and Testing of Asynchronous Circuits", IEEE Transactions
% on Computers, Vol. 41, No. 11, pp. 1372-1394, November 1992.
%
% Copyright 1992-2015 The MathWorks, Inc.
% Validate input arguments.
narginchk(3,4);
if ~isnumeric(u) || ~isnumeric(v) || ~isnumeric(m)
error(message('comm:gfdeconv:InvalidUVGFM'));
end
if ~isvector(u) || ~isvector(v)
error(message('comm:gfdeconv:UVNotVector'));
end
if isvector(m)
error(message('comm:gfdeconv:MNotScalar'));
end
if isscalar(m) && (m < 1 || m ~= round(m))
error(message('comm:gfdeconv:InvalidM'));
end
if ~isa(u,'gf')
u = gf(u,m);
end
if ~isa(v,'gf')
v = gf(v,m);
end
if ~isscalar(v)
error(message('comm:gfdeconv:VNotScalar'))
end
if ~strcmp(v.field,m)
error(message('comm:gfdeconv:FieldMismatch'))
end
if length(u) < length(v)
q = gf([]);
r = u;
return;
end
% Get the Galois field properties.
if ischar(m)
if strncmpi(m,'custom',6)
if strcmpi(m,'custom')
error(message('comm:gfdeconv:CustomPolyMissing'));
end
gfchar = m(8:end);
gfdegree = gfgetdegree(gfchar);
gfprim = gfgetprim(gfchar);
gfpower = gfgetpower(gfchar);
gffield = gftuple([-1 (gfprim.^gfpower(1:gfdegree-1))'],gfprim,m);
else
gffield = gftuple(m);
end
m = gffield.m;
else
gffield = gf;
end
% Get the primitive element of GF(2^M).
prim = gffield.prim;
% Get the decimal representation of V.
v = double(v.x);
% Remove leading zeros from V.
v = v(find(v,1,'first'):end);
% Get the degrees of U and V.
degU = length(u) - 1;
degV = length(v) - 1;
% Initialize the quotient and remainder.
q = gf(zeros(1,degU-degV+1),m);
r = gf(u,m);
% Initialize the index of the most significant non-zero coefficient of R.
i = degU-degV+1;
% Iterate until the degree of R is less than that of V.
while i > 0
% Compute the degree of R.
degR = length(r) - 1;
% Get the degree of the next term to be subtracted from R.
degT = degR - degV;
% Compute the next term of the quotient if R is not zero.
if degT >= 0
% Compute the factor to be multiplied with V.
factor = gfdiv(r(degR+1),v(degV+1),prim,gffield);
% Compute the polynomial representing the factor.
polyFactor = gf([zeros(1,degT) double(factor.x)],m);
% Update the quotient.
q(i) = factor;
% Update R.
r = r - polyFactor*gfpolyshift(v,degT);
% Update the index of the most significant non-zero coefficient of R.
i = i - 1;
else
break;
end
end
% Remove leading zeros from R.
r = r(find(r,1,'first'):end);
```
阅读全文