Graph error with Periodogram, incorrect plotting
Show older comments
I have this portion of code, my goal is to have my data go from 1200 x 1 to 300 by 4 and then reshape back into a []x 1 matrix. my problem is when i change the matrix to 300 x 4 then take the periodogram...since my Fs is 5, w for each column is now 0 to 2.5 hz which is fine for a 300 x4 matrix. when i make everything back to [] x 1 matrix, since size of w is 300 x4 it keeps repeating 0 to 2.5 4 times. i want the value for w to be continuous since my FS is 5 for the whole data. the periodogram give me four diff graphs instead of one. here's my code. Help
New_Pxx=[];
New_w=[];
test=Downsampled_data(:);
New_array=reshape(test,(length(test)/length(timerArray)),length(timerArray));
for i=1:4
Fs=5;
[Pxx w]=periodogram(test,[],'onesided',[],Fs);
New_Pxx=[New_Pxx;Pxx];
New_w=[New_w;w]
end
loglog(New_w,New_Pxx);
10 Comments
dpb
on 20 May 2014
Why did you do the reshape(test,4,[]) operation?
Internally, periodogram converts a 2D array X into a single vector
x=X(:);
and does the work over it. I didn't delve into the rest of the guts but it isn't documented to operate on an array unless it's a cell array of 2-elements so it's not clear just what is done on output.
What're you really trying to accomplish rather than asking about some syntax? Do you think you get an average or somesuch by doing this?
Mini Me
on 20 May 2014
dpb
on 20 May 2014
...inside the fo loop, it does the periodogram for each column...
test=Downsampled_data(:);
..
for i=1:4
[Pxx w]=periodogram(test,[],'onesided',[],Fs);
No, actually, on reading the code more closely, it does the periodogram over and over on the same data and you just concatenate those results. The reshape results aren't used in the loop. Unless, of course, the code posted isn't actually the code under discussion.
That's still then same vector four times as test is a column vector of size(numel(test),1). It would, in fact, error on the second pass thru the loop on an indexing error.
Slow down, write a script or enter some commands at the command line interactively that actually work to demonstrate precisely what you're trying to do.
Then explain what it is that you think it means to do so and what's different than what you are getting.
ADDENDUM:
OK, on reflection with the first posting and the follow-on, maybe I'm able to fill in the blanks...
Fs=5;
test=reshape(Downsampled_data(:),length(test)/length(timerArray),[]);
for i=1:4
[Pxx w]=periodogram(test(:,i),[],'onesided',[],Fs);
New_Pxx=[New_Pxx;Pxx];
New_w=[New_w;w];
end
That will at least run; it'll give four separate periodograms over the sections of the whole time series that will be similar or not depending on the stationarity of the signal with time.
Now I still don't understand what you expect the frequency associated with those to be other than that from 0 to half-Nyquist for each--that's what you've computed.
Mini Me
on 21 May 2014
And now we're back to the question I posed above -- just what do you expect New_w to be other than [0 Nyquist/2] for the four (N) separate periodograms you've computed from subsections of the overall time series?
You talked about plotting and being "continuous" -- if I again draw an inference that what you want is a plot from left to right of all values instead of overlaying, you can artificially create that by adding
(n-1)*Nyquist/2
for each of the sections above base to string 'em out horizontally. But, of course, it's only a visualization trick; has nothing to do w/ reality.
Mini Me
on 21 May 2014
dpb
on 21 May 2014
And the problem fix was????
Answers (0)
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!