8 Fast Fourier transform (FFT)

 8.1 Differences between NAG and FFTPACK
 8.2 Data formats for FFTPACK and NAG
 8.3 Replacing calls to C06FAF
 8.4 Replacing calls to C06FBF
 8.5 Replacing calls to C06FCF
 8.6 Replacing calls to C06FJF
 8.7 Replacing calls to C06FUF
 8.8 Replacing calls to C06GBF and C06GCF

The routines for fast Fourier transform (and their origin) are:

8.1 Differences between NAG and FFTPACK

8.2 Data formats for FFTPACK and NAG

This section describes the differences between the way NAG and FFTPACK store arrays of Fourier coefficients. In the following, the Fourier transform of an array of N data values is represented by a sequence of N complex values [A0+i*B0], [A1+i*B1], ..., [A(N-1)+i*B(N-1)].

The differences are basically in the organisation of the Fourier coefficients within the returned array, and also in the normalisation. The normalisation of the FFTPACK values is such that doing a forward transform followed by a backward transform will result in the original array values being multiplied by a factor of N.

Routines to do conversions between FFTPACK and NAG formats have been added to the library.

8.2.1 Fourier transforms of sequences of purely real values

The relevant NAG routines are C06FAF and C06FBF (the “Hermitian” routines), and the FFTPACK routines are PDA_DRFFTI, PDA_DRFFTF and PDA_DRFFTB. These routines take advantage of the symmetries present in the Fourier transform of a purely real sequence. Only half of the real (A) and imaginary (B) terms need to be calculated and stored because the other halves are just the same. This means that only half the space is required to store the Fourier transform (i.e. N elements rather than 2*N), and it takes roughly half the time to evaluate. The disadvantage is that the resulting Fourier transform array can be rather more difficult to use than if all the real and imaginary parts are stored explicitly. There are routines PDA_DNAG2R and PDA_DR2NAG to do in-situ conversions between NAG and FFTPACK format. Note, each of these routines divides the supplied values by SQRT(N), so successive calls to PDA_DR2NAG and PDA_DNAG2R do not leave the original data unaffected (they are divided by N). This is done to cancel the effect of successive calls of PDA_DRFFTF and PDA_DRFFTB which multiplies the original data by N.

The real and imaginary coefficients produced by PDA_DRFFTF are numerically larger than the corresponding C06FAF coefficients by a factor of SQRT(N), and are ordered differently in the returned arrays. Both routines return A0 (i.e. the DC level in the array) in element 1. PDA_DRFFTF then has corresponding real and imaginary terms in adjacent elements, whereas C06FAF has all the real terms together, followed by all the imaginary terms (in reverse order):

     PDA_DRFFTF:  A0,    A1, B1,     A2, B2,     A3, B3,   ...
     C06FAF:      A0,    A1, A2, A3, ...,        ..., B3, B2, B1

The zeroth imaginary term (B0) always has the value zero and so is not stored in the array. Care has to be taken about the parity of the array size. If it is even, then there is one more real term than there are imaginary terms (excluding A0), i.e. if N = 10, then the coefficients are stored as follows:

     PDA_DRFFTF:  A0, A1, B1, A2, B2, A3, B3, A4, B4, A5
     C06FAF:      A0, A1, A2, A3, A4, A5, B4, B3, B2, B1

If N = 9, then the coefficients are stored as follows:

     PDA_DRFFTF:  A0, A1, B1, A2, B2, A3, B3, A4, B4
     C06FAF:      A0, A1, A2, A3, A4, B4, B3, B2, B1
8.2.2 Fourier transforms of sequences of complex values

The relevant NAG routine is C06FCF and the FFTPACK routines are PDA_DCFFTI, PDA_DCFFTF and PDA_DCFFTB. These routines take the Fourier transform of a general complex sequence of N values (i.e. 2*N real values), also returning the Fourier transform in a sequence of N complex values. FFTPACK and NAG differ in that FFTPACK stores the real and imaginary parts of each complex value in adjacent elements of the array, whereas NAG has two separate arrays, one for the real terms and one for the imaginary terms. There is also a difference in the normalisation of the routines in that the real and imaginary Fourier coefficients produced by PDA_DRFFTF are numerically larger than the corresponding C06FAF coefficients by a factor of SQRT(N). There are subroutines PDA_DNAG2C and PDA_DC2NAG to convert between NAG and FFTPACK format. Successive calls to PDA_DC2NAG and PDA_DNAG2C will result in the original data being divided by N. This is done to cancel the multiplication by N which occurs when successive calls to PDA_DCFFTF and PDA_DCFFTB are made.

8.3 Replacing calls to C06FAF

C06FAF is the NAG routine for finding the FFT of a one-dimensional sequence of real data values. The routine performs a forward transform, storing the FFT as a “Hermitian” sequence in which only half of the real and imaginary terms are kept. The inverse transform is obtained by calling C06FBF, which finds the FFT of a one-dimensional Hermitian sequence.

The following steps are involved in replacing C06FAF calls with equivalent FFTPACK calls:

8.4 Replacing calls to C06FBF

C06FBF is the NAG routine for finding the FFT of a one-dimensional Hermitian sequence such as created by C06FAF. The routine performs a forward transform, but it is usually used to perform an inverse transform by preceeding it with a call to C06GBF to form the complex conjugates of the input (frequency domain) data.

The following steps are involved in replacing C06FBF calls with equivalent FFTPACK calls:

8.5 Replacing calls to C06FCF

C06FCF is the NAG routine for finding the FFT of a one-dimensional sequence of complex data values. The routine performs a forward transform. To do an inverse transform the complex conjugate of the input data is taken before calling C06FCF (using C06GCF), and the complex conjugate of the output data is taken on return from C06FCF.

The steps involved in replacing C06FCF calls with equivalent FFTPACK calls are listed separately for forward and inverse transforms.

8.5.1 Forward transforms
8.5.2 Inverse transforms

8.6 Replacing calls to C06FJF

C06FJF is the NAG routine for finding the FFT of an N-dimensional array of complex data values. The routine performs a forward transformation. To do an inverse transform the complex conjugate of the input data is taken before calling C06FJF (using C06GCF), and the complex conjugate of the output data is taken on return from C06FJF.

There are no equivalent routines in FFTPACK as found in NETLIB. PDA_DNFFTF and PDA_DNFFTB have been written, which do the equivalent of C06FJF. These routines are a bit different to genuine FFTPACK routines in that they do not need any initialisation, and use NAG format rather than native FFTPACK format for complex data arrays and Fourier coefficient arrays. Consequently, replacing C06FJF is a bit easier than replacing the one-dimensional routines.

The steps involved in replacing C06FJF calls with equivalent FFTPACK calls are listed separately for forward and inverse transforms.

8.6.1 Forward transforms
8.6.2 Inverse transforms

8.7 Replacing calls to C06FUF

C06FUF is the NAG routine for finding the FFT of a two-dimensional sequence of complex data values. There is no direct equivalent. Use the N-dimensional routines instead (with N = 2). See C06FJF.

8.8 Replacing calls to C06GBF and C06GCF

The complex conjugation NAG routines C06GBF and C06GCF should no longer be needed since separate routines are provided within FFTPACK for doing inverse transformation.