《malterlab作业题汇总.doc》由会员分享,可在线阅读,更多相关《malterlab作业题汇总.doc(37页珍藏版)》请在三一文库上搜索。
1、习题一2输入A=7 1 5;2 5 6;3 1 5,B=1 1 1; 2 2 2; 3 3 3,在命令窗口中执行下列表达式,掌握其含义: A(2,3)ans =6 A(:,2)ans = 1 5 1 A(3,:)ans =3 1 5 A(:,1:2:3)ans = 7 5 2 6 3 5 A(:,3).*B(:,2)ans = 5 12 15 A(:,3)*B(2,:)ans = 10 10 10 12 12 12 10 10 10 A*Bans = 24 24 24 30 30 30 20 20 20 A.*Bans = 7 1 5 4 10 12 9 3 15 A2ans = 66 17
2、66 42 33 70 38 13 46 A.2ans = 49 1 25 4 25 36 9 1 25 B/Aans = 0.1842 0.2105 -0.2368 0.3684 0.4211 -0.4737 0.5526 0.6316 -0.7105 B./Aans = 0.1429 1.0000 0.2000 1.0000 0.4000 0.33331.0000 3.0000 0.60003输入C=1:2:20,则C(i)表示什么?其中i=1,2,3,10; C=1:2:20C = 1 3 5 7 9 11 13 15 17 19 C(1)ans = 1 C(2)ans = 3 C(5)
3、ans = 9 C(10)ans = 194查找已创建变量的信息,删除无用的变量 whos A Name Size Bytes Class A 3x3 72 double arrayGrand total is 9 elements using 72 bytes whos C Name Size Bytes Class C 1x10 80 double arrayGrand total is 10 elements using 80 bytes clear A A? Undefined function or variable A.5创建如下变量: 在03 均匀的产生10个点值,形成10维向量
4、 3*3阶单位距阵,随机距阵,魔方距阵,全0距阵,全1距阵, 生成以向量V=1,2,3,4为基础向量的范得蒙矩阵 生成3阶的希尔伯特矩阵 linspace(0,3,10)ans = 0 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000 2.3333 2.6667 3.0000 E=ones(3,3)E = 1 1 1 1 1 1 1 1 1 randn(3,3)ans = -0.4326 0.2877 1.1892 -1.6656 -1.1465 -0.0376 0.1253 1.1909 0.3273 magic(3)ans = 8 1 6 3 5 7 4
5、9 2 eye(3,3)ans = 1 0 0 0 1 0 0 0 1 zeros(3,3)ans = 0 0 0 0 0 0 0 0 0 E=ones(3,3)E = 1 1 1 1 1 1 1 1 1randn(3,3)ans = -0.4326 0.2877 1.1892 -1.6656 -1.1465 -0.0376 0.1253 1.1909 0.3273E = 1 1 1 1 1 1 1 1 1ans = 1 1 1 1 8 4 2 1 27 9 3 1 64 16 4 1ans = 9 -36 30 -36 192 -180 30 -180 1806. (1)求方程组 的解R=5
6、 6 0 0 0;1 5 6 0 0;0 1 5 6 0;0 0 1 5 6;0 0 0 1 5,T=1 ;0 ;0 ;0; 1R = 5 6 0 0 0 1 5 6 0 0 0 1 5 6 0 0 0 1 5 6 0 0 0 1 5T = 1 0 0 0 1 RTans = 2.2662 -1.7218 1.0571 -0.5940 0.3188第八题ans = x*exp(x), log(sin(x) 1/(1+x2), x(3/2)第九题(1)y = -2.0946 1.0473 + 1.1359i 1.0473 - 1.1359i(2)x = -4 -1(3)p = 1 1 3(4)x
7、1 = .61375389080390682789737879102986 x2 = -.68619276878228013395848197030388 第十题ans = exp(-t)*sin(t) ans = C1*exp(-t)*sin(t)+C2*exp(-t)*cos(t)习题二1编写程序,计算1+3+5+7+(2n+1)的值(用input语句输入n 值)。解:程序:sum=0;n=input(Please input a number:);t=2*n+1;for i=1:2:t sum=sum+i;enddisp(sum)结果:Please input a number:4 25
8、2习题4-1 程序:x1=0:0.1:20;x2=-5:0.1:5;y1=sqrt(x1);y2=sin(x2);subplot(1,2,1)plot(x1,y1,.-r);subplot(1,2,2)plot(x2,y2,g);结果: 4-2. 使用for函数编写一个程序实现sum(A)的功能,其中A为矩阵。解:1. 程序:s=0;m=input(Please input a number:);n=input(Please input a number:);A=ones(m,n)for i=1:m for j=1:n s=s+A(i,j); endenddisp(s)2. 结果Please
9、input a number:2Please input a number:3A = 1 1 1 1 1 1 64-3. 编写一个函数文件,用于生成等比数列。1. 程序:q=1n=input(Please input a number n:);m=input(Please input a number m:);for j=1:(m-1) q=q*n;end disp(q) 结果:Please input a number n:2Please input a number m:5 164-7设 在四个子图中分别画出其曲线,并给出图例。程序:syms tt=0:pi/65:pi;x=cos(t);
10、subplot(2,2,1)plot(x,sin(2*t+0);title(a=0)subplot(2,2,2)plot(x,sin(2*t+pi/3);title(a=pi/3)subplot(2,2,3)plot(x,sin(2*t+pi/2);title(a=pi/2)subplot(2,2,4)plot(x,sin(2*t+pi);title(a=pi)结果:4-8. 绘制函数 的三维曲面图.程序x,y=meshgrid(-4*pi:0.1*pi:4*pi);r=sqrt(x.2+y.2);z=sin(r)./(r+eps);surf(x,y,z);结果 。49 程序 x=0:0.01
11、:2y1=sin(x);y2=0.5*exp(x);plot(x,y1,-.r,x,y2,g)legend(y=sin(x),y2=0.5*exp(x)xlabel(x);ylabel(y);结果习题三1.1 在MATLAB命令窗口输入 funtool,在弹出的figure No.3产生以下信号波形: 3sin(x),5exp(-x),sin(x)/x,1-2abs(x)/a, sqrt(a*x) (a=2)1.2 产生50hz的正弦波的程序 t=0:0.001:50; y=sin(2*pi*50*t); plot(t(1:50),y(1:50) title(sin)1.3 产生加入随机噪声的
12、正弦波: t=0:0001:50; y=sin(2*pi*50*t); s=y+randn(size(t);plot(t(1:50),s(1:50)1.4 产生周期方波的的程序:(f=30hz) t = 0:.0001:.0625; y = SQUARE(2*pi*30*t); plot(t,y)1.5 产生周期锯齿波 t=0:0.001:0.25; y=sawtooth(2*pi*30*t); plot(t,y) axis(0 0.2 -1 1)2. 试用MATALB绘制两正弦序列 的时域波形,观察它们的周期性,并验证是否与理论分析结果相符。(提示:并非所有的离散时间正弦序列信号都是周期的,
13、不同于连续时间正弦信号)3. 完成与两函数的卷积运算其中:在一个图形窗口中,画出、以及卷积结果。4 已知描述某连续系统的微分方程为:,试用MATLAB:(1)绘出该系统在030s范围内,并以时间间隔0.01s取样的冲激响应和阶跃响应的时域波形;(2)求出系统在030s范围内,并以时间间隔0.01s取样的冲激响应和阶跃响应的数值解。h =2/21*exp(-1/4*t)*sin(3/4*7(1/2)*t)*7(1/2)*(-1+heaviside(t)g=-1/168*heaviside(t)*(-21+exp(-1/4*t)*sin(3/4*7(1/2)*t)*7(1/2)+21*exp(-1
14、/4*t)*cos(3/4*7(1/2)*t)5已知某一连续时间信号为,试绘出它的时域波形响应的频谱图。6. 绘制系统函数的零极点图;绘制系统的幅频特性和相频特性;求单位冲激响应h(t)并画图;用laplace逆变换求h(t)表达式,并分析系统的稳定性。H(s)=(s2+s)/(2s2+6s+4)f =1/2*dirac(t)-exp(-2*t) 7. 习题69 要求同习题68zeros = -2 -1poles = 0.0000 + 1.4142i 0.0000 - 1.4142i -2.0000 -1.0000 f =1/2*2(1/2)*sin(2(1/2)*t)8 习题610Y1 =i
15、*(exp(-i*w)-1)/w/(1+i*w)2 y1 =(1-exp(-x)*x-exp(-x)*heaviside(x)+(exp(-x+1)*x-1)*heaviside(x-1) Y2 =(1/s-exp(-s)/s)/(s+1)2 y2 =(-1+exp(-t+1)*t)*heaviside(t-1)+1-t*exp(-t)-exp(-t)习题四1. 产生下列序列:(1)产生周期为1 的方波t=0:0.01:5;x=square(2*pi*t);subplot(221)plot(t,x)%产生占空比为50% 的方波t=0:0.01:5;x=square(2*pi*t,50);sub
16、plot(222)plot(t,x) %产生占空比为80% 的方波 t=0:0.01:5;x=square(2*pi*t,80);subplot(223)plot(t,x) %产生占空比为20% 的方波t=0:0.01:5;x=square(2*pi*t,10);subplot(224)plot(t,x)(1) 产生正弦序列并画图程序如下:Ts=0.01*pi;n=0:100;x=sin(2*pi*n*Ts);stem(n,x)2 已知离散系统的系统函数为,绘出其零、极点分布图;求系统的频率响应和单位脉冲响应,试编程。零极点分布图:程序:b=1 0.8 0;a=1 1 0.25;zplane(
17、b,a);单位脉冲响应:程序:delta=1 zeros(1,63);b=1 0.8 0;a=1 1 0.25;h=impz(b,a,64);stem(h);频率响应程序:b=1 0.8 0;a=1 1 0.25;h f=freqz(b,a,256,1);hr=abs(h);hph=angle(h)*180/pi;subplot(2,1,1)plot(f,hr);xlabel(归一化频率)ylabel(幅度)title(幅频响应)subplot(2,1,2)plot(f,hph);xlabel(归一化频率)ylabel(相位/角度)title(相频响应):3 已知序列求两序列的卷积。程序:a=
18、1 2 3 4;b=1 1 1 2;x=conv(a,b)stem(x);title(线性卷积)结果:x = 1 3 6 11 11 10 8图示:3. 已知序列分别求两序列的DFT。程序:a=1 2 3 4;b=1 1 1 2;y1=conv(b,a);subplot(2,1,1)stem(y1);X1=fft(a,7);X2=fft(b,7);X=X1.*X2;x=ifft(X)subplot(2,1,2)stem(x);title()结果:x = 1.0000 3.0000 6.0000 11.0000 11.0000 10.0000 8.0000图1234567051015123456
19、7051015?书75 程序:wp=80*2*pi;ws=60*2*pi;fs=200;rp=1;rs=40;N,Ws=cheb1ord(wp,ws,rp,rs,s);Z P K=buttap(N)A B C D=zp2ss(Z,P,K)b a=zp2tf(Z,P,K)freqs(b,a)传递函数形式:b = 0 0 0 0 0 0 0 0 1.0000a =1.0000 5.1258 13.1371 21.8462 25.6884 21.8462 13.1371 5.1258 1.0000零极点增益形式:Z = P = -0.1951 + 0.9808i -0.1951 - 0.9808i
20、-0.5556 + 0.8315i -0.5556 - 0.8315i -0.8315 + 0.5556i -0.8315 - 0.5556i -0.9808 + 0.1951i -0.9808 - 0.1951iK = 1.0000状态方程形式:A =-1.9616 -1.0000 0 0 0 0 0 01.0000 0 0 0 0 0 0 0 0 1.0000 -1.6629 -1.0000 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 0 1.0000 -1.1111 -1.0000 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 0 1.0000
21、-0.3902 -1.0000 0 0 0 0 0 0 1.0000 0B = 1 0 0 0 0 0 0 0C = 0 0 0 0 0 0 0 1.0000D = 0书76 程序:Wn=150,300/500;b,a=butter(10,Wn);subplot(2,1,1)hn=impz(b,a,100);stem(hn)subplot(2,1,2)H,w=freqz(b,a);plot(w,abs(H) 书77程序:clear all;close allf=0:0.01:1m(1:41)=1;m(42:61)=0;m(62:71)=0.5;m(72:81)=0;m(82:101)=1; p
22、lot(f,m,k:);hold onN=38;b=fir2(N,f,m); h,f1=freqz(b);f1=f1./pi;plot(f1,abs(h);legend(理想滤波器,设计滤波器);xlabel(归一化频率),ylabel(幅值);习题五:8-1 程序:Ts=1/64; %采样时间间隔T=2; %信号时长Fm1=75; %信源信号频率Fm2=100;Fc=10000; %载波频率 t=0:Ts:T-Ts;mt=0.1*cos(2*pi*Fm1*t)+0.3*sin(2*pi*Fm2*t); %信源信号t_dsb=mt.*cos(2*pi*Fc*t); %时域调制信号delta_f
23、=1/T; %频率分辨率N=length(t_dsb); %采样点数f=delta_f*-N/2:N/2-1; f_mt=fft(mt); f_mt=T/N*fftshift(f_mt); %把FFT结果平移到负频率上 psf_mt=(abs(f_mt).2+eps)/T; %基带信号功率谱f_dsb=fft(t_dsb); %时域调制信号的FFT f_dsb=T/N*fftshift(f_dsb); %把FFT结果平移到负频率上psf_dsb=(abs(f_dsb).2+eps)/T; %时域调制信号的功率谱subplot(221);plot(t,mt);grid on;xlabel(t);
24、ylabel(amp);title(基带信号)subplot(222);plot(f,abs(f_mt);grid on;%plot(f,10*log10(psf_mt);xlabel(f);ylabel(psf);title(基带信号功率谱)subplot(223);plot(t,t_dsb);grid on; % t_dsb时域调制信号xlabel(t);ylabel(amp);title(DSB信号)subplot(224);plot(f,abs(f_dsb);grid on;%plot(f,10*log10(psf_dsb);xlabel(f);ylabel(psf);title(DS
25、B信号功率谱)结果:8-2.程序:Ts=1/128; %采样时间间隔T=2; %信号时长Fc=20000; %载波频率 t=0:Ts:T-Ts;mt=1-abs(t-1); %信源信号t_dsb=mt.*cos(2*pi*Fc*t); %时域调制信号delta_f=1/T; %频率分辨率N=length(t_dsb); %采样点数f=delta_f*-N/2:N/2-1; f_mt=fft(mt); f_mt=T/N*fftshift(f_mt); %把FFT结果平移到负频率上psf_mt=(abs(f_mt).2+eps)/T; %基带信号功率谱f_dsb=fft(t_dsb); %时域调制
26、信号的FFTf_dsb=T/N*fftshift(f_dsb); %把FFT结果平移到负频率上psf_dsb=(abs(f_dsb).2+eps)/T; %时域调制信号的功率谱subplot(221);plot(t,mt);grid on;xlabel(t);ylabel(amp);title(基带信号)subplot(222);plot(f,abs(f_mt);grid on;%plot(f,10*log10(psf_mt);xlabel(f);ylabel(psf);title(基带信号功率谱)subplot(223);plot(t,t_dsb);grid on; % t_dsb时域调制信
27、号xlabel(t);ylabel(amp);title(AM信号)subplot(224);plot(f,abs(f_dsb);grid on;%plot(f,10*log10(psf_dsb);xlabel(f);ylabel(psf);title(AM信号功率谱)结果:8-5程序:A=1; Fc1=2;Fc2=4;Fs=128; Ts=1/Fs;M=20; Td=1;T=M*Td;t=0:Ts:T-Ts;N=length(t)d=sign(sprandn(1,M,0.3); dd=sigexpand(d+1)/2,Fs);gt=ones(1,Fs);figure(1)subplot(22
28、1);t_snrz=conv(dd,gt); delta_f=1/T; N=length(t); f=delta_f*-N/2:N/2-1; f_snrz=fft(t_snrz(1:length(t); f_snrz=T/N*fftshift(f_snrz);psf=(abs(f_snrz).2+eps)/T;plot(t,t_snrz(1:length(t);grid onaxis(0 5 0 1.2);xlabel(t);ylabel(amp);title(基带信号);subplot(222);plot(f,10*log10(abs(f_snrz).2/T+eps);grid onplot
29、(f,abs(f_snrz).2/T+eps);grid onaxis(-2 2 0 10);xlabel(f);ylabel(psf);title(基带信号频谱);ht1=A*cos(2*pi*Fc1*t);ht2=A*cos(2*pi*Fc2*t);t_2fsk=(1-t_snrz(1:N).*ht1+t_snrz(1:N).*ht2;f_2fsk=fft(t_2fsk(1:N); f_2fsk=T/N*fftshift(f_2fsk);psf=(abs(f_2fsk).2+eps)/T;subplot(223)plot(t,t_2fsk);grid on;axis(0 5 -1.2 1.2);xlabel(t);ylabel(amp);title(2FSK信号);subplot(224)plot(f,abs(f_2fsk).2/T+eps);grid on;axis(-10 10 0 2);xlabel(f);ylabel(psf);title(2FSK信号功率谱); 结果:
链接地址:https://www.31doc.com/p-3312941.html