LIBML  Version 3.2.4
LIBML DSP Software Library
Functions
Finite Impulse Response (FIR) Decimator
Collaboration diagram for Finite Impulse Response (FIR) Decimator:

Functions

void tpt_fir_decimate_f32 (f32_t *aOutData, const tpt_fir_decimate_f32_t *aFilter, f32_t *aInData, uint32_t aCount)
 Processing function for floating-point FIR decimator. More...
 
void tpt_fir_decimate_fast_q15 (q15_t *aOutData, const tpt_fir_decimate_q15_t *aFilter, q15_t *aInData, uint32_t aCount)
 Function for the q15 Decimator FIR filter. More...
 
void tpt_fir_decimate_fast_q31 (q31_t *aOutData, const tpt_fir_decimate_q31_t *aFilter, q31_t *aInData, uint32_t aCount)
 Function for the q31 Decimator FIR filter. More...
 
void tpt_fir_decimate_init_f32 (tpt_fir_decimate_f32_t *aFilter, uint32_t aTaps, uint32_t M, f32_t *aCoeffs, f32_t *aState, uint32_t aCount)
 Initialization function for the floating-point FIR decimator. More...
 
void tpt_fir_decimate_init_q15 (tpt_fir_decimate_q15_t *aFilter, uint32_t aTaps, uint32_t M, q15_t *aCoeffs, q15_t *aState, uint32_t aCount)
 Initialization function for the Q15 FIR decimator. More...
 
void tpt_fir_decimate_init_q31 (tpt_fir_decimate_q31_t *aFilter, uint32_t aTaps, uint32_t M, q31_t *aCoeffs, q31_t *aState, uint32_t aCount)
 Initialization function for the Q31 FIR decimator. More...
 
void tpt_fir_decimate_q15 (q15_t *aOutData, const tpt_fir_decimate_q15_t *aFilter, q15_t *aInData, uint32_t aCount)
 Processing function for the Q15 FIR decimator. More...
 
void tpt_fir_decimate_q31 (q31_t *aOutData, const tpt_fir_decimate_q31_t *aFilter, q31_t *aInData, uint32_t aCount)
 Processing function for the Q31 FIR decimator. More...
 

Detailed Description

These functions combine an FIR filter together with a decimator. They are used in multirate systems for reducing the sample rate of a signal without introducing aliasing distortion. Conceptually, the functions are equivalent to the block diagram below:

"Components included in the FIR Decimator functions" When decimating by a factor of M, the signal should be prefiltered by a lowpass filter with a normalized cutoff frequency of 1/M in order to prevent aliasing distortion. The user of the function is responsible for providing the filter coefficients.

The FIR decimator functions provided in the CMSIS DSP Library combine the FIR filter and the decimator in an efficient manner. Instead of calculating all of the FIR filter outputs and discarding M-1 out of every M, only the samples output by the decimator are computed. The functions operate on blocks of input and output data. pSrc points to an array of blockSize input values and pDst points to an array of blockSize/M output values. In order to have an integer number of output samples blockSize must always be a multiple of the decimation factor M.

The library provides separate functions for Q15, Q31 and floating-point data types.

Algorithm:
The FIR portion of the algorithm uses the standard form filter:
      y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[aTaps-1]
      * x[n-aTaps+1]
  
where, b[n] are the filter coefficients.
The aCoeffs points to a coefficient array of aCount aTaps. Coefficients are stored in time reversed order.
      {b[aTaps-1], b[aTaps-2], b[N-2], ..., b[1], b[0]}
  
pState points to a state array of aCount aTaps + aCount - 1. Samples in the state buffer are stored in the order:
      {x[n-aTaps+1], x[n-aTaps], x[n-aTaps-1], x[n-aTaps-2]....x[0],
      x[1], ..., x[aCount-1]}
  
The state variables are updated after each block of data is processed, the coefficients are untouched.
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 array should be allocated separately. There are separate instance structure declarations for each of the 3 supported data types.
Initialization Functions
There is also an associated initialization function for each data type. The initialization function performs the following operations:
  • Sets the values of the internal structure fields.
  • Zeros out the values in the state buffer.
  • Checks to make sure that the aCount of the input is a multiple of the decimation factor. To do this manually without calling the init function, assign the follow subfields of the instance structure: aTaps, aCoeffs, M (decimation factor), aState. 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. The code below statically initializes each of the 3 different data type filter instance structures
      tpt_fir_decimate_f32_t aFilter = {M, aTaps, aCoeffs, aState};
      tpt_fir_decimate_q31_t aFilter = {M, aTaps, aCoeffs, aState};
      tpt_fir_decimate_q15_t aFilter = {M, aTaps, aoeffs, aState};
  
