IIRBiQuadDirect

Applies a BiQuad cascade infinite impulse response (IIR) filter of the direct form I structure.

Syntax

Intel IPP style:

IppStatus ippsqIIRBiQuadDirect_32f(const Ipp32f* pSrc, Ipp32f* pDst, Ipp32u len, const Ipp32f* pTaps, Ipp32u numBq, Ipp32f* pDlyLine);

IppStatus ippsqIIRBiQuadDirectQ15_16s_RmSfs(const Ipp16s* pSrc, Ipp16s* pDst, Ipp32u len, const Ipp16s* pTaps, Ipp32u numBq, Ipp16s* pDlyLine, Ipp32s scaleFactor);

IppStatus ippsqIIRBiQuadDirectFastQ15_16s_RmSfs(const Ipp16s* pSrc, Ipp16s* pDst, Ipp32u len, const Ipp16s* pTaps, Ipp32u numBq, Ipp16s* pDlyLine, Ipp32s scaleFactor);

IppStatus ippsqIIRBiQuadDirectQ31_32s_RmSf(const Ipp32s* pSrc, Ipp32s* pDst, Ipp32u len, const Ipp32s* pTaps, Ipp32u numBq, Ipp32s* pDlyLine, Ipp32s scaleFactor);

IppStatus ippsqIIRBiQuadDirectFastQ31_32s_RmSf(const Ipp32s* pSrc, Ipp32s* pDst, Ipp32u len, const Ipp32s* pTaps, Ipp32u numBq, Ipp32s* pDlyLine, Ipp32s scaleFactor);

IppStatus ippsqIIRBiQuadDirectQ31Q63_32s64s_RmSf(const Ipp32s* pSrc, Ipp32s* pDst, Ipp32u len, const Ipp32s* pTaps, Ipp32u numBq, Ipp64s* pDlyLine, Ipp32s scaleFactor);

DSP style:

typedef struct {
    Ipp32u  numStages;
    Ipp32f *pState;
    Ipp32f *pCoeffs;
} ippsq_biquad_casd_df1_inst_f32;

void ippsq_biquad_cascade_df1_init_f32(ippsq_biquad_casd_df1_inst_f32 *S, uint8_t numStages, float32_t *pCoeffs, float32_t *pState);

void ippsq_biquad_cascade_df1_f32(const ippsq_biquad_casd_df1_inst_f32 *S, float32_t *pSrc, float32_t *pDst, uint32_t blockSize);

typedef struct {
    Ipp8s   numStages;
    Ipp16s *pState;
    Ipp16s *pCoeffs;
    Ipp8s   postShift;
} ippsq_biquad_casd_df1_inst_q15;

void ippsq_biquad_cascade_df1_init_q15(ippsq_biquad_casd_df1_inst_q15 *S, uint8_t numStages, q15_t *pCoeffs, q15_t *pState, int8_t postShift);

void ippsq_biquad_cascade_df1_q15(const ippsq_biquad_casd_df1_inst_q15 *S, q15_t *pSrc, q15_t *pDst, uint32_t blockSize);

void ippsq_biquad_cascade_df1_fast_q15(const ippsq_biquad_casd_df1_inst_q15 *S, q15_t *pSrc, q15_t *pDst, uint32_t blockSize);

typedef struct {
    Ipp32u  numStages;
    Ipp32s *pState;
    Ipp32s *pCoeffs;
    Ipp8u   postShift;
} ippsq_biquad_casd_df1_inst_q31;

void ippsq_biquad_cascade_df1_init_q31(ippsq_biquad_casd_df1_inst_q31 *S, uint8_t numStages, q31_t *pCoeffs, q31_t *pState, int8_t postShift);

void ippsq_biquad_cascade_df1_q31(const ippsq_biquad_casd_df1_inst_q31 *S, q31_t *pSrc, q31_t *pDst, uint32_t blockSize);

void ippsq_biquad_cascade_df1_fast_q31(const ippsq_biquad_casd_df1_inst_q31 *S, q31_t *pSrc, q31_t *pDst, uint32_t blockSize);

