THE FILTER BENCH
Digital signal processing · a bench you can poke

One impulse in.
Two very different answers.

Hit a filter with a single sample and watch what comes back. That one experiment separates FIR from IIR, tells you whether the thing can be built from a capacitor or needs a shift register, and explains why the ideal filter in the textbook never shows up in your lab.

Live · impulse response race
FIR IIR n = 0
FIR · 16-tap moving average IIR · one-pole, a = 0.93 input δ[n]
IIR feedback a0.930
The whole page in one line

The FIR output is exactly zero from sample 16 onward — its memory ran out. The IIR output gets smaller forever but never reaches zero, because part of its output is fed back into its own input. Everything else follows from that.

01 · TIME DOMAIN

The impulse response is the filter

Feed in δ[n] — one sample of 1, then silence. What comes out is h[n], and it contains everything: knowing h[n] means you can predict the output for any input by convolution. The response is either finite or it is infinite. There is no third option, and that is literally the naming scheme.

Impulse · step · frequency response
multiplies/sample samples to settle
h[n] — impulse response. Stems are individual samples.
|H(e)| in dB — what it does to each frequency.
Taps N16
Cutoff0.20
Read the left plot

FIR: the stems stop. The filter only ever looks at the last N input samples, so after N samples of silence it has nothing left to say.

Read it again for IIR

IIR: the stems decay geometrically. Each output sample is partly a recycled previous output, so the ringing shrinks by a constant factor forever. "Settled" only ever means "below my noise floor".

02 · STRUCTURE

Where the difference actually lives: one wire

Both filters are built from the same three pieces — a delay, a multiply, an add. The only structural difference is whether a wire runs backward from the output.

FIR · feed-forward only
no feedback
x[n] z⁻¹ z⁻¹ z⁻¹ b₀b₁ b₂b₃ + y[n]
y[n] = b₀x[n] + b₁x[n−1] + b₂x[n−2] + b₃x[n−3]

Output depends only on inputs. The signal enters on the left and leaves on the right. Nothing circulates.

IIR · feed-forward + feedback
recursive
x[n] z⁻¹ b₀b₁ + y[n] z⁻¹ −a₁
y[n] = b₀x[n] + b₁x[n−1] − a₁·y[n−1]

That amber loop is the entire story. Output re-enters the summer, so a single input keeps circulating, attenuated a little each lap.

Trade study
PropertyFIRIIR
StabilityUnconditional. No poles to run away.Conditional — poles must stay inside the unit circle.
Linear phaseFree, if coefficients are symmetric. Constant group delay.Not achievable causally. Phase warps near cutoff.
Order for a specHigh. A sharp 60 dB lowpass can need 100+ taps.Low. Same spec in a 4th–8th order biquad chain.
Cost per sampleN multiply-accumulates.Typically 5 MACs per biquad.
Coefficient roundingDegrades the response, gently.Moves poles. Can oscillate or blow up.
Arithmetic quirksNo feedback ⇒ no limit cycles.Limit cycles, overflow oscillation, needs care in fixed point.
TransientSettles in exactly N samples.Exponential; "settled" is a threshold you pick.
Natural homeDigital. Needs exact delays.Analog and digital. Any RC network is one.
03 · Z-PLANE

Why feedback is dangerous, drawn as a picture

Write the filter as H(z) = B(z)/A(z). Roots of the numerator are zeros — frequencies killed. Roots of the denominator are poles — frequencies amplified. A pole is only stable if it sits inside the unit circle, and feedback is what creates poles. An FIR filter's denominator is 1, so all its poles pile up harmlessly at the origin.

Drag the pole, or use the sliders
|p| = 0.90 Q ≈ stable
z-plane — drag inside it to move the pole. ✕ = pole, ○ = zero.
Resulting impulse response. Radius sets the decay rate, angle sets the ringing frequency.
Pole radius |p|0.90
Pole angle ω₀0.25 π
Push |p| past 1.00

The impulse response grows without bound from a single input sample. Nothing external is driving it — the loop gain simply exceeds unity. This failure mode does not exist for FIR, at any coefficient value, ever.

04 · IMPLEMENTATION

Building it from parts: capacitors or registers

The two domains pull in opposite directions. Analog components store energy and leak it back — that is feedback, so analog gets you IIR almost for free and FIR only with pain. Digital hardware has a perfect, free, exact delay — a flip-flop — so it gets you FIR trivially and IIR with caveats.

Analog · RC lowpass = a one-pole IIR
2 parts
Vin R C Vout
H(s) = 1 / (1 + sRC)      h(t) = (1/RC)·e−t/RC

The capacitor's stored charge is the state variable. Its voltage feeds back through R to oppose the input. Exponential decay, never zero — an infinite impulse response made of two passive parts.

Analog · Sallen–Key = a 2-pole IIR (biquad)
Q from feedback
Vin R1 R2 C1 + Vout unity-gain feedback C2 C2 is the feedback that sets Q
two poles ⇒ H(s) = ω₀² / (s² + (ω₀/Q)s + ω₀²)

