Quantization Noise

Round a signal to a few levels and the rounding error acts like random hiss. Its power is Δ²/12, so each extra bit buys 6.02 dB of clean signal.

Learn why a staircase of rounded values can be treated as the original signal plus simple noise, when that trick is true, and what it tells you about bits in audio, images and neural networks.

Pick a signal, then drag the bit depth from 2 up to 12. Watch the purple error shrink and the meter climb. Then we build, piece by piece, the staircase, the saturation limit, the noise model, Bennett’s theorem and its proof, and the 6 dB rule.

You need a feel for a probability density (how likely each value is) and decibels (a log scale for power ratios). We teach both inside the chapters.

Based on Lecture 3 of Stanford EE269: Signal Processing and Quantization for Machine Learning, taught by Mert Pilanci. Course slides. Every idea is re-taught here in our own words and devices; it follows Lecture 2, Discrete Signals.

Squeeze the signal

4

The signals are made up for this page and span full scale (from −1 to +1). The quantizer is the lecture’s uniform midrise quantizer over that range, so the step is 2/2b. The signal-to-noise ratio is measured live on 4,000 samples.

Chapter 0

Why Rounding Leaves a Trace

See why every digital recording carries a faint hiss that nobody added, and what this lecture lets you say about it

You hold a microphone near a guitar string and record one clean note. The note is a smooth wave. You save the file, close the program, and play it back. The note is there, but under it you hear a faint hiss, like a distant waterfall.

No cable made that hiss. No fan was running. The room was silent. The hiss was born at the moment the computer wrote your smooth wave down as numbers.

A computer owns only so many numbers

A computer stores a number in bits. A bit is one switch with two settings, 0 or 1. With b bits you can set the switches in 2b different ways, so you can name only 2b different values. Three bits give 8 values. Eight bits give 256. Sixteen bits give 65,536.

A real sound, a real brightness, a real voltage, can take any value in between. A smooth wave has endless in-between values. The computer must pick the nearest one it owns and keep that instead.

That act is called quantization: replacing a value by the nearest allowed value from a short list. Think of a ruler marked only in whole centimetres. You can measure a pencil, but every answer is a whole number. The part of the pencil between the marks is gone.

The part that is gone has a name too. The quantization error is the true value minus the rounded value. A short list means a big error. A long list means a small one. Played back over time, the string of errors is the quantization noise, and it is the hiss you heard.

The question this lecture answers

Rounding is awkward to study. It is a nonlinear operation: put in twice the signal and you do not get twice the output. The usual tools of signal processing, such as filters and spectra, need linear steps.

So Mert Pilanci’s lecture asks a bold question. Can we pretend that rounding is just adding a small random number to the signal? If we can, the awkward staircase turns into plain addition, and we can compute how loud the hiss is.

The answer is yes, under conditions we can name. The lecture’s outline is the path we will walk, in this order:

  1. The uniform quantizer. A staircase with equal steps (slides 3 to 5).
  2. Saturation. What happens when the signal is too big for the staircase (slide 6).
  3. The noise model. Two assumptions that make rounding look like added noise (slides 7 to 9).
  4. Asymptotic analysis. Bennett’s theorem says when the assumptions hold (slide 10).
  5. Statistical properties. The error has mean 0 and variance Δ²/12 (slide 11).
  6. The 6 dB rule. Each bit makes the signal 6.02 dB cleaner (slides 12 to 15).
  7. Practical takeaways. What bits buy in audio and images (slides 13 to 15). The proof of Bennett’s theorem closes the deck (slides 16 to 20).

Why does a machine learning course care? Because every model you ship is rounded. A neural network weight stored in 8 bits is a quantized number. A camera image is quantized. A microphone feeding a speech model is quantized. The same hiss, and the same rule for its size, appears in all of them.

Feel one rounding before the theory

Drag the number below. The line holds 4, 8 or 16 allowed values between −1 and +1. Watch where your number lands, and how far it must travel to get there.

Round one number

The blue dot is your true value. Warm ticks are the allowed values. The purple bar is the distance the dot must move. Drag the value, then change the bits.

0.370

The allowed values are the lecture’s midrise levels over the range −1 to +1: the middle of each of 2b equal cells. Chapter 1 builds that staircase properly.

Slide the dot slowly. The warm tick it snaps to jumps from one level to the next, and the purple bar flips sides at that moment. The bar never grows past half the gap between two ticks. Keep that fact in your pocket. It is the whole of Chapter 1.

A note on logistics. This is the third lecture of EE269, Signal Processing and Quantization for Machine Learning. The slides are on the course page. They carry no assigned reading, so everything here comes from the deck and from the arithmetic we do ourselves.

Start with the hero at the top of the page. Its three panels are the three characters of this lecture: the blue signal, the warm staircase copy, and the purple error between them. Chapters 1 to 3 explain what you see. Chapters 4 to 6 explain why the purple trace looks so much like noise. Chapters 7 and 8 explain the meter. Chapter 9 proves the claim at the heart of it.

A sensor value is stored in 3 bits. How many different values can the computer keep, and what happens to a true value between two of them?

Chapter 1

The Uniform Quantizer

Build the staircase that rounds any input to the middle of its step, and prove the error can never pass half a step

Walk up a slope that is cut into stairs. You can stand at any height you like on the way, but your feet always rest on a step. The step has a flat top. Every point of the slope above that step, up to the next edge, puts you on the same flat top.

A uniform quantizer is that staircase for numbers. Every step has the same width. You hand it any input, and it hands back the value at the middle of the step your input falls on.

Four things describe the staircase

First, the step size Δ (the Greek letter delta). It is the width of one step. Second, the number of steps, M, which the lecture calls the number of bins. With b bits there are M = 2b of them. Third, the cells: the stretch of input values that share one step. Fourth, the levels: the one value each cell is replaced by, which sits at the middle of the cell.

Slide 4 writes these down. The cells run from k = 0 at the bottom to k = M − 1 at the top. Cell number k starts at (−M/2 + k)Δ and ends at (−M/2 + k + 1)Δ. Its level is half a step above its start: (−M/2 + k + ½)Δ. The two end cells are special. The bottom cell reaches down to minus infinity, and the top cell reaches up to plus infinity, so every real input has a home.

This shape is called a midrise quantizer, because zero sits on the edge between two cells, so the staircase rises through zero. There is no level exactly at zero. (Another design, the midtread quantizer, puts a flat step at zero. The lecture uses midrise throughout, and so do we.)

One formula for the middle of the step

Inside the main range we can write the whole staircase as one line. Ask four small questions about an input x: how many whole steps fit under it, which cell is that, where is the middle, and what number is that in real units?

q(x)
The quantizer output: the level that input x is replaced by.
Δ
The step size. Dividing by it counts in steps; multiplying by it turns steps back into real units.
⌊ x / Δ ⌋
The floor: x measured in steps, rounded down to a whole number. It tells you which cell x is in.
½
Half a step. It moves the answer from the start of the cell to the middle of the cell.

