00:00:04
This right here is what we're going to build to this video,
00:00:07
a certain animated approach to thinking about a super important idea from math,
00:00:11
the Fourier transform.
00:00:13
For anyone unfamiliar with what that is, my number one goal
00:00:16
here is just for the video to be an introduction to that topic.
00:00:20
But even for those of you who are already familiar with it,
00:00:23
I still think that there's something fun and enriching about seeing what all of its
00:00:27
components actually look like.
00:00:29
The central example to start is going to be the classic one,
00:00:32
decomposing frequencies from sound.
00:00:34
But after that I also want to show a glimpse of how this idea extends well beyond
00:00:39
sound and frequency into many seemingly disparate areas of math, and even physics.
00:00:44
Really, it's crazy just how ubiquitous this idea is.
00:00:49
Let's dive in.
00:00:50
This sound right here is a pure A, 440 beats per second,
00:00:54
meaning if you were to measure the air pressure right next to your
00:00:58
headphones or your speaker as a function of time,
00:01:02
it would oscillate up and down around its usual equilibrium in this wave,
00:01:06
making 440 oscillations each second.
00:01:09
A lower pitch note, like a D, has the same structure, just fewer beats per second.
00:01:15
And when both of them are played at once, what do you think the resulting pressure vs.
00:01:19
time graph looks like?
00:01:22
Well, at any point in time, this pressure difference is going to
00:01:25
be the sum of what it would be for each of those notes individually,
00:01:29
which let's face it is kind of a complicated thing to think about.
00:01:33
At some points the peaks match up with each other, resulting in a really high pressure.
00:01:38
At other points they tend to cancel out.
00:01:41
And all in all, what you get is a wave-ish pressure vs.
00:01:44
time graph that is not a pure sine wave, it's something more complicated.
00:01:48
And as you add in other notes, the wave gets more and more complicated.
00:01:53
But right now, all it is is a combination of four pure frequencies,
00:01:57
so it seems needlessly complicated given the low amount of information put into it.
00:02:03
A microphone recording any sound just picks up on the air pressure
00:02:06
at many different points in time, it only sees the final sum.
00:02:10
So our central question is going to be how you can take a signal
00:02:14
like this and decompose it into the pure frequencies that make it up.
00:02:18
Pretty interesting, right?
00:02:20
Adding up those signals really mixes them all together,
00:02:23
so pulling them back apart feels akin to unmixing multiple paint colors that have
00:02:27
all been stirred up together.
00:02:29
The general strategy is going to be to build for ourselves a mathematical machine that
00:02:34
treats signals with a given frequency differently from how it treats other signals.
00:02:40
To start, consider simply taking a pure signal,
00:02:43
say with a lowly 3 beats per second, so we can plot it easily.
00:02:47
And let's limit ourselves to looking at a finite portion of this graph,
00:02:51
in this case the portion between 0 seconds and 4.5 seconds.
00:02:55
The key idea is going to be to take this graph and sort of wrap it up around a circle.
00:03:04
Concretely, here's what I mean by that.
00:03:07
Imagine a little rotating vector where at each point in time
00:03:10
its length is equal to the height of our graph for that time.
00:03:14
So high points of the graph correspond to a greater distance from the origin,
00:03:18
and low points end up closer to the origin.
00:03:22
And right now I'm drawing it in such a way that moving forward 2
00:03:25
seconds in time corresponds to a single rotation around the circle.
00:03:29
Our little vector drawing this wound up graph is rotating at half a cycle per second.
00:03:35
So this is important, there are two different frequencies at play here.
00:03:38
There's the frequency of our signal, which goes up and down 3 times per second,
00:03:42
and then separately there's the frequency with which we're wrapping the graph
00:03:47
around the circle, which at the moment is half of a rotation per second.
00:03:51
But we can adjust that second frequency however we want.
00:03:54
Maybe we want to wrap it around faster?
00:03:58
Or maybe we go and wrap it around slower?
00:04:03
And that choice of winding frequency determines what the wound up graph looks like.
00:04:09
Some of the diagrams that come out of this can be pretty complicated,
00:04:12
although they are very pretty, but it's important to keep in mind that
00:04:15
all that's happening here is that we're wrapping the signal around a circle.
00:04:20
The vertical lines that I'm drawing up top, by the way,
00:04:23
are just a way to keep track of the distance on the original graph that corresponds to
00:04:27
a full rotation around the circle.
00:04:30
So lines spaced out by 1.5 seconds would mean
00:04:33
it takes 1.5 seconds to make one full revolution.
00:04:37
And at this point we might have some sort of vague sense that something special will
00:04:41
happen when the winding frequency matches the frequency of our signal, 3 beats per second.
00:04:46
All of the high points on the graph happen on the right side of the circle,
00:04:49
and all of the low points happen on the left.
00:04:52
But how precisely can we take advantage of that in
00:04:55
our attempt to build a frequency unmixing machine?
00:04:59
Well, imagine this graph is having some kind of mass to it, like a metal wire.
00:05:04
This little dot is going to represent the center of mass of that wire.
00:05:08
As we change the frequency and the graph winds up differently,
00:05:11
that center of mass kind of wobbles around a bit.
00:05:16
And for most of the winding frequencies, the peaks and valleys are all spaced out
00:05:19
around the circle in such a way that the center of mass stays pretty close to the origin.
00:05:26
But when the winding frequency is the same as the frequency of our signal,
00:05:30
in this case 3 cycles per second, all of the peaks are on the right,
00:05:34
and all of the valleys are on the left, so the center of mass is unusually far
00:05:38
to the right.
00:05:42
Here, to capture this, let's draw some kind of plot that keeps
00:05:45
track of where that center of mass is for each winding frequency.
00:05:49
Of course, the center of mass is a two-dimensional thing,
00:05:51
it requires two coordinates to fully keep track of, but for the moment,
00:05:54
let's only keep track of the x-coordinate.
00:05:57
So for a frequency of zero, when everything is bunched up on the right,
00:06:01
this x-coordinate is relatively high.
00:06:03
And then as you increase that winding frequency,
00:06:06
and the graph balances out around the circle, the x-coordinate of
00:06:10
that center of mass goes closer to zero, and it just kind of wobbles around a bit.
00:06:26
But then, at 3 beats per second, there's a spike, as everything lines up to the right.
00:06:44
This right here is the central construct, so let's sum up what we have so far.
00:06:47
We have that original intensity vs time graph,
00:06:50
and then we have the wound up version of that in some two-dimensional plane,
00:06:55
and then as a third thing, we have a plot for how the winding frequency influences
00:07:00
the center of mass of that graph.
00:07:03
And by the way, let's look back at those really low frequencies near zero.
00:07:07
This big spike around zero in our new frequency plot just
00:07:11
corresponds to the fact that the whole cosine wave is shifted up.
00:07:16
If I had chosen a signal that oscillates around zero, dipping into negative values,
00:07:21
then as we play around with various winding frequencies,
00:07:25
this plot of the winding frequency vs center of mass would only have a spike
00:07:30
at the value of 3.
00:07:32
But negative values are a little bit weird and messy to think about,
00:07:35
especially for a first example, so let's just continue thinking in terms of the
00:07:39
shifted up graph.
00:07:41
I just want you to understand that that spike around zero only corresponds to the shift.
00:07:45
Our main focus, as far as frequency decomposition is concerned, is that bump at 3.
00:07:51
This whole plot is what I'll call the almost Fourier transform of the original signal.
00:07:56
There's a couple small distinctions between this and the actual Fourier transform,
00:08:00
which I'll get to in a couple minutes, but already you might be able to
00:08:03
see how this machine lets us pick out the frequency of a signal.
00:08:07
Just to play around with it a little bit more, take a different Fourier signal,
00:08:11
let's say with a lower frequency of 2 beats per second, and do the same thing.
00:08:16
Wind it around a circle, imagine different potential winding frequencies,
00:08:20
and as you do that keep track of where the center of mass of that graph is,
00:08:24
and then plot the x coordinate of that center of mass as you adjust the winding frequency.
00:08:30
Just like before, we get a spike when the winding frequency is the same as
00:08:34
the signal frequency, which in this case is when it equals 2 cycles per second.
00:08:39
But the real key point, the thing that makes this machine so delightful,
00:08:43
is how it enables us to take a signal consisting of multiple frequencies and pick out
00:08:48
what they are.
00:08:49
Imagine taking the two signals we just looked at,
00:08:51
the wave with 3 beats per second and the wave with 2 beats per second, and add them up.
00:08:56
Like I said earlier, what you get is no longer a nice pure cosine wave,
00:08:59
it's something a little more complicated.
00:09:02
But imagine throwing this into our winding frequency machine.
00:09:06
It is certainly the case that as you wrap this thing around it looks a
00:09:09
lot more complicated, you have this chaos and chaos and chaos and chaos,
00:09:12
and then whoop, things seem to line up really nicely at 2 cycles per second.
00:09:16
Then as you continue on it's more chaos and more chaos and more chaos and chaos
00:09:20
and chaos and chaos, whoop, things nicely align again at 3 cycles per second.
00:09:23
And like I said before, the wound up graph can look kind of busy and complicated,
00:09:27
but all it is is the relatively simple idea of wrapping the graph around a circle.
00:09:31
It's just a more complicated graph and a pretty quick winding frequency.
00:09:36
Now what's going on here with the two different spikes is that if you were to
00:09:40
take two signals and then apply this almost Fourier transform to each of them
00:09:45
individually, and then add up the results, what you get is the same as if you
00:09:49
first added up the signals and then applied this almost Fourier transform.
00:09:55
And the attentive viewers among you might want to pause and ponder
00:09:58
and convince yourself that what I just said is actually true.
00:10:01
It's a pretty good test to verify for yourself that it's clear
00:10:04
what exactly is being measured inside this winding machine.
00:10:09
Now this property makes things really useful to us,
00:10:11
because the transform of a pure frequency is close to zero everywhere except
00:10:16
for a spike around that frequency, so when you add together two pure frequencies,
00:10:20
the transform graph just has these little peaks above the frequencies that went into it.
00:10:26
So this little mathematical machine does exactly what we wanted.
00:10:29
It pulls out the original frequencies from their jumbled up sums,
00:10:33
unmixing the mixed bucket of paint.
00:10:36
And before continuing into the full math that describes this operation,
00:10:40
let's just get a quick glimpse of one context where this thing is useful, sound editing.
00:10:44
Let's say that you have some recording and it's got an
00:10:47
annoying high pitch that you would like to filter out.
00:10:50
Well at first your signal is coming in as a function of various intensities over time,
00:10:55
different voltages given to your speaker from one millisecond to the next.
00:10:59
But we want to think of this in terms of frequencies.
00:11:02
So when you take the Fourier transform of that signal,
00:11:05
the annoying high pitch is going to show up just as a spike at some high frequency.
00:11:11
Filtering that out by just smushing the spike down,
00:11:13
what you'd be looking at is the Fourier transform of a sound that's just like your
00:11:18
recording, only without that high frequency.
00:11:21
Luckily there's a notion of an inverse Fourier transform that tells
00:11:24
you which signal would have produced this as its Fourier transform.
00:11:29
I'll be talking about that inverse much more fully in the next video,
00:11:32
but long story short, applying the Fourier transform to the Fourier
00:11:36
transform gives you back something close to the original function.
00:11:40
Kind of, this is a little bit of a lie, but it's in the direction of truth.
00:11:44
And most of the reason it's a lie is that I still have yet to
00:11:47
tell you what the actual Fourier transform is,
00:11:50
since it's a little more complex than this x-coordinate of the center of mass idea.
00:11:55
First off, bringing back this wound up graph and looking at its center of mass,
00:11:59
the x-coordinate is really only half the story, right?
00:12:02
I mean, this thing is in two dimensions, it's got a y-coordinate as well.
00:12:05
And as is typical in math, whenever you're dealing with something two-dimensional,
00:12:10
it's elegant to think of it as the complex plane,
00:12:12
where this center of mass is going to be a complex number that has both a real
00:12:16
and an imaginary part.
00:12:21
And the reason for talking in terms of complex numbers,
00:12:23
rather than just saying it has two coordinates,
00:12:25
is that complex numbers lend themselves to really nice descriptions of
00:12:29
things that have to do with winding and rotation.
00:12:32
For example, Euler's formula famously tells us that if you take e to some number times i,
00:12:37
you're going to land on the point that you get if you were to walk that number of
00:12:42
units around a circle with radius 1 counterclockwise starting on the right.
00:12:47
So imagine you wanted to describe rotating at a rate of 1 cycle per second.
00:12:54
One thing you could do is take the expression e to the 2 pi times i times t,
00:12:59
where t is the amount of time that has passed, since for a circle with radius 1,
00:13:04
2 pi describes the full length of its circumference.
00:13:08
And this is a little dizzying to look at, so maybe you want to describe
00:13:12
a different frequency, something lower and more reasonable,
00:13:16
and for that you would just multiply that time t in the exponent by the frequency f.
00:13:21
For example, if f was 1 tenth, then this vector makes one full turn every 10 seconds,
00:13:27
since the time t has to increase all the way to 10 before the full exponent looks like 2
00:13:33
pi i.
00:13:34
I have another video giving some intuition on why this is the
00:13:37
behavior of e to the x for imaginary inputs, if you're curious,
00:13:40
but for right now we're just going to take it as a given.
00:13:44
Now why am I telling you this, you might ask?
00:13:46
Well it gives us a really nice way to write down the idea
00:13:49
of winding up the graph into a single tight little formula.
00:13:53
First off, the convention in the context of Fourier transforms is to think about
00:13:58
rotating in the clockwise direction, so let's throw a negative sign up into that exponent.
00:14:04
Now take some function describing a signal intensity versus time,
00:14:08
like this pure cosine wave we had before, and call it g of t.
00:14:12
If you multiply this exponential expression times g of t,
00:14:16
it means that the rotating complex number is getting scaled up and down according to
00:14:21
the value of this function.
00:14:24
So you can think of this little rotating vector with
00:14:27
its changing length as drawing the wound up graph.
00:14:31
So think about it, this is awesome, this really small expression
00:14:35
is a super elegant way to encapsulate the whole idea of
00:14:38
winding a graph around a circle with a variable frequency, f.
00:14:43
And remember, the thing we want to do with this wound up graph is to track
00:14:47
its center of mass, so think about what formula is going to capture that.
00:14:51
Well, to approximate it at least, you might sample a whole bunch of times
00:14:55
from the original signal, see where those points end up on the wound up graph,
00:15:00
and then just take an average, that is, add them all together as complex numbers,
00:15:05
and then divide by the number of points you've sampled.
00:15:09
This will become more accurate if you sample more points which are closer together.
00:15:14
And in the limit, rather than looking at the sum of a whole bunch of
00:15:18
points divided by the number of points, you take an integral of this
00:15:21
function divided by the size of the time interval we're looking at.
00:15:25
The idea of integrating a complex valued function might seem weird,
00:15:29
and to anyone who's shaky with calculus maybe even intimidating,
00:15:32
but the underlying meaning here really doesn't require any calculus knowledge.
00:15:36
The whole expression is just the center of mass of the wound up graph.
00:15:41
So great, step by step, we have built up this kind of complicated but let's face it,
00:15:46
surprisingly small expression for the whole winding machine idea I talked about,
00:15:51
and now there is only one final distinction to point out between this and the actual
00:15:56
honest-to-goodness Fourier transform, namely, just don't divide out by the time interval.
00:16:02
The Fourier transform is just the integral part of this.
00:16:06
What that means is that instead of looking at the center of mass,
00:16:09
you would scale it up by some amount.
00:16:11
If the portion of the original graph you were using spanned 3 seconds,
00:16:15
you would multiply the center of mass by 3.
00:16:19
If it was spanning 6 seconds, you would multiply the center of mass by 6.
00:16:25
Physically, this has the effect that when a certain frequency persists for a long time,
00:16:30
then the magnitude of the Fourier transform at that frequency is scaled up more and more.
00:16:36
For example, what we're looking at here is how when you have a pure frequency of 2
00:16:40
beats per second and you wind it around the graph at 2 cycles per second,
00:16:45
the center of mass stays in the same spot, just tracing out the same shape.
00:16:49
But the longer that signal persists, the larger the value of the Fourier transform
00:16:54
at that frequency.
00:16:56
For other frequencies, even if you just increase it by a bit,
00:16:59
this is cancelled out by the fact that for longer time intervals,
00:17:02
you're giving the wound-up graph more of a chance to balance itself around the circle.
00:17:08
That is a lot of different moving parts, so let's
00:17:11
step back and summarize what we have so far.
00:17:14
The Fourier transform of an intensity vs.
00:17:17
time function, like g of t, is a new function, which doesn't have time as an input,
00:17:22
but instead takes in a frequency, what I've been calling the winding frequency.
00:17:28
In terms of notation, by the way, the common convention is to
00:17:31
call this new function g-hat with a little circumflex on top of it.
00:17:35
The output of this function is a complex number,
00:17:38
some point in the 2d plane that corresponds to the strength of a given
00:17:43
frequency in the original signal.
00:17:46
The plot I've been graphing for the Fourier transform is just the real
00:17:49
component of that output, the x-coordinate, but you could also graph
00:17:53
the imaginary component separately if you wanted a fuller description.
00:17:57
And all of this is encapsulated inside that formula we built up.
00:18:01
And out of context, you can imagine how seeing this formula would seem sort of daunting,
00:18:07
but if you understand how exponentials correspond to rotation,
00:18:10
how multiplying that by the function g of t means drawing a wound up version of the
00:18:15
graph, and how an integral of a complex valued function can be interpreted in terms
00:18:20
of a center of mass idea, you can see how this whole thing carries with it a very rich
00:18:25
intuitive meaning.
00:18:27
And by the way, one quick small note before we can call this wrapped up.
00:18:30
Even though in practice, with things like sound editing,
00:18:33
you'll be integrating over a finite time interval,
00:18:36
the theory of Fourier transforms is often phrased where the bounds of this
00:18:40
integral are negative infinity and infinity.
00:18:43
Concretely, what that means is that you consider this expression
00:18:46
for all possible finite time intervals, and you just ask,
00:18:49
what is its limit as that time interval grows to infinity?
00:18:54
And man oh man, there is so much more to say.
00:18:57
So much, I don't want to call it done here.
00:18:58
This transform extends to corners of math well
00:19:01
beyond the idea of extracting frequencies from signal.
00:19:04
So the next video I put out is going to go through a couple of these,
00:19:06
and that's really where things start getting interesting.
00:19:10
So stay subscribed for when that comes out, or an alternate option
00:19:13
is to just binge on a couple 3Blue and Brown videos so that the
00:19:16
YouTube recommender is more inclined to show you new things that come out.
00:19:19
Really the choice is yours.
00:19:22
And to close things off, I have something pretty fun,
00:19:25
a mathematical puzzler from this video's sponsor, Jane Street,
00:19:28
who's looking to recruit more technical talent.
00:19:31
So let's say that you have a closed bounded convex set C sitting in 3D space,
00:19:36
and then let B be the boundary of that space, the surface of your complex blob.
00:19:42
Now imagine taking every possible pair of points on that surface and adding them up,
00:19:47
doing a vector sum.
00:19:48
Let's name this set of all possible sums D.
00:19:52
Your task is to prove that D is also a convex set.
00:19:57
So Jane Street is a quantitative trading firm,
00:19:59
and if you're the kind of person who enjoys math and solving puzzles like this,
00:20:03
the team there really values intellectual curiosity,
00:20:05
so they might be interested in hiring you.
00:20:08
And they're looking both for full-time employees and interns.
00:20:11
For my part, I can say the couple of people I've interacted with there just
00:20:14
seem to love math and sharing math, and when they're hiring,
00:20:17
they look less at a background in finance than they do at how you think,
00:20:20
how you learn, and how you solve problems, hence the sponsorship of a 3Blue1Brown video.
00:20:25
If you want the answer to that puzzler, or to learn more about what they do,
00:20:29
or to apply for open positions, go to janestreet.com slash 3b1b.
00:20:41
Thank you.