This is the first of a series of posts about implementing the Fast Fourier Transform in Haskell (and trying to make it go fast). This part is going to be pretty pedestrian, but we need to lay some groundwork before the interesting stuff.
Fourier transforms turn up everywhere. They're important in pure mathematics, but they're also used in pretty much any application that deals with time series: filtering, signal analysis, numerical solution of differential equations and many others. While the classical theory of Fourier analysis is based on functions, in applications we most often deal with discrete series of values sampled from a function. The discrete Fourier transform is how we do Fourier analysis in this setting.
In this series of posts, we're not going to look very much at applications (well, maybe we'll have one little exception a bit later) and we're not going to talk a lot about the theory behind the Fourier transform. Instead, after briefly introducing the discrete Fourier transform, we're going to use the fast Fourier transform algorithm and some variations to explore some aspects of Haskell programming. In particular, we'll look at how Haskell deals with complex numbers, vectors, profiling and benchmarking, meta-programming and finally, as our pièce de résistance, we'll use all of this to build a Haskell fast Fourier transform package that does compile-time empirical optimisation for arbitrary-sized transforms.
In practice, if you want to do Fourier transforms of discrete data, you use something called FFTW ("the Fastest Fourier Transform in the West"). Our code has no chance of competing with FFTW, which is incredibly clever , but we can demonstrate some of the methods that they use and learn some techniques along the way that are applicable to more complicated problems. (There are Haskell bindings for FFTW -- the vector-fftw package is a good choice.)