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







Admin & Author: Salim

s

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

📘 Overview of BER and SNR 🧮 Online Simulator for BER calculation of m-ary QAM and m-ary PSK 🧮 Online Simulator for Constellation Diagram of m-ary QAM 🧮 Online Simulator for Constellation Diagram of m-ary PSK 🧮 MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... 🧮 MATLAB Code for BER calculation of ASK, FSK, and PSK 🧮 MATLAB Code for BER calculation of Alamouti Scheme 🧮 Different approaches to calculate BER vs SNR 📚 Further Reading Modulation Constellation Diagrams BER vs. SNR BER vs SNR for M-QAM, M-PSK, QPSk, BPSK, ... What is Bit Error Rate (BER)? The abbreviation BER stands for bit error rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. It is defined as,  In mathematics, BER = (number of bits received in error / total number of ...

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

https://www.salimwireless.com/2024/11/constellation-diagram-in-matlab.html 📘 Overview 🧮 Simulator 🧮 Noise Sensitivity, Bandwidth, Complexity, etc. 🧮 MATLAB Code for BER vs. SNR Analysis of ASK, FSK, and PSK 🧮 MATLAB Code for Constellation Diagrams of ASK, FSK, and PSK 🧮 Simulator for ASK, FSK, and PSK Generation 🧮 Simulator for ASK, FSK, and PSK Constellation 🧮 Some Questions and Answers 📚 Further Reading Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK   Simulator for Calculating Bandwidth of ASK, FSK, and PSK The baud rate represents the number of symbols transmitted per second. Both baud rate and bit rate are same for binary ASK, FSK, and PSK. Select Modulation Type: ASK FSK PSK Baud Rat...

Constellation Diagrams of ASK, PSK, and FSK

📘 Overview 🧮 Online Simulator for constellation diagrams of ASK, FSK, and PSK 🧮 Theory 🧮 MATLAB Codes 🧮 Simulator for constellation diagrams of m-ary PSK 🧮 Simulator for constellation diagrams of m-ary QAM 📚 Further Reading BASK (Binary ASK) Modulation: Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1.    BFSK (Binary FSK) Modulation: Transmits one of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals: +√Eb​ or -√Eb (they differ by 180 degree phase shift), where Eb​ is the energy per bit. These signals represent binary 0 and 1.    Simulator for BASK, BPSK, and BFSK Constellation Diagrams ...

MATLAB Code for Pulse Amplitude Modulation (PAM) and Demodulation

📘 Overview & Theory 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of an Analog Signal 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of an Analog Signal (2) 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of Digital data 🧮 Simulation results for comparison of PAM, PWM, PPM, DM, and PCM 🧮 Other Pulse Modulation Techniques (e.g., PWM, PPM, DM, and PCM) 📚 Further Reading   Pulse Amplitude Modulation (PAM) & Demodulation of an Analog Message Signal MATLAB Script clc; clear all; close all; fm= 10; % frequency of the message signal fc= 100; % frequency of the carrier signal fs=1000*fm; % (=100KHz) sampling frequency (where 1000 is the upsampling factor) t=0:1/fs:1; % sampling rate of (1/fs = 100 kHz) m=1*cos(2*pi*fm*t); % Message signal with period 2*pi*fm (sinusoidal wave signal) c=0.5*square(2*pi*fc*t)+0.5; % square wave with period 2*pi*fc s=m.*c; % modulated signal (multiplication ...

RMS Delay Spread, Excess Delay Spread and Multi-path ...

📘 Overview 🧮 Multipath Components or MPCs 🧮 Excess Delay spread 🧮 Power delay Profile 🧮 RMS Delay Spread 🧮 Simulator for Calculating RMS Delay Spread 🧮 Why is there significant multipath in the case of very high frequencies? 🧮 Why RMS Delay Spread is essential for wireless communication? 🧮 Why the Power Delay Profile is essential? 🧮 MATLAB Codes 📚 Further Reading Signal Processing RMS Delay Spread, Excess Delay Spread, and Multipath... RMS Delay Spread, Excess Delay Spread, and Multipath (MPCs) The fundamental distinction between wireless and wired connections is that in wireless connections signal reaches at receiver thru multipath signal propagation rather than directed transmission like co-axial cable. Wireless Communication has no set communication path between the transmitter and the receiver. The line of sight path, also known as the LOS path, is the shortest and most direc...

Relationship between Gaussian and Rayleigh distributions

📘 Introduction, Gaussian Distribution, Relationship Between Gaussian and Rayleigh Distribution 🧮 How to mitigate Rayleigh fading? 🧮 Equalizer to reduce Rayleigh Fading (or Multi-path Effects) in MATLAB 🧮 MATLAB Code for Effects of AWGN and Rayleigh Fading in Wireless Communication 🧮 Simulator for the effect of AWGN and Rayleigh Fading on a BPSK Signal 📚 Further Reading Wireless Signal Processing Gaussian and Rayleigh distributions ...   The Rayleigh distribution in classical fading models (like wireless communication) arises from modeling the real and imaginary parts of a complex baseband signal as independent, zero-mean Gaussian random variables — under specific assumptions . 1. Gaussian Distribution  The Gaussian distribution has a lot of applications in wireless communication. Since noise in wireless communication systems is unpredictable, we frequently assume that it has a Gaussian distribution...

MATLAB Codes for Various types of beamforming | Beam Steering, Digital...

Beamforming Techniques MATLAB Codes for Beamforming... The mathematical [↗] and theoretical aspects of beamforming [↗] have already been covered. We'll talk about coding in MATLAB in this tutorial so that you may generate results for different beamforming approaches. Let's go right to the content of the article. In analog beamforming, certain codebooks are employed on the TX and RX sides to select the best beam pairs. Because of their beamforming gains, communication created through the strongest beams from both the TX and RX side enhances spectrum efficiency. Additionally, beamforming gain directly impacts SNR improvement. Wireless communication system capacity = bandwidth*log2(1+SNR) bits/s. Thus, the capacity or overall throughput of the system increases. MATLAB Script %Written by Salim Wireless %Visit www.salimwireless.com for study materials on wireless communication %or, if you want to learn how to code in MATLAB clear all;...

Difference between AWGN and Rayleigh Fading

📘 Introduction, AWGN, and Rayleigh Fading 🧮 Simulator for the effect of AWGN and Rayleigh Fading on a BPSK Signal 🧮 MATLAB Codes 📚 Further Reading Wireless Signal Processing Gaussian and Rayleigh Distribution Difference between AWGN and Rayleigh Fading 1. Introduction Rayleigh fading coefficients and AWGN, or additive white gaussian noise [↗] , are two distinct factors that affect a wireless communication channel. In mathematics, we can express it in that way.  Fig: Rayleigh Fading due to multi-paths Let's explore wireless communication under two common noise scenarios: AWGN (Additive White Gaussian Noise) and Rayleigh fading. y = h*x + n ... (i) Symbol '*' represents convolution. The transmitted signal  x  is multiplied by the channel coefficient or channel impulse response (h)  in the equation above, and the symbol  "n"  stands for the white Gaussian noise that is added to the si...