Skip to main content

Calculation of SNR from FFT bins in MATLAB


SNR Estimation Overview

In digital signal processing, estimating the Signal-to-Noise Ratio (SNR) accurately is crucial. Below, we demonstrate how to calculate SNR from periodogram and FFT bins using the Kaiser Window. The beta (β) parameter is the key—it allows you to control the trade-off between main-lobe width and side-lobe levels for precise spectral analysis.

1 Define Sampling rate and Time vector
2 Compute FFT and Periodogram PSD
3 Identify Signal Bin and Frequency resolution
4 Segment Signal Power from Noise floor
5 Logarithmic calculation of SNR in dB

Method 1: Estimation from FFT Bins

This approach uses a Hamming window to estimate SNR directly from the spectral bins.

MATLAB Source Code
clc; clear; close all;
% Parameters
fs = 8000; f_tone = 1000; N = 8192; 
t = (0:N-1)/fs;

% Generate signal + noise
signal = sin(2*pi*f_tone*t);
SNR_true_dB = 20; 
signal_power = mean(signal.^2);
noise_power = signal_power / (10^(SNR_true_dB/10));
noisy_signal = signal + sqrt(noise_power) * randn(1, N);

% Apply window
w = hamming(N)';
windowed_signal = noisy_signal .* w;
U = sum(w.^2)/N; 

% FFT and PSD
X = fft(windowed_signal);
f = (0:N-1)*fs/N;
Pxx = abs(X).^2 / (fs * N * U); 

% Find signal bin
[~, signal_bin] = min(abs(f - f_tone));
signal_bins = signal_bin-1 : signal_bin+1;
signal_power_est = sum(Pxx(signal_bins));

% Noise estimation
noise_bins = setdiff(1:N/2, signal_bins); 
noise_power_est = sum(Pxx(noise_bins));

% Estimate SNR
SNR_est_dB = 10 * log10(signal_power_est / noise_power_est);
fprintf('Estimated SNR from FFT: %.2f dB\n', SNR_est_dB);

Method 2: Using Kaiser Window

Optimized spectral estimation using the Kaiser window (Beta=38) for better side-lobe suppression.

MATLAB Source Code
clc; clear; close all;
fs = 32000;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*3000*t) + 0.05*randn(size(t)); % Example Signal

N = length(x);
w = kaiser(N, 38);
[Pxx, F] = periodogram(x, w, N, fs);

% SNR Estimation
freq_resolution = abs(F(2)-F(1));
[~, target_idx] = min(abs(F - 3000)); % Find 3kHz index

% Signal Power (using bins around peak)
sig_idx = target_idx-2 : target_idx+2;
Sig_power_val = sum(Pxx(sig_idx)) * freq_resolution;
Sig_power_dB = 10*log10(Sig_power_val);

% Noise Power (excluding signal)
Noise_Pxx = Pxx;
Noise_Pxx(sig_idx) = 0; 
N_avg = sum(Noise_Pxx) / (length(Pxx) - length(sig_idx));
N_power_dB = 10*log10(N_avg * fs/2);

SNR = Sig_power_dB - N_power_dB;
fprintf('SNR = %.4f dB\n', SNR);
BER vs SNR Main Page >
Fourier Transform Main Page >
Online Signal Processing Simulations Main Page >

Power Spectral Density Calculation Using FFT

Power Spectral Density (PSD) is a fundamental metric used to characterize how the power of a signal is distributed across the frequency spectrum. While a standard Fourier Transform provides the amplitude and phase of frequency components, the PSD focuses on the intensity of power, making it an essential tool for analyzing noise, stochastic processes, and signal-to-noise ratios in communication systems.

Mathematical Logic

PSD = |FFT|2 / (fs · N)

The calculation follows a strict sequence:

  • Compute the FFT of the time-domain signal.
  • Take the Absolute Magnitude.
  • Square the magnitude to find raw power.
  • Normalize by sampling rate and sample count.

