/* * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool * Generated by MATLAB(R) 9.9 and Signal Processing Toolbox 8.5. * Generated on: 06-Oct-2022 12:50:19 */ /* * 离散时间 FIR 滤波器(实数) * ---------------- * 滤波器结构 : 直接型 FIR * 滤波器长度 : 16 * 稳定 : 是 * 线性相位 : 是 (Type 2) */ /* General type conversion for MATLAB generated C-code */ //#include "tmwtypes.h" /* * Expected path to tmwtypes.h * D:\Program Files\R2020b\extern\include\tmwtypes.h */ /* * Warning - Filter coefficients were truncated to fit specified data type. * The resulting response may not match generated theoretical response. * Use the Filter Design & Analysis Tool to design accurate * single-precision filter coefficients. */ #include "math/fir.h" static const float Fir_Ceofs[16] = { -0.002180566313,-0.009224493057, -0.01853588782, -0.01606058516, 0.0186471995, 0.09345125407, 0.1863618642, 0.2517603636, 0.2517603636, 0.1863618642, 0.09345125407, 0.0186471995, -0.01606058516, -0.01853588782,-0.009224493057, -0.002180566313 }; void Fir_init(Fir_t *fir) { for (int i = 0; i < FIR_Ceof_Len; i++) { fir->X[0] = 0.0f; } fir->k = 0; } float Fir_Filter(Fir_t *fir, float in) { float out = 0; fir->X[fir->k] = in; for (int i = 1; i <= FIR_Ceof_Len; i++) { out += Fir_Ceofs[i-1] * fir->X[(i+fir->k) % FIR_Ceof_Len]; } fir->k = (fir->k + 1) % FIR_Ceof_Len; return out; }