[R] Recuperate Spectrum() amplitude

Marie Guillot marie.guillot at bordeaux.inra.fr
Tue Feb 8 18:34:15 CET 2011


Dear list,
I apologies first for my English, hope you will understand well my question.
I am working on 1/2 hour piezometric data, time unit is second. They 
present daily oscillation when using the spectrum() function. What I am 
really interested in, is to find the amplitude corresponding to this 
oscillation.
I  work with a college using Matlab, and although we apply the same 
methodology, our results differs : we find the same frequencies, but not 
the same amplitudes.

I put the code I use here to understand if the difference comes from the 
way that fft function are encoded int both software or from my own 
misunderstanding of the function.
I am importing data as zoo, and verifying that they are regular spaced, 
and after, I simply use the non smoothed spectrum() function :
SP<-spectrum(as.ts(Piezo))
To recuperate the amplitude I calculate the square root of the density, 
divided by the number of observations at the the frequency I am 
interested  in (1/86400=frequency of one cycle per day) :
sqrt(SP$spec[which(SP$freq==1/86400)])/length(Piezo)

Does anyone of you use both Matlab and R and have already find 
differences in results ? Or does my trouble comes from my own methodology ?
Thank you very much in advance for your feedback,

-- 
---------------------------------------------------------------------------
Marie Guillot
PhD Student
INRA - UR1263
Centre de Recherche de Bordeaux
Unité de Recherche EPHYSE



More information about the R-help mailing list