1、DSP与matlab联合设计FIR滤波器设计FIR滤波器作业报告学号:姓名: 设计FIR滤波器作业报告本设计主要内容是利用MATLAB验证设计思路并用CCS3.3仿真环境设计一个FIR滤波器,要求滤除给定的叠加正弦波的两个较高频分量。给定波形函数为:y=sin(2*pi*100*t)+sin(2*pi*250*t)+sin(2*pi*270*t)。1.设计思路:输入信号是频率为100Hz、250HZ、270Hz的合成正弦等幅信号,由于给定的谐波分量最高为270Hz,根据奈奎斯特准则,采样频率应大于最高频率分量的2倍,即大于2*270,故可以以600Hz的采样频率进行采样,即fs=600Hz。设
2、计了一个截止频率为200Hz的低通滤波器,目的是通过所设计的低通bartlett滤波器将信号源中频率为200Hz以上的信号滤掉,留下频率为100Hz的信号,达到滤波的效果。利用MATLAB设计合适的滤波器实现滤波,然后得到其滤波器系数在CCS的simulator方式下编写滤波程序,调用波形数据,实现滤波,并观看滤波前后的信号波形图、频谱图,观察滤波达到预期效果。2.设计过程1) 在MATLAB中进行算法验证MATLAB语言由于具有数值计算功能、符号计算功能、数据可视化功能、建模仿真可视化功能,使得MATLAB在命题构思、模型建立、仿真研究、假想验证、数据源可视化各环节起着强大的作用。因此在设计
3、中必须先在MATLAB语言中设计一个FIR滤波器。本设计采用的是bartlett窗函数。下面是在MATLAB中设计的27阶FIR型bartlett滤波器程序:clear all; %请寄存器clf; %清屏N=256; %清数据点fs=600; %采样频率dt=1/fs; %采样时间间隔for t=1:N f1=250; f2=100; f3=270; y(t)=(sin(2*pi*f1*t*dt)+sin(2*pi*f2*t*dt)+sin(2*pi*f3*t*dt);%产生合成信号 x(t)=round(10000*y(t); %为DSP汇编程序做数据转换end figure(1)plot
4、(y),title(滤波前的波形图像);fp=200fst=250NL=26 f1=200;w1=2*pi*f1/fswindow=bartlett(NL+1) %窗函数 n=1:NL+1hd=sin(w1*(n-NL/2)./(pi*(n-NL/2);hd(NL/2)=0.67;h=hd.*rot90(window)h1=h*32768;h2=fft(h,N); %将信号做FFT变换pyy=h2.*conj(h2); %做功率谱分析f=(0:(N/2-1);for i=1:N/2-1 f(i)=f(i)*fs/N;end figure(2)plot(f,pyy(1:N/2),title(滤波
5、器的频谱图像);yy1=filter(h,1,y); %滤波figure(3)plot(yy1),title(滤波后的波形图像);y=fft(y,N);pyy=y.*conj(y); f=(0:(N/2-1);for i=1:N/2-1 f(i)=f(i)*fs/N;end figure(4)subplot(1,2,1),plot(f,pyy(1:N/2),title(滤波前的波形频谱图像);y=fft(yy1,N);pyy=y.*conj(y);f=(0:(N/2-1);for i=1:N/2-1 f(i)=f(i)*fs/N;end subplot(1,2,2),plot(f,pyy(1:
6、N/2),title(滤波后的波形频谱图像) 其中采样点为256个,采样频率为600Hz,输入信号为100Hz、250Hz、270Hz的合成信号,设定的截止频率为200Hz,通过FIR滤波器后,期望保留的信号是100Hz的信号,200Hz以上的频率基本被滤掉。图1是滤波前的图形,图2是滤波后的图形,图3为滤波器频谱图像,图4滤波前后的波形频谱图像。从这四个图中可以看住原始信号中的频率有100Hz、250Hz、270Hz,经过滤波后200Hz以上的信号成分基本上被滤掉。只留下100Hz的信号。图1 滤波前波形图像图2 滤波后波形图像图3 滤波器的频谱图像图4.滤波前后的波形频谱图像2) 在CCS
7、环境的仿真首先配置处理器项,进入CCStudio v3.3中,编写程序,程序如下: .mmregs .ref filter_start .def _c_int00K_DATA_SIZE .set 256K_BUFFER_SIZE .set 32K_STACK_SIZE .set 256K_B .set 27K_CIR .set K_BUFFER_SIZE STACK .usect stack,K_STACK_SIZESYSTEM_STACK .set K_STACK_SIZE+STACKDATA_DP .usect filter_vars,0filterdata .usect filter_v
8、ars,K_DATA_SIZEbufferdatay .usect filter_vars,K_BUFFER_SIZE*2bufferdatax .usect filter_vars,K_BUFFER_SIZE*2 .data .global inputdatainputdata .WORD 16750, -5878, 18090,-26831, 6340, -9511,11750,11443 .WORD -6910, 0,-16750, 5878, 5570, 9511,0,-7810 .WORD -11750, 5878, 570, 17321,-6910, -5878,-5570,-95
9、11 .WORD 23660, -9511, 18090,-23198, -570, 0, 570, 23198,-18090 .WORD 9511,-23660, 9511, 5570, 5878,6910,-17321,-570 .WORD -5878,11750,7810,0,-9511,-5570,-5878,16750 .WORD 0,6910,-11443,-11750,9511,-6340,26831,-18090 .WORD 5878,-16750,0,16750,-5878,18090,-26831,6340 .WORD -9511,11750,11443,-6910,0,-
10、16750,5878,5570 .WORD 9511,0,-7810,-11750,5878,570,17321,-6910 .WORD -5878,-5570,-9511,23660,-9511,18090,-23198,-570 .WORD 0,570,23198,-18090,9511,-23660,9511,5570 .WORD 5878,6910,-17321,-570,-5878,11750,7810,0 .WORD -9511,-5570,-5878,16750,0,6910,-11443,-11750 .WORD 9511,-6340,26831,-18090,5878,-16
11、750,0,16750 .WORD -5878,18090,-26831,6340,-9511,11750,11443,-6910 .WORD 0,-16750,5878,5570,9511,0,-7810,-11750 .WORD 5878,570,17321,-6910,-5878,-5570,-9511,23660 .WORD -9511,18090,-23198,-570,0,570,23198,-18090 .WORD 9511,-23660,9511,5570,5878,6910,-17321,-570 .WORD -5878,11750,7810,0,-9511,-5570,-5
12、878,16750 .WORD 0,6910,-11443,-11750,9511,-6340,26831,-18090 .WORD 5878,-16750,0,16750,-5878,18090,-26831,6340 .WORD -9511,11750,11443,-6910,0,-16750,5878,5570 .WORD 9511,0,-7810,-11750,5878,570,17321,-6910 .WORD -5878,-5570,-9511,23660,-9511,18090,-23198,-570 .WORD 0,570,23198,-18090,9511,-23660,95
13、11,5570 .WORD 5878,6910,-17321,-570,-5878,11750,7810,0 .WORD -9511,-5570,-5878,16750,0,6910,-11443,-11750 .WORD 9511,-6340,26831,-18090,5878,-16750,0,16750 .WORD -5878,18090,-26831,6340,-9511,11750,11443,-6910 .WORD 0,-16750,5878,5570,9511,0,-7810 .text_c_int00: .asg AR2,ORIGIN .asg AR3,INPUT .asg A
14、R4,FILTER .asg AR5,OUTPUTSTART: SSBX FRCT SSBX INTM LD #DATA_DP,DP STM #STACK,SP CALL filter_start NOP NOP NOPLOOP B LOOP .def h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15,h16,h17,h18,h19,h20,h21,h22,h23,h24,h25,h26 .def filter_starth0 .set 0000Hh1 .set -003FHh2 .set 008AHh3 .set 0000Hh4 .s
15、et -015BHh5 .set 01F0Hh6 .set 0000Hh7 .set -03CDHh8 .set 056EHh9 .set 0000Hh10 .set -0D92Hh11 .set 1DDBHh12 .set 4F2AHh13 .set 2349Hh14 .set -1049Hh15 .set 0000Hh16 .set 06C9Hh17 .set -04E3Hh18 .set 0000Hh19 .set 02B7Hh20 .set -0209Hh21 .set 0000Hh22 .set 0116Hh23 .set -00BEHh24 .set 0000Hh25 .set 0
16、035Hh26 .set 0000H .textfilter_start: STM #K_CIR,BK STM #1,AR0 ;设置循环缓冲区的大小和步长 STM #inputdata,ORIGIN STM #bufferdatax,INPUT ; STM #bufferdatay,FILTER STM #filterdata,OUTPUT STM #K_DATA_SIZE-1,BRC ;设置快循环计数器 RPTB filter_end-1 MVDD *ORIGIN+,*INPUT RPT #K_B-1-1 MAR *INPUT-0% MPY *INPUT+0%,#h26,B LD B,A M
17、PY *INPUT+0%,#h25,B ADD B,A MPY *INPUT+0%,#h24,B ADD B,A MPY *INPUT+0%,#h23,B ADD B,A MPY *INPUT+0%,#h22,B ADD B,A MPY *INPUT+0%,#h21,B ADD B,A MPY *INPUT+0%,#h20,B ADD B,A MPY *INPUT+0%,#h19,B ADD B,A MPY *INPUT+0%,#h18,B ADD B,A MPY *INPUT+0%,#h17,B ADD B,A MPY *INPUT+0%,#h16,B ADD B,A MPY *INPUT+
18、0%,#h15,B ADD B,A MPY *INPUT+0%,#h14,B ADD B,A MPY *INPUT+0%,#h13,B ADD B,A MPY *INPUT+0%,#h12,B ADD B,A MPY *INPUT+0%,#h11,B ADD B,A MPY *INPUT+0%,#h10,B ADD B,A MPY *INPUT+0%,#h9,B ADD B,A MPY *INPUT+0%,#h8,B ADD B,A MPY *INPUT+0%,#h7,B ADD B,A MPY *INPUT+0%,#h6,B ADD B,A MPY *INPUT+0%,#h5,B ADD B
19、,A MPY *INPUT+0%,#h4,B ADD B,A MPY *INPUT+0%,#h3,B ADD B,A MPY *INPUT+0%,#h2,B ADD B,A MPY *INPUT+0%,#h1,B ADD B,A MPY *INPUT+0%,#h0,B ADD B,A ; STH A,*FILTER-0% STH A,*OUTPUT+ ; MAR *FILTER-0%filter_end: NOP RET .end配置文件:MEMORY PAGE 0: PARAM:org=3000h len=4000h PAGE 1: DARAM:org=100h len=4000h SECTIONS .text : PARAM PAGE 0 STACK : DARAM PAGE 1 filter_vars : DARAM PAGE 1 .bss : DARAM PAGE 1 .data : DARAM PAGE 1 仿真结果如下:图5、6为滤波前的信号时域图和频谱图像,图7、8为滤波后的信号时域图和频谱图像。图5 滤波前的信号时域波形图像图6 滤波前的信号功率谱图图7 滤波后的信号时域波形图像图8 滤波后的信号功率谱图
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1