CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details
Dependents: K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more
Finite Impulse Response (FIR) Filters
[Filtering Functions]
This set of functions implements Finite Impulse Response (FIR) filters for Q7, Q15, Q31, and floating-point data types. More...
Functions | |
void | arm_fir_f32 (const arm_fir_instance_f32 *S, float32_t *pSrc, float32_t *pDst, uint32_t blockSize) |
Processing function for the floating-point FIR filter. | |
void | arm_fir_fast_q15 (const arm_fir_instance_q15 *S, q15_t *pSrc, q15_t *pDst, uint32_t blockSize) |
Processing function for the fast Q15 FIR filter. | |
void | arm_fir_fast_q31 (const arm_fir_instance_q31 *S, q31_t *pSrc, q31_t *pDst, uint32_t blockSize) |
Processing function for the fast Q31 FIR filter. | |
void | arm_fir_init_f32 (arm_fir_instance_f32 *S, uint16_t numTaps, float32_t *pCoeffs, float32_t *pState, uint32_t blockSize) |
Initialization function for the floating-point FIR filter. | |
arm_status | arm_fir_init_q15 (arm_fir_instance_q15 *S, uint16_t numTaps, q15_t *pCoeffs, q15_t *pState, uint32_t blockSize) |
Initialization function for the Q15 FIR filter. | |
void | arm_fir_init_q31 (arm_fir_instance_q31 *S, uint16_t numTaps, q31_t *pCoeffs, q31_t *pState, uint32_t blockSize) |
Initialization function for the Q31 FIR filter. | |
void | arm_fir_init_q7 (arm_fir_instance_q7 *S, uint16_t numTaps, q7_t *pCoeffs, q7_t *pState, uint32_t blockSize) |
Initialization function for the Q7 FIR filter. | |
void | arm_fir_q15 (const arm_fir_instance_q15 *S, q15_t *pSrc, q15_t *pDst, uint32_t blockSize) |
Processing function for the Q15 FIR filter. | |
void | arm_fir_q31 (const arm_fir_instance_q31 *S, q31_t *pSrc, q31_t *pDst, uint32_t blockSize) |
Processing function for the Q31 FIR filter. | |
void | arm_fir_q7 (const arm_fir_instance_q7 *S, q7_t *pSrc, q7_t *pDst, uint32_t blockSize) |
Processing function for the Q7 FIR filter. |
Detailed Description
This set of functions implements Finite Impulse Response (FIR) filters for Q7, Q15, Q31, and floating-point data types.
Fast versions of Q15 and Q31 are also provided. The functions operate on blocks of input and output data and each call to the function processes blockSize
samples through the filter. pSrc
and pDst
points to input and output arrays containing blockSize
values.
- Algorithm:
- The FIR filter algorithm is based upon a sequence of multiply-accumulate (MAC) operations. Each filter coefficient
b[n]
is multiplied by a state variable which equals a previous input samplex[n]
.y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1]
Finite Impulse Response filter
pCoeffs
points to a coefficient array of sizenumTaps
. Coefficients are stored in time reversed order.
{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
pState
points to a state array of sizenumTaps + blockSize - 1
. Samples in the state buffer are stored in the following order.
{x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]}
- Note that the length of the state buffer exceeds the length of the coefficient array by
blockSize-1
. The increased state buffer length allows circular addressing, which is traditionally used in the FIR filters, to be avoided and yields a significant speed improvement. 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 arrays cannot be shared. There are separate instance structure declarations for each of the 4 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.
- 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. The code below statically initializes each of the 4 different data type filter instance structures
arm_fir_instance_f32 S = {numTaps, pState, pCoeffs}; arm_fir_instance_q31 S = {numTaps, pState, pCoeffs}; arm_fir_instance_q15 S = {numTaps, pState, pCoeffs}; arm_fir_instance_q7 S = {numTaps, pState, pCoeffs};
where numTaps
is the number of filter coefficients in the filter; pState
is the address of the state buffer; pCoeffs
is the address of the coefficient buffer.
- Fixed-Point Behavior
- Care must be taken when using the fixed-point versions of the FIR 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
void arm_fir_f32 | ( | const arm_fir_instance_f32 * | S, |
float32_t * | pSrc, | ||
float32_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the floating-point FIR filter.
- Parameters:
-
[in] *S points to an instance of the floating-point FIR filter structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block of output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Definition at line 124 of file arm_fir_f32.c.
void arm_fir_fast_q15 | ( | const arm_fir_instance_q15 * | S, |
q15_t * | pSrc, | ||
q15_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the fast Q15 FIR filter.
- Parameters:
-
[in] *S points to an instance of the Q15 FIR filter structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block of output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Scaling and Overflow Behavior:
- This fast version uses a 32-bit accumulator with 2.30 format. The accumulator maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around and distorts the result. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits. The 2.30 accumulator is then truncated to 2.15 format and saturated to yield the 1.15 result.
- Refer to the function
arm_fir_q15()
for a slower implementation of this function which uses 64-bit accumulation to avoid wrap around distortion. Both the slow and the fast versions use the same instance structure. Use the functionarm_fir_init_q15()
to initialize the filter structure.
Definition at line 62 of file arm_fir_fast_q15.c.
void arm_fir_fast_q31 | ( | const arm_fir_instance_q31 * | S, |
q31_t * | pSrc, | ||
q31_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the fast Q31 FIR filter.
- Parameters:
-
[in] *S points to an instance of the Q31 structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Scaling and Overflow Behavior:
- This function is optimized for speed at the expense of fixed-point precision and overflow protection. The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format. These intermediate results are added to a 2.30 accumulator. Finally, the accumulator is saturated and converted to a 1.31 result. The fast version has the same overflow behavior as the standard version and provides less precision since it discards the low 32 bits of each multiplication result. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits.
- Refer to the function
arm_fir_q31()
for a slower implementation of this function which uses a 64-bit accumulator to provide higher precision. Both the slow and the fast versions use the same instance structure. Use the functionarm_fir_init_q31()
to initialize the filter structure.
Definition at line 63 of file arm_fir_fast_q31.c.
void arm_fir_init_f32 | ( | arm_fir_instance_f32 * | S, |
uint16_t | numTaps, | ||
float32_t * | pCoeffs, | ||
float32_t * | pState, | ||
uint32_t | blockSize | ||
) |
Initialization function for the floating-point FIR filter.
- Parameters:
-
[in,out] *S points to an instance of the floating-point FIR filter structure. [in] numTaps Number of filter coefficients in the filter. [in] *pCoeffs points to the filter coefficients buffer. [in] *pState points to the state buffer. [in] blockSize number of samples that are processed per call.
- Returns:
- none.
Description:
pCoeffs
points to the array of filter coefficients stored in time reversed order:{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
pState
points to the array of state variables.pState
is of lengthnumTaps+blockSize-1
samples, whereblockSize
is the number of input samples processed by each call toarm_fir_f32()
.
Definition at line 65 of file arm_fir_init_f32.c.
arm_status arm_fir_init_q15 | ( | arm_fir_instance_q15 * | S, |
uint16_t | numTaps, | ||
q15_t * | pCoeffs, | ||
q15_t * | pState, | ||
uint32_t | blockSize | ||
) |
Initialization function for the Q15 FIR filter.
- Parameters:
-
[in,out] *S points to an instance of the Q15 FIR filter structure. [in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4. [in] *pCoeffs points to the filter coefficients buffer. [in] *pState points to the state buffer. [in] blockSize is number of samples processed per call.
- Returns:
- The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if
numTaps
is not greater than or equal to 4 and even.
Description:
pCoeffs
points to the array of filter coefficients stored in time reversed order:{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
Note thatnumTaps
must be even and greater than or equal to 4. To implement an odd length filter simply increasenumTaps
by 1 and set the last coefficient to zero. For example, to implement a filter withnumTaps=3
and coefficients{0.3, -0.8, 0.3}
setnumTaps=4
and use the coefficients:{0.3, -0.8, 0.3, 0}.
Similarly, to implement a two point filter{0.3, -0.3}
setnumTaps=4
and use the coefficients:{0.3, -0.3, 0, 0}.
pState
points to the array of state variables.pState
is of lengthnumTaps+blockSize-1
, whereblockSize
is the number of input samples processed by each call toarm_fir_q15()
.
Definition at line 82 of file arm_fir_init_q15.c.
void arm_fir_init_q31 | ( | arm_fir_instance_q31 * | S, |
uint16_t | numTaps, | ||
q31_t * | pCoeffs, | ||
q31_t * | pState, | ||
uint32_t | blockSize | ||
) |
Initialization function for the Q31 FIR filter.
- Parameters:
-
[in,out] *S points to an instance of the Q31 FIR filter structure. [in] numTaps Number of filter coefficients in the filter. [in] *pCoeffs points to the filter coefficients buffer. [in] *pState points to the state buffer. [in] blockSize number of samples that are processed per call.
- Returns:
- none.
Description:
pCoeffs
points to the array of filter coefficients stored in time reversed order:{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
pState
points to the array of state variables.pState
is of lengthnumTaps+blockSize-1
samples, whereblockSize
is the number of input samples processed by each call toarm_fir_q31()
.
Definition at line 65 of file arm_fir_init_q31.c.
void arm_fir_init_q7 | ( | arm_fir_instance_q7 * | S, |
uint16_t | numTaps, | ||
q7_t * | pCoeffs, | ||
q7_t * | pState, | ||
uint32_t | blockSize | ||
) |
Initialization function for the Q7 FIR filter.
- Parameters:
-
[in,out] *S points to an instance of the Q7 FIR filter structure. [in] numTaps Number of filter coefficients in the filter. [in] *pCoeffs points to the filter coefficients buffer. [in] *pState points to the state buffer. [in] blockSize number of samples that are processed per call.
- Returns:
- none
Description:
pCoeffs
points to the array of filter coefficients stored in time reversed order:{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
pState
points to the array of state variables.pState
is of lengthnumTaps+blockSize-1
samples, whereblockSize
is the number of input samples processed by each call toarm_fir_q7()
.
Definition at line 62 of file arm_fir_init_q7.c.
void arm_fir_q15 | ( | const arm_fir_instance_q15 * | S, |
q15_t * | pSrc, | ||
q15_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the Q15 FIR filter.
- Parameters:
-
[in] *S points to an instance of the Q15 FIR structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block of output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Scaling and Overflow Behavior:
- The function is implemented using a 64-bit internal accumulator. Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format.
- Refer to the function
arm_fir_fast_q15()
for a faster but less precise implementation of this function.
Definition at line 65 of file arm_fir_q15.c.
void arm_fir_q31 | ( | const arm_fir_instance_q31 * | S, |
q31_t * | pSrc, | ||
q31_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the Q31 FIR filter.
- Parameters:
-
[in] *S points to an instance of the Q31 FIR filter structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block of output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Scaling and Overflow Behavior:
- The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits. After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format.
- Refer to the function
arm_fir_fast_q31()
for a faster but less precise implementation of this filter.
Definition at line 64 of file arm_fir_q31.c.
void arm_fir_q7 | ( | const arm_fir_instance_q7 * | S, |
q7_t * | pSrc, | ||
q7_t * | pDst, | ||
uint32_t | blockSize | ||
) |
Processing function for the Q7 FIR filter.
- Parameters:
-
[in] *S points to an instance of the Q7 FIR filter structure. [in] *pSrc points to the block of input data. [out] *pDst points to the block of output data. [in] blockSize number of samples to process per call.
- Returns:
- none.
Scaling and Overflow Behavior:
- The function is implemented using a 32-bit internal accumulator. Both coefficients and state variables are represented in 1.7 format and multiplications yield a 2.14 result. The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. The accumulator is converted to 18.7 format by discarding the low 7 bits. Finally, the result is truncated to 1.7 format.
Definition at line 61 of file arm_fir_q7.c.
Generated on Tue Jul 12 2022 14:13:55 by 1.7.2