Frequency Resolution (Δf)

Δf = fs / N

fs (Sampling Frequency): Higher rates increase the total range but require more samples to maintain resolution.

N (Sample Count): Increasing N provides finer frequency "bins," allowing for higher precision in identifying signal peaks.

Core Principles of Spectral Estimation

Understanding PSD requires balancing the trade-offs between frequency range and clarity:

  1. 1
    Amplitude vs. Power: Fourier Magnitude represents the "strength" of a frequency, whereas PSD represents its energy density. Squaring the magnitude is what shifts the analysis from voltage/amplitude levels to power levels.
  2. 2
    Nyquist Limits: The sampling frequency (fs) dictates the maximum detectable frequency. To avoid aliasing, the PSD can only accurately describe components up to fs / 2.
  3. 3
    Statistical Reliability: In real-world applications, raw PSD calculations (periodograms) can be "noisy." Techniques like Welch's Method or Bartlett's Method improve accuracy by averaging multiple segments of the signal to smooth out random fluctuations.

Why PSD is Crucial

PSD is the primary tool for identifying hidden periodicities in noisy data. By observing the "floor" of a PSD plot, engineers can determine the Noise Power, while the "peaks" reveal the presence of dominant signals, enabling the calculation of the Signal-to-Noise Ratio (SNR).

Read More: about Power Spectral Density Calculation Using FFT (in MATLAB)

Contact Us

Name

Email *

Message *

Popular Posts

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions 📋 Exam Pattern 💡 Preparation Tips ❓ FAQs 📊 Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading 📂 View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...

UGC NET Electronic Science June 2025 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2025 Solved UGC NET Electronic Science June 2025 Question Paper with Answer Key and Full Explanations 📥 Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Explanations 1.  Answer: Option (3) For forming a p-type semiconductor, the dopant must be a trivalent impurity (three valence electrons) so that it creates acceptor levels and holes become the majority carriers. Among the given elements, boron (B) is a group-III element (trivalent). Arsenic (As) and phosphorus (P) are group-V (pentavalent) donors that produce n-type material, and germanium (Ge) is a group-IV element usually used as the semiconductor, not as an acceptor dopant. Hence, doping an intrinsic semiconductor with B produces a p-type semiconductor. 2.  Answer: Option (4) The ohmic resistance of a JFET at zero gate bias is given by the standard relation: R DS(on) = V P / I DSS ...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. 📘 Theory 🧮 Simulators 💻 MATLAB Code 📚 Resources BER Definition SNR Formula BER Calculator MATLAB Comparison 📂 Explore M-ary QAM, PSK, and QPSK Topics ▼ 🧮 Constellation Simulator: M-ary QAM 🧮 Constellation Simulator: M-ary PSK 🧮 BER calculation for ASK, FSK, and PSK 🧮 Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit f...

Q-function in BER vs SNR Calculation

Q-function in BER vs. SNR Calculation | Interactive Guide Q-function in BER vs. SNR Calculation In digital communications and signal processing, the Q-function plays a significant role in predicting system reliability. It allows engineers to quantify the probability that Gaussian noise will exceed a specific threshold, causing a bit error. What is the Q-function? The Q-function is a mathematical function representing the tail probability of the standard normal (Gaussian) distribution. It is the complementary cumulative distribution function (CCDF) of a standard Gaussian distribution. Q(x) = (1 / √(2Ï€)) ∫â‚“∞ e^(-t² / 2) dt Q-Function Interactive Simulator Move the slider to see how the "Tail Probability" (the area in red) changes. This area represents the Probability of Error (BER) . Threshold Distance ( x ) — (Simulates Increasing SNR) ...

MATLAB Code for ASK, FSK, and PSK (with Online Simulator)

MATLAB Code for ASK, FSK, and PSK Comprehensive implementation of digital modulation and demodulation techniques with simulation results. 📘 Theory 📡 ASK Code 📶 FSK Code 🎚️ PSK Code 🕹️ Simulator 📚 Further Reading Amplitude Shift Frequency Shift Phase Shift Live Simulator ASK, FSK & PSK HomePage MATLAB Code MATLAB Code for ASK Modulation and Demodulation COPY % The code is written by SalimWireless.Com clc; clear all; close all; % Parameters Tb = 1; fc = 10; N_bits = 10; Fs = 100 * fc; Ts = 1/Fs; samples_per_bit = Fs * Tb; rng(10); binar...

Which of the following statements are correct? A. If the intermediate frequency is too high, poor selectivity results even if sharp cutoff filters are used in the IF stage.

  61) Which of the following statements are correct?  A. If the intermediate frequency is too high, poor selectivity results even if sharp cutoff filters are used in the IF stage.  B. A high value of intermediate frequency increases tracking difficulties.  C. As the intermediate frequency is lowered, image frequency rejection becomes better.  D. A very low intermediate frequency can make the selectivity too sharp.  Choose the correct answer from the options given below:  1. A and B only [Option ID = 3073]  2. B and C only [Option ID = 3074]  3. C and D only [Option ID = 3075]  4. B and D only [Option ID = 3076 Answer: 4  Previous yr Question papers with Full Explanations → Electronics and Communiaction Study Materials → Try Interactive Online Simulator Run the Simulation The Superheterodyne Principle The...

Shannon Limit Explained: Negative SNR, Eb/No and Channel Capacity

Understanding Negative SNR and the Shannon Limit An explanation of Signal-to-Noise Ratio (SNR), its behavior in decibels, and how Shannon's theorem defines the ultimate communication limit. Signal-to-Noise Ratio in Shannon’s Equation In Shannon's equation, the Signal-to-Noise Ratio (SNR) is defined as the signal power divided by the noise power: SNR = S / N Since both signal power and noise power are physical quantities, neither can be negative. Therefore, the SNR itself is always a positive number. However, engineers often express SNR in decibels: SNR(dB) When SNR = 1, the logarithmic value becomes: SNR(dB) = 0 When the noise power exceeds the signal power (SNR < 1), the decibel representation becomes negative. Behavior of Shannon's Capacity Equation Shannon’s channel capacity formula is: C = B log₂(1 + SNR) For SNR = 0: log₂(1 + SNR) = 0 When SNR becomes smaller (including negative values in dB), the expression approache...

Reed–Solomon Coding and Decoding

Reed–Solomon Coding and Decoding 1. Input Bitstream to Symbols Given input bitstream: 101011000… Choose symbol size: m = 3 ⇒ symbols in GF(2³) Grouping bits: 101 | 011 | 000 Binary to decimal symbols: [5, 3, 0] 2. Finite Field Construction GF(2³) Primitive polynomial: p(x) = x³ + x + 1 Element Polynomial Binary Decimal α⁰ 1 001 1 α¹ α 010 2 α² α² 100 4 α³ α + 1 011 3 α⁴ α² + α 110 6 α⁵ α² + α + 1 111 7 α⁶ α² + 1 101 5 3. Message Polynomial Choose RS(7,3): n = 7, k = 3 Message symbols: [5, 3, 0] Message polynomial: m(x) = 5 + 3x + 0x² 4. Generator Polynomial Number of parity symbols: n − k = 4 Generator polynomial: g(x) = (x − α)(x − α²)(x − α³)(x − α⁴) Expanded form: g(x) = x⁴ + 6x³ + x² + 6x + 1 5. RS Encoding (Polynomial Division) Multiply message by x⁴: x⁴m(x) = 5x⁴ + 3x⁵ Divide by generator polynomial: r(x) = 6 + 4x + 2x² + 5x³ Codeword polynomial: c(x) = x⁴m(x) + r(x) Final codeword symbols: [...