- 设计滤波系数
/* * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool * Generated by MATLAB(R) 9.0 and the Signal Processing Toolbox 7.2. * Generated on: 27-Nov-2019 07:42:47 */ /* * Discrete-Time IIR Filter (real) * ------------------------------- * Filter Structure : Direct-Form II * Numerator Length : 7 * Denominator Length : 7 * Stable : Yes * Linear Phase : No */ /* General type conversion for MATLAB generated C-code */ #include "tmwtypes.h" /* * Expected path to tmwtypes.h * C:\Program Files\MATLAB\R2016a\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. */ const int NL = 7; const real32_T NUM[7] = { 0.004106325097, 0.02463795058, 0.06159487367, 0.08212649822, 0.06159487367, 0.02463795058, 0.004106325097 }; const int DL = 7; const real32_T DEN[7] = { 1, -2.021385193, 2.312567234, -1.521253347, 0.6202822328, -0.1416414529, 0.01423505601 };C代码实现Butterworlth滤波系数数组定义
float FACTOR_B[] = {0.004106325097, 0.02463795058, 0.06159487367, 0.08212649822, 0.06159487367, 0.02463795058, 0.004106325097}; float FACTOR_A[] = {1, -2.021385193, 2.312567234, -1.521253347, 0.6202822328, -0.1416414529, 0.01423505601};Butterworlth数据结构
typedef struct { float xBuffer[FACTOR_NUMBER]; float yBuffer[FACTOR_NUMBER]; }BUTTER_WORTH_BUFFER;Butterworth算法实现
static BUTTER_WORTH_BUFFER s_ecgFilter; #define FACTOR_NUMBER 7 uint16_t buterworlthFilter(uint16_t x) { uint32_t i; //运算之前Buf向前移动一个位置,以保存之前Buf的数据; for(i=FACTOR_NUMBER-1; i>0;i--) { s_ecgFilter.yBuffer[i] = s_ecgFilter.yBuffer[i-1]; s_ecgFilter.xBuffer[i] = s_ecgFilter.xBuffer[i-1]; } s_ecgFilter.xBuffer[0] = x; s_ecgFilter.yBuffer[0] = 0; for(i=1;i关注打赏