TBTK
FourierTransform

Fast Fourier transform

One of the most commonly employed tools in physics is the Fourier transform and TBTK therefore provides a class that can carry out one-, two-, and three-dimensional Fourier transforms. The class is a wrapper for the FFTW3 library (http://www.fftw.org), which implements an optimized version of the fast Fourier transform (FFT).

Basic interface

The basic interface for executing a transform is

FourierTransform::transform(in, out, SIZE_X, SIZE_Y, SIZE_Z, SIGN);

where the SIZE_Y and SIZE_Z can be dropped depending on the dimensionality of the transform. Further, in and out are complex<double> arrays with SIZE_X*SIZE_Y*SIZE_Z elements, and SIGN should be -1 or 1 and determines the sign in the exponent of the transform. The normalization factor is \(\sqrt{SIZE\_X\times SIZE\_Y\times SIZE\_Z}\).

For simplicity the FourierTransform also has functions with special names for the transforms with positive and negative sign. The transform with negative sign can be called as

FourierTransform::forward(in, out, SIZE_X, SIZE_Y, SIZE_Z);

while the transform with positive sign can be called as

FourierTransform::inverse(in, out, SIZE_X, SIZE_Y, SIZE_Z);

Advanced interface

While the basic interface is very convenient, each such call involves a certain amount of overhead. First, the FFTW3 library requires a plan to be setup prior to executing a transform, which involves a certain amount of computation ahead of the actual transform in order to figure out the optimal configuration. For similar transforms it is possible to do such calculations once and reuse the same plan. Second, by default the transform uses a specific normalization and it can be convenient to specify a custom normalization factor, or to set the normalization factor to 1, in which case the normalization step is avoided completely. For this reason it is possible to setup a plan ahead of execution that both wraps the FFTW3 plan, as well as contains information about the normalization.

The creation of a plan mimics the interface for performing basic transforms

FourierTransform::Plan<complex<double>> plan(
in,
out,
SIZE_X,
SIZE_Y,
SIZE_Z,
SIGN
);

Similar calls are available for creating forward and inverse transforms without explicitly specifying the sign and are called FourierTransform::ForwardPlan<complex<double>> and FourierTransform::InversePlan<complex<double>>, respectivley. The normalization factor is set using

plan.setNormalizationFactor(1.0);

Once a plan is setup, repeated transforms can be carried out on the data in the in and out arrays by simply typing

FourierTransform::transform(plan);