资源描述:
《FIR滤波器的DSP程序.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include"DSP28x_Project.h"//DeviceHeaderfileandExamplesIncludeFile#include"math.h"#defineFIRNUMBER25#defineSIGNAL1F1000#defineSIGNAL2F4500#defineSAMPLEF10000#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
2、,-0.11,-0.02,0.049,-0.018,-0.009,0.01,-0.002,-0.002,0.001,0.0,0.0};floatfXn[FIRNUMBER]={0.0};floatfInput,fOutput;floatfSignal1,fSignal2;floatfStepSignal1,fStepSignal2;floatf2PI;inti;floatfIn[256],fOut[256];intnIn,nOut;voidmain(void){nIn=0;nOut=0;f2PI=2*PI;fSignal1=0.0;fSignal2=PI*0.1;fStepSigna
3、l1=2*PI/30;fStepSignal2=2*PI*1.4;//Step1.InitializeSystemControl://PLL,WatchDog,enablePeripheralClocks//ThisexamplefunctionisfoundintheDSP2833x_SysCtrl.cfile.InitSysCtrl();//Step2.InitalizeGPIO://ThisexamplefunctionisfoundintheDSP2833x_Gpio.cfileand//illustrateshowtosettheGPIOtoit'sdefaultstate
4、.//InitGpio();Skippedforthisexample//Step3.ClearallinterruptsandinitializePIEvectortable://DisableCPUinterruptsDINT;//InitializePIEcontrolregisterstotheirdefaultstate.//ThedefaultstateisallPIEinterruptsdisabledandflags//arecleared.//ThisfunctionisfoundintheDSP2833x_PieCtrl.cfile.InitPieCtrl();/
5、/DisableCPUinterruptsandclearallCPUinterruptflags:IER=0x0000;IFR=0x0000;//InitializethePIEvectortablewithpointerstotheshellInterrupt//ServiceRoutines(ISR).//Thiswillpopulatetheentiretable,eveniftheinterrupt//isnotusedinthisexample.Thisisusefulfordebugpurposes.//TheshellISRroutinesarefoundinDSP2
6、833x_DefaultIsr.c.//ThisfunctionisfoundinDSP2833x_PieVect.c.InitPieVectTable();//Step4.while(1){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(
7、fSignal1)+cos(fSignal2)/6.0;fSignal1+=fStepSignal1;if(fSignal1>=f2PI)fSignal1-=f2PI;fSignal2+=fStepSignal2;if(fSignal2>=f2PI)fSignal2-=f2PI;return(fXn[0]);}floatFIR(){floatfSum;fSum=0;for(i=0;i