Draw a shape below to see it drawn as the sum of Fourier coefficients on a complex plane. Adjust the slider to reduce the number of coefficients that are used.
How it works
The image is a series of coordinates. If we consider the coordinates to be complex values, we can take their Discrete Fourier Transform to yield a series of complex-valued Fourier coefficients . To recover the original image from the coefficients, we can use the inverse DFT:
Let’s write out the sum for n = 0, 1, and 2 and N = 3.
Each X[k] is a vector in the complex plane. Multiplication of a complex number by a complex exponential geometrically rotates the vector counterclockwise by . By keeping fixed and observing how the argument to its exponential evolves with increasing we can get an idea of what’s happening: For every unit increase in , will not rotate because the argument to its exponential will always be zero. will rotate by , and will rotate by These values can be considered the rotational velocity of the vectors. If you look at the animation, you can see that each circle is indeed rotating at a fixed rate. Circles spinning faster correspond to higher frequency content. Large circles indicate that more of the signal’s frequency content lies in that circle’s frequency range.
Summary
The procedure to get the animation above is as follows:
- Collect x, y coordinates for the drawing
- Treat each x, y pair as a complex number and compute the DFT coefficients.
- For every n in 0…N-1
- Calculate k complex numbers .
- Sort the k complex numbers by their magnitude descending.
- Take the value from the slider and call it h. This is how many of the k complex numbers will be used to redraw the shape.
- Draw out the addition of the h complex numbers as vectors in the complex plane. i.e. draw them head-to-tail.
- When the last vector is drawn, plot the estimated value of y[n] based on h vectors.
Notes
Notice that for a lot of shapes, h can be much lower than N and still result in an acceptable redrawing of the original image. This works because when we order by vectors by their magnitude descending and take the first h, those are the h vectors that contribute most to the signal’s shape. Something like this can be used for compression - instead of sharing all N points of a signal, you might share N / 2 points and the other person would be able to recreate an acceptable version of your signal.
Another thing to note is that in the animation, I’m skipping the first circle since that one doesn’t spin and isn’t very interesting. All it does is offset the image from being centered about the origin to being centered about the center of the canvas - (320, 240) in this case.