Graph error with Periodogram, incorrect plotting

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 comentarios

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
Mini Me el 20 de Mayo de 2014
from the periodogram Pxx will be 513 and w will be 513 as well if i pick the frequency bin to be 1024. now, inside the fo loop, it does the periodogram for each column and append them into a new matrix. New_pxx values are good. but New_w values are 0 to 2.5 appending four times in the new matrix..causing my loglog plot to be wrong. Meaning instead of ploting(w,Pxx) once...it gives me 4 plots of 513 data points....
...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.
Mini Me
Mini Me el 20 de Mayo de 2014
Editada: Mini Me el 21 de Mayo de 2014
my mistake...the one im using is different.
test=Downsampled_data(:);
for i=1:4
DC_rem=test(:,i)-mean(test(:,i))
[Pxx w]=periodogram(Dc_rem,[],'onesided',[],Fs);
dpb
dpb el 21 de Mayo de 2014
Editada: dpb el 21 de Mayo de 2014
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
Mini Me el 21 de Mayo de 2014
I edited the code above i'm the one who made the mistake..
Mini Me
Mini Me el 21 de Mayo de 2014
Editada: Mini Me el 21 de Mayo de 2014
Here's the code. filedir=(dirpath) then i read the data, downsample it and do the rest below: timerArray=vertcat(timerArray, (filedir(cnt).datenum));
New_Pxx=[];
New_w=[];
test=Downsampled_data(:,s);
New_array=reshape(test,(length(test)/length(timerArray)),length(timerArray));
New_Pxx=[];
New_w=[];
for i=1:size(New_array,2)
t=1/Fs; % sampling period(interval)
M=Fs/size(New_array,2)*i;
DC_rem=New_array(:,i)-mean(New_array(:,i));
[Pxx1 w1]=periodogram(DC_rem,[],'onesided',[],Fs);
timepower=sum(DC_rem.^2)/length(DC_rem);
freqpower=sum(Pxx1);
Pxx1=Pxx1*timepower/freqpower;
Pxx1=sqrt(Pxx1);
New_Pxx=[New_Pxx;Pxx1];
New_w=[New_w;w1]
size(New_w)
size(New_Pxx)
% hold off
end
loglog(New_w,New_Pxx);
axis tight
dpb
dpb el 21 de Mayo de 2014
Editada: dpb el 21 de Mayo de 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
Mini Me el 21 de Mayo de 2014
never mind i fix the problem....Thank you for responding...
dpb
dpb el 21 de Mayo de 2014
And the problem fix was????

Iniciar sesión para comentar.

Respuestas (0)

Productos

Preguntada:

el 20 de Mayo de 2014

Comentada:

dpb
el 21 de Mayo de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by