All problems
Quantization Noise SNR
Problem
Compute the quantization signal-to-noise ratio in dB: step = (max-min)/(2^bits-1), noise power = step^2/12, signal power = mean(x^2), and return 10*log10(signal/noise). Zero signal or zero noise returns 0.0.
The signature is quantization_noise_snr(values, bits=8).
Hint
Each extra bit adds roughly 6 dB of SNR under a fixed full-scale range.
Test cases
case 1
in: [[1,-1],8]
expected: 52.90201615587573
case 2
in: [[0,1],4]
expected: 31.303337684950062
case 3
in: [[0,0],8]
expected: 0
case 4
in: [[0.5,1.5,2],8]
expected: 58.75871190727366
Starter codePython
import math
def quantization_noise_snr(values, bits=8):
# Your code here
pass4 test cases · run your code against them in the editor