Why isn't my quantization noise in my code matching the SNR=6.02(number of bits) + 1.76
7 views (last 30 days)
Show older comments
I have written a code for an oversampled quantizer and the SNR which i get is not following SNR = 6.02n + 1.76 value. It differs slightly for every bit. Here :
clear all
close all
fs=1024e3; %Very high sampling rate 500 kHz
N=8
m=16
f=m*fs/(2^N); %Frequency of sinusoid
nCyl=16; %generate sixteen cycles of sinusoid
t=0:1/fs:nCyl*1/f; %time index
x=cos(2*pi*f*t);
ra=2%range of signal
n=20%number of bits
q=ra/((2^n)-1)
t=0:1/fs:nCyl*1/f;
y=1+cos(2*pi*f*t);
x0=round(y/q)
y1=x0*q
y2=y1-1
nfft=length(y2);
nfft2=2^nextpow2(nfft);
ff=fft(y2,256);%FFT of the quantized signal
ff0=fft(x,256)%FFT of the unquantized signal
fabs=abs(ff)
s=((fabs(17))^2 )*2/256 %signal power (17th peak of FFT)
t=sum((fabs).^2)/256%complete signal spectrum power
noise=t-s%noise power
snrc =s/noise%SNR calculated
snrcf=10*log10(snrc)%SNR in dB
isnr=(6.02*n)+1.76%ideal SNR by formula
s=snr(y1);
s0=snr(x);
qe=x-y2;%quantization error
deltaSNR= snrcf-isnr%error in SNR
Please help!
0 Comments
Answers (1)
Kambiz Shoarinejad
on 3 May 2021
Because that equation assumes uniformly distributed quantization noise. And with a pure tone, that may not be quite true. To see that, in your code, replace your actual quantization by the following line:
y2 = x + (-q/2) + q.*rand(size(x));
In other words, you would just be adding uniformly distributed quantization noise, in (-q/2,q/2) range, to your signal. And you will see that your calculated SNR would closely match the equation.
Also if you just change the number of points in your FFT from 256 to 1024 (i.e., change your N from 8 to 10), again you will see that your simulated SNR would be in line with the equation.
You may find this article useful (for example, see the plots on Page 6): https://www.analog.com/media/en/training-seminars/tutorials/MT-001.pdf
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!