public class Fft
extends java.lang.Object
FftComplex
and FftReal
.
For example, the user has less control over the sampling of frequency.
However, for many applications this class may be simpler to use.
For example, the following program shows how to use this class to filter a real-valued sequence in the frequency domain.
Fft fft = new Fft(nx); // nx = number of samples of f(x)
Sampling sk = fft.getFrequencySampling1();
int nk = sk.getCount(); // number of frequencies sampled
float[] f = ... // nx real samples of input f(x)
float[] g = fft.applyForward(f); // nk complex samples of g(k)
for (int kk=0,kr=0,ki=kr+1; kk<nk; ++kk,kr+=2,ki+=2) {
double k = sk.getValue(kk); // frequency k in cycles/sample
// modify g[kr], the real part of g(k)
// modify g[ki], the imag part of g(k)
}
float[] h = fft.applyInverse(g); // nx real samples of output h(x)
This example is almost as simple for multi-dimensional transforms.
A forward transform computes an output array of complex values g(k) from an input array of real or complex values f(x). An inverse transform computes the corresponding real or complex values f(x) from g(k). For definiteness, in this documentation, the variable x represents spatial coordinates and the variable k represents spatial frequencies (or wavenumbers). For functions of time, simply replace the word "space" with "time" in this documentation.
This class enables transforms of 1D, 2D, and 3D arrays. For example, a 2D array f[nx2][nx1] represents nx2*nx1 samples of a function f(x1,x2) of two spatial coordinates x1 and x2. In addition to numbers of samples nx1 and nx2, sampling intervals dx1 and dx2 and first sampled coordinates fx1 and fx2 may also be specified. (The default sampling interval is 1.0 and the default first sample coordinate is 0.0.) These sampling parameters may be specified with samplings sx1 and sx2.
For each specified spatial sampling sx, this class defines a corresponding frequency sampling sk, in which units of frequency are cycles per unit distance. The number of frequencies sampled is computed so that the Fourier transform is fast, but the number of frequency samples is never less than the number of space samples. Arrays to be transformed may be padded with zeros to obtain the required frequency sampling. Optional additional padding may be specified to sample frequency more finely.
A frequency sampling sk may be centered. Such a centered frequency sampling always has an odd number of samples, and zero frequency corresponds to the middle sample in the array of complex transformed values. The default is not centered, so that zero frequency corresponds to the first sample, the one with index 0.
Arrays input to forward transforms may contain either real or complex values. If complex, values are packed sequentially as (real,imaginary) pairs of consecutive floats. The default input type is real.
Signs of the exponents in the complex exponentials used in forward transforms may be specified. The opposite signs are used for inverse transforms. The default signs are -1 for forward transforms and 1 for inverse transforms.
Constructor and Description |
---|
Fft(boolean complex,
float[] f)
Constructs an FFT for the specified 1D array of values.
|
Fft(boolean complex,
float[][] f)
Constructs an FFT for the specified 2D array of values.
|
Fft(boolean complex,
float[][][] f)
Constructs an FFT for the specified 3D array of values.
|
Fft(float[] f)
Constructs an FFT for the specified 1D array of real values.
|
Fft(float[][] f)
Constructs an FFT for the specified 2D array of real values.
|
Fft(float[][][] f)
Constructs an FFT for the specified 3D array of real values.
|
Fft(int nx1)
Constructs an FFT with specified number of space samples.
|
Fft(int nx1,
int nx2)
Constructs an FFT with specified numbers of space samples.
|
Fft(int nx1,
int nx2,
int nx3)
Constructs an FFT with specified numbers of space samples.
|
Fft(Sampling sx1)
Constructs an FFT with specified space sampling.
|
Fft(Sampling sx1,
Sampling sx2)
Constructs an FFT with specified space sampling.
|
Fft(Sampling sx1,
Sampling sx2,
Sampling sx3)
Constructs an FFT with specified space sampling.
|
Modifier and Type | Method and Description |
---|---|
float[] |
applyForward(float[] f)
Applies a forward space-to-frequency transform of a 1D array.
|
float[][] |
applyForward(float[][] f)
Applies a forward space-to-frequency transform of a 2D array.
|
float[][][] |
applyForward(float[][][] f)
Applies a forward space-to-frequency transform of a 3D array.
|
float[] |
applyInverse(float[] g)
Applies an inverse frequency-to-space transform of a 1D array.
|
float[][] |
applyInverse(float[][] g)
Applies an inverse frequency-to-space transform of a 2D array.
|
float[][][] |
applyInverse(float[][][] g)
Applies an inverse frequency-to-space transform of a 3D array.
|
Sampling |
getFrequencySampling1()
Gets the frequency sampling for the 1st dimension.
|
Sampling |
getFrequencySampling2()
Gets the frequency sampling for the 2nd dimension.
|
Sampling |
getFrequencySampling3()
Gets the frequency sampling for the 3rd dimension.
|
void |
setCenter(boolean center)
Sets the centering of frequency samplings for all dimensions.
|
void |
setCenter1(boolean center)
Sets the centering of frequency sampling for the 1st dimension.
|
void |
setCenter2(boolean center)
Sets the centering of frequency sampling for the 2nd dimension.
|
void |
setCenter3(boolean center)
Sets the centering of frequency sampling for the 3rd dimension.
|
void |
setComplex(boolean complex)
Sets the type of input (output) values for forward (inverse) transforms.
|
void |
setOverwrite(boolean overwrite)
Sets the ability of this transform to overwrite specified arrays.
|
void |
setPadding(int padding)
Sets the minimum padding with zeros for all array dimensions.
|
void |
setPadding1(int padding)
Sets the minimum padding with zeros for the 1st array dimension.
|
void |
setPadding2(int padding)
Sets the minimum padding with zeros for the 2nd array dimension.
|
void |
setPadding3(int padding)
Sets the minimum padding with zeros for the 3rd array dimension.
|
void |
setSign(int sign)
Sets the sign used for forward transforms in all dimensions.
|
void |
setSign1(int sign)
Sets the sign used for forward transforms in the 1st dimension.
|
void |
setSign2(int sign)
Sets the sign used for forward transforms in the 2nd dimension.
|
void |
setSign3(int sign)
Sets the sign used for forward transforms in the 3rd dimension.
|
public Fft(float[] f)
f
- an array with dimensions like those to be transformed.public Fft(float[][] f)
f
- an array with dimensions like those to be transformed.public Fft(float[][][] f)
f
- an array with dimensions like those to be transformed.public Fft(boolean complex, float[] f)
complex
- true, for complex values; false, for real values.f
- an array with dimensions like those to be transformed.public Fft(boolean complex, float[][] f)
complex
- true, for complex values; false, for real values.f
- an array with dimensions like those to be transformed.public Fft(boolean complex, float[][][] f)
complex
- true, for complex values; false, for real values.f
- an array with dimensions like those to be transformed.public Fft(int nx1)
nx1
- number of samples in the 1st dimension.public Fft(int nx1, int nx2)
nx1
- number of samples in the 1st dimension.nx2
- number of samples in the 2nd dimension.public Fft(int nx1, int nx2, int nx3)
nx1
- number of samples in the 1st dimension.nx2
- number of samples in the 2nd dimension.nx3
- number of samples in the 3rd dimension.public Fft(Sampling sx1)
sx1
- space sampling for the 1st dimension.public Fft(Sampling sx1, Sampling sx2)
sx1
- space sampling for the 1st dimension.sx2
- space sampling for the 2nd dimension.public void setComplex(boolean complex)
complex
- true, for complex values; false, for real values.public void setOverwrite(boolean overwrite)
overwrite
- true, to overwrite; false, to copy.public Sampling getFrequencySampling1()
public Sampling getFrequencySampling2()
public Sampling getFrequencySampling3()
public void setSign(int sign)
sign
- the sign, -1 or 1.public void setSign1(int sign)
sign
- the sign, -1 or 1.public void setSign2(int sign)
sign
- the sign, -1 or 1.public void setSign3(int sign)
sign
- the sign, -1 or 1.public void setCenter(boolean center)
center
- true, for centering; false, otherwise.public void setCenter1(boolean center)
center
- true, for centering; false, otherwise.public void setCenter2(boolean center)
center
- true, for centering; false, otherwise.public void setCenter3(boolean center)
center
- true, for centering; false, otherwise.public void setPadding(int padding)
padding
- the minimum padding.public void setPadding1(int padding)
padding
- the minimum padding.public void setPadding2(int padding)
padding
- the minimum padding.public void setPadding3(int padding)
padding
- the minimum padding.public float[] applyForward(float[] f)
f
- the array to be transformed, a sampled function of space.public float[][] applyForward(float[][] f)
f
- the array to be transformed, a sampled function of space.public float[][][] applyForward(float[][][] f)
f
- the array to be transformed, a sampled function of space.public float[] applyInverse(float[] g)
g
- the array to be transformed, a sampled function of frequency.public float[][] applyInverse(float[][] g)
g
- the array to be transformed, a sampled function of frequency.public float[][][] applyInverse(float[][][] g)
g
- the array to be transformed, a sampled function of frequency.