typedef struct {
    Ipp32u  numStages;
    Ipp64s *pState;
    Ipp32s *pCoeffs;
    Ipp8u   postShift;
} ippsq_biquad_cas_df1_32x64_ins_q31;

void ippsq_biquad_cas_df1_32x64_init_q31(ippsq_biquad_cas_df1_32x64_ins_q31 *S, uint8_t numStages, q31_t *pCoeffs, q63_t *pState, uint8_t postShift);

void ippsq_biquad_cas_df1_32x64_q31(const ippsq_biquad_cas_df1_32x64_ins_q31 *S, q31_t *pSrc, q31_t *pDst, uint32_t blockSize);

Include Files

ippsq.h

dsp.h

Parameters

pSrc

Pointer to the source vector.

pDst

Pointer to the destination vector.

len, blockSize

Number of elements in the source/destination vectors.

pTaps, pCoeffs

Pointer to the filter coefficients.

numBq, numStages

Number of biquad stages in a filter.

pDlyLine, pState

Pointer to the filter delay line.

scaleFactor, postShift

Value by which the accumulated result might be shifted.

Description

These functions apply a BiQuad cascade infinite impulse response (IIR) filter of the direct form I structure to the source vector. Direct form I is a direct implementation of the second order difference equation. The following figure demonstrates the direct form I structure of a biquad second-order IIR filter:

where

  • x[n] is a sample of the input signal

  • y[n] is a sample of the output signal

  • b0, b1, b2, a1, a2 are filter coefficients

The output signal is computed by the following formula:

y[n]=b0*x[n]+b1*x[n-1]+b2*x[n-2]+a1*y[n-1]+a2*y[n-2]

A biquad IIR filter is a cascade of second-order filters. The figure below shows the structure of the biquad filter with k cascades of second-order filters:

Both pSrc and pDst arrays contain len (blockSize for DSP) values.

The pDlyLine (pState for DSP) array specifies the delay line values. The number of elements in the array is 4*numBq (4*numStages for DSP). The delay line values are arranged in the array as follows:

x0,-1; x0,-2; y0,-1; y0,-2; x1,-1; x1,-2; y1,-1; y1,-2; ...xnumBq-1,-1; xnumBq-1,-2; ynumBq-1,-1; ynymBq-1,-2

A biquad IIR filter is defined by a cascade of biquads. The number of cascades of biquads is specified by the numBq (numStages for DSP) value. The 5*numBq-length (5*numStages-length for DSP) array pTaps (pCoeffs for DSP) specifies the taps arranged in the array as follows:

b0,0; b0,1; b0,2; b1,0; b1,1; b1,2;a1,1; a1,2; ...bnumBq-1,0; bnumBq-1,1; bnumBq-1,2; anymBq-1,1; anymBq-1,2

The scaleFactor (postShift for DSP) value is used to scale the accumulated integer result. The scaleFactor value can be obtained from postShift and vice versa by the following equations:

Q15: scaleFactor=15-postShift

Q15: scaleFactor=31-postShift

Intel IPP style: Functions perform filtering without initialization of the filter state structure. All required parameters are directly set in functions.

Function flavors with the_RmSf suffix perform rounding to minus and scaling.

Flavors with the _RmSf suffix perform rounding down, scaling, and saturation of the resulting value if it exceeds the data range.

DSP style: Each function type (f32, q15, q31, and 32x64_q31) has its own state structure, which must be initialized with the corresponding initialization function. The initialization function copies arguments into the state structure and sets the pState array to zero. The ippsq_biquad_cas_df1_32x64_q31 function performs high-precision biquad filtering as delay line values are stored in the 1.63 format.

Scaling, Truncation, Saturation

Intel IPP style:

Function Description
ippsqIIRBiQuadDirectQ15_16s_RmSfs

The pSrc, pDst, pTaps, and pDlyLine values are represented in Q15 format. The function uses a 64-bit internal accumulator in Q34.30 format, so it preserves full precision of intermediate calculations and avoids internal overflow. In the end, the function shifts the accumulator right by scaleFactor bits and saturates it in the [IPP_MIN_16S, IPP_MAX_16S] range.