where M is the decimation factor; aTaps is the number of filter coefficients in the filter; aCoeffs is the address of the coefficient buffer; aState is the address of the state buffer. Be sure to set the values in the state buffer to zeros when doing static initialization.
Fixed-Point Behavior
Care must be taken when using the fixed-point versions of the FIR decimate filter functions. In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. Refer to the function specific documentation below for usage guidelines.

Function Documentation

◆ tpt_fir_decimate_f32()

void tpt_fir_decimate_f32 ( f32_t aOutData,
const tpt_fir_decimate_f32_t aFilter,
f32_t aInData,
uint32_t  aCount 
)

Processing function for floating-point FIR decimator.

Parameters
[out]aOutDatapoints to the block of output data
[in]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aInDatapoints to the block of input data
[in]aCountnumber of samples to process

◆ tpt_fir_decimate_fast_q15()

void tpt_fir_decimate_fast_q15 ( q15_t aOutData,
const tpt_fir_decimate_q15_t aFilter,
q15_t aInData,
uint32_t  aCount 
)

Function for the q15 Decimator FIR filter.

Parameters
[out]aOutDatapoints to the output block data.
[in]aFilterpoints to an instance of the Decimator FIR structure.
[in]aInDatapoints to the input block data.
[in]aCountnumber of the aCount.

◆ tpt_fir_decimate_fast_q31()

void tpt_fir_decimate_fast_q31 ( q31_t aOutData,
const tpt_fir_decimate_q31_t aFilter,
q31_t aInData,
uint32_t  aCount 
)

Function for the q31 Decimator FIR filter.

Parameters
[out]aOutDatapoints to the output block data.
[in]aFilterpoints to an instance of the Decimator FIR structure.
[in]aInDatapoints to the input block data.
[in]aCountnumber of the aCount.

◆ tpt_fir_decimate_init_f32()

void tpt_fir_decimate_init_f32 ( tpt_fir_decimate_f32_t aFilter,
uint32_t  aTaps,
uint32_t  M,
f32_t aCoeffs,
f32_t aState,
uint32_t  aCount 
)

Initialization function for the floating-point FIR decimator.

Parameters
[in,out]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aTapsnumber of coefficients in the filter
[in]Mdecimation factor
[in]aCoeffspoints to the filter coefficients
[in]aStatepoints to the state buffer
[in]aCountnumber of input samples to process per call

◆ tpt_fir_decimate_init_q15()

void tpt_fir_decimate_init_q15 ( tpt_fir_decimate_q15_t aFilter,
uint32_t  aTaps,
uint32_t  M,
q15_t aCoeffs,
q15_t aState,
uint32_t  aCount 
)

Initialization function for the Q15 FIR decimator.

Parameters
[in,out]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aTapsnumber of coefficients in the filter
[in]Mdecimation factor
[in]aCoeffspoints to the filter coefficients
[in]aStatepoints to the state buffer
[in]aCountnumber of input samples to process per call

◆ tpt_fir_decimate_init_q31()

void tpt_fir_decimate_init_q31 ( tpt_fir_decimate_q31_t aFilter,
uint32_t  aTaps,
uint32_t  M,
q31_t aCoeffs,
q31_t aState,
uint32_t  aCount 
)

Initialization function for the Q31 FIR decimator.

Parameters
[in,out]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aTapsnumber of coefficients in the filter
[in]Mdecimation factor
[in]aCoeffspoints to the filter coefficients
[in]aStatepoints to the state buffer
[in]aCountnumber of input samples to process per call

◆ tpt_fir_decimate_q15()

void tpt_fir_decimate_q15 ( q15_t aOutData,
const tpt_fir_decimate_q15_t aFilter,
q15_t aInData,
uint32_t  aCount 
)

Processing function for the Q15 FIR decimator.

Parameters
[out]aOutDatapoints to the block of output data
[in]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aInDatapoints to the block of input data
[in]aCountnumber of samples to process

◆ tpt_fir_decimate_q31()

void tpt_fir_decimate_q31 ( q31_t aOutData,
const tpt_fir_decimate_q31_t aFilter,
q31_t aInData,
uint32_t  aCount 
)

Processing function for the Q31 FIR decimator.

Parameters
[out]aOutDatapoints to the block of output data
[in]aFilterpoints to an instance of the floating-point FIR decimator structure
[in]aInDatapoints to the block of input data
[in]aCountnumber of samples to process