+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Member level 1
    Points: 637, Level: 5

    Join Date
    Jan 2016
    Posts
    33
    Helped
    0 / 0
    Points
    637
    Level
    5

    Calculating SNR in time and frequency domain

    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)

    •   AltAdvertisment

        
       

  2. #2
    Newbie level 4
    Points: 39, Level: 1

    Join Date
    Aug 2018
    Posts
    6
    Helped
    0 / 0
    Points
    39
    Level
    1

    Re: Calculating SNR in time and frequency domain

    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))



--[[ ]]--