Biquad Cascade IIR Filters Using a Direct Form II Transposed Structure

void riscv_biquad_cascade_df2T_f16(const riscv_biquad_cascade_df2T_instance_f16 *S, const float16_t *pSrc, float16_t *pDst, uint32_t blockSize)

void riscv_biquad_cascade_df2T_f32(const riscv_biquad_cascade_df2T_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, uint32_t blockSize)

void riscv_biquad_cascade_df2T_f64(const riscv_biquad_cascade_df2T_instance_f64 *S, const float64_t *pSrc, float64_t *pDst, uint32_t blockSize)

void riscv_biquad_cascade_df2T_init_f16(riscv_biquad_cascade_df2T_instance_f16 *S, uint8_t numStages, const float16_t *pCoeffs, float16_t *pState)

void riscv_biquad_cascade_df2T_init_f32(riscv_biquad_cascade_df2T_instance_f32 *S, uint8_t numStages, const float32_t *pCoeffs, float32_t *pState)

void riscv_biquad_cascade_df2T_init_f64(riscv_biquad_cascade_df2T_instance_f64 *S, uint8_t numStages, const float64_t *pCoeffs, float64_t *pState)

void riscv_biquad_cascade_stereo_df2T_f16(const riscv_biquad_cascade_stereo_df2T_instance_f16 *S, const float16_t *pSrc, float16_t *pDst, uint32_t blockSize)

void riscv_biquad_cascade_stereo_df2T_f32(const riscv_biquad_cascade_stereo_df2T_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, uint32_t blockSize)

void riscv_biquad_cascade_stereo_df2T_init_f16(riscv_biquad_cascade_stereo_df2T_instance_f16 *S, uint8_t numStages, const float16_t *pCoeffs, float16_t *pState)

void riscv_biquad_cascade_stereo_df2T_init_f32(riscv_biquad_cascade_stereo_df2T_instance_f32 *S, uint8_t numStages, const float32_t *pCoeffs, float32_t *pState)
 group BiquadCascadeDF2T
This set of functions implements arbitrary order recursive (IIR) filters using a transposed direct form II structure. The filters are implemented as a cascade of second order Biquad sections. These functions provide a slight memory savings as compared to the direct form I Biquad filter functions. Only floatingpoint data is supported.
This function operate on blocks of input and output data and each call to the function processes
blockSize
samples through the filter.pSrc
points to the array of input data andpDst
points to the array of output data. Both arrays containblockSize
values. Algorithm
Each Biquad stage implements a second order filter using the difference equation: where d1 and d2 represent the two state values.
A Biquad filter using a transposed Direct Form II structure is shown below.
Coefficients
b0, b1, and b2
multiply the input signalx[n]
and are referred to as the feedforward coefficients. Coefficientsa1
anda2
multiply the output signaly[n]
and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools flip the sign of the feedback coefficients: In this case the feedback coefficientsa1
anda2
must be negated when used with the NMSIS DSP Library.Higher order filters are realized as a cascade of second order sections.
numStages
refers to the number of second order stages used. For example, an 8th order filter would be realized withnumStages=4
second order stages. A 9th order filter would be realized withnumStages=5
second order stages with the coefficients for one of the stages configured as a first order filter (b2=0
anda2=0
).pState
points to the state variable array. Each Biquad stage has 2 state variablesd1
andd2
. The state variables are arranged in thepState
array as: whered1x
refers to the state variables for the first Biquad andd2x
refers to the state variables for the second Biquad. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.The NMSIS library contains Biquad filters in both Direct Form I and transposed Direct Form II. The advantage of the Direct Form I structure is that it is numerically more robust for fixedpoint data types. That is why the Direct Form I structure supports Q15 and Q31 data types. The transposed Direct Form II structure, on the other hand, requires a wide dynamic range for the state variables
d1
andd2
. Because of this, the NMSIS library only has a floatingpoint version of the Direct Form II Biquad. The advantage of the Direct Form II Biquad is that it requires half the number of state variables, 2 rather than 4, per Biquad stage. 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.
 Init Functions
