MSP DSP Library
|
The FIR functions in DSPLib require past sample history to compute output samples. The most straight forward approach is to copy a block of samples from the end of the previous sample buffer to the beginning of the next sample buffer but is generally inefficient and requires additional time and energy. The FIR functions include a circular input buffer feature where the end of the input buffer wraps around to the beginning of the same buffer. This feature is supported by LEA and enables FIR filtering with less memory usage and less sample copy overhead.
When using the circular buffer feature the input buffer must be twice the FIR length and aligned to an address equal to it's total byte size. The diagram below shows an example allocation of a 128 sample circular buffer aligned to a 256-byte address and separated into two 64-sample buffers for FIR filtering.
The code snippet below from example filter_ex1_fir_q15 demonstrates how to allocate the above buffer with the correct alignment using the included macros.
The following steps demonstrate how to use the same 128-sample circular buffer to run a continuous FIR filter with 64 samples and 4 coefficient taps.
See examples filter_ex1_fir_q15 and filter_ex2_fir_iq31 for example code using the circular buffer feature with Q15 and IQ31 FIR filters.