Sound into numbers
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.
Each sample is stored as a 16-bit integer from −32768 to +32767: 65,536 levels. A full-scale sine then sits about 98.1 dB above the rounding noise. Two channels cost 1,411,200 bits every second.
Seeing sound: the spectrogram
Our recording: notes A4, C#5 and E5, a quarter second each, plus a faint 3 kHz whine. We cut it into frames of 1024 samples (23.2 ms), each shaped by a Hann window, starting every 512 samples.
The FFT turns frame 10 into 513 frequency bins, 43.1 Hz apart (fs/N). Two peaks stand out: the 440 Hz note at −6.3 dBFS and the 3 kHz whine at −26.7 dBFS.
Do that for all 63 frames and stand the spectra side by side: time across, frequency up, loudness as colour. The three notes climb like stairs; the whine is a thin line at 3 kHz all the way through.
A frame of N samples lasts N/fs and its bins are fs/N apart: the product is always 1. N = 1024 gives 23.2 ms and 43.1 Hz; N = 4096 sharpens bins to 10.8 Hz but blurs time to 92.9 ms.
Shaping sound: the equaliser
An equaliser turns some frequencies up or down. A parametric band has three knobs: centre frequency, gain and width (Q). We set one band to 3 kHz, −18 dB, Q = 4: a narrow dip right on the whine.
The band is a biquad: each output mixes the last three inputs and two outputs. y[n] = b0·x[n] + b1·x[n−1] + b2·x[n−2] − a1·y[n−1] − a2·y[n−2]. That is 220,500 multiplies a second per channel.
Run every sample through the band and look again. The whine drops from −26.7 to −44.7 dBFS, 18 dB down; the note still reads −6.3 dBFS. On the spectrogram the 3 kHz line fades; the stairs stay.
In code
With numpy and scipy, signal.spectrogram computes the whole picture: Hann frames of 1024, overlap 512. signal.lfilter runs the biquad over every sample, given b and a from the cookbook formulas.
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.