ADCFIR↓3bypassy[0]–y[1]–y[2]–1from scipy import signal2h = signal.firwin(61, 1/3)3v = signal.lfilter(h, 1, x)4y = v[::3]012345678
00.250.50.751-1-0.500.51t (ms)valueSAMPLESx[n]: 48 per mskept: x[0], x[3], x[6] ...kept: 16 per mskept samples: 1 kHz − 6 kHzx[n]: 48 per msx[n]: 48 per msfiltered v[n], kept every 3rdonly kept v[n] computedy = v[::3]fs/(2M)folds after ↓30481216202400.51f (kHz)peak · gainSPECTRUM1 kHz and 10 kHz, 0.5 each1 kHz and 10 kHz, 0.5 eachnew fs/2 = 8 kHz10 kHz folds to 6 kHz: 0.50FIR gain |H(f)|, cutoff 8 kHzgains 1.002 and 0.0008alias 0.0004 at 6 kHzalias 0.0004 at 6 kHzfirwin(61, 1/3)
Coloured parts: what the current step is about; everything else rests in whiteBlocks: converter (ADC), FIR low-pass filter chip, bypass switch, the keep-1-in-3 block (↓3), output cells and a Python code cardPlots: the samples over 1 ms with the kept ones ringed, and the spectrum with the new fs/2, tone bars and the filter's gainNumbered sample tokens and the folding whistle bar move in slow motion; dropped tokens fall awayAudio at 48000 samples a second (a 1000 Hz tone and a 10000 Hz whistle, 0.5 each) drops to 16000 by keeping one sample in three. Without a filter the whistle folds to 6000 Hz at 0.50; after a 61-tap FIR low-pass (cutoff 8000 Hz) it lands at 0.0004. Real decimation filters put the cutoff a little below fs/(2M) so the transition band (here 8 kHz is already −6 dB) does not let anything fold into the band you keep; this filter is fine for a 7 kHz speech band.

Fewer samples

  1. Audio arrives as samples x[n], 48 000 a second, one every 20.8 µs. It holds a 1 kHz tone we want and a 10 kHz whistle we do not, 0.5 each. A speech system needs only 16 000 samples a second.

Aliasing again

Filter first

In practice

The working

# step 1/9 · rate

fs = 48 000 samples per second
Ts = 1 / fs = 20.8 µs

x[n] = 0.5·sin(2π·1000·n/fs)
     + 0.5·sin(2π·10000·n/fs)

goal: fs' = 16 000 per second
      48 000 / 16 000 = 3 = M

plots: x[n] over 1 ms (48 samples),
and its spectrum (DFT of 96 samples:
1000 Hz 0.50, 10000 Hz 0.50)

48 000 samples a second is the standard rate of professional video and audio; 16 000 is the wideband speech rate of ITU-T G.722 (audio up to 7 kHz). The two tones of 0.5 each are a chosen example. The filter is scipy.signal.firwin(61, 1/3), the same filter scipy.signal.decimate(x, 3, ftype="fir") uses. Filtered values are the steady state, after the first 60 samples. Every number is computed from this model. The motion is slowed down a great deal: real samples arrive every 20.8 µs.