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)