genasig2.m

来自「trabajos en matlab para verificar son mu」· M 代码 · 共 154 行

M
154
字号
function xs = genasig2(x,ty)% GENSIG Symbolic representation of x(t) = Kexp(-at)(t^p)cos(wt+r)u(t)%%	xs = GENASIG2(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)%	GENASIG2 with no input arguments invokes the following example:%%  	% Find the symbolic form for x(t)=4texp(-t)sin(t)u(t)% 	  >>y = genasig2([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) 1998if nargin==0,help genasig2,disp('Strike a key to see results of the example')pause,y=genasig2([4 1 1 1 -pi/2],'t'),return,endhat=' .^ ';if nargin<2,ty='t';endty=ty(1);if ty=='t',N=5;else,N=6;endx=[x(:).' zeros(1,N-length(x))];if ty=='t'%if x(2)<0,error('must have decaying exponentials'),return,endif x(3)<0|rem(x(3),1)~=0,error('powers of t must be positive integers'),return,endif x(4)<0,x(4)=-x(4);x(5)=-x(5);endelseif ty=='n'%if x(2)==0, error('base of exponential must be non-zero'),return,endif x(3)<0|rem(x(3),1)~=0,error('powers of n must be positive integers'),return,endif x(4)<0,x(4)=-x(4);x(5)=-x(5);endif x(6)<0|rem(x(6),1)~=0,error('Delay must be a positive integer'),return,endif x(6)~=0,ty=['(' ty '-' int2str(x(6)) ')'];endendcst=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,endif abs(cst)<50*eps,cst=0;end
%cst_trm=[];if cst~=1,cst_trm=num2str(cst);endcst_trm=num2str(cst);%Now build stringif ty=='t'exp_trm=[];if x(2)~=0,if x(2)==1exp_trm=['exp(-' ty ')'];elseif x(2)==-1exp_trm=['exp(' ty ')'];elseexp_trm=['exp(' num2str(-x(2)) '*' ty ')'];endendpol_trm=[];if x(3)~=0,if x(3)==1pol_trm=['(' ty ')'];elsepol_trm=['(' ty  hat  int2str(x(3)) ')'];endendcos_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 ')'];  endendxs=exp_trm;if ~isempty(pol_trm) if ~isempty(xs),xs=[xs '.*' pol_trm];else,xs=pol_trm;endendif ~isempty(cos_trm)if ~isempty(xs),xs=[xs '.*' cos_trm];else,xs=cos_trm;endend%if ~isempty(cst_trm)%if ~isempty(xs),xs=[cst_trm '*' xs];end%endif isempty(xs)xs=[cst_trm '+0*t'];elsexs=[cst_trm '*' xs];endreturn,end% Now for the n caseexp_trm=[];if x(2)~=0,if x(2)~=1exp_trm=['(' num2str(x(2))  hat  ty ')'];endendpol_trm=[];if x(3)~=0,if x(3)==1pol_trm=['(' ty ')'];elsepol_trm=['(' ty  hat  int2str(x(3)) ')'];endendcos_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 ')'];  endendxs=exp_trm;if ~isempty(pol_trm) if ~isempty(xs),xs=[xs '.*' pol_trm];else,xs=pol_trm;endendif ~isempty(cos_trm)if ~isempty(xs),xs=[xs '.*' cos_trm];else,xs=cos_trm;endend%if ~isempty(cst_trm)%if ~isempty(xs),xs=[cst_trm '*' xs];end%endif isempty(xs)xs=[cst_trm '+0*n'];elsexs=[cst_trm '*' xs];end

⌨️ 快捷键说明

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