- Thank you to Curiosity Stream for sponsoring this episode.
Get access to my streaming video service Nebula
when you sign up for Curiosity Stream
using the link in the description.
Hello, welcome to "Up and Atom". I'm Jade.
Did you know that you can write any function
just by summing up sine and cosine waves?
Thrilling, isn't it?
This is known as the Fourier series,
and it, along with an accompanying idea,
the Fourier transform, can be found in everything
from digital music, to quantum mechanics,
to image recognition.
If you've never heard of the Fourier series before
you might be skeptical.
Can we really write any function
in terms of sine and cosine functions?
They have a very smooth, wavy shape,
so how would you make something like this square wave,
which has sharp corners?
First, let's take a step back.
What happens when we add two functions together?
If sine X looks like this
and sine three X looks like this,
a regular sine function with a smaller frequency,
then sine X plus sine three X takes the Y values
of each function at each value of X
and adds them together.
For example, at three pi on four,
sine X is equal to one on root two
and sine three X is also equal to one on root two.
So adding them together gives us root two.
At pi on two,
sine X is one and sine three X is negative one.
So when we add them together, we get zero.
If we do that with all the values,
this is the resulting graph.
When the original functions are both positive,
the sum gets bigger.
And when one is positive and the other negative,
the functions can cancel each other out.
This may already look slightly closer to a square wave
than a sine wave does.
Now let's try giving sine three X a smaller amplitude.
Then the added functions would look like this.
This is already much closer to the square wave.
By adding more and more terms
it will get closer and closer to the square wave.
Fourier series are infinite sums,
meaning you can add infinitely many waves
so you will always reach an exact solution.
Another example is the Fourier series of a sawtooth wave.
The first few terms are sine X
minus half sine two X
plus 1/3 sine three X.
When we keep adding terms
we can see the sawtooth wave taking form.
Now, you may be wondering, what's the point?
If it's just a different way to write the same thing,
why bother?
Especially if it means dealing with an infinite sum?
Well, in practice, we often don't need a perfect solution,
we just need a solution
that's good enough for our application.
Like if we had these two functions
and we wanted to write a program
that could tell the difference between them.
The first few terms of the square wave Fourier series
are sine X plus zero sine two X plus 1/3 sine three X,
while the first few terms of the sawtooth wave
are sine X minus 1/2 sine two X plus 1/3 sine three X.
Simply by knowing the amplitude of that second term,
the program would know which was which.
Now, while it comes to the simple example
of finding the difference
between a square wave and a sawtooth wave,
finding the Fourier series
might be more work than it's worth.
But the idea can be extended
to pattern and shape recognition in general.
If you take two objects like an apple and a slice of pizza,
their outlines can be analyzed using this technique
to figure out which is which.
Fourier analysis is an important tool
in image analysis and shape recognition.
The trickiest part of this whole process
is trying to figure out how to find the Fourier series,
or in other words, which waves will add up correctly
to make the shape you want.
After all, how would you go about adding waves together
to make a pizza shape,
or knowing which frequencies get added into a square wave?
It's almost like asking someone
to figure out the instructions
for how to put individual atoms together to make your body.
But before we talk about that,
let's look at one more useful feature of the Fourier series.
Our original square wave function
tells us how the function changes with time,
while the Fourier series is a sum of different frequencies.
Now, imagine if you have a recording
with a high pitch sound that you want to get rid of.
(piano music) (tone screeching)
If you found the Fourier series of that recording,
you could just get rid of the terms of the sum
that are associated with the high pitched sound,
add the sum back up,
and get your original recording
without the distracting high pitch.
There's a tool associated with the Fourier series
called the Fourier transform.
It can be used to pick out which frequencies,
or which sines and cosines, go into the Fourier series.
More powerfully, it can be used to pick out
and remove frequencies from a function
as we just did with the audio recording,
even without needing to find the Fourier series.
The basic idea of the Fourier transform
is that you feed it your amplitude versus time function
and it spits out the same function
as an amplitude versus frequency function.
This is because the Fourier transform
decomposes the function into sine and cosine waves
but we only really care
about the amplitude and frequency pairing.
If we were to graph all the sine and cosine waves like this,
as we have been doing, that's pretty messy.
We're only interested in the frequencies and amplitudes,
so let's rewrite the decomposition
in terms of just those two properties.
Here we've just collapsed each wave into a bar
representing its amplitude on the Y axis
and its frequency on the X axis.
This is how the Fourier series is typically represented.
So to sum it up, the output of the Fourier transform
is nothing more than a frequency domain view
of the original time domain function.
So if I go back to our first few terms
of the Fourier series of a square wave,
we expect sine X zero sine two X and 1/3 sine three X.
This new function, which is dependent on frequency,
gets large at the frequency associated with sine X,
is zero at the frequency associated with sine two X,
and has a spike at the frequency
associated with sine three X, though of a smaller amplitude.
To understand how the Fourier transform figures out
how much of each sine or cosine is in the Fourier series,
let's look at how the Fourier transform works.
The mathematical equation for the Fourier transform
is surprisingly simple, given its power.
Here F of omega is the Fourier transform
from which we get the Fourier series.
Notice how it's the subject of the equation,
the thing we're trying to find.
So basically, if we do all of this stuff
we can figure out the Fourier series.
So what is all of this stuff?
F of X is the time function
we're calculating the Fourier series for.
Then we have this exponential term, and an integral.
Why would multiplying the time function
by an exponential term
and taking the integral of that result
give us the sine and cosine waves
that that function is made of?
Well, there's a famous result in mathematics
called Euler's Formula.
It tells us that you can write this exponential
in terms of sine and cosine waves.
This is a very beautiful result,
and there are already a lot of great videos about it
which I've linked in the description.
So that's where the sine and cosine waves
come into the Fourier transform equation.
But still, why would multiplying the original time function
by this sine and cosine term and taking the integral
tell us the frequencies
that make up the original time function?
To understand, let's do an example.
Say we want to know whether a wave with frequency three
is used to make up this square wave,
and if so, how much of it?
Like will we need its full amplitude,
a quarter of its amplitude?
The reason we have an imaginary component
is to handle the general case
where there may be different phases necessary
to make up the function.
But this square wave starts in phase
with all sine waves at X equals zero,
so we know we won't need any of that.
So without loss of generality, we can drop the cosine term
and treat the sine term as the real component.
This term is telling us
to multiply each Y value of the square wave
with the same Y value of the sine wave.
The value it returns
will tell us how correlated the waves are,
or, more scientifically, how much they groove together.
Like at pi on six, the square wave has a value of one
and the sine wave has a value of one, so we get one.
At pi on four,
we get a positive value less than one.
This tells us that the waves are more correlated
at pi on six than at pi on four, which we can see is true.
When the waves are correlated,
the multiplication will always return a positive value.
When the waves are anti-correlated
the multiplication will return a negative value.
And when the waves aren't correlated at all,
it will return a zero.
Now we come to the integral,
which is the continuous version of a sum.
The sum of all of these values
will tell us whether this sine wave
is necessary to build the square wave.
If the sum is positive, the waves are overall correlated,
and this sine wave is in the Fourier series
of this square wave.
If the sum is zero, the waves are not correlated at all,
and none of this wave is used to make up the square wave.
If the sum is negative,
the waves are overall anti-correlated,
which is kind of like grooving upside down.
So the negative of the sine wave
goes into the Fourier series.
It turns out that the sum is positive,
so sine three X does indeed
go into the making of this square wave.
But how much of it?
After normalization, we get a value of 1/3.
This tells us that only 1/3 of the amplitude of sine three X
is used to make the square wave.
And when we compare with our earlier example,
we do indeed see the term 1/3 sine three X.
So to recap, the multiplication tells us
how correlated the waves are at each time step,
and the integral tells us how correlated
the waves are overall.
Now notice how the square wave is made up
of only odd sine terms, and it's pretty easy to see why.
For every period of the square wave,
there are always two more correlation humps
than anti-correlation humps,
so the sum will always add to a positive number.
Whereas with even frequencies,
the positive and negative humps exactly cancel out,
leaving us with a sum of zero.
This is also why we don't see
any cosine waves in the series.
The Fourier transform
does this same process for any frequency,
thereby telling us which frequencies
go into any specific function.
I think this process is super beautiful.
You can also think of it
as changing the basis of the function
in an infinite dimensional space.
That was a jargon dump, so let's break it down.
Just like we can change the basis of a vector space,
choosing new coordinates to describe the same vector,
we can also change the basis in function space.
We started with a function expressed as amplitudes
at an infinite number of time positions,
and we changed the basis
so that it was described in terms of amplitudes
at an infinite number of frequency values.
This is only possible because our sine and cosine waves
make up an orthogonal basis,
which is just a fancy way of saying they can be combined
to make any function in function space,
the same way an orthogonal vector basis
can be combined to make any vector in a vector space.
Transforming functions back and forth
between bases is super useful
in lots of areas of math and engineering,
but the pure algebraic treatment only works
if you have a mathematical description
of the input function.
Often in real world applications
you only have the raw data to work with.
Right now your computer is using Fourier transforms
to play this video,
but it has to handle the messiness of the real world's data.
For that, we need to write algorithms.
Algorithms are step by step instructions
that break down a really complicated process
into small, manageable tasks.
The pattern recognition
and audio engineering example we used
would both need an algorithm to work.
It might amaze you how many algorithms are working
quietly behind the scenes in our everyday lives.
There's a great documentary on Curiosity Stream
called "The Secret Rules of Modern Living",
which explores how these algorithms work,
from how TV streaming services choose
which shows to recommend to you,
to matching profiles on dating websites,
to saving lives with the best kidney transplant solution.
I was surprised at just how simple and clever
some of these algorithms are,
but also at how effective they are
in helping us make the best decisions.
If you're interested in learning more,
you can watch this documentary for free
by signing up to Curiosity Stream
with the link in the description.
Curiosity Stream is an award-winning documentary service
with thousands of titles, from space exploration,
to the history of mathematics, to engineering of the future.
They're also supporting
a bunch of us educational YouTube creators
with our own streaming platform, Nebula.
Where Curiosity Stream
is all about big budget documentaries,
we are building Nebula because we want a place
for education-y creators to try out new content ideas
that might not work on YouTube.
I've made a documentary
about whether math is invented or discovered,
which you can check out if you like.
Curiosity Stream loves independent creators
and wants to help us grow our platform,
so they're offering "Up and Atom" viewers
free access to Nebula
when you sign up at curiositystream.com/upandatom.
They're also offering a 26% discount
to "Up and Atom" viewers,
so that's two streaming services for just $14 79 for a year.
By signing up to Curiosity Stream,
you will be helping not just me,
but the entire educational community.
Thank you for watching,
and thank you to all my Patreon supporters.
I'll see you in the next episode. Bye.
(techno music)