next up previous
Next: Sample Codes for Using Up: How FFTEASY works Previous: FFTR1: One-Dimensional Real Fourier

FFTRN: Multi-Dimensional Real Fourier Transforms

The structure of fftrn is almost identical to fftr1 and the basic equations used are the same. The key difference comes from the fact that in more than one dimension the element $H_{-b}$ can no longer simply be found at the location $N/2-b$. Rather the index must be reversed from $b$ to $-b$ separately for each dimension. Likewise in the one-dimensional case $F_b$ only needed to include non-negative value of $b$ whereas in this case that is true only in the last dimension.

This indexing is particularly tricky since fftrn treats the data as a one-dimensional array. (There is no practical way to treat the data as a multi-dimensional array without knowing in advance how many dimensions are going to be used.) Fortunately there is a simple solution to this problem. The function fftrn defines an array called $indices$ that keeps track of the separate indices in all the dimensions. At the bottom of the main loop these indices are incremented, advancing the last one until it reaches its maximum and then starting it over and incrementing the next to last one, and so on. At the top of the main loop is a call to the function find_index, which finds the one-dimensional array index that corresponds to these different multi-dimensional indices. More importantly, the function find_index also finds the one-dimensional index corresponding to the negative of the frequencies indicated by $indices$. From there the implementation is almost identical to fftr1. The inner loop runs over the last dimension and applies the exact same formulas as fftr1 to calculate $F$, the desired transform, from $H$, the output of fftcn. I leave it as an exercise for the reader to show that these formulas are still valid provided the frequencies in all but the last dimension are replaced by their corresponding negative frequencies as shown.

The $0$ and $N/2$ (Nyquist) frequencies present a problem. In one dimension these both had to be real because $F(k) = F(-k)^*$. In multiple dimensions, however, it is no longer true that all values of $F$ for which the last index are $0$ or $N/2$ are real. To illustrate what I mean let me use $k$ to indicate the frequency in the last dimension and $p$ to indicate the frequency components in all other dimensions. Now the symmetry is simply $F(p,0) = F(-p,0)^*$. This means that applying equation [16] to the case $k=0$ will no longer yield a real number as it did in the one-dimensional case and so $k=N/2$ can no longer be packaged with $k=0$ into one complex array index. So fftrn takes as input an array $fnyquist$ that it uses for the values $k=N/2$ and uses both the real and imaginary parts of the first elements of the array $f$ for $k=0$. In practice this means that the output is redundant because it will contain $f(p,0)$ and $f(-p,0)$, which are complex conjugates of each other (and likewise for $p$ and $-p$ in $fnyquist$).

As with fftr1 the algebra for the inverse transform turns out to be virtually identical to the forward case, and once again I leave the details to the reader to verify. Note that it is up to the user to make sure that the symmetries noted above are obeyed by the input to the inverse transform. In section [4.3] I provide sample code for generating data with all the correct symmetries in three dimensions. You can simply cut and paste this sample code into your own program and substitute whatever function you want to generate in frequency space.


next up previous
Next: Sample Codes for Using Up: How FFTEASY works Previous: FFTR1: One-Dimensional Real Fourier

Go to The FFTEASY Home Page
Go to Gary Felder's Home Page
Send email to Gary at gfelder@email.smith.edu

This documentation was generated on 2003-09-30