edu.mines.jtk.dsp
Class FftComplex

java.lang.Object
  extended by edu.mines.jtk.dsp.FftComplex

public class FftComplex
extends java.lang.Object

Fast Fourier transform of complex-valued arrays. The FFT length nfft equals the number of complex numbers transformed. The transform of nfft complex numbers yields nfft complex numbers. Those complex numbers are packed into arrays of floats as [real_0, imag_0, real_1, imag_1, ...]. Here, real_k and imag_k correspond to the real and imaginary parts, respectively, of the complex number with array index k.

When input and output arrays are the same array, transforms are performed in-place. For example, an input array cx[2*nfft] of nfft complex numbers may be the same as an output array cy[2*nfft] of nfft complex numbers. By "the same array", we mean that cx==cy.

Transforms may be performed for any dimension of a multi-dimensional array. For example, we may transform the 1st dimension of an input array cx[n2][2*nfft] of n2*nfft complex numbers to an output array cy[n2][2*nfft] of n2*nfft complex numbers. Or, we may transform the 2nd dimension of an input array cx[nfft][2*n1] of nfft*n1 complex numbers to an output array cy[nfft][2*n1] of nfft*n1 complex numbers. In either case, the input array cx and the output array cy may be the same array, such that the transform may be performed in-place.

Version:
2005.03.21
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
FftComplex(int nfft)
          Constructs a new FFT, with specified length.
 
Method Summary
 void complexToComplex(int sign, float[] cx, float[] cy)
          Computes a complex-to-complex fast Fourier transform.
 void complexToComplex1(int sign, int n2, float[][] cx, float[][] cy)
          Computes a complex-to-complex dimension-1 fast Fourier transform.
 void complexToComplex1(int sign, int n2, int n3, float[][][] cx, float[][][] cy)
          Computes a complex-to-complex dimension-1 fast Fourier transform.
 void complexToComplex2(int sign, int n1, float[][] cx, float[][] cy)
          Computes a complex-to-complex dimension-2 fast Fourier transform.
 void complexToComplex2(int sign, int n1, int n3, float[][][] cx, float[][][] cy)
          Computes a complex-to-complex dimension-2 fast Fourier transform.
 void complexToComplex3(int sign, int n1, int n2, float[][][] cx, float[][][] cy)
          Computes a complex-to-complex dimension-3 fast Fourier transform.
 int getNfft()
          Gets the FFT length for this FFT.
static int nfftFast(int n)
          Returns an FFT length optimized for speed.
static int nfftSmall(int n)
          Returns an FFT length optimized for memory.
 void scale(int n1, float[] cx)
          Scales n1 complex numbers in the specified array by 1/nfft.
 void scale(int n1, int n2, float[][] cx)
          Scales n1*n2 complex numbers in the specified array by 1/nfft.
 void scale(int n1, int n2, int n3, float[][][] cx)
          Scales n1*n2*n3 complex numbers in the specified array by 1/nfft.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FftComplex

public FftComplex(int nfft)
Constructs a new FFT, with specified length. Valid FFT lengths can be obtained by calling the methods nfftSmall(int) and nfftFast(int).

Parameters:
nfft - the FFT length, which must be valid.
Method Detail

nfftSmall

public static int nfftSmall(int n)
Returns an FFT length optimized for memory. The FFT length will be the smallest valid length that is not less than the specified length n.

Parameters:
n - the lower bound on FFT length.
Returns:
the FFT length.
Throws:
java.lang.IllegalArgumentException - if the specified length n exceeds the maximum length supported by this implementation. Currently, the maximum length is 720,720.

nfftFast

public static int nfftFast(int n)
Returns an FFT length optimized for speed. The FFT length will be the fastest valid length that is not less than the specified length n.

Parameters:
n - the lower bound on FFT length.
Returns:
the FFT length.
Throws:
java.lang.IllegalArgumentException - if the specified length n exceeds the maximum length supported by this implementation. Currently, the maximum length is 720,720.

getNfft

public int getNfft()
Gets the FFT length for this FFT.

Returns:
the FFT length.

complexToComplex

