# Filter in hardware or in software? The decision you make before the ADC

> When a filter must be analog (anti-aliasing, EMI rejection) and when a digital IIR is better: tunable, steep, reproducible. A decision made before the ADC.

Published: 2026-06-24
Category: hardware
Tag: hardware, filters, anti-aliasing, adc, dsp, iir, signal-processing

Page: <https://www.stline.it/en/blog/filtro-analogico-o-digitale/>

---

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, not a cosmetic one: it affects board cost, CPU load and — in the worst case — the very validity of the acquired data. The answer isn't "it depends on taste": there are cases where the filter **must** be analog, full stop, and others where a digital IIR is the better choice. Here's where the line falls.

## When the filter must be analog

There's one case where a digital filter **is not an option**, and understanding it is the point that separates a correct system from one that lies elegantly: **anti-aliasing**.

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. It's the most expensive conceptual error we see: trusting an anti-aliasing done "afterwards".

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 precious 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](/en/tools/analog-filter-bode/) online; the theory, with the use cases, is in the [dedicated wiki](/en/wiki/analog-filter-bode/).

## 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.

It's **tunable at runtime**: change the coefficients and you change the cutoff frequency without touching a single component. In a product that has to cover multiple configurations or adapt to the signal, this is decisive. It has **no component drift**: an analog filter lives on resistor and capacitor tolerances, which age and vary with temperature, shifting the pole over time. An IIR has its response defined by exact numbers, identical today and ten years from now. It's **bit-reproducible**: a thousand boards have a thousand strictly identical filters, with none of the spread of an analog BOM. And it allows **steep slopes and controlled phase** — high orders, elliptic or linear-phase Bessel responses — that in analog would need multiple stages, footprint and cost.

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](/en/tools/iir-filter-designer/) and its [wiki](/en/wiki/iir-filter-designer/).

## The rule we apply

The synthesis we use in design is clear-cut: **analog for what has to happen before conversion** — anti-aliasing above all, plus rejection of high-energy disturbances — and **digital for fine shaping** once the signal is safe in the sampled domain. The analog anti-aliasing filter is non-negotiable and isn't delegated to software: it's the only protection against an error that, once it has happened, no algorithm can undo. Everything else is where the digital side, with its flexibility and reproducibility, is at its best.

---

Are you dimensioning the acquisition chain of a project and need to decide where to put the filter? [Let's talk](/en/contact/).
