# SQNR simulation result does not match with the formula 6.02*N + 1.76

67 views (last 30 days)
Engincan Ergen on 29 Oct 2021
Answered: Arthi Sathyamurthi on 28 Dec 2021
I have implemented an ideal 10 bit midrise type quantizer in MATLAB. The signal-to-quantization-noise value from the simulation
and theory differ by approximately 6 dB. I have checked this difference with multiple bit numbers such as 10 bits, 12bits, 16bits and
the result is the same, SQNR from the simulation is always 6 dB below the ideal value. Also, fft of the quantized signal is strange, it
does have two peaks at signal frequency as expected, however all other values are zero. I cannot understand these two results.
Here is my code:
clear all;clc;close all;
fs = 1e6;
t = 0:1/fs:4.095e-3;
y1 = sin(2*pi*37/512*1e6*t);
N = length(y1);
y1_dft = abs(fft(y1))/N;
dft_idy1 = 0:N-1;
f = (fs/N)*dft_idy1;
figure (1);
plot(f,20*log10(y1_dft));
title("fft of the original signal y1");
nbits = 10;
delta = 2*max(abs(y1))/(2^nbits); %% for n bit quantization, step size(delta) is Vpp/(2^nbit)
n_quants = 2^nbits;
% following part implements a midrise quantizer
partition_right = delta:delta:(n_quants/2)*delta;
partition_left = -flip(partition_right,2);
partition = [partition_left 0 partition_right];
codebook_left = [min(partition_left) partition_left];
codebook_right = [partition_right max(partition_right)];
codebook = [codebook_left codebook_right];
[index,y1_quantized] = quantiz(y1,partition,codebook);
%quantized_y1 = floor((n_quants-1)*y1)/(n_quants);
figure(2);
plot(t,y1);
hold on
stem(t,y1_quantized);
legend('Original signal y1','Quantized y1');
hold off
quants_dft = abs(fft(y1_quantized))/N;
dft_idquants = 0:N-1;
f = (fs/N)*dft_idquants;
figure(3);
plot(f,(quants_dft));
title("fft of the quantized signal");
quantization_noise = y1 - y1_quantized;
figure
plot(t,quantization_noise);
xlabel('time')
ylabel('quantization noise')
title('quantization noise in time domain')
quantization_noise_power = sum(abs(quantization_noise).^2)/N;
quantization_noise_power_theory = (delta^2)/12;
signal_power = var(y1);
SQNR_sim = 10*log10(signal_power/quantization_noise_power);
SQNR_theory = 6.02*nbits + 1.76 % in dB

Arthi Sathyamurthi on 28 Dec 2021
Hello,
The theoritical SQNR formula is where is the signal power in dB and ν is the number of bits. Hence you can try modifying the SQNR theory as
SQNR_theory = 10*log10(signal_power) + 6.02*nbits + 1.76;
Also to calculate the power of the signal you can use the bandpower function.