> restart;

Fourier Polynomials and Series

>

Fourier Polynomials

Fourier polynomials provide a way of approximating general periodic functions by sums of very simple periodic functions, namely the familiar sine and cosine functions, shifted and scaled. We will consider functions, f(x), that are 2 [Maple Math] -periodic, so that f(x + [Maple Math] ) = f(x). For example, any function of the form [Maple Math] or [Maple Math] , where k is a positive integer while [Maple Math] and [Maple Math] are constants, is 2 [Maple Math] -periodic, although it may have a smaller period. That is, the period of , say, [Maple Math] is [Maple Math] , so that it repeats after every interval of length [Maple Math] , but then of course it repeats after every interval of length 2 [Maple Math] . The integer k gives the frequency of the sine or cosine function, so large values of k correspond to very wiggly graphs. The numbers [Maple Math] and [Maple Math] give the amplitudes . Recall also that the graph of cos(x) is obtained from the graph of sin(x) by a horizontal shift of [Maple Math] /2, and the graph of Acos(kx) is likewise obtained from the graph of Asin(kx) by a horizontal shift of length [Maple Math] /(2k). What do you get if you shift the graph of Asin(kx) horizontally by some other distance? It turns out that any such horizontal shift of Asin(kx) can be represented in the form

(1) [Maple Math]

where the amplitude A is equal to [Maple Math] . Functions of the form (1) are convenient to work with. Sums of such functions, with possibly an added constant which we denote by [Maple Math] , are called Fourier polynomials. Thus a Fourier polynomial of degree n is a function of the form F(x) =

[Maple Math] .

A Fourier polynomial can be specified by giving the Fourier coefficients [Maple Math] , ... . For example, suppose [Maple Math] , with all other coefficients being 0. The corresponding Fourier polynomials is then

F(x) = [Maple Math] . Let's graph the three functions [Maple Math] , [Maple Math] , and F(x) on the same axes:

> plot([1+cos(x)/2,cos(8*x)/8+sin(8*x)/8,1+cos(x)/2+cos(8*x)/8+sin(8*x)/8], x=-Pi..Pi, color=[blue, green,black]);

[Maple Plot]

>

Note that we only graphed between [Maple Math] and [Maple Math] , a practice we will continue throughout the worksheet. Observe that the high frequency term is a shifted sine with amplitude [Maple Math] ~ 0.177 and that the graph of F(x) is the superposition of this high frequency graph with that of the vertically shifted cos(x)/2.

It will be convenient to specify the Fourier coefficients by giving the constant term [Maple Math] , and then two lists for the coefficents [Maple Math] , and [Maple Math] . The procedure FPoly defined below, takes the constant term , the two lists and the degree and returns the Fourier polynomial as an expression. For our example, the coefficient list for the a's is [1/2,0,0,0,0,0,0,0,0,1/8] while the coefficient list for the b's is [0,0,0,0,0,0,0,0,0,1/8]. Be sure to execute the next command line.

> FPoly:=proc(a0,a,b,n) local k;
a0+sum('a[k]*cos(k*x)+b[k]*sin(k*x)','k'=1..n); end;

[Maple Math]

As an example let's plot the degree 9 Fourier polynomial F(x) = [Maple Math] .

> plot(
FPoly(.25, [0,0,.5,0,.25,0,0,0,.125],[0,0,0,0,0,0,0,0,0],9),x=-Pi..Pi);

[Maple Plot]

>

Note that this is the graph of an even function of x, and that all the sine coefficients were 0. This is an example of the following general fact you will find useful.

Odd and Even:

A Fourier polynomial is an even function when all its sine coefficients are 0. A Fourier polynomial with its constant term removed is an odd function when all the cosine coefficients are 0.

>

Problem 1. By trial and error, estimate the Fourier coefficients of the degree 4 Fourier polynomials whose graphs are shown below. All plots are from [Maple Math] to [Maple Math] and (hint) each has no more than 3 nonzero coefficients.

>

a)

[Maple Plot]

>

b)

[Maple Plot]

>

c)

[Maple Plot]

>

The Fourier Polynomials of a Function

If f(x) is a 2 [Maple Math] periodic function, we define the Fourier coefficients of f to be

[Maple Math] , for k = 1,2,...n.

The degree n Fourier polynomial with these coefficients is called the degree n Fourier polynomial of f . The infinite series whose partial sums are the Fourier polynomials of f is called the Fourier series of f . The degree n Fourier polynomial of f is the Fourier polynomial of degree n that best approximates the function f over the whole interval [- [Maple Math] , [Maple Math] ] in a certain technical sense we won't go into here.

The calculation of the integrals that give the Fourier coefficients is usually very tedious. We provide Maple procedures to do these calculations. The procedures acoefs and bcoefs take the function f and the degree n and return lists of the coefficients [Maple Math] , resp. [Maple Math] for k = 1..n. A separate procedure called azero returns to constant coefficient [Maple Math] . We also provide similar procedures called Nacoefs, Nbcoefs, Nazero that do the same things with all integrals computed numerically. You may find it useful to try both kinds on the problems. Be sure to execute the following commands.

> acoefs:=proc(f,n) local k;
[seq(int(f(x)*cos(k*x),x=-Pi..Pi)/Pi,k =1..n)];
end;
bcoefs:=proc(f,n) local k; [seq(int(f(x)*sin(k*x),x=-Pi..Pi)/Pi,k=1..n)];
end;
azero:=proc(f) int(f(x),x=-Pi..Pi)/(2*Pi); end;
Here are the purely numerical versions of these procedures
Nacoefs:=proc(f,n) local k;
[seq(evalf(Int(f(x)*cos(k*x),x=-Pi..Pi))/evalf(Pi),k=1..n)];
end;
Nbcoefs:=proc(f,n) local k;
[seq(evalf(Int(f(x)*sin(k*x),x=-Pi..Pi))/evalf(Pi),k=1..n)];
end;
Nazero:=proc(f) evalf(Int(f(x),x=-Pi..Pi))/evalf(2*Pi); end;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Let's try this out on the simple function below, whose graph is shown.

> f:=x->piecewise(x>0,1,0);

[Maple Math]

> plot(f(x),x=-3..3);

[Maple Plot]

>

The part of the graph of f between -3 and 0 does not show as the function is zero there. We compute the Fourier coefficients up to degree 20. We will call the coefficient lists a and b. We print out the Fourier polynomial of degree 9 and we plot the graph of f together with the graphs of the Fourier polynomials of degrees 5,10,15 and 20. Note that [Maple Math] for k 's except k = 0 . This illustrates an extension of the odd/even principle we discussed above.

If a function is even, all its sine coefficients will be 0. If a function can be made into an odd function by some vertical shift, then all its cosine coefficients will be 0.

For our present function f , shifting vertically down by 1/2 produces an odd function. It is often very useful to observe even or odd symmetry of the function you are dealing with and to simply set the appropriate coefficient list equal to a list of zeros without doing any calculation.

> a:=acoefs(f,20): b:=bcoefs(f,20): a0:=azero(f):

> FPoly(a0,a,b,9);

[Maple Math]

> plot([f(x),seq(FPoly(a0,a,b,5*n),n=1..4)],x=-Pi..Pi);

[Maple Plot]

>

Problem 2 Consider the function g(x) = [Maple Math] for x between [Maple Math] and [Maple Math] repeated periodically.

a) Compute and have Maple print the Fourier polynomials of degrees 5,10, and 15.

b) Plot them together with the graph of g(x) on the interval [- [Maple Math] , [Maple Math] ] .

c) Write a paragraph discussing the Fourier coefficients and your results are to be expected in view of the symmetry of the function g.

>

The Energy Spectrum

We have seen above that the Fourier series of the function f, is a sum of functions of the form

[Maple Math] , where the coefficients [Maple Math] are computed as integrals of cosines and sines times f(x). We call this function, [Maple Math] , the k-th harmonic of f . As noted in the introductory discussion the k-th harmonic is a shifted sine with frequency k and amplitude [Maple Math] , for k >0. We will call the square of the amplitude, [Maple Math] , the energy of the k-th harmonic of f, if k > 0, and we define [Maple Math] . By analogy with some ideas from physics, we say that a [Maple Math] -periodic function has energy given by [Maple Math] . For functions f(x) with just a finite number of

points of discontinuity, we have the Energy Theorem, whose proof is beyond this course:

Energy Theorem. [Maple Math] .

If we interpret the function f as a wave or a signal, this says that the total energy of the wave or signal is the sum of the energies of its harmonics. A graph of [Maple Math] as a function of k, is called the energy spectrum of f.

Let's apply this to a new function, h(x), defined as follows. (Execute the next line.)

> h:=x->x-floor(x);

[Maple Math]

Here is the graph of h , as usual from [Maple Math] .

> plot(h(x), x=-Pi..Pi);

[Maple Plot]

>

