In this video we are gonna consider
how fast a Fourier series converges
to its target. So we are talking about
periodic Fourier series or periodic
function with period L and we know
that we can write it as a sum of
complex exponentials. If you prefer,
you can use cos and sin of 2πinx/L.
I prefer to write it as complex 
exponential. And we know
how to get the coefficients. You get them
by integrating 1/ L  times f(x) times  exp(-2 pi inx/L).
And the big question is, if you want to
approximate a function, how many
terms you need? Is it good enough
to just use 5 terms? You need 10?
100? 1000?
Another way to put that is how fast
do the coefficients shrink?
If they shrink really fast, you only
need the first few.
If they shrink slowly, you are gonna
need a lot of them.
So the basic rule is that the smoother
the function is, the faster the Fourier
coefficients decay. In particular,
if you have a jump in the kth derivative,
if the worst thing that happens to f
is that its kth derivative jumps,
then typically the Fourier coefficient 
go as 1/n^(k+1).
If it's infinitely differentiable,
there are no jumps at all, you can
take derivatives as long as you like.
Then it decays faster than any power of n.
No matter how big p is, n^p * f hat of n
goes to 0.
And if it's analytic, meaning that it can 
be expressed as a convergent power series,
then these not only decay faster than
the power. They decay exponentially fast.
Okay, so let's see why this might be.
The key observation is how derivatives
work? You see if a function is given
as a Fourier series, then you take
a derivative, you just take the derivative
of each term. The derivative of
this exponential is the exponential
times what's inside.
In other words, the nth Fourier 
coefficient of the derivative of f
is just 2πin/L * nth Fourier coefficient
of f. And you can continue to process
the nth Fourier coefficient of the kth
derivative, you just pick up k factor
of 2πin/L.
Now the second big observation 
has to do with interproducts.
We saw in our previous video that
the interproduct of f with itself,
was 1/L times the sum of (f-hat n)^2.
Now, if the kth derivative exists
and is (inaudible), then...
Sorry not 1/L. L.
Then the, 1/L times the interproduct
of the kth derivative of itself,
is gonna be the sum of the Fourier
coefficients of the kth derivative.
And those squared and that's gonna
be (2π/L)^2k * sum of n^2k (f-hat n)^2.
In other words, this sum converges.
If you got kth derivatives, then this sum
has to converge and if this sum converges,
then the coefficients f-hat n have to
decay faster than (1/n)^k. And typically,
if you are on the border line,
the decay is 1 / (n ^ k+1). So let's
take a look at some examples of this.
In our first example, we looked at
the stepped function. So the function
whose value is, will take L = 1
and the function that's 1 up to a half,
and then is -1 from a half to 1.
And then repeats. It's 1 from 1
to 1 and a half and it's -1 from 1 and
a half to 2. Then it's 1 from 2 to 2
and a half. -1 from 2 and a half to 3.
And so on. Now this function
obviously is discontinuous. It jumps
up at integers and jumps down at
half integers. So since the 0 derivative
has jumps, you expect the Fourier
coefficient to go as 1/n and if you do
the actual calculation, the nth
Fourier coefficient is the integral of
from 0 to half of f(x), that's 1.
Times this complex exponential,
plus the integral from 1 half to 1 of
f(x). That's -1. Times the complex
exponential. And it works out
to -2i / nπ for an odd and 0 for an even.
And you see that this decays like 1/n.
What that means is that the 100th
term is only a factor of 100 smaller
than the first term. If you want to get
99% accuracy, you better take at least
100 terms because that 100th term
is gonna give you a 1% correction.
So doing Fourier series with this
kind of function is not all that
effective, because it just takes
way too many terms to get
anything useful. Now next example
is we
consider the tent function. It goes
x, 1 - x and then it repeats.
Goes up and down and up and down
and up and down. In fact the derivative
of this function is this function.
Well, this has a discontinuous first
derivative. So you should expect
the coefficients to go as 1/ n^2
and in fact they do.
The coefficients are 1/4 for n = 0.
-1/ (nπ) for n odd and 0 for n even.
Now the 100th term is, sorry
the 10th is 100 times smaller
than the leading term. You only need
roughly 10 terms to get 99% accuracy.
Much more efficient. It's much
easier to take 10 terms than 100.
Our last example, is we will look at
something that at first glance,
looks pretty smooth. We will
take a parabola between 0 and 1
and then we will take a different
parabola between 1 and 2.
So this is gonna be periodic 
with period 2, rather than with
period 1. But the second derivative
is discontinuous. The second
derivative of this function is -1. 
It's always curving down.
Sorry -2. It's always curving down
between 0 and 1, then it's +2.
It's always curving up between
1 and 2. The second derivative
is discontinuous, so you should
expect the coefficients to go
as 1 / n^3. To get 99% accuracy.
you probably need only about 5 terms.
Bottom line, the smoother the function
is, the better Fourier series works.
If you're starting off with a very smooth
function, then you only need
a handful of terms to get a very very
good approximation to it.
You start with a rough function,
the Fourier series doesn't work
nearly as well.