Now a worked case. Take 3 bits over the range −1 to +1. Then M = 8, and Δ = 2/8 = 0.25. The eight levels are −0.875, −0.625, −0.375, −0.125, +0.125, +0.375, +0.625 and +0.875.

Feed in x = 0.37. Step one: x/Δ = 0.37/0.25 = 1.48. Step two: the floor of 1.48 is 1. Step three: add ½ to get 1.5. Step four: multiply by 0.25 to get 0.375. The output is 0.375, and the error is 0.37 − 0.375 = −0.005. Tiny, because 0.37 was near the middle of its step.

Feed in x = −0.61. Divide: −0.61/0.25 = −2.44. The floor rounds down, to −3, not to −2. Add ½ to get −2.5, multiply to get −0.625. The error is −0.61 − (−0.625) = +0.015. Always check negative inputs: the floor of a negative number goes toward minus infinity.

Feed in x = 0.5, exactly on a cell edge. Divide: 2.0. Floor: 2. Add ½: 2.5. Output: 0.625. The error is 0.5 − 0.625 = −0.125. This is the worst case, exactly half a step, and it happens only on the edge.

Climb the staircase

Top: the output q(x) against the input x. The dashed line is “no rounding”. Bottom: the error at each input. Choose the bits, then drag the input along the staircase.

0.370

The range is −1 to +1, so the step is 2/2b. This is the lecture’s midrise quantizer; the numbers 0.37, −0.61 and 0.5 in the text are ours.

Look at the bottom panel. The error is a sawtooth: it climbs in a straight line, jumps back at each cell edge, and climbs again. Its slope is exactly 1, because inside a cell the output is fixed while the input rises. Its height never leaves the band from −Δ/2 to +Δ/2. That picture is the proof of the guarantee.

The guarantee, and what the machine stores

Inside a cell the output is the middle. The farthest an input can be from the middle is half the cell, which is half a step. So for every input in the main range, |x − q(x)| ≤ Δ/2. No input, however unlucky, breaks that bound.

Now follow the data. The encoder takes a real number and produces an integer code k from 0 to M − 1. That integer is what is stored: exactly b bits. The decoder takes k and rebuilds the level. Nothing else travels.

pythondef encode(x, b, A=1.0):          # x: float in, k: int out (b bits)
    M, D = 2**b, 2*A / 2**b
    k = int(math.floor(x / D + M / 2))
    return min(max(k, 0), M - 1)  # the two end cells reach to infinity

def decode(k, b, A=1.0):          # k: int in, level: float out
    M, D = 2**b, 2*A / 2**b
    return (k - M / 2 + 0.5) * D

The min and max line is the two infinite end cells from slide 4. Without it, a large input would produce a code outside the b-bit range. Chapter 3 shows what that clamp costs.

Notice the trade at the heart of the design. Fix the range, say −1 to +1. Then more bits mean more cells, so a smaller Δ, so a smaller worst error. Each extra bit halves Δ. Hold on to that sentence. By Chapter 7 it becomes the 6 dB rule.

A midrise quantizer has 16 levels over the range −1 to +1. What are its step size and its largest error inside the range?

Chapter 2

Quantizing a Cosine

Quantize a real wave sample by sample, then look at, and listen to, the error signal it leaves behind

Take the simplest wave there is, a cosine. It rises, falls and repeats. A microphone turns a pure musical note into something very close to it. Now we digitize that wave in two moves, and the lecture’s fifth slide shows both.

First comes sampling: we read the wave at evenly spaced moments and keep a list of numbers, x0, x1, x2 and so on. (Lecture 2 covers sampling.) Second comes quantization, the staircase of Chapter 1, applied to each number in the list.

Three lists of numbers

After both moves you hold three lists, all the same length. The signal xn is what the wave really was at sample n. The quantized signal q(xn) is what you stored. The error signal εn = xn − q(xn) is the gap at each sample. The error list is a signal in its own right, and it is the one the rest of the lecture studies.

Rearrange the definition and you get q(xn) = xn + εn. Read it aloud: what you stored is the true signal plus the error. This is not an approximation. It is just the definition of ε, written the other way round. The approximation comes later, when we describe ε as random.

One cosine, sample by sample

Use 3 bits on the range −1 to +1, so Δ = 0.25 and the levels are the eight of Chapter 1. Let xn = 0.9 cos(2πn/16): one full wave every 16 samples. Here are the first six samples, worked with the formula q(x) = Δ(⌊x/Δ⌋ + ½).

nxnx/Δfloorq(xn)εn
00.90003.60030.875+0.0250
10.83153.32630.875−0.0435
20.63642.54620.625+0.0114
30.34441.37810.375−0.0306
40.00000.00000.125−0.1250
5−0.3444−1.378−2−0.375+0.0306

Read the errors down the last column. They wobble above and below zero: +0.025, −0.0435, +0.0114, −0.0306, −0.125, +0.0306. Each is under 0.125, half a step, as promised. Row 4 deserves a second look. The true signal is exactly zero, silence, but a midrise quantizer has no level at zero. It must pick +0.125, so it turns silence into a small constant offset.

Now watch the same thing at scale. The device below uses 100 samples. Move the bits and the number of cycles, and read the error trace against the signal.

Quantize a cosine

Top: 100 samples of the cosine (blue) and their rounded values (warm). Bottom: the error at each sample (purple), with the ±Δ/2 band. Press a button to hear a 440 Hz tone, or only its error.

3
2

The plot uses the cosine 0.9 cos(2π·cycles·n/100) with the range −1 to +1. The sound is a 440 Hz sine at 0.9 of full scale, rounded at 44,100 samples a second, one second long, played quietly. The error-only sound is scaled to the same peak at every bit depth so you can hear its character, not its loudness.

At 1 or 2 bits the error is not random at all. It is a tidy repeating pattern, a sawtooth that restarts with every wave. Press Hear only the error at 2 bits: you hear a buzzy tone, not a hiss. The error is a fixed function of the signal (the sawtooth of Chapter 1), so a periodic signal makes a periodic error. Periodic means harmonics, extra pure tones stacked on the note.

Raise the bits to 6 or 8. The pattern breaks up. The error still lives inside its band, but now it jumps around with no visible rhythm, and the error-only sound turns into a soft hiss. Something changes between 2 bits and 8 bits that makes a deterministic error behave like noise. Chapter 5 names it.

Compare the loudness too. Play the tone at 3 bits and at 8 bits. At 3 bits you hear the crunch over the note. At 8 bits you hear almost nothing. The size of the error band is Δ/2, and Δ halves with each bit, so the error halves too.