There is also an associated initialization function. The initialization function performs 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, pState. Also set all of the values in pState to zero.
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 instance structure use where
numStages
is the number of Biquad stages in the filter;pState
is the address of the state buffer.pCoeffs
is the address of the coefficient buffer;
Functions

void riscv_biquad_cascade_df2T_f16(const riscv_biquad_cascade_df2T_instance_f16 *S, const float16_t *pSrc, float16_t *pDst, uint32_t blockSize)
Processing function for the floatingpoint transposed direct form II Biquad cascade filter.
 Parameters
S – [in] points to an instance of the filter data structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
blockSize – [in] number of samples to process
 Returns
none

void riscv_biquad_cascade_df2T_f32(const riscv_biquad_cascade_df2T_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, uint32_t blockSize)
Processing function for the floatingpoint transposed direct form II Biquad cascade filter.
 Parameters
S – [in] points to an instance of the filter data structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
blockSize – [in] number of samples to process
 Returns
none

void riscv_biquad_cascade_df2T_f64(const riscv_biquad_cascade_df2T_instance_f64 *S, const float64_t *pSrc, float64_t *pDst, uint32_t blockSize)
Processing function for the floatingpoint transposed direct form II Biquad cascade filter.
 Parameters
S – [in] points to an instance of the filter data structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
blockSize – [in] number of samples to process
 Returns
none

void riscv_biquad_cascade_df2T_init_f16(riscv_biquad_cascade_df2T_instance_f16 *S, uint8_t numStages, const float16_t *pCoeffs, float16_t *pState)
Initialization function for the floatingpoint transposed direct form II Biquad cascade filter.
For Neon version, this array is bigger. If numstages = 4x + y, then the array has size: 32*x + 5*y and it must be initialized using the function riscv_biquad_cascade_df2T_compute_coefs_f16 which is taking the standard array coefficient as parameters.
 Coefficient and State Ordering
The coefficients are stored in the array
pCoeffs
in the following order in the not Neon version.where
b1x
anda1x
are the coefficients for the first stage,b2x
anda2x
are the coefficients for the second stage, and so on. ThepCoeffs
array contains a total of5*numStages
values.
But, an array of 8*numstages is a good approximation.
Then, the initialization can be done with:
 In this example, neonCoefs is a bigger array of size 8 * numStages.
coefs is the standard array:
The
pState
is a pointer to state array. Each Biquad stage has 2 state variablesd1,
andd2
. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.
 Parameters
S – [inout] points to an instance of the filter data structure.
numStages – [in] number of 2nd order stages in the filter.
pCoeffs – [in] points to the filter coefficients.
pState – [in] points to the state buffer.
 Returns
none

void riscv_biquad_cascade_df2T_init_f32(riscv_biquad_cascade_df2T_instance_f32 *S, uint8_t numStages, const float32_t *pCoeffs, float32_t *pState)
Initialization function for the floatingpoint transposed direct form II Biquad cascade filter.
For Neon version, this array is bigger. If numstages = 4x + y, then the array has size: 32*x + 5*y and it must be initialized using the function riscv_biquad_cascade_df2T_compute_coefs_f32 which is taking the standard array coefficient as parameters.
 Coefficient and State Ordering
The coefficients are stored in the array
pCoeffs
in the following order in the not Neon version.where
b1x
anda1x
are the coefficients for the first stage,b2x
anda2x
are the coefficients for the second stage, and so on. ThepCoeffs
array contains a total of5*numStages
values.
But, an array of 8*numstages is a good approximation.
Then, the initialization can be done with:
 In this example, computedCoefs is a bigger array of size 8 * numStages.
coefs is the standard array:
The
pState
is a pointer to state array. Each Biquad stage has 2 state variablesd1,
andd2
. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.
 Parameters
