Skip to main content

Calculation of SNR from FFT bins in MATLAB


 

Here, you can find the SNR of a received signal from periodogram / FFT bins using the Kaiser operator. The beta (β) parameter characterizes the Kaiser window, which controls the trade-off between the main lobe width and the side lobe level in the frequency domain. For that you should know the sampling rate of the signal. 

The Kaiser window is a type of window function commonly used in signal processing, particularly for designing finite impulse response (FIR) filters and performing spectral analysis. It is a general-purpose window that allows for control over the trade-off between the main lobe width (frequency resolution) and side lobe levels (suppression of spectral leakage). The Kaiser window is defined using a modified Bessel function of the first kind.

 

 Steps

  1. Set up the sampling rate and time vector
  2. Compute the FFT and periodogram
  3. Plot the periodogram using FFT
  4. Specify parameters for Kaiser window and periodogram
  5. Calculate the frequency resolution and signal power
  6. Exclude the signal power from noise calculation
  7. Compute the noise power
  8. Calculate the SNR
 

MATLAB Code for Estimation of SNR from FFT bins of a Noisy Signal

clc;
clear;
close all;

% Parameters
fs = 8000; % Sampling frequency (Hz)
f_tone = 1000; % Tone frequency (Hz)
N = 8192; % Use large N so 1000 Hz aligns with an FFT bin
t = (0:N-1)/fs; % Time vector

% Generate 1 kHz sine wave
signal = sin(2*pi*f_tone*t);

% Add white Gaussian noise
SNR_true_dB = 20; % Desired true SNR in dB
signal_power = mean(signal.^2);
noise_power = signal_power / (10^(SNR_true_dB/10));
noise = sqrt(noise_power) * randn(1, N);
noisy_signal = signal + noise;

% Apply window to reduce leakage
w = hamming(N)';
windowed_signal = noisy_signal .* w;
U = sum(w.^2)/N; % Window power normalization factor

% FFT
X = fft(windowed_signal);
f = (0:N-1)*fs/N;

% Power spectrum
Pxx = abs(X).^2 / (fs * N * U); % Proper normalization for PSD

% Find signal bin (closest to 1 kHz)
[~, signal_bin] = min(abs(f - f_tone));

% Estimate signal power from ±1 bins around 1 kHz
signal_bins = signal_bin-1 : signal_bin+1;
signal_power_est = sum(Pxx(signal_bins));

% Estimate noise power from all other bins
noise_bins = setdiff(1:N/2, signal_bins); % Use only one-sided spectrum
noise_power_est = sum(Pxx(noise_bins));

% Estimate SNR
SNR_est = signal_power_est / noise_power_est;
SNR_est_dB = 10 * log10(SNR_est);

% Print results
fprintf('True SNR: %.2f dB\n', SNR_true_dB);
fprintf('Estimated SNR from FFT: %.2f dB\n', SNR_est_dB);

% Plot
figure;
plot(f(1:N/2), 10*log10(Pxx(1:N/2)));
xlim([0 fs/2]);
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Power Spectrum of Noisy Signal with Hamming Window');
grid on;

Output

True SNR: 20.00 dB
Estimated SNR from FFT: 19.77 dB
 

 
 
 
 
 
 
 

MATLAB Code for Estimation of Signal-to-Noise Ratio from Power Spectral Density Using FFT and Kaiser Window Periodogram from real signal data

clc; clear ; close all;
fs = 32000;
t = 0:1/fs:1-1/fs;

 x=load("x2.mat");
 x = x.x2;

N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:fs/length(x):fs/2;

figure; plot(freq,pow2db(psdx))
grid on
title("Periodogram Using FFT")
xlabel("Frequency (Hz)")
ylabel("Power/Frequency (dB/Hz)")

%rng default
Fi = 3000;
Fs = 32e3;
N = 1024;%2048;


w = kaiser(numel(x),38);
[Pxx, F] = periodogram(x,w,numel(x),Fs);
SNR_periodogram = snr(Pxx,F,'psd')

freq_resolution= abs(F(2)-F(3));
Signal_power= Pxx(3000); % p

s=sum((Signal_power), 1); s=s/length(Signal_power); s=abs(s);
Sig_power=pow2db(freq_resolution*s)

exclude_range = pxx(3000);
Noise_power = Pxx;
Noise_power(exclude_range) = 0; % Set the values in the specified range to zero

% Noise_power= Pxx(20001:24001); %x,y,z
n=sum((Noise_power), 1)/length(Noise_power); n=abs(n);
N_power=pow2db(freq_resolution*n)

SNR=Sig_power-N_power 

Output

 
 
 
 
 SNR =  25.8906 (in dB)


 

Copy the code from here


 

Further Reading

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

Constellation Diagram of ASK in Detail

A binary bit '1' is assigned a power level of E b \sqrt{E_b}  (or energy E b E_b ), while a binary bit '0' is assigned zero power (or no energy).   Simulator for Binary ASK Constellation Diagram SNR (dB): 15 Run Simulation Noisy Modulated Signal (ASK) Original Modulated Signal (ASK) Energy per bit (Eb) (Tb = bit duration): We know that all periodic signals are power signals. Now we’ll find the energy of ASK for the transmission of binary ‘1’. E b = ∫ 0 Tb (A c .cos(2П.f c .t)) 2 dt = ∫ 0 Tb (A c ) 2 .cos 2 (2П.f c .t) dt Using the identity cos 2 x = (1 + cos(2x))/2: = ∫ 0 Tb ((A c ) 2 /2)(1 + cos(4П.f c .t)) dt ...