Follow the data one more step. One second of sound at 44,100 samples a second is a list of 44,100 real numbers, with shape (44100,). The encoder turns each into an integer code, so the stored list is again (44100,), now with b bits per entry. At 16 bits that is 88,200 bytes for one second of one channel. The decoder reads the codes back and rebuilds the levels. The hiss you hear is the list of 44,100 errors, one per sample, played as if it were a sound of its own.

Why does the error matter more when the wave is quiet? A quiet signal uses only a few cells near zero. The error band stays the same size, but the signal is small next to it. Chapter 3 pushes this to the edge, and Chapter 7 puts a number on it.

You quantize a pure repeating wave to 2 bits. What does the error signal look like, and why?

Chapter 3

Saturation and Overload

Find the edge of the staircase, see the error stop being small past it, and learn why a signal that is too quiet also loses

A singer leans into a microphone and shouts. On the recording desk, a red light flashes. On playback, the loudest moments sound harsh and flat, as if someone had sliced the tops off the wave. Nothing is broken. The wave was simply taller than the quantizer could count.

A staircase has a top step and a bottom step. Anything above the top step is stuck on it. Chapter 1 hid this behind a clamp in the code. Now we pay for that clamp.

Two regions

The lecture splits the input line in two. The no-overload range (also called the granular range) is every input between −MΔ/2 and +MΔ/2, the span of the M ordinary cells. Inside it, an input maps to the middle of its cell and the error is at most Δ/2. That is Chapter 1’s guarantee.

The overload range is everything outside. There, the input lands in an end cell that reaches to infinity, and the output is stuck at the end level. The error is larger than Δ/2, and nothing limits it. This is saturation, or clipping. The farther the input goes past the edge, the worse the error gets.

The size is easy to write. The top level sits half a step below the edge, at (M − 1)Δ/2. For an input x above the edge, the output is that level, so the error is the gap.

ε
The quantization error: input minus output. In overload it grows without a limit.
x
The input, beyond the top edge of the range.
(M − 1)Δ/2
The top level: the middle of the top cell, half a step below the edge. The output is stuck here.
MΔ/2
The top edge of the no-overload range. Past this line, the clamp starts.

A worked case. Use 3 bits over −1 to +1: M = 8, Δ = 0.25, the edge at MΔ/2 = 1.0, the top level at 0.875. Input 1.0 sits right on the edge. The error is 1.0 − 0.875 = 0.125, which is Δ/2, still within the guarantee. Input 1.3 gives 1.3 − 0.875 = 0.425, which is 1.7 steps. Input 2.0 gives 1.125, which is 4.5 steps. Every extra 0.1 of input adds 0.1 of error, one for one.

Two kinds of noise

So there are two sources of error. Granular noise comes from rounding inside the range: small, bounded by Δ/2, spread evenly. Overload noise comes from clipping outside: large, unbounded, and concentrated at the loud peaks. The rest of this lecture studies granular noise, and its main theorem assumes no overload at all. Overload is the failure we must design away.

That design choice has a catch. You fix the number of bits, so M is fixed. The only free choice is Δ, which sets the range MΔ/2. Make the range wide and nothing clips, but each step is wide too, so granular noise is large. Make the range narrow and the steps are fine, but loud peaks overload. You cannot win both ways. Pilanci’s deck states the saturation rule, and the engineering consequence is a balance.

The device below draws that balance for a sine wave. The slider sets how tall the wave is, as a fraction of the staircase’s full scale. The curve on the bottom is the signal-to-noise ratio measured at every height. You will meet the SQNR formally in Chapter 7. For now, read it as: the higher the curve, the cleaner the sound.

Fit the wave to the staircase

Top: the wave (blue) and its rounded copy (warm); red marks every sample that overloads. Bottom: how clean the result is (SQNR) at each height; your height is the dot. Drag the height past 1.0, then below 0.1.

1.00

Wave height 1.00 means the wave just touches the edge of the range. The curve is computed live in your browser from a sine sampled 512 times at each of 70 heights; it is not a formula. At 4 bits, a wave under about 0.06 stays inside the two middle cells, so the error can be as large as the signal.

Read the curve from the left. Below full scale it climbs in a straight line. Each time you double the height, the curve rises by about 6 dB. That is not a coincidence. A wave that is half as tall uses half as many cells, so it behaves as if you had one bit fewer. Halving the height costs exactly one bit of clean sound.

Then the curve peaks near a height of 1.0, the wave that just fills the range. This is the best use of the bits. Past that, the curve falls off a cliff. At height 1.4, about half of the samples overload, and the tops of the wave are sliced away. At 8 bits the clean sound falls from 49.8 dB at height 1.0 to 25.8 dB at height 1.1. The error is no longer a tiny wobble. It is a big, structured piece cut out of every peak.

The cut-off peaks are harmful in a second way. Slicing the tops of a wave adds new frequencies that were not in the music. The result is the harsh sound you heard on the shouted recording. In an image, the same thing is a pure white patch where the sky was: detail that is gone and cannot be rebuilt.

For a builder this gives a plain rule. Use the whole range, but do not exceed it. Recording engineers call the safety room they leave headroom. Weight quantizers in neural networks do the same: they pick the range from the largest weight, or clip the rare outliers on purpose. Chapter 7 gives a number to that choice, a loading factor.

A 3-bit quantizer covers −1 to +1, with its top level at 0.875. The input is 1.3. What is the error, and is it within Δ/2?

Chapter 4

Rounding as Added Noise

Replace the awkward staircase with a clean signal plus a small random number, and learn the two assumptions that make this work

A mechanic who must predict how a faulty engine behaves does not model every cracked part. She says: the good engine, plus a rattle of about this loudness. The rattle is easy to describe. The cracked parts are not. If that description is good enough, she can plan the whole repair around the rattle.

Signal engineers do the same with rounding. The quantizer is the cracked part: a nonlinear staircase. They replace it with the true signal plus a rattle, and the rattle is the quantization noise.

The additive noise model

Slide 7 defines the error as ε = x − q(x). For a whole sequence of inputs xn, there is a whole sequence of errors εn. Chapter 2 showed that q(xn) = xn + εn. The slide draws that as a block diagram: the input xn enters a summing node, the error εn is added from above, and q(xn) comes out. This is the additive noise model.

As a statement of fact, the model is trivially true. As a tool, it is empty until we say what εn looks like. If we know its statistics, we can ask real questions. How loud is the hiss? What does a filter do to it? Does it add up when we mix tracks? Those questions need numbers, not a staircase.

Two things we need to know about the noise

Before the assumptions, two small ideas. First, a probability density says how likely each value is. Imagine measuring a million errors and stacking them into a histogram, with a bar for each small range of values. As the bars get thinner and the count grows, the bar tops trace a smooth curve. That curve is the density. A uniform density is flat: every value in its range is equally likely.

Second, correlation asks whether two numbers move together. If a big error tends to be followed by another big error of the same sign, the two are correlated. If knowing one tells you nothing about the next, they are uncorrelated. Sequences whose neighbours are all uncorrelated are called white noise, the same flat hiss you get from a radio tuned between stations.

Now slide 8 says what we would like to be true. The error is a bit like a fair spinner on a dial that runs from −Δ/2 to +Δ/2, spun fresh at every sample.

(A1)
The first assumption: each error is uniformly distributed over one step, centred on zero.
fε(e)
The probability density of the error at value e. A flat density of height 1/Δ over a width of Δ has total area 1, as a density must.
Δ
The step size. The error range is exactly one step wide.
(A2)
The second assumption: errors at different samples are uncorrelated, so the noise is white.
E[εi εj]
The average of the product of two errors. It is zero when they do not move together.
i ≠ j
Two different sample positions in the sequence.

If both hold, the noise is simple to describe, and everything in Chapters 6 and 7 follows. Slide 9 then says something blunt: these assumptions are usually false. Pilanci puts it on its own slide so that nobody forgets.

Why they are usually false: a worked case

Feed the quantizer a constant, say x = 0.3 at every sample, with 3 bits (Δ = 0.25). Then 0.3/0.25 = 1.2, the floor is 1, add ½ to get 1.5, and the output is 0.375. The error is 0.3 − 0.375 = −0.075. It is −0.075 at every sample, forever.

Check (A1). The density is one single spike at −0.075, not a flat curve. The mean error is −0.075, not 0. Check (A2). E[εiεj] = (−0.075)(−0.075) = 0.0056, not 0. Both assumptions fail completely, because the error is a fixed function of a fixed input.

Now try a signal that changes slowly. Between two samples it moves a tiny fraction of a step. Both samples land in the same cell, at almost the same spot, so their errors are almost equal. Neighbouring errors are strongly correlated. Only a signal that jumps across many cells between samples can break that link. The device lets you test four signals at once.

Test the noise assumptions

Top: the first 100 errors, scaled to the band. Bottom: a histogram of 4,000 errors against the flat line that (A1) predicts. Pick a signal, then raise the bits.

4

Constant: 0.3. Slow sine: 0.9 sin(2π · 0.0012 n), almost five waves in 4,000 samples. Fast chord: three sines at 0.0731, 0.1713 and 0.2897 cycles per sample. Noise: Gaussian with spread 0.25, clipped to the range. All are our own toy signals. Neighbour correlation is the sum of εnεn+1 divided by the sum of εn2. Distance from flat is half the summed gap between the histogram and a flat 20-bar histogram.

Start on Constant. The histogram is one tall bar (0.95 from flat) and the neighbour correlation is 1.00: the worst possible. Raising the bits only moves the spike. A constant never becomes noise.

Move to Slow sine. Its histogram looks nearly flat at every bit depth, because over time the wave sweeps across every cell. So (A1) can pass. But at 4 bits the errors form long smooth runs, a sawtooth, with neighbour correlation 0.82. At 5 bits it is 0.61. The signal is slow, so neighbours stay in the same cell and have almost the same error. The correlation fades only near 6 to 8 bits, when a step becomes small next to the change between samples. This is a case where (A1) holds and (A2) fails.

Now Fast chord and Noise. Both jump by more than a step between samples, even at 2 or 3 bits. The histogram sits close to the dashed line, within 0.05, and the neighbour correlation stays within 0.03 of zero at every bit depth you can pick. Here both assumptions are nearly true, and the additive model is a very good description.

So the lecture’s warning and its hope are both right. The assumptions are false in general, and good in a precise situation: many cells, a signal that wanders widely across them, and a smooth distribution of values. Chapter 5 turns that situation into a theorem.

A slowly drifting sensor reading is quantized with a fine step, and its error stays almost the same from one sample to the next. Which assumption fails?

Chapter 5

Bennett’s Theorem

Learn the four conditions that turn a deterministic rounding error into a uniform, white one, and test each condition yourself

Picture a wide, slow river with a smooth current, and a row of fence posts standing in it, one post every metre. A leaf floats down. Where does it pass between two posts? Anywhere. The current is so even across one metre that the leaf is equally likely to be at any spot in the gap.

Now move the posts a kilometre apart, or make the current change sharply every few centimetres. The leaf is no longer equally likely anywhere in the gap. The current has changed too much inside one cell for the guess to hold.

That is Bennett’s idea. The posts are the quantizer cells. The leaf is the input value. The spot in the gap is the rounding error.

The statement

Slide 10 states it as a theorem. It says that as the number of bins grows to infinity and Δ goes to zero, assumptions (A1) and (A2) become correct. Four conditions go with it:

  1. The input is in the no-overload region. Nothing clips. This is Chapter 3’s overload rule.
  2. M, the number of bins, is asymptotically large. There are very many cells.
  3. Δ is asymptotically small. Each cell is narrow. (With a fixed range, conditions 2 and 3 are the same fact seen from two sides.)
  4. The probability density of the signal is smooth. It changes gently, with no spikes, jumps or gaps.

The word asymptotically means “in the limit”. The theorem is a promise about the limit, not about any finite b. At a real bit depth you get approximate truth, and the approximation is better the more bits you have. Bennett proved a version of this in 1948, which is why the theorem carries his name.

Why the four conditions are the right ones

Take each in turn. Condition 4, smoothness, is the river. If the density of the input is smooth, then across one narrow cell it is almost flat. Inside the cell, every position is almost equally likely. The error is how far the input sits from the cell’s middle, so every error from −Δ/2 to +Δ/2 is almost equally likely. That is (A1).

Conditions 2 and 3 make “almost flat” precise. A density can only look flat across a cell if the cell is narrow compared with how fast the density bends. Many narrow cells give many small chances for that to hold, everywhere along the density.

Condition 1 keeps the clamp out of the story. Overloaded inputs land in an end cell with an error that is not bounded by Δ/2, so they can never look uniform on that band.

What about (A2)? The deck states it as part of the theorem but works out only the one-sample argument in its proof. The intuition is the same: if the joint density of two samples is smooth, knowing where one sample fell in its cell tells you almost nothing about where the other fell in its. Chapter 9 proves the one-sample case, which gives (A1).

One more point on honesty. The deck itself labels its conclusion heuristic. It is a good argument, not a full proof, and the rest of the lecture treats it as an engineering tool.

The test bench

Let us check the four conditions on a computer. The input here is a Gaussian, the familiar bell-shaped density, which is smooth. You choose its spread σ (how wide the bell is) and the bits. The key number is how many steps the bell spans: σ/Δ.

Break each condition

Top: the input density (blue) and the cells. Middle: histogram of the errors against the flat line. Bottom: how far from flat the errors are, against how many steps the input spans; your setting is the dot. Narrow the input, widen it toward the range edge, or switch to a spiky input.

5
0.10

The range is −1 to +1. The bell is Gaussian with the spread you choose, from 0.01 to 0.8; inputs beyond the range overload. The two-valued input is 4,000 draws from just −0.3 and +0.1, a density that is as unsmooth as possible. Distance from flat counts any error outside the band as wrong. The curve is computed live from a quantizer with no range limit and step 1. All settings are our own toy tests of the theorem.

