资源描述:
《设计低通FIR滤波器.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、设计低通FIR滤波器。通带边缘频率10KHz,阻带边缘频率22KHz,阻带衰减75dB,采样频率50KHz窗函数选定:阻带衰减75dB,选择blackman窗截止频率:2pi*(10+(22-10)/2)/50=0.64pi窗函数长度:blackman窗的过渡带宽为5.98,单位为2pi/N,而要设计的低通滤波器的过渡带宽为2pi*12/50=0.48pi,二者相等,得N=24.9,取25。理想低通滤波器脉冲响应:h1[n]=sin(nΩ1)/n/pi=sin(0.64pi*n)/n/pi窗函数为:w[n]=0.42-0.5cos(2pi*n/24)+0.8cos
2、(4pi*n/24)则滤波器脉冲响应为:h[n]=h1*w[n]
3、n
4、<=12h[n]=0
5、n
6、>12#include"DSP281x_Device.h"DSP281xHeaderfileIncludeFile#include"DSP281x_Examples.h" DSP281xExamplesIncludeFile#include"f2812a.h"#include"math.h"#defineFIRNUMBER25#defineSIGNAL1F1000#defineSIGNAL2F4500#defineSAMPLEF 1000
7、0#definePI3. floatInputWave();floatFIR(); floatfHn[FIRNUMBER]={0.0,0.0,0.001,-0.002,-0.002,0.01,-0.009, -0.018,0.049,-0.02,0.11,0.28,0.64,0.28, -0.11,-0.02,0.049,-0.018,-0.009,0.01, -0.002,-0.002,0.001,0.0,0.0
8、 };floatfXn[FIRNUMBER]={0.0};floatfInput,fOutput;floatfSignal1,fSignal2;floatfStepSignal1,fStepSignal2;floatf2PI;inti;floatfIn[256],fOut[256];intnIn,nOut; main(void){ nIn=0;nOut=0; f2PI=2*PI; fSignal1=0.0; fSignal2=PI*0.1; fStepSignal1=2*PI/30; fStepSignal2=2*PI*1.4; while(1
9、) { fInput=InputWave(); fIn[nIn]=fInput; nIn++;nIn%=256; fOutput=FIR(); fOut[nOut]=fOutput; nOut++; if(nOut>=256) { nOut=0; /*请在此句上设置软件断点*/ } }} floatInputWave(){ for(i=FIRNUMBER-1;i>0;i--) fXn[i]=fXn[i-1]; fXn[0]=sin(fSignal1)+cos(fSignal2)/6.0; fSignal1+=fStepSignal1;
10、 if(fSignal1>=f2PI) fSignal1-=f2PI; fSignal2+=fStepSignal2; if(fSignal2>=f2PI) fSignal2-=f2PI; return(fXn[0]);} floatFIR(){ floatfSum; fSum=0; for(i=0;i