Definition (quantizer). A quantizer is a function Q:R→Aq={Q0,…,QL−1} that associates with each sample a(mTs) a levelaq(mTs)=Q(a(mTs)). The real line is divided into L disjoint regions separated by L−1thresholds; a sample in region i becomes Qi. One takes L=2b with b bits per sample.
Example. The thresholds {−1,0,1} divide R into four regions; with levels {−1.5,−0.5,0.5,1.5} the sample 0.3 becomes 0.5 and the sample −4 becomes −1.5 (L=4, b=2 bits).
Uniform quantizer (PCM) and mid-riser
In PCM (pulse code modulation) all steps are equal. To design it:
choose a dynamic range[−Vsat,Vsat] (saturation voltage Vsat);
fix the number of levels L=2b;
the quantization step is
Δ=L2Vsat=2b2Vsat,Vsat=2b−1Δ;
divide R into L disjoint regions: the L−2 central regions have width Δ and the two outer ones extend to infinity; each is associated with a level Qi (usually the centre point of the region).
Mid-riser. It has a threshold at the origin: 0 is not a level. The levels are
Qi=±2Δ,±23Δ,…,±2(L−1)Δ,
and the thresholds are kΔ with k=−2L+1,…,2L−1 (i.e. 0,±Δ,±2Δ,…). The mid-tread quantizer instead has the level 0: its levels are 0,±Δ,…. The mid-riser is used here. Beyond the extreme thresholds the quantizer saturates: it always returns ±(Vsat−2Δ).
Example.L=8 (b=3) and Vsat=4 V: Δ=1 V; levels ±0.5,±1.5,±2.5,±3.5 V; thresholds −3,−2,−1,0,1,2,3 V. The input 1.2 V falls between the thresholds 1 and 2 and becomes 1.5 V (error +0.3); the input −5 V is beyond −Vsat and saturates at the lowest level −3.5 V (error +1.5). The level 0 is never produced.
2. The quantization error
The quantization error is
eq(mTs)=aq(mTs)−a(mTs)⟺aq=a+eq,
so the output is the signal plus an additive "noise", as if the error were due to the channel. As a function of a the error has a sawtooth shape: inside the dynamic rangeinterval of values the quantizer represents without saturating its amplitude is at most 2Δ (granular error); outside the range it grows linearly with the distance from Vsat (saturation error).
The statistical power of the error, with the sample density pa, is the sum of three integrals over the three zones of the real axis:
It is a heavy calculation, simplified with two assumptions.
(A) The saturation probability Psat is small. The saturation error is neglected. The saturation probability is the probability that the sample leaves the range:
Psat=P[∣a∣>Vsat]=∫∣u∣>Vsatpa(u)du.
signal density
Psat
zero-mean Gaussian, variance σ2
2Q(σVsat)
uniform in [−A,A]
0 if Vsat≥A
Laplacian with parameter bL, p(u)=2bL1e−∣u∣/bL
e−Vsat/bL
exponential λe−λu (u≥0, range [0,Vsat])
e−λVsat
(Q is the Gaussian tail function, Q(y)=2π1∫y∞e−x2/2dx; for the Gaussian the factor 2 counts the two tails.) For a Gaussian signal Vsat=3σ gives Psat=2.7⋅10−3, 4σ gives 6.3⋅10−5, 5σ gives 5.7⋅10−7.
(B) L is large (Δ small compared with how the density varies). Inside each interval the density pa is almost constant, so the granular error is uniform in [−2Δ,2Δ]: pe(e)=Δ1rect(Δe). Hence
(The integral of e2 is 3e3, which between −2Δ and 2Δ gives 12Δ3, divided by Δ.) The error is also assumed uncorrelated with the signal and with itself at different instants: the quantization noise is then white (flat spectrum). These are assumptions, not theorems: they work well for large L. The rms error is 12Δ, not 2Δ (the maximum error): with Δ=1 V, Me=121=0.0833 V2 and the rms error is 0.289 V.
Compromise in choosing Vsat and L.
To minimise Psat take Vsat large.
But at fixed L, Δ=L2Vsat grows with Vsat and the granular error 12Δ2 increases: L must be large, i.e. more bits.
If L is huge and Δ tiny, the granular error becomes so small that the saturation error is no longer negligible: assumption (A) fails and the saturation term must be included.
Definition.Λq=E[eq(mTs)2]E[a(mTs)2]=MeMa,[Λq]dB=10log10Λq.
For a zero-mean signal Ma=σa2 (variance); in general Ma=σa2+ma2 (statistical power). The higher it is, the more faithful the quantized signal.
Example. A signal with σa2=2 V2 and noise Me=0.002 V2: Λq=1000, i.e. 30 dB.
With (A) and (B), Me=12Δ2 with Δ2=4b4Vsat2:
Λq=Δ2/12σa2=4Vsat212σa24b=3Vsat2σa24b.
In decibels (10log103=4.77, 10log104=6.02):
[Λq]dB=6.02b+4.77+20log10Vsatσa.
The ratio σaVsat is the load factor of the quantizer. The formula gathers in one line four design parameters: SNR, b, σa and Vsat. Consequences:
every extra bit (doubling of the levels, halved Δ, error power divided by 4) improves the SNR by 6.02 dB;
widening the range worsens it: if Vsat=kσ, the term 20log10Vsatσ=−20log10k is −9.5 dB for k=3, −12 dB for k=4 and −14 dB for k=5.
For a uniform signal at full scale (Ma=3Vsat2) the SNR is Λq=4b, i.e. 6.02b dB; for a full-scale sinusoid 6.02b+1.76 dB (with b=16 about 98 dB). Values computed for a Gaussian signal (Vsat=kσ):
k=σVsat
Psat=2Q(k)
b=4
b=8
b=12
b=16
3
2.7⋅10−3
19.3 dB
43.4
67.5
91.5
3.72
2⋅10−4
17.4
41.5
65.6
89.7
4
6.3⋅10−5
16.8
40.9
65.0
89.0
5
5.7⋅10−7
14.9
39.0
63.0
87.1
For example b=8, k=4: 6.02⋅8+4.77−12.04=40.89 dB.
4. Designing a quantizer
Typical data: the signal density (Gaussian, Laplacian, exponential) with its parameter, a maximum saturation probabilityprobability that the sample leaves the dynamic range and/or a minimum SNR.
exponential (positive signal): use the range [0,Vsat] with Psat=e−λVsat⇒Vsat=λ1lnPsat1 and step Δ=LVsat (it makes no sense to waste half the levels on negative values);
bounded signal ∣a∣≤A: Vsat=A and Psat=0.
Bits from the required SNR, solving the formula for b: b≥6.02ΛdB−4.77−20log10Vsatσ, rounded up to the next integer (with fewer bits the SNR would be below the threshold). The actual SNR with integer b is a little higher than required.
Example 1 (Gaussian). Zero-mean Gaussian signal with σ2=2 mV2, mid-riser quantizer with b=3 bits and Psat=2⋅10−4.
Vsat=σQ−1(10−4)=2⋅3.719=5.26 mV.
L=8: Δ=82⋅5.26=1.315 mV.
Λq=Δ2/12σ2=1.7292⋅12=13.88≈11.42 dB.
Example 2 (Gaussian, SNR given).σ=0.5 V, Psat≤10−4, SNR ≥40 dB. Q−1(5⋅10−5)=3.891, Vsat=1.945 V. 20log100.51.945=11.80 dB, b≥6.0240−4.77+11.80=7.81⇒b=8. L=256, Δ=2562⋅1.945=0.0152 V, Λq=6.02⋅8+4.77−11.80=41.13 dB. With b=7 it would be 35.1 dB, insufficient.
Example 3 (Laplacian, SNR given).bL=1 V (σ2=2bL2=2 V2), Psat=2⋅10−4, SNR ≥60 dB. Vsat=ln5000=8.52 V; 20log108.521.414=−15.6 dB; b≥6.0260−4.77+15.6=11.76⇒b=12, L=4096, Δ=4.16 mV, Λq=61.4 dB. With 11 bits the SNR would be 55.4 dB (insufficient).
Signals with non-zero mean. What counts is the statistical powerMa=σ2+ma2, not the variance. For the exponential Exp(λ): Ma=λ22. With range [0,Vsat] and L levels Λq=Δ2/12Ma with Δ=LVsat. Alternatively the mean c is subtracted before quantizing (and added back at the receiver): the power to cover is then σa2≪Ma.
When the simplification is not enough. Assumption (A) holds only if Psat is small compared with the granular error. As b grows, Δ2/12 falls by a factor 4 per bit, while the saturation error power Msat stays the same (it depends only on Vsat and the density). Sooner or later it dominates and the SNR stops growing: the 6 dB per bit rule fails. Then Me≃(1−Psat)12Δ2+PsatMsat.
Numerical example (zero-mean Gaussian with σ2=0.01 V2, range [−0.4,0.4] V, Psat=2Q(4)=6.3⋅10−5, numerical integration):
L
Δ
Mgr=12Δ2
Msat
Λq granular only
Λq total
8
0.1 V
8.3⋅10−4
3.6⋅10−7
10.79 dB
10.79 dB
800
0.001 V
8.3⋅10−8
6.3⋅10−8
50.79 dB
48.34 dB
With L=8 saturation does not matter; with L=800 it is almost on a par with the granular error and removes 2.5 dB.
5. Non-uniform quantizers
If the density is not uniform (for instance speech, with many values near zero) it is better to be more precise where the samples fall more often. The typical way is the compander: a compressor block deforms the scale, a uniform quantizer works on the compressed signal and an expander restores the original scale. The optimal steps for a given density can also be chosen.
6. Analog signals sent in digital form: channel errors
An analog signal sent with the chain A/D, coding, channel, decoding, D/A is affected by two independent sources of error: quantization (deterministic, depending on b and Vsat) and bit errors of the digital channel (probability Pbit per bit): a wrong bit causes a wrong level to be decoded, with a possibly large error. The performance is the ratio between signal power and the sum of the two error powers, ΛPCM=Mq+McMa (the powers of the uncorrelated errors add; the SNRs in dB are not added).
The most significant bit (i=b−1) accounts for almost 43 of the error: errors on the high bits are the most harmful. With Mq=12Δ2 and Λq=Δ2/12Ma:
ΛPCM=1+4Pbit(4b−1)Λq(linear scale).
Convert Λq from dB to linear before using it, and convert the result back. For a uniform full-scale signal Λq=4b. From the required SNR Λ, the maximum tolerable error probability is
Pbit≤4Λ(4b−1)Λq−Λ(Λ≤Λq).
Threshold. If Pbit≪4⋅4b1, ΛPCM≈Λq: every extra bit gives 6.02 dB. If Pbit≫4⋅4b1, ΛPCM≈4Pbit1does not depend on b: adding bits no longer improves, and at most ΛPCM→4Pbit1 (24 dB for Pbit=10−3).
Example (uniform signal, b=8 bits, Λq=48=48.2 dB):
Pbit
ΛPCM
0
48.2 dB
10−4
33.8 dB
10−3
24.0 dB
10−2
14.0 dB
Sizing example (cinema hall signals). Video with SNR of at least 50 dB (b=9, Λq=54.2 dB): Pbit≤4⋅105(49−1)49−105=1.55⋅10−6. Audio with 92 dB (b=16, Λq=96.3 dB): Pbit≤9.95⋅10−11: audio is the tighter constraint, since it has more bits and a higher SNR.
Typical mistakes
Δ=LVsat with a symmetric range: the 2 is missing. (For [0,Vsat] it is LVsat.)
Writing the mid-riser with level 0: the levels are at ±2Δ,±23Δ,….
One tail only for a symmetric signal: Psat=2Q(σVsat), so Q−1(2Psat).
Not rounding bup and not giving the effective SNR.
Using the variance instead of the statistical power for signals with non-zero mean.
Believing the SNR grows 6 dB per bit always: only while saturation is negligible.
Applying 12Δ2 with small L or large Psat without checking the assumptions.
Adding SNRs in dB instead of error powers; forgetting the factor 4b−1; using Λq in dB inside the linear formula.
Versione ripasso
Uniform mid-riser quantizer.Q:R→{Q0,…,QL−1}, L=2b. Range [−Vsat,Vsat], step Δ=L2Vsat, Vsat=2b−1Δ. Thresholds kΔ; levels ±2Δ,±23Δ,…,±2(L−1)Δ; no level 0 (mid-tread has it). Saturation returns ±(Vsat−2Δ). Example: L=8, Vsat=4 V: Δ=1 V; 1.2 V →1.5 V; −5 V →−3.5 V.
Error.eq=aq−a, so aq=a+eq: sawtooth; granular ∣eq∣≤2Δ inside the range, saturation error outside. Power: sum of two saturation integrals and a granular one.
(A) Psat=P[∣a∣>Vsat] small: Gaussian 2Q(σVsat); uniform 0 if Vsat≥A; Laplacian e−Vsat/bL; exponential e−λVsat (range from 0).
(B) L large: e uniform in [−2Δ,2Δ], me=0, Me=12Δ2 (rms 12Δ), white noise.
Trade-off: large Vsat lowers Psat but raises Δ; with huge L saturation matters again.
SNR.Λq=MeMa, Ma=σ2+ma2. With (A), (B): Λq=3Vsat2σa24b and
[Λq]dB=6.02b+4.77+20log10Vsatσa.
Each bit +6.02 dB; Vsat=kσ costs 20log10k (9.5 dB at k=3, 12 at 4, 14 at 5). Uniform full scale: 4b; sinusoid: 6.02b+1.76. Example: Gaussian Vsat=4σ, b=8: 40.89 dB.
Design. (1) Vsat: Gaussian σQ−1(2Psat); Laplacian bLlnPsat1; exponential on [0,Vsat]: λ1lnPsat1; bounded: A. (2) b≥6.02ΛdB−4.77−20log10(σ/Vsat) rounded up. (3) L=2b, Δ=L2Vsat, actual SNR, rate Fsb.
PCM with channel errors. Error powers add: ΛPCM=Mq+McMa. Natural binary code, bit i weighs 2iΔ: Mc=PbitΔ234b−1; high bits are the most harmful.
Threshold: Pbit≪4⋅4b1 gives 6.02 dB per bit; beyond it ΛPCM≈4Pbit1, independent of b. b=8 uniform: 48.2, 33.8 (10−4), 24.0 (10−3), 14.0 dB (10−2). Cinema: video b=9, 50 dB: Pbit≤1.55⋅10−6; audio b=16, 92 dB: Pbit≤9.95⋅10−11, the tighter.
Typical mistakes:Δ=LVsat with a symmetric range; level 0 in the mid-riser; one Gaussian tail only; rounding b down; variance instead of power; 6 dB per bit even with saturation; SNRs in dB added; Λq in dB inside the linear formula.