matlab信号与系统代码整理

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

连续时间系统...................................................................................................................................1离散时间系统...................................................................................................................................2拉普拉斯变换...................................................................................................................................4Z变换...............................................................................................................................................5傅里叶..............................................................................................................................................7连续时间系统%%%%%%%%%%向量法%%%%%%%%%%%%%%%%t1=-2:0.01:5;f1=4*sin(2*pi*t1-pi/4);figure(1)subplot(2,2,1),plot(t1,f1),gridon%%%%%%%%%符号运算法%%%%%%%%%%%%symstf1=sym('4*sin(2*pi*t-pi/4)');figure(2)subplot(2,2,1),ezplot(f1,[-25])跟plot相比,ezplot不用指定t,自动生成。axis([-5,5,-0.1,1])控制坐标轴的范围xx,yy;求一个函数的各种响应Y’’(t)+4y’(t)+2y(t)=f”(t)+3f(t)%P187第一题%(2)clearall;a1=[142];b1=[103];[A1,B1,C1,D1]=tf2ss(b1,a1);t1=0:0.01:10;x1=exp(-t1).*Heaviside(t1);rc1=[21];(起始条件)figure(1)subplot(3,1,1),initial(A1,B1,C1,D1,rc1,t1);title('零输入响应')subplot(3,1,2),lsim(A1,B1,C1,D1,x1,t1);title('零状态响应')subplot(3,1,3),lsim(A1,B1,C1,D1,x1,t1,rc1);title('全响应')Y=lsim(A1,B1,C1,D1,x1,t1,rc1);title('全响应')则是输出数值解subplot(2,1,1),impulse(b1,a1,t1:t:t2可加),gridon,title('冲激响应')subplot(2,1,2),step(b1,a1,t1:t:t2可加),gridon,title('阶跃响应')卷积%第九题P189clearall;%(1)t1=-1:0.01:3;f1=Heaviside(t1)-Heaviside(t1-2);%定义信号t2=0:0.01:4;f2=(Heaviside(t2-1)-Heaviside(t2-3));%定义信号figure(1)gggfconv(f1,f2,t1,t2);%计算卷积积分并绘出时域波形离散时间系统画图x=[-1,2,3,3,5,-4];n=[-2,-1,0,1,2,3];figure(1)stem(n,x)离散序列画图函数各种序列操作函数%ex_2clearall;x=[1234567654321];n=[-4-3-2-1012345678];%[x1_1,n1_1]=sigshift(2*x,n,5);%2x(n-5)[x1_2,n1_2]=sigshift(-3*x,n,-4);%-3x(n+4)[x1,n1]=sigadd(x1_1,n1_1,x1_2,n1_2);%2x(n-5)-3x(n+4)subplot(3,1,1),stem(n1,x1)%[x2_1,n2_1]=sigshift(x,n,-3);%x(n+3)[x2_2,n2_2]=sigfold(x2_1,n2_1);%x(-n+3)[x2_3,n2_3]=sigshift(x,n,2);%x(n-2)[x2_4,n2_4]=sigmult(x,n,x2_3,n2_3);%x(n)x(n-2)[x2,n2]=sigadd(x2_4,n2_4,x2_2,n2_2);%x(n)x(n-2)+x(-n+3)subplot(3,1,2),stem(n2,x2)%x3_2=zeros(1,length(x));n3_2=n;forj=1:5[x3_1,n3_1]=sigshift(x,n,j)[x3_2,n3_2]=sigadd(x3_2,n3_2,x3_1,n3_1)endx3=x3_2.*n3_2n3=n3_2subplot(3,1,3),stem(n3,x3)复指数序列各因数画图%P157第8题%(1)clearall;n1=-10:10;f1=exp(j*n1*pi)f1_m=abs(f1);f1_a=angle(f1);f1_r=real(f1);f1_i=imag(f1);figure(1)subplot(2,2,1),stem(n1,f1_m),title('模')subplot(2,2,2),stem(n1,f1_a),title('幅角')subplot(2,2,3),stem(n1,f1_r),title('实部')subplot(2,2,4),stem(n1,f1_i),title('虚部')求差分方程各响应y(n)-5y(n-1)+6y(n-2)=x(n)-3x(n-2)Y(-1)=-2y(-2)=1x(n)=exp(-2*n)%ex_6clearall;n=0:50;x=exp(-2*n);a=[1,-5,6];b=[1,0,-3];yi=[-2,-1];xi=0;xic=filtic(b,a,yi,xi);差分方程求响应的函数xi为0就是零输入y1=filter(b,a,zeros(1,length(n)),xic);%求零输入相应y2=filter(b,a,x);%求零状态响应y3=filter(b,a,x,xic);%求全响应figure(1)subplot(3,1,1),stem(n,y1),title('零输入响应')subplot(3,1,2),stem(n,y2),title('零状态响应')subplot(3,1,3),stem(n,y3),title('全响应')%n=0:50;u1=impseq(0,50,0);%冲激序列y4=filter(b,a,u1);%冲激响应u2=stepseq(0,50,0);%阶跃序列y5=filter(b,a,u2);%阶跃响应figure(2)subplot(2,1,1),stem(n,y4);title('冲激响应')subplot(2,1,2),stem(n,y5);title('阶跃响应')求单位样值响应函数Impz(b,a,可加N表示范围)卷积%P189第八题clearall;x1=[121];n1=[-101];x2=[11111];n2=[-2-1012];x3=[321]n3=[012]x4=[1-11-1]n4=[0123]%(2)[f2,k2]=dconv(x2,x3,n2,n3);%x2*x3figure(1)stem(k2,f2),title('x2*x3')%(4)[x2_1,n2_1]=sigadd(x2,n2,x1,n1);%x2-x1[f2,k2]=dconv(x2,x3,n2,n3);%(x2-x1)*x3figure(2)stem(k2,f2),title('(x2-x1)*x3')拉普拉斯变换%作业1利用matlabe的laplace函数,求下列信号的拉普拉斯变换clearallsymst;f1=sym('(1-exp(-0.5*t))');F1=laplace(f1)%作业2利用matlabe的ilaplace函数,求下列信号的反拉普拉斯变换clearallsymss;F1=(s+1)/(s*(s+2)*(s+3));f1=ilaplace(F1)%作业3利用matlabe的residue函数(部分分式展开法),求下列信号的反拉普拉斯变换clearallmedia1=conv([120],[13]);a1=[11];分子系数b1=[1560];分母系数[k1,p1,c1]=residue(a1,b1);k是展开项系数,p是极点,给出系统函数求零极点分布clearall%第四题(1)figure(1)subplot(2,1,1)%零极点分布B1=[1];A1=[1,6,8];[z1,p1]=tf2zp(B1,A1);zplane(z1,p1);title('零极点分布')subplot(2,1,2)%冲击响应及其图形impulse(B1,A1,5);title('冲击响应')H1=impz(B1,A1);%冲击响应%分析:函数极点分布在左半平面,故响应成衰减图形%P253_5b=[2];a=[0.04,0.4,2];[h,w]=freqs(b,a,100);h1=abs(h);%幅频响应h2=angle(h);%相频响应subplot(2,1,1);plot(w,h1);holdonplot([7.07117.0711],[00.707],':');%截止频率的位置plot([07.0711],[0.707,0.707],':');axis([0400.11]);gridxlabel('角频率');ylabel('幅度');title('幅频特性');subplot(2,1,2);plot(w,h2*180/pi);gridxlabel('角频率');ylabel('相位');title('相频特性');Z变换%P3441(1)求Z变换clearall%(1)f1=sym('n^2*heaviside(n)');F1=ztrans(f1)%P344_2_4逆变换clearallF=sym('(z^2+0.5*z)/(z-0.5)^3');f=iztrans(F)%P345_3_4residuez求逆变换clearallnum=[10.50];den=[1-1.50.75-0.125];[r,p,k]=residuez(num,den)解释见315零极点分布图%P3456clearall%(1)b=[240];a=[231];[z,p]=tf2zp(b,a);求零极点的函数figure(1)subplot(2,1,1),zplane(z,p);画图函数subplot(2,1,2),impz(b,a,20);绘制单位序列响应%P345clearall%(1)b=[2,0,0,-1];a=[1,-2,-1];[z,p,k]=tf2zp(a,b);subplot(2,2,1)zplane(z,p);legend('零点','极点');title('零极点分布');修饰subplot(2,2,2);impz(a,b,20);title('时域波形');%分析:其极点均分布在单位圆内,故系统稳定,且时域波形成衰减趋势幅频响应%P346_10clearall;b=[1-2.8284];a=

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功