Start with the smooth bell at 5 bits and a spread near 0.10. The spread covers about 1.6 steps, and the distance from flat is only 0.03. Now narrow the bell to its minimum, 0.01. The whole bell sits inside the two middle cells, the histogram piles into a lump, and the distance from flat jumps to 0.39. The density is no longer flat across a cell: condition 3 fails.

Fix that by adding bits. At 8 bits the same narrow bell covers 1.3 steps and the distance falls back to 0.04. A finer step restores the condition.

Now widen the bell toward 0.8. The histogram stays flat while the bell grows, but the tails of the bell begin to reach beyond ±1. At 0.8, 22% of the inputs overload and the distance from flat climbs to 0.22. That is condition 1 failing, and no bit depth helps, because the clamp is not a rounding effect.

Now switch to Two fixed values. Raise the bits to 10. Nothing helps. The errors take just two values, forever, whatever the step. A density with spikes breaks condition 4, and more bits cannot rescue it.

The bottom curve is the law behind all of this. For a smooth input it depends on one number, σ/Δ. Once the input spans more than about half a step, the distance from flat is already near its floor of about 0.03, which is just the sampling wobble of 4,000 draws. That is why a few bits are enough for most real signals: audio, images and sensor data are wide, smooth and busy compared with their step.

The takeaway. Rounding becomes noise-like not because the error is random, but because the signal is busy. When the signal covers many cells, the position inside each cell is a coin the quantizer cannot predict.
Which change makes the uniform-error assumption (A1) worse for a Gaussian input quantized to 6 bits?

Chapter 6

How Loud Is the Hiss?

Compute the mean and the power of the rounding noise from one flat density, and check the answer by drawing errors

A friend hands you a fair spinner. Its pointer can stop anywhere on a dial marked from −5 to +5, and every spot is equally likely. You have never seen it spin. Can you say what its average reading will be, and how widely the readings will scatter? Yes. The dial alone tells you.

Quantization noise under (A1) is that spinner, with a dial from −Δ/2 to +Δ/2. This chapter reads off its two key numbers: the average, and the power.

Two ideas to carry

The expected value E[ε] is the average of ε over very many draws. The variance Var[ε] is the average of the squared distance from that average. It measures how widely the draws scatter, and the squaring makes every miss count as positive.

Here is why we care about the second one. The power of a noise signal is the average of its square. Loudness depends on squares: a sound wave carries energy proportional to its height squared. When the average error is zero, the variance is the power. So to know how loud the hiss is, we need the variance.

The mean is zero

Slide 11 starts here. Under (A1) the density is flat on a band that is the same width on both sides of zero. Every positive error has an equally likely negative twin. They cancel in the average, so E[εn] = 0. The slide writes this as the average of q(xn) − xn and notes it is zero. The sign order does not matter, since the band is symmetric.

The variance, one step at a time

The variance of a variable with density f is the integral of e² times f(e). An integral is a sum over a continuum: slice the band into thin strips, multiply each strip’s e² by its probability, and add them up. Here the density is the constant 1/Δ on the band.

Var[ε]
The variance of the error, which equals E[ε²] here because the mean is 0. It is the noise power.
1/Δ
The flat density from (A1). Its height is 1/Δ so that the area over a band of width Δ is 1.
−Δ/2 to Δ/2
The limits of the integral: the whole error band.
e²
The squared error at value e: the power that value contributes.
Δ²/12
The answer: the noise power depends on the step size alone.

Work the integral in four short steps. Step one: the antiderivative of e² is e³/3. Step two: evaluate it at the two limits, (Δ/2)³/3 − (−Δ/2)³/3 = 2(Δ/2)³/3. Step three: (Δ/2)³ = Δ³/8, so this is 2Δ³/24 = Δ³/12. Step four: multiply by 1/Δ to get Δ²/12. The slide states the same result, Var[εn] = Δ²/12.

There is a picture. Plot e² across the band: a parabola, zero in the middle and (Δ/2)² = Δ²/4 at each edge. The variance is the average height of this parabola. A parabola’s average height over its width is one third of its peak: Δ²/4 divided by 3 is Δ²/12. The 12 comes from 4 times 3.

Real numbers

Take 8 bits over −1 to +1. The step is 2/256 = 0.0078125. Its square is 6.1035 × 10−5. Divide by 12 to get a noise power of 5.086 × 10−6. The typical error, the square root, is Δ/√12 = 0.2887Δ = 0.00226. The largest possible error is Δ/2 = 0.0039. So the typical error is about 58% of the biggest.

For 3 bits, Δ = 0.25, the power is 0.0625/12 = 0.00521, and the typical error is 0.0722. In Chapter 2 we found six real errors for a cosine at 3 bits. Their root-mean-square is 0.058. That is the right size for six samples, and a long run gets closer to 0.0722.

Is that really so? Do not trust the algebra alone. The device below draws errors from a busy input, one batch at a time, and keeps a running tally. Pick the bits, press the buttons, and watch the tally settle.

Draw errors, watch the tally

Top: the squared error across the band, with each draw as a dot on the parabola. Bottom: the running average square, in units of Δ², against the theory 1/12. Draw a few, then thousands.

4

The inputs are 4,000 Gaussian draws with spread 0.3 (our toy choice), quantized at the bits you pick, in the same fixed order each time. Errors are shown in units of Δ so the picture looks the same at every bit depth. The theory line is Δ²/12, which is 0.0833 in these units.

After 10 draws the tally jumps around, sometimes far from the line. After 1,000 it sits within a few percent of it. After 4,000 it is nearly on top. That is the law of large numbers: averages of many draws settle on the expected value. Change the bits and the units stay the same, because the result is a fixed fraction, one twelfth, of Δ².

The result also tells us how the noise power scales. It goes with Δ². Halve the step and the power falls by four. Chapter 1 said each extra bit halves Δ, so each extra bit divides the noise power by four. Chapter 7 turns that into decibels.

A quantizer has step size 0.1. Under the uniform error model, what is the noise power?

Chapter 7

The 6 dB Rule

Measure the hiss against the signal, convert the ratio to decibels, and prove that every extra bit buys exactly 6.02 dB

Suppose your hiss has a power of 0.000005. Is that a lot? For a whispered voice, it might drown the words. For a shouted one, you would never notice. A noise level means nothing alone. It matters only against the signal it sits beside.

So engineers use a ratio: the signal power divided by the noise power. A big ratio means a clean signal. This ratio has a name, and slide 12 opens with it.

The ratio, and a ruler for it

The signal-to-quantization-noise ratio, or SQNR, is SQNR = E[x²] / E[ε²]: the average signal power over the average noise power. If the signal has zero mean and variance σ², its power is σ². Chapter 6 gave the noise power as Δ²/12. So the slide writes SQNR ≈ σ² / (Δ²/12), which is 12σ²/Δ².

