[Thread Prev][Thread Next][Index]

Re: How to do the Fourier Analysis in ferret



HiYogesh,
Ferret has a set of FFT functions to compute the FFT amplitude and phase, the
real and imaginary parts of the FFT, and the the inverse from the real and imaginary
parts. I will write more about these below.

To read your data into Ferret, I would suggest you use the "file/format=delimited"
syntax. If your data file is called co2.dat, then:

yes? FILE/FORMAT=delimited/DELIM=" "/VAR="v1,v2,v3"/TYPE="date,numeric,numeric" co2.dat

Are your data equally spaced in time? The FFT functions require this to be
the case. The example file you list has only the year; is that correct? You will
need more information to define a time axis for your data, and assign the data
to that axis. The FILE command above puts the data onto an abstract X axis,
so we need to use RESHAPE to put it onto the time axis.
You might do something like this:

yes? DEFINE AXIS/T=1-jan-1993:31-dec-2002:1/UNITS=days tax
yes? LET dummy = t[gt=tax]
yes? LET co2_obs = RESHAPE(v2,dummy)
yes? LET c02_model = RESHAPE(v3,dummy)

If your data file contains more information about time, you can create a time
axis using the ideas in the FAQ, "Creating a time axis from time variables" at
http://www.ferret.noaa.gov/Ferret/FAQ/axes_and_data/time_axis_from_variables.html


To learn about the functions to compute the FFT of a time series in Ferret;
please see FFT in the index to the Users Guide,
http://www.ferret.noaa.gov/Ferret/Documentation/Users_Guide/current/fer_html.htm

There is a demonstration script which may be of help to you:
yes? go ef_fft_demo.jnl

However, this script doesn't currently contain examples of the functions
FFT_RE, FFT_IM, and FFT_INVERSE, which are probably what you will
want to use. Here is a script with some examples of these functions. We will
add this information to the ef_fft_demo script before the next Ferret release.

! Script to demonstrate the FFT_RE, FFT_IM, and FFT_INVERSE functions:
! Compute FFT of a time series; then invert to recover the time series.

! Define a time series function.

DEFINE AXIS/t=1:366:1 dayt
LET tpts = t[GT=dayt]

LET fcn1 = SIN(0.5*tpts - 6.) /2.
LET fcn2 = COS(0.3*tpts)

LET sample_function = fcn1 - fcn2 + 0.2* RANDU(tpts)

! Compute the equivalent of FFTA(sample_function)

LET sample_re = FFT_RE(sample_function)
LET sample_im = FFT_IM(sample_function)
LET amp_fft = (sample_re* sample_re + sample_im* sample_im)^0.5

! Compare with the computation in fcn FFTA

SET WINDOW/SIZ=0.4
SET VIEW upper
PLOT FFTA(sample_function)
SET VIEW lower
PLOT amp_fft

! Now overlay amplitude spectrum computed by FFTA
PAUSE
PLOT/OVER FFTA(sample_function)

! Next compare the phase function
PAUSE
! Compute the equivalent of FFTP(sample_function)

LET sample_re = FFT_RE(sample_function)
LET sample_im = FFT_IM(sample_function)

LET rad = 180.0/ (4.*ATAN(1.))
LET phas = rad* ATAN2(-1.*sample_im, sample_re) ! the computation done in FFTP(v)

! Compare with the computation of FFTP

SET WINDOW/SIZ=0.4
SET VIEW upper
PLOT FFTP(sample_function)
SET VIEW lower
PLOT phas

! Overlay FFT phase computed by FFTP
PAUSE
PLOT/OVER FFTP(sample_function)

! Next invert the FFT and compare with original time series
PAUSE

LET invert_ts = FFT_INVERSE(sample_re, sample_im)
SET VIEW upper
PLOT/TITLE="Original SAMPLE_FUNCTION" sample_function

SET VIEW lower
PLOT invert_ts
Overlay the original time series function
PAUSE
PLOT/OVER sample_function




Yogesh K. Tiwari wrote:

Hello Ferret Users,

How to do the Harmonic Analysis inside the ferret.

I have ASCII data looks like :-

!Yr co2_obs co2_model

1993 355.10 360.23
1993 355.49 360.61
1993 355.87 360.89
1993 357.75 361.27
1993 358.20 362.12
1993 358.38 361.96
1993 357.48 361.46
......................
....................
.........
......

The data period is till 2002,


How to fit the co2 values to get the components of Fourier transform and then how to do the inverse fourier transform.

Finally I want to compute the residuals by subtracting the original
co2 ( as above in table) from the values got from the inverse
transform.

First time I am trying to use the ferret in this type of statistical analysis, so please help me in bit detail, if possible.

Thanks in advane for your help.

Regards,
Yogesh



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement