ELE-350 · Lesson 5 of 12 · 25 min

Sampling, quantization and PCM

Most information that travels today begins as an analog waveform and ends up as bits. A voice, a temperature or a vibration is sampled at regular instants, each sample is rounded to one of a finite set of levels, and each level is written as a binary code word. This process, pulse-code modulation, is what made the digital telephone network possible, and it is the front end of every digital communication system that carries analog information. This lesson reviews the sampling theorem from a communication point of view, analyzes quantization noise and the signal-to-quantization-noise ratio, explains companding, and shows how differential and adaptive methods reduce the bit rate.

The TLR-1 is mostly a data radio, but the city has asked for one analog feature. When a resident complains that an accessible signal is too quiet or too loud, the traffic technician would like to listen to the street sound at the push-button station from the cabinet, without climbing the pole, to check the automatic volume adjustment that ELE-340's APS-2 amplifier performs. Amara has to decide how to digitize a short clip of the microphone signal and whether the radio link can carry it.

Sampling revisited

ELE-250 established the sampling theorem: a signal band-limited to W hertz is completely described by samples taken at a rate f_s > 2W, and it can be recovered by an ideal low-pass filter. Sampling multiplies the signal by an impulse train, so the spectrum of the samples consists of copies of the signal's spectrum repeated at every multiple of f_s. If f_s is less than 2W, the copies overlap and aliasing makes some frequencies impossible to separate. In practice an anti-aliasing filter limits the signal before sampling, and the rate is chosen with a guard band to let a real filter roll off. Telephone speech is filtered to about 3.4 kHz and sampled at 8 kHz, leaving a guard band of about 1.2 kHz between 3.4 kHz and the folding frequency of 4 kHz.

\[x_s(t) = x(t)\sum_{n} \delta(t - nT_s) \;\Longleftrightarrow\; X_s(f) = f_s\sum_k X(f - k f_s) \qquad f_s > 2W\]

Real samplers do not take instantaneous samples. Pulse-amplitude modulation (PAM) with flat-top pulses, produced by a sample-and-hold circuit, holds each sample for a time τ. Holding is a convolution with a rectangular pulse, so the spectrum is multiplied by a sinc function, which attenuates high frequencies slightly. This aperture effect is small if τ is much less than the sampling period, and an equalizer with the inverse response can correct it. When τ equals the full sampling period, as in a zero-order hold at the output of a digital-to-analog converter, the droop at the top of the band reaches about 3.9 dB at the folding frequency.

Uniform quantization

A quantizer maps each sample to the nearest of L levels. With n bits per sample, L = 2ⁿ. For a uniform quantizer covering the range −V_max to +V_max, the step size is Δ = 2V_max/L. The difference between the true sample and its quantized value is the quantization error. If the signal is busy and covers many steps, the error is equally likely anywhere between −Δ/2 and +Δ/2 and is unrelated to the signal, so it behaves like additive noise with a uniform distribution.

Two graphs. The upper graph shows one cycle of a sine wave drawn as a smooth curve, with a staircase approximation from a 3-bit uniform quantizer of 8 levels; the step size delta is marked. The lower graph shows the quantization error, the difference between the two, as a jagged sawtooth-like signal confined between minus delta over 2 and plus delta over 2, marked by dashed lines.
A 3-bit uniform quantizer. The error stays between −Δ/2 and +Δ/2 and looks like noise when the signal covers many steps.
\[\Delta = \frac{2V_{max}}{2^{n}} \qquad \sigma_q^2 = \frac{1}{\Delta}\int_{-\Delta/2}^{\Delta/2} e^2\,de = \frac{\Delta^2}{12}\]

For a full-scale sine wave, of amplitude V_max and power V_max²/2, the signal-to-quantization-noise ratio follows directly. Each added bit halves Δ and quarters the noise power, a gain of 6.02 dB. This is the most quoted rule in data conversion.

\[\text{SQNR} = \frac{V_{max}^2/2}{\Delta^2/12} = \frac{3}{2}\,2^{2n} \qquad \text{SQNR}_{dB} = 6.02\,n + 1.76\]

