Fast Fourier transform

The fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform of a vector in time $$O(n log(n))$$, where a naive implementation achieves only $$O(n^2)$$ time. APL implementations of the fast Fourier transform began appearing as early as 1970, with an 8-line implementation by Alan R. Jones published in APL Quote-Quad.

A Fourier Transform (FFT) is a method of calculating the frequency components in a data set — and the inverse FFT converts back from the frequency domain — 4 applications of the FFT rotates you round the complex plane and leaves you back with the original data.

APLX
This FFT code is implemented with the Cooley–Tukey FFT algorithm by dividing the transform into two pieces of size  at each step. It will run under APLX.

This is as given in Robert J. Korsan's article in APL Congress 1973, p 259-268, with just line labels and a few comments added.


 * X and Z are two-row matrices representing the input and output real and imaginary data. The data length must be  (N integer), and the algorithm will cope with varying N, unlike many DSP versions which are for fixed N.
 * Zero frequency is at, maximum frequency in the middle; from there to   are negative frequencies. i.e. for an input Gaussian they transform a 'bath-tub' to a 'bath-tub'.
 * This is an elegant algorithm, and works by transforming the input data into an array of 2×2 FFT Butterflies.

Simple recursive implementation
Sample usage:

fft 1 1 1 1 0 0 0 0 4 1J¯2.414213562 0 1J¯0.4142135624 0 1J0.4142135624 0 1J2.414213562

Inverse FFT can be defined for testing:

2-dimensional FFT and inverse 2D FFT:

Sample usage: fft2D 2 2⍴⍳4 10 ¯2 ¯4 0       ifft2D fft2D 2 2⍴⍳4 1 2 3 4

Dyalog APL
FFT appears in dfns.dws, a workspace supplied with Dyalog APL, in the context of fast multi-digit multiplication. Extracted from there, it is there defined as: