Steps to calculate Spectral power density using Bartlett Method
1. 'M' is the length of each segment for the Bartlett method, set to 100 samples.
2. 'K' is the number of segments obtained by dividing the total number of samples N by the segment length 'M'.
3. psd_bartlett_broadband is initialized to store the accumulated periodogram.
4. For each segment k, x_k extracts the k-th segment of the broadband signal.
5. P_k computes the periodogram of the k-th segment using the FFT.
6. The periodograms are accumulated and averaged over all segments.
7. The PSD is plotted in dB/Hz by converting the power values to decibels using 10*log10.
MATLAB Script
clc;
clear;
close all;
% Parameters
fs = 1000; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
N = length(t); % Number of samples
% Generate synthetic broadband ARMA process
arma_order = [2, 2]; % ARMA(p,q) order
a = [1, -0.75, 0.5]; % AR coefficients
b = [1, 0.4, 0.3]; % MA coefficients
%broadband_signal = filter(b, a, randn(size(t)));
% Generate sinusoids with different frequencies
frequencies = [50, 150, 300, 450]; % Frequencies in Hz
amplitudes = [1, 0.8, 0.6, 0.4]; % Amplitudes
broadband_input = zeros(size(t));
for i = 1:length(frequencies)
broadband_input = broadband_input + amplitudes(i) * sin(2*pi*frequencies(i)*t);
end
% Add noise for realism (optional)
broadband_signal = broadband_input + 0.2*randn(size(t));
broadband_signal = filter(b, a, broadband_signal);
% Generate synthetic narrowband process
f0 = 50; % Center frequency of narrowband process
narrowband_signal = sin(2*pi*f0*t) + 0.5*randn(size(t));
% Parameters for Bartlett method
M = 100; % Length of each segment
K = N / M; % Number of segments
% Initialize the PSD estimate for broadband signal
psd_bartlett_broadband = zeros(1, M);
% Loop over each segment for broadband signal
for k = 1:K
% Extract the k-th segment
x_k = broadband_signal((k-1)*M + (1:M));
% Compute the periodogram of the k-th segment
P_k = abs(fft(x_k, M)).^2 / M;
% Accumulate the periodogram
psd_bartlett_broadband = psd_bartlett_broadband + P_k;
end
% Average the periodograms
psd_bartlett_broadband = psd_bartlett_broadband / K;
% Initialize the PSD estimate for narrowband signal
psd_bartlett_narrowband = zeros(1, M);
% Loop over each segment for narrowband signal
for k = 1:K
% Extract the k-th segment
x_k = narrowband_signal((k-1)*M + (1:M));
% Compute the periodogram of the k-th segment
P_k = abs(fft(x_k, M)).^2 / M;
% Accumulate the periodogram
psd_bartlett_narrowband = psd_bartlett_narrowband + P_k;
end
% Average the periodograms
psd_bartlett_narrowband = psd_bartlett_narrowband / K;
% Frequency axis
f = (0:M-1)*(fs/M);
% Plot the PSD for broadband signal
figure;
plot(f(1:50), 10*log10(psd_bartlett_broadband(1:50)));
title('Power Spectral Density (Bartlett Method) - Broadband Signal');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
% Plot the PSD for narrowband signal
figure;
plot(f(1:50), 10*log10(psd_bartlett_narrowband(1:50)));
title('Power Spectral Density (Bartlett Method) - Narrowband Signal');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
web('https://www.salimwireless.com/search?q=spectral%20estimation', '-browser');
Output

Copy the code from here
Further Reading