5.8 Fourier transforms
The fft and ifft commands take Fourier transforms and inverse Fourier transforms respectively of data. As with other commands, data can be supplied from a data file, from functions, or from a colon-separated list of vectors (see Section 6.5.3). In each case, a regular grid of abscissa values must be specified on which to take the discrete Fourier transform, which can extend over an arbitrary number of dimensions. The following example demonstrates the syntax of these commands as applied to a two-dimensional top-hat function:
step(x,y) = tophat(x,0.2) * tophat(y,0.4) fft [ 0: 1:0.01][ 0: 1:0.01] f() of step() ifft [-50:49:1 ][-50:49:1 ] g() of f()
In the fft command above, equally-spaced samples of the function step are taken between limits of and for each of equally-spaced values of on an identical raster, giving a total of samples. These are converted into a rectangular grid of samples of the Fourier transform f at
where and is analogously defined. These samples are interpolated stepwise, such that an evaluation of the function f for general inputs yields the nearest sample, or zero outside the rectangular grid where samples are available. In general, even the Fourier transforms of real functions are complex, and their evaluation when complex arithmetic is not enabled (see Section 4.5) is likely to fail. For this reason, a warning is issued if complex arithmetic is disabled when a Fourier transform function is evaluated.
In the example above, we go on to convert this set of samples back into the function with which we started by instructing the ifft command to take equally-spaced samples along the -axis between and , with similar sampling along the -axis.
Taking the simpler example of a one-dimensional Fourier transform for clarity, as might be calculated by the instructions
step(x) = tophat(x,0.2) fft [ 0: 1:0.01] f() of step()
It may be shown in the limit that becomes small – i.e. when the number of samples taken becomes very large – that these sums approximate the integrals
Fourier transforms may also be taken of data stored in data files using syntax of the form
fft [-10:10:0.1] f() of 'datafile.dat'
In such cases, the data read from the data file for an -dimensional FFT must be arranged in columns1, with the first containing the abscissa values for each of the dimensions, and the final column containing the data to be Fourier transformed. The abscissa values must strictly match those in the raster specified in the fft or ifft command, and must be arranged strictly in row-major order.