Skip to main content

Power Spectral Density Calculation Using FFT in MATLAB



Power spectral density (PSD) tells us how the power of a signal is distributed across different frequency components, whereas Fourier Magnitude gives you the amplitude (or strength) of each frequency component in the signal.

Steps to calculate the PSD of a signal

  1. Firstly, calculate the first Fourier transform (FFT) of a signal
  2. Then, calculate the Fourier magnitude of the signal
  3. The power spectrum is the square of the Fourier magnitude
  4. To calculate power spectrum density (PSD), divide the power spectrum by the total number of samples and the frequency resolution. {Frequency resolution = (sampling frequency / total number of samples)}

 Sampling frequency (fs): The rate at which the continuous-time signal is sampled (in Hz).

Total number of samples (N): The number of samples in the time-domain signal used for the DFT/FFT.

 Suppose:

    Sampling frequency = 1000 Hz

    Number of samples = 500

Then:
ฮ”f=1000/500=2 Hz

This means the FFT result will contain frequency components spaced 2 Hz apart: 0 Hz, 2 Hz, 4 Hz, ..., up to fs.

  1. Increasing the number of samples (N) → improves frequency resolution
  2. Increasing the sampling frequency (fs) → worsens frequency resolution, but increases the total frequency range analyzed

 

MATLAB Script

% The code is written by SalimWireless.com
clear
close all
clc
fs = 40000; % sampling frequency
T = 1; % total recording time
L = T .* fs; % signal length
tt = (0:L-1)/fs; % time vector
ff = (0:L-1)*fs/L;
y = sin(2*pi*100 .* tt) .* sin(2*pi*1000 .* tt); y = y(:); % reference sinusoid


% Allow user to input SNR in dB
snr_db = input('Enter the SNR (in dB): '); % User input for SNR
snr_linear = 10^(snr_db / 10); % Convert SNR from dB to linear scale


% Calculate noise variance based on SNR
signal_power = mean(y.^2); % Calculate signal power
noise_variance = signal_power / snr_linear; % Calculate noise variance


x = noise_variance*randn(L,1) + y; x = x(:); % sinusoid with additive Gaussian noise




% Plot results
figure


% Manual Power Spectral Density plots
subplot(311)
plot(y, tt,'r')
title('Original Message signal')
legend('Original signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')


% Manual Power Spectral Density plots
subplot(312)
[psd_y, f_y] = manualPSD(y, fs); % PSD of the original signal
plot(f_y,10*log10(psd_y),'r')
title('Power Spectral Density')
legend('Original signal PSD')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')


% Manual Power Spectral Density plots
subplot(313)
[psd_x, f_x] = manualPSD(x, fs); % PSD of the noisy signal
plot(f_x,10*log10(psd_x),'k')
title('Power Spectral Density')
legend('Noisy signal PSD')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')




% Manual PSD calculation function
function [psd, f] = manualPSD(signal, fs)
N = length(signal); % Signal length
fft_signal = fft(signal); % FFT of the signal
fft_signal = fft_signal(1:N/2+1); % Take only the positive frequencies
psd = (1/(fs*N)) * abs(fft_signal).^2; % Compute the power spectral density
psd(2:end-1) = 2*psd(2:end-1); % Adjust the PSD for the one-sided spectrum
f = (0:(N/2))*fs/N; % Frequency vector
end

Output





Copy the MATLAB 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 ๐Ÿงฎ Simulator for m-ary QAM and m-ary PSK ๐Ÿงฎ MATLAB Codes ๐Ÿ“š 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 transmitted bits)  On the other hand, SNR refers to the signal-to-noise power ratio. For ease of calculation, we commonly convert it to dB or decibels.   What is Signal the signal-to-noise ratio (SNR)? SNR = signal power/noise power (SNR is a ratio of signal power to noise power) SNR (in dB) = 10*log(signal power / noise power) [base 10] For instance,...

Constellation Diagrams of ASK, PSK, and FSK

๐Ÿ“˜ Overview ๐Ÿงฎ Simulator for constellation diagrams of ASK, FSK, and PSK ๐Ÿงฎ Theory ๐Ÿงฎ MATLAB Codes ๐Ÿ“š 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 SNR (dB): 15 Add A...

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

๐Ÿ“˜ Overview ๐Ÿงฎ Simulator ๐Ÿงฎ Noise Sensitivity, Bandwidth, Complexity, etc. ๐Ÿงฎ MATLAB Codes ๐Ÿงฎ 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 Rate or Bit Rate (bps): Frequency Deviation (Hz) for FSK: Calculate Bandwidth Comparison among ASK,  FSK, and PSK Performance Comparison: 1. Noise Sensitivity:    - ASK is the most sensitive to noise due to its r...

Simulation of ASK, FSK, and PSK using MATLAB Simulink

ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink      In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation.  Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux is a tool for displaying both modulated and unmodulated signals at the same time. The result section shows that binary '1' is modulated by a certain sine wave amplitude of 1 Volt, and binary '0' is modulated by zero amplitude. Simulation of Frequency Shift Keying (FSK) using MATLAB Simulink   Result The diagram above shows t...

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

Pathloss : Large Scale & Small Scale Pathloss and Pathloss Exponent 'n'

๐Ÿ“˜ Overview ๐Ÿงฎ Free Space Pathloss ๐Ÿงฎ Close-in Path Loss Model ๐Ÿงฎ Large Scale Pathloss ๐Ÿงฎ Small Scale Pathloss ๐Ÿงฎ Path loss exponent 'n' ๐Ÿ“š Further Reading Wireless Communication Pathloss : Large Scale & Small Scale Pathloss... In wireless communication , the path loss is proportional to the square of the operating carrier frequency. As a result, the higher the frequency, the greater the path loss. Although path loss is affected by several parameters, including fading, shadowing, angle of arrival (AOA), and angle of departure (AOD), and others. In comparison to lesser frequencies, when the frequency is extremely high, it is easily absorbed by atmospheric gases, vapor, and rain. In the case of higher frequencies , however, the penetration loss is also greater. Path loss is linearly proportional to the carrier frequency, according to Firs' free space path loss. Path loss parameters are often di...