# How does companding compress dynamic range?

Regarding when you 'compress' the signal, I typically see diagrams like this:

And the companding curve:

I can only see how the companding curve achieves a higher average SQNR by rounding down higher amplitudes more than lower amplitudes when making the quantization, according to a normal PDF, making the quantisation more efficient. I don't see how it reduces the dynamic range of the signal to the 'compressed dynamic range'. The only dynamic range compression I can see is that when the higher amplitudes are expanded again, they'll be expanded to the figure they were rounded down to during quantisation, reducing the upper dynamic range, but not the lower.

The dynamic range compression appears to be referring to the dynamic range of the signal after the compressor and before the expander, but this doesn't make sense. How can PCM samples have a dynamic range that isn't anything you want it to be.. and as the samples are uniform, surely a high rounded down amplitude now has a higher relative amplitude (sample 255/256 for instance whereas it was originally rounded down much more), and of course a lower amplitude is now a much higher amplitude.

What confused me is that there is a correspondence between 1.0 input amplitude and 1.0 output amplitude, which doesn't compress the dynamic range at all.

I hope that the key word in the output is 'relative' i.e. relative to the output range and it's actually mapping it onto a smaller dynamic range, though it looks like it's the same range. It would make sense to me if the dynamic range compression comes from the dynamic range that the samples are being mapped to is smaller than the input, and the companding curve is just a way to do this more efficiently than linear.

Why is the companding curve even called 'compression', surely the compression part is mapping it to a smaller dynamic range, or when using digital compression, the compression part is the reduction of bits in the PCM sample, and you can compress with linear companding, which wouldn't be considered compression at all if you were defining compression to be non uniform quantisation.

Companding is used when you want a signal to noise ratio (SNR) that's largely independent of the signal level.

Quantization noise is constant, so if the signal level varies, so does the SNR.

Let's consider an audio signal that's quantized at 8 bit. The quantization noise sits at -53dBFS. If you have a loud signal, i.e. -10dBFS you have a healthy 43 dB SNR. However, for a soft signal at -40dBFS, the SNR is very poor at 13 dB.

If you compand you can get an SNR of maybe 30dB for both cases, which is much better. The audibility of the quantization noise is NOT a function of the absolute noise level but the noise level relative to the signal. You can tolerate more noise, if the signal itself is louder since the louder signal masks more of the noise.

Companding implies that there is a decompression operation, whereas compression implies that it is lossy compression and the final product, which is just used to compress in a way that cannot be restored, which can be used for effect in a DAW, or to reduce file size. Though linear companding is lossy, it's still called companding because there's a basic decompression operation back to the original PCM bit depth.

A codec can employ digital companding, and the goal is to reduce the file size / increase the samples that can be sent per second on a transmission line, allowing for better sampling rates for the same amount of data, while preserving the dynamic range of the signal as best as possible.

The dynamic range of an ADC is the ratio of the largest signal to the smallest signal that can be produced, which can be simplified to $$20\log_{10}{(2^N -1)}$$ because the voltage scaling factor is cancelled out $$\frac{V(2^N -1)}{V} = 2^N - 1$$. The maximum signal that can be produced is $$V(2^N - 1)$$ because there are $$2^N$$ quantisation levels and $$2^N$$ quantisation levels make a signal of peak to peak magnitude of $$2^N-1$$. The smallest signal that can be produced is indeed of peak to peak magnitude of V*1. This is illustrated below.

The dynamic range of the red signal $$20\log(7/1)$$ here is the same as measuring the amplitude of the signal $$20\log(3.5/0.5)$$. The ADC could use the floor function across the board, or a rounding function, but in practice, it doesn't matter, because of other error in a practical ADC. If a rounding function were used then the peak to peak magnitude of the minimum recognised signal would only need to be a fraction of 1, i.e. 0.0001, but the minimum output is 1 and therefore the dynamic range of the ADC refers to the output. The quantisation noise floor is therefore a magnitude of 1 (at a high sampling rate) and the dynamic range is the difference between the noise floor and the maximum signal. The SQNR on the other hand is the input signal average power over average quantisation noise power which is RMS voltage squared over noise RMS voltage squared.

When you sample a signal, it introduces quantisation noise into the samples, because the quantisation isn't exact because you've only got a certain bit depth. The maximum quantisation error as sampling rate approaches infinity is therefore V1 (where max quantisation noise amplitude tends to V1), and as the maximum signal is $$V(2^N-1)$$, DNR is therefore the max signal amplitude to max quantisation noise amplitude. Noise already existing in the signal is not considered part of the dynamic range of the ADC. In a real ADC, thermal noise etc. is also introduced

If you had a 12 bit depth you could have a codec that just compresses it linearly to 8 bit samples by truncating the last 3 bits of the 12 bit samples, i.e. rounding down to a multiple of 8. This increases the quantisation noise in the samples because when you expand the samples to 12 bits again by adding 3 0s to the end, the samples now are more inaccurate and have higher granularity. Linear companding is therefore lossy, and you get identical to what you would have got if you just sampled with 8 bit samples in the first place, and therefore you get the dynamic range of an 8 bit depth sampling. So you don't preserve the dynamic range of the original signal.

That's why you get codecs like G.711 that use non linear companding such as A law companding, because they map the 12 bit samples of lower amplitudes to the 8 bit amplitude levels at 1:1 rather than 8:1 across the board, and then the higher amplitude samples obviously at 64:1, to make up for it, such that you get the same average 8:1 compression across the board. But of course, because most of the signal is in this dynamic range, you end up getting lower average quantisation noise, because most of the signal is quantised as if it were 12 bit PCM, so when you reverse this to get the 12 bit PCM samples again, the quantisation noise is similar to if it were truly 12 bit PCM, meaning the inherent dynamic range in these samples is now close to 12 bit PCM instead of the 8 bit PCM they were compressed to.

If you want to preserve the dynamic range of a signal in the analogue domain, you map it to the same dynamic range using an A law curve. Mapping it linearly will do absolutely nothing because the signal will just be linearly scaled, meaning it will have the same dynamic range (unless a linear scaling down causes it to drop below the noise floor of the dynamic range of the analogue circuitry, then the dynamic range will be reduced), but altering it with a companding curve will cause an 8 bit quantisation to quantise in the same way the 12 to 8 bit sample digital conversion does, except entirely analoguely. So you just get those 8 bit samples mentioned earlier straight out of the ADC. So you can actually do the companding curve in physical circuitry on the physical signal. In this case you don't compress the physical dynamic range, you just compress and expand the signal at a net 1:1 change because you're doing the digital domain companding but in the analogue domain.

In compression of an analogue domain or digital domain analogue audio signal, where it is the final product, it is usually shown on an unnormalised plot where the input and output dynamic range (on the axes) are the same, in this case a 1:1 compression is $$y = x$$ and maps the amplitudes 1:1, whereas the dynamic range is compressed 4:1 above the threshold for instance, and you can see the new dynamic range on the output axis (y).

In the digital domain, the dynamic range of the signal is capped on the lower bound to V*1, but may of course not have a peak that low, so the dynamic range of an N bit-depth signal is less than or equal to the dynamic range of an N bit ADC.