org.opensourcephysics.numerics
Class FFT

java.lang.Object
  extended by org.opensourcephysics.numerics.FFT

public class FFT
extends java.lang.Object

FFT computes FFT's of complex, double precision data of arbitrary length n. This class has been copied from Bruce Miller's FFT package for use in the Open Source Physics Project. The original package contains code for other transformations and other data types. This class uses the Mixed Radix method; it has special methods to handle factors 2, 3, 4, 5, 6 and 7, as well as a general factor.

This algorithm appears to be faster than the Radix2 method, when both methods apply, but requires extra storage (which FFTComplex manages itself).

Complex data is represented by 2 double values in sequence: the real and imaginary parts. Thus N data points are represented by a double array dimensioned to 2*N. The physical layout in the array data, of the mathematical data d[i] is as follows:

     Re(d[i]) = data[i0 + stride*i]
     Im(d[i]) = data[i0 + stride*i+1]
 
The default offset, i0, is 0 and the stride is 2. The transformed data is returned in the original data array in wrap-around order.

Author:
Bruce R. Miller bruce.miller@nist.gov, Contribution of the National Institute of Standards and Technology,, not subject to copyright., Derived from GSL (Gnu Scientific Library), GSL's FFT Code by Brian Gough bjg@vvv.lanl.gov, Since GSL is released under, GPL,, this class must also be.

Constructor Summary
FFT()
          Constructs a complex FFT transformation.
FFT(int n)
          Constructs a complex FFT transformation for n complex data points.
 
Method Summary
 double[] backtransform(double[] data)
          Computes the back Fast Fourier Transform of data leaving the result in data.
static int[] factor(int n, int[] fromfactors)
          Return the prime factors of n.
 int getN()
          Gets the number of complex data points.
 double[] getNaturalFreq(double delta)
          Gets an array containing the frequencies in natural order.
 double[] getNaturalFreq(double xmin, double xmax)
          Gets an array containing the frequencies in natural order.
 double[] getNaturalModes()
          Gets an array containing the mode numbers in natural order.
 double[] getNaturalOmega(double delta)
          Gets an array containing the frequencies in natural order.
 double[] getNaturalOmega(double xmin, double xmax)
          Gets an array containing the frequencies in natural order.
 double getNormalization()
          Gets the normalization constant.
 double[] getWrappedFreq(double delta)
          Gets an array containing the frequencies in wrap-around order.
 double[] getWrappedFreq(double xmin, double xmax)
          Gets an array containing the frequencies in wrap-around order.
 double[] getWrappedModes()
          Gets an array containing the mode numbers in wrap-around order.
 double[] getWrappedOmega(double delta)
          Gets an array containing the angular frequencies (wavenumber) in wrap-around order.
 double[] getWrappedOmega(double xmin, double xmax)
          Gets an array containing the angular frequencies (wavenumber) in wrap-around order.
 double[] inverse(double[] data)
          Computes the (nomalized) inverse FFT of data, leaving it in place.
 void setN(int n)
          Sets the number of complex data points.
 void setNormalization(double norm)
          Sets the normalization constant.
 double[] toNaturalOrder(double[] data)
          Reorder the transformed data from most negative frequency to most positive frequency leaving the result in data.
 double[] toWrapAroundOrder(double[] data)
          Reorder the data using wraparound order.
 double[] transform(double[] data)
          Computes the Fast Fourier Transform of data leaving the result in data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FFT

public FFT(int n)
Constructs a complex FFT transformation for n complex data points.

Parameters:
n - the number of complex data points

FFT

public FFT()
Constructs a complex FFT transformation.

Method Detail

setN

public void setN(int n)
Sets the number of complex data points.

Parameters:
n - int

getN

public int getN()
Gets the number of complex data points.

Returns:
int

setNormalization

public void setNormalization(double norm)
Sets the normalization constant. The toNaturalOrder method normalizes data.

Parameters:
norm - double

getNormalization

public double getNormalization()
Gets the normalization constant. The toNaturalOrder method normalizes data.

