Top Description Inners Fields Constructors Methods
org.apache.commons.math3.transform

public Class FastFourierTransformer

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.lang.reflect.Array, org.apache.commons.math3.analysis.FunctionUtils, .UnivariateFunction, org.apache.commons.math3.complex.Complex, org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalArgumentException, .MathIllegalStateException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.ArithmeticUtils, .FastMath, .MathArrays

Implements the Fast Fourier Transform for transformation of one-dimensional real or complex data sets. For reference, see Applied Numerical Linear Algebra, ISBN 0898713897, chapter 6.

There are several variants of the discrete Fourier transform, with various normalization conventions, which are specified by the parameter DftNormalization.

The current implementation of the discrete Fourier transform as a fast Fourier transform requires the length of the data set to be a power of 2. This greatly simplifies and speeds up the code. Users can pad the data with zeros to meet this requirement. There are other flavors of FFT, for reference, see S. Winograd, On computing the discrete Fourier transform, Mathematics of Computation, 32 (1978), 175 - 199.

Since
1.2
See Also
DftNormalization

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
FastFourierTransformer.MultiDimensionalComplexMatrix

Deprecated see MATH-736
Complex matrix implementation.

Field Summary

Modifier and TypeField and Description
private final DftNormalization
normalization

The type of DFT to be performed.

pack-priv static final long
serialVersionUID

Serializable version identifier.

private static final double[]
W_SUB_N_I

W_SUB_N_I[i] is the imaginary part of exp(- 2 * i * pi / n): W_SUB_N_I[i] = -sin(2 * pi/ n), where n = 2^i.

private static final double[]
W_SUB_N_R

W_SUB_N_R[i] is the real part of exp(- 2 * i * pi / n): W_SUB_N_R[i] = cos(2 * pi/ n), where n = 2^i.

Constructor Summary

AccessConstructor and Description
public
FastFourierTransformer(final DftNormalization
the type of normalization to be applied to the transformed data
normalization
)

Creates a new instance of this class, with various normalization conventions.

Method Summary

Modifier and TypeMethod and Description
private static void
bitReversalShuffle2(double[]
the first array to be shuffled
a
,
double[]
the second array to be shuffled
b
)

Performs identical index bit reversal shuffles on two arrays of identical size.

public Object

Returns:

transform of mdca as a Multi-Dimensional Complex Array, i.e. Complex[][][][]
mdfft
(Object
Multi-Dimensional Complex Array, i.e. Complex[][][][]
mdca
,
TransformType
the type of transform (forward, inverse) to be performed
type
)
Deprecated see MATH-736

Performs a multi-dimensional Fourier transform on a given array.

private void
mdfft(FastFourierTransformer.MultiDimensionalComplexMatrix
input matrix
mdcm
,
TransformType
the type of transform (forward, inverse) to be performed
type
,
int
index of the dimension to process
d
,
int[]
recursion subvector
subVector
)
Deprecated see MATH-736

Performs one dimension of a multi-dimensional Fourier transform.

private static void
normalizeTransformedData(final double[][]
the unscaled transformed data
dataRI
,
final DftNormalization
the normalization to be applied
normalization
,
final TransformType
the type of transform (forward, inverse) which resulted in the specified data
type
)

Applies the proper normalization to the specified transformed data.

public Complex[]

Returns:

