S8 · Lesson 32 · Rate–distortion theory and quantization
The fewest bits that describe a source to within a given distortion, the Gaussian source's 6 dB per bit, a binary source with Hamming distortion, Lloyd–Max quantizers and how close they come, entropy-coded quantization's 1.53 dB gap, and source–channel separation
Lesson 30 compressed sources without losing anything. Audio, images and sensor readings are continuous, so a finite number of bits can never describe them exactly: something must be lost. Cover and Thomas ask the right question for lossy coding: for a given amount of distortion, what's the least number of bits per sample any scheme could use? For a Gaussian source the answer is the 6 dB per bit that lesson 8 found for PCM, and it shows how far practical quantizers fall short.
- A Gaussian source of variance σ² described with R bits per sample. The solid line is the rate–distortion bound: the least mean-squared distortion any coder can reach, , falling 6.02 dB per bit.
- The dots are the best fixed-rate scalar quantizers (Lloyd–Max) at 1 to 4 bits. The dashed line is a uniform quantizer followed by ideal entropy coding at high rate, 1.53 dB above the bound.
- No scheme can go below the line. Getting closer than the dashed line takes coding many samples together: vector quantization.
Predict
A Gaussian source must be described with mean-squared error a hundredth of its variance (20 dB SNR). What's the least number of bits per sample any coder can use?
= 3.32 bits. Each bit buys 6.02 dB, so 20 dB takes 20/6.02 = 3.32 bits. A practical quantizer needs more: the best fixed-rate scalar quantizer at 4 bits reaches only 20.2 dB.
Name it
The rate–distortion function
For a source X, a reconstruction and a distortion measure , the rate–distortion function is the least mutual information between them consistent with an average distortion D:
Cover and Thomas prove it's achievable, by coding long blocks of samples together, and that nothing does better. It decreases as D grows and reaches zero when describing nothing (always guessing the mean) is good enough.
Two sources worth knowing
- Gaussian, squared error: for D ≤ σ², or . Each bit cuts the distortion by a factor of four: 6.02 dB. The Gaussian is the hardest source of a given variance to compress.
- Binary (Bernoulli 1/2), Hamming distortion: for D ≤ 1/2, where H is the binary entropy. Allowing 10% of the bits to be wrong saves almost half the rate: R(0.1) = 0.531 bit.
Scalar quantizers
A Lloyd–Max quantizer is the best fixed-rate scalar quantizer: its reconstruction levels sit at the centroids (conditional means) of their cells, and its cell boundaries halfway between levels. For a Gaussian source with one bit, the levels are ±σ√(2/π) = ±0.798σ and = 0.363σ², 1.6 dB worse than R(D) at one bit. At high rate, a uniform quantizer followed by entropy coding of its outputs comes within = 1.53 dB of the bound, a quarter of a bit: the price of quantizing one sample at a time.
Separation
Shannon's source–channel separation theorem: a source can be sent over a channel with distortion D if and only if (per channel use, adjusted for how many source samples each use carries). So the best system can be built in two independent parts, a compressor down to R(D) and a channel code up to C, without loss, at least for long blocks. Modern systems are built this way: codecs designed knowing nothing of the radio, and radios knowing nothing of the content.
Worked example
A sensor's Gaussian noise-like output must be stored with 30 dB SNR. How many bits per sample does the bound require, and how many would a uniform quantizer with ideal entropy coding need?
Show the solution
- The bound.
- Entropy-coded uniform quantizer. It's 1.53 dB worse, which costs 1.53/6.02 = 0.25 bit:
- Fixed-rate Lloyd–Max quantizer. It would need a whole number of bits, and even 5 bits falls short of 30 dB, so it would need 6.
Answer 4.98 bits per sample at the bound, 5.24 with an entropy-coded uniform quantizer and 6 with a fixed-rate Lloyd–Max quantizer.
Worked example
A Gaussian source producing 1000 samples per second is sent over a channel with capacity 3000 bits per second. What's the smallest mean-squared distortion any system can achieve?
Show the solution
- Bits per sample. Each sample gets at most 3 bits on average.
- The distortion bound. By separation, an SNR of 18.1 dB.
- What reaches it. No combination of compression and channel coding can beat it, and long-block separated designs approach it.
- A simple scheme. A one-sample-at-a-time 3-bit Lloyd–Max quantizer with ideal channel coding gets 0.0345σ², 14.6 dB.
Answer , an SNR of 18.1 dB.
Worked example
Fair random bits may be reproduced with 5% of them wrong; and a Gaussian signal must be kept at 40 dB SNR. What rates do the bounds require?
Show the solution
- Random bits at 5% error. bit per bit, a saving of 29%.
- Gaussian at 40 dB.
- Practical quantizers. A uniform quantizer with ideal entropy coding needs about a quarter bit more (1.53 dB), and a fixed-rate Lloyd–Max quantizer about 0.72 bit more at high rates (4.35 dB, the Panter–Dite constant ).
Answer 0.714 bit per bit for the random bits and 6.64 bits per sample for the Gaussian signal.
Check
A Gaussian source of variance 4 must be described with mean-squared error 0.01. What's the least rate, in bits per sample?
Check
A Gaussian source is coded at the rate–distortion bound with 2.5 bits per sample. What signal-to-distortion ratio results?
Check
A stream of fair random bits may be reproduced with a fraction 0.05 of them wrong. What's the least rate, in bits per source bit?
Check
A 1-bit Lloyd–Max quantizer codes a zero-mean Gaussian of standard deviation 1. Where are its two reconstruction levels (give the positive one)?
Check
How many bits per sample does a uniform quantizer with ideal entropy coding need for 30 dB SNR on a Gaussian source, at high rate?
Check
A Gaussian source of 500 samples per second is sent over a channel of capacity 4000 bit/s. What's the best possible signal-to-distortion ratio?
Check
A Gaussian source must be kept at 35 dB SNR; separately, fair bits may be reproduced with a fraction 0.02 wrong.
(a)
What rate per sample does the Gaussian bound require?
(b)
What rate per bit does the binary bound require?
Check
A Gaussian source of variance v is coded with mean-squared error D, or at rate R.
Step 1
What is the least rate for distortion D (D < v)?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the least distortion at rate R?
Step 3
What SNR is that, in dB?
Explain why
Why does coding many samples together beat quantizing each sample separately, even for a source with independent samples?
A scalar quantizer must tile the line of possible values with cells, and a vector quantizer tiles a space of many dimensions. In many dimensions, cells can be shaped more like spheres, which cover space with less mean-squared error per cell than cubes do; the gain approaches the 1.53 dB that separates the uniform quantizer from the bound. A second gain comes from shaping where the cells go: in many dimensions, independent Gaussian samples almost always land near the surface of a sphere of a predictable radius, so a block code need only cover that thin shell, while a scalar quantizer wastes codes on combinations that essentially never occur. Rate–distortion theory captures both gains in the limit of long blocks, which is why its bound is achievable only by coding samples jointly.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.