Skip to main content

Digital Filters

Learning Objectives

  • Explain what a digital filter does and why filtering is central to digital signal processing
  • Write the difference equations for FIR and IIR filters and identify their coefficients
  • Compare FIR and IIR filters on stability, phase linearity, and computational cost
  • Describe the windowing method and bilinear transformation as filter design techniques
  • Identify appropriate applications for digital filters in audio, image, and communication systems
  • Simulate a basic digital filter and interpret its effect on a noisy signal

Quick Answer

A digital filter is an algorithm — not a physical circuit — that reshapes a discrete-time signal's frequency content, boosting or suppressing chosen bands. There are two families: FIR (Finite Impulse Response) filters, which use only past and current input samples and are always stable, and IIR (Infinite Impulse Response) filters, which feed output samples back into the calculation, achieving sharper responses with fewer coefficients but risking instability and phase distortion. Digital filters matter because they replace analog components (resistors, capacitors, inductors) with software or DSP code, giving precise, repeatable, temperature-independent behavior that dominates modern audio, communications, and image processing systems.

What a Digital Filter Actually Does

A digital filter takes a sequence of numbers — the samples of a discrete-time signal x[n] — and produces a new sequence y[n] in which certain frequency components are amplified and others attenuated. Unlike an analog filter built from resistors, capacitors, and op-amps, a digital filter is pure arithmetic: multiplications and additions performed on sample values, either in software or on dedicated DSP hardware.

Because it's arithmetic rather than physical components, a digital filter's behavior is exact and repeatable — it doesn't drift with temperature, doesn't age, and can be redesigned instantly by changing a set of numbers (its coefficients) rather than swapping components on a board.

FIR Filters: Finite Impulse Response

An FIR filter computes each output sample as a weighted sum of a finite window of input samples only:

y[n] = Σ (k=0 to M) h[k] x[n-k]

Here h[k] are the filter coefficients (the filter's impulse response) and M is the filter order. Because the output never depends on past outputs, an FIR filter has no feedback — which guarantees it is always stable, and it can be designed to have exactly linear phase (every frequency component is delayed by the same amount), which matters wherever preserving waveform shape is important, such as audio and biomedical signal processing.

The trade-off: to get a sharp frequency response, an FIR filter typically needs many coefficients (a high order), which means more computation per output sample.

IIR Filters: Infinite Impulse Response

An IIR filter feeds previous output samples back into the calculation:

y[n] = Σ (k=0 to M) b[k] x[n-k] - Σ (j=1 to N) a[j] y[n-j]

The b[k] are feedforward coefficients and a[j] are feedback coefficients. This feedback lets an IIR filter achieve a much sharper frequency response with far fewer coefficients than an equivalent FIR filter — the classic Butterworth, Chebyshev, and elliptic filters are all IIR designs. The cost is that feedback can make the filter unstable if coefficients aren't chosen carefully, and IIR filters generally introduce nonlinear phase distortion, which FIR filters can avoid.

Filter Design Techniques

  • Windowing method — start from the ideal (infinite, non-causal) impulse response you want, then multiply it by a finite window function (Hamming, Hanning, Blackman) to truncate it into a realizable FIR filter. The window shape trades off between transition sharpness and ripple in the passband/stopband.
  • Bilinear transformation — takes a well-understood analog filter design (like a Butterworth) and maps it mathematically onto the digital domain, producing an IIR filter with a matching frequency response.
  • Frequency sampling method — you specify the desired frequency response directly at a set of frequency points, and the method computes the FIR coefficients that best match those points.

Worked Example: Comparing FIR and IIR on the Same Task

import numpy as np
from scipy.signal import butter, firwin, lfilter

fs = 1000
t = np.arange(0, 1, 1/fs)
signal = np.sin(2*np.pi*50*t) + 0.5*np.random.normal(size=t.shape)

# IIR: 4th-order Butterworth low-pass, cutoff 100 Hz
b_iir, a_iir = butter(4, 100/(fs/2), btype='low')
y_iir = lfilter(b_iir, a_iir, signal)

# FIR: 51-tap low-pass filter, same cutoff, via windowing
b_fir = firwin(51, 100/(fs/2))
y_fir = lfilter(b_fir, [1.0], signal)

The Butterworth filter reaches its target roll-off with only 4 feedback coefficients; the FIR filter needs 51 coefficients to achieve a comparable transition sharpness. That difference — few coefficients with feedback risk, versus many coefficients with guaranteed stability — is the central design trade-off between IIR and FIR.

Real-World Applications

  • Audio processing — equalizers, noise gates, and dynamic range compressors are almost universally implemented as digital filters today.
  • Image processing — 2D FIR filters perform smoothing, sharpening, and edge detection.
  • Communications — channel equalizers and pulse-shaping filters (often FIR, for their linear-phase property) prevent inter-symbol interference.
  • Control systems — digital filters condition sensor signals before they reach a control algorithm, removing measurement noise without introducing destabilizing phase lag.

Key Terms

TermDefinitionRelated Concept
Digital filterAn algorithm that reshapes a discrete-time signal's frequency contentFIR, IIR
FIR filterFilter whose output depends only on current and past input samplesLinear phase, always stable
IIR filterFilter whose output depends on past inputs and past outputs (feedback)Sharper response, possible instability
Filter coefficientsThe numeric weights (h[k], b[k], a[j]) that define a filter's behaviorFilter order
Filter orderThe number of past samples used in the filter's calculationRoll-off steepness
Windowing methodFIR design technique: truncating an ideal impulse response with a window functionHamming, Hanning windows
Bilinear transformationMaps an analog filter design onto an equivalent digital IIR filterButterworth, Chebyshev filters
Linear phaseProperty where all frequencies are delayed by the same amount, preserving waveform shapeFIR filters, symmetric coefficients

Common Mistakes

Misconception: IIR filters are strictly better than FIR filters because they need fewer coefficients. Why it's wrong: Fewer coefficients means less computation, but IIR filters trade this for potential instability and nonlinear phase distortion — problems FIR filters don't have. Correct understanding: The choice depends on the application: FIR when guaranteed stability and linear phase matter (audio, biomedical), IIR when computational efficiency and a sharp cutoff matter more than phase linearity (many real-time control and communications tasks).


Misconception: "Finite" and "Infinite" in FIR/IIR refer to the length of the input signal. Why it's wrong: They refer to the duration of the filter's impulse response — how long the filter's output rings on after a single impulse input — not to the signal being filtered. Correct understanding: An FIR filter's impulse response dies out completely after a finite number of samples (equal to its order); an IIR filter's impulse response, due to feedback, in principle continues forever (though it typically decays toward zero in a stable design).


Misconception: A digital filter with more coefficients (higher order) is always a better filter. Why it's wrong: More coefficients cost more computation and add more delay (latency) between input and output — a genuine problem for real-time systems. Correct understanding: Filter order should be chosen as the minimum that meets the required roll-off and ripple specifications; over-designing wastes computation and adds unnecessary latency.

Comparison and Connections

PropertyFIR FilterIIR Filter
FeedbackNone (feedforward only)Yes (uses past outputs)
StabilityAlways stableCan be unstable if poorly designed
Phase responseCan be exactly linearGenerally nonlinear
Coefficients needed for sharp cutoffManyFew
Computational cost per sampleHigher (more taps)Lower (fewer coefficients)
Typical design methodWindowing, frequency samplingBilinear transform from analog prototype

Practice Questions

Recall

  1. Write the difference equation for an FIR filter and identify each symbol. Answer guidance: y[n] = Σ(k=0 to M) h[k]x[n-k]; y[n] is the output, x[n] is the input, h[k] are the filter coefficients, M is the filter order.

  2. Name three techniques used to design digital filters. Answer guidance: Windowing method, bilinear transformation, and frequency sampling method.

Understanding

  1. Explain why an FIR filter is inherently stable while an IIR filter can become unstable. Answer guidance: An FIR filter's output depends only on past and current inputs — there is no feedback loop that can cause the output to grow without bound. An IIR filter feeds past outputs back into the calculation, and if the feedback coefficients place a pole outside the unit circle, the output can grow unbounded, i.e., become unstable.

  2. Why can an FIR filter be designed with exactly linear phase, but a typical IIR filter cannot? Answer guidance: Linear phase requires the impulse response to be symmetric (or anti-symmetric) around its center — achievable in a finite-length FIR filter by construction. IIR filters, because of their feedback structure and rational transfer function, generally cannot achieve exact symmetry in their impulse response, so their phase response is nonlinear.

Application

  1. You need to filter an ECG signal where preserving the exact shape of the QRS complex (no phase distortion) is critical, and computational cost is not a major constraint. Which filter type would you choose, and why? Answer guidance: FIR, designed with linear phase, because preserving waveform shape (no phase distortion) is the priority and the application can tolerate the extra computation of a higher-order filter.

  2. A real-time embedded system has very limited processing power but needs a sharp low-pass cutoff at 1 kHz. Which filter type is more practical, and what design method would you use? Answer guidance: IIR, because it achieves a sharp cutoff with far fewer coefficients, reducing computational load. It would typically be designed using the bilinear transformation from an analog Butterworth or Chebyshev prototype.

Analysis

  1. Compare the trade-offs of increasing filter order for an FIR filter versus increasing filter order for an IIR filter. Answer guidance: For FIR, a higher order gives a sharper cutoff and more control over ripple, at the cost of more computation and added latency (group delay), but stability is never at risk. For IIR, a higher order can achieve a sharper cutoff with much less added computation than an equivalent FIR order, but it increases the risk of numerical instability and makes the phase response more nonlinear.

  2. A student claims that using more filter coefficients always makes the filtered output "more accurate." Evaluate this claim using the FIR/IIR comparison as context. Answer guidance: This is an oversimplification. More coefficients can sharpen the transition between passband and stopband, but "accuracy" also depends on phase distortion, added latency, and whether the extra sharpness is even needed for the application. An over-designed filter wastes resources without improving the outcome relevant to the task.

FAQ

Do digital filters completely replace analog filters? Not entirely — a signal must be sampled (converted from analog to digital) before a digital filter can process it, and that sampling step itself needs an analog anti-aliasing filter beforehand. In practice, systems use a simple analog filter before the ADC and do the bulk of the filtering work digitally afterward.

Why are Butterworth, Chebyshev, and elliptic filters usually implemented as IIR filters? These are classic analog filter designs. The bilinear transformation converts their well-understood analog transfer functions directly into digital IIR filters, inheriting the sharp roll-off characteristics of the analog prototype with relatively few coefficients.

What does "filter order" mean in practical terms? It's the number of past samples (and, for IIR filters, past outputs) the filter uses to compute each new output. Higher order generally means a sharper transition between passband and stopband but also more computation and more delay.

Can a filter be both FIR and have zero phase distortion in a non-real-time context? Yes — applying a filter forward and then backward through the same data (as scipy.signal.filtfilt does) cancels out phase distortion entirely, even for an IIR filter, but this requires having the whole signal in memory already, so it only works offline, not in real time.

Why do audio engineers care so much about linear phase? Nonlinear phase distorts the relative timing of different frequency components in a signal, which can smear transients and alter the perceived timbre of a sound. For monitoring and mastering audio, linear-phase FIR filters preserve waveform shape more faithfully.

Quick Revision

  • A digital filter reshapes a signal's frequency content using arithmetic on sample values, not physical components
  • FIR: y[n] = Σ h[k]x[n-k] — feedforward only, always stable, can have exact linear phase
  • IIR: y[n] = Σ b[k]x[n-k] − Σ a[j]y[n-j] — feedback included, sharper response with fewer coefficients, but risk of instability and phase distortion
  • Windowing method designs FIR filters by truncating an ideal impulse response with a window function
  • Bilinear transformation converts analog filter designs (Butterworth, Chebyshev) into digital IIR filters
  • FIR needs more coefficients for a sharp cutoff; IIR needs fewer but risks instability
  • Filter order controls the trade-off between roll-off steepness and computational cost/latency
  • scipy.signal.butter designs IIR filters; scipy.signal.firwin designs FIR filters
  • filtfilt cancels phase distortion by filtering forward and backward, but only works offline
  • Choose FIR for guaranteed stability and linear phase; choose IIR for efficiency and sharp cutoffs when phase distortion is tolerable

Prerequisites: Introduction to Signal Processing, Frequency-Domain Analysis, Fourier Transform

Related Topics: Fourier Transform, Frequency-Domain Analysis, Signal Sampling and Reconstruction

Next Topics: Signal Sampling and Reconstruction, Signal Compression