Class DiscreteFourierTransform
- java.lang.Object
-
- org.ojalgo.data.transform.DiscreteFourierTransform
-
- All Implemented Interfaces:
DataTransform<Access1D<?>,MatrixStore<ComplexNumber>>
- Direct Known Subclasses:
DiscreteFourierTransform.FFT
,DiscreteFourierTransform.FullMatrix
,DiscreteFourierTransform.Single
public abstract class DiscreteFourierTransform extends java.lang.Object implements DataTransform<Access1D<?>,MatrixStore<ComplexNumber>>
The discrete Fourier transform (DFT) converts a finite sequence of equally-spaced samples of a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency. The interval at which the DTFT is sampled is the reciprocal of the duration of the input sequence. An inverse DFT is a Fourier series, using the DTFT samples as coefficients of complex sinusoids at the corresponding DTFT frequencies. The DFT is therefore said to be a frequency domain representation of the original input sequence.The fast Fourier transform (FFT) is an algorithm for computing the DFT; it achieves its high speed by storing and reusing results of computations as it progresses.
Calling the factory method newInstance(int) will return an FFT implementation if the size is a power of 2, and a full matrix implementation otherwise.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DiscreteFourierTransform.Directive
(package private) static class
DiscreteFourierTransform.FFT
(package private) static class
DiscreteFourierTransform.FullMatrix
(package private) static class
DiscreteFourierTransform.Single
-
Field Summary
Fields Modifier and Type Field Description private static int[][]
BIT_REVERSED_INDICES
(package private) static DiscreteFourierTransform.Directive
DEFAULT
(package private) static DiscreteFourierTransform.Directive
INVERSE
private int
mySize
private static ComplexNumber[][]
UNIT_ROOTS
-
Constructor Summary
Constructors Constructor Description DiscreteFourierTransform(int size)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) static void
generate(Mutate2D matrix)
static int[]
getBitReversedIndices(int size)
static Access1D<ComplexNumber>
getUnitRoots(int size)
void
inverse(Access1D<?> input, Mutate2D.ModifiableReceiver<ComplexNumber> output)
MatrixStore<ComplexNumber>
inverse(Access1D<ComplexNumber> input)
static MatrixStore<ComplexNumber>
inverse2D(MatrixStore<?> input)
(package private) static int[]
lookupIndices(int size)
(package private) static ComplexNumber[]
lookupRoots(int size)
private static ComplexNumber[]
lookupRootsExponent(int exponent)
static DiscreteFourierTransform
newInstance(int size)
Will return a functioning instance for any size, but if you want fast transformation (FFT) it needs to be a power of 2.static <M extends Mutate2D>
MnewVandermonde(Factory2D<M> factory, int size)
static MatrixC128
newVandermondeMatrix(int size)
private static void
reverseBits(int[] indices)
Function to perform bit-reversal on indicesstatic MatrixStore<ComplexNumber>
sample(java.util.function.DoubleUnaryOperator function, PrimitiveFunction.SampleDomain sampleDomain)
Sample, and transform, a function using the Discrete Fourier Transform.static MatrixStore<ComplexNumber>
sample(PeriodicFunction function, int nbSamples)
static <N extends java.lang.Comparable<N>>
MatrixStore<N>shift(MatrixStore<N> matrix)
There is a symmetry in the DFT matrix.(package private) int
size()
(package private) static int
toPowerOf2Exponent(int size)
MatrixStore<ComplexNumber>
transform(double... input)
MatrixStore<ComplexNumber>
transform(Access1D<?> input)
abstract void
transform(Access1D<?> input, DiscreteFourierTransform.Directive directive, Mutate2D.ModifiableReceiver<ComplexNumber> output)
void
transform(Access1D<?> input, Mutate2D.ModifiableReceiver<ComplexNumber> output)
static MatrixStore<ComplexNumber>
transform2D(MatrixStore<?> input)
Perform a 2D Discrete Fourier Transform on the input matrix.static void
transform2D(MatrixStore<?> input, DiscreteFourierTransform.Directive directive, TransformableRegion<ComplexNumber> output)
-
-
-
Field Detail
-
BIT_REVERSED_INDICES
private static final int[][] BIT_REVERSED_INDICES
-
UNIT_ROOTS
private static final ComplexNumber[][] UNIT_ROOTS
-
DEFAULT
static final DiscreteFourierTransform.Directive DEFAULT
-
INVERSE
static final DiscreteFourierTransform.Directive INVERSE
-
mySize
private final int mySize
-
-
Method Detail
-
getBitReversedIndices
public static int[] getBitReversedIndices(int size)
-
getUnitRoots
public static Access1D<ComplexNumber> getUnitRoots(int size)
-
inverse2D
public static MatrixStore<ComplexNumber> inverse2D(MatrixStore<?> input)
-
newInstance
public static DiscreteFourierTransform newInstance(int size)
Will return a functioning instance for any size, but if you want fast transformation (FFT) it needs to be a power of 2.
-
newVandermondeMatrix
public static MatrixC128 newVandermondeMatrix(int size)
-
sample
public static MatrixStore<ComplexNumber> sample(java.util.function.DoubleUnaryOperator function, PrimitiveFunction.SampleDomain sampleDomain)
Sample, and transform, a function using the Discrete Fourier Transform.
-
sample
public static MatrixStore<ComplexNumber> sample(PeriodicFunction function, int nbSamples)
-
shift
public static <N extends java.lang.Comparable<N>> MatrixStore<N> shift(MatrixStore<N> matrix)
There is a symmetry in the DFT matrix. The first half of the rows (and columns) are the complex conjugates of the second half. Furthermore, the first half correspond to positive frequencies, and the second half to negative frequencies.Re-arranging the elements of a matrix, shifting the first and second halves of the rows (and columns), puts the zero-frequency term in the middle, and the conjugate pairs at equal distances from the centre.
This is useful when displaying the 2D DFT matrix as an image.
To revert the shift, simply call shift(MatrixStore) again. However, this will not work correctly if there's an odd number of rows or columns. In that case the second call will not correctly revert the position of the zero-frequency term – it will end up in the last row/column instead of in the first.
-
transform2D
public static MatrixStore<ComplexNumber> transform2D(MatrixStore<?> input)
Perform a 2D Discrete Fourier Transform on the input matrix. The output will be a complex matrix of the same size.
-
transform2D
public static void transform2D(MatrixStore<?> input, DiscreteFourierTransform.Directive directive, TransformableRegion<ComplexNumber> output)
-
lookupRootsExponent
private static ComplexNumber[] lookupRootsExponent(int exponent)
-
reverseBits
private static void reverseBits(int[] indices)
Function to perform bit-reversal on indices
-
generate
static void generate(Mutate2D matrix)
-
lookupIndices
static int[] lookupIndices(int size)
-
lookupRoots
static ComplexNumber[] lookupRoots(int size)
-
toPowerOf2Exponent
static int toPowerOf2Exponent(int size)
-
inverse
public final void inverse(Access1D<?> input, Mutate2D.ModifiableReceiver<ComplexNumber> output)
-
inverse
public final MatrixStore<ComplexNumber> inverse(Access1D<ComplexNumber> input)
-
transform
public final MatrixStore<ComplexNumber> transform(Access1D<?> input)
- Specified by:
transform
in interfaceDataTransform<Access1D<?>,MatrixStore<ComplexNumber>>
-
transform
public abstract void transform(Access1D<?> input, DiscreteFourierTransform.Directive directive, Mutate2D.ModifiableReceiver<ComplexNumber> output)
-
transform
public final void transform(Access1D<?> input, Mutate2D.ModifiableReceiver<ComplexNumber> output)
-
transform
public MatrixStore<ComplexNumber> transform(double... input)
-
size
int size()
-
-