1.4.2.18 DSP_FilterIIRBQ32 Function
Performs a high resolution single-pass IIR Biquad Filter.
Description
int32_t DSP_FilterIIRBQ32(int32_t Xin, PARM_EQUAL_FILTER_32 *pFilter);
Calculates a single pass IIR biquad filter on Xin, and delivers the result as a 16-bit output. All math is performed using 32 bit instructions, with results truncated to 32-bits for the output. The delay register is stored as a 32-bit value for subsequent functions.
All values are fractional Q31, see data structure for specifics.
Y = X(0)*b0 + (b1 * X(-1)) + (b2 * X(-2)) - (a1 * Y(-1)) - (a2 * Y(-2))
Preconditions
Delay register values should be initialized to zero.
Parameters
Xin input data element X (int32_t)
pFilter pointer to high resolution filter coef and delay structure
Returns
Sample output Y (int32_t)
Remarks
The delay register values should be initialized to zero prior to the first call to the function, they are updated each pass. A gain of 2 has been hard coded into the function. This implies that all coefs should be input at half value. This is purposeful, since many filter designs need a div2 to have each coef between the required -1
Example
PARM_EQUAL_FILTER_32 *ptrFiltEQ32; PARM_EQUAL_FILTER_32 FilterEQ32; int32_t DataIn32, DataOut32; ptrFiltEQ32 = &FilterEQ32; ptrFiltEQ32->Z[0]=0; ptrFiltEQ32->Z[1]=0; _// 1000 Hz Q= 0.9 BP filter design, 44.1K sampling_ _//_ _// b0 = 0.07311778239751009 forward_ _// b1 = 0_ _// b2 = -0.07311778239751009_ _// a1 = -1.8349811166056893 back_ _// a2 = 0.8537644352049799_ _// note all coefs are half value of original design, gain handled in algorithm_ ptrFiltEQ32->b[0]=0x04ADF635; _// feed forward b0 coef_ ptrFiltEQ32->b[1]=0; _// feed forward b1 coef_ ptrFiltEQ32->b[2]=0xFB5209CB; _// feed forward b2 coef_ _// note all coefs are half value of original design, gain handled in algorithm_ _// note subtract is handled in algorithm, so coefs go in at actual value_ ptrFiltEQ32->a[0]=0x8A8FAB5D; _// feedback a1 coef_ ptrFiltEQ32->a[1]=0x36A41395; _// feedback a2 coef_ for (i=0;i<256;i++) { _// *** get input data here_ DataIn32 = three_hundred_hz[i]; DataOut32 = DSP_FilterIIRBQ32(DataIn32, ptrFiltEQ32); _// *** do something with the DataOut32 here_ }
C
int32_t DSP_FilterIIRBQ32 (int32_t Xin , PARM_EQUAL_FILTER_32 * pFilter );