Ratios like this span huge ranges, from 10 to 10 billion. A logarithm compresses them. The base-10 logarithm of a number counts its zeros: log10(100) = 2 and log10(1,000,000) = 6. A decibel (dB) is ten times the base-10 logarithm of a power ratio. A ratio of 10 is 10 dB. A ratio of 100 is 20 dB. A ratio of 1,000 is 30 dB. Every factor of 10 in power adds 10 dB.

Two more values to keep. A ratio of 2 in power is 3.01 dB. A ratio of 4 in power is 6.02 dB. Notice that 6.02 = 2 × 3.01, because doubling twice multiplies by four, and logarithms turn multiplying into adding.

SQNRdB
How far the signal power stands above the noise power, in decibels. Bigger is cleaner.
12σ²
Twelve times the signal variance. The 12 comes from the noise power Δ²/12, moved to the top of the fraction.
Δ²
The squared step size. It controls the noise power: halve the step and this falls by four.

Where 6 dB comes from

Halve the step, and Δ² falls to a quarter, so the ratio inside the logarithm becomes four times bigger. The change in decibels is 10 log10(4) = 20 log10(2) ≈ 6.02 dB. That is the slide’s line: halve Δ and SQNR improves by 20 log10 2 ≈ 6.02 dB.

Now connect Δ to bits. A uniform quantizer covering a total range of 2A, from −A to +A, with b bits has 2b steps. Each is Δ = 2A / 2b. One more bit doubles the number of steps and halves Δ. So each bit adds about 6.02 dB. This is the 6 dB rule.

There is a catch: the rule gives the slope, not the starting height. The full answer depends on how big the signal is compared with the range. Let the range edge A equal K times the signal spread, A = Kσ. The number K is the loading factor: how many signal spreads fit inside the range. Then Δ = 2Kσ/2b.

Work the algebra. Step one: Δ² = 4K²σ²/4b. Step two: 12σ²/Δ² = 12σ² · 4b / (4K²σ²) = 3 · 4b / K². The σ² cancels. Step three: in decibels, 10 log10(3) = 4.77, 10 log10(4b) = 6.02b, and 10 log10(1/K²) = −20 log10K.

SQNRdB ≈ 6.02 b + 4.77 − 20 log10 K

The signal size dropped out. Only the bits b and the loading K are left. Three cases: a full-scale sine wave has σ = A/√2, so K = √2 = 1.41, and the offset is 4.77 − 3.01 = +1.76 dB. A bell-shaped signal loaded at K = 4 (the range reaches four spreads) has an offset of 4.77 − 12.04 = −7.27 dB. A signal that fills the range evenly has K = √3 and an offset of 0.

A worked number. With b = 8 and K = 4: 6.02 × 8 = 48.16. Then 48.16 + 4.77 = 52.93. Then subtract 12.04 to get 40.89 dB. The device below measures it and compares.

Measure the 6 dB per bit

The dashed line is the formula. The warm dots are measured on 6,000 samples at each bit depth. Pick a signal, then slide the bits. Look at where the dots leave the line.

8

Bell means Gaussian with spread 1/K, quantized over the range −1 to +1; draws past the range overload, which is why K 2 sags. The sine is full scale. The formula is 6.02 b + 4.77 − 20 log10 K. All signals and loadings here are our own toy tests of the lecture’s formula.

For the bell at K = 4, the dots sit on the line from 2 bits all the way to 14. At 8 bits the measured value is 41.0 dB against a formula value of 40.9. Only at 1 bit is it off, by about 1.2 dB, because two cells are too few for the noise model of Chapter 5.

Now choose K = 2. The dots rise with the line for 3 or 4 bits and then flatten. At 8 bits the formula says 46.9 dB and the measurement says 19.2. About 5% of the draws now fall beyond two spreads and overload, and overload noise is not in the formula. It sets a floor near 19 dB, and no extra bit can lift the SQNR past it. K = 3 flattens in the mid 30s of dB. Overload sets a ceiling, and the loading factor decides where it sits.

Pick the sine and compare 8 bits to 16: the gap is 8 × 6.02 = 48.2 dB. The rule is remarkably exact for a busy signal at many bits, which is what the next chapter puts to use.

A 12-bit quantizer gives a certain SQNR. You need 18 dB more. How many extra bits does the 6 dB rule say you need?

Chapter 8

What Bits Buy in Sound and Pictures

Use the 6 dB rule to read a bit-depth table, see why codecs spend bits unevenly, and find where the eye stops needing more

A sound engineer is handed a job: record a choir for a CD. A different engineer must send voice down a telephone line. A third must store a photograph. Each asks the same question: how many bits per sample is enough? Too few, and the hiss shows. Too many, and the file is huge for no gain.

The 6 dB rule answers this. It turns “how clean must it sound?” into “how many bits?”. Slides 13 to 15 do exactly that for audio and images.

The audio table, and its hidden offset

Slide 13 lists five bit depths and the SQNR each gives, for uniform quantization with full-scale use and no overload. We have put the slide’s numbers in a table and added one column: what Chapter 7’s formula gives.

BitsSQNR on the slide6.02 b + 1.76Typical use (slide 13)
4about 25 dB25.8 dBSevere audible distortion
8about 50 dB49.9 dBTelephone PCM, AM radio quality
12about 74 dB74.0 dBHigh-quality speech, FM radio, early digital audio
16about 98 dB98.1 dBCD-quality audio, professional distribution
24about 146 dB146.2 dBStudio recording

The slide’s numbers are the full-scale sine formula to the nearest whole decibel. That hidden +1.76 dB is the offset from Chapter 7 with K = √2. Each row is 6.02 dB per bit higher than the one before, scaled by the bit gap: from 8 to 16 bits is 8 × 6.02 = 48.2 dB.

Slide 15 says 6 dB per bit, so 8 bits is about 48 dB, without the offset. Both are right. 48 uses the bare slope, 50 includes the offset for a full-scale sine. For rough engineering the difference is a rounding error. Notice how the table sorts the world: 8 bits is a phone call, 16 bits is a CD, 24 bits is a studio.

Why would a studio use 24 bits, if no ear can use 146 dB? The faintest sound you can hear and one that hurts are roughly 120 dB apart (a common textbook figure, not from the slides). A studio adds, filters and mixes many tracks. Each step rounds again, and the rounding noise adds up. Spare bits at the start keep the final mix clean.

Climb the bit-depth ladder

Each bar is one standard bit depth, as long as its SQNR. The teal line is your bit depth. Slide it past each bar and watch which uses it clears.

13

The five bars and their uses are slide 13’s. Your line is 6.02 b + 1.76, for a full-scale sine with no overload, as in the slide’s table.

Not every file keeps its bits

Slide 14 draws a line between two families. WAV, AIFF and FLAC keep a true bit depth: every sample is stored at the stated number of bits. (FLAC compresses the file without changing a single sample.) MP3, AAC and MP4 do not have a fixed bit depth. They use psychoacoustic quantization: they spend bits according to what the ear can hear. The effective number of bits varies in time, in frequency and across channels.

The idea rests on masking. A loud tone hides quieter sounds at nearby pitches. If noise is hidden anyway, it can be loud. A codec splits the sound into frequency bands, finds how much noise each band can hide, and quantizes that band just coarsely enough to keep its noise under that line. By the 6 dB rule, a band that needs to stand X dB above its allowed noise needs about X/6.02 bits.

Spend bits where the ear listens

Eight frequency bands, low to high. Blue is the signal, purple is the loudest noise each band can hide, and the yellow number is the bits that band needs. Drag the loudness of the masker in band 3.

85 dB

Illustrative: the band levels, the hearing threshold and the masking spread (15 dB below the masker, falling 9 dB per band away) are made up for this page. Real codecs use measured models. The rule that a band needs ceil(distance above its allowed noise / 6.02) bits is Chapter 7’s.

Drag the masker louder. The bands beside it hide more noise, so they need fewer bits. Drag it quieter and they need more. A fixed 16 bits in every band would waste almost all of them. That is how MP3 and AAC reach small files: the quantizer is not a single uniform staircase but a different one for each band and each moment.

Pictures: the eye stops at 8 bits

For images, slide 15 gives the same arithmetic: at 6 dB per bit, 8 bits gives about 48 dB of SQNR, and the slide says human vision saturates around this level for uniform noise. That is why PNG and JPEG use 8 bits for each colour channel. The deck adds that 10-bit and 12-bit images exist only for HDR (high dynamic range) or professional post-processing.

Look at it yourself. The picture below is a smooth sky, a glowing sun and a dark hill. The left half is kept at 8 bits, the right half at the bits you choose.

Watch the sky band

Left of the line: 8 bits. Right: your bit depth. Drag the bits down and look at the smooth sky for steps.

3

A synthetic grey picture made for this page, drawn in your browser. The SQNR is measured over its pixels against the original, treating grey as a value from −1 to +1. Your screen shows only 256 grey levels, so the left half is the best it can display.

At 2 or 3 bits the sky breaks into wide stripes: the error is no longer noise but structure, as in Chapter 4. At 6 bits the stripes are faint. At 8 bits you cannot find a step. The error there sits about 48 dB under the picture, below what the eye notices. Past that, more bits give no visible gain, except room for editing.

The same arithmetic applies to the weights of a neural network. Store a bell-shaped list of weights in 8 bits with the range reaching four spreads, and Chapter 7’s formula gives 40.9 dB. Store them in 4 bits and it gives 16.8 dB. Fewer bits, more noise, and how much a model suffers depends on whether it can tolerate that noise. The next lectures, on the Lloyd-Max quantizer and dithering, show how to do better than a plain uniform staircase.

An MP3 file does not have a fixed bit depth. Why can it get away with so few bits in some frequency bands?

Chapter 9

Proof of Bennett’s Theorem

Follow the deck’s five-step argument, slice by slice, from a smooth density to a flat error

You run a bakery that cuts a loaf into 16 equal slices. Each slice has crumbs spread through it, and the crumb count changes gently from one end of the loaf to the other. A customer asks: “What fraction of all the crumbs sit in the first 40% of their slice?” You do not need to measure every slice. If the crumb density barely changes across one slice, the answer is simply 40%.

That is the whole proof. The loaf is the range of the signal, the slices are the quantizer cells, and the first 40% of a slice is the set of inputs whose error is below a chosen value. This chapter walks the five steps of slides 16 to 20 and shows every number.

Three tools, defined first

The proof uses three standard tools. The cumulative distribution function, or CDF, of the error, Fε(α) = Pr(ε ≤ α), is the total probability that the error is at most α. It climbs from 0 to 1. The density is its slope: where the CDF is a straight line of slope 1/Δ, the density is flat at 1/Δ.

The mean value theorem for integrals says: on a smooth stretch, the area under a curve equals the curve’s height at some point of the stretch, times the stretch’s width. If the curve is nearly flat, that height is nearly any height on the stretch.

A Riemann sum adds the areas of thin bars to estimate an integral. Bars of width Δ and heights f(yk) have total area Σ f(yk)Δ, which approaches the integral of f as Δ shrinks.

Step 1: the setup (slide 16)

Let Xn be a continuous random variable with density f. The quantizer is the midrise one with step Δ and M cells. Cell Rk runs from −MΔ/2 + kΔ to −MΔ/2 + (k + 1)Δ, for k = 0 up to M − 1. The error εn = Xn − Q(Xn) lies in (−Δ/2, Δ/2). We want its marginal law: how likely each error value is, ignoring the other samples.

Step 2: split the probability by cell (slide 17)

The error is at most α if Xn fell in some cell and landed low enough within it. Add up over cells: Pr(ε ≤ α) = Σk Pr(ε ≤ α and Xn ∈ Rk). This is the law of total probability: the cells do not overlap and together cover every input.

Step 3: one slice of one cell (slide 18)

Inside cell Rk, the event “error at most α” is a slice at the bottom of the cell: all X from the cell’s left edge up to a point. The slide measures the slice width α from that left edge, so its α runs from 0 to Δ. In terms of the error itself, which is measured from the cell’s middle, shift by Δ/2. The final law is the same.

The probability of the slice is the area of the density over it: the integral of f from the left edge to the left edge plus α. If f is smooth compared with Δ, the mean value theorem says this equals f(yk) times α, for some point yk in the cell. That is the one approximation, and it is where the word smooth enters.

Step 4: add the slices up (slide 19)

Sum over all cells: Pr(ε ≤ α) ≈ α Σ f(yk). Multiply and divide by Δ: this is (α/Δ) Σ f(yk)Δ. The sum is now a Riemann sum for the integral of f over the whole range, which is 1 (a density has total area 1, and condition 1 says no input falls outside the range). So Pr(ε ≤ α) ≈ α/Δ.

Pr(ε ≤ α)
The CDF of the error: the chance that the error is at most α.
α
The slice width, measured from the left edge of a cell as the deck does. It runs from 0 to Δ.
Δ
The step size. The ratio α/Δ is the fraction of the cell that the slice covers.
fε(α)
The density of the error at α.
d Fε/dα
The slope of the CDF. A straight line of slope 1/Δ has this slope everywhere, so the density is flat.

Step 5: read off the density (slide 20)

Differentiate the CDF. A straight line from 0 to 1 over a width Δ has slope 1/Δ, so fε(α) ≈ 1/Δ on the band. The error is approximately uniform on [−Δ/2, +Δ/2], and nothing in the derivation mentions the input density. The slide closes with that: the error is independent of the input signal in its law. It labels the result heuristic.

