skip to content

When a recorded signal spends most of its time near zero, why can equal-sized quantization steps waste most of the available levels?

level: seniorimportance: should knowfreq 34%

answer

  1. levels should follow the probability
  2. uniform spends range, not mass
  3. quiet passages get few levels
  4. steps growing with magnitude
  5. constant relative error, not absolute

basics

~20 s

Uniform steps allocate levels in proportion to range, not to probability, so most levels sit over amplitudes the signal rarely reaches while the crowded region near zero gets only a few. Steps that grow with magnitude hold relative error roughly constant instead.

solid answer

~50 s

A uniform grid gives every part of the range the same resolution, but a signal whose amplitude is peaked near zero visits the extremes rarely. The levels near full scale go almost unused, while quiet passages - where detail still matters - get only the handful of levels closest to zero, and their ratio of signal to error collapses as the amplitude drops. Non-uniform quantization places levels densely where the probability mass is: logarithmic or companded steps grow with magnitude, which keeps the **relative** error roughly constant across the range instead of the absolute error. An eight-bit logarithmic code can therefore carry a dynamic range that a uniform code needs roughly twelve bits to cover, for signals of that shape. The costs are that the error is no longer level-independent, and every consumer must know the mapping.

go deeper

for a junior

Recall that equal steps are the right default only when the signal uses the whole range fairly evenly; one that hugs zero wants finer steps there and coarser ones out at the extremes.

for a middle

Explain the consequence in ratios: with uniform steps the absolute error is constant, so signal-to-error falls as amplitude falls and the quiet passages get the worst of it.

for a senior

Show where expansion happens in a real chain - which stages may touch companded codes, which must expand first, and how the level table travels with the data to every consumer.

for a principal

Judge whether a non-uniform code earns its interop cost: every consumer must know the mapping, and a uniform code at greater depth is often the cheaper answer when bits are not scarce.

## Levels are a budget, and uniform spending ignores the odds A `b`-bit quantizer has `2^b` levels to spend, and the only real question is where to put them. A uniform grid spends them **in proportion to range**: every volt of the span gets the same number of levels, whether the signal lives there or never goes there. Now take a signal whose amplitude distribution is sharply peaked near zero - quiet most of the time, with occasional loud passages. Uniform spacing produces a specific, measurable waste: - levels in the top part of the range are visited **rarely or never**, so the bits that index them convey almost nothing; - the dense region near zero is covered by **only the few levels nearest the origin**, so quiet detail is crushed into a handful of distinct values; - the absolute error is constant at half a step, so the **ratio** of signal to error falls as the amplitude falls, roughly 6 dB for every halving of level; - the perceived quality therefore tracks the quiet passages, which are exactly the ones the grid serves worst. ## What a non-uniform grid changes Non-uniform quantization keeps the same `2^b` levels and **moves** them. The standard shape is logarithmic companding: compress the amplitude with a logarithm-like curve, quantize the compressed value uniformly, and expand on the way out. In terms of the original amplitude, the steps grow with magnitude. The consequence is a different invariant: | | Uniform steps | Logarithmic steps | |---|---|---| | Constant quantity | absolute error, half a step | error relative to the sample's magnitude | | Best served | large amplitudes | the whole range, evenly, in ratio terms | | Signal-to-error | falls about 6 dB per halving of level | roughly flat across amplitudes | | Good when | amplitudes are spread evenly | amplitudes are peaked near zero | | Interop cost | none, the grid is implicit | every consumer must know the mapping | The headline result is that an eight-bit logarithmic code can cover a dynamic range a uniform code would need around twelve bits for, given a suitably peaked amplitude distribution. Nothing was created: the eight bits still index 256 levels. They are simply placed where the values are. ## Designing the level placement If the amplitude distribution is known, the placement can be derived rather than assumed. The standard iteration alternates two steps until it settles: 1. **Assign** every value in a representative sample to its nearest current level. 2. **Move** each level to the centre of mass of the values that chose it. 3. Repeat until the levels stop moving appreciably. That converges on a placement minimising average squared error for that distribution, and it reproduces the intuition directly: levels crowd where the density is high. It is design-time work, and the resulting level table has to travel with the data, because a decoder cannot infer it from the codes alone. It is also worth stating the converse, because it stops the technique being applied reflexively: **if the amplitude distribution is flat, uniform spacing is already optimal**, and companding makes the result worse. Non-uniformity is a bet on the shape of the distribution, and a wrong bet costs quality. ## What breaks downstream Companded codes are not amplitudes, and arithmetic on them is not arithmetic on the signal: - **adding two codes does not add the underlying values**, so mixing must happen after expansion; - **averaging codes biases the result** toward the compressed end of the curve; - **filters and gain stages** must expand, operate on a uniform representation, and re-compand on the way out - and each re-compand is another rounding; - **measurement and thresholds** computed on raw codes are wrong by a nonlinear factor that varies with level. None of this is exotic, and all of it has been shipped as a bug at least once by everyone who has built such a chain. ## The judgement the question is really about The trade is resolution-where-it-matters against interoperability and arithmetic simplicity. A non-uniform code is worth it when the distribution is stable, well understood, and the bit budget is genuinely tight. When bits are cheap, a uniform code at greater depth gives the same effective quality with none of the mapping to distribute, none of the expansion steps to forget, and an error model every downstream stage already assumes.

  • How would you place the levels if you knew the signal's amplitude distribution?
    Iterate: assign every value in a representative sample to its nearest level, then move each level to the centre of mass of the values that chose it, and repeat until it settles. That converges on a placement minimising average squared error for that distribution, crowding levels where the density is high. It is design-time work, and the resulting table must ship with the decoder.
  • What breaks if a downstream stage treats companded samples as if they were uniform?
    Arithmetic on the codes stops meaning anything: adding two companded codes does not add the underlying amplitudes, and averaging them biases the result toward the compressed end. Anything that mixes, filters, thresholds or measures has to expand the codes to a uniform representation first, work there, and re-compand on the way out.
  • Does non-uniform quantization reduce the number of bits needed?
    Not by itself - the same b bits still index the same number of levels. What changes is where those levels sit, so a fixed budget covers a much wider useful dynamic range for a peaked signal. If the amplitude distribution were flat, uniform spacing would already be optimal and companding would only make the result worse.

saying these in an interview costs you the question

  • Says non-uniform steps add levels rather than move them
  • Assumes uniform spacing is optimal for every signal
  • Thinks constant absolute error means constant perceived quality
  • Mixes or filters companded codes without expanding them first
  • Claims companding is lossless because the curve is invertible
  • Believes a decoder can infer the level table from the codes