Let's compute the coefficients of the degree 20 Fourier polynomial for this function. We will use a0, a, and b as the names of the constant term, the cosine coefficient list, and the sine coefficient list.

Warning: a0, a, and b will now have values throughout the worksheet associated with our specific function h, i.e. a0, a and b are GLOBAL variables. When finished with this section it's a good idea to restore them to being just letters again, by the commands a0:='a0', a:='a', b:='b'.

This time, we will use the numerical integration versions of the procedures to calculate the Fourier coefficients.

>

> a0:=Nazero(h); a:=Nacoefs(h, 20); b:=Nbcoefs(h,20);

[Maple Math]

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

[Maple Math]
[Maple Math]
[Maple Math]

>

Look at the results. The list a has entries that are 0 except for numerical integration error. Do you see why this makes sense? We now plot the energy spectrum using the listplot command as follows. (Note:We are plotting [Maple Math] against k for k = 1..20. We don't plot [Maple Math] .)

> with(plots): listplot([seq(a[k]^2+b[k]^2,k=1..20)],style=POINT,symbol=BOX);

[Maple Plot]

>

The spectrum tells us that there is a strong harmonic at k=6, with strong, but less energetic harmonics at k=7,13 and 19.

Let's plot the function h(x) and the degree 20 Fourier polynomial.

> plot([h(x), FPoly(a0,a,b,20)],x=-Pi..Pi, color = [red,black]);

[Maple Plot]

>

Now let's plot h(x) and just the constant term with the four dominant harmonics we identified from the energy spectrum.

> plot([h(x), a0+ a[6]*cos(6*x)+b[6]*sin(6*x) + a[7]*cos(7*x)+b[7]*sin(7*x)+ a[13]*cos(13*x) + b[13]*sin(13*x)+a[19]*cos(19*x)+b[19]*sin(19*x)],x=-Pi..Pi, color=[red,blue]);

[Maple Plot]

>

These harmonics captured some of the shape, but of course didn't do as well as the full Fourier polynomial, which, on the other hand, requires more computation.

Let us see how much of the total energy of the function h is contained in these harmonics. We calculate the total energy, E, in the function and then the total energy, EH, in the harmonics from k=0 to 20 (remember that k=0 is a special case), and finally, the total energy, DHE contained in the dominant k-th harmonics, namely those with k=0, k=6,7,13,19.

> E:= evalf(Int(h(x)^2,x=-Pi..Pi)/Pi);
EH:= 2.0*a0^2+sum(a[k]^2+b[k]^2, k=1..20);
DHE:= 2.0*a0^2 +a[6]^2+b[6]^2+a[7]^2+b[7]^2+a[13]^2+b[13]^2+a[19]^2+b[19]^2;
EH/E; DHE/E;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

>

Thus we see that in this case, about 91.9% of the total energy is contained in the constant term and the 4 dominant harmonics we identified from the energy spectrum.

Problem 3. Consider the function Sq defined below, with graph as shown. (Sq is short for "square wave.")

> Sq:=x-> signum(sin(Pi*(x-1/4)));

[Maple Math]

> plot(Sq(x),x=-Pi..Pi);

[Maple Plot]

>

a) Using the numerical versions of the functions to find coefficients e.g. Nacoefs, plot the 10th and the 20th degree Fourier polynomials for Sq together with the graph of Sq itself.

b) Use the energy spectrum to identify the 3 most energetic harmonics and plot the sum of these and the constant term along with the graph of Sq.

c) Find the percentage of the total energy of Sq contained in the constant term and the 3 most energetic harmonics you found in part b).

Problem 4. Consider the function q(x) = [Maple Math] for x in the interval [Maple Math] .

a) Compute the 10th degree Fourier polynomial and display it. (Use the acoefs, bcoefs procedures for this.)

b) Use a) to guess a formula for the energy of the k-th harmonic.

c) * Verify your guess in part b) either by hand calculation or by using Maple. If you use Maple you should execute the following command first

> assume(k, integer);

>

d) Apply the Energy Theorem to this function and your guess for the energy in the k-th harmonic to find a formula, which will involve [Maple Math] , for the sum of the infinite series

[Maple Math] + .......

e) Use your result in d) to find an estimate for [Maple Math] using only simple arithmetic and a single square root. You should, of course, have Maple do all the arithmetic! How could you get a better estimate, using only the same kind of simple arithmetic?

Homework Problems

Your homework for this worksheet consists of Problems 1-4 above.

MTH 142 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 1999.

Last modified August 1999.

>