Skip to main content
Home Wireless Communication Modulation MATLAB Beamforming Project Ideas MIMO Computer Networks Lab 🚀

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

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

profile

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

Modulation Constellation Diagrams BER vs. SNR BER vs SNR for M-QAM, M-PSK, QPSk, BPSK, ... 1. 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.   2. 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, the SNR for a given communication system is 3dB. So, SNR (in ratio) = 10^{SNR (in dB) / 10} = 2 Therefore, in this instance,...

How to use MATLAB Simulink

  MATLAB Simulink is a popular add-on of MATLAB. Here, you can use different blocks like modulator, demodulator, AWGN channel, etc. And you can do experiments on your own.       Steps Go to the 'Simulink' tab at the top navbar of MATLAB. If not found, click on the add-on tab, search 'Simulink,' and then click on it to add. Once you installed the simulation, click the 'new' tap at the top left corner. Then, search the required blocks in the 'Simulink library.' Then, drag it to the editor space. You can double-click on the blocks to see the input parameters Then, connect the blocks by dragging a line from one block's output terminal to another block's input. If the connection is complete, click the 'run' tab in the middle of the top navbar.   After clicking on the run button, your Simulink is ready. Then double-click on any block to see the output   The following block diagram is an example of the MATLAB simulation of 'QPSK...

MATLAB Code for Pulse Width Modulation (PWM) and Demodulation

   Pulse Width Modulation (PWM) MATLAB Script clc; clear all; close all; fs=30; %frequency of the sawtooth signal fm=3; %frequency of the message signal sampling_frequency = 10e3; a=0.5; % amplitide t=0:(1/sampling_frequency):1; %sampling rate of 10kHz sawtooth=2*a.*sawtooth(2*pi*fs*t); %generating a sawtooth wave subplot(4,1,1); plot(t,sawtooth); % plotting the sawtooth wave title('Comparator Wave'); msg=a.*sin(2*pi*fm*t); %generating message wave subplot(4,1,2); plot(t,msg); %plotting the sine message wave title('Message Signal'); for i=1:length(sawtooth) if (msg(i)>=sawtooth(i)) pwm(i)=1; %is message signal amplitude at i th sample is greater than %sawtooth wave amplitude at i th sample else pwm(i)=0; end end subplot(4,1,3); plot(t,pwm,'r'); title('PWM'); axis([0 1 0 1.1]); %to keep the pwm visible during plotting. %% Demodulation % Demodulation: Measure the pulse width to reconstruct the signal demodulated_signal = zeros(size(msg)); for i = 1:leng...

MATLAB Code for QAM (Quadrature Amplitude Modulation)

  One of the best-performing modulation techniques is QAM [↗] . Here, we modulate the symbols by varying the carrier signal's amplitude and phase in response to the variation in the message signal (or voltage variation). So, we may say that QAM is a combination of phase and amplitude modulation. Additionally, it performs better than ASK or PSK [↗] . In fact, any constellation for any type of modulation, signal set (or, symbols) is structured in a way that prevents them from interacting further by being distinct by phase, amplitude, or frequency. MATLAB Script (for 4-QAM) % This code is written by SalimWirelss.Com % This is an example of 4-QAM. Here constellation size is 4 % or total number of symbols/signals is 4 % We need 2 bits once to represent four constellation points % QAM modulation is the combination of Amplitude modulation plus % Phase Modulation. We map the decimal value of the input symbols, i.e., % 00, 01, 10, 11 to 1 + 1i, -1 + 1i, 1 - 1i, and -1 - 1i, respectively. cl...

Constellation Diagrams of M-ary PSK | M-ary Modulation

Constellation Diagrams QPSK, M-PSK, M-QAM ... What is the difference between Bit and Symbol in the perspective of transmission? Symbols use bandwidth more efficiently than bits. For example, in the case of QPSK, one symbol or signal waveform is represented by 2 bits. Hence symbol rate is one-half of the bit rate. As a result, it occupies half bandwidth compared to the BPSK waveform. We know the primary purpose of modulation [↗] is to multiplex data. Here multiplexing is done so that there is less interference between parallel data streams. Suppose there is a communication channel; we can transmit a single data stream simultaneously. But if we send a symbol instead of a bit, we can send more than 1 bit at a time. In ASK modulation, we assign two amplitude levels to a signal where a higher level is represented by binary '1' and another level as '0'. For BFSK, we apply phase shift in signal (for example, 0 phase shift for consecutive binary ...

MATLAB Code for ASK, FSK, and PSK

ASK, FSK & PSK HomePage MATLAB Code MATLAB Code for Amplitude Shift Keying (ASK) % The code is written by SalimWireless.Com % Clear previous data and plots clc; clear all; close all; % Parameters Tb = 1; % Bit duration fc = 10; % Carrier frequency N = 10; % Number of bits % Generate carrier signal t = 0:Tb/100:1; carrier_signal = sqrt(2/Tb) * sin(2*pi*fc*t); % Generate message signal rng(10); % Set random seed for reproducibility binary_data = rand(1, N); % Generate random binary data t_start = 0; t_end = Tb; for i = 1:N t = [t_start:0.01:t_end]; % Generate message signal if binary_data(i) > 0.5 binary_data(i) = 1; message_signal = ones(1, length(t)); else binary_data(i) = 0; message_signal = zeros(1, length(t)); end % Store message signal message(i,:) = message_signal; % Modulate message with carrier ...

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

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 Performance Comparison: 1. Noise Sensitivity:    - ASK is the most sensitive to noise due to its reliance on amplitude variations.    - PSK is less sensitive to noise compared to ASK.    - FSK is relatively more robust against noise, making it suitable for noisy environments. 2. Bandwidth Efficiency:    - PSK is the most bandwidth-efficient, requiring less bandwidth than FSK for the same data rate.    - FSK requires wider bandwidth compared to PSK.    - ASK's bandwidth efficiency lies between FSK and PSK. Bandwidth Calculator for ASK, FSK, and PSK The baud rate represents the number of symbols transmitted per second Select Modulation Type: ASK...

Coherence Bandwidth and Coherence Time

  Coherence Bandwidth Coherence bandwidth is a concept in wireless communication and signal processing that relates to the frequency range over which a wireless channel remains approximately constant in terms of its characteristics. coherence bandwidth is  The inverse of Doppler spread delay time, or any spread delay time due to fading in general.  The coherence bandwidth is related to the delay spread of the channel, which is a measure of the time it takes for signals to traverse the channel. The two are related by the following formulae: Coherence bandwidth = 1/(delay spread time) Or, Coherence Bandwidth = 1/(root-mean-square delay spread time) (Coherence bandwidth in Hertz) For instance, the coherence bandwidth is 2 MHz when the delay spread is {1/(2*10^6)} = 500 ns in a household indoor environment. For narrowband approximation, Coherence Bandwidth = 1/root-mean-square delay spread time Coherence bandwidth is a measure of the frequency spread over which a wir...