数字信号处理第二次上机作业1.计算序列(){其他的N=16及N=32点的DFT,即X(k)=DFT[x(n)]。分别输出|X(k)|,Φ(k)曲线(并与FFT函数计算结果比较)代码:clcclearallclosealln=0:15;xn=0.1*n+1;%16点DFTN1=16;X1=dft(xn,N1);figure(1)k=0:N1-1;subplot(2,1,1)stem(k,abs(X1),'.');xlabel('k'),ylabel('|X1(k)|');title('16点DFT'),gridonsubplot(2,1,2)stem(k,angle(X1),'.');gridonxlabel('k');ylabel('angle(X1(k))');%16点FFTN1=16;X1=fft(xn,N1);figure(2)k=0:N1-1;subplot(2,1,1)stem(k,abs(X1),'.');xlabel('k');ylabel('|X1(k)|');title('16点FFT'),gridonsubplot(2,1,2)stem(k,angle(X1),'.');gridonxlabel('k');ylabel('angle(X1(k))');%32点DFTN2=32;X2=dft(xn,N2);figure(3)k=0:N2-1;subplot(2,1,1)stem(k,abs(X2),'.');xlabel('k');ylabel('|X(2k)|');title('32点DFT'),gridonsubplot(2,1,2)stem(k,angle(X2),'.');gridonxlabel('k');ylabel('angle(X2(k))');%32点FFTN2=32;X2=fft(xn,N2);figure(4)k=0:N2-1;subplot(2,1,1)stem(k,abs(X2),'.');xlabel('k');ylabel('|X(2k)|');title('32点FFT'),gridonsubplot(2,1,2)stem(k,angle(X2),'.');gridonxlabel('k');ylabel('angle(X2(k))');运行结果:2.输出序列x(n)=sin(0.5n+0.2),0,N自定。计算并输出x(n)的N点DFT:(),以及x(n)的2N点DFT:()。观察()和(),能得出什么结论?代码:clcclearallcloseallN=32;%第一次取采样点32个,第二次取采样点2*32=64个n=0:N-1;xn=sin(0.5*pi*n+0.2*pi);Xk1=fft(xn,N)Xk2=fft(xn,2*N)subplot(2,1,1)k=0:N-1;stem(k,abs(Xk1),'.');xlabel('k');ylabel('|Xk1(k)|'),gridon,title('32点DFT')subplot(2,1,2)k=0:2*N-1;stem(k,abs(Xk2),'.');xlabel('k');ylabel('|Xk2(k)|'),gridon,title('64点DFT')运行结果:3.用快速卷积算法计算下列两序列的线性卷积序列,并输出结果(){22}(){(2)n(98)n628输出x1(n)、x2(n)及其FFT信号图形,输出卷积结果。(注意FFT点数应满足循环卷积与线性卷积相等条件)与第一次上机作业中时域线性卷积比较(指计算时间比较,卷积结果应相同)。代码:clcclearallcloseallx1=[0,2,2,1];%序列1n=0:15;a1=(1.02).^n;n=16:28;a2=(0.98).^n;x2=[a1a2];%序列2N1=length(x1);X1=fft(x1,N1);figure(1)k=0:N1-1;subplot(2,1,1)stem(k,abs(X1),'.');xlabel('k'),ylabel('|X1(k)|');title('x1的DFT'),gridonsubplot(2,1,2)stem(k,angle(X1),'.'),gridonxlabel('k');ylabel('angle(X1(k))');N2=length(x2);X2=fft(x2,N2);figure(2)k=0:N2-1;subplot(2,1,1)stem(k,abs(X2),'.');xlabel('k'),ylabel('|X2(k)|');title('x2的DFT'),gridonsubplot(2,1,2)stem(k,angle(X2),'.');gridonxlabel('k');ylabel('angle(X2(k))');L=N1+N2-1;y1=ifft(fft(x1,L).*fft(x2,L))%卷积figure(3)subplot(3,1,1),stem(x1,'.');xlabel('n');ylabel('x1'),gridon,title('x1')subplot(3,1,2),stem(x2,'.');xlabel('n');ylabel('x2'),gridon,title('x2')subplot(3,1,3),stem(y1,'.');xlabel('n');ylabel('y'),gridon,title('y=x1*x2')y2=juanji(x1,x2)figure(4)subplot(3,1,1),stem(x1,'.');xlabel('n');ylabel('x1'),gridon,title('x1')subplot(3,1,2),stem(x2,'.');xlabel('n');ylabel('x2'),gridon,title('x2')subplot(3,1,3),stem(y1,'.');xlabel('n');ylabel('y2'),gridon,title('y=x1*x2直接卷积结果')运行结果:4.若x(n)=x1(n)+jx2(n),其中x1(n)=cos(n/4),x2(n)=sin(n/8)。根据DFT的对称性,由X(k)求出X1(k)=DFT[x1(n)]和X2(k)=DFT[x2(n)]。(X(k)=DFT[x(n)])代码:clcclearcloseallN=4;n=0:N-1;x1=cos(pi*n/4);x2=sin(pi*n/8);xn=x1+x2*i;Xk=fft(xn,N);Xk(N+1)=Xk(1);k=1:N;Xepk=0.5*(Xk(k)+conj(Xk(N+2-k)));Xopk=0.5*(Xk(k)-conj(Xk(N+2-k)));X1k=Xepk%DFT(x1)X2k=Xopk/j%DFT(x2)运行结果: