Step 1: Signal Representation
Let the signal be x[n], where:
n = 0, 1, ..., N-1(discrete-time indices),Nis 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
Here:
krepresents discrete frequency bins,f_k = k/N * f_s, wheref_sis the sampling frequency.
Step 3: Compute Power Spectral Density (PSD)
The periodogram estimates the PSD as:
S_x(f_k) = (1/N) |X[k]|²
Where:
S_x(f_k)represents the power of the signal at frequencyf_k.- The factor
1/Nnormalizes the power by the signal length.
Step 4: Convert to Decibels (Optional)
For visualization, convert PSD to decibels (dB):
S_xdB(f_k) = 10 log₁₀(S_x(f_k))
Practical Notes
- Frequency Resolution: Depends on the signal duration
T = N / f_s. HigherNgives finer frequency resolution. - Windowing (Optional): Use a window function (e.g., Hamming, Hann) to reduce spectral leakage:
x'[n] = x[n] * w[n]. - Frequency Range: PSD spans frequencies:
f_k = k/N * f_sfor positive frequencies.f_k = -(N-k)/N * f_sfor negative frequencies.
MATLAB Code
clc;
clear;
close all;
% Define signal parameters
N = 256; % Number of samples
fs = 1000; % Sampling frequency in Hz
t = (0:N-1)/fs; % Time vector
% Generate a sample signal (sum of two sinusoids)
f1 = 50; % Frequency of first sinusoid in Hz
f2 = 120; % Frequency of second sinusoid in Hz
x = sin(2*pi*f1*t) + 0.5*sin(2*pi*f2*t) + randn(1, N)*0.1; % Signal with noise
% Compute DFT of the signal
X = fft(x, N);
% Calculate the periodogram
Pxx = (1/N) * abs(X).^2;
% Generate frequency vector
f = (0:N-1)*(fs/N);
% Keep only the positive frequencies (up to Nyquist frequency)
Pxx = Pxx(1:N/2+1);
f = f(1:N/2+1);
% Plot the periodogram
figure;
plot(f, 10*log10(Pxx), 'LineWidth', 1.5);
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Periodogram');
grid on;Output
Copy the MATLAB Code above from here
Further Reading
- Periodogram and Windowed Periododgram in details
- Correlogram in MATLAB
- Bartlett Method in MATLAB
- Blackman-Tukey Method in MATLAB
- Welch's Method in MATLAB