the complex transformed array
transform
(final double[]
the real data array to be transformed
f
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Returns the (forward, inverse) transform of the specified real data set.

public Complex[]

Returns:

the complex transformed array
transform
(final UnivariateFunction
the function to be sampled and transformed
f
,
final double
the (inclusive) lower bound for the interval
min
,
final double
the (exclusive) upper bound for the interval
max
,
final int
the number of sample points
n
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.

public Complex[]

Returns:

the complex transformed array
transform
(final Complex[]
the complex data array to be transformed
f
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Returns the (forward, inverse) transform of the specified complex data set.

public static void
transformInPlace(final double[][]
the two dimensional array of real and imaginary parts of the data
dataRI
,
final DftNormalization
the normalization to be applied to the transformed data
normalization
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Computes the standard transform of the specified complex data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

normalizationback to summary
private final DftNormalization normalization

The type of DFT to be performed.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Serializable version identifier.

W_SUB_N_Iback to summary
private static final double[] W_SUB_N_I

W_SUB_N_I[i] is the imaginary part of exp(- 2 * i * pi / n): W_SUB_N_I[i] = -sin(2 * pi/ n), where n = 2^i.

W_SUB_N_Rback to summary
private static final double[] W_SUB_N_R

W_SUB_N_R[i] is the real part of exp(- 2 * i * pi / n): W_SUB_N_R[i] = cos(2 * pi/ n), where n = 2^i.

Constructor Detail

FastFourierTransformerback to summary
public FastFourierTransformer(final DftNormalization normalization)

Creates a new instance of this class, with various normalization conventions.

Parameters
normalization:DftNormalization

the type of normalization to be applied to the transformed data

Method Detail

bitReversalShuffle2back to summary
private static void bitReversalShuffle2(double[] a, double[] b)

Performs identical index bit reversal shuffles on two arrays of identical size. Each element in the array is swapped with another element based on the bit-reversal of the index. For example, in an array with length 16, item at binary index 0011 (decimal 3) would be swapped with the item at binary index 1100 (decimal 12).

Parameters
a:double[]

the first array to be shuffled

b:double[]

the second array to be shuffled

mdfftback to summary
public Object mdfft(Object mdca, TransformType type)

Deprecated

see MATH-736

Performs a multi-dimensional Fourier transform on a given array. Use transform(Complex[], TransformType) in a row-column implementation in any number of dimensions with O(N×log(N)) complexity with N = n1 × n2 ×n3 × ... × nd, where nk is the number of elements in dimension k, and d is the total number of dimensions.

Parameters
mdca:Object

Multi-Dimensional Complex Array, i.e. Complex[][][][]

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:Object

transform of mdca as a Multi-Dimensional Complex Array, i.e. Complex[][][][]

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if any dimension is not a power of two
mdfftback to summary
private void mdfft(FastFourierTransformer.MultiDimensionalComplexMatrix mdcm, TransformType type, int d, int[] subVector)

Deprecated

see MATH-736

Performs one dimension of a multi-dimensional Fourier transform.

Parameters
mdcm:FastFourierTransformer.MultiDimensionalComplexMatrix

input matrix

type:TransformType

the type of transform (forward, inverse) to be performed

d:int

index of the dimension to process

subVector:int[]

recursion subvector

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if any dimension is not a power of two
normalizeTransformedDataback to summary
private static void normalizeTransformedData(final double[][] dataRI, final DftNormalization normalization, final TransformType type)

Applies the proper normalization to the specified transformed data.

Parameters
dataRI:double[][]

the unscaled transformed data

normalization:DftNormalization

the normalization to be applied

type:TransformType

the type of transform (forward, inverse) which resulted in the specified data

transformback to summary
public Complex[] transform(final double[] f, final TransformType type)

Returns the (forward, inverse) transform of the specified real data set.

Parameters
f:double[]

the real data array to be transformed

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:Complex[]

the complex transformed array

Exceptions
MathIllegalArgumentException:
if the length of the data array is not a power of two
transformback to summary
public Complex[] transform(final UnivariateFunction f, final double min, final double max, final int n, final TransformType type)

Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.

Parameters
f:UnivariateFunction

the function to be sampled and transformed

min:double

the (inclusive) lower bound for the interval

max:double

the (exclusive) upper bound for the interval

n:int

the number of sample points

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:Complex[]

the complex transformed array

Exceptions
NumberIsTooLargeException:
if the lower bound is greater than, or equal to the upper bound
NotStrictlyPositiveException:
if the number of sample points n is negative
MathIllegalArgumentException:
if the number of sample points n is not a power of two
transformback to summary
public Complex[] transform(final Complex[] f, final TransformType type)

Returns the (forward, inverse) transform of the specified complex data set.

Parameters
f:Complex[]

the complex data array to be transformed

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:Complex[]

the complex transformed array

Exceptions
MathIllegalArgumentException:
if the length of the data array is not a power of two
transformInPlaceback to summary
public static void transformInPlace(final double[][] dataRI, final DftNormalization normalization, final TransformType type)

Computes the standard transform of the specified complex data. The computation is done in place. The input data is laid out as follows

  • dataRI[0][i] is the real part of the i-th data point,
  • dataRI[1][i] is the imaginary part of the i-th data point.
Parameters
dataRI:double[][]

the two dimensional array of real and imaginary parts of the data

normalization:DftNormalization

the normalization to be applied to the transformed data

type:TransformType

the type of transform (forward, inverse) to be performed

Exceptions
DimensionMismatchException:
if the number of rows of the specified array is not two, or the array is not rectangular
MathIllegalArgumentException:
if the number of data points is not a power of two
org.apache.commons.math3.transform back to summary

private Class FastFourierTransformer.MultiDimensionalComplexMatrix

extends Object
implements Cloneable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.transform.FastFourierTransformer.MultiDimensionalComplexMatrix
All Implemented Interfaces
java.lang.Cloneable
Annotations
@Deprecated

Deprecated

see MATH-736

Complex matrix implementation. Not designed for synchronized access may eventually be replaced by jsr-83 of the java community process http://jcp.org/en/jsr/detail?id=83 may require additional exception throws for other basic requirements.

Field Summary

Modifier and TypeField and Description
protected int[]
dimensionSize

Size in all dimensions.

protected Object

Constructor Summary

AccessConstructor and Description
pack-priv
MultiDimensionalComplexMatrix(Object
array containing the matrix elements
multiDimensionalComplexArray
)

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

private void
clone(FastFourierTransformer.MultiDimensionalComplexMatrix
array where to copy data
mdcm
)
Deprecated as a consequence of FastFourierTransformer.MultiDimensionalComplexMatrix being deprecated.

Copy contents of current array into mdcm.

public Complex

Returns:

matrix element
get
(int...
indices of the element
vector
)

Get a matrix element.

public Object

Returns:

underlying storage array
getArray
()

Get the underlying storage array.

public int[]

Returns:

size in all dimensions
getDimensionSizes
()

Get the size in all dimensions.

public Complex

Returns:

the previous value
set
(Complex
magnitude of the element
magnitude
,
int...
indices of the element
vector
)

Set a matrix element.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dimensionSizeback to summary
protected int[] dimensionSize

Size in all dimensions.

multiDimensionalComplexArrayback to summary
protected Object multiDimensionalComplexArray

Storage array.

Constructor Detail

MultiDimensionalComplexMatrixback to summary
pack-priv MultiDimensionalComplexMatrix(Object multiDimensionalComplexArray)

Simple constructor.

Parameters
multiDimensionalComplexArray:Object

array containing the matrix elements

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
cloneback to summary
private void clone(FastFourierTransformer.MultiDimensionalComplexMatrix mdcm)

Deprecated

as a consequence of FastFourierTransformer.MultiDimensionalComplexMatrix being deprecated. See corresponding docs for further information.

Copy contents of current array into mdcm.

Parameters
mdcm:FastFourierTransformer.MultiDimensionalComplexMatrix

array where to copy data

getback to summary
public Complex get(int... vector) throws DimensionMismatchException

Get a matrix element.

Parameters
vector:int[]

indices of the element

Returns:Complex

matrix element

Exceptions
DimensionMismatchException:
if dimensions do not match
getArrayback to summary
public Object getArray()

Get the underlying storage array.

Returns:Object

underlying storage array

getDimensionSizesback to summary
public int[] getDimensionSizes()

Get the size in all dimensions.

Returns:int[]

size in all dimensions

setback to summary
public Complex set(Complex magnitude, int... vector) throws DimensionMismatchException

Set a matrix element.

Parameters
magnitude:Complex

magnitude of the element

vector:int[]

indices of the element

Returns:Complex

the previous value

Exceptions
DimensionMismatchException:
if dimensions do not match