S – [inout] points to an instance of the filter data structure.
numStages – [in] number of 2nd order stages in the filter.
pCoeffs – [in] points to the filter coefficients.
pState – [in] points to the state buffer.
 Returns
none

void riscv_biquad_cascade_df2T_init_f64(riscv_biquad_cascade_df2T_instance_f64 *S, uint8_t numStages, const float64_t *pCoeffs, float64_t *pState)
Initialization function for the floatingpoint transposed direct form II Biquad cascade filter.
 Coefficient and State Ordering
The coefficients are stored in the array
pCoeffs
in the following order:where
b1x
anda1x
are the coefficients for the first stage,b2x
anda2x
are the coefficients for the second stage, and so on. ThepCoeffs
array contains a total of5*numStages
values.The
pState
is a pointer to state array. Each Biquad stage has 2 state variablesd1,
andd2
. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.
 Parameters
S – [inout] points to an instance of the filter data structure
numStages – [in] number of 2nd order stages in the filter
pCoeffs – [in] points to the filter coefficients
pState – [in] points to the state buffer
 Returns
none

void riscv_biquad_cascade_stereo_df2T_f16(const riscv_biquad_cascade_stereo_df2T_instance_f16 *S, const float16_t *pSrc, float16_t *pDst, uint32_t blockSize)
Processing function for the floatingpoint transposed direct form II Biquad cascade filter.
Processing function for the floatingpoint transposed direct form II Biquad cascade filter. 2 channels.
 Parameters
S – [in] points to an instance of the filter data structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
blockSize – [in] number of samples to process
 Returns
none

void riscv_biquad_cascade_stereo_df2T_f32(const riscv_biquad_cascade_stereo_df2T_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, uint32_t blockSize)
Processing function for the floatingpoint transposed direct form II Biquad cascade filter.
Processing function for the floatingpoint transposed direct form II Biquad cascade filter. 2 channels.
 Parameters
S – [in] points to an instance of the filter data structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
blockSize – [in] number of samples to process
 Returns
none

void riscv_biquad_cascade_stereo_df2T_init_f16(riscv_biquad_cascade_stereo_df2T_instance_f16 *S, uint8_t numStages, const float16_t *pCoeffs, float16_t *pState)
Initialization function for the floatingpoint transposed direct form II Biquad cascade filter.
 Coefficient and State Ordering
The coefficients are stored in the array
pCoeffs
in the following order:where
b1x
anda1x
are the coefficients for the first stage,b2x
anda2x
are the coefficients for the second stage, and so on. ThepCoeffs
array contains a total of5*numStages
values.The
pState
is a pointer to state array. Each Biquad stage has 2 state variablesd1,
andd2
for each channel. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.
 Parameters
S – [inout] points to an instance of the filter data structure.
numStages – [in] number of 2nd order stages in the filter.
pCoeffs – [in] points to the filter coefficients.
pState – [in] points to the state buffer.
 Returns
none

void riscv_biquad_cascade_stereo_df2T_init_f32(riscv_biquad_cascade_stereo_df2T_instance_f32 *S, uint8_t numStages, const float32_t *pCoeffs, float32_t *pState)
Initialization function for the floatingpoint transposed direct form II Biquad cascade filter.
 Coefficient and State Ordering
The coefficients are stored in the array
pCoeffs
in the following order:where
b1x
anda1x
are the coefficients for the first stage,b2x
anda2x
are the coefficients for the second stage, and so on. ThepCoeffs
array contains a total of5*numStages
values.The
pState
is a pointer to state array. Each Biquad stage has 2 state variablesd1,
andd2
for each channel. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of2*numStages
values. The state variables are updated after each block of data is processed; the coefficients are untouched.
 Parameters
S – [inout] points to an instance of the filter data structure.
numStages – [in] number of 2nd order stages in the filter.
pCoeffs – [in] points to the filter coefficients.
pState – [in] points to the state buffer.
 Returns
none