1.4.2.12 DSP_FilterIIRBQ16 Function

Performs a single-pass IIR Biquad Filter.

Description

int16_t DSP_FilterIIRBQ16(int16_t Xin, PARM_EQUAL_FILTER *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 16-bits for the output. The delay register is stored as a 32-bit value for subsequent functions.

All values are fractional Q15 and 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 (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 *ptrFilterEQ;

PARM_EQUAL_FILTER 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(DataIn, ptrFilterEQ);

_// *** do something with the DataOut here_

}

C

int16_t DSP_FilterIIRBQ16 (int16_t Xin , PARM_EQUAL_FILTER * pFilter );