Real signals are not full-scale sine waves. Speech has a peak-to-average power ratio, or crest factor, of 10 dB or more, so its average power is well below that of a sine of the same peak, and the SQNR is correspondingly lower. A quiet talker 30 dB below full scale loses 30 dB of SQNR with a uniform quantizer, because the noise Δ²/12 is fixed while the signal shrinks. If the signal exceeds V_max, it clips, causing overload distortion that is far more objectionable than quantization noise. A designer sets the quantizer range, or the gain before it, to balance the two: high enough to avoid frequent clipping, low enough to use most of the levels.

Worked problem

Bits for a required SQNR

Amara wants at least 40 dB SQNR for speech with a crest factor that puts its average power 12 dB below a full-scale sine. How many bits does a uniform quantizer need? What if a 20 dB range of talker levels must also be covered?

Show solution
  1. \[6.02\,n + 1.76 - 12 \ge 40 \;\Rightarrow\; n \ge \frac{50.24}{6.02} = 8.3 \;\Rightarrow\; n = 9\]
  2. \[6.02\,n + 1.76 - 12 - 20 \ge 40 \;\Rightarrow\; n \ge \frac{70.24}{6.02} = 11.7 \;\Rightarrow\; n = 12\]

Answer: A uniform quantizer would need 9 bits for one talker level and 12 bits to cover a 20 dB range of levels. Companding, next, lets 8 bits do the job of 12 for speech.

Companding

The quiet-talker problem has an elegant solution: make the steps small for small signals and large for large ones, so the SQNR stays roughly constant over a wide range of levels. This is a non-uniform quantizer, and it is usually built as a compressor, which squeezes large values with a logarithmic curve, followed by a uniform quantizer; the receiver applies the inverse expander. Compressing and then expanding is called companding. North American and Japanese telephone systems use the μ-law with μ = 255; Europe and most other countries use the A-law with A = 87.6. Both give 8-bit telephone channels a usable SQNR of about 35 to 38 dB over a range of about 40 dB of input level, roughly what 12 or 13 uniform bits would give at the top of the range.

\[y = \text{sgn}(x)\,\frac{\ln(1 + \mu|x|)}{\ln(1 + \mu)} \qquad |x| \le 1\]
Measured SQNR of a uniform quantizer against the 6.02n + 1.76 rule, and 8-bit uniform versus μ-law quantization over a 40 dB range of signal levels.
import math
def quantize(v, n):                      # uniform mid-rise quantizer on [-1, 1)
    L = 2 ** n; d = 2 / L
    k = min(L - 1, max(0, int((v + 1) / d)))
    return -1 + (k + 0.5) * d
def sqnr(signal, out):
    ps = sum(s * s for s in signal); pn = sum((s - o) ** 2 for s, o in zip(signal, out))
    return 10 * math.log10(ps / pn)
N = 20000
sine = [math.sin(2 * math.pi * 0.0123457 * k) for k in range(N)]   # full-scale test tone
for n in (4, 8, 12):
    q = [quantize(s, n) for s in sine]
    print(f"{n:2d} bits: measured SQNR = {sqnr(sine, q):5.1f} dB, formula = {6.02*n + 1.76:5.1f} dB")
mu = 255
comp = lambda x: math.copysign(math.log1p(mu * abs(x)) / math.log1p(mu), x)
expand = lambda y: math.copysign(((1 + mu) ** abs(y) - 1) / mu, y)
for level_db in (0, -10, -20, -30, -40):
    a = 10 ** (level_db / 20)
    sig = [a * s for s in sine]
    uni = [quantize(s, 8) for s in sig]
    law = [expand(quantize(comp(s), 8)) for s in sig]
    print(f"tone at {level_db:4d} dB: 8-bit uniform {sqnr(sig, uni):5.1f} dB, 8-bit mu-law {sqnr(sig, law):5.1f} dB")
Output
 4 bits: measured SQNR =  25.3 dB, formula =  25.8 dB
 8 bits: measured SQNR =  49.9 dB, formula =  49.9 dB
12 bits: measured SQNR =  74.2 dB, formula =  74.0 dB
tone at    0 dB: 8-bit uniform  49.9 dB, 8-bit mu-law  37.5 dB
tone at  -10 dB: 8-bit uniform  40.8 dB, 8-bit mu-law  39.2 dB
tone at  -20 dB: 8-bit uniform  30.0 dB, 8-bit mu-law  38.4 dB
tone at  -30 dB: 8-bit uniform  19.1 dB, 8-bit mu-law  36.5 dB
tone at  -40 dB: 8-bit uniform   9.3 dB, 8-bit mu-law  34.3 dB

