Finite Impulse Response (FIR) Sparse Filters
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_f32 (riscv_fir_sparse_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, float32_t *pScratchIn, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_f32 (riscv_fir_sparse_instance_f32 *S, uint16_t numTaps, const float32_t *pCoeffs, float32_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q15 (riscv_fir_sparse_instance_q15 *S, uint16_t numTaps, const q15_t *pCoeffs, q15_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q31 (riscv_fir_sparse_instance_q31 *S, uint16_t numTaps, const q31_t *pCoeffs, q31_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q7 (riscv_fir_sparse_instance_q7 *S, uint16_t numTaps, const q7_t *pCoeffs, q7_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q15 (riscv_fir_sparse_instance_q15 *S, const q15_t *pSrc, q15_t *pDst, q15_t *pScratchIn, q31_t *pScratchOut, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q31 (riscv_fir_sparse_instance_q31 *S, const q31_t *pSrc, q31_t *pDst, q31_t *pScratchIn, uint32_t blockSize)
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q7 (riscv_fir_sparse_instance_q7 *S, const q7_t *pSrc, q7_t *pDst, q7_t *pScratchIn, q31_t *pScratchOut, uint32_t blockSize)
- group FIR_Sparse
- Deprecated:
Those functions are no more tested nor maintained and will be removed in a future version.
This group of functions implements sparse FIR filters. Sparse FIR filters are equivalent to standard FIR filters except that most of the coefficients are equal to zero. Sparse filters are used for simulating reflections in communications and audio applications.
There are separate functions 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
blockSize
samples through the filter.pSrc
andpDst
points to input and output arrays respectively containingblockSize
values.- Algorithm
The sparse filter instant structure contains an array of tap indices
pTapDelay
which specifies the locations of the non-zero coefficients. This is in addition to the coefficient arrayb
. The implementation essentially skips the multiplications by zero and leads to an efficient realization.pCoeffs
points to a coefficient array of sizenumTaps
;pTapDelay
points to an array of nonzero indices and is also of sizenumTaps
;pState
points to a state array of sizemaxDelay + blockSize
, wheremaxDelay
is the largest offset value that is ever used in thepTapDelay
array. Some of the processing functions also require temporary working buffers.- 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 and offset 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: numTaps, pCoeffs, pTapDelay, maxDelay, stateIndex, 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
- Fixed-Point Behavior
Care must be taken when using the fixed-point versions of the sparse 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.
Functions
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_f32 (riscv_fir_sparse_instance_f32 *S, const float32_t *pSrc, float32_t *pDst, float32_t *pScratchIn, uint32_t blockSize)
Processing function for the floating-point sparse FIR filter.
- Parameters
S – [in] points to an instance of the floating-point sparse FIR structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
pScratchIn – [in] points to a temporary buffer of size blockSize
blockSize – [in] number of input samples to process
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_f32 (riscv_fir_sparse_instance_f32 *S, uint16_t numTaps, const float32_t *pCoeffs, float32_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
Initialization function for the floating-point sparse FIR filter.
- Details
pCoeffs
holds the filter coefficients and has lengthnumTaps
.pState
holds the filter’s state variables and must be of lengthmaxDelay + blockSize
, wheremaxDelay
is the maximum number of delay line values.blockSize
is the number of samples processed by theriscv_fir_sparse_f32()
function.
- Parameters
S – [inout] points to an instance of the floating-point sparse FIR structure
numTaps – [in] number of nonzero coefficients in the filter
pCoeffs – [in] points to the array of filter coefficients
pState – [in] points to the state buffer
pTapDelay – [in] points to the array of offset times
maxDelay – [in] maximum offset time supported
blockSize – [in] number of samples that will be processed per block
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q15 (riscv_fir_sparse_instance_q15 *S, uint16_t numTaps, const q15_t *pCoeffs, q15_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
Initialization function for the Q15 sparse FIR filter.
- Details
pCoeffs
holds the filter coefficients and has lengthnumTaps
.pState
holds the filter’s state variables and must be of lengthmaxDelay + blockSize
, wheremaxDelay
is the maximum number of delay line values.blockSize
is the number of words processed byriscv_fir_sparse_q15()
function.
- Parameters
S – [inout] points to an instance of the Q15 sparse FIR structure
numTaps – [in] number of nonzero coefficients in the filter
pCoeffs – [in] points to the array of filter coefficients
pState – [in] points to the state buffer
pTapDelay – [in] points to the array of offset times
maxDelay – [in] maximum offset time supported
blockSize – [in] number of samples that will be processed per block
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q31 (riscv_fir_sparse_instance_q31 *S, uint16_t numTaps, const q31_t *pCoeffs, q31_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
Initialization function for the Q31 sparse FIR filter.
- Details
pCoeffs
holds the filter coefficients and has lengthnumTaps
.pState
holds the filter’s state variables and must be of lengthmaxDelay + blockSize
, wheremaxDelay
is the maximum number of delay line values.blockSize
is the number of words processed byriscv_fir_sparse_q31()
function.
- Parameters
S – [inout] points to an instance of the Q31 sparse FIR structure
numTaps – [in] number of nonzero coefficients in the filter
pCoeffs – [in] points to the array of filter coefficients
pState – [in] points to the state buffer
pTapDelay – [in] points to the array of offset times
maxDelay – [in] maximum offset time supported
blockSize – [in] number of samples that will be processed per block
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_init_q7 (riscv_fir_sparse_instance_q7 *S, uint16_t numTaps, const q7_t *pCoeffs, q7_t *pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize)
Initialization function for the Q7 sparse FIR filter.
- Details
pCoeffs
holds the filter coefficients and has lengthnumTaps
.pState
holds the filter’s state variables and must be of lengthmaxDelay + blockSize
, wheremaxDelay
is the maximum number of delay line values.blockSize
is the number of samples processed by theriscv_fir_sparse_q7()
function.
- Parameters
S – [inout] points to an instance of the Q7 sparse FIR structure
numTaps – [in] number of nonzero coefficients in the filter
pCoeffs – [in] points to the array of filter coefficients
pState – [in] points to the state buffer
pTapDelay – [in] points to the array of offset times
maxDelay – [in] maximum offset time supported
blockSize – [in] number of samples that will be processed per block
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q15 (riscv_fir_sparse_instance_q15 *S, const q15_t *pSrc, q15_t *pDst, q15_t *pScratchIn, q31_t *pScratchOut, uint32_t blockSize)
Processing function for the Q15 sparse FIR filter.
- Scaling and Overflow Behavior
The function is implemented using an internal 32-bit accumulator. The 1.15 x 1.15 multiplications yield a 2.30 result and these are added to a 2.30 accumulator. Thus the full precision of the multiplications is maintained but there is only a single guard bit in the accumulator. If the accumulator result overflows it will wrap around rather than saturate. After all multiply-accumulates are performed, the 2.30 accumulator is truncated to 2.15 format and then saturated to 1.15 format. In order to avoid overflows the input signal or coefficients must be scaled down by log2(numTaps) bits.
- Parameters
S – [in] points to an instance of the Q15 sparse FIR structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
pScratchIn – [in] points to a temporary buffer of size blockSize
pScratchOut – [in] points to a temporary buffer of size blockSize
blockSize – [in] number of input samples to process per call
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q31 (riscv_fir_sparse_instance_q31 *S, const q31_t *pSrc, q31_t *pDst, q31_t *pScratchIn, uint32_t blockSize)
Processing function for the Q31 sparse FIR filter.
- Scaling and Overflow Behavior
The function is implemented using an internal 32-bit accumulator. The 1.31 x 1.31 multiplications are truncated to 2.30 format. This leads to loss of precision on the intermediate multiplications and provides only a single guard bit. If the accumulator result overflows, it wraps around rather than saturate. In order to avoid overflows the input signal or coefficients must be scaled down by log2(numTaps) bits.
- Parameters
S – [in] points to an instance of the Q31 sparse FIR structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
pScratchIn – [in] points to a temporary buffer of size blockSize
blockSize – [in] number of input samples to process
- RISCV_DSP_ATTRIBUTE void riscv_fir_sparse_q7 (riscv_fir_sparse_instance_q7 *S, const q7_t *pSrc, q7_t *pDst, q7_t *pScratchIn, q31_t *pScratchOut, uint32_t blockSize)
Processing function for the Q7 sparse FIR filter.
- 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 then converted to 18.7 format by discarding the low 7 bits. Finally, the result is truncated to 1.7 format.
- Parameters
S – [in] points to an instance of the Q7 sparse FIR structure
pSrc – [in] points to the block of input data
pDst – [out] points to the block of output data
pScratchIn – [in] points to a temporary buffer of size blockSize
pScratchOut – [in] points to a temporary buffer of size blockSize
blockSize – [in] number of input samples to process