The Fourier Coefficients applet lets us explore the approximation of periodic functions by Fourier series. This is the opening screen of the applet. On the right, you see a series of sliders controlling coefficients. And they're the coefficients of the sine terms in a Fourier series, as you can see by clicking this formula box.
So at this point, what we're studying is an odd function, a sine series, and the sliders let us control the coefficients of sine of k*t. If I click the cosine box, I'd see coefficients of the cosine functions.
Let's go back to sine and start to play with the tool a little bit. What will happen if I move the b_2 slider? I should get multiples of the sine of 2t showing up on my graphing window. If I push b_2 to the right, I get positive multiples of the sine of 2t. The sine of 2t goes through two full periods when t ranges from 0 to 2pi. And if b_2 is negative, I get negative multiples of the sine of 2t.
What happens if I change b_1 in this tool? This will add a multiple of the sine of t to the function that I already have. If I push this to the right, I'm going to get positive multiples of the sine of 2t, and you can see the alteration in the yellow graph when I do that. When I push b_1 to the left, I'm adding negative multiples of the sine of t.
You get quite a variety of interesting functions by playing with these various sliders. But it's even more fun to try to match a target periodic function by means of sine or cosine series. And the tool has built into it a whole family of target functions to try for.
Right now, the target function is 0. But we can select target A instead, and what we have now is a square wave. Actually, this isn't the standard square wave that we deal with in the course, quite. It is periodic, of period 2pi, and alternates between positive and negative values, but those values are pi over 4 and minus pi over 4, instead of plus 1 and minus 1, as they are for the standard square wave. That's chosen so that the Fourier coefficients come out more neatly, as we'll see.
So let's try to approximate this function by a finite trigonometric sum. I'm going to push the Reset key here to reset all the coefficients to zero, and start trying to match the function that I have at hand with multiples of sine of k*t. Let's begin with the sine function itself, sine of t.
Well, I don't know what to do. Let's just set it so the maxima coincide. Why not? Maybe that will be an appropriate amount of the sine of t function to put into the pot when I'm trying to mix up the square wave.
Let's go on to b_2 now. I'm going to push the b_2 slider to the right. When I do that, you see a hump forming on the left-hand side of the positive part of the square wave. If push b_2 to the left, the same kind of hump forms on the right-hand side of that positive part of the square wave.
Neither one of them seems to be doing us very much good. And in fact, it's creating an asymmetry in the Fourier series that's not present in our target function. It's not respecting the symmetry that you see around pi over 2 in the square wave itself.
So I suspect that b_2 is not going to be useful to us, that the sine of 2t is not going to be a constituent in the Fourier series for square wave. In fact, I think that none of the even sines will be of any use to us. And I can get rid of them and look only at the odd terms by clicking this Odd Terms box.
This leaves the sine function that we had in place. It eliminates all the odd terms in the series. It eliminates all the even coefficients and leaves us only with the odd ones. But there are more of them, so we should be able to do a better job of approximating the square wave.
So let's continue. Let's try changing b_3 to get a good approximation. Well, I could push b_3 to the left, and I get a sharper spike in the middle. That doesn't look too good. It looks better to push b_3 to the right and flatten out the top. But when I do that, the top becomes too low.
And so maybe I made a mistake in choosing b_1 so that the maxima agreed. Maybe I should have made b_1 a little bit bigger. Now you can see the white curve there-- that's giving me the multiple of the sine wave itself, the one that I'm controlling by this slider. And I guess I should push it up so that my flat part comes closer to the top of the square wave. Maybe that's a better approximation.
Well, I can continue playing this game, trying out various multiples of higher sine functions, and going back to try to fix up what I had before. In fact, what we should be trying to do is create a least squares fit. You should try to look at the root-mean-square distance between the Fourier series and the target function, and minimize that distance. That distance can be read out in this tool by clicking the Distance button down here. And so the root-mean-square distance between the green curve and the yellow one is 0.24 and so on, in this case.
Let me come down here and kill the formula. We know the formula well now, and it makes the screen a little less cluttered if we get rid of it. And let me reset the values of the coefficients to zero, and start to try to approximate this square wave again by watching the root-mean-square distance between the Fourier series that I'm creating and the target function.
So I'll start with b_1 in this case, If I move it down, the distance increases. If I move it up, the distance decreases more and more slowly. But now when b_1 becomes greater than one, it starts to increase. So let me push it down again. I can use these little arrow keys to step the value of b_1. That's very convenient. I'm just watching the root-mean-square distance, this number up here. I'm trying to make that as small as possible. It's a measure of the closeness of fit.
Ah, it just started to increase again. Let me step up. And I found the value of one. I didn't set it to one. I set it to the value that minimized this number. And that's the right quantity of the sine wave to put in, if you want to mix up the square wave, or rather pi over 4 times the square wave.
Let's look at b_3. Again, if I decrease b3, things get worse. The root-mean-square distance increases. But if I increase b_3 above the value of zero, that number is getting smaller. Now it's growing again. I think I'll stop there and use these arrow keys. That's better, that's better, that's better, that's worse. Let me go back. And I find the value 0.33 for b_3. That's the optimal amount of the sine of 3t to put in if you want to mix up the formula for this square wave.
I'll do one more. Any guesses for what the optimal value of b_5 should be? It's not going to be negative. That will increase the root-mean-square distance. Let's push it up in the positive direction. That's about right. That's worse, that's better, that's better, better, better, worse. I come down here. That's optimal.
We've discovered by experimentation with this applet that the optimal value of b_5 is 0.200. Each one of these coefficients seems to have optimal value equal to the reciprocal of the index. 1/3 in this case, 1 in this case, 1/5 in this case. And I predict that the optimal value of b_7 is going to be 1/7, which is about 0.14. There you go. it's right in there.
So this applet lets you understand the true meaning of the Fourier coefficients. They're the multiples of the sine waves or the cosine waves which give you the optimal fit, in terms of a finite Fourier series, to the target function.