Plotting data in 30 second increments within a for loop?

2 ビュー (過去 30 日間)
Maria Y
Maria Y 2019 年 2 月 11 日
コメント済み: Maria Y 2019 年 2 月 12 日
Hello,
I have a set of data which I separated into 10 different subplots, each showing 30 seconds of data up to 300 seconds:
nrow = 5;
ncol = 2;
nplots = nrow * ncol;
sec30 = 0:30:300;
for i = 1: nplots
subplot(nrow, ncol, i)
idx = timex >= sec30(i) & timex <=sec30(i+1);
plot(timex(idx), signal(idx))
end
Separately, I generated the Power Spectral Density (PSD) of my data using the pwelch function like so:
Fs=794; % samples per unit time, in this case
WINDOW = 1024; % segment length and Hamming window length for welch's method (use power of 2)
NOVERLAP = 512; % # signal samples that are common to adjacent segments for welch's method (half the window value)
NFFT = 1024; % Same # as window
nsignal = size(signal,1);
%run pwelch to figure out output length
[psdecog,freq]=pwelch(signal(1,:),WINDOW,NOVERLAP,NFFT,Fs);
psd_length = length(psdecog);
%initialize psdall
psdall = zeros(psd_length,nsignal);
for i = 1:nsignal
psdall(:,i) = pwelch(signal(i,:),WINDOW,NOVERLAP,NFFT,Fs);
end
and then plotted that:
figure;
nrow = 1;
ncol = 2;
nplots = nrow * ncol;
plotNames={'1';'2'}
for i = 1: nplots
subplot(nrow, ncol, i)
plot(freq,log(psdall(:,i)));
title(sprintf('Signal %s', plotNames{i}))
x_title=sprintf('Frequency',i);
xlabel(x_title)
y_title=sprintf('PSD',i);
ylabel(y_title)
end
What I would like to do now, is generate/plot my PSD data for each of those 30 second incremements - so basically combining the functions of my first and last plots.
Does anyone know how I might go about doing this? Thanks in advanced for any advice and let me know if I need to clarify anything.
  2 件のコメント
KSSV
KSSV 2019 年 2 月 12 日
Read about reshape. You can reshape your data with this function.
Maria Y
Maria Y 2019 年 2 月 12 日
I'll look into it, thank you!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by