0
$\begingroup$

Suppose I have ADC microphone with a given SNR in the sense that is related to its quantization. From this tutorial we have the following connection how bit-depth determines SNR, Eq. (9): $$ \mathrm{SNR} = 6.02 \times N + 1.76 \ \mathrm{dB} $$ where $N$ is the bit-depth. I would like to invert this relation in Python. Generate a float32 signal and quantize it as if it was recorded by an ADC microphone with the given SNR.

My original Python code was:

bits = int((snr_mic - 1.76)/6.02)
quant = 2**bits
out_audio = np.floor(audio * quant).astype(int)/quant

Later, I modified the code to this:

bits = np.floor((snr_mic - 1.76)/6.02) + 1
quant = 2**bits
out_audio = (audio * quant).astype(int)/quant

Since it enforces a signal simulated to be recorded with 0 dB SNR mic to be all 0's. However, even signals simulated to be recorded with 5 dB of SNR mic was all 0's. So I probably have bug in my code, probably related to the fine difference between floor and int for negative numbers.

What is the correct way to do it and have nonzero quantized signals for a given nonzero SNR mic?

$\endgroup$
2
  • $\begingroup$ What exactly do you mean by "ADC microphone". Do you want to model A_ the noise of an ADC quantization. B) the self noise of a microphone or C) the typically acoustic background noise that dominates most microphone recordings? These are all very different things. If someone uses the term "SNR of a microphone recording" they typically mean C) or B). A) is rarely a significant issue $\endgroup$
    – Hilmar
    Feb 22, 2022 at 7:09
  • $\begingroup$ A 1-bit microphone would have an SNR of 7.8dB -- why are you surprised that a calculation that specifies fewer than one bit(s) has all zeros as an output? As a debugging aid, printing out your 'bits' and 'quant' numbers would probably be helpful. $\endgroup$
    – TimWescott
    Jul 21, 2022 at 19:28

1 Answer 1

1
$\begingroup$

5 dB is not a sensible value for a formula whose minimum result would be 7.78 dB for $N=1$. So, your test case is "broken", and correctly, you get a 0-bit quantization (i.e., no values at all).

Even for higher SNRs: This sounds pretty reasonable!

Your audio will rarely come close to maximum amplitude. Think about this: if you only had, say, two bits, then that's 1 bit for the sign (think your audio as shifted to be centered around 0 if it helps), and 1 bit leading to two amplitude steps. If your audio recording always keeps more than 6 dB headroom (to avoid clipping!), then that quantization leads to all-zero.

Audio ADCs are pretty good, and I'd have no problem calling anything with a QSNR < 32 dB "atrocious".


Note that your considerations also has another shortcoming:

The formula you cite only applies to signals that are uniformly distributed over exactly the full ADC range. You'll be very hard tasked finding an audio signal that even remotely looks like that! For clipping / linearity / crest factor reasons, you need to have headroom for the vast majority of audio samples. Then, speech, music and many noise sources do not resemble uniformly distributed values:

Unnormalized histogram: triangle with tails nearly reaching max. amplitude Unnormalized 100-bin histogram over the values in Devin Townsend's Kingdom, a song that definitely tries to also achieve high amplitudes.

Unnormalized Histogram: Pretty much a triangle Unnormalized 100-bin histogram over the values in Nightwish's Angels Fall First, a song that contains clean vocals and acoustic guitar playing.

As you can see, assuming all values are equally probable is very far from the truth; accordingly, the actual quantization noise (the difference between quantized and original signal) does not follow the oft-cited formula. Whether or not that's a problem to you, I can't tell: it depends on what you want to show. However, "I have an audio SNR of x dB, thus I must have an ADC with (x-1.76)/6.02" is a fallacy.

$\endgroup$
10
  • 3
    $\begingroup$ Most signals will be distributed over a quantization interval as long as the signal spans a few quantization levels between samples (similar to making random white noise generators through modulo math). The main point about the formula is that it is applicable to the signal being a sine wave specifically (with a variance of Vpp/8 compared to the variance of noise as q/12). $\endgroup$ Feb 21, 2022 at 18:08
  • $\begingroup$ That comment should have more than my upvote, @DanBoschen $\endgroup$ Feb 21, 2022 at 19:35
  • 1
    $\begingroup$ Your quantization model as is looks correct, you'd want to use int instead of floor (floor(-0.1) == -1), to get lower average error. $\endgroup$ Feb 22, 2022 at 9:18
  • 2
    $\begingroup$ @MarcusMüller See dsp.stackexchange.com/questions/40259/… I simulated this in the past with backing off from full-scale and decreasing number of bits and different distribution with interesting results-- if someone ever asks a related question I can post those results, but it is completely independent of back-off (reduces db for db) as long as we meet the first criteria I gave on what makes the quantization noise approximately a white noise process with uniform distribution. $\endgroup$ Feb 22, 2022 at 13:08
  • 1
    $\begingroup$ Also rounding and truncation give the same error other than introducing a DC offset (which typically is not included in noise power similar to not including the mean in the standard deviation and variance). $\endgroup$ Feb 22, 2022 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.