Audio compression: ADPCM, vocoders and MPEG audio
Notes on three families of audio compression: ADPCM (adaptive differential PCM), vocoders (source‑filter and LPC based) and MPEG audio (perceptual coding used in MP3/Layer II), with formulas, worked examples and exam guidance.
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
Audio in multimedia must often be stored or streamed with limited storage and bandwidth. Engineers use ADPCM, vocoders and MPEG audio to reduce bitrate while keeping intelligibility and perceptual quality — ADPCM for low‑complexity telephony and codecs, vocoders for very low bitrate speech (telecom, voice synthesis), and MPEG audio for high‑quality music streaming and storage.
Key ideas
Start from first principles: digital audio stores samples x[n] (units: volts or normalized amplitude). Raw PCM bit rate = sample_rate × bits_per_sample × channels.
Pulse‑code modulation (PCM): the straightforward linear quantisation of samples. Defined: PCM is the process of sampling an analog signal and quantising each sample to a finite set of amplitude levels; stored as binary words of fixed length.
Differential PCM (DPCM): defined: DPCM codes the difference d[n] = x[n] − p[n] between the current sample and a prediction p[n] based on past samples, then quantises that difference. Assumes signal is correlated across samples so differences have smaller variance than samples.
Adaptive DPCM (ADPCM): defined: ADPCM is DPCM with an adaptive quantiser step size (and often an adaptive predictor). The encoder and decoder both track the step size so only quantiser indices are transmitted. Key equations (general):
- Prediction: p[n] = sum_{k=1..P} a_k · x_hat[n−k] (linear predictor of order P). Bold: predictor coefficients a_k.
- Prediction error (difference): e[n] = x[n] − p[n].
- Quantiser: q[n] = Q(e[n], Δ[n]) where Δ[n] is current step size; send index i[n].
- Reconstruction: x_hat[n] = p[n] + q[n].
- Step update: Δ[n+1] = f(Δ[n], i[n]) where f is an adaptation rule. Assumptions: encoder and decoder share initial state and adaptation function f; predictor uses reconstructed samples x_hat at decoder side. Common standards: ITU‑T G.726 ADPCM (16/24/32/40 kbit/s at 8 kHz) and IMA/DVI ADPCM (4‑bit index with step‑size adaptation via tables).
Vocoders: defined: a vocoder (voice coder) models speech by separating a source (excitation: periodic pulses for voiced sounds or noise for unvoiced) and a filter (vocal tract resonances, i.e., formants). Modern vocoders often use Linear Predictive Coding (LPC) to estimate the filter.
- LPC model: x[n] ≈ sum_{k=1..p} a_k·x[n−k] + G·u[n], where a_k are LPC coefficients (filter denominator coefficients; poles are the roots of 1 − ∑ a_k z^{-k}), G is gain, u[n] is excitation (periodic or noise). The encoder transmits quantised a_k, pitch (period) for voiced frames, and gain — very compact; in practice, LPC parameters are often converted to line spectral pairs/frequencies (LSP/LSF) for quantisation to preserve filter stability.
- Derivation commonly asked: Yule–Walker (normal) equations for LPC coefficients are obtained by minimizing the total squared prediction error E = sum e[n]^2; set partial derivatives to zero and get R·a = r, where R is autocorrelation matrix and r is autocorrelation vector.
- Vocoder tradeoffs: very low bitrate but synthetic timbre; good for intelligibility, not for natural music.
MPEG audio (Layer I/II/III): defined: MPEG audio codecs use perceptual audio coding — remove or coarsely quantise spectral components below the masking threshold determined by a psychoacoustic model. Block diagram to describe: input PCM → filterbank (subband or MDCT) → psychoacoustic model (compute masking thresholds) → bit allocation / quantisation → entropy coding (Huffman). Specifics:
- Layer I and II use subband coding (polyphase filterbank + scalar quantisation). Layer III (MP3) uses a hybrid filterbank (32-band polyphase analysis followed by an MDCT), adds block/window switching to control pre-echo, a bit reservoir for variable allocation across frames, joint stereo tools (M/S and intensity), and Huffman coding.
- Perceptual model: compute masking thresholds using critical bands, tonality, and the absolute threshold of hearing (ATH); allocate bits where audible.
- Result: much lower bitrates (e.g., 64–320 kbit/s) with perceptually transparent audio for music at sufficient bitrate.
Diagrams to draw (exam):
- ADPCM encoder/decoder pair: draw input PCM → predictor → subtractor (difference) → adaptive quantiser → transmitted index → decoder mirror with inverse quantiser and predictor using reconstructed samples. Label signals x[n], p[n], e[n], q[n], Δ[n].
- Vocoder block diagram: input → analysis (window → LPC analysis / pitch detector) → parameter quantiser → bitstream → synthesis (dequantise parameters → excitation generator conditioned on pitch → LPC filter) → output. Label LPC coefficients, pitch, gain.
- MPEG audio encoder: PCM input → filterbank (subbands / MDCT) → psychoacoustic model → scalefactor & bit allocation → quantiser → Huffman coder → bitstream.
Formulas
bitrate_pcm = fs · b · C where fs = sampling rate (Hz), b = bits per sample, C = number of channels. Applies for uncompressed PCM.
e[n] = x[n] - p[n] where e[n] (also called d[n] in DPCM) is the prediction error (unit: same as x[n]).
p[n] = sum_{k=1..P} a_k · x_hat[n-k] predictor of order P; a_k unitless.
x_hat[n] = p[n] + q[n] reconstructed sample; q[n] is quantised difference (same units as x).
Δ[n+1] = f(Δ[n], i[n]) general adaptive step update; Δ in units of amplitude.
Minimisation for LPC (Yule–Walker form):
R · a = r where R[i,j] = sum_n x[n-i]·x[n-j] (autocorrelation), r[i] = sum_n x[n]·x[n-i], a = [a1..ap]^T. Units: R in amplitude^2, a unitless.
compression_ratio = bitrate_pcm / bitrate_compressed with bitrates in bits per second (b/s).
Psychoacoustic masking relation (conceptual): audible if S(ω) > masking_threshold(ω) where S(ω) is spectral magnitude.
Worked examples
- ADPCM (simple 1‑tap predictor, adaptive step-rule example) Given PCM samples (normalized amplitude, unitless) at fs = 8000 Hz: x = [0.50, 0.48, 0.46, 0.49]. Use predictor p[n] = x_hat[n-1] (a1=1), initial x_hat[0]=0.50, initial step Δ[1]=0.02. Quantiser: uniform midtread with levels k·Δ (including zero), and we send the index i[n] where q[n] = round(d[n]/Δ)·Δ = i[n]·Δ. Update rule: if |index|≥2 then Δ←1.5·Δ else Δ←0.75·Δ (example adaptation rule). Steps:
- n=1: x[1]=0.50 (given as initial reconstructed). x_hat[1]=0.50. No transmission.
- n=2: p[2]=x_hat[1]=0.50. d[2]=x[2]−p[2]=0.48−0.50=−0.02. Δ=0.02. Quantise q[2]=round(d[2]/Δ)·Δ = round(−1)·0.02 = −0.02. index = −1 so |index|=1 → Δ←0.75·0.02=0.015. Reconstruct x_hat[2]=p[2]+q[2]=0.50−0.02=0.48.
- n=3: p[3]=x_hat[2]=0.48. d[3]=0.46−0.48=−0.02. Δ=0.015. q[3]=round(−0.02/0.015)·0.015=round(−1.333)·0.015=−1·0.015=−0.015. index=−1 → Δ←0.75·0.015=0.01125. x_hat[3]=0.48−0.015=0.465.
- n=4: p[4]=0.465. d[4]=0.49−0.465=0.025. Δ=0.01125. q[4]=round(0.025/0.01125)·0.01125=round(2.222)·0.01125=2·0.01125=0.0225. index=2 → |index|≥2 → Δ←1.5·0.01125=0.016875. x_hat[4]=0.465+0.0225=0.4875. Final reconstructed sequence x_hat ≈ [0.50, 0.48, 0.465, 0.4875]. Quantiser indices transmitted: (−1, −1, 2). This shows typical ADPCM behaviour: small differences encoded with small indices and step size adapted.
Notes: this worked example used a simple adaptation rule for illustration; implementations differ (verify table values for IMA ADPCM if required).
LPC vocoder: compute order‑2 LPC coefficients from autocorrelation Given autocorrelations r0 = 1.0, r1 = 0.8, r2 = 0.5 (units amplitude^2). For p=2, Yule–Walker equations: R = [[r0, r1],[r1, r0]] = [[1.0, 0.8],[0.8,1.0]], r = [r1, r2] = [0.8, 0.5]. Solve R a = r. Compute determinant: det = 1.0·1.0 − 0.8·0.8 = 1 − 0.64 = 0.36. Inverse R = (1/det)·[[1.0, −0.8], [−0.8, 1.0]] = (1/0.36)·[[1, −0.8], [−0.8, 1]]. Multiply a = R^{-1} r = (1/0.36)·[[1, −0.8],[−0.8, 1]]·[0.8,0.5]. Compute first element: (1·0.8 + (−0.8)·0.5) = 0.8 − 0.4 = 0.4. Second: (−0.8·0.8 + 1·0.5) = −0.64 + 0.5 = −0.14. Multiply by 1/0.36 ≈ 2.7778: a1 = 0.4·2.7778 ≈ 1.1111, a2 = −0.14·2.7778 ≈ −0.3889. So LPC coefficients: a1 ≈ 1.1111, a2 ≈ −0.3889. These feed the vocoder synthesis filter H(z)=1/(1−a1 z^{-1} − a2 z^{-2}).
Compression ratio for MPEG: compute PCM and compressed bitrates Given stereo PCM 16‑bit, fs = 44.1 kHz. Compute PCM bitrate:
bitrate_pcm = 44100 Hz · 16 bits · 2 = 1,411,200 bits/s = 1.4112 Mbit/s. If compressed to MP3 128 kbit/s (128,000 bits/s) thencompression_ratio = 1,411,200 / 128,000 ≈ 11.02. Final: ≈11:1 compression.
Common mistakes
- Mixing up units for bitrate (use bits per second) and file size (bytes). Always convert 1 byte = 8 bits.
- In LPC derivation, failing to state the minimisation of squared error and to derive Yule–Walker equations (students often write the matrix but not derive it).
- Saying MP3 simply “uses transform coding” without naming the MDCT and psychoacoustic model and entropy coding stages.
For your exam
Question types: definitions (define ADPCM/vocoder/MPEG audio), block diagrams (draw and label encoder/decoder), derivations (derive Yule–Walker for LPC; show ADPCM encoder/decoder equations), numericals (compute bitrates, simple ADPCM trace or LPC coefficient calculation), short notes (compare vocoder vs waveform coder), and algorithm traces.
What full‑marks answers include:
- Definitions with bold names and clear assumptions (e.g., predictor order, shared state between encoder/decoder).
- Correct, labelled diagrams (signals x[n], p[n], e[n], q[n], Δ[n] for ADPCM; LPC coefficients, pitch, gain for vocoder; filterbank/MDCT and psychoacoustic model for MPEG).
- Stepwise derivations: show minimisation step and final normal equations for LPC; show equations for quantisation and reconstruction in ADPCM.
- Units and numeric steps with formula before substitution in numericals.
Quick check
- In ADPCM why must the decoder use reconstructed past samples rather than original samples?
- Give the formula for uncompressed PCM bitrate for stereo 24‑bit audio at 48 kHz.
- Name two roles of the psychoacoustic model in MPEG audio encoding.
Answers: 1) Because only reconstructed samples are available at decoder; predictor must be identical encoder/decoder to remain synchronized. 2)
bitrate = 48000 · 24 · 2 = 2,304,000 bits/s = 2.304 Mbit/s. 3) Compute masking thresholds and guide bit allocation (decide which spectral components may be quantised more coarsely or discarded).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?