|
void | tpt_fir_f32 (f32_t *aOutData, const tpt_fir_f32_t *aFilter, const f32_t *aInData, uint32_t aCount) |
| Processing function for floating-point FIR filter. More...
|
|
void | tpt_fir_fast_q15 (q15_t *aOutData, const tpt_fir_q15_t *aFilter, const q15_t *aInData, uint32_t aCount) |
| Processing function for the Q15 FIR filter.(fast version) More...
|
|
void | tpt_fir_fast_q31 (q31_t *aOutData, const tpt_fir_q31_t *aFilter, const q31_t *aInData, uint32_t aCount) |
| Processing function for Q31 FIR filter.(fast version) More...
|
|
void | tpt_fir_init_f32 (tpt_fir_f32_t *aFilter, uint16_t aTaps, const f32_t *aCoeffs, f32_t *aState, uint32_t aCount) |
| Initialization function for the floating-point FIR filter. More...
|
|
void | tpt_fir_init_q15 (tpt_fir_q15_t *aFilter, uint16_t aTaps, const q15_t *aCoeffs, q15_t *aState, uint32_t aCount) |
| Initialization function for the Q15 FIR filter. More...
|
|
void | tpt_fir_init_q31 (tpt_fir_q31_t *aFilter, uint16_t aTaps, const q31_t *aCoeffs, q31_t *aState, uint32_t aCount) |
| Initialization function for the Q31 FIR filter. More...
|
|
void | tpt_fir_init_q7 (tpt_fir_q7_t *aFilter, uint16_t aTaps, const q7_t *aCoeffs, q7_t *aState, uint32_t aCount) |
| Initialization function for the Q7 FIR filter. More...
|
|
void | tpt_fir_q15 (q15_t *aOutData, const tpt_fir_q15_t *aFilter, const q15_t *aInData, uint32_t aCount) |
| Processing function for the Q15 FIR filter. More...
|
|
void | tpt_fir_q31 (q31_t *aOutData, const tpt_fir_q31_t *aFilter, const q31_t *aInData, uint32_t aCount) |
| Processing function for Q31 FIR filter. More...
|
|
void | tpt_fir_q7 (q7_t *aOutData, const tpt_fir_q7_t *aFilter, const q7_t *aInData, uint32_t aCount) |
| Processing function for the Q7 FIR filter. More...
|
|
This set of functions implements Finite Impulse Response (FIR) filters for Q7, Q15, Q31, and floating-point data types. The functions operate on blocks of input and output data and each call to the function processes aCount
samples through the filter. aInData
and aOutData
points to input and output arrays containing aCount
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 sample x[n]
at any time point n:
y[n] = b[0] * x[n] + b[1] * x[n - 1] + b[2] * x[n - 2] + ...
+ b[uTaps - 1] * x[n - uTaps + 1]
Finite Impulse Response filter
pCoeffs
points to a coefficient array of size uTaps
. Coefficients are stored in time reversed order:
{ b[uTaps - 1], b[uTaps - 2], ..., b[1], b[0] }
pState
points to a state array of size uTaps + aCount - 1
. Samples in the state buffer are stored in the time order at time point n:
{ x[n - uTaps + 1], x[n - uTaps], x[n - uTaps - 1], ...,
x[n] = aInData[0], ..., x[n + aCount - 1] = aInData[aCount - 1] }
- Note that the length of the state buffer exceeds the length of the coefficient array by
aCount - 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. To do this manually without calling the init function, assign the follow subfields of the instance structure: uTaps, 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. The code below statically initializes each of the 4 different data type filter instance structures:
tpt_fir_f32_t aFilter1 = { aTaps, aState, aCoeffs };
tpt_fir_q31_t aFilter2 = { aTaps, aState, aCoeffs };
tpt_fir_q15_t aFilter3 = { aTaps, aState, aCoeffs };
tpt_fir_q7_t aFilter4 = { aTaps, aState, aCoeffs };
where aTaps
is the number of filter coefficients in the filter; aState
is the address of the state buffer; aCoeffs
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.
◆ tpt_fir_f32()
Processing function for floating-point FIR filter.
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the floating-point FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- Returns
- none
◆ tpt_fir_fast_q15()
Processing function for the Q15 FIR filter.(fast version)
Processing function for the Q15 FIR filter.
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the Q15 FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- 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(uTaps) bits.
◆ tpt_fir_fast_q31()
Processing function for Q31 FIR filter.(fast version)
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the Q31 FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- 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(uTaps) bits.
◆ tpt_fir_init_f32()
void tpt_fir_init_f32 |
( |
tpt_fir_f32_t * |
aFilter, |
|
|
uint16_t |
aTaps, |
|
|
const f32_t * |
aCoeffs, |
|
|
f32_t * |
aState, |
|
|
uint32_t |
aCount |
|
) |
| |
Initialization function for the floating-point FIR filter.
- Parameters
-
[in,out] | aFilter | points to an instance of the floating-point FIR filter structure. |
[in] | aTaps | number of filter coefficients in the filter |
[in] | aCoeffs | points to the filter coefficients buffer. |
[in] | aState | points to the state buffer. |
[in] | aCount | number of samples processed per call |
- Returns
- none
- Details
aCoeffs
points to the array of filter coefficients stored in time reversed order:
{ b[aTaps - 1], b[aTaps - 2], ..., b[1], b[0] }
aState
points to the array of state variables. aState
is of length aTaps + aCount - 1
where aCount
is the number of input samples processed by each call to tpt_fir_q15()
. Samples in the state buffer are stored in time order at time point n:
{ x[n - aTaps + 1], x[n - aTaps + 2], ..., x[n - 1], x[n] = aInData[0],
x[n + 1] = aInData[1], ..., x[n + aCount - 1] = aInData[aCount - 1] }
◆ tpt_fir_init_q15()
void tpt_fir_init_q15 |
( |
tpt_fir_q15_t * |
aFilter, |
|
|
uint16_t |
aTaps, |
|
|
const q15_t * |
aCoeffs, |
|
|
q15_t * |
aState, |
|
|
uint32_t |
aCount |
|
) |
| |
Initialization function for the Q15 FIR filter.
- Parameters
-
[in,out] | aFilter | points to an instance of the Q15 FIR filter structure. |
[in] | aTaps | number of filter coefficients in the filter |
[in] | aCoeffs | points to the filter coefficients buffer. |
[in] | aState | points to the state buffer. |
[in] | aCount | number of samples processed per call |
- Returns
- none
- Details
aCoeffs
points to the array of filter coefficients stored in time reversed order:
{ b[aTaps - 1], b[aTaps - 2], ..., b[1], b[0] }
aState
points to the array of state variables. aState
is of length aTaps + aCount - 1
where aCount
is the number of input samples processed by each call to tpt_fir_q15()
. Samples in the state buffer are stored in time order at time point n:
{ x[n - aTaps + 1], x[n - aTaps + 2], ..., x[n - 1], x[n] = aInData[0],
x[n + 1] = aInData[1], ..., x[n + aCount - 1] = aInData[aCount - 1] }
◆ tpt_fir_init_q31()
void tpt_fir_init_q31 |
( |
tpt_fir_q31_t * |
aFilter, |
|
|
uint16_t |
aTaps, |
|
|
const q31_t * |
aCoeffs, |
|
|
q31_t * |
aState, |
|
|
uint32_t |
aCount |
|
) |
| |
Initialization function for the Q31 FIR filter.
- Parameters
-
[in,out] | aFilter | points to an instance of the Q31 FIR filter structure. |
[in] | aTaps | number of filter coefficients in the filter |
[in] | aCoeffs | points to the filter coefficients buffer. |
[in] | aState | points to the state buffer. |
[in] | aCount | number of samples processed |
- Returns
- none
- Details
aCoeffs
points to the array of filter coefficients stored in time reversed order:
{ b[aTaps - 1], b[aTaps - 2], ..., b[1], b[0] }
aState
points to the array of state variables. aState
is of length aTaps + aCount - 1
where aCount
is the number of input samples processed by each call to tpt_fir_q31()
. Samples in the state buffer are stored in time order at time point n:
{ x[n - aTaps + 1], x[n - aTaps + 2], ..., x[n - 1], x[n] = aInData[0],
x[n + 1] = aInData[1], ..., x[n + aCount - 1] = aInData[aCount - 1] }
◆ tpt_fir_init_q7()
void tpt_fir_init_q7 |
( |
tpt_fir_q7_t * |
aFilter, |
|
|
uint16_t |
aTaps, |
|
|
const q7_t * |
aCoeffs, |
|
|
q7_t * |
aState, |
|
|
uint32_t |
aCount |
|
) |
| |
Initialization function for the Q7 FIR filter.
- Parameters
-
[in,out] | aFilter | points to an instance of the Q7 FIR filter structure. |
[in] | aTaps | number of filter coefficients in the filter |
[in] | aCoeffs | points to the filter coefficients buffer. |
[in] | aState | points to the state buffer. |
[in] | aCount | number of samples processed per call |
- Returns
- none
- Details
aCoeffs
points to the array of filter coefficients stored in time reversed order:
{ b[aTaps - 1], b[aTaps - 2], ..., b[1], b[0] }
aState
points to the array of state variables. aState
is of length aTaps + aCount - 1
where aCount
is the number of input samples processed by each call to tpt_fir_q15()
. Samples in the state buffer are stored in time order at time point n:
{ x[n - aTaps + 1], x[n - aTaps + 2], ..., x[n - 1], x[n] = aInData[0],
x[n + 1] = aInData[1], ..., x[n + aCount - 1] = aInData[aCount - 1] }
◆ tpt_fir_q15()
Processing function for the Q15 FIR filter.
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the Q15 FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- 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.
◆ tpt_fir_q31()
Processing function for Q31 FIR filter.
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the Q31 FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- 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(uTaps) bits. After all multiply-accumulates are performed, the 2.62 accumulator is right shifted by 31 bits and saturated to 1.31 format to yield the final result.
◆ tpt_fir_q7()
void tpt_fir_q7 |
( |
q7_t * |
aOutData, |
|
|
const tpt_fir_q7_t * |
aFilter, |
|
|
const q7_t * |
aInData, |
|
|
uint32_t |
aCount |
|
) |
| |
Processing function for the Q7 FIR filter.
- Parameters
-
[out] | aOutData | points to the block of output data. |
[in] | aFilter | points to an instance of the Q7 FIR filter structure. |
[in] | aInData | points to the block of input data. |
[in] | aCount | number of samples to process |
- 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.