1.4.2.15 DSP_FilterIIRBQ16_fast Function
Performs a single-pass IIR Biquad Filter.
Description
int16_t DSP_FilterIIRBQ16_fast(int16_t Xin, PARM_EQUAL_FILTER_16 *pFilter);
Calculates a single pass IIR biquad filter on Xin, and delivers the result as a 16-bit output. All math is performed using 16 bit instructions, with results rounded to 16-bits for the output. The delay register is stored as a 16-bit value for subsequent functions.
The function will saturate the results if maximum or minimum fractional values are exceeded. All values are fractional Q15 format.
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 (int16_t)
pFilter pointer to filter coef and delay structure
Returns
Sample output Y (int16_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_16 *ptrFilterEQ; PARM_EQUAL_FILTER_16 FilterEQ; uint16_t DataIn, DataOut; ptrFilterEQ = &FilterEQ; _// 48KHz sampling; 1 KHz bandpass filter; Q=0.9_ _// divide by 2 and convert to Q15_ _// b0 = 0.06761171785499065_ _// b1 = 0_ _// b2 = -0.06761171785499065_ _// a1 = -1.848823142275648_ _// a2 = 0.8647765642900187_ _// note all coefs are half value of original design, gain handled in algorithm_ ptrFiltEQ32->b[0]=0x0453; _// feed forward b0 coef_ ptrFiltEQ32->b[1]=0; _// feed forward b1 coef_ ptrFiltEQ32->b[2]=0xFBAD; _// 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]=0x89AD; _// feedback a1 coef_ ptrFiltEQ32->a[1]=0x3758; _// feedback a2 coef_ for (i=0;i<256;i++) { _// *** get some input data here_ DataIn32 = three_hundred_hz[i]; DataOut = DSP_FilterIIRBQ16_fast(DataIn, ptrFilterEQ); _// *** do something with the DataOut here_ }
C
int16_t DSP_FilterIIRBQ16_fast (int16_t Xin , PARM_EQUAL_FILTER_16 * pFilter );