# Haskell arb-fft FFT library

This series of blog posts describes the development of a pure Haskell arbitrary length fast Fourier transform library. This goes well beyond the usual textbook treatment of the FFT, dealing with efficient decomposition of transforms of arbitrary lengths (i.e. not just powers of two), specialised transforms for small sizes and treatment of prime-length transforms using Rader’s algorithm.

As well as implementation of the main algorithms, there’s quite a bit of material covering empirical optimisation of this type of numerical code, using profiling and benchmarking to guide the optimisation process, and using gradual refinement with localised mutability, unboxing and other optimisations to eventually get within a factor of five or so of the `vector-fftw`

package (“the fastest Fourier transform in the West”).

The Discrete Fourier Transform: Introduction to the DFT and a naïve implementation.

Matrix factorisation: The Cooley-Tukey approach to factorising Fourier matrices.

Cooley-Tukey for Powers of Two: The “textbook” Cooley-Tukey algorithm for powers-of-two input lengths.

A Simple Application: Audio filtering example.

Transforming Vectors of Arbitrary Lengths: Extending the Cooley-Tukey idea to arbitrary input lengths.

Implementing the Mixed-Radix FFT: Haskell code (and testing) for the arbitrary length Cooley-Tukey algorithm.

Where We’ve Got To, Where We’re Going: Taking stock.

Benchmarking Experiments: Benchmarking with Criterion, and a plan for optimisation.

Prime-Length FFT With Rader’s Algorithm: Dealing with prime input lengths– some number theory, some group theory, and achieving $O(N \log N)$ scaling.

Building a package: Code organisation.

Optimisation Part 1: Mutable vectors, unboxing.

Optimisation Part 2: Plan generation: heuristics and empirical plan selection.

Optimisation Part 3: Improvements to Rader’s algorithm, compiler flags, final benchmarking.

Wrap-up: What we’ve done, lessons learned, what’s left to do.