The fourier transform is this black box operation which takes in a function in terms of time and returns a function in terms of frequency. However treating the fourier transform as a pure black box is foolish, especially when what's inside isn't necessarily something that we need to be scared of.
I have seen a few "intuitive" explanations of the mathematics behind the fourier transform and although they do a good job of explaining the intuition behind the fourier transform at a high level, I still feel that they fail capture the essence of what the fourier transform really is doing at a low level. Which I feel is a shame because it is actually very cool, so let's talk about the mathematics foundational to fourier analysis.
Suppose that we had some function mapping some domain to the complex numbers. The set of such functions forms a vector space. We can add and scale functions as we would expect:
It is reasonable then to expect there to be a set of basis vectors, as in there is some minimal set of vectors for which any function can be written as a linear combination of our basis vectors.
Where are complex number themselves. Much like how every point in dimensional space can be written as a linear combination of , and .
Notice the three vectors , and are normal which means that their respective magnitudes are exactly .
Also notice that these three vectors are orthogonal, what this means in the context of dimensional space is that the angle between each of the respective vectors is exactly or in other words where is the angle between the two vectors. Which is also to say that two vectors and in dimensional spaces are orthogonal if and only if .
We may recognize this as the dot product between the vectors and , so we can say that two vectors are normal if the "dot" product of the two vectors is .
Whats interesting about the dot product is that for any vector we can "extract" out one of the components of the vector by using the dot product.
If we had the vector we could extract out the component of the vector by dotting it with one of our orthonormal basis vectors , we could also extract out the component of this vector by dotting it with . Note that by extracting out the and components of and , we have enough information to fully reconstruct the original vector. This is like a sommelier, who is able to pick out the individual components of a wine, you could imagine that this process if extended to arbitrary functions could be quite useful.
The fourier transform comes from extending the idea of the dot product to the vector space of functions and we will now refer to this dot product as the inner product.
An inner product is simply a function , taking in two elements of a vector space and outputting a complex number.
The inner product is not just any function however, it is a function satisfying the following rules:
If we have a set of orthonormal basis vectors then we have that and when
Now finally if we have a function
We have that
This is in essence what fourier analysis is about, we are able to split any function up into components that make it up as long as we find a suitable inner product and our set of components are orthonormal basis vectors.
I claim that the set of functions forms a set of orthonormal basis vectors over the vector-space of continuous functions with period with the inner product
I would like to think that these are a very natural choice for a set of basis functions for the vector-space of continuous functions with period as is pretty much the most fundamental periodic function (you cannot have , or any of the other trig functions without )
We can prove that for any function which is periodic with period and for any large that we pick there is a linear combination of functions in equal to for which for at least different values of . This is not too hard to prove although a little tedious so is left as an exercise to the reader. (Hint: Linear Simultaneous Equation)
Note that is is also useful to think of these functions as mapping to
We now show that the functions in are normal.
If you are observant then you might remember that the word orthonormal contains both ortho and normal. This means that we also have to show that our vectors are orthogonal.
Which is just going to be .
So indeed our basis vectors are ortho and normal.
We will now use fourier analysis to solve the following problem using the set of orthonormal basis vectors described above.
What we want is a function such that
Okay well lets take the function . I now claim that
With the exception of where the inner product evaluates to . Again this is relatively easy to prove, but slightly tedious.
Then we know that when
This is actually really really good, using the inner product we are able to write the same expression in two different ways.
This gives us that
Yay! we have manage to achieve what Euler did 1735.
If you've managed to follow along then you might realise this means that if for then we can also write
Let's try and approximate the value of this infinite sum and plot the result.
import numpy as np
import matplotlib.pyplot as plt
k = 100
def f(x):
y = 0
for n in range(-k, k+1):
if n == 0:
continue
y += (1j * (-1)**n / n) * np.exp(1j*n*x)
return y
X = np.linspace(-np.pi*1.1, np.pi*1.1, 1000)
Y = np.array([f(x) for x in X])
plt.figure(figsize=(10,10))
plt.plot(X,Y)
xticks = np.arange(-np.pi, np.pi + np.pi/2, np.pi/2)
xtick_labels = [
r'$-\pi$',
r'$-\frac{\pi}{2}$',
r'$0$',
r'$\frac{\pi}{2}$',
r'$\pi$'
]
plt.xticks(xticks, xtick_labels)
plt.xlabel("$x$")
plt.ylabel("$f(x)$")
plt.show()
We call the above infinite sum the fourier series of
We see that we can write any periodic function with period as a linear combination of terms. This means that we can actually write any periodic with a period as a combination of terms. Can we use the same technique as we used before to extract these components out of a periodic function with period ?
Let's consider the set of orthonormal basis vectors , of course it's not really a set of orthonormal basis vectors unless they are normal and pairwise orthogonal and for that we need an inner product because how can you even claim the inner product between two vectors is without defining an inner product first.
Well I claim that the following choice of inner product is what we are looking for
Again the details are not too bad but are the exact same as what we have previously done, so I'll skip over them.
Now the idea of the fourier transform is to take the limit of as approaches infinity. What this means is that our vector space approaches the set of functions which have an infinite period. Which just means any function. We can also think of this as expanding the function domain to
Now our set of orthonormal basis vectors becomes where is very large. This allows us to get to be arbitrarily close to any real number and so we can think of the basis vectors of this new vector-space to be the set of functions for any real number . Which corresponds to the component of a function with frequency .
Using to be a very large number
We can say that the "magnitude" of the component of function with frequency is proportional to
This last part is very hand-wavy but it is a very natural extension of the mathematics used to create fourier series. It can also be seen that we turn the ito two 's which we shift into the basis functions.
But more or less we now see exactly why it is the case that the fourier transform can transform a function in terms of time into a function in terms of frequency. It is because the fourier transform is just the limit of an inner product which extracts out discrete frequency components from a function.
While you can intuitively think that the fourier transform has constructive interference when aligns with the "frequency" of and destructive interference otherwise I think that this is a very useful way to think about the fourier transform but also misses a very cool detail which I think is very sad.