The demo above shows how closed contours can be approximated via sums of complex exponentials. The process involves taking samples, performing a Discrete Fourier Transform on them, and then using the resulting Fourier Coefficients for complex exponentials. This is sometimes referred to as epicycles. This page gets into how the Discrete Fourier Transform Works.
Preliminary rambling notes
- Take a closed contour
- Take sample points along it, separated evenly by arc length.
- Calculate the Fourier coefficient at each of the points. These correspond to the frequencies We're basically measuring how much of each frequency the contour has at each of the different points.
We calculate the Fourier Coefficient as
- Only about half of these are unique because the frequency is the same as (just like moving back 2 hours from 12 on a clock to 10 it the same as moving forward by 10 hours).
- Each represents a vector in the complex plane with:
- length =
- phase angle =
- rotation speed =
Seems to be measuring how well the sample points move around the unit circle at the same rate as the rotation vector?
Let's take and talk about what happens when our curve is a unit circle.
With frequency we have no rotations, so, for each sample point, we add the sample point directly to the summation vector. The result is the average of all the sample points, the center of gravity, or DC component. For the unit circle this is
With frequency
Starting with we have which is at Our first rotation doesn't rotate at all, so our summation is now pointing at
Now at , our second sample point is pointing at The imaginary component of our exponential gives us
So, our sample point and our rotation are the same. When we multiply them in exponential form, we add the angles, and get We take the exponential from our first sample and add it to this exponential, which gives us their average, and we get as our summation vector so far.
Next at our sample point is at and our rotation vector is too. The resulting angle is Our summation vector now points at midway between its previous value and the value of this sample.
The demo below shows how each individual Fourier Coefficient calculation works by taking a sample point and rotating it.
Math on the Unit Circle
The th roots of unity. There are roots of 1. So, has 1 solution, itself. has 2 solutions, and Note that is on the opposite side of the unit circle from has 3 solutions: and The general pattern is that the th roots of unity are given by
Now, multiplying these roots by each other can be accomplished by adding their exponents, which are just terms in i.e. the product of and is
Note that the resultant product is a root of unity as well, and in general the roots of unit form a @cyclic abelian group under multiplication.
It also turns out that this group is isomorphic to under addition modulo The multiplication we gave above is equivalent to on and just like on
The th roots of unity under multiplication are isomorphic to under addition.
Let
be the th roots of unity, and
be the first non-negative integers under addition modulo
Let
be a mapping we will show to be an isomorphism.
First, note that and are obviously the same cardinality, by their definitions.
Now, suppose Then
so is a @group-homomorphism.
Now, is 1, that is, so But, is and so is @injective, and an @isomorphism, and and are isomorphic.
One more fact worth noting, now that we've established this isomorphism. On the unit circle, a negative rotation (clockwise) by is equal to a positive rotation (counterclockwise) by This is easy to see:
Thus, the th th root of unit, equals the th root of unity (because the th th root of unity corresponds to a full rotation). This corresponds to on For example, on and on
Coming soon... roots of unity as the elements of basis vectors for and DFT as computing the inner product (basically, cosine similarity * magnitude) between the sample points and these basis vectors. That is, DFT is a change of basis onto these basis vectors, it is literally projecting onto these.
Sample Points as Vectors in
Let's say we have a contour on the complex plane, and we take sample points on it, in order, so We can view these sample points (which form a sequence) as forming a vector in
Now, the standard basis for is the same as that of which is where is a -dimensional vector with a 1 in the th position and 0's in the other position, i.e.
It's easy to see that these basis vectors are orthogonal (and therefore @linearly-independent); to see that they span , suppose Then, that is, the components of (which are complex numbers) are exactly the scalar coefficients we need to multiply by our basis vectors to form so this basis spans
is an Inner Product Space
Now, we can equip this vector space with an inner product
The function
defined on is an inner product, and so ( a positive integer) forms an @inner-product-space.
Since is a field, is obviously a vector space.
To see that this is indeed an inner product, we'll show the required properties hold.
For @conjugate-symmetry, let and let Then,
and
and since is arbitrary, it holds for any respective pair of components in and and so
For @linearity in the first argument, let Then
Now, to show @positive-definiteness let Then,
Since is an inner-product space, we can use the inner product to compare how well aligned two vectors are, and to perform projections.
Fourier Basis
We can use complex numbers representing varying degrees of rotation around the unit circle to form a basis vector. Given a sample count we can make a basis from the vectors whose elements are defined as
To work on intuition some, let's take the case
Then for
and
If we use our isomorphism we have a
Each of these values represents a different frequency. For our total angle swept across all points is For the total angle swept is For the total angle swept is So, we can say that basis vector is associated with (represents?) rotation at frequency
Now note that equals the conjugate of It appears that the conjugate of the basis vector representing rotation at frequency represents rotation at frequency
For odd one basis vector represents no rotation - no frequency - aka DC - this is for Then, for each up to we have a positive frequency vector and a matching frequency vector. The vectors representing each pair of frequencies are made up of sample points which are conjugates of each other (reflections of each other across the -axis, or alternatively, rotations by the same increments in opposite directions.) That is, the th point in the vector for is the conjugate of the th point in the vector for
For even we have a similar situation, except there is an additional frequency at that is sometimes called the Nyquist frequency. This frequency has only real components and is therefore its own conjugate. The th element of this vector is given by
Let be a positive integer. Then the vectors
for form a basis for
To show linear independence, we will show a stronger condition, orthogonality, holds.
For we can write that the th entry of is
and that the conjugate of the th entry of is
Then, in our inner product between and , the th term is
Thus, for
Now we need to show that this sum is Note that if we let we can rewrite this as
From Finite Geometric Series, we have that
Substituting back in for we get
Thus, and so when an are orthogonal and therefore @linearly-independent.
Now we need to show that span
Let We need to find such that
That is, we want constants such that
To find some specific we can take the inner product of both sides with respect to to get
@Linearity in the first argument of the inner product allows us to rewrite the right side to get
Now, we know that
so the inner product on the right-hand side is except when and this reduces to
Therefore,
This shows that the Fourier basis described here indeed spans and shows how to compute the Fourier coefficients
The Fourier Coefficient given as
Is just the @scalar-projection of onto It is a complex number, and is proportional to the amplitude of the frequency present in while gives the phase of frequency in
We've given this as the inner product divided by This is allowed but not typical. In order to make
we need as a factor in either the DFT or the IDFT, but typically, it's done in the IDFT.
Now we're ready to see the DFT as a change of basis from the standard basis for to the DFT (Fourier) Basis for The DFT is given as
and the IDFT is given as
If we collect the conjugates of the vectors as rows in a matrix we get
Then, given a vector in we can compute its DFT via matrix vector multiplication as
and we can invert it via IDFT using the conjugate rows of as
In practice, while this matrix multiplication approach works, it can be optimized. This isn't an arbitrary matrix - it has some particular structure, and it can be factored to come up with a more efficient operation. This is what the Fast Fourier Transform does.
The demo below allows drawing a contour and then editing the Fourier coefficients. Playing with this helps gives some intuition for what the coefficients represent, and it also shows one of the applications of DFT - filtering and amplifying components of a signal. Try drawing a closed contour that wraps around the origin three times counter-clockwise. What's the biggest component? Try drawing a similar shape, but go clockwise, maybe go clockwise 4 times.