An easy to use fast Fourier transform.
This class is less flexible than
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.