1import numpy as np2from scipy.signal import group_delay3m = np.arange(21) - 104h = np.sinc(m/4)/4 * np.hamming(21)5group_delay((h, 1), [250, 750], fs=8000)n = 0.00250 Hz: –750 Hz: –250 Hz: –750 Hz: –
0510152000.10.2n (tap number)h[n]TAPS h[n]ABh[n] = h[20 − n]02505007501000-8-6-4-20f (Hz)φ (rad)PHASE φ (passband)AB02505007501000024681012f (Hz)τ (samples)GROUP DELAY τ (passband)AB
Coloured parts: what the current step is about; everything else rests in whiteBlocks: packet source, filter A (symmetric taps on its face), filter B (its twin), two outputs and a Python cardPlots: the taps h[n], the phase φ and the group delay τ of both filters, 0 to 1000 HzPackets cross each filter in its group delay, counted in samples (slow motion)Two packets at 250 and 750 Hz go through a symmetric 21-tap lowpass (linear phase, 10 samples late at every frequency) and its minimum-phase twin (same gain, 3.87 and 5.41 samples). Symmetric taps with an odd length (Type I) are one of four kinds of linear-phase FIR filter: symmetric or antisymmetric taps, odd or even length. Where the real amplitude A(ω) changes sign the phase jumps by π, but the group delay stays (L − 1)/2.

A symmetric filter

  1. 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?

Phase and group delay

A lopsided twin

In code and in practice

The working

# step 1/10 · packets

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

Filter A is the Hamming-windowed 21-tap lowpass (cutoff 1000 Hz at 8000 samples a second) designed in the windowing lesson. Filter B is computed from A's zeros. Every number and curve in the figure is computed from these taps. A packet's envelope is delayed by the group delay at its frequency when the packet is narrow in frequency (Oppenheim and Schafer §5.1). The motion is slowed down and counted in samples.