Class FastFourierTransform
- java.lang.Object
-
- org.apache.commons.math4.transform.FastFourierTransform
-
- All Implemented Interfaces:
Function<org.apache.commons.numbers.complex.Complex[],org.apache.commons.numbers.complex.Complex[]>
,UnaryOperator<org.apache.commons.numbers.complex.Complex[]>
,ComplexTransform
public class FastFourierTransform extends Object implements ComplexTransform
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
FastFourierTransform.Norm
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FastFourierTransform.Norm
Normalization types.
-
Constructor Summary
Constructors Constructor Description FastFourierTransform(FastFourierTransform.Norm normalization)
FastFourierTransform(FastFourierTransform.Norm normalization, boolean inverse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.commons.numbers.complex.Complex[]
apply(double[] f)
Returns the transform of the specified data set.org.apache.commons.numbers.complex.Complex[]
apply(DoubleUnaryOperator f, double min, double max, int n)
Returns the transform of the specified function.org.apache.commons.numbers.complex.Complex[]
apply(org.apache.commons.numbers.complex.Complex[] f)
Returns the transform of the specified data set.void
transformInPlace(double[][] dataRI)
Computes the standard transform of the data.
-
-
-
Constructor Detail
-
FastFourierTransform
public FastFourierTransform(FastFourierTransform.Norm normalization, boolean inverse)
- Parameters:
normalization
- Normalization to be applied to the transformed data.inverse
- Whether to perform the inverse transform.
-
FastFourierTransform
public FastFourierTransform(FastFourierTransform.Norm normalization)
- Parameters:
normalization
- Normalization to be applied to the transformed data.
-
-
Method Detail
-
transformInPlace
public void transformInPlace(double[][] dataRI)
Computes the standard transform of the data. Computation is done in place. Assumed layout of the input data:dataRI[0][i]
: Real part of thei
-th data point,dataRI[1][i]
: Imaginary part of thei
-th data point.
- Parameters:
dataRI
- Two-dimensional array of real and imaginary parts of the data.- Throws:
IllegalArgumentException
- if the number of data points is not a power of two, if the number of rows of the specified array is not two, or the array is not rectangular.
-
apply
public org.apache.commons.numbers.complex.Complex[] apply(double[] f)
Returns the transform of the specified data set.- Specified by:
apply
in interfaceComplexTransform
- Parameters:
f
- the data array to be transformed (signal).- Returns:
- the transformed array (spectrum).
- Throws:
IllegalArgumentException
- if the length of the data array is not a power of two.
-
apply
public org.apache.commons.numbers.complex.Complex[] apply(DoubleUnaryOperator f, double min, double max, int n)
Returns the transform of the specified function.- Specified by:
apply
in interfaceComplexTransform
- Parameters:
f
- Function to be sampled and transformed.min
- Lower bound (inclusive) of the interval.max
- Upper bound (exclusive) of the interval.n
- Number of sample points.- Returns:
- the result.
- Throws:
IllegalArgumentException
- if the number of sample pointsn
is not a power of two, if the lower bound is greater than, or equal to the upper bound, if the number of sample pointsn
is negative
-
apply
public org.apache.commons.numbers.complex.Complex[] apply(org.apache.commons.numbers.complex.Complex[] f)
Returns the transform of the specified data set.- Specified by:
apply
in interfaceComplexTransform
- Specified by:
apply
in interfaceFunction<org.apache.commons.numbers.complex.Complex[],org.apache.commons.numbers.complex.Complex[]>
- Parameters:
f
- the data array to be transformed (signal).- Returns:
- the transformed array (spectrum).
- Throws:
IllegalArgumentException
- if the length of the data array is not a power of two.
-
-