Digital audio: 44.1 kHz, equalisers and spectrograms
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A stand-alone deep dive into how sound lives in a computer. Follow one short recording, three notes with an annoying 3 kHz whine, from the microphone to 44,100 sixteen-bit samples a second, see it as a spectrogram built from Hann-windowed FFT frames, then remove the whine with one equaliser band, a biquad filter, and do it all in Python with scipy. It builds on the lessons on sampling, quantization, the DFT and FFT, windowing and IIR filters; this lesson links to them rather than teaching them again.
Why 44.1 kHz
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.
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)
اقرأ الدرس خطوة بخطوة
Why 44.1 kHz
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.
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)16 bits per sample
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.
q[n] = round(32767 · x[n]) (int16) q[0..4] = 0, 1706, 3285, 4634, 5688 levels 2^16 = 65,536 range 6.02 · 16 + 1.76 = 98.1 dB (full-scale sine vs rounding noise) bit rate 44100 × 16 bits × 2 channels = 1,411,200 bit/s = 1411.2 kbit/s the samples arrive every 1/44100 s = 22.7 µsCut the sound into frames
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.
x[n] = 0.5·sin(note) + 0.05·sin(2π·3000·n/fs) notes A4 440 Hz, C#5 554.37 Hz, E5 659.26 Hz (equal temperament: 440 · 2^(k/12)) whine 3000 Hz, 20 dB quieter than a note frame N = 1024 samples = 23.2 ms hop 512 samples = 11.6 ms (50 % overlap) Hann w[n] = 0.5 − 0.5·cos(2πn/N) fades each frame in and out 0.75 s -> 63 framesOne frame, one spectrum
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.
frame 10: samples 5120 .. 6143 (116 .. 139 ms) X[k] = Σ w[n]·x[n]·e^(−j2πkn/N), k = 0 .. 512 bin spacing fs / N = 44100 / 1024 = 43.1 Hz level 20·log10(|X[k]| / (N/4)) dBFS (a full-scale sine reads 0 dBFS) note bin 10 (431 Hz) −6.3 dBFS whine bin 70 (3015 Hz) −26.7 dBFS 0.5 -> −6.0 dB, 0.05 -> −26.0 dB, less the loss when a tone falls between binsStack the spectra: a spectrogram
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.
spectrogram = |STFT|², drawn in dB column m = spectrum of frame m 63 columns × 513 bins (0 .. 4 kHz shown) colour steps of 12 dB: ≥ −12, −24, −36, −48, −60, −72 dBFS quieter cells are left blank a frame that straddles two notes shows both of themTime or frequency: pick one
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.
duration × bin spacing = (N/fs) × (fs/N) = 1 N duration bin spacing 512 11.6 ms 86.1 Hz 1024 23.2 ms 43.1 Hz 4096 92.9 ms 10.8 Hz long frames: sharp pitch, smeared onsets short frames: sharp onsets, smeared pitchAn equaliser band
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.
peaking band (Audio EQ Cookbook, R. Bristow-Johnson) f0 = 3000 Hz, gain = −18 dB, Q = 4 A = 10^(gain/40), w0 = 2π·f0/fs α = sin(w0) / (2Q) |H| at 3000 Hz −18.00 dB |H| at the notes: never below −0.11 dB |H| at 1 kHz −0.28 dB a graphic EQ is a row of such bands, each at its own fixed frequencyFive multiplies per sample
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.
Direct Form 1 (a0 scaled to 1): b0 = 0.88861 a1 = −1.58814 b1 = −1.58814 a2 = 0.74514 b2 = 0.85653 5 multiplies × 44100 samples/s = 220,500 multiplies/s per channel feedback (a1, a2) makes it an IIR filter: one biquad gives a sharp, cheap bandThe whine is gone, the notes stay
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.
frame 10, before -> after the EQ note −6.3 -> −6.3 dBFS whine −26.7 -> −44.7 dBFS 18 dB less = 1/8 of the amplitude the output goes to a DAC and a speaker (see the lesson on reconstruction)The same in Python
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.
from scipy import signal f, t, S = signal.spectrogram( x, fs, 'hann', 1024, 512) y = signal.lfilter(b, a, x) # x: float array, fs = 44100 # S: power per bin and frame; # 10*np.log10(S) gives dB # f: 513 bin frequencies, t: 63 frame centres # b, a: the peakingEQ coefficients (Python 3, numpy, scipy)
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01Why is the CD rate 44.1 kHz and not exactly 40 kHz?
Sampling must be faster than twice 20 kHz. A real low-pass filter cannot drop from pass to block instantly, so 44.1 kHz gives it 2.05 kHz of room below fs/2 = 22.05 kHz. The exact value came from video-based PCM recorders.
02What is the bit rate of stereo CD audio (44,100 samples/s, 16 bits, 2 channels)?
44,100 × 16 × 2 = 1,411,200 bits per second, which is 1411.2 kbit/s.
03You switch the spectrogram from 1024-sample frames to 4096-sample frames at 44.1 kHz. What happens?
Duration N/fs and bin spacing fs/N multiply to 1: a longer frame sharpens frequency and blurs time.
04A peaking EQ band is set to 3 kHz, −18 dB. By how much does it scale the amplitude of a steady 3 kHz tone?
−18 dB means 10^(−18/20) ≈ 0.126, about one eighth of the amplitude. Tones far from 3 kHz are hardly touched.
05How many multiplications does one biquad (b0, b1, b2, a1, a2) need per second for one 44.1 kHz channel?
Five multiplies per output sample × 44,100 samples per second = 220,500.
المسرد
- Nyquist frequency
- Half the sampling rate, fs/2: the highest frequency the samples can represent without aliasing. 22.05 kHz for CD audio.
- PCM, bit depth
- Pulse-code modulation stores each sample as an integer; the bit depth (16 for CD) sets the number of levels, 2^16 = 65,536.
- dBFS
- Decibels relative to full scale: 0 dBFS is the loudest sine the format can hold; quieter sounds are negative.
- Frame, hop, window
- A frame is a block of N samples analysed together; the hop is how far the next frame starts; the window (here Hann) fades each frame in and out to reduce leakage.
- Spectrogram
- The magnitude squared of the short-time Fourier transform, drawn as an image: time across, frequency up, level as colour.
- Equaliser (EQ)
- A set of filters that turn chosen frequency bands up or down. A parametric band has a centre frequency, a gain and a width (Q).
- Biquad
- A second-order IIR filter: each output uses three inputs and two past outputs, y[n] = b0x[n] + b1x[n−1] + b2x[n−2] − a1y[n−1] − a2y[n−2].
الملاحظات والمصادر
- 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.
- 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.
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing, readings: Oppenheim, Schafer & Buck, Discrete-Time Signal Processing (sampling, DFT/FFT, time-dependent Fourier analysis, quantization noise)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011)
- W3C Audio EQ Cookbook (R. Bristow-Johnson, ed. R. Toy, 2021): peakingEQ coefficients and Direct Form 1
- 44,100 Hz (Wikipedia): 20 kHz hearing, sampling theorem, 2.05 kHz transition band, PCM adaptor origin
- Compact Disc Digital Audio (Wikipedia): 16-bit signed samples, 2 channels, 1411.2 kbit/s, IEC 60908
- Audio bit depth (Wikipedia): SQNR ≈ 6.02·b + 1.76 dB, 98.09 dB at 16 bits
- Short-time Fourier transform (Wikipedia): frames, windows, spectrogram = |STFT|², resolution trade-off
- Equalization (audio) (Wikipedia): graphic and parametric equalisers
- Piano key frequencies (Wikipedia): f = 440·2^((n−49)/12), C#5 = 554.37 Hz, E5 = 659.26 Hz
- SciPy documentation: scipy.signal.spectrogram
- SciPy documentation: scipy.signal.get_window (periodic windows by default)
- SciPy documentation: scipy.signal.windows.hann
- SciPy documentation: scipy.signal.lfilter
- NumPy documentation: numpy.fft.rfft (n//2 + 1 bins)
اختبار يتاح بعد الخطوة الأخيرة.