Matlab与通信仿真 ② 考虑信号xk[n]?sin(?kn),式中?k=2πk/5.给出k=1,2,4,6,用stem画出每个信号在区间0≤n≤9内的图。利用subplot在同一幅图上用单独的坐标轴画出全部符号。 程序: k=[1,2,3,6]; n=0:9; figure
for i=1:length(k)
xk=sin(2*pi*k(i)*n/5); subplot(length(k),1,i) % plot(n,xk);hold on s=int2str(k(i)) title(['k=' s]); stem(n,xk,'r'); end 结果:
10-110-110-110-10123456789012345678901234567890123456789
③ N=6,试画出x1[n]?cos(2n3n2?n3?n)?2cos();x2[n]?2cos()?cos()
NNNN2?n5?nx3[n]?cos()?3sin()的图形。
N2N程序:
N=6; n=0:100;
xn1=cos(2*pi*n/N)+2*cos(3*pi*n/N); xn2=cos(2*n/N)+2*cos(3*n/N);
9
Matlab与通信仿真 xn3=cos(2*pi*n/N)+3*sin(5*pi*n/N); figure
subplot(3,1,1) stem(n,xn1);hold plot(n,xn1,'r') subplot(3,1,2) stem(n,xn2);hold plot(n,xn2,'r') subplot(3,1,3) stem(n,xn3);hold plot(n,xn3,'r') 结果:
50-550-550-5010203040506070809010001020304050607080901000102030405060708090100
④ 在0≤n≤31内画出下面每一个信号:
x1[n]?sin(?n4)cos(?n4); x2[n]?cos2(?n4); x3[n]?sin(?n4)cos(?n8)。
程序: n=0:31;
xn1=cos(pi*n/4).*sin(pi*n/4); xn2=cos(pi*n/4).^2;
xn3=cos(pi*n/8).*sin(pi*n/4); figure
subplot(3,1,1) stem(n,xn1);hold plot(n,xn1,'r') subplot(3,1,2)
10
Matlab与通信仿真 stem(n,xn2);hold plot(n,xn2,'r') subplot(3,1,3) stem(n,xn3);hold plot(n,xn3,'r') 结果:
0.50-0.5-110.5010-1051015202530350510152025303505101520253035
⑤ 用stem画出信号
?2,n?0?1,n?2??x[n]???1,n?3
?3,n?4???0,其余n定义:y1[n]=x[n-2], y2[n]=x[n+1],y3[n]=x[-n], y4[n]=x[-n+1], 用stem分别画出y1~y4,并用legend 命令给出图例。 程序: function x=xn(t) %方法一
%x1=2*ones(1,length(t)); %x2=ones(1,length(t)); %x3=-1*ones(1,length(t)); %x4=3*ones(1,length(t));
11
Matlab与通信仿真 %x=x1.*(t==0)+x2.*(t==2)+x3.*(t==3)+x4.*(t==4); % 方法二
x=zeros(1,length(t));
x=2*(t==0)+1*(t==2)+(-1)*(t==3)+3*(t==4); %主程序
t= -10 : 10 ; y0=xn(t) ;
y1=xn(t-2) ; y2=xn(t+1) ; y3=xn(-t) ;
y4=xn(-t+1) ;
subplot(511);p=plot(t,y0,'k');set(p,'LineWidth',2);hold on;stem(t,y0,'r') xlabel('t');ylabel('x(t)');title('原始信号 x(t)');grid;
subplot(512);p=plot(t,y1,'k');set(p,'LineWidth',2);hold on;stem(t,y1,'r') xlabel('t');ylabel('x(t-2)');title('第一个变换');grid;
subplot(513);p=plot(t,y2,'k');set(p,'LineWidth',2);hold on;stem(t,y2,'r') xlabel('t');ylabel('x(t+1)');title('第二个变换');grid;
subplot(514);p=plot(t,y3,'k');set(p,'LineWidth',2);hold on;stem(t,y3,'r') xlabel('t');ylabel('x(-t)');title('第三个变换');grid;
subplot(515);p=plot(t,y4,'k');set(p,'LineWidth',2);hold on;stem(t,y4,'r') xlabel('t');ylabel('x(-t+1)');title('第四个变换');grid;
原始信号 x(t)5x(t)0-5-10-8-6-4-202t第一个变换4681050-5-10x(t-2)-8-6-4-202t第二个变换4681050-5-10x(t+1)-8-6-4-202t第三个变换4681050-5-10x(-t)-8-6-4-202t第四个变换468105x(-t+1)0-5-10-8-6-4-20t246810
12
Matlab与通信仿真 2.设周期信号一个周期的波形为f?t????1,t?T/4?0,其他,求该信号傅里叶级数展开式,并用
MATLAB画出傅里叶技术展开后的波形,并通过展开式项数的变化考察其对f?t?的逼近程度,考察其物理意义。 程序:
% 实验二 exp0302.m
% 设周期信号一个周期的波形为f(t)=1,|t| ft=ft+Fn(m+N+1)*exp(j*2*pi*m*fs*t) ; % Fn是一个数组,其序号是从1开始的,到 % 2N+1结束, % 故该语句中为Fn(m+N+1) % 而当n=0时,Fn=0,在数组中的位置 % 为第N+1个元素,故令Fn(N+1)=0 end plot(t,ft) 1.510.50-0.5-1-1.5012345678910 13