In every project that acquires a signal, sooner or later the same question arrives: should I do this filter in hardware with an active or passive stage ahead of the ADC, or in software with a few lines of code in the DSP? It’s an architectural choice: it affects board cost, CPU load and — in the worst case — the validity of the acquired data. In some cases the filter must be analog, in others a digital IIR is the better choice.
When the filter must be analog
Anti-aliasing protection must act before unwanted components overlap the useful band. Filtering after that sampling operation cannot distinguish contributions already folded together.
An ADC samples at a frequency Fs and, by the Nyquist theorem, can correctly represent only signals below Fs/2. Any signal component above Fs/2 isn’t discarded: it’s folded (aliased) into the useful band, where it disguises itself as a legitimate signal at a lower frequency. Once it has happened, it’s irreversible. A disturbance at Fs − f looks identical to a real signal at f: no algorithm, however sophisticated, can separate them after the fact, because the information that distinguished them was lost at the moment of sampling.
This is why an anti-aliasing filter has to go before the ADC, and is therefore necessarily analog. A digital filter, no matter how steep, works on samples that are already acquired: if aliasing has already contaminated those samples, the digital filter will happily filter the alias as if it were good signal. It recovers nothing, because there’s nothing left to recover. Anti-aliasing done “afterwards” is a frequent error.
Analog also wins in two other practical scenarios. First, EMI and high-energy out-of-band rejection: a passive filter ahead of the input attenuates radio-frequency disturbances before they saturate the conditioning stage or the ADC itself — a job the digital side can’t do, because those disturbances don’t even reach the converter intact. Second, zero CPU load: an analog filter burns no cycles. On an MCU where the compute budget is already contended among control, communication and application logic, moving a fixed filter into hardware frees up machine time.
To dimension these stages — choose Sallen-Key or multiple-feedback, place the pole, read the roll-off — we put a analog filter designer with Bode plot online; the theory, with the use cases, is in the dedicated wiki.
When a digital IIR is better
Past the anti-aliasing barrier, once the samples are inside the digital domain and already protected from aliasing, software filtering almost always becomes the better choice. A digital IIR (Infinite Impulse Response) filter offers advantages analog can’t match.
An IIR is adjustable at runtime: changing coefficients changes the response without replacing components. It avoids resistor and capacitor tolerances, but depends on coefficient precision, arithmetic and the clock. Reproducibility must be checked in the implementation. Bessel prioritises the analog prototype’s group delay; digital transformation alters its phase, whereas a suitably designed FIR can have exactly linear phase.
The price to pay is computational load and attention to numerical stability: a badly conditioned IIR, implemented in fixed point with too little coefficient resolution, can go unstable or introduce limit cycles. To design the filter, choose the topology and verify its response we have an IIR filter designer and its wiki.
The rule we apply
Analog for what has to happen before conversion (anti-aliasing, rejection of high-energy disturbances), digital for fine shaping after sampling. The anti-aliasing filter isn’t delegated to software: it’s the only protection against an error that, once it has happened, no algorithm can undo.
Discuss your acquisition-chain requirements with us to choose where filtering belongs.