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?