ippsqIIRBiQuadDirectFastQ15_16s_RmSfs

The pSrc, pDst, pTaps, and pDlyLine values are represented in Q15 format. The function uses a 32-bit internal accumulator in Q2.30 format and provides only one guard bit. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by scaleFactor bits and saturates it in the [IPP_MIN_16S, IPP_MAX_16S] range.

ippsqIIRBiQuadDirectQ31_32s_RmSf

The pSrc, pDst, pTaps, and pDlyLine values are represented in Q31 format. The function uses a 64-bit internal accumulator in Q2.62 format and provides only one guard bit. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by scaleFactor bits and does not perform saturation.

ippsqIIRBiQuadDirectFastQ31_32s_RmSf

The pSrc, pDst, pTaps, and pDlyLine values are represented in Q31 format. The function uses a 32-bit internal accumulator in Q2.30 format. The function shifts right the result of multiplication of Q31 numbers, truncates it to Q2.30 format, and adds it to the accumulator. The function is not protected from internal overflow and provides less precision because it discards low 32 bits after multiplication. In the end, the function shifts the accumulator left by scaleFactor bits and does not perform saturation.

ippsqIIRBiQuadDirectQ31Q63_32s64s_RmSf

The pSrc, pDst, pTaps values are represented in Q31 format and pDlyLine is in Q63. The function uses a 64-bit internal accumulator in Q2.62 format and provides only one guard bit. Internal multiplication of Q31 numbers pSrc and pCoeffs results in a Q2.62 number; the function shifts right the result of multiplication of Q31 pCoeffs and Q63 pState, truncates it to Q2.62, and adds it to the accumulator. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by scaleFactor bits and does not perform saturation.

DSP style:

Function Description
ippsq_biquad_cascade_df1_q15

The pSrc, pDst, pCoeffs, and pState values are represented in Q15 format. The function uses a 64-bit internal accumulator in Q34.30 format, so it preserves full precision of intermediate calculations and avoids internal overflow. In the end, the function shifts the accumulator right by 15-postShift bits and saturates it in the [IPP_MIN_16S, IPP_MAX_16S] range.

ippsq_biquad_cascade_df1_fast_q15

The pSrc, pDst, pCoeffs, and pState values are represented in Q15 format. The function uses a 32-bit internal accumulator in Q2.30 format and provides only one guard bit. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by 15-postShift bits and saturates it in the [IPP_MIN_16S, IPP_MAX_16S] range.

ippsq_biquad_cascade_df1_q31

The pSrc, pDst, pCoeffs, and pState values are represented in Q31 format. The function uses a 64-bit internal accumulator in Q2.62 format and provides only one guard bit. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by 31-postShift bits and does not perform saturation.

ippsq_biquad_cascade_df1_fast_q31

The pSrc, pDst, pCoeffs, and pState values are represented in Q31 format. The function uses a 32-bit internal accumulator in Q2.30 format. The function shifts right the result of multiplication of Q31 numbers, truncates it to Q2.30 format, and adds it to the accumulator. The function is not protected from internal overflow and provides less precision because it discards low 32 bits after multiplication. In the end, the function shifts the accumulator left by postShift+1 bits and does not perform saturation.

ippsq_biquad_cas_df1_32x64_q31

The pSrc, pDst, pCoeffs values are represented in Q31 format and pState is in Q63. The function uses a 64-bit internal accumulator in Q2.62 format and provides only one guard bit. Internal multiplication of Q31 numbers pSrc and pCoeffs results in a Q2.62 number; the function shifts right the result of multiplication of Q31 pCoeffs and Q63 pState, truncates it to Q2.62, and adds it to the accumulator. The function is not protected from internal overflow. In the end, the function shifts the accumulator right by postShift+1 bits and does not perform saturation.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error when any of the specified pointers is NULL.
For more complete information about compiler optimizations, see our Optimization Notice.