Returns:
the normalization

transform

public double[] transform(double[] data)
Computes the Fast Fourier Transform of data leaving the result in data. The given array is returned after it has been transformed.

Parameters:
data - double[] the data to be transformed
Returns:
double[] the data after the FFT

backtransform

public double[] backtransform(double[] data)
Computes the back Fast Fourier Transform of data leaving the result in data. The given array is returned after it has been transformed.

Parameters:
data - double[] the data to be transformed
Returns:
double[] the data after the FFT

inverse

public double[] inverse(double[] data)
Computes the (nomalized) inverse FFT of data, leaving it in place. The frequency domain data must be in wrap-around order, and be stored in the following locations:
    Re(D[i]) = data[i]
    Im(D[i]) = data[i+1]
 

Parameters:
data - double[] the data to be transformed
Returns:
double[] the data after the FFT

toNaturalOrder

public double[] toNaturalOrder(double[] data)
Reorder the transformed data from most negative frequency to most positive frequency leaving the result in data. Divides by the normalization to remove the FFT scaling.

Parameters:
data - double[] the data to be transformed
Returns:
double[] the data after the FFT

toWrapAroundOrder

public double[] toWrapAroundOrder(double[] data)
Reorder the data using wraparound order. Multiplies by the normalization to reverse the toNaturalOrder method.

Parameters:
data - double[] the data to be transformed
Returns:
double[] the data after the FFT

getWrappedModes

public double[] getWrappedModes()
Gets an array containing the mode numbers in wrap-around order.

Returns:
the array of mode numbers

getWrappedOmega

public double[] getWrappedOmega(double delta)
Gets an array containing the angular frequencies (wavenumber) in wrap-around order. Samples in the orginal data are separated by delta.

Parameters:
delta -
Returns:
the array of frequencies

getWrappedOmega

public double[] getWrappedOmega(double xmin,
                                double xmax)
Gets an array containing the angular frequencies (wavenumber) in wrap-around order. The first data point is at xmin (tmin) and the last data point is at xmax (tmax).

Parameters:
xmin -
xmax -
Returns:
the array of frequencies

getWrappedFreq

public double[] getWrappedFreq(double delta)
Gets an array containing the frequencies in wrap-around order. Samples in the data are separated by delta.

Parameters:
delta -
Returns:
the array of frequencies

getWrappedFreq

public double[] getWrappedFreq(double xmin,
                               double xmax)
Gets an array containing the frequencies in wrap-around order. The first data point is at xmin (tmin) and the last data point is at xmax (tmax).

Parameters:
xmin -
xmax -
Returns:
the array of frequencies

getNaturalFreq

public double[] getNaturalFreq(double delta)
Gets an array containing the frequencies in natural order. Data are separated by delta.

Parameters:
delta -
Returns:
the array of frequencies

getNaturalFreq

public double[] getNaturalFreq(double xmin,
                               double xmax)
Gets an array containing the frequencies in natural order. The first data point is at xmin (tmin) and the last data point is at xmax (tmax).

Parameters:
xmin -
xmax -
Returns:
the array of frequencies

getNaturalOmega

public double[] getNaturalOmega(double delta)
Gets an array containing the frequencies in natural order. Data are separated by delta.

Parameters:
delta -
Returns:
the array of frequencies

getNaturalOmega

public double[] getNaturalOmega(double xmin,
                                double xmax)
Gets an array containing the frequencies in natural order. The first data point is at xmin (tmin) and the last data point is at xmax (tmax).

Parameters:
xmin -
xmax -
Returns:
the array of frequencies

getNaturalModes

public double[] getNaturalModes()
Gets an array containing the mode numbers in natural order.

Returns:
the array of mode numbers

factor

public static int[] factor(int n,
                           int[] fromfactors)
Return the prime factors of n. The method first extracts any factors in fromfactors, in order (which needn't actually be prime). Remaining factors in increasing order follow.

Parameters:
n -
fromfactors -
Returns: