Hi Verica
Below is my version of your script.
The patterns are exactly the same.
They should be since spec_anal uses the same FFT.
The Y-axis on the direct FFT plot [ ezfftf(w) ]
and the spectral plot [ specx_anal ] should be different.
The spectra returned by specx_anal has been normalized such
that the area under the spectral curve represents the
(population) variance of the series.
The script computes this area explictly.
Note: the units for the spectra returned by specx_anal
are (units_of_input_variable)^2 per frequency interval.
Questions ... let me know.
THX for answering some ncl-talk questions.
D
----
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
; input file
fi = addfile("1DfftExmpl.nc","r")
w = fi->w
nw = dimsizes(w)
printMinMax(w, True)
print("pop variance="+variance(w)*(nw-1)/nw) ; population variance
; fft
riCoef = ezfftf(w) ; real/imaginary coef (2,512)
printVarSummary(riCoef)
spcfft = riCoef(0,:)^2 + riCoef(1,:)^2 ; periodgram
;spcfft = spcfft/(2.*dimsizes(w)) ; normalization
printMinMax(spcfft, True)
; spectra
dofw = specx_anal(w,0,1,0.)
frqw = dofw_at_frq
wvarw = dofw_at_xvari
spcw = dofw_at_spcx
print(dofw)
;print(frqw+" "+spcw)
ns = dimsizes(spcw)
df = frqw(2)-frqw(1)
area = (spcw(0) + spcw(ns-1))*df*0.5 + sum(spcw(1:ns-2)*df)
print("area="+area)
exit
wks = gsn_open_wks("x11","1DfftExmpl")
res = True
res_at_gsnDraw = False
res_at_gsnFrame = False
plot1 = gsn_csm_xy(wks,(/frqw/),(/spcw/) ,res)
plot2 = gsn_csm_xy(wks,(/frqw/),(/spcfft/),res)
resP = True
resP_at_gsnMaximize = True
gsn_panel(wks,(/plot1,plot2/),(/2,1/),resP)
exit
system("eps2eps 1DfftExmpl.epsi 1DfftExmpl.eps")
system("epstopdf 1DfftExmpl.eps")
system("rm *epsi *eps")
end
On Fri, 18 May 2007, Verica Savic-Jovcic wrote:
> Hi All,
>
> I have a question regarding the 1D fft and 1D spectra, in respect to the very
> different results for the spectra constructed using ezfftf comparing to the
> spectra from specx_anal.
> Attached is the plot with the resulting curves. On the left hand side is
> specx_anal curve, and on the right hand side is the curve from ezfftf.
> In addition to very different shape of the curve and very different values on
> the Y axis, I have also found a mismatch between the variances calculated from
> the two spectra. From the description of the specx_anal, area under the curve
> should give the total variance of the initial v
> ariable. I've tried comparing the variance with the area under the curve from
> ezfftf and curve from specx_anal and I get about 5 times larger value for the
> integral under specx_anal:
> integral(spectra from ezfftf) = 0.291434
> variance(data) = 0.292072
> xvari = 0.291501
> xvaro = 0.291501
> integral(spectra from specx_anal) = 1.71725
> xvari and xvaro are the attributes of the result of specx_anal.
>
> In addition to the plot, I've also attached the code with both routines and a
> file with sample of data I used for this example.
>
> Does someone know what is the difference?
>
> Thank you,
> Verica
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun May 20 2007 - 11:30:03 MDT
This archive was generated by hypermail 2.2.0 : Mon May 21 2007 - 09:22:55 MDT