The measured values agree with the formula within a fraction of a decibel. The companding comparison shows the point of μ-law: at full scale, the 8-bit uniform quantizer is better, but every 10 dB drop in level costs it 10 dB of SQNR, while the μ-law quantizer stays near 38 dB until the signal is about 30 dB down, falling only gradually below that. For speech, where levels vary widely, μ-law is the better use of 8 bits.

Pulse-code modulation

In PCM each quantized sample is represented by an n-bit code word, and the code words are sent one after another as a stream of binary pulses. The bit rate is the sampling rate times the bits per sample. For telephony, 8000 samples per second at 8 bits gives the 64 kb/s channel on which the whole digital telephone hierarchy was built. Multiplexing 24 such channels with one framing bit per frame of 24 samples gives the North American T1 or DS1 rate of 1.544 Mb/s; Europe's E1 carries 32 time slots at 2.048 Mb/s. Time-division multiplexing interleaves the code words of several channels in fixed slots, the counterpart in time of frequency-division multiplexing.

\[R_b = n\,f_s \qquad \text{T1: } (24 \times 8 + 1)\ \text{bits/frame} \times 8000\ \text{frames/s} = 1.544\ \text{Mb/s}\]

The price of PCM is bandwidth. A 3.4 kHz voice channel becomes 64 kb/s, which lesson 6 will show needs at least 32 kHz of baseband bandwidth, nearly ten times the original. The reward is that the bits can be regenerated, error-checked, encrypted, switched and stored. With enough SNR, the only lasting impairment is the quantization noise introduced once at the source.

Differential and adaptive methods

Successive samples of speech, or of most physical signals, are strongly correlated: the next sample is usually close to the last. Differential PCM (DPCM) quantizes the difference between each sample and a prediction formed from previous samples. The difference is much smaller than the sample itself, so fewer bits give the same SQNR. The prediction is made from the decoded values, not the original ones, so the transmitter and receiver predict identically and quantization errors do not accumulate. The improvement over PCM is called the prediction gain, often 5 to 10 dB for speech.

Delta modulation is the extreme case: one bit per sample, saying only whether the signal is above or below the running estimate, which then steps up or down by a fixed amount δ. It needs a sampling rate many times the Nyquist rate. Two kinds of error appear. When the signal changes faster than δ per sample, the estimate cannot keep up, called slope overload. When the signal is nearly constant, the estimate hunts up and down by δ, called granular noise. Choosing δ trades one against the other, and adaptive delta modulation changes δ on the fly. The same adaptive idea in DPCM gives ADPCM, which carries telephone-quality speech at 32 kb/s, half the PCM rate, and is still used in cordless telephones and some radio systems.

\[\text{no slope overload if}\quad \delta f_s \ge \max\Big|\frac{dx}{dt}\Big| = 2\pi f A \ \text{for a tone}\]

Modern speech codecs go much further. Instead of describing the waveform, they model the vocal tract with a short-term filter, transmit its coefficients and a compact description of the excitation, and let the decoder synthesize speech that sounds right. Codecs of this kind carry intelligible speech at 2 to 13 kb/s and are used in cellular telephones and digital land-mobile radio.

Speech digitization methods, from waveform coding to model-based coding.
MethodBits per sampleRate for 8 kHz speechMain idea
Uniform PCM12–1396–104 kb/sFixed steps, SQNR falls with level
Companded PCM (μ-law, A-law)864 kb/sLogarithmic steps, near-constant SQNR
ADPCM432 kb/sQuantize an adaptive prediction error
Delta modulation1 at many times the Nyquist rate16–64 kb/sOne-bit up or down steps
Model-based speech codecsnot sample based2–13 kb/sTransmit a vocal-tract model and excitation

The listen-in feature

Amara's first estimate rules out real-time listening. The TLR-1 link, as lessons 8 to 12 will show, will run at about 50 kb/s and is shared by four pole stations, with button presses taking priority. A 64 kb/s μ-law stream does not fit. She proposes a store-and-forward clip instead: the APS-2 records 4 seconds of street sound at 8 kHz with 4-bit ADPCM, 16 kilobytes in total, and sends it in low-priority packets over several seconds. The technician hears it a few seconds late, which is acceptable for checking a volume setting, and button messages are never delayed. The microphone channel's 300 Hz to 3 kHz band, from ELE-250, sampled at 8 kHz with the existing anti-aliasing filter, needs no new hardware.

