(1)高通与低通系数
#if LOWPASS
float32 B [FILTER_LEN] = {0.0625L, 0.25L, 0.375L, 0.25L, 0.0625L};
#elif HIGHPASS
float32 B [FILTER_LEN] = {0.0625L, -0.25L, 0.375L, -0.25L, 0.0625L};
#endif
(2)算法实现
FILTER_LEN = 5
变量定义:
float32 fir[FILTER_LEN];
float32 fir_temp,Y,Y_OUT;
FIR计算:
fir[0] = AdcResult.ADCRESULT1; //取ADC值
fir_temp = fir[4];
Y = B[4] * fir_temp; //系数乘法计算
fir[4] = fir[3]; //移位
fir_temp = fir[3];
Y = Y + B[3] * fir_temp; //累加
fir[3] = fir[2];
fir_temp = fir[2];
Y = Y + B[2] * fir_temp;
fir[2] = fir[1];
fir_temp = fir[1];
Y = Y + B[1] * fir_temp;
fir[1] = fir[0];
fir_temp = fir[0];
Y = Y + B[0] * fir_temp;
Y_OUT = Y; //FIR输出