C2 bootstraps the mid-node from the output — positive feedback that sets Q. Cascade a few and you have an elliptic anti-aliasing filter. This is the analog world's default answer to everything.

Live · the same filter, both ways
τ = RC a = e^(−T/RC) f−3dB
analog RC step response, continuous digital one-pole IIR, sampled at fs
RC time constant1.0 ms
Sample rate fs10 kHz
Drop fs and the digital version stops tracking the analog curve — not because the maths changed, but because you are sampling a continuous system too slowly to represent it.
Analog FIR · the hard way
needs real delay
Vin delay line — coax / SAW / CCD τ Σ y(t)
  • The delay is the problem. A 10 µs analog delay is 2 km of coax or a bulky LC ladder that disperses and attenuates.
  • Taps drift. Resistor tolerance and temperature move your coefficients around after the board is built.
  • It is done anyway where nothing else works: SAW transversal filters, CCD/bucket-brigade lines, microwave tapped-line filters, and optical FIR built from splitters and fibre delays.
Digital FIR · the easy way
delay is free
clk x[n] FF FF FF ×b₀×b₁ ×b₂×b₃ + y[n]
  • z⁻¹ is one flip-flop. Exact, drift-free, temperature-independent, free on any FPGA.
  • Coefficients are numbers in a ROM. Change the filter by rewriting memory, not by unsoldering.
  • It maps to silicon directly. One DSP slice per tap in a systolic chain; symmetric taps fold, halving the multipliers.
Which domain wants which filter
AnalogDigital
Delay z⁻¹ / τExpensive, lossy, dispersiveOne register. Exact.
Multiply by a constantResistor ratio, ±1% and driftingExact to the bit you allocate
Feedback / memoryIntrinsic — every C and L stores stateDeliberate, and needs stability analysis
So you naturally get…IIRFIR (and IIR if you want it)
Runs atGHz, zero latency, no clockBounded by fs, plus converter latency
Still mandatory forAnti-alias + reconstruction. Digital cannot fix what the ADC already folded.Anything needing exact linear phase or reconfigurability
05 · TRANSFORMS

Fourier transform, DFT, FFT — one is not like the others

These three names get used interchangeably and they are not the same kind of thing. Two are transforms — definitions in mathematics. One is an algorithm — a way of computing one of the transforms quickly. The confusion is worth clearing up because it decides what your spectrum plot actually means.

Four transforms · time on the left, frequency on the right
rule discrete in one domain ⇒ periodic in the other

Continuous-time Fourier transform

Continuous, infinite duration in → continuous, infinite in frequency. An integral. A computer cannot evaluate it: infinitely many inputs, infinitely many outputs.

Fourier series

Continuous but periodic in → discrete harmonic lines out. Periodicity in time quantises the frequency axis.

Discrete-time Fourier transform (DTFT)

Sampled but infinitely long in → continuous and periodic out. Sampling in time makes the spectrum repeat every fs. Still not computable: infinite sum, continuous output.

Discrete Fourier transform (DFT)

N samples in → N complex bins out. Finite both ways. This is the only one a machine ever computes, and it is what every spectrum analyser and every np.fft call returns.
DFT:   X[k] = Σn=0..N−1 x[n]·e−j2πkn/N   k = 0 … N−1
The part that trips people up

The DFT does not analyse "your signal". It analyses an infinite periodic repetition of your N samples. That assumption is baked into the definition, and it is the direct cause of spectral leakage in §08.

FFT is not a transform

The FFT is a family of algorithms — Cooley–Tukey, radix-2, split-radix, Bluestein — that compute exactly the DFT, just without the redundant work. Same inputs, same outputs, same maths. Only the operation count differs.

06 · ALGORITHM

Prove it: same numbers, wildly different clock time

Below, the naive O(N²) DFT and a radix-2 FFT run on the same random data, in your browser, right now. Compare the outputs and compare the times.

Live benchmark · your machine
N 1024 DFT FFT max |Δ|
Operation count. Both axes log. At N = 65 536 the ratio is about 4 000×.
Both spectra, overplotted: thin mint FFT sitting exactly on thick red DFT. Every wiggle in the noise floor lines up, because the two agree to floating-point rounding.
Transform size N1024
Why it is faster · radix-2 butterfly, N = 8
stage 1 of 3
An 8-point DFT is split into two 4-point DFTs, each split into two 2-point DFTs. log₂N stages, N/2 butterflies each. The trick is that e−j2πkn/N takes only N distinct values, so the naive version recomputes the same products over and over.
Highlight stageauto
07 · IDEAL vs REAL

The brickwall filter cannot be built. Here is exactly why.

Ask for a response that is 1 below cutoff and 0 above it, and the inverse transform hands you a sinc — which extends to ±∞ in time and is non-zero before t = 0. Infinite means unbuildable. Non-causal means it needs the future. So you truncate, and truncation has a price.

