LIBDSP Version 4.1.9
LIBDSP Software Library
Loading...
Searching...
No Matches
tpt_biquad_cascade_df1_32x64_q31.c File Reference
#include "tpt_math.h"
Include dependency graph for tpt_biquad_cascade_df1_32x64_q31.c:

Functions

void tpt_biquad_cascade_df1_32x64_q31 (q31_t *aOutData, const tpt_biquad_cascade_df1_32x64_q31_t *aFilter, const q31_t *aInData, uint32_t aCount)
 Processing function for the Q31 Biquad cascade 32x64 filter.

Function Documentation

◆ tpt_biquad_cascade_df1_32x64_q31()

void tpt_biquad_cascade_df1_32x64_q31 ( q31_t * aOutData,
const tpt_biquad_cascade_df1_32x64_q31_t * aFilter,
const q31_t * aInData,
uint32_t aCount )

Processing function for the Q31 Biquad cascade 32x64 filter.

Algorithm
Each Biquad stage implements a second order filter using the difference equation: pre> y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] /pre> A Direct Form I algorithm is used with 5 coefficients and 4 state variables per stage.
Single Biquad filter stage
Coefficients b0, b1 and b2 multiply the input signal code>x[n] and are referred to as the feedforward coefficients. Coefficients a1 and a2 multiply the output signal code>y[n] and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools use the difference equation pre> y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] - a1 * y[n-1] - a2 * y[n-2] /pre> In this case the feedback coefficients a1 and code>a2 must be negated when used with the CMSIS DSP Library.
Higher order filters are realized as a cascade of second order sections. code>numStages refers to the number of second order stages used. For example, an 8th order filter would be realized with code>numStages=4 second order stages.
8th order filter using a cascade of Biquad
stages" A 9th order filter would be realized with <code>numStages=5</code> second order stages with the coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>). @par The <code>pState</code> points to state variables array. Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1] /code> and <code>y[n-2]</code> and each state variable in 1.63 format to improve precision. The state variables are arranged in the array as: pre> {x[n-1], x[n-2], y[n-1], y[n-2]} /pre> @par The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. The state array has a total length of <code>4*numStages</code> values of data in 1.63 format. The state variables are updated after each block of data is processed, the coefficients are untouched. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter. Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. @par Init Function There is also an associated initialization function which performs the following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. To do this manually without calling the init function, assign the follow subfields of the instance structure: numStages, pCoeffs, postShift, pState. Also set all of the values in pState to zero. @par Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure must be manually initialized. Set the values in the state buffer to zeros before static initialization. For example, to statically initialize the filter instance structure use pre> arm_biquad_cas_df1_32x64_ins_q31 S1 = {numStages, pState, pCoeffs, postShift}; /pre> where <code>numStages</code> is the number of Biquad stages in the filter; code>pState</code> is the address of the state buffer; code>pCoeffs</code> is the address of the coefficient buffer; code>postShift</code> shift to be applied which is described in detail below. @par Fixed-Point Behavior Care must be taken while using Biquad Cascade 32x64 filter function. Following issues must be considered: - Scaling of coefficients - Filter gain - Overflow and saturation @par Filter coefficients are represented as fractional values and restricted to lie in the range <code>[-1 +1)</code>. The processing function has an additional scaling parameter <code>postShift</code> which allows the filter coefficients to exceed the range <code>[+1 -1)</code>. At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits. @image html BiquadPostshift.gif "Fixed-point Biquad with shift by postShift bits after accumulator" This essentially scales the filter coefficients by 2^postShift. For example, to realize the coefficients pre> {1.5, -0.8, 1.2, 1.6, -0.9} /pre> set the Coefficient array to: pre> {0.75, -0.4, 0.6, 0.8, -0.45} /pre> and set postShift=1
The second thing to keep in mind is the gain through the filter. The frequency response of a Biquad filter is a function of its coefficients. It is possible for the gain through the filter to exceed 1.0 meaning that the filter increases the amplitude of certain frequencies. This means that an input signal with amplitude < 1.0 may result in an output > 1.0 and these are saturated or overflowed based on the implementation of the filter. To avoid this behavior the filter needs to be scaled down such that its peak gain < 1.0 or the input signal must be scaled down so that the combination of input and filter are never overflowed.
he third item to consider is the overflow and saturation behavior of the fixed-point Q31 version. This is described in the function specific documentation below.