---
title: Pulse-code modulation
heading: Turning analog messages into bits, PCM bit rates and bandwidth, uniform quantization noise, companding with the μ-law, and delta modulation's slope overload
eyebrow: S8 · Lesson 8 · Pulse-code modulation
xp: 50
---

::: hook
The telephone network went digital in the 1960s with a simple recipe: sample speech 8,000 times a second, round each sample to one of 256 levels, and send the eight-bit codes. Pulse-code modulation turned every voice into 64 kb/s, which could be regenerated perfectly at every repeater instead of accumulating noise. The rounding is the price, and speech makes it awkward: quiet talkers would drown in the quantization noise of a uniform quantizer sized for loud ones. Companding fixes that by spacing the levels logarithmically, giving nearly the same SNR across a 40 dB range of loudness.
:::

::: play
- Quantization SNR against the input level (a sine, in dB relative to full scale) for a uniform n-bit quantizer (dashed) and a μ-law companded one (solid).
- The uniform quantizer loses a dB of SNR for every dB the signal drops: at −40 dB an 8-bit quantizer gives only 9.9 dB.
- The μ-law quantizer (μ = 255) gives 38 dB at full scale and still 34.5 dB at −40 dB, trading a little peak SNR for a flat response across levels.
:::
:::

```sim plot
view: graph
x: L = -60..0 dB
y: S = -10..80 dB
slider: n = 6..12 = 8 step 1
slider: u = 5..1000 = 255 log
plot: 6.02*n + 4.77 - 20*log(ln(1 + u)) - 10*log(1 + (sqrt(2)*10^(-L/20)/u)^2 + sqrt(3)*sqrt(2)*10^(-L/20)/u) | samples: 400 | label: μ-law companded
plot: 6.02*n + 1.76 + L | samples: 200 | dashed | color: ch3 | label: uniform
```

::: predict
## A telephone channel uses 8-bit PCM at 8 kHz. What bit rate does that need, and what's the least bandwidth that can carry it as binary pulses?

- [ ] 8 kb/s and 8 kHz
- [x] 64 kb/s and 32 kHz
- [ ] 64 kb/s and 64 kHz
- [ ] 64 kb/s and 4 kHz

::: reveal
8 bits × 8000 samples/s = 64 kb/s. Binary pulses need at least $R_b/2$ of bandwidth (the Nyquist minimum, lesson 9), so 32 kHz, eight times the 4 kHz the analog voice occupied. Digital transmission pays in bandwidth for its immunity to noise accumulation.
:::
:::

::: nameit
## PCM

Sample at $f_s \ge 2W$, quantize each sample to $L = 2^n$ levels, send n bits per sample:

$$R_b = nf_s, \qquad B_T \ge \frac{R_b}{2}\text{ (binary, ideal Nyquist pulses)}$$

## Uniform quantization

Step Δ over a range ±$X_\text{max}$, error uniform with variance $\Delta^2/12$. For a sine of amplitude A:

$$\text{SNR} = 6.02n + 1.76 + 20\log\frac{A}{X_\text{max}}\text{ dB}$$

Each added bit buys 6 dB; each dB of lower signal level costs a dB.

## Companding

A **μ-law** compressor $y = \text{sgn}(x)\frac{\ln(1 + \mu|x|/X_\text{max})}{\ln(1 + \mu)}$ before a uniform quantizer (and the inverse expander after) spaces the levels roughly logarithmically. For large μ and a signal of rms σ,

$$\text{SNR} \approx 6.02n + 4.77 - 20\log\ln(1 + \mu) - 10\log\left[1 + \left(\frac{X_\text{max}}{\mu\sigma}\right)^2 + \sqrt{3}\frac{X_\text{max}}{\mu\sigma}\right]$$

nearly independent of σ over a wide range. North American telephony uses μ = 255; Europe uses the similar A-law.

## Delta modulation

Sending one bit per sample, up or down by a step δ, at a high rate $f_s$. The staircase can rise at most $\delta f_s$ per second; a sine $A\sin2\pi ft$ overloads when $2\pi fA > \delta f_s$. Too small a δ causes **slope overload**; too large a δ causes **granular noise**. Adaptive step sizes (CVSD) balance the two.
:::

::: example
## Compare 8-bit uniform and μ-law (μ = 255) quantization for a full-scale sine and one 40 dB lower.

::: solution
1. **Uniform.** 49.9 dB at full scale and 9.9 dB at −40 dB:
   $$\begin{aligned} \text{SNR} &= 6.02 \times 8 + 1.76 \\ &= 49.9\ \text{dB} \end{aligned}$$
