ADCq[0]–q[1]–q[2]–q[3]–q[4]–FFT1from scipy import signal2f, t, S = signal.spectrogram(3 x, fs, 'hann', 1024, 512)4y = signal.lfilter(b, a, x)EQqy
201001k10k−100−80−60−40−200f (Hz)level (dBFS)SPECTRUM OF FRAME 10beforeafter EQ20 kHzhearingfs/2 = 22.05 kHz440 Hz −6.33 kHz −26.743.1 Hz per bin−26.7 → −44.7whine 18 dB down201001k10k−18−12−60f (Hz)gain (dB)EQ BAND |H(f)|f0 3 kHz · −18 dB · Q 4220,500 mult/s00.250.50.7501k2k3k4kt (s)f (Hz)SPECTROGRAMframe 10: 116–139 ms3 kHz whineA4C#5E563 framesN 1024: 23.2 ms · 43.1 Hz23.2 mswhine −18 dBafter the EQ
Coloured parts: what the current step is about; everything else rests in whiteBlocks: microphone, converter (ADC), sample memory, FFT, equaliser (EQ), speaker and a Python code cardPlots: one frame's spectrum, the EQ band's gain and the spectrogramSamples, frames and the filtered stream move in slow motion; the yellow band marks the frame being analysedA 0.75 s recording (three notes and a 3 kHz whine) sampled at 44100 Hz in 16 bits, analysed in Hann frames of 1024 samples (hop 512) and cleaned by one peaking EQ band (3 kHz, −18 dB, Q 4). The equaliser band uses the peakingEQ formulas of the Audio EQ Cookbook (W3C Note, 2021), where gain is the level at f0 and Q sets the width.

Sound into numbers

  1. We hear up to about 20 kHz. The sampling theorem says: sample faster than twice the highest frequency. At 44,100 samples a second the limit, fs/2, is 22.05 kHz, leaving 2.05 kHz for the anti-alias filter to roll off.

Seeing sound: the spectrogram

Shaping sound: the equaliser

In code

The working

# step 1/10 · rate

hearing        about 20 Hz .. 20 kHz
sampling rule  fs > 2 · fmax  ->  fs > 40 kHz

CD rate        fs   = 44100 samples/s
Nyquist        fs/2 = 22050 Hz
guard band     22050 − 20000 = 2050 Hz

the analog low-pass (anti-alias) filter must
pass 20 kHz and block everything above 22.05 kHz
(see the lessons on sampling and anti-aliasing)

The recording is a constructed example: three equal-tempered notes at half of full scale and a 3 kHz whine at one twentieth, 0.75 s at 44100 samples a second, stored as 16-bit integers. Every number, curve and spectrogram cell in the figure is computed from it (FFT, Hann window, biquad). The spectrum plot stops at −100 dBFS; quieter bins are drawn on its floor. The 16-bit rounding noise of this recording is spread over 513 bins and lies below that line. The motion is slowed down a great deal: a real frame lasts 23.2 ms and samples arrive every 22.7 µs.