Alexander Martinez-Marchese's Home Page

C++ matrix class for FFTW

One of the fastest fast Fourier transform (FFT) C++ libraries is FFTW. However, its use is not as straight forward as typing fft(array). To make it easier to use, I added functions to a 2D array template class. The functions can read and write to and from the 1D array used in FFTW, which depends on what FFT is carried out. For example; real to complex, complex to complex, etc. Also there is a function to swap the quadrants of the 2D array, which is needed to get the FFT of an image. The matrix class has simple overloaded operators like multiplication, sum and subtraction.

To demonstrate the use of the class, I wrote a program that calculates the error between the Fourier transform of the discretized cylinder function and its actual Fourier transform evaluated at the same points. The program also measures how fast FFTW is working. More information about the Fourier transform of the cylinder function can be found here.

Here is the class and a sample program: array2d.h, circleFFTwFile.cpp.

The program gives the following output: circleErrors.txt,