资源描述:
《c语言写的fir低通滤波器》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、根据fir滤波器的公式y(n)=∑h(m)x(n-m);(m:0~(N-1)).利用MATLAB产生滤波器系数(h(n))并归一化,下面为一个LP滤波算法voidfilter(void){uint16i,j;fp32sum;int16x1[2030];fp32h[19]={-0.0027,-0.0025,0.0050,0.0157,-0.0000,-0.0471,-0.0482,0.0838,0.2953,0.4013,0.2953,0.0838,-0.0482,-0.0471,-0.0000,0.0157,0.00
2、50,-0.0025,-0.0027};for(i=0;i<2020;i++)x1[i]=data0[i];for(i=0;i<2020;i++){sum=0.0;for(j=0;j<19;j++){if(i>=j)sum+=h[j]*x1[i-j];else;}data0[i]=(int16)sum;}for(i=0;i<2000;i++){data0[i]=data0[i+20];}}考虑到前19个点为不完全累加和,故抛去前19个点。(应该是前后各18个点都是不完全累加和,都应该去掉,对于数据分段进入滤波器的情况
3、,应该把前一段的后面数据放到下一段的前面,这段时间我在解调FSK时遇到了这个问题,通过滤波器的数据的分段处理。)设输入数据x[N],输出数据y[N],滤波器系数h[n]1.直接法(由y(m)=h(0)*x(m)+h(1)*x(m-1)+...+h(N-1)*x(m-n-1));voidfir(shortx[],shorth[],shorty[]){inti,j;longlongsum;for(j=0;j>1
4、5;}}乘法器使用次数:N*n2.逆推法:voidfir(shortx[],shorth[],shorty[]){inti,j;longsum;for(j=0;j>15;}}}乘法器使用次数:N*n3.倒序法:(输入输出可以是同一量)voidfir(shortx[],shorth[],shorty[]){inti,j;longlongsum;for(j=N;j>0;j--){sum=0;for(i=n;i>0;
5、i--)sum+=x[j-i]*h[i];y[j]=sum>>15;}}#include#include#definetrue1#definefalse0#definen8#definebufsize100/*thebuffersizeis100*//*globaldeclarations*/intin_buffer[bufsize];/*processingdatabuffers*/intout_buffer[bufsize];/*functions*/staticintproce
6、ssing(int*input,int*output);staticvoiddataio(void);staticlonground(longa);voidmain(){int*input=&in_buffer[0];int*output=&out_buffer[0];puts("the1stexperimentstarted");/*loopforever*/while(true){/**readinputdatausingaprobe-pointconnectedtoahostfile.*writeoutpu
7、tdatatoagraphconnectedthroughaprobe-point.*///readtheinputsignal.//iftheinputfileissine1.dat,thesignalcontains300hz,400hzand500hz.//iftheinputfileissine2.dat,thesignalcontains100hz,400hzand500hz.//thesamplingfrequencyis1200hz.dataio();/*removethefrequencycompom
8、entof400hzand500hz*/processing(input,output);//writetheoutputsignal.//theoutputfileisresult.dat.dataio();}}/**========processing========**function:applyalow-passfirfiltertoi