A capture is quantized, gain-adjusted, then quantized again at the same bit depth; when does the second pass add error?
answer
- ask about the grid, not the values
- same grid twice is free
- a gain change shifts the grid
- half a step per misaligned pass
- the coarsest pass sets the floor
basics
~20 sRe-rounding values that already sit on the same grid changes nothing. Any gain change, resample or range change moves the grid under them, so each such pass can add another half step, and the coarsest stage in the chain dominates the total.
solid answer
~50 sQuantizing onto a grid is idempotent: the output already sits on a level, so rounding it again onto the same grid is a no-op and costs nothing. Error compounds only when something moves the values off that grid between passes - a gain change, a resample, a filter, a different range or a different step. Then each pass adds up to another half step of fresh error, and the worst case over `n` misaligned passes is the sum of the half-steps rather than one of them. Because the per-pass errors are close to independent, the RMS floor grows like the square root of `n` rather than linearly. Two asymmetries matter: the coarsest pass dominates the result, and no later pass at a deeper bit depth recovers what an earlier coarse one discarded. So plan the chain to round once, late, over wide intermediates.
code
pseudocode · 10 linesfunction q(x, step, offset):
return offset + round((x - offset) / step) * step
y = q(x, step, 0) # |y - x| <= step/2
y2 = q(y, step, 0) # y2 == y : y is already a grid point
z = q(y, step, step/2) # same step, grid shifted half a step
# |z - y| == step/2 exactly
# so |z - x| can reach a full stepgo deeper
Remember that a value already sitting on the grid survives another rounding untouched, and that what usually breaks this is a gain change or a resample between the two passes.
Explain the arithmetic: a shifted or rescaled grid puts each value back between levels, so a second round-to-nearest can cost another half step on top of the first.
Design the chain so rounding happens once and late - wide intermediates for gain, mixing and filtering, and aligned grids wherever an already-quantized result must be handed on.
Decide where the irreversible step lives in an organisation's pipeline, what archival depth sits behind it, and who may introduce a stage that re-rounds someone else's output.
## Rounding onto a grid is idempotent Start with the case people get wrong in both directions. Let `q(x)` round `x` to the nearest point of a uniform grid with step `d`. Then `q(q(x)) = q(x)`: the first call already landed on a grid point, and the nearest grid point to a grid point is itself. Re-encoding values onto **the grid they already occupy costs nothing at all** - not a little, not a half step, nothing. This matters because the folklore says the opposite: that every re-save degrades the data further. That is true of pipelines with a transform or a prediction stage between the roundings, and false of a bare re-quantization onto an identical grid. Knowing which situation you are in is the whole question. ## What moves the grid Error compounds when something displaces the values relative to the grid between passes. The usual culprits: - **a gain change** - multiplying every sample by a factor lands them between levels again; - **a resample or a filter** - new sample values are interpolations, which are almost never grid points; - **a different range** - the same depth over a different span is a different step; - **a different depth** - a coarser grid is not a subset of the fine one unless the step is an exact power-of-two multiple and the grids are aligned; - **an offset** - a DC shift or a re-centring moves every value off the lattice by the same amount. Each surviving pass then adds up to `d/2` of genuinely new error. ## How the error actually accumulates Two different growth laws get conflated, and an interviewer will notice: | Quantity | Over n misaligned passes | Why | |---|---|---| | Worst case on one sample | up to the sum of the half-steps | each pass may push the same direction | | RMS across many samples | grows like the square root of n | near-independent errors add in power | | Same grid, no displacement | zero extra | each pass is a no-op | The square-root law is the one that describes what you measure: per-pass errors behave like independent zero-mean noise across a long signal, and independent noise adds in power, not in amplitude. The linear worst case still bounds any single sample. ## The coarsest pass dominates, and nothing undoes it Suppose a chain rounds to a coarse step `d1`, then later to a fine step `d2` with `d2` much smaller. The final value is within `d2/2` of the coarse value, which is itself within `d1/2` of the original. The total is bounded by the sum, and it is dominated by `d1/2`. Reverse the order and the same conclusion holds: whichever stage is coarsest sets the floor. The second asymmetry follows from what quantization actually threw away: 1. The coarse pass replaced each value with a level and **stored nothing about the discarded remainder**. 2. A finer grid can represent those coarse values exactly - it usually contains them as a subset. 3. It has nothing to represent the lost detail with, because that information no longer exists in the data. So re-encoding a shallow capture at greater depth produces a larger file carrying the same information. That is not a subtle point, and candidates who miss it usually also believe that an archive can be upgraded after the fact. ## Designing the chain The practical rules fall straight out of the mechanism: - **Round once, late.** Carry intermediates in a representation wider than the delivery format, and do gain, mixing and filtering there. - **Align grids where a handoff is unavoidable.** Same range, same step means the receiving stage's rounding is a no-op. - **Keep the widest thing you can afford as the archival copy**, because every stage downstream of an irreversible rounding inherits its floor. - **Name the coarsest stage explicitly** in any design review; it is the one that decides the quality of everything after it. ## What the interviewer is testing They want to hear you refuse the folklore in both directions: no, repeated encoding is not automatically destructive, and yes, it becomes destructive the moment anything shifts the grid - which in a real chain is almost every stage. The candidate who can say which of the two situations a given pipeline is in, and point at the stage that sets the floor, has answered the question.
- Why does re-quantizing at a deeper bit depth not undo an earlier coarse pass?Because the coarse pass replaced each value with a level and stored nothing about the remainder it discarded. A finer grid can hold those coarse values exactly, and usually contains them as a subset, but it has nothing to reconstruct the lost detail from. The result is a larger representation carrying exactly the information the coarse pass left behind.
- If each pass adds at most half a step, why is the growth described as a square root?Half a step is the worst case for a single sample, and across many samples the per-pass errors behave like independent zero-mean noise. Independent noise adds in power rather than in amplitude, so the RMS floor over n misaligned passes grows like the square root of n, while the absolute worst case on one sample still grows linearly.
- How do you keep a multi-stage chain from re-quantizing needlessly?Carry intermediates wider than the delivery format and do the gain, mixing and filtering there, then quantize once at the end. Where a stage must hand off an already-quantized result, keep its grid aligned with the next stage's - same range, same step - so the receiving rounding is a no-op rather than another half step.
saying these in an interview costs you the question
- Claims re-rounding onto the identical grid still degrades the values
- Assumes a later deeper pass restores detail a coarse pass dropped
- Thinks a gain change is harmless because the depth did not change
- Treats the worst case over n passes and the RMS growth as one number
- Believes the finest stage in the chain sets the final error floor
- Rounds to the delivery grid before mixing and gain staging