Plotting data in 30 second increments within a for loop?
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!