📄 genasig.m
字号:
function xs = genasig(x,ty)
% GENSIG Symbolic representation of x(t) = Kexp(-at)(t^p)cos(wt+r)u(t)
%
% xs = GENASIG(X,TY) returns the symbolic form for
% x(t) = Kexp(-at)(t^p)cos(wt+r)u(t) OR
% x[n] = K(a^(n-n0))[(n-n0)^p]cos(nw+r)u[n]
% For CT signals, X is a 5 element array with X=[K a p w r]
% For DT signals, X is a 6 element array with X=[K a p w r n]
% TY is 't' (for CT signals) or 'n' (for DT signals)
% GENASIG with no input arguments invokes the following example:
%
% % Find the symbolic form for x(t)=4texp(-t)sin(t)u(t)
% >>y = genasig([4 1 1 1 -pi/2],'t')
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin==0,help genasig,disp('Strike a key to see results of the example')
pause,y=genasig([4 1 1 1 -pi/2],'t'),return,end
v=matverch;if v<5,hat='^';else,hat='{\^}';end
if nargin<2,ty='t';end
ty=ty(1);
if ty=='t',N=5;else,N=6;end
x=[x(:).' zeros(1,N-length(x))];
if ty=='t'
%if x(2)<0,error('must have decaying exponentials'),return,end
if x(3)<0|rem(x(3),1)~=0,error('powers of t must be positive integers'),
return,end
if x(4)<0,x(4)=-x(4);x(5)=-x(5);end
elseif ty=='n'
%if x(2)==0, error('base of exponential must be non-zero'),return,end
if x(3)<0|rem(x(3),1)~=0,error('powers of n must be positive integers'),
return,end
if x(4)<0,x(4)=-x(4);x(5)=-x(5);end
if x(6)<0|rem(x(6),1)~=0,error('Delay must be a positive integer'),return,end
if x(6)~=0,ty=['(' ty '-' int2str(x(6)) ')'];end
end
cst=x(1);
if x(4)==0 & x(5)~=0,cst=x(1)*cos(x(5));x(5)=0;end
%if abs(cst)<50*eps,return,end
if abs(cst)<50*eps,cst=0;end
%cst_trm=[];
%if cst~=1,cst_trm=num2str(cst);end
cst_trm=num2str(cst);
%Now build string
if ty=='t'
exp_trm=[];
if x(2)~=0,
if x(2)==1
exp_trm=['exp(-' ty ')'];
elseif x(2)==-1
exp_trm=['exp(' ty ')'];
else
exp_trm=['exp(' num2str(-x(2)) ty ')'];
end
end
pol_trm=[];if x(3)~=0,
if x(3)==1
pol_trm=['(' ty ')'];
else
pol_trm=['(' ty hat int2str(x(3)) ')'];
end
end
cos_trm=[];
if x(4)~=0
if x(4)==1,cs=ty;else,cs=[num2str(x(4)) ty];end
if x(5)==0,
cos_trm=['cos(' cs ')'];
else
if x(5)<0,sn='-';else,sn='+';end
ph=[num2str(abs(x(5)/pi)) 'pi'];
cos_trm=['cos(' cs sn ph ')'];
end
end
xs=exp_trm;
if ~isempty(pol_trm)
if ~isempty(xs),xs=[xs pol_trm];else,xs=pol_trm;end
end
if ~isempty(cos_trm)
if ~isempty(xs),xs=[xs cos_trm];else,xs=cos_trm;end
end
%if ~isempty(cst_trm)
%if ~isempty(xs),xs=[cst_trm '*' xs];end
%end
if isempty(xs)
xs=cst_trm;
else
xs=[cst_trm '*' xs];
end
return,end
% Now for the n case
exp_trm=[];
if x(2)~=0,
if x(2)~=1
exp_trm=['(' num2str(x(2)) hat ty ')'];
end
end
pol_trm=[];if x(3)~=0,
if x(3)==1
pol_trm=['(' ty ')'];
else
pol_trm=['(' ty hat int2str(x(3)) ')'];
end
end
cos_trm=[];
if x(4)~=0
if x(4)==1,cs=ty;else,cs=[num2str(x(4)) ty];end
if x(5)==0,
cos_trm=['cos(' cs ')'];
else
if x(5)<0,sn='-';else,sn='+';end
ph=[num2str(abs(x(5)/pi)) 'pi'];
cos_trm=['cos(' cs sn ph ')'];
end
end
xs=exp_trm;
if ~isempty(pol_trm)
if ~isempty(xs),xs=[xs pol_trm];else,xs=pol_trm;end
end
if ~isempty(cos_trm)
if ~isempty(xs),xs=[xs cos_trm];else,xs=cos_trm;end
end
%Include constant multiplier.
%if ~isempty(cst_trm)
%if ~isempty(xs),xs=[cst_trm '*' xs];
%else,
%xs=cst_trm;
%end
%end
if isempty(xs)
xs=cst_trm;
else
xs=[cst_trm '*' xs];
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -