数字信号处理第三版高西全实验 下载本文

内容发布更新时间 : 2024/5/3 10:35:07星期一 下面是文章的全部内容请认真阅读。

代码: n=0:26;

xa=1:14;xb=13:-1:1;xn=[xa,xb]; Xk=fft(xn,512);

k=0:2/512:2*(1-1/512); subplot(321) plot(k,abs(Xk)) axis([0,1,0,200]) title('FT[x(n)]') subplot(322) stem(n,xn,'.')

title('三角波序列') X32k=fft(xn,32); x32n=ifft(X32k); X16k=X32k(1:2:32); x16n=ifft(X16k,16); k=0:15; subplot(323)

stem(k,abs(X16k),'.') title('16点频域采样') axis([0,10,0,200]) subplot(324) stem(k,x16n,'.')

title('16点IDFT[X16k]') axis([0,30,0,15]) k1=0:31; subplot(325)

stem(k1,abs(X32k),'.') title('32点频域采样') axis([0,10,0,200]) subplot(326) stem(k1,x32n,'.')

title('32点IDFT[X32k]') axis([0,30,0,15])

运行结果:

图2 实验(2)频域采样

3. 实验三:用FFT对信号作频谱分析 代码: clc clear n1=0:30;

x1=[1,1,1,1,zeros(1,27)]; n2=0:27;

x2=[1:4,4:-1:1,zeros(1,20)]; x3=[4:-1:1,1:4,zeros(1,20)]; subplot(331) stem(n1,x1,'.') axis([0,10,0,1])

title('x1(n)');xlabel('n');ylabel('x1(n)') subplot(332) stem(n2,x2,'.') axis([0,10,0,4])

title('x2(n)');xlabel('n');ylabel('x2(n)') subplot(333) stem(n2,x3,'.') axis([0,10,0,4])

title('x3(n)');xlabel('n');ylabel('x3(n)') k1=0:1/4:7/4; k2=0:1/8:15/8; X8k1=fft(x1,8); subplot(334)

stem(k1,abs(X8k1),'.') title('8点FFT变换') X16k1=fft(x1,16); subplot(337)

stem(k2,abs(X16k1),'.')

title('16点FFT变换') X8k2=fft(x2,8); subplot(335)

stem(k1,abs(X8k2),'.') title('8点FFT变换') X16k2=fft(x2,16); subplot(338)

stem(k2,abs(X16k2),'.') title('16点FFT变换') X8k3=fft(x3,8); subplot(336)

stem(k1,abs(X8k3),'.') title('8点FFT变换') X16k3=fft(x3,16); subplot(339)

stem(k2,abs(X16k3),'.') title('16点FFT变换')

运行结果:

图1 实验(1)图形

代码: clc clear n=0:30;

x4=cos(pi/4*n);

x5=cos(pi/4*n)+cos(pi/8*n); subplot(321) stem(n,x4,'.') axis([0,30,-1,1])

title('x4(n)=cos(pi/4*n)');xlabel('n');ylabel('x4(n)') subplot(322) stem(n,x5,'.')

axis([0,30,-2,2])

title('x5(n)=cos(pi/4*n+pi/8*n)');xlabel('n'); ylabel('x5(n)') k1=0:1/4:7/4; k2=0:1/8:15/8; X8k1=fft(x4,8); subplot(323)

stem(k1,abs(X8k1),'.') axis([0,2,0,5])

title('8点FFT变换') X16k1=fft(x4,16); subplot(325)

stem(k2,abs(X16k1),'.') axis([0,2,0,8])

title('16点FFT变换') X8k2=fft(x5,8); subplot(324)

stem(k1,abs(X8k2),'.') axis([0,2,0,10])

title('8点FFT变换') X16k2=fft(x5,16); subplot(326)

stem(k2,abs(X16k2),'.') axis([0,2,0,10])

title('16点FFT变换')

图2 实验(2)图形

clc clear n=1:100;

Fs=64;

x6=cos(8*pi*n/Fs)+cos(16*pi*n/Fs)+cos(20*pi*n/Fs); N1=16; F1=Fs/N1;

k1=-N1/2:N1/2-1; fk1=F1*k1;

X16k=fft(x6,16); X16k1=fftshift(X16k) subplot(311)

stem(fk1,abs(X16k1),'.') axis([-30,30,0,10]) title('变换区间N=16') N2=32; F2=Fs/N2;

k2=-N2/2:N2/2-1; fk2=F2*k2;

X32k=fft(x6,32); X32k1=fftshift(X32k) subplot(312)

stem(fk2,abs(X32k1),'.') axis([-30,30,0,20]) title('变换区间N=32') N3=64; F3=Fs/N3;

k3=-N3/2:N3/2-1; fk3=F3*k3;

X64k=fft(x6,64); X64k1=fftshift(X64k) subplot(313)

stem(fk3,abs(X64k1),'.') axis([-30,30,0,40]) title('变换区间N=64')