FFTW for IDL
FFTW is a free C subroutine library for computing the
discrete Fourier transform (DFT) in one or more dimensions, of
arbitrary input size, and of both real and complex data (as well as of
even/odd data, i.e. the discrete cosine/sine transforms or DCT/DST). It
is known to be one of the fastest freely available implementations of
fast fourier transforms.
IDL has build-in routines for performing fourier transforms,
which are easy to use and in most cases sufficiently fast. However, for
certain time-critical computations it might be useful to use FFTW
instead.
Speed:
The
speed improvement can be quite significant, in particular when
transforming multi-dimensional arrays and when using real-to-complex
and complex-to-real transforms, which doesn't exist in IDL. A factor of
2-4 compared to native IDL is the normal case.
To give an imagination what can be possible, here is a result
from a 4-processor IRIX machine. A 2D-FFT of a 4096x4096 complex matrix
took 127.2 sec in native IDL and only 17.2 sec using libIDLfftw. Keep
in mind that also IDL uses all 4 processors when doing fft's.
Routines:
Currently, only 4 different FFTW functions are implemented, which were of particular interest for me:
fftw1d_arr : 1d fourier
transform of a complex 2d array (columns or rows)
Usage in IDL: fftw1d_arr,array,dimension,direction.
array = 2d data array, dimension=1 (row) or 2 (colums),
direction= -1 (forward fft) or +1 (backward fft)
fftw2d : 2d fourier
transform of a complex 2d array
Usage in IDL: fftw2d,array,direction.
array = 2d data array, direction= -1 (forward fft) or +1
(backward fft)
fftw2d_cr : 2d
complex-to-real fourier transform of a complex 2d array
Usage in IDL: result =
fftw2d_cr(array)
array = 2d complex input data array, result = 2d real output
array
fftw2d_rc : 2d
real-to-complex fourier transform of a real 2d array
Usage in IDL: result =
fftw2d_rc(array)
array = 2d real input data array, result = 2d complex output
array
Maybe I'll add some more routines to the wrapper in the future, but don't thrust me too much on this. I would appreciate very much any contribution.
Installation:
Step 1: Download an unpack
libIDLfftw (see below). If you found a suitable binary distribution,
you can directly switch over to step 5. If not, or if it is not working
for some reason, you'll have to go on and compile libIDLfftw for
yourself. When compliling for windows, download the binary
distribution, as it contains some additional files needed under windows.
Step 2: Download an compile fftw-2.1.5 (you have to use version
2.1.5, not
3.x). Use the configure program of fftw before compilation. Here you
have use the flag "--enable-float" (when you're working with single
precision complex data). Set also the flag"--enable-threads". After
configuring, issue the command 'make' to compile fftw.
Step 3: Now you have to copy the fftw libraries into the
libIDLfftw directory:
cp
threads/.libs/libfftw_threads.a /my/path/to/libIDLfftw
cp threads/.libs/librfftw_threads.a /my/path/to/libIDLfftw
cp fftw/.libs/libfftw.a /my/path/to/libIDLfftw
cp rfftw/.libs/librfftw.a /my/path/to/libIDLfftw
Step 4: Change into the
libIDLfftw directory and compile libIDLfftw by issuing the commands:
make clean
make
This generates four
shared object files:
libIDLfftw.so - single processor version
libIDLfftw_threads2.so - dual processor version
libIDLfftw_threads4.so - quadro processor version
libIDLfftw_threads8.so - 8 processor version
Step 5: To use libIDLfftw from within IDL, you first have to
start IDL and link the library (possibly add these lines to your
startup.pro). Use the threaded versions when you have more than one
processor.
IDL>
linkimage,'fftw2d','libIDLfftw.so'
IDL> linkimage,'fftw1d_arr','libIDLfftw.so'
IDL> linkimage,'fftw2d_rc','libIDLfftw.so'
IDL> linkimage,'fftw2d_cr','libIDLfftw.so'
Once this is done
you can use the 4 new routines, as described above.
Download:
libIDLfftw.tar.gz: source distribution (in C).
libIDLfftw-bin-linux.tar.gz:
pre-compiled linux/i686 binary (SUSE 9.0). 1,2,4 and 8 processor version
libIDLfftw-bin-irix32.tar.gz: pre-compiled IRIX/mips32 binary (IRIX 6.5.1). 1,2,4 and 8 processor version
libIDLfftw-bin-irix64.tar.gz:
pre-compiled IRIX/mips64 binary (IRIX 6.5.1). 1,2,4 and 8 processor
version
Authors:
Andreas Reigber:
first (buggy) implementation, linux and irix port
Pau Prats:
stability and bug fixes, windows port
Todo:
The documentation is more than bad. Sorry for that. But you learn a lot until you get working :-)
Include more of the FFTW routines.