# How to plot average power spectra of 5 time series data ?

9 visualizaciones (últimos 30 días)
DURYODHAN PRUSTY el 21 de Abr. de 2021
Respondida: Vaibhav el 14 de Feb. de 2024
I have 5 time series data files . i.e. first.dat , second.dat, third.dat , four.dat , five.dat
I want to plot average power spectra plot of these five time series data at a time . Please suggest how to plot?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Vaibhav el 14 de Feb. de 2024
Hi Duryodhan
I understand that you would like to plot average power spectra plot for time series data simultaneously.
You can consider following the below steps:
2. Compute the power spectral density (PSD) for each time series using the "pwelch" function.
3. Average the power spectra of all the time series.
4. Plot the average power spectrum.
Here is a code snippet for your reference:
% Initialize an array to store the power spectra.
powerSpectra = [];
% Define the list of filenames.
filenames = {'first.dat', 'second.dat', 'third.dat', 'four.dat', 'five.dat'};
% Loop through each file.
for i = 1:length(filenames)
% Load the time series data from the file.
% Assuming the data is a single column of values. If it's not, you may need to adjust this.
timeseries = data(:,1);
% Compute the power spectral density (PSD) using Welch's method.
% You may need to specify the window, overlap, and NFFT parameters as needed.
[pxx, f] = pwelch(timeseries, [], [], [], 'onesided');
% Store the power spectrum in the array.
powerSpectra = [powerSpectra; pxx'];
end
% Compute the average power spectrum.
averagePowerSpectrum = mean(powerSpectra, 1);
% Plot the average power spectrum.
figure;
plot(f, 10*log10(averagePowerSpectrum));
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Average Power Spectrum');
grid on;
Hope this helps!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by