Digital audio: sampling and quantisation
How continuous audio becomes digital: sampling converts time axis to discrete times (Nyquist condition, aliasing) and quantisation maps amplitudes to discrete levels (step size, quantisation noise, SNR, bit depth, PCM).
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two sentences: Engineers convert microphone signals and analog audio sources into digital form for storage, processing and transmission. Correct choice of sampling rate and quantisation (bit depth) decides whether the audio is faithful (no aliasing, acceptable noise) and how large the resulting data is.
Key ideas
Define terms before use. Bolded terms are defined the first time they appear.
- Analog signal: a continuously varying electric quantity (voltage vs time) representing sound.
- Sampling: measuring the value of a continuous-time signal at discrete times. If the continuous-time signal is x(t), sampling at interval T_s produces samples x[n] = x(n·T_s) where n is an integer. The sampling frequency is f_s = 1/T_s (unit Hz).
- Bandlimited signal: a signal whose continuous-time Fourier transform X(f) = 0 for |f| > f_m for some finite f_m (Hz). f_m is the highest frequency present.
- Nyquist rate: minimum sampling frequency for perfect reconstruction of a bandlimited signal. The Nyquist rate is 2·f_m. The Nyquist frequency is f_s/2.
Exact statement (Nyquist–Shannon sampling theorem) used in exams:
- If x(t) is bandlimited with maximum frequency f_m (i.e. X(f)=0 for |f|>f_m), and the sampling frequency f_s satisfies f_s > 2·f_m (strict inequality to avoid boundary problems) then x(t) is uniquely determined by its samples x[n] = x(n·T_s) and can be reconstructed by ideal low-pass interpolation (sinc interpolation). Explicit reconstruction formula: x(t) = Σ_{n=-∞}^{∞} x[n] · sinc((t - nT_s)/T_s) with sinc(u) = sin(πu)/(πu). Assumptions: ideal bandlimit, infinite-duration sinc reconstruction, no noise.
Derivation exam steps often asked (standard sketch):
- Write sampled signal as x_s(t) = x(t) · Σ_n δ(t - nT_s) (impulse sampling model).
- In frequency domain this multiplies into convolution: X_s(f) = (1/T_s)·Σ_k X(f - k f_s) (spectrum copies shifted by multiples of f_s; amplitude scaled by 1/T_s).
- If f_s > 2·f_m the shifted spectra X(f-k f_s) do not overlap for different k. Low-pass filter with cutoff between f_m and f_s - f_m will pass original X(f) while rejecting other copies. Hence perfect reconstruction is possible.
Aliasing: if f_s ≤ 2·f_m (or if f_s is insufficient for the highest component present), the shifted spectral copies overlap and cannot be separated. High-frequency components fold into lower frequencies—this is aliasing. Exam diagram to draw: frequency axis showing original spectrum centered at 0, copies at ±f_s, and overlapping regions; label f_s/2 as Nyquist frequency and indicate alias-folded component frequency.
Anti-aliasing filter: a low-pass analog filter applied before sampling to make the input bandlimited (suppress frequencies above the passband); in practice the cutoff is set below f_s/2 to allow a transition band. Practical requirement because ideal filters don't exist.
Quantisation: mapping each sampled amplitude (a real number) to one of a finite set of discrete levels. The number of levels is L = 2^b for b bits per sample. A uniform quantiser divides the allowed amplitude range into equal steps of width Δ (the step size). A mid-tread and mid-rise describe whether a level is centered on zero or there is a step crossing zero—explain only if asked.
Quantisation error (noise): e[n] = q(x[n]) - x[n]; for a uniform quantiser with step Δ and assuming the quantisation error is uniformly distributed in [-Δ/2, +Δ/2] and uncorrelated with the signal (standard exam assumption for full-scale, busy signals), the mean squared quantisation noise power is Δ^2/12. This assumption is approximate but widely used in exam problems and engineering estimates. In audio practice, adding low-level dither (e.g., TPDF) before quantisation randomises the error, making the uniform-noise model valid and preventing tonal distortion; exams may ask for a short note on dithering.
Derivation of SNR for a full-scale sine in a uniform b-bit quantiser (exam derivation often required):
- Full-scale sine amplitude: peak-to-peak range equals the quantiser full-scale range. Let signal peak A (peak amplitude). For a full-scale sine, A equals the maximum allowed amplitude (V_pk).
- RMS signal power for a sine with peak A is P_signal = A^2/2.
- Quantisation noise power P_noise = Δ^2/12 with Δ = full-scale range / 2^b. For symmetric range ±V_pk, full-scale range = 2·V_pk, so Δ = 2·V_pk / 2^b = V_pk / 2^{b-1}.
- SNR (linear) = P_signal / P_noise. Convert to dB: SNR_dB = 10·log10(P_signal / P_noise). Substitute and simplify for a full-scale sine to get the common rule: SNR_dB ≈ 6.02·b + 1.76 dB (assumes full-scale sine and uniform quantiser). Assumptions: uniform quantiser, error uniformly distributed, signal uses full dynamic range (full-scale), no other noise sources.
Pulse-Code Modulation (PCM): sequence of b-bit words representing successive samples. For stereo PCM: channels are interleaved or multiplexed, so data rate multiplies by number of channels.
Dynamic range: the ratio (in dB) between largest undistorted signal and smallest discernible signal (often limited by quantisation noise). For ideal b-bit quantiser, dynamic range ≈ 6.02·b + 1.76 dB (for a full-scale sine under the uniform-noise assumption).
Diagrams to draw for exam answers (describe exactly):
- Time-domain sampling: draw continuous sinusoid and show vertical arrows at sampling instants t = nT_s; label T_s and f_s = 1/T_s and sample values x[n].
- Frequency-domain sampling: draw X(f) nonzero in |f| ≤ f_m, then copies at ±f_s, ±2f_s; label f_s/2 and show non-overlap when f_s>2f_m and overlap when f_s≤2f_m.
- Quantiser characteristic: draw input amplitude on x-axis and quantised output levels as horizontal steps (staircase); draw sample point and vertical error to quantised level labeled e[n]. Also sketch uniform distribution of error between ±Δ/2.
Formulas
f_s = 1 / T_s — f_s is sampling frequency in hertz (Hz), T_s is sampling interval in seconds (s). Applies always.
Nyquist rate = 2 · f_m — f_m is maximum frequency present in the signal (Hz). Minimum f_s must be > Nyquist rate for perfect reconstruction under ideal assumptions.
f_Nyquist = f_s / 2 — Nyquist frequency in Hz; the highest unaliased sinusoidal component must be strictly less than f_s/2 (components exactly at f_s/2 are phase-dependent and problematic).
L = 2^b — L is number of quantisation levels, b is bits per sample (dimensionless integer).
Δ = (V_max - V_min) / 2^b — Δ is quantisation step (volts, V). For symmetric ±V_pk range, Δ = 2·V_pk / 2^b.
P_noise = Δ^2 / 12 — mean squared quantisation noise power (V^2). Assumes uniform distribution of quant error in [-Δ/2, Δ/2].
P_signal (sine) = A^2 / 2 — RMS power of a sine with peak amplitude A (A in V; power in V^2).
SNR_linear = P_signal / P_noise — linear signal-to-noise ratio (dimensionless).
SNR_dB = 10 · log10(SNR_linear) — SNR in decibels (dB).
SNR_dB ≈ 6.02 · b + 1.76 dB — approximate SNR for a full-scale sine in a uniform b-bit quantiser. b is bits per sample.
Bitrate R = f_s · b · N_channels — bits per second (bps). f_s in Hz, b bits per sample per channel, N_channels is count (dimensionless).
Aliased frequency f_a = | f - k·f_s | chosen such that f_a is in [0, f_s/2] for some integer k that minimizes f_a — frequency after aliasing into baseband (Hz).
Worked examples
Example 1 — Choose sampling rate and PCM bitrate (numerical, exam style) Problem: You want to digitise audio with bandwidth up to 20 kHz for stereo playback, using 16-bit PCM. Use a standard sampling rate 44.1 kHz. Compute minimum theoretical sampling rate and the PCM bit rate. Steps:
- Nyquist minimum:
f_s_min = 2 · f_m = 2 · 20,000 Hz = 40,000 Hz. - Practical choice: standard
f_s = 44,100 Hz> 40,000 Hz (satisfies Nyquist). - PCM bit rate:
R = f_s · b · N_channels = 44,100 · 16 · 2 = 1,411,200 bits/s. - Convert to more convenient units:
1,411,200 bits/s = 1.4112 Mb/s(megabits per second) and= 176,400 bytes/s ≈ 172.27 KiB/s. Answer: Minimum theoretical f_s = 40 kHz; chosen f_s = 44.1 kHz; PCM bitrate = 1,411,200 b/s (≈1.4112 Mb/s).
Example 2 — Quantisation noise and SNR for 16-bit full-scale ±1 V range Problem: Uniform 16-bit quantiser, full-scale ±1 V (so V_pk = 1 V). Find Δ, noise power, noise RMS, and SNR for a full-scale sine. Steps:
Δ = 2·V_pk / 2^b = 2·1 V / 65536 = 2 / 65536 = 3.0517578125e-5 V.P_noise = Δ^2 / 12 = (3.0517578125e-5)^2 / 12 ≈ 9.313225746e-10 / 12 ≈ 7.761021455e-11 V^2.- Noise RMS = sqrt(P_noise) ≈
8.8099e-6 V. - Signal RMS for full-scale sine: A = V_pk = 1 V, so RMS = A / sqrt(2) ≈
0.70710678 V, P_signal = (0.7071)^2 =0.5 V^2. SNR_linear = P_signal / P_noise ≈ 0.5 / 7.761e-11 ≈ 6.441e9.SNR_dB = 10·log10(6.441e9) ≈ 98.08 dB(compare to formula 6.02·16 + 1.76 = 98.08 dB). Answer: Δ ≈ 3.0518e-5 V, noise RMS ≈ 8.81e-6 V, P_noise ≈ 7.761e-11 V^2, SNR ≈ 98.08 dB.
Example 3 — Aliasing calculation Problem: A 15 kHz pure tone is sampled at f_s = 20 kHz. What frequency appears after sampling (alias frequency)? Steps:
- Nyquist frequency f_s/2 = 10 kHz; 15 kHz > 10 kHz so aliasing occurs.
- Compute alias: nearest folding gives f_a = |f - f_s| = |15 kHz - 20 kHz| = 5 kHz. Answer: Aliased frequency observed = 5 kHz.
Common mistakes
- Confusing sampling rate (temporal resolution) with bit depth (amplitude resolution). Both matter but affect different artifacts: aliasing vs quantisation noise.
- Using RMS and peak interchangeably without converting (e.g., using peak instead of RMS when computing SNR; remember sine RMS = peak/√2).
- Forgetting to multiply by number of channels for PCM bitrate; units errors (bits vs bytes) when reporting bitrate.
- Misusing SNR formula outside its assumptions (the 6.02·b + 1.76 dB rule applies for full-scale sine and uniform quantiser with assumed uniform error distribution).
- Confusing dBFS (decibels relative to full scale) and dB (relative power); be explicit which reference is used in answers.
For your exam
Types of questions you will see:
- Definitions: sampling, Nyquist rate, quantisation, bit depth, aliasing. Give precise definitions and assumptions.
- Short notes: explain aliasing and anti-aliasing filters; explain quantisation noise and SNR; compare uniform and companded quantisers briefly (mention μ-law / A-law without full derivation unless asked).
- Derivations: show spectral replication from sampling (impulse model) and derive the Nyquist condition; derive P_noise = Δ^2/12 and then SNR ≈ 6.02·b + 1.76 dB for a full-scale sine.
- Numericals: compute minimum f_s, compute bitrate R, compute Δ and SNR for given b and V_pk, compute aliased frequency.
- Diagrams: draw time-domain sampling, frequency-domain copies and aliasing, quantiser staircase and error. Full-marks answers include definitions, assumptions, algebraic steps, units, and correctly labelled diagrams.
Quick check
- What is the Nyquist frequency for a sampling rate of 48 kHz? 2. For a 12-bit uniform quantiser with full-scale ±2 V, what is the quantisation step Δ? 3. A 30 kHz tone is sampled at 40 kHz. What aliased frequency appears in baseband? Answers: 1. 24 kHz. 2. Δ = (4 V) / 2^12 = 4 / 4096 ≈ 9.7656e-4 V. 3. f_a = |30 kHz - 40 kHz| = 10 kHz (folds to 10 kHz which is at Nyquist for 40 kHz sampling).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?