5.8 Fourier transformsThe 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,
where 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 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() the fft and ifft commands compute, respectively, discrete sets of samples
and
where:
It may be shown in the limit that
and
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 Example: The Fourier transform of a top-hat function It is straightforward to show that the Fourier transform of a top-hat function of unit width is the function ![]()
![]() ![]()
In this example, we demonstrate this numerically by taking the Fourier transform of such a step function, and comparing the result against the function sinc(x) which is pre-defined within Pyxplot: set numerics complex step(x) = tophat(x,0.5) fft [-1:1:0.01] f() of step() plot [-10:10] Re(f(x)), sinc(pi*x) Note that the function Re(x) is needed in the plot statement here, since although the Fourier transform of a symmetric function is in theory real, in practice any numerical Fourier transform will yield a small imaginary component at the level of the accuracy of the numerical method used. Although the calculated numerical Fourier transform is defined throughout the range ![]() ![]() ![]() In the following steps, we take the square of the function ![]() g(x) = f(x)**2 ifft [-50:49.5:0.5] h(x) of g(x) plot [-2:2] Re(h(x)) ![]() As can be seen, the result is a triangle function. This is the result which would be expected from the convolution theorem, which states that when the Fourier transforms of two functions are multiplied together and then inverse transformed, the result is the convolution of the two original functions. The convolution of a top-hat function with itself is, indeed, a triangle function. Footnotes
|