Fourier Art Classes
In this blog's first post, we are going to visualise a complex Fourier transform as sum of plane waves.
Intro
Discrete Fourier transforms are ubiquitous in image and signal processing. They allow the decomposition of a time-dependent signal into a sum of plane waves with constant frequencies. Today, we are going to visualise them in a cool neon-look using Python. I recommend the the excellent explanatory videos on the Fourier transform by the Youtube channel 3Blue1Brown where I first came across this type of visualisation. Before diving in, below is a gif showing an animation of our result: You may find the accompanying Python code on GitHub .
Discrete Fourier transform
The one-dimensional discrete Fourier transform (DFT) and its inverse (IDFT) are defined as
\(\hat{f}(k) = \sum_{t=0}^{N-1} f(t) \cdot e^{-i 2 \pi t n/N}\)
\(f(t) = \frac{1}{N} \sum_{k=0}^{N-1} \hat{f}(k) \cdot e^{+i 2 \pi k t/N}\)
for a function \(f\) taking real or complex values, \(N > 0\) and \(0 \leq t, k < N\).
How to interpret these equations? Each frequency \(k\) corresponds to a vector of constant length \(\frac{1}{N} \hat{f}(k)\). At a given time, it points in the direction of the plane wave \(e^{+i 2 \pi k t/N}\), that is, the point \((\cos(2 \pi k t/N), \sin(2 \pi k t/N))\) in the complex plane. The sum of plane waves is equal to adding the vectors with the sum of vectors pointing to the complex number \(f(t)\). Time evolution implies that each vector rotates at constant speed tracing a circle.
Drawing an Elephant
This equips us with the knowledge to get started: We take the discrete Fourier transform of a periodic (\(f(t) = f(t + \delta t)\)), time-dependent input function. Our input function \(f(t)\) is von Neumann’s 4-parameter elephant based on the paper “Drawing an elephant with four complex parameters” by Jürgen Mayer et al. (2010, DOI:10.1119/1.3254017).
In the next step, we compute the IDFT at a given time by first calculating an array containing the plane waves with the magnitudes calculated by the DFT and then sort them from low to high frequencies.
Finally, we plot the elephant as well as the vectors the plane waves describe and the circles they trace:
The final result looks as follows: If you like you can play around with the code and use different input data. Have fun!