Skip to main content
  • Home
  • Documentation
  • FAQ
  • Downloads
  • Support
  • Current Release Notes
  • Ferret Users Guide
    • Users Guide Index
    • Commands Reference
    • 1. Introduction
    • 2. Data Set Basics
    • 3. Variables & Expressions
    • 4. Grids & Regions
    • 5. Animations & Gif Images
    • 6. Customizing Plots
    • 7. Handling String Data Symbols
    • 8. Working with Special Data Sets
    • 9. Computing Environment
    • 10. Converting to NetCDF
    • 11. Writing External Functions
    • Glossary
    • Appendix A: Functions
    • Appendix B: PPLUS Guide
    • Appendix C: Ferret-Specific PPLUS Enhancements
  • Previous Release Notes
  • Tutorials and Demos
    • Ferret Tour
    • DSG files: Discrete Sampling Geometries Demo
    • Ferret sorting demo
    • Fast Fourier Transforms demo
    • Empirical Orthogonal Functions demo
    • Ferret objective analysis demo
    • Ferret Palette Demo
    • Map projections
    • Ferret polygon vector demo
    • Ferret Graticules demo
    • Ferret Polytube Demo
    • Ferret Polymark Demo
    • Ferret Constant-Array demo
    • Ferret land_detail demo
    • COADS Tour
    • Levitus Tour
    • Use OPeNDAP
    • Ferret binary read demo
  • PyFerret
    • PyFerret Downloads and Install
    • What is PyFerret?
    • Why use PyFerret?
    • PyFerret for the Ferret user
    • PyFerret command syntax: quick-start notes
    • PyFerret for the Python user
    • Graphics in PyFerret ?
    • New Ferret functionality
    • PyFerret Python functions and constants
    • PyFerret Python objects and methods
    • Ferret external functions in Python
    • Ferret Fortran external functions
    • PyFerret metadata-and-data dictionaries
  • OPeNDAP
    • OPeNDAP usage in Ferret
    • Use OPeNDAP Demo
    • Test OPeNDAP

Ferret FFT demo

How to use Ferret External Functions for computing FFT's

Below is an annotated version of the script ef_fft_demo.jnl

yes? go/help ef_fft_demo
 
! Description: Demonstration of external functions for Fast Fourier Transforms:

FFTA computes amplitude spectrum

FFTP computes phase

The functions operate on the full time axis from the input grid without requiring the explicit time specification; if a subset of time is desired, specify that within the function call, see the Ferret documentation about Grid Changing Functions.

The functions set the units for the frequency axis to "1./(time units)" with the time units taken from the Ferret variable.

Example:

We will plot an FFT for the monthly_navy_winds and look for the annual cycle.

Open the datset, and compute an average over an XY region.  Plot the FFT

 

yes? USE monthly_navy_winds
yes? LET FFT_uwndtim = uwnd[x=150e:130w@ave,y=20n:40n@ave]
yes? LET/TITLE="Amplitude Spectrum"  FFT_uwndfft = ffta(FFT_uwndtim)
 
yes? plot/thick/color=blue FFT_uwndfft
 

FFTA example amplitude vs frequency

 

 

For easier interpretation, invert the frequency axis and plot the spectrum vs period; months/cycle

Get the frequency increment used in the FFT.

 

yes? LET FFT_nf = `FFT_uwndfft,return=lend`
 
yes? LET FFT_nyquist = 0.5
yes? LET FFT_freq1 = FFT_nyquist/ FFT_nf
 

Define a frequency axis.

yes? DEFINE AXIS/T=`FFT_freq1`:`FFT_nyquist`:`FFT_freq1` FAXIS
yes? LET a = T[gt=FAXIS]

Define the period from the frequency axis.

yes? LET per = 1./a

Plot period vs FFT Amplitudes showing the first 24 months where most of the energy is.

The PPL commands clean up the appearance of the plot.

yes? SET VIEW right
yes? PLOT/VS/LINE/HLIMITS=0:30:2/TITLE="Amplitude Spectrum"/SET_UP per[l=1:`FFT_nf`], FFT_uwndfft
yes? PPL XFOR (I2)
yes? PPL XLAB Period, months/cycle
yes? PPL YLAB 
yes? PPL PLOT

Compute and plot the phase using the function FFTP.

yes? LET/TITLE="FFT Phase"/UNITS="deg" FFT_uwndfftp = fftp(FFT_uwndtim)
 
yes? SET VIEW left
yes? PLOT FFT_uwndfftp
 
yes? SET VIEW right
yes? PLOT/VS/LINE/HLIMITS=0:30:2/TITLE="FFT Phase"/SET_UP  per[l=1:`FFT_nf`],FFT_uwndfftp
 
yes? PPL XFOR (I2)
yes? PPL XLAB Period, months/cycle
yes? PPL YLAB Deg
yes? PPL PLOT