Skip to content

Quantization & noise

Round a signal to B bits, watch the error stay within half a step, and see why each bit adds about 6 dB of SNR.

Before this8.4 · 10.1 · 10.3 · 2 more
Chapter 11 · Lesson 1 of 3

First, the picture

Here a slow ramp from −1-1 to 11 goes through a converter that may keep only 8 values, and each sample is rounded to the nearest one. Watch the error, the gap between output and input, as the ramp climbs.

The rounding error of a slow ramp

3 bits: 8 levels, Δ = 0.25 apart.

A slow ramp from −1 to 1 goes into a 3-bit quantizer: 8 levels, Δ = 0.25 apart.

input
−1.000
output
−0.875
mean square of error ÷ Δ²
0.250
0.00 / 10.00 s
Describe this picture

A 3-bit quantizer: 8 levels, Δ=0.25\Delta = 0.25 apart. The picture has no control; the ramp draws over 8 seconds, and the picture then holds. The upper panel shows the ramp as a thin line, “input x”, and the thick staircase “output x_q”. The lower panel shows the sawtooth “e = x_q − x” between dashed lines “±Δ/2” at ±0.125\pm0.125. Two readouts, “input” and “output”, follow the newest point on the ramp, and a third, “mean square of error ÷ Δ²”, keeps a running mean square of the error and settles at 0.083.

Rounding to the nearest level

Kinds of signals (1.2) described a digital signal as a ruler with only so many marks: every value has to be one of a fixed list of levels. Chapter 10 chose when we look at a signal. This page chooses which values we may keep.

A converter with BB bits can store 2B2^B different levels. I take the signal’s range to be −1-1 to 11 and spread the levels evenly across it. The gap between neighbouring levels is the step, written Δ\Delta:

Δ=22B\Delta = \frac{2}{2^B}

The quantizer, written Q{⋅}Q\{\cdot\}, replaces each sample with the nearest level, so the stored signal is xq[n]=Q{x[n]}x_q[n]=Q\{x[n]\}. What it gets wrong is the error e[n]=xq[n]−x[n]e[n]=x_q[n]-x[n].

Here the levels sit at ±Δ/2\pm\Delta/2, ±3Δ/2\pm3\Delta/2, and so on, with no level at 0. This placement is called mid-rise. With B=3B=3 there are 8 levels, Δ=0.25\Delta=0.25, and the levels are ±0.125\pm0.125, ±0.375\pm0.375, ±0.625\pm0.625 and ±0.875\pm0.875.

Do not read this as “more bits make a drawn curve smoother”. The staircase in Reconstruction (10.3) was a different one: it held each value for a whole sample period, so it changed the time. This staircase changes the value. More bits do not mainly smooth a curve; they make the error quieter.

The error of a slow ramp

The picture at the top of the page put the simplest input, a slow ramp from −1-1 to 11, through a 3-bit quantizer.

Look at the sawtooth. Each level covers one stretch of the ramp. Inside that stretch the output stays put while the input climbs past it, so the error runs from +Δ/2+\Delta/2 down to −Δ/2-\Delta/2. The same tooth then repeats on every step, and the error never leaves the dashed lines.

That is a general fact about rounding: the nearest level is never more than half a step away. Prices rounded to the nearest 5 cents are never more than 2.5 cents off, whatever the price.

The readout “mean square of error ÷ Δ²” keeps a running mean square of the error over the stretch drawn so far. Watch it settle at 0.083.

To see where 0.083 comes from, write the error as a fraction of a step, u=e/Δu=e/\Delta. On the ramp, uu spreads evenly from −12-\tfrac12 to 12\tfrac12 along each tooth. How big is a signal (1.3) found the average of u2u^2 over 0 to 1 to be 13\tfrac13. The same recipe over −12-\tfrac12 to 12\tfrac12 gives:

u2‾=∫−1/21/2u2 du=13(18+18)=112\begin{aligned} \overline{u^2} &= \int_{-1/2}^{1/2} u^2\,du \\ &= \frac13\left(\frac18+\frac18\right) = \frac1{12} \end{aligned}

The mean square of the error is therefore Δ2/12\Delta^2/12, which is 0.083 Δ20.083\,\Delta^2 to three decimals. Its square root, Δ/12\Delta/\sqrt{12}, is the RMS error.

A busy signal: same values, scrambled

A ramp is too tidy to be a real signal. Now try one that is busy: two tones for 20 ms, into the same 3-bit quantizer. The signal is 0.6sin⁡(2π⋅997t)+0.35sin⁡(2π⋅2311t+1.0)0.6\sin(2\pi\cdot997t)+0.35\sin(2\pi\cdot2311t+1.0), sampled at 48 kHz, so 960 samples. Watch the error, and its mean square.

The rounding error of a busy signal

Two tones, 20 ms, into the same 3-bit quantizer.

A busy signal, two tones for 20 ms, into the same 3-bit quantizer.

mean square of error ÷ Δ²
nothing drawn yet
0.00 / 10.00 s
Describe this picture

The same two panels as the ramp, against time from 0 to 20 ms: the two-tone signal and its 3-bit output above, the error between the dashed lines at ±Δ/2\pm\Delta/2 below. There is one readout, “mean square of error ÷ Δ²”, which reads “nothing drawn yet” until the first sample is drawn, then 0.082 at 10 ms and 0.083 at 20 ms.

The error no longer traces teeth. It jumps about, because the signal keeps landing at different places inside different steps. It still stays inside ±Δ/2\pm\Delta/2, and it still takes the same range of values, only in a scrambled order. So its mean square comes out close to Δ2/12\Delta^2/12 again: the readout reads 0.082 at 10 ms and 0.083 at 20 ms.

This is the noise model. It treats the error as a steady hiss of mean square Δ2/12\Delta^2/12 added to the signal, xq[n]=x[n]+e[n]x_q[n]=x[n]+e[n]. The model is an approximation. It works when there are many levels and the signal is busy, and the last two sections show where it fails.

Where the levels sit

Rounding to the nearest level is one choice. Two others show up in practice.

xx_qmid-riseno level at 0xx_qmid-treadlevel at 0xx_qtruncationalways rounds down
Fig. Three ways to place the steps. Rounding keeps the error centred on 0; truncation shifts it by half a step.

In the figure, each plot has input along the horizontal axis and quantized output up the vertical axis, and the dashed diagonal is a perfect, unquantized output.

Mid-tread puts a level at 0, so the levels are 00, ±Δ\pm\Delta, ±2Δ\pm2\Delta and so on. A quiet input then comes out as exactly 0. This is the version that matters for the last section. Truncation always rounds down, so the error runs from 0 to −Δ-\Delta instead of from −Δ/2-\Delta/2 to Δ/2\Delta/2. Over that range, u=e/Δu=e/\Delta is spread evenly from −1-1 to 00: its mean is −12-\tfrac12 and its mean square is ∫−10u2 du=13\int_{-1}^{0}u^2\,du=\tfrac13. So the error has mean −Δ/2-\Delta/2 and mean square Δ2/3\Delta^2/3, which is four times the mean square of rounding.

Each bit is worth 6 dB

Now the quantity this whole page has been heading for: the signal-to-noise ratio. How big is a signal (1.3) defined it as the ratio, in dB, of signal power to noise power. I use the loudest sine that fits, a full-scale sine of amplitude 1.

Its RMS is 1/21/\sqrt2, so its mean square is (1/2)2=12(1/\sqrt2)^2=\tfrac12. By the noise model, the noise has mean square Δ2/12\Delta^2/12. Put in Δ=2/2B\Delta=2/2^B:

Δ212=(2/2B)212=13⋅4BPsignalPnoise=1/21/(3⋅4B)=1.5⋅4B\begin{aligned} \frac{\Delta^2}{12} &= \frac{(2/2^B)^2}{12} = \frac{1}{3\cdot4^B} \\ \frac{P_\text{signal}}{P_\text{noise}} &= \frac{1/2}{1/(3\cdot4^B)} = 1.5\cdot4^B \end{aligned}

The ratio is of powers, so SNR in dB uses 10log⁡1010\log_{10}. The log of a product is a sum of logs, as in Frequency response and Bode plots (8.4), and log⁡104B=Blog⁡104\log_{10}4^B=B\log_{10}4:

SNRdB=10log⁡10 ⁣(1.5⋅4B)=10log⁡101.5+B⋅10log⁡104=1.76+6.02 B\begin{aligned} \mathrm{SNR}_\text{dB} &= 10\log_{10}\!\left(1.5\cdot4^B\right) \\ &= 10\log_{10}1.5 + B\cdot10\log_{10}4 \\ &= 1.76 + 6.02\,B \end{aligned}

Each extra bit multiplies the number of levels by 2, halves the step, and so cuts the noise power by 4. A factor of 4 in power is 10log⁡104=6.0210\log_{10}4=6.02 dB. That is the rule of thumb: about 6 dB per bit.

The formula rests on the noise model, so I measured it. The instrument below quantizes a full-scale 997 Hz sine, 1 second at 48 kHz, to BB bits for B=1B=1 to 16, and compares the measured SNR with the formula. Watch the measured dots against the formula’s line as BB grows.

Measured SNR against 6.02B + 1.76

A full-scale 997 Hz sine, 1 s at 48 kHz, through a B-bit mid-rise quantizer.

One bit, two levels: 6.44 dB measured, 7.78 dB from the formula. With so few levels the error is not a steady hiss.

bits B
1
measured SNR
6.44 dB
6.02B + 1.76
7.78 dB
formula − measured
1.34 dB
0.00 / 12.00 s
Describe this picture

SNR in dB, from 0 to 100, against bits BB from 1 to 16. A dashed line is labelled “6.02B + 1.76” and filled dots “measured”. The clip steps BB upward from 1 and adds one dot per step, and the caption names each value, for example “Four bits: 25.31 dB measured, 25.84 dB from the formula.” The readouts are “bits B”, “measured SNR”, “6.02B + 1.76” and “formula − measured”, the last three in dB to two decimals. Once it has played, BB can be set from 1 to 16 by dragging the ringed dot or with the arrow keys.

Look at the last readout, “formula − measured”. At B=1B=1 it reads 1.34: the formula says 7.78 dB, the measurement is 6.44 dB. At B=8B=8 it reads 0.13, and at B=16B=16 it reads 0.00, with both values at 98.08 dB.

From 8 bits upward the formula and the measurement agree within 0.13 dB. At 1 to 4 bits the formula is between 0.53 and 1.34 dB too optimistic. With only a few levels, the error is no longer a steady hiss: it follows the shape of the signal instead of scrambling it.

The same rule gives the dynamic range of a converter, the span from its noise to the loudest signal it can hold, in dB. A 12-bit converter gets 6.02⋅12+1.76=74.006.02\cdot12+1.76=74.00 dB, and 16-bit audio gets 98.08 dB. At 24 bits the rounded formula gives 146.24 dB, and unrounded constants give 146.26 dB.

A quiet sine

The noise model also fails in the other direction, when the signal is quiet and simple. Take a sine whose peak is only 1.4 steps, quantized with mid-tread levels, with 32 samples in each period.

dashed curve = inputsquares on stems = output10−1value (steps)03264sample n
Fig. A quiet sine, only 1.4 steps tall. The error repeats with the signal, so it is not hiss but extra harmonics: the third has 0.273 of a step against the fundamental’s 1.220. 11.2 fixes this.

The output takes only the values −1-1, 00 and 11 steps, and it is the same staircase in every period. So the error repeats with the signal: it is a copy of the same pattern, period after period. A wave that repeats is a sum of harmonics, sines at whole-number multiples of the fundamental frequency, as in Signals as sums of sinusoids (7.1). The rounded sine therefore holds the original fundamental plus extra harmonics that were never in the input.

The third harmonic has amplitude 0.273 of a step against the fundamental’s 1.220. That is distortion: tones in the output that follow the signal, not hiss spread across all frequencies. Dither (11.2) fixes this.

Worked example

A 12-bit converter on 0 to 3.3 V. The range is 3.3 V wide, so the step is Δ=3.3/212=3.3/4096=0.806\Delta=3.3/2^{12}=3.3/4096=0.806 mV. (On ±1\pm1 the range is 2 wide, which gives Δ=2/2B\Delta=2/2^B.) The RMS error is Δ/12=0.806/3.464=0.233\Delta/\sqrt{12}=0.806/3.464=0.233 mV.

Quiet music. Take a 16-bit recording of a sine 20 dB below full scale. The noise stays where it was, so the signal loses 20 dB against it, and the SNR is 98.08−20=78.0898.08-20=78.08 dB. Each dB of level you give up costs a dB of SNR.

Rounding against truncation. For the same step Δ\Delta, rounding gives an error with mean 0 and mean square Δ2/12\Delta^2/12. Truncation gives mean −Δ/2-\Delta/2 and mean square Δ2/3\Delta^2/3, which is 4×4\times as much.

Where you’ll meet this

Audio CDs store 16 bits per sample, a dynamic range of about 98 dB, and studios record at 24 bits to leave room to adjust levels. A microcontroller’s built-in converter is usually 10 or 12 bits, so its step sets the smallest voltage change it can see. A photo saved with too few shades shows bands in smooth skies, the same rounding on brightness. Oversampling and noise shaping (11.3) shows how to push the noise out of the band you care about.

The maths behind it · variance of a uniform value

A value spread evenly over a range of width Δ\Delta has mean square Δ2/12\Delta^2/12 about its middle. Statistics calls that number the variance of the uniform distribution. The noise model treats e[n]e[n] as such a value, fresh at every sample.

The maths behind it · rounding a vector to a grid

Rounding every entry of a vector to a grid moves it to the nearest grid point. The error vector stays inside a small cube around the original, half a step in every direction.

Reference card

QuantityFormulaNotes
Levels, step2B2^B levels, Δ=2/2B\Delta=2/2^B on ±1\pm1BB = bits
Errore[n]=xq[n]−x[n]e[n]=x_q[n]-x[n], ∣e∣≤Δ/2\lvert e\rvert\le\Delta/2rounding
Mean square of the errorΔ2/12\Delta^2/12many levels, busy signal
SNR, full-scale sineSNRdB=6.02B+1.76\mathrm{SNR}_\text{dB}=6.02B+1.76a full-scale sine reads −3.01-3.01 dBFS by RMS on this site
Per bit+6.02+6.02 dB
Truncationmean −Δ/2-\Delta/2, mean square Δ2/3\Delta^2/3
Model failsfew levels, quiet or repeating signalserror becomes harmonics (11.2)

End of lesson 11.1

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look