这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » FIR算法C语言实现

共1条 1/1 1 跳转至

FIR算法C语言实现

工程师
2014-08-15 13:58:57     打赏

(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输出


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]