Now step through it yourself. Choose how many cells, how wide a slice, and walk the five steps. The density here is a smooth two-bump shape we made up.

Walk the proof

Top: the input density, cut into cells. Bottom: the chance that the error is at most the slice, against slice width. Press the steps in order, then change the cells and the slice.

4
0.40

The density is a mixture of two bell shapes (centres −0.35 and +0.30, spreads 0.22 and 0.30) cut to the range −1 to +1, and its integrals are computed exactly from the bell-curve formula. It is our own smooth example, not the deck’s. The slice width follows the deck’s convention, measured from the left edge of each cell.

At step 2, the warm slices in every cell are the pieces of probability that sum to the dot on the bottom curve. At step 3, compare the exact slice area in the busiest cell to its rectangle. At step 4, the bars of height f(yk) add up to 1.0003 with 16 cells. At step 5 the exact curve and the straight line are almost the same, and the largest gap is 0.0004, which is 0.04 percent.

Now lower the bits to 2, so there are only 4 cells. The warm slices are wide and the density changes a lot across each. The curve wobbles around the line, and the gap grows to 0.0062, about 0.6 percent. Raise the bits to 6 and the gap falls to 0.0001. This is Bennett’s theorem as a picture: more cells, flatter density within each, a straighter CDF.

Which single approximation in the proof needs the input density to be smooth?

Chapter 10

Field Guide: Quantization Noise on One Page

Keep the numbers, the checks and the code, and use a calculator to pick a bit depth for your own job

The lecture in one paragraph. A uniform quantizer rounds each input to the middle of its cell, so inside its range the error never passes Δ/2. Past the range it saturates and the error grows without limit. If the signal is busy and smooth, the error behaves like uniform, white noise (Bennett’s theorem, proved heuristically by a mean value and Riemann sum argument). Then the noise has mean 0 and power Δ²/12, the SQNR is about 12σ²/Δ², and every extra bit adds 6.02 dB. Audio, images and neural network weights all follow that arithmetic.

The numbers and terms

NameValueWhere it comes from
Largest error in range|ε| ≤ Δ/2Slide 6; Chapter 1
Step sizeΔ = 2A / 2bSlide 12; Chapter 7
Noise mean and power0 and Δ²/12Slide 11; Chapter 6
SQNR10 log10(12σ²/Δ²) dBSlide 12; Chapter 7
Gain per bit20 log10 2 = 6.02 dBSlide 12; Chapter 7
Audio ladder4, 8, 12, 16, 24 bits: 25, 50, 74, 98, 146 dBSlide 13; Chapter 8
Image bit depth8 bits, about 48 dBSlide 15; Chapter 8
Loading offsetSQNR = 6.02 b + 4.77 − 20 log10 K; sine +1.76, bell at K 4 −7.27Our derivation; Chapter 7
Bennett’s four conditionsno overload, many cells, small step, smooth densitySlide 10; Chapter 5

A checklist before you trust Δ²/12

  1. Is anything clipping? The largest error should stay under Δ/2. A bigger one means overload (Chapter 3).
  2. Are there enough cells? Our tests held from about 2 bits for busy signals, but more is safer (Chapter 5).
  3. Is the signal busy? Neighbouring errors should be uncorrelated. A slow drift or a constant fails (Chapter 4).
  4. Is the density smooth? Few distinct values or sharp spikes break the model (Chapter 5).
  5. What is the loading K? The formula’s starting height depends on it (Chapter 7).

The core as code

pythonimport numpy as np

def quantize(x, b, A=1.0):                     # x: float array (N,)  ->  codes int (N,), levels float (N,)
    M, D = 2**b, 2*A / 2**b                     # M cells of width D over [-A, A]
    k = np.clip(np.floor(x / D + M / 2), 0, M - 1).astype(int)   # Ch 1, with the two infinite end cells
    return k, (k - M / 2 + 0.5) * D                  # the code is what you store: b bits

def check(x, b, A=1.0):                         # the five-point checklist in numbers
    k, q = quantize(x, b, A); e = x - q; D = 2*A / 2**b
    return dict(
        sqnr_db  = 10*np.log10(np.mean(x**2) / np.mean(e**2)),    # measured
        theory_db= 10*np.log10(12*np.var(x) / D**2),            # Ch 7: 12 sigma^2 / D^2
        overload = np.max(np.abs(e)) / (D / 2),                # above 1.0 means clipping (Ch 3)
        lag1     = np.mean(e[:-1] * e[1:]) / np.mean(e**2),  # near 0: (A2) plausible (Ch 4)
        flat     = np.histogram(e / D, bins=20, range=(-.5, .5))[0] / len(e))  # near 0.05 each: (A1)

Run check on a tone, on a recorded voice and on a list of weights. If sqnr_db and theory_db agree within a decibel or so, the additive noise model is working. If not, one of the checklist lines will say why.

Now use it the other way round. Name the SQNR your job needs and see how many bits it costs.

How many bits does my job need?

Choose a target SQNR and a loading. Each lit square is one bit. The read-out gives the step, and the raw size of a minute of mono sound.

98 dB

Bits needed = ceil((target − 4.77 + 20 log10 K) / 6.02), from Chapter 7’s formula. The step is over the range −1 to +1. Storage assumes raw, uncompressed samples at 44,100 per second, one channel: an illustration, not a codec.

Where this sits, and where to go

Uniform quantization is the plainest rounding rule. The next lecture on the Lloyd-Max quantizer asks what to do when a uniform staircase wastes levels where the signal rarely goes. The lecture after it, dithering, asks what to do when the error is not noise-like, by adding a little noise on purpose so that the assumptions come true. For the sampling half of digitization, go back to Lecture 2. After that, the DFT shows how to see this noise in the frequency domain.

The takeaway. Rounding is a deterministic act that looks like random noise whenever the signal is busy, wide and smooth. In that case it has power Δ²/12, and each bit cuts that power by four. The skill is knowing the four conditions well enough to spot the day they fail.

Now press Present or Teach and explain the chain from memory. Cover why the error is bounded in range, why overload breaks it, and what the two assumptions say. Then say when Bennett’s theorem makes them true, where Δ²/12 comes from, and why a bit is worth 6.02 dB. Then go back to the instrument at the top, pick the loud-then-quiet signal and explain why its quiet part sounds worse at the same bit depth.

Credit: this lesson re-teaches Lecture 3 of EE269, Signal Processing and Quantization for Machine Learning, taught by Mert Pilanci at Stanford University. The staircase figure on slide 3 is credited there to B. Gray. See the course site and the slides. All devices, toy signals and worked numbers on this page are ours, and the slide images are not reproduced.

EE269 Lecture 3: Quantization Noise
The course site · Course slides · Back to Lecture 2 · On to Lecture 4
Course by Mert Pilanci, Stanford University. Re-taught in our own words and devices; the slides are linked, never copied.