Periodogram in MATLAB

Power Spectral Density Estimation Using the Periodogram Step 1: Signal Representation Let the signal be x[n] , where: n = 0, 1, ..., N-1 (discrete-time indices), N is the total number of samples. Step 2: Compute the Discrete-Time Fourier Transform (DTFT) The DTFT of x[n] is: X(f) = ∑ x[n] e -j2Ï€fn For practical computation, the Discrete Fourier Transform (DFT) is used: X[k] = ∑ x[n] e -j(2Ï€/N)kn , k = 0, 1, ..., N-1 k represents discrete frequency bins, f_k = k/N * f_s , where f_s is the sampling frequency. Step 3: Compute Power Spectral Density (PSD) The periodogram estimates the PSD as: S_x(f_k) = (1/N) |X[k]|² S_x(f_k) ...

MATLAB Code for Rms Delay Spread

RMS delay spread is crucial when you need to know how much the signal is dispersed in time due to multipath propagation, the spread (variance) around the average. In high-data-rate systems like LTE, 5G, or Wi-Fi, even small time dispersions can cause ISI. RMS delay spread is directly related to the amount of ISI in such systems. RMS Delay Spread [↗] Delay Spread Calculator Enter delays (ns) separated by commas: Enter powers (dB) separated by commas: Calculate   The above calculator Converts Power to Linear Scale: It correctly converts the power values from decibels (dB) to a linear scale. Calculates Mean Delay: It accurately computes the mean excess delay, which is the first moment of the power delay profile. Calculates RMS Delay Spread: It correctly calculates the RMS delay spread, defined as the square root of the second central moment of the power delay profile.   MATLAB Code  clc...

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   Start Simulator for binary ASK Modulation Message Bits (e.g. 1,0,1,0) Carrier Frequency (Hz) Sampling Frequency (Hz) Run Simulation Simulator for binary FSK Modulation Input Bits (e.g. 1,0,1,0) Freq for '1' (Hz) Freq for '0' (Hz) Sampling Rate (Hz) Visualize FSK Signal Simulator for BPSK Modulation ...

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022: Previous Year Question Papers ... UGC-NET (Electronics Science, Subject code: 88) UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2024]  UGC Net Paper 1 With Answer Key Download Pdf [Sep 2024] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [Sep 2024]  UGC Net Paper 1 With Answer Key Download Pdf [June 2023] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2023] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2023] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2021] ...

Comparisons among ASK, PSK, and FSK | And the definitions of each

📘 Comparisons among ASK, FSK, and PSK 🧮 Online Simulator for calculating Bandwidth of ASK, FSK, and PSK 🧮 MATLAB Code for BER vs. SNR Analysis of ASK, FSK, and PSK 📚 Further Reading 📂 View Other Topics on Comparisons among ASK, PSK, and FSK ... 🧮 Comparisons of Noise Sensitivity, Bandwidth, Complexity, etc. 🧮 MATLAB Code for Constellation Diagrams of ASK, FSK, and PSK 🧮 Online Simulator for ASK, FSK, and PSK Generation 🧮 Online Simulator for ASK, FSK, and PSK Constellation 🧮 Some Questions and Answers Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK Comparison among ASK, FSK, and PSK Parameters ASK FSK PSK Variable Characteristics Amplitude Frequency ...

5G Channel Estimation using Orthogonal Matching Pursuit (OMP)

5G Channel Estimation... For millimeter wave massive MIMO communication in 5G, we observe that the number of available multipath that avails communication is much smaller than the maximum connections possible between the transmitter(TX) and receiver(RX). Only a few MPCs reach at receiver with good received signal strength. For example, the number of strong MPCs that reaches the receiver is L and there is N transmitter antenna on the transmitter side and N number of antennas on the receiver side. So, from the channel matrix of the massive MIMO system, we can say the total number of available paths or connections between TX and RX is equal to, N X N or, N^(2) Now, L << N^(2) For simplicity, if the number of possible strong beams from the transmitter and receiver sides are NtBeams and NrBeams, then, L = NtBeams * NrBeams If we look up the massive MIMO channel matrix , then, H= Primarily, if the number of available MPCs to avail communication bet...

OFDM for 4G & 5G

📘 Overview 📘 Example: (OFDM using QPSK) 🧮 MATLAB Codes 🧮 Q & A and Summary 📚 Further Reading   Orthogonal Frequency Division Multiplexing When a signal with high bandwidth traverses through a medium, it tends to disperse more compared to a signal with lower bandwidth. A high-bandwidth signal comprises a wide range of frequency components. Each frequency component may interact differently with the transmission medium due to factors such as attenuation, dispersion, and distortion. OFDM combats the high-bandwidth frequency selective channel by dividing the original signal into multiple orthogonal multiplexed narrowband signals. In this way it, overcomes the inter-symbol interferences (ISI) issue. Block Diagram     ‘k’ indicates kth position in a input symbol N is the number of subcarriers   Example: (OFDM using QPSK) 1.        Input Parameters: N   Number of Input bits: 128 Number ...