Truncate the sinc · pay in ripple
passband ripple stopband transition
Ideal sinc, greyed, running off both edges. Kept taps in colour.
Dashed white = the brickwall you asked for. Solid = what you get. Passband ripple is too small to see on a dB axis — read it off the chip above.
Taps kept31
Cutoff (×Nyquist)0.25
Gibbs phenomenon

Chop the sinc with a rectangular window and the overshoot at the edge settles at about 9 % and refuses to shrink. Adding taps makes the ripple narrower, never shorter. That is not a bug in your design — it is what a discontinuity does.

The bargain every filter designer makes

Taper the window and the sidelobes drop from −21 dB to −74 dB, but the transition band gets wider for the same tap count. Sharpness, stopband depth, tap count: pick two. That single trade is most of practical FIR design.

08 · IDEAL vs REAL

Your spectrum analyser is lying, politely

Textbook: a pure sine gives a single spectral line. Reality: one clean bin only when the sine completes a whole number of cycles inside your capture window. Move it half a bin off and the energy smears across the entire spectrum.

Slide the tone between bins
bin offset 0.00 peak error 0.00 dB worst sidelobe
Solid = the window the DFT actually sees, tiled end to end. Dashed = the real tone carrying on. The step where they part is the leakage source.
Magnitude, dB. Every non-zero bin here is an artefact — the input is one pure tone.
Tone frequency, in bins8.00
Leakage and scalloping

Off-bin energy has nowhere legal to go, so it spreads — leakage. The peak also reads low, by nearly 4 dB with no window, because the true peak falls between two bins — scalloping loss. Your amplitude measurement is wrong and the plot looks perfectly healthy.

Windows are damage control, not a fix

A window fades the capture to zero at both ends so the tiled version has no jump. Leakage collapses; in exchange the main lobe widens, so two close tones merge. Dynamic range or resolution — same trade as §07, because it is the same mathematics.

09 · IDEAL vs REAL

Finite word length: where IIR bites back

On paper your coefficients are real numbers. In an FPGA or a fixed-point DSP they are integers with a binary point. Rounding them moves the poles. For a high-Q filter the poles sit near the unit circle already, and there may not be a representable grid point left on the safe side.

Round the coefficients · watch the poles move
format pole shift stable
White ✕ = ideal pole, coloured ✕ = where rounding lands it, red line = |z| = 1. Grey dots in the zoom are every pole the coefficient grid can express: widely spaced vertically, finely spaced horizontally. That anisotropy is why low-frequency, high-Q poles are the dangerous ones.
Dashed = ideal. Solid = after rounding. Only the feedback coefficients are rounded here, since those are what place the poles — a real design scales the numerator separately.
Fractional bits10
Resonance f₀0.020
Q30
Low f₀ is the dangerous corner

Push f₀ down and the poles crowd against z = 1, where the coefficient grid is coarsest relative to what you need. Walk the bits down on this Q = 30, f₀ = 0.02 resonator: it detunes first, then at 6 fractional bits both poles land exactly on the circle and it oscillates forever on its own. Fix: cascade biquads instead of one high-order section, or move to a coupled-form / lattice structure whose grid is uniform.

FIR just shrugs

Round FIR coefficients and the stopband gets shallower. That is the whole failure mode. There are no poles to displace, so no amount of rounding can make it unstable — which is why FIR wins wherever a filter must never, under any conditions, misbehave.

10 · IDEAL vs REAL

The failure that no filter downstream can undo

Sample a tone above fs/2 and it does not disappear — it comes back wearing a disguise, at |f − k·fs|, indistinguishable from a real low-frequency signal. Once the ADC has folded it in, the information is gone.

Sweep the input past Nyquist
input reconstructed below Nyquist
true continuous input samples taken what reconstruction gives back
Input frequency (× fs)0.20
This is why an analog anti-alias filter in front of the converter is not optional, and why it cannot be replaced by any amount of DSP after the fact.
SUMMARY

The short version

Filters
  • FIR — no feedback, finite h[n], always stable, linear phase available, many taps.
  • IIR — feedback, infinite h[n], can be unstable, cheap for sharp responses, phase warps.
  • Analog gives you IIR for the price of a capacitor. Analog FIR needs a real delay line, so it is rare and expensive.
  • Digital gives you an exact delay for the price of a flip-flop, which makes FIR the default.
  • Choose FIR when phase linearity matters, when the response must be reconfigurable, or when instability is unacceptable.
  • Choose IIR when a sharp response has to fit in a tiny compute budget and phase is not critical.
Transforms
  • Fourier transform — continuous in, continuous out. A definition, not something you run.
  • DFT — N samples in, N bins out. The computable one. Assumes your window repeats forever.
  • FFT — an algorithm for the DFT. Identical output, O(N log N) instead of O(N²).
  • Leakage happens when the tone is not an exact bin multiple. Windows trade it against resolution.
  • Bin spacing is fs/N. Zero-padding interpolates the plot; it never adds resolution.
  • Alias first, ask later — nothing after the ADC can separate a folded tone from a genuine one.