#include "math.h"
#define pi 3.14
#define fs 500
#define FIR_N 20
float An[21]= {
-0.001088760105017,
-0.002745405423523,
0.005553074688913,
0.003845842298928,
-0.021081289865066,
0.007532145808243,
0.047873859849196,
-0.059289535253658,
-0.074633752327147,
0.299872616508739,
0.585937500000000,
0.299872616508739,
-0.074633752327147,
-0.059289535253658,
0.047873859849196,
0.007532145808243,
-0.021081289865066,
0.003845842298928,
0.005553074688913,
-0.002745405423523,
-0.001088760105017,
};
float FIR(float) ;
main()
{
int i;
float a,Filter_data[fs];
while(1)
{
for(i=0;i<fs;i++)
{
a = cos(2*pi*80*i/fs) + cos(2*pi*200*i/fs);
Filter_data[i] = FIR(a);
}
}
}
float FIR(float DATA)//FIR滤波函数
{
static float Xn[FIR_N];
float Sum;
int i;
Sum = 0.0;
for( i=FIR_N ; i>0 ; i-- )
{
Xn[i] = Xn[i-1];
}
Xn[0] = DATA ;
for (i=0;i<FIR_N;i++)
{
Sum = Sum + ( Xn[i]*An[i] );//输入乘累加
}
return(Sum);
}
|