|
低通滤波C程序:1.
6.7.#include <stdio.h> 8.const int length = 180
9.void filter(int xin[ ],int xout[ ],int n,float h[ ]);
10.
11.static float h[19]=
12.{0.01218354,-0.009012882,-0.02881839,-0.04743239,-0.04584568,
13.-0.008692503,0.06446265,0.1544655,0.2289794,0.257883,
14.0.2289794,0.1544655,0.06446265,-0.008692503,-0.04584568,
15.-0.04743239,-0.02881839,-0.009012882,0.01218354};
16.static int x1[length+20];
17.
18.void filter(int xin[ ],int xout[ ],int n,float h[ ])
19.{
20.int i,j;
21.float sum;
22.for(i=0;i<length;i++) x1[n+i-1]=xin[i];
23.for (i=0;i<length;i++)
24.{
25.sum=0.0;
26.for(j=0;j<n;j++) sum+=h[j]*x1[i-j+n-1];
27.xout[i]=(int)sum;
28.}
29.for(i=0;i<(n-1);i++) x1[n-i-2]=xin[length-1-i];
30.}
31.32.
33.void main( )
34.{
35.FILE *fp1,*fp2;
36.int frame,indata[length],outdata[length];
37.fp1=fopen(insp.dat,"rb");
38.fp2=fopen(outsp.dat,"wb");
39.40.frame=0;
41.while(feof(fp1)==0)
42.{
43.frame++;
44.printf("frame=%d\n",frame);
45.for(i=0;i<length;i++) indata[i]=getw(fp1);
46.filter(indata,outdata,19,h);
47.for(i=0;i<length;i++) putw(outdata[i],fp2);
48.}
49.fcloseall( );
50.return(0);
51.}
|
|