当前位置:文档之家› ztrans函数

ztrans函数

function F = ztrans(varargin)
%ZTRANS Z-transform.
% F = ZTRANS(f) is the Z-transform of the scalar sym f with default
% independent variable n. The default return is a function of z:
% f = f(n) => F = F(z). The Z-transform of f is defined as:
% F(z) = symsum(f(n)/z^n, n, 0, inf),
% where n is f's symbolic variable as determined by FINDSYM. If
% f = f(z), then ZTRANS(f) returns a function of w: F = F(w).
%
% F = ZTRANS(f,w) makes F a function of the sym w instead of the
% default z: ZTRANS(f,w) <=> F(w) = symsum(f(n)/w^n, n, 0, inf).
%
% F = ZTRANS(f,k,w) takes f to be a function of the sym variable k:
% ZTRANS(f,k,w) <=> F(w) = symsum(f(k)/w^k, k, 0, inf).
%
% Examples:
% syms k n w z
% ztrans(2^n) returns z/(z-2)
% ztrans(sin(k*n),w) returns sin(k)*w/(1-2*w*cos(k)+w^2)
% ztrans(cos(n*k),k,z) returns z*(-cos(n)+z)/(-2*z*cos(n)+z^2+1)
% ztrans(cos(n*k),n,w) returns w*(-cos(k)+w)/(-2*w*cos(k)+w^2+1) % ztrans(sym('f(n+1)')) returns z*ztrans(f(n),n,z)-f(0)*z
%
% See also IZTRANS, LAPLACE, FOURIER.
% Copyright 1993-2003 TheMathWorks, Inc.
% $Revision: 1.20.4.2 $ $Date: 2004/04/16 22:23:22 $
% Trap for errors in input first.
ifnargin>= 4
error('symbolic:sym:ztrans:errmsg1','ZTRANS can take at most 3 input variables'); end
% Make f a sym and extract the variable closest to 'x'.
f = sym(varargin{1});
% Find all symbolic variables in f.
vars = [ '{' findsym(f) '}' ];
% Determine whether n is in the expression.
varcheck = maple([ vars ' intersect {n}']);
% If n is a symbolic variable, make it the default. Otherwise
% let the variable closest to x be the variable of integration.
ifisequal(varcheck,'{n}')
var = sym('n');
else
var = findsym(f,1);
end
% If var is empty, then the default is var = 'n'.
ifisempty(var)
var = sym('n');
end
% determine whether f is a function of z or another variable. z_test = strcmp(char(var),'z');
% If f = f(z), return F = F(w)
ifnargin == 1 &z_test == 1
n = var;
z = 'w';
end
ifnargin == 1 &z_test == 0
n = var;
z = 'z';
end
ifnargin == 2
n = var;
ifisempty(n), n = 'n'; end;
z = sym(varargin{2});
end
ifnargin == 3
n = sym(varargin{2});
z = sym(varargin{3});
end
F = maple('map','ztrans',f,n,z);
intrans函数如下:
function g = intrans(f,varargin)
error (nargchk(2,4,nargin))
%check input
classin = class(f);
%stroe the class of the input for use later.
ifstrcmp(class(f),'double') & max(f(:))>1 & ~strcmp(varargin{1},'log')
f = mat2gray(f);
%if all the 3 conditions is filling the need .
else
% make sure the class(f) is in the class of double , f(:) means all the
% elemnets in the martix F, and the max(f(:))>1 means if the max(f(:))>1 so % convert them into double , in this way they are all less then1.
% strcmp(varargin[1],'log') is the string compare, and the varargin {1}
% compares with log.
f = im2double(f);
end
method = varargin{1};
switch method
case 'neg'
g = imcomplement(f);
case 'log'
if length(varargin) == 1
c = 1;
elseif length(varargin) == 2
c = varargin{2};
elseif length(varargin) == 3
c = varargin{2};
classin = varargin{3};
else
error('Incorrect number of input for the log option.')
end
g = c*(log(1+double(f)));
case 'gamma'
if length(varargin) < 2
error('not enough input for the gamma option')
end
gam = varargin{2};
g = imadjust (f, [], [], gam);
case 'stretch'
if length(varargin) == 1
%defaults vaule
m = mean2(f);
E = 4.0;
elseif length(varargin) == 3
m = varargin{2};
E = varargin{3};
else error('incorrect number of inputs for the srtetch option.') end
g = 1./(1 + (m./(f+eps)).^E);
otherwise
error('unkown enhancement method.')
end
% g = changeclass(classin , g);。

相关主题