Worked problem

Clip size and transfer time

A 4 s clip is sampled at 8 kHz with 4-bit ADPCM. Packets carry 128 data bytes, and the link gives the clip at most 20 percent of a 50 kb/s channel after overhead. Find the clip size, number of packets and transfer time.

Show solution
  1. \[\text{bits} = 4\ \text{s} \times 8000 \times 4 = 128\,000\ \text{bits} = 16\,000\ \text{bytes}\]
  2. \[\text{packets} = \lceil 16\,000/128 \rceil = 125\]
  3. \[t = \frac{128\,000}{0.2 \times 50\,000} = 12.8\ \text{s}\]

Answer: The clip is 16 kB in 125 packets and arrives about 13 seconds after it is recorded. Amara notes that 8-bit μ-law would double both the size and the wait.

Common mistakes

  • MistakeAssuming every extra bit gives 6 dB more SQNR for any signal.

    InsteadThe 6.02 dB per bit holds for busy signals; SQNR also depends on the signal's level and crest factor relative to full scale.

  • MistakeSetting the quantizer range far above the signal to avoid clipping at all costs.

    InsteadUnused range wastes levels; a quiet signal loses SQNR dB for dB.

  • MistakePredicting from the original samples in a DPCM encoder.

    InsteadPredict from the reconstructed samples, as the decoder must, or errors accumulate.

  • MistakeForgetting the anti-aliasing filter because the signal is said to be band-limited.

    InsteadNoise and interference above f_s/2 fold into the band; filter before sampling.

Summary and key terms

  • Sampling above 2W preserves a band-limited signal; flat-top sampling adds a small sinc-shaped aperture loss.
  • A uniform n-bit quantizer has step Δ = 2V_max/2ⁿ and noise power Δ²/12.
  • For a full-scale sine, SQNR = 6.02n + 1.76 dB; real signals lose SQNR by their crest factor and level below full scale.
  • μ-law and A-law companding keep 8-bit telephone SQNR near constant over a wide range of levels.
  • PCM bit rate is n f_s: 64 kb/s for telephony; T1 multiplexes 24 channels at 1.544 Mb/s.
  • DPCM, ADPCM and delta modulation exploit correlation between samples to cut the bit rate.
Pulse-code modulation
Representing an analog signal by sampling, quantizing and coding each sample as a binary word.
Quantization noise
The error between a sample and its quantized value, treated as noise.
SQNR
Signal-to-quantization-noise ratio.
Companding
Compressing a signal before uniform quantization and expanding it after decoding to obtain near-constant SQNR.
Crest factor
The ratio of a signal's peak value to its RMS value, often given in dB.
Time-division multiplexing
Sharing a channel by giving each signal its own repeating time slot.
Slope overload
Delta modulation error when the input changes faster than the step size allows.
DPCM
Differential PCM, which quantizes the difference between each sample and its prediction.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Find the SQNR of a 10-bit quantizer for a full-scale sine.

    Show answer

    6.02 × 10 + 1.76 = 61.96 dB.

  2. A 12-bit converter covers ±5 V. Find Δ and the RMS quantization noise.

    Show answer

    Δ = 10/4096 = 2.44 mV; σ = Δ/√12 = 0.70 mV.

  3. A sensor signal of 0–200 Hz is sampled at 1 kHz with 12 bits. Find the bit rate.

    Show answer

    12 kb/s.

  4. How many 64 kb/s channels does a 2.048 Mb/s E1 frame carry, and how many are for voice?

    Show answer

    32 time slots, normally 30 for voice and 2 for framing and signalling.

  5. A delta modulator samples at 64 kHz with δ = 0.05 V. What is the largest 1 kHz tone amplitude without slope overload?

    Show answer

    A ≤ δ f_s/(2πf) = 3200/6283 = 0.51 V.

  6. Why does companding help speech more than it helps a constant-level test tone?

    Show answer

    Speech levels vary over tens of dB; companding keeps the SQNR near constant across them, while a constant full-scale tone gains nothing.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz