A Finite Impulse Response (FIR) filter is a discrete-time digital filter whose output depends only on a finite window of past and present input samples, weighted by a fixed set of coefficients. Because it has no feedback path, its impulse response is nonzero for at most N samples and is exactly zero thereafter, where N is the filter length.
In practice
FIR filters appear frequently in embedded signal processing pipelines: audio equalization, sensor data smoothing, anti-aliasing before decimation, and communications baseband processing. The core operation is a multiply-accumulate (MAC) loop: each output sample y[n] is computed as the dot product of the coefficient array h[k] and the most recent N input samples. On a Cortex-M4 or Cortex-M7 with a hardware FPU and DSP extensions, SIMD MAC instructions such as SMLAD (integer dual 16-bit MAC) can process multiple taps per cycle, though exact throughput depends on the specific core, pipeline, data layout, and compiler. On 8-bit or 16-bit MCUs without hardware multiply, long FIR filters can be prohibitively expensive; designers often replace them with IIR designs, use multirate structures, or accept the cost when phase linearity requirements prevent alternatives.
A key practical advantage is the ability to achieve linear phase response. When the coefficient array is symmetric (h[k] = h[N-1-k]), the filter introduces a constant group delay across all frequencies, which means all frequency components are delayed by the same number of samples with no phase distortion. This property is explored in depth in "The Most Interesting FIR Filter Equation in the World: Why FIR Filters Can Be Linear Phase." Linear phase is valuable in applications like ECG processing or audio where waveform shape matters, and it is not easily achieved with IIR filters.
The main cost of FIR filters relative to IIR alternatives is computational load and memory. A sharp transition-band specification can require hundreds or thousands of taps; a comparable IIR filter may need only four to eight biquad stages. CMSIS-DSP (for Cortex-M targets) provides optimized arm_fir_f32, arm_fir_q15, and arm_fir_q31 functions that use a circular buffer internally, avoiding the cost of shifting the sample history on every output. Using fixed-point variants (Q15 or Q31) rather than floating-point is often necessary on MCUs without an FPU to meet real-time deadlines.
A common pitfall is coefficient quantization. Coefficients designed in double precision on a workstation must be rounded to the target word width (typically 16 or 32 bits in fixed-point implementations), and this quantization shifts the actual frequency response away from the designed response, particularly in the stopband. Always simulate the quantized response before committing to a hardware implementation. The blog post "An Efficient Lowpass Filter in Octave" demonstrates practical lowpass FIR design and evaluation in a scripting environment before deployment.
Discussed on DSPRelated
Frequently asked
What is the difference between a FIR filter and an IIR filter?
A FIR filter has no feedback: each output depends only on a finite number of current and past inputs. An
IIR (Infinite
Impulse Response) filter feeds previous outputs back into the computation, so its impulse response theoretically never reaches zero. IIR filters can meet a given
frequency response specification with far fewer coefficients, but they can become unstable if not designed carefully and typically cannot achieve
linear phase. The blog post 'The First-Order IIR Filter -- More than Meets the Eye' covers IIR behavior in detail. FIR filters are always stable and, with symmetric coefficients, can achieve exact linear
phase.
How do I choose the number of taps (filter length) for a FIR filter?
Filter length is primarily determined by the sharpness of the transition band and the required stopband attenuation. A commonly cited rule of thumb associated with the
Kaiser window method estimates the required filter order as approximately (A - 8) / (2.285 * Δω), where A is the desired stopband attenuation in dB and Δω is the normalized transition
bandwidth in radians; note that exact constants vary depending on the derivation and normalization convention used, and this gives an order estimate that must be converted to a tap count. Practical tools (
MATLAB's fir1/firpm,
SciPy's firwin, or Octave equivalents) automate this. On resource-constrained MCUs, always profile the MAC loop at the chosen length against your
sample rate budget before finalizing the design.
Can a FIR filter be used for differentiation or interpolation, not just frequency-selective filtering?
Yes. A FIR filter computes a linear
convolution of the input with a finite
impulse response, so the same structure implements differentiators, Hilbert transformers,
interpolation/
decimation filters, and matched filters by choosing appropriate coefficients. The blog post 'A New Contender in the Digital Differentiator Race' discusses FIR-based differentiation specifically. The post 'FIR Filter to Match Any Magnitude and
Phase Response' covers designing FIR filters to approximate an arbitrary target response.
What is a polyphase FIR filter and when is it used in embedded systems?
A
polyphase decomposition splits the coefficient array into M sub-filters (phases), each operating at the lower rate, to implement sample-rate conversion (
decimation or
interpolation) efficiently. Instead of filtering at the high rate and discarding samples (for decimation), or inserting zeros and then filtering (for interpolation), the polyphase structure operates each
phase at the lower
sample rate. This reduces the MAC workload by the decimation or interpolation factor M, which is critical on MCUs where computational budget is tight.
Is fixed-point or floating-point arithmetic better for FIR filters on microcontrollers?
It depends on the target hardware. On Cortex-M4/M7 and similar cores with a single-precision FPU,
floating-point FIR (e.g., arm_fir_f32 from CMSIS-DSP) is convenient and avoids quantization arithmetic errors. On MCUs without an FPU, fixed-point
Q15 or Q31 arithmetic using integer MAC instructions is typically significantly faster, though the exact speedup is hardware- and workload-dependent. Q15 is sufficient for many audio and sensor applications; Q31 provides more headroom for accumulation without overflow. Always verify that coefficient quantization to the chosen fixed-point format does not degrade the stopband response below the required specification.
Differentiators vs similar concepts
FIR filters are often contrasted with
IIR (Infinite
Impulse Response) filters. The core distinction is structural: FIR filters use only feedforward paths (no output feedback), guaranteeing stability and making
linear phase straightforward to achieve with symmetric coefficients. IIR filters use feedback, allowing sharp frequency responses with far fewer coefficients but at the cost of potential instability, nonlinear
phase, and more complex design. For many embedded applications where computational budget is tight, IIR biquad cascades are preferred; where linear phase or guaranteed stability is required, FIR is the natural choice.