Calculating SNR in time and frequency domain

Status
Not open for further replies.

Chinmaye

Full Member level 3
Joined
Jan 18, 2016
Messages
164
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
3,145
Hello all,
I am trying this for study purpose. I have a signal "signal = 5*sin(2*pi*250*time)" for which am adding noise and trying to calculate SNR in time and freq domain. Both of them don't seem to match. Also using a window should improve the SNR but it is not. (PS : Window part of the code not attached) Attaching the code. Plz help
Code:
Fs = 4096;
time = 0:1/Fs:1-1/Fs;

signal = 5*sin(2*pi*250*time);

noise = randn(size(signal));
x = signal + noise
X = db(abs(fft(x)))

actualSNR = 20*log10(norm(signal)/norm(x - signal))
sigfft = 0;
noisefft = 0;

for i = 1:7
    sigfft = sigfft + abs(X2(i+248)).^2;% consider 7 bins closest to the signal of interest
end
sigfft = sigfft/7
for i = 1:2048
    noisefft = noisefft + abs(X2(i)).^2;
end
noisefft = noisefft-sigfft;
noisefft = noisefft/2040
snrfft = 10*log10(sigfft/noisefft)
 

In your code,In the following line:

actualSNR = 20*log10(norm(signal)/norm(x - signal))

add a dot before the backslash division sign, i.e,

actualSNR = 20*log10(norm(signal)./norm(x - signal))
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…