FA 2 | Computing Fourier series
Articles,  Blog

FA 2 | Computing Fourier series

I’d like to talk to you now about
computing Fourier series. Now, just because it’s a computation
doesn’t mean it’s routine or boring. In fact the ideas behind computing Fourier series are the start for much deeper ideas in math, and I think they are pretty interesting in their own right and I hope by the end of the video you’ll agree with me. When we get to the key idea of this computation
we’re going to need the values of some integrals. So let’s discuss those (in order to prepare for that.) Now these integrals will involve some
integers so let’s let ‘k’ and ‘l’ be the positive integers. Now let’s consider the following products of cosines and sines. We’re going to consider ‘cos kx’ times ‘sin lx’ ‘cos kx’ times ‘cos lx’ and ‘sin kx’ times ‘sin lx’. Now the integrals we’re interested in
are integrals of these products over intervals of length ‘2*Pi’. Now I’m going to choose the interval of length 2*Pi
to be the interval [-Pi, Pi] and we will discuss some other intervals.. shortly. Now I realize I’m using the words ‘integral’ ‘interval’ and ‘integer’. (and I apologize for that) Let me go ahead and give you the values
of these integrals and I think you might even be surprised how simple they turn out: The first one no matter what k and l are,
as long they’re positive integers.. I’ll always get ‘0’. The second one depends on k and l, so I break it into two cases: the case in which k is not equal to l ..I get ‘0’, the case in which k equals l I get ‘Pi’. The same goes for the third integral:
I get ‘0’ if k is not equal to l and ‘Pi’ if k equals l. As always I encourage you not to take my word but to do these computations yourself. So I’ll give you that as an exercise: Check these computations. To keep things interesting,
or give you a couple things to think about while you do this exercise: one is is this hypothesis on k and l necessary? So ” what about ” k and l.. less than or equal to ‘0’? Can I still say that the same formulas hold? Another thing to think about would be are there other intervals besides [-Pi,Pi]? So ” what about ” integrals over other intervals [a,b]? can I replace [-Pi,Pi] with some other
‘a to b’ and get the same formulas? I encourage you to pause the video
and do this exercise right now. If you get stuck you can come back
because I’m going to give you a ‘hint’ right now. [PAUSE] I’ll give you a hint
for evaluating this integral with the cosines: ” use a trig identity ” ,,and the trig identity that comes in useful
is the product-to-sum identity for cos: product cos T[heta].cos P[hi] is equal to (1/2) times ‘cos (Theta + Phi)’ plus ‘cos (Theta – Phi)’. We’re ready now to move on
to the big idea behind Fourier series. So taking one last note of these formulas here because
we’re going to need them. Okay we’re ready for the big idea: Let’s suppose that we know what f (x) is and we want to find these Fourier coefficients: ‘a_k’.. ‘b_k’ So suppose that we have the Fourier expansion of f (x). Suppose that f (x) is equal to this
sum of sines and cosines. And this ‘equality’ doesn’t have to be ‘everywhere’:
remember when we did the Fourier expansion [ of y=x ] we found that it was only
‘equal’ on the interval [-Pi, Pi] So let’s suppose that this is at least on the interval [-Pi, Pi] (that’ll be good enough for our purposes.) One more thing to note here is that I put a (‘a 0’/2) instead of ‘a 0’ ..and that’s just a matter of convenience. And you’ll see why I did that in a moment. Now here’s the trick: Let’s take both sides of this expression. Let’s multiply both sides by ‘cos lx’ ..where l is a positive integer. (So you see why I left those little spaces
when I wrote it down.. … I had a plan) I’m going to integrate from -Pi to Pi ..all of these terms.. I’ll pull the constants out, rather than leaving them inside the integrals. I will leave the ‘dx s’ off the ends of these integrals (only because I don’t want to write them) I should point out one little thing which is inconsistent with our notation from the last slide on the last slide we let k and l be positive integers and I want to allow ‘l equals 0’ in this situation So let’s make a note: ” l=0 is allowed “. Okay. What have we got? On the right-hand side we have three types of integrals all of which we can evaluate. So let’s look at them one by one. This one first: this is an integral, from -Pi to Pi, of ‘sin kx * cos lx’ Well. if k and l are positive integers
we know from the last slide that this integral is ‘0’. The only case not covered is when l=’0′ in which case this is the integral of just ‘sin kx’ (which is also zero) so this integral is always equal to ‘0’. What about this one: this looks just like an integral from the last slide if k and l are positive integers then this will be either ‘0’ or ‘Pi’
according to whether k is not equal to .. .. or k equals l So it’s: ‘0’ if ‘k not equals. l’ and it’s: ‘Pi’ if ‘k equals l’ The only situation not covered by the
last slide is when l is ‘0’ and in that case we have just
the integral of ‘cos kx’ (which is zero) So we can have that covered by this situation: ‘k not equals l’. Finally, we have this guy: now this guy is going to be ‘0’ except
in the situation when l is zero, so only in the case ‘l equals 0’ this guy will be: 2*Pi. And now (maybe) you see why I have this (‘a 0’/2):
I want that ‘1/2’ to cancel with this ‘2*Pi’. You may have figured out what we are ‘up to’
at this point: we are multiplying by ‘cos lx’
..and integrating from -Pi to Pi and what that’s doing is essentially
‘picking off’ the a_l coefficient. So, for instance, if l is ‘0’ then this first guy [integral] is the only term which
is non-zero and it’s equal to Pi*’a 0′ If l is ‘1’ then just the first term here
is the only one that’s non-zero and it’s Pi*’a 1′. If l is ‘2’, we get Pi*’a 2′.. etcetera. So no matter what l is:
l =’1′, ‘2’, ‘3’ ‘4’… etcetera this guy is equal to Pi*a_l. Now I’d like to do a similar thing
to find the b_l coefficients. So what I’ll do is take the same sum I had before and instead of multiplying by ‘cos lx’
I will multiply by ‘sin lx’ and integrate again from -Pi to Pi. Now you can see it’s a very similar situation (slightly different) in that now the terms for ‘a 0’ and a_k will drop out and I’ll be left with just the b_k terms. And you can verify the details but it’s not hard to see that you will
get Pi*b_l as a result. I should say, just to be clear, that there is no ‘b 0′ term So this formula that we have here is
only valid for l=’1’, ‘2’, ‘3’… etcetera. In fact if we let l=’0′ in this equality
we just get ‘0’ equals ‘0’ (so it doesn’t tell us anything.) Now let me summarize what it is that we’ve done: We started out with f (x) being a sum of sines and cosines So we know ‘f’ and we want figure out what those coefficients are in that sum of sines and cosines ..we want to figure out the a’s and the b’s. and so by this very clever trick we are able to compute the a’s and the b’s by integrating the product of ‘f (x) and cosine’ or ‘f (x) and sine’ and then of course dividing by ‘Pi’. So this gives us a way to figure out the a’s and the b’s purely by computing a certain integral involving ‘f (x)’. I have summarized all of our computations in an official formula that we can use. So it says that if you want to compute
the Fourier expansion of ‘f (x)’ then the coefficients in the expansion, a_k and b_k,
are given by the following formulas: (1/Pi) times this integral of ‘f (x).cos kx’ and (1/Pi) times this integral of ‘f (x).sin kx’ Now I’ve replaced equality with the ‘twiddle’ [‘~’] again and what I want you to ‘think’ is ..I want you to think of this twiddle [~] as meaning simply equal ‘on an interval’. So remember we had assumed that we
had equality on [-Pi, Pi] and that was how we deduced these formulas. Now I really should point out that it’s not completely correct to say that if I
compute the Fourier series in this manner, using these formulas, then the result will be equal to f (x) on the interval [-Pi, Pi] (that’s not always true) but, for current purposes, we might as well just assume that’s the case. And we’ll discuss more about this later when we talk about convergence of Fourier series. It’s definitely now time for an example, so let’s look back at that Fourier series that we did in the first video that I just simply gave to you: and that was the Fourier series for f (x)=x Let’s compute each a_k and b_k via these formulas. So I know that a_k is going to be given by: (1/Pi) times the integral from -Pi to Pi of ‘x.cos kx’ and b_k similarly will be: (1/Pi) times the integral from -Pi to Pi of ‘x.sin kx’. I claim that the a_k’s are actually easy to compute: they’re all ‘0’. The way we see this is by noticing that x is an ‘odd’ function and ‘cos kx’ is an ‘even’ function for any of our k’s. So the product is an odd function: We’re in integrating an odd function over an
interval which is symmetric about ‘0’ and the result will always be zero. For the b_k’s we need to actually do a computation and that computation is a simple ‘integration by parts’. I’ve done this ahead of time so I’ll tell you
what the answer is: ‘2.(-1)^k+1’ divided by k. And I encourage you to ” check using integration by parts “. (that’s good exercise) And that’s it: we’re done. So, we have that
the Fourier expansion for x is given by this sum: all of a_k’s are zero (including ‘a 0’) and so we just have the b_k’s times sin kx: the b_k’s are given by these formulas. So we have [x=] 2 times the sum [sigma] from k=1 to infinity of ‘(-1)^k+1’ ..divided by k ..times ‘sin kx’. Now if you compare that to the
expression that we had in the last video you’ll find it’s exactly the same. Now I’ve got something for you to try, so here’s an exercise: (and it’s pretty interesting exercise, and not too hard) I want you to compute the Fourier series for x again but do it on a different interval (not the interval [-Pi, Pi]): do it on the interval [0, 2*Pi]. So ” Compute “.. ” Fourier series “.. ” for x on “… ” (0, 2*Pi) “. Now the mechanics of doing this are pretty simple: these formulas can be used. All you have to do is modify them so
that they are valid not on [-Pi, Pi] but on the interval [0, 2*Pi]. You just replace the bounds of integration ..with the appropriate ones. You should go back and check and make sure the computation that we did on the last slide still goes through: ‘nothing funny’ happens. And in fact you should notice
that I can do the computation with any interval of length ‘2*Pi’ –
it doesn’t have to [-Pi, Pi] or [0, 2*Pi] it can be ANY interval of length 2*Pi. Now just so you can check your
computations I’ll tell you what I got and I’ll call it ‘the answer’
(I’m just that confident) I got: ” ‘a 0’/2=Pi ” all the other a_k’s=0 and I got to b_k=(-2)/k and that’s of course for ‘k>=1’. I encourage you to graph this solution using Mathematica or MATLAB [etc] and take a look and see that it actually converges to the function x on the interval [0, 2*Pi] rather than the interval [-Pi, Pi] as this expression does. We’ll conclude with one final example: (and I’ve written it out ahead of time so
you don’t have to watch me scribble) The example is f (x)=| x |
(absolute value x) and we’ll compute the Fourier series on the interval [-Pi, Pi]. So we use the usual formulas for finding the coefficients ‘a_k’ is this integral of | x |.cos kx. Now this integral can be split into two pieces, one piece where x is negative and the
other piece where x is positive, and you can evaluate each of those
pieces using integration by parts. It’s not then hard to arrive it this formula for the coefficient a_k. On the other hand ‘a 0’ I’ll do separately So ‘cos kx’ [k=0] is just ‘1’ and so I get just the integral | x | and that’s ‘Pi’. The b_k’s will all be zero the reason for that is similar to the
reason we learned before which is I have and even function times an odd function (and it’s a symmetric interval) so I always get an integral of zero. Put it all together and we get the following Fourier series for absolute value x (don’t forget to divide the ‘a 0’ term by 2) and I’ve made an animation just to show you the .. successive
terms of the Fourier series and their approximation to | x |: the ‘V’ shape here, of course, is the absolute value function and this is the first term of the Fourier series:
just [constant] ‘Pi’/2. So I’ll begin adding terms: it gets pretty close pretty quick. So there are just six terms and
.. I can’t really see much difference between the two functions so it’s a nice Fourier series. for a maybe not-so-nice function: | x |


Leave a Reply

Your email address will not be published. Required fields are marked *