1、MATALB 信号处理实习报告1、实习目的“数字信号处理”是电子信息工程专业的主干课程,其理论性较强,学生通过理论课的系统学习后,应通过 MATLAB 语言对其所涉及的算法进行仿真,这不仅能帮助学生理解其抽象的物理概念,工程概念和复杂算法,加强感性认识,而且能激发学生更进一步地在该领域的学习和探索热情。2、实习任务及功能概述1. FT 与 DFT 关系的 MATLAB 仿真任务要求:(1)任设一个长度为 N 的实序列;(2)编写 MATLAB 代码,实现该序列的傅立叶变换和离散傅立叶变换;(3)调试运行代码,得到仿真图形;(4)通过仿真图形观察二者的关系,并得出结论。% x is origin
2、al sequency,N is transforming point% X is FT result of x,XK is DFT result of xfunction X,Xk=mydft(x,N)w=2*pi*(0:127)/128;X=x*exp(-j*1:length(x)*w) % x 的傅立叶变换 FTsubplot(211)plot(w,abs(X)k=0:N-1;XK=x*exp(-j*1:length(x)*(2*pi*k)/N) % x 的离散傅立叶变换 DFTsubplot(212)stem(k,abs(XK)end x=1 0 1 0 0 1 0 1; N=32;
3、mydft(x,N)由图可得 DFT 是有限长序列傅里叶变换的有限点离散采样。2. DFT 的快速算法 FFT 的仿真任务要求:(1)在熟悉 FFT 算法原理的基础上,对所给的时域信号进行分析;(2)对信号做时域分析时要注意混叠现象的发生;(3)对混合信号 做快速傅立叶变换 FFT 运算,)2sin()si()2sin() 321 tffttftf 其中 、 、 自设,变换点数根据所设的情况自定; 1f23f(4)对变换结果做分析。 myfft(40,60,160,320,64)3. 利用 MATLAB 信号处理工具箱设计 FIR 滤波器要求如下: (1) 熟悉 FIR 滤波器的工作原理;(2
4、) 设计一个 N 阶高通数字滤波器,阶数和截止频率自定;% h is impulse response of FIR filter,s is original signal,sf is filtered signal% f1 and f2 are frequency of signal s,fs is sample frequencyfunction h,s,sf=myFIRhighpassfilter(f1,f2,fs)m=(0.3*f1)/(fs/2); % define transition bandwidth M=round(8/m); % define length of hammi
5、ng windowN=M-1; % define order of FIR filterb=fir1(N,0.9*f2/(fs/2),high); h,f=freqz(b,1,512); % frequency response of filterplot(f*fs/(2*pi),20*log10(abs(h) % draw magnitude_frequency of filterxlabel(frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)figuresubplot(211) t=0:1/
6、fs:1;s=sin(2*pi*f1*t)+sin(2*pi*f2*t); plot(t,s); % draw original signal s xlabel(time/Second,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)subplot(212)SK=fft(s,512); SXK=abs(SK);f=(0:255)*fs/512;plot(f,SXK(1:256) % draw magnitude_frequency of sn xlabel(Frequency/Hz,fontsize,8,fontwei
7、ght,bold)set(gca,fontsize,8,fontweight,bold)figure sf=filter(b,1,s); % filter ssubplot(211)plot(t,sf) % draw filtered signal sfxlabel(time/Second,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)axis(0.2 .5 -2 2)subplot(212)SFK=fft(sf,512);SFXK=abs(SFK);f=(0:255)*fs/512;plot(f,SFXK(1:25
8、6) xlabel(Frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)end myFIRhighpassfilter(50,200,650)(3) 设计一个 N 阶带通数字滤波器,阶数和截止频率自定;% h is impulse response of FIR filter,s is original signal,sf is filtered signal% f1 , f2 and f3 are frequency of signal s,fs is sample frequencyfunct
9、ion h,s,sf=myFIRbandpassfilter(f1,f2,f3,fs)m=(0.3*f1)/(fs/2); % define transition bandwidth M=round(8/m); % define length of hamming windowN=M-1; % define order of FIR filterb=fir1(N,0.8*f2/(fs/2) 1.2*f2/(fs/2); % 上下限截止频率分别取 f2 的 0.8 和 1.2h,f=freqz(b,1,512);axes(position,0.1 0.76 0.33 .2)plot(f*fs/(
10、2*pi),20*log10(abs(h)xlabel(frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)t=0:1/fs:1;s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);axes(position,0.1 0.43 0.33 .2)plot(t,s);xlabel(time/Second,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)sf=filter(b,1,s);
11、axes(position,0.1 0.1 0.33 .2)plot(t,sf)axis(0.2 .5 -2 2)xlabel(time/Second,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)endmyFIRbandpassfilter(40,100,180,400)(4) 设计一个 N 阶低通数字滤波器,阶数和截止频率自定;% h is impulse response of FIR filter,s is original signal,sf is filtered signal% f1 and f2 ar
12、e frequency of signal s,fs is sample frequencyfunction h,s,sf=myFIRlowpassfilter(f1,f2,fs)m=(0.3*f1)/(fs/2); % define transition bandwidth M=round(8/m); % define length of hamming windowN=M-1; % define order of FIR filterb=fir1(N,0.9*f2/(fs/2); h,f=freqz(b,1,512); % frequency response of filterplot(
13、f*fs/(2*pi),20*log10(abs(h) % draw magnitude_frequency of filterxlabel(frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)figuresubplot(211) t=0:1/fs:1;s=sin(2*pi*f1*t)+sin(2*pi*f2*t); plot(t,s); % draw original signal s xlabel(time/Second,fontsize,8,fontweight,bold)set(gca,f
14、ontsize,8,fontweight,bold)subplot(212)SK=fft(s,512); SXK=abs(SK);f=(0:255)*fs/512;plot(f,SXK(1:256) % draw magnitude_frequency of sn xlabel(Frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)figure sf=filter(b,1,s); % filter ssubplot(211)plot(t,sf) % draw filtered signal sfxl
15、abel(time/Second,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)axis(0.2 .5 -2 2)subplot(212)SFK=fft(sf,512);SFXK=abs(SFK);f=(0:255)*fs/512;plot(f,SFXK(1:256) xlabel(Frequency/Hz,fontsize,8,fontweight,bold)set(gca,fontsize,8,fontweight,bold)endmyFIRlowpassfilter(50,200,500)(5) 有完整的 MA
16、TLAB 代码。 4. 利用 MATLAB 信号处理工具箱设计 IIR 滤波器要求如下:(1)熟悉 IIR 数字滤波器的工作原理;(2)设计一个 N 阶高通数字滤波器,阶数和截止频率自定;% x is original signal,xf is filtered singnal% m is magni_frequ of xFFT,mf is magni_frequ xfFFT% f1 and f2 are frequency of signal x, fs is sample frequency,n is% transforming point function x,m,xf,mf=myfft
17、andhighIIRfilter(f1,f2,fs,n)subplot(411)t=0:1/fs:.5;x=sin(2*pi*f1*t)+sin(2*pi*f2*t);plot(t,x)subplot(412)y=fft(x,n);m=abs(y)/max(abs(y);f=fs*(0:n/2-1)/n;plot(f,m(1:n/2);b,a=ellip(6,.1,40,.5*(f1+f2)/(fs/2),high);xf=filter(b,a,x);subplot(413)plot(t,xf);subplot(414)yf=fft(xf,n);mf=abs(yf)/max(abs(yf);f
18、=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);endmyhighIIRfilter(50,100,300,16)(3)设计一个 N 阶带通数字滤波器,阶数和截止频率自定;% x is original signal,xf is filtered singnal% m is magni_frequ of xFFT,mf is magni_frequ xfFFT% f1 and f2 are frequency of signal x, fs is sample frequency% n is transforming point function x,m,xf,mf=myba
19、ndpassIIRfilter(f1,f2,f3,fs,n)subplot(411)t=0:1/fs:.5;x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);plot(t,x)subplot(412)y=fft(x,n);m=abs(y)/max(abs(y);f=fs*(0:n/2-1)/n;plot(f,m(1:n/2);b,a=ellip(6,.1,40,0.8*f2/(fs/2) 1.2*f2/(fs/2);xf=filter(b,a,x);subplot(413)plot(t,xf);subplot(414)yf=fft(xf,n);mf=
20、abs(yf)/max(abs(yf);f=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);endmybandpassIIRfilter(50,100,150,400,256)(4)设计一个 N 阶低通数字滤波器,阶数和截止频率自定;% x is original signal,xf is filtered singnal% m is magni_frequ of xFFT,mf is magni_frequ xfFFT% f1 and f2 are frequency of signal x, fs is sample frequency,n is% transforming
21、 point function x,m,xf,mf=mylowIIRfilter(f1,f2,fs,n)subplot(411)t=0:1/fs:.5;x=sin(2*pi*f1*t)+sin(2*pi*f2*t);plot(t,x)subplot(412)y=fft(x,n);m=abs(y)/max(abs(y);f=fs*(0:n/2-1)/n;plot(f,m(1:n/2);b,a=ellip(6,.1,40,.5*(f1+f2)/(fs/2);xf=filter(b,a,x);subplot(413)plot(t,xf);subplot(414)yf=fft(xf,n);mf=abs
22、(yf)/max(abs(yf);f=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);endmylowIIRfilter(50,100,300,256)(5)有完整的 MATLAB 代码。5. 利用所设计的滤波器对混合信号进行滤波要求如下:(1)设计一个 IIR 或 FIR 数字滤波器,将混合信号)2sin()si()2sin() 321 tffttftf 中的 、 或 选择出来, 、 、 自定,滤波器类型自定;3123f(2)有完整的 MATALB 代码;function x,m,xf,mf=fj(f1,f2,f3,fs,n)subplot(421)t=0:1/fs:.5;x
23、=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);plot(t,x)subplot(422)y=fft(x,n);m=abs(y)/max(abs(y);f=fs*(0:n/2-1)/n;plot(f,m(1:n/2);b,a=ellip(6,.1,40,0.8*f2/(fs/2) 1.2*f2/(fs/2);xf=filter(b,a,x);subplot(423)plot(t,xf);subplot(424)yf=fft(xf,n);mf=abs(yf)/max(abs(yf);f=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);d
24、,c=ellip(6,.1,40,.5*(f1+f2)/(fs/2);xf=filter(d,c,x);subplot(425)plot(t,xf);subplot(426)yf=fft(xf,n);mf=abs(yf)/max(abs(yf);f=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);f,e=ellip(6,.1,40,.5*(f2+f3)/(fs/2),high);xf=filter(f,e,x);subplot(427)plot(t,xf);subplot(428)yf=fft(xf,n);mf=abs(yf)/max(abs(yf);f=fs*(0:n/2-1)/n;plot(f,mf(1:n/2);end(3)仿真结果;fj(50,100,200,500,128)