public void complexToComplex(int sign,
                             float[] cx,
                             float[] cy)
Computes a complex-to-complex fast Fourier transform. Transforms a 1-D input array cx[2*nfft] of nfft complex numbers to a 1-D output array cy[2*nfft] of nfft complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
cx - the input array.
cy - the output array.

complexToComplex1

public void complexToComplex1(int sign,
                              int n2,
                              float[][] cx,
                              float[][] cy)
Computes a complex-to-complex dimension-1 fast Fourier transform. Transforms a 2-D input array cx[n2][2*nfft] of n2*nfft complex numbers to a 2-D output array cy[n2][2*nfft] of n2*nfft complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
n2 - the 2nd dimension of arrays.
cx - the input array.
cy - the output array.

complexToComplex2

public void complexToComplex2(int sign,
                              int n1,
                              float[][] cx,
                              float[][] cy)
Computes a complex-to-complex dimension-2 fast Fourier transform. Transforms a 2-D input array cx[nfft][2*n1] of nfft*n1 complex numbers to a 2-D output array cy[nfft][2*n1] of nfft*n1 complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
n1 - the 1st dimension of arrays.
cx - the input array.
cy - the output array.

complexToComplex1

public void complexToComplex1(int sign,
                              int n2,
                              int n3,
                              float[][][] cx,
                              float[][][] cy)
Computes a complex-to-complex dimension-1 fast Fourier transform. Transforms a 3-D input array cx[n3][n2][2*nfft] of n3*n2*nfft complex numbers to a 3-D output array cy[n3][n2][2*nfft] of n3*n2*nfft complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
n2 - the 2nd dimension of arrays.
n3 - the 3rd dimension of arrays.
cx - the input array.
cy - the output array.

complexToComplex2

public void complexToComplex2(int sign,
                              int n1,
                              int n3,
                              float[][][] cx,
                              float[][][] cy)
Computes a complex-to-complex dimension-2 fast Fourier transform. Transforms a 3-D input array cx[n3][nfft][2*n1] of n3*nfft*n1 complex numbers to a 3-D output array cy[n3][nfft][2*n1] of n3*nfft*n1 complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
n1 - the 1st dimension of arrays.
n3 - the 3rd dimension of arrays.
cx - the input array.
cy - the output array.

complexToComplex3

public void complexToComplex3(int sign,
                              int n1,
                              int n2,
                              float[][][] cx,
                              float[][][] cy)
Computes a complex-to-complex dimension-3 fast Fourier transform. Transforms a 3-D input array cx[nfft][n2][2*n1] of nfft*n2*n1 complex numbers to a 3-D output array cy[nfft][n2][2*n1] of nfft*n2*n1 complex numbers.

Parameters:
sign - the sign (1 or -1) of the exponent used in the FFT.
n1 - the 1st dimension of arrays.
n2 - the 2nd dimension of arrays.
cx - the input array.
cy - the output array.

scale

public void scale(int n1,
                  float[] cx)
Scales n1 complex numbers in the specified array by 1/nfft. The inverse of a complex-to-complex FFT is a complex-to-complex FFT (with opposite sign) followed by this scaling.

Parameters:
n1 - 1st (only) dimension of the array cx.
cx - the input/output array[2*n1].

scale

public void scale(int n1,
                  int n2,
                  float[][] cx)
Scales n1*n2 complex numbers in the specified array by 1/nfft. The inverse of a complex-to-complex FFT is a complex-to-complex FFT (with opposite sign) followed by this scaling.

Parameters:
n1 - the 1st dimension of the array cx.
n2 - the 2nd dimension of the array cx.
cx - the input/output array[n2][2*n1].

scale

public void scale(int n1,
                  int n2,
                  int n3,
                  float[][][] cx)
Scales n1*n2*n3 complex numbers in the specified array by 1/nfft. The inverse of a complex-to-complex FFT is a complex-to-complex FFT (with opposite sign) followed by this scaling.

Parameters:
n1 - the 1st dimension of the array cx.
n2 - the 2nd dimension of the array cx.
n3 - the 3rd dimension of the array cx.
cx - the input/output array[n3][n2][2*n1].