ENع
←Linear phase
Lesson 41 · Digital filter design

Linear phase and group delay

16 min10 steps5 questionsAdvanced
About this lesson

A filter changes the size of each frequency, and it also delays it. Follow two packets, short bursts at 250 Hz and 750 Hz, through two filters with exactly the same gain. Filter A, the 21-tap Hamming lowpass from the windowing lesson, has mirror-image taps: its phase is a straight line, φ = −10ω, and both packets come out 10 samples (1.25 ms) late, together. Filter B, its minimum-phase twin, is quicker but delays them by 3.87 and 5.41 samples. You will meet phase delay and group delay, see why symmetry gives linear phase, and measure it with scipy. It builds on the frequency response and poles and zeros lessons, and on the Circuits lessons on filters and Bode plots.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 41 · Interactive
01 / 10

Two packets of sound

A packet is a short burst of one sine wave. The source sends two at once: a low one at 250 Hz and a high one at 750 Hz, sampled 8000 times a second. The question: how late does each come out of a filter?

packet = a short burst of a sine wave
         (one frequency, a smooth on and off)

low   f = 250 Hz   ω = 2π·250/8000 = 0.196 rad/sample
high  f = 750 Hz   ω = 2π·750/8000 = 0.589 rad/sample

fs = 8000 samples per second
1 sample = 0.125 ms
Loading figure…
or ← →
Read the lesson step by step
  1. Two packets of sound

    A packet is a short burst of one sine wave. The source sends two at once: a low one at 250 Hz and a high one at 750 Hz, sampled 8000 times a second. The question: how late does each come out of a filter?

    packet = a short burst of a sine wave
             (one frequency, a smooth on and off)
    
    low   f = 250 Hz   ω = 2π·250/8000 = 0.196 rad/sample
    high  f = 750 Hz   ω = 2π·750/8000 = 0.589 rad/sample
    
    fs = 8000 samples per second
    1 sample = 0.125 ms
  2. Filter A: mirror-image taps

    Filter A is the 21-tap Hamming lowpass from the windowing lesson, cutoff 1000 Hz. Its taps are a mirror image around the middle one: h[n] = h[20 − n]. Fold the plot at n = 10 and the halves match.

    y[n] = h[0]·x[n] + h[1]·x[n−1] + ... + h[20]·x[n−20]
    
    h[9]  = 0.2200
    h[10] = 0.2500   (the middle tap)
    h[11] = 0.2200
    
    h[n] = h[20 − n] for every n: symmetric
    gain at 0 Hz = sum of taps = 1.004
  3. Every packet waits 10 samples

    Send both packets through A. Each comes out exactly 10 samples (1.25 ms) after it went in, low and high alike. They arrive together, so a pulse or a sound made of both keeps its shape.

    packet     delay through A
    250 Hz     10.00 samples = 1.25 ms
    750 Hz     10.00 samples = 1.25 ms
    
    sizes change by the gain:
    |H| = 1.001 at 250 Hz, 0.807 at 750 Hz
    timing does not change between them
    
    motion: slowed down, n counted in samples
  4. Phase falls in a straight line

    Delaying a tone by D samples turns it by −ω·D radians. So A's phase is φ(ω) = −10ω: a straight line through zero. At 250 Hz that is −1.96 rad; at 750 Hz, −5.89 rad. This is linear phase.

    pure delay of D samples:
      H(e^jω) = e^(−jωD),  φ(ω) = −ωD
    
    filter A:  φ(ω) = −10ω
      ω = 0.196  ->  φ = −1.96 rad
      ω = 0.589  ->  φ = −5.89 rad
    
    plot: φ unwrapped from 0 Hz
    (np.angle would wrap −5.89 to 0.39)
  5. Why mirror taps give a line

    Pair the taps: h[0] with h[20], h[1] with h[19], and so on. Each pair sits the same distance either side of n = 10, so their two turns average to the middle one. Every pair points along e^(−j10ω).

    one pair, k and 20 − k (equal taps):
      h[k]·e^(−jωk) + h[k]·e^(−jω(20−k))
      = e^(−j10ω) · 2h[k]·cos(ω(10 − k))
    
    add all pairs and the middle tap:
      H(e^jω) = e^(−j10ω) · A(ω),  A(ω) real
    
    so φ = −10ω (plus π where A(ω) < 0,
    only in the stopband here)
  6. Group delay is the slope

    Group delay is how late a packet's envelope arrives: τ(ω) = −dφ/dω, the downhill slope of the phase. A straight line has the same slope everywhere, so A gives τ = 10 samples at every frequency.

    group delay   τg(ω) = −dφ/dω   (the envelope)
    phase delay   τp(ω) = −φ(ω)/ω  (the crests)
    
    filter A: φ = −10ω
      τg = 10 samples at every ω
      τp = 10 samples in the passband
      (in the stopband A(ω) < 0 adds π)
    
    linear phase: both equal and constant
    = the filter's delay, (L − 1)/2 = 10
  7. Filter B: same gains, lopsided taps

    Filter B has exactly A's gain at every frequency. It was built from A's zeros, with those outside the unit circle flipped inside (a minimum-phase filter). Its taps bunch up at the start and are not symmetric.

    zeros of A: 20 (np.roots)
      12 on the unit circle (the stopband)
       8 off it, in pairs r and 1/r
    flip each zero with |z| > 1 to 1/z*
      -> |H_B| = |H_A| at every frequency
    
    B taps: h[0] = 0.014, h[4] = 0.239
            h[20] = 0.0005   (not a mirror)
  8. B is quicker, but uneven

    Through B the 250 Hz packet takes 3.87 samples and the 750 Hz packet 5.41. Both arrive sooner than with A, but not together. B's phase curve bends, so its slope, the delay, changes with frequency.

    packet     delay through B
    250 Hz     3.87 samples = 0.48 ms
    750 Hz     5.41 samples = 0.68 ms
    spread     1.53 samples
    
    phase of B: −0.73 rad at 250 Hz
                −2.53 rad at 750 Hz
    not −ω·(one number): not linear
    
    uneven delay = phase distortion
  9. In Python: group_delay

    scipy.signal.group_delay takes a filter as (b, a) and the frequencies in hertz when you give fs. For filter A it prints 10 samples at both 250 and 750 Hz. np.sinc(m/4)/4 is the delayed ideal lowpass.

    import numpy as np
    from scipy.signal import group_delay
    m = np.arange(21) - 10
    h = np.sinc(m/4)/4 * np.hamming(21)
    group_delay((h, 1), [250, 750], fs=8000)
    
    (array([250., 750.]), array([10., 10.]))
    
    (h, 1): FIR, so a = 1
    the twin B gives ≈ [3.87, 5.41]
    (Python 3 with numpy and scipy)
  10. The price is latency

    A symmetric 21-tap filter always waits 10 samples (1.25 ms). Audio, ECG and data receivers pay that to keep shapes. Control loops often prefer a quick filter like B. Offline, filtfilt runs a filter forward then backward: zero phase.

    symmetric L taps -> delay (L − 1)/2 samples
      21 taps at 8000/s -> 1.25 ms
    
    linear phase (A): shapes kept, fixed delay
    minimum phase (B): least delay, uneven
    
    recorded data: scipy.signal.filtfilt
      forward, then backward in time
      the two phases cancel: zero phase
      (needs the whole signal first)

Quiz Unlocks after the last step.