Sampling and Quantization

Nyquist-Shannon Sampling Theorem
A continuous signal with maximum frequency f_max can be perfectly reconstructed from its samples if the sampling rate f_s > 2·f_max.
f_s > 2·f_max (Nyquist rate = 2·f_max)
Nyquist frequency: f_s/2 — the maximum frequency representable at sampling rate f_s.
Aliasing
When f_s < 2·f_max, high frequencies fold back into the representable range, creating false low-frequency components (aliases).
Example: A 15 kHz tone sampled at 20 kHz appears as a 5 kHz tone (15 kHz aliases to 20 - 15 = 5 kHz).
Prevention: Apply an anti-aliasing filter (low-pass) before sampling, cutting off frequencies above f_s/2.
CD audio: f_s = 44.1 kHz. Nyquist = 22.05 kHz. Human hearing: ~20 Hz – 20 kHz. Anti-aliasing filter cuts above ~20 kHz.
Sample Rate Conversion
Upsampling (Interpolation)
Increase the sampling rate by factor L:
- Insert L-1 zeros between each sample.
- Apply a low-pass filter (interpolation filter) to smooth.
Downsampling (Decimation)
Decrease the sampling rate by factor M:
- Apply a low-pass anti-aliasing filter (cutoff at π/M).
- Keep every M-th sample.
Polyphase Filters
Efficient implementation of sample rate conversion. Decompose the filter into M subfilters, each operating at the lower rate. Avoids computing samples that will be discarded.
Arbitrary Rate Conversion
Combine upsampling by L and downsampling by M: effective rate change = L/M. Or use polynomial interpolation for non-integer ratios.
Quantization
Map continuous amplitude values to a finite set of discrete levels.
Uniform Quantization
Equal step sizes. For B bits: 2^B levels.
Step size: Δ = (x_max - x_min) / 2^B
Quantization: Q(x) = round(x / Δ) × Δ
Quantization noise: Modeled as additive uniform noise in [-Δ/2, Δ/2]. Variance = Δ²/12.
SNR (Signal-to-Noise Ratio): For a full-scale sinusoid with B-bit quantization:
SNR = 6.02B + 1.76 dB
Each additional bit adds ~6 dB of dynamic range.
| Bits | Levels | SNR | Application | |---|---|---|---| | 8 | 256 | ~50 dB | Telephony, basic audio | | 16 | 65536 | ~98 dB | CD audio | | 24 | 16M | ~146 dB | Professional audio, recording | | 32 | 4G | ~194 dB | Scientific measurement |
Non-Uniform Quantization
More levels where the signal is likely to be (near zero for speech).
μ-law (North America, Japan): Compress before uniform quantization.
F(x) = sgn(x) × ln(1 + μ|x|) / ln(1 + μ) (μ = 255)
A-law (Europe): Similar compression.
Both used in telephony (G.711 codec) to achieve ~13-bit quality with 8 bits.
Oversampling
Sample at rate >> Nyquist, then quantize. Spreads quantization noise over a wider bandwidth. After digital low-pass filtering and decimation: more effective bits.
Rule: Oversampling by 4× gives +1 effective bit (6 dB improvement).
Sigma-Delta (ΣΔ) modulation: Extreme oversampling (64-256×) with 1-bit quantization + noise shaping. Pushes quantization noise to high frequencies where it's filtered out. Used in high-quality audio ADCs and DACs.
Applications in CS
- Audio/video: Sampling rates (44.1/48/96 kHz audio, 30/60 fps video), bit depth selection.
- IoT sensors: ADC resolution and sampling rate tradeoffs for power vs accuracy.
- Software-defined radio: Sample rate conversion, decimation, interpolation in digital receivers.
- Machine learning: Feature extraction from audio requires proper sampling and quantization. Model quantization (FP32 → INT8) for inference.