Plotting data in 30 second increments within a for loop?

조회 수: 17 (최근 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 CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by