2. **μ-law constant term.**
   $$\begin{aligned} C &= 48.2 + 4.8 - 14.9 \\ &= 38.1\ \text{dB} \end{aligned}$$
3. **μ-law at full scale.** The bracket is 1.0096:
   $$\begin{aligned} \text{SNR} &= 38.1 - 10\log 1.0096 \\ &= 38.0\ \text{dB} \end{aligned}$$
4. **μ-law at −40 dB.** Now $X_\text{max}/(\mu\sigma)$ = 0.555 and the bracket is 2.27:
   $$\begin{aligned} \text{SNR} &= 38.1 - 10\log 2.27 \\ &= 34.5\ \text{dB} \end{aligned}$$
5. **The trade.** Companding gives up 12 dB at the top to gain 25 dB at the bottom.

**Answer:** uniform quantization gives 49.9 dB at full scale and 9.9 dB at −40 dB; μ-law gives 38.0 dB and 34.5 dB.
:::
:::

::: example
## A delta modulator runs at 64 kHz with a step of 0.1 V. What's the largest 1 kHz sine it can follow without slope overload?

::: solution
1. **Staircase slope.** The staircase can climb
   $$0.1 \times 64\,000 = 6400\ \text{V/s}$$
2. **Sine slope.** A 1 kHz sine of amplitude A has a maximum slope of
   $$2\pi \times 1000 \times A$$
3. **Largest amplitude.** Keep the sine's slope within the staircase's:
   $$\begin{aligned} A &\le \frac{6400}{6283}\ \text{V} \\ &= 1.02\ \text{V} \end{aligned}$$
   Higher frequencies or amplitudes overload, and the staircase falls behind the signal.

**Answer:** a 1 kHz sine of up to 1.02 V amplitude.
:::
:::

::: example
## Compact disc audio is 16-bit stereo PCM at 44.1 kHz. What bit rate does it need, and what SNR does a full-scale sine get, and one at −20 dBFS?

::: solution
1. **Bit rate.**
   $$\begin{aligned} R &= 16 \times 44\,100 \times 2 \\ &= 1.4112\ \text{Mb/s} \end{aligned}$$
   of audio data, before error correction.
2. **Full-scale sine.**
   $$\begin{aligned} \text{SNR} &= 6.02 \times 16 + 1.76 \\ &= 98.1\ \text{dB} \end{aligned}$$
3. **At −20 dBFS.**
   $$98.1 - 20 = 78.1\ \text{dB}$$
4. **Quiet passages.** They lose a decibel of SNR for every decibel of level, which is why mastering engineers keep levels high and why μ-law telephony uses companding instead.

**Answer:** 1.4112 Mb/s, with an SNR of 98.1 dB at full scale and 78.1 dB at −20 dBFS.
:::
:::

::: check
given: n = 8 | 12 | 16; f = 8 | 16 | 44.1
answer: n*f
unit: kb/s
tolerance: 0.5%

## A PCM system samples at {f} kHz with {n} bits per sample. What bit rate does it need?

::: right
Right. $nf_s$ = {answer} kb/s.
:::

::: misses
- [f*2^n] The bit rate counts bits, n per sample, not levels.
- [any] Not yet. $R_b = nf_s$.
:::
:::

::: check
given: n = 6 | 8 | 12; L = -6 | -20 | -40
answer: 6.02*n + 1.76 + L
unit: dB
tolerance: 0.05

## A uniform {n}-bit quantizer receives a sine at {L} dB relative to full scale. What's its SNR?

::: right
Right. $6.02n + 1.76 + L$ = {answer} dB.
:::

::: misses
- [6.02*n + 1.76] That's for a full-scale sine; quieter signals lose SNR dB for dB.
- [any] Not yet. The noise is fixed by the step size; the signal shrinks.
:::
:::

::: check
given: n = 7 | 8 | 10; u = 87.6 | 255
answer: 6.02*n + 4.77 - 20*log(ln(1 + u))
unit: dB
tolerance: 0.05

## What's the level-independent SNR term of a μ-law quantizer with n = {n} bits and μ = {u}?

::: right
Right. $6.02n + 4.77 - 20\log\ln(1 + \mu)$ = {answer} dB.
:::

::: misses
- [6.02*n + 4.77 - 20*log(log(1 + u))] The compressor uses the natural logarithm.
- [any] Not yet. The companding costs $20\log\ln(1 + \mu)$.
:::
:::

::: check
given: n = 8 | 12 | 16; f = 8 | 44.1 | 96
answer: n*f/2
unit: kHz
tolerance: 0.5%

## What's the least bandwidth that can carry {n}-bit PCM at {f} kHz as binary pulses?

::: right
Right. $R_b/2$ = {answer} kHz.
:::

::: misses
- [n*f] That's the bit rate; ideal Nyquist pulses need half of it in hertz.
- [any] Not yet. $B_T \ge R_b/2$.
:::
:::

::: check
given: S = 40 | 60 | 90
answer: ceil((S - 1.76)/6.02 - 0.0001)
tolerance: 0

## How many bits must a uniform quantizer have to give at least {S} dB SNR for a full-scale sine?

::: right
Right. n ≥ (SNR − 1.76)/6.02, rounded up: {answer}.
:::

::: misses
- [floor((S - 1.76)/6.02 + 0.0001)] Round up: one fewer bit falls short.
- [any] Not yet. Solve 6.02n + 1.76 ≥ SNR.
:::
:::

::: check
given: d = 0.02 | 0.1; s = 32 | 64 | 128; f = 0.5 | 2 | 4
answer: d*s*1000/(2*pi*f*1000)
unit: V
tolerance: 0.5%

## A delta modulator has step {d} V at {s} kHz. What's the largest {f} kHz sine it can track without slope overload?

::: right
Right. $A_\text{max} = \delta f_s/(2\pi f)$ = {answer} V.
:::

::: misses
- [d*s*1000/(f*1000)] The sine's peak slope is $2\pi fA$.
- [any] Not yet. The staircase's slope $\delta f_s$ must match the sine's peak slope.
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 24; f = 8 | 44.1 | 96; c = 1 | 2 | 6

## PCM audio uses {n} bits at {f} kHz on {c} channel(s).

::: part
answer: n*f*c/1000
unit: Mb/s
tolerance: 0.5%

### What bit rate does it need?

::: misses
- [any] $n f_s$ times the number of channels.
:::
:::

::: part
answer: n*f*c/2/1000
unit: MHz
tolerance: 0.5%

### What is the least bandwidth that can carry it as binary pulses?

::: misses
- [any] $R_b/2$.
:::
:::
:::

::: check
kind: derivation
vars: n = 2..24, A = -60..0, d = 0.001..1, s = 1000..1000000, f = 10..10000

## A uniform n-bit quantizer receives a sine at A dB relative to full scale; separately, a delta modulator has step d at rate s.

::: step
answer: 6.02*n + 1.76 + A

### What SNR does the PCM quantizer give?
:::

::: step
answer: d*s

### What is the delta modulator's fastest slope?
:::

::: step
answer: d*s/(2*pi*f)

### What is the largest sine at frequency f it can follow?
:::

::: right
Right. PCM's SNR falls with level; delta modulation's limit falls with frequency.
:::
:::

::: explain
## Why does companding keep the quantization SNR nearly constant across signal levels?

::: model
A uniform quantizer has the same step size everywhere, so its noise power is fixed, and a quiet signal sees a much worse ratio than a loud one. A compressor with a logarithmic curve spreads small amplitudes across many quantizer levels and squeezes large ones into few, so after expansion the effective step size is roughly proportional to the signal's own amplitude. The error is then roughly a fixed fraction of the signal rather than a fixed absolute size, which makes the signal-to-noise ratio nearly independent of level. The cost is a somewhat lower SNR for full-scale signals, an acceptable trade for speech, whose level varies over 40 dB between talkers and syllables.
:::
:::

::: practice

::: check
given: n = 10 | 14; f = 16 | 48
answer: n*f
unit: kb/s
tolerance: 0.5%

## PCM rate: {n} bits at {f} kHz?

::: misses
- [any] $nf_s$.
:::
:::

::: check
given: n = 8 | 10; L = -10 | -30
answer: 6.02*n + 1.76 + L
unit: dB
tolerance: 0.05

## Uniform SNR: {n} bits, sine at {L} dB?

::: misses
- [any] $6.02n + 1.76 + L$.
:::
:::

::: check
given: d = 0.05 | 0.2; s = 48 | 96; f = 1 | 3
answer: d*s*1000/(2*pi*f*1000)
unit: V
tolerance: 0.5%

## DM overload limit: step {d} V, {s} kHz, {f} kHz sine?

::: misses
- [any] $\delta f_s/(2\pi f)$.
:::
:::
:::
