You are on page 1of 2

Lab on week 23:

Fourier series
Activity 1
Use Matlab to plot the graph of the function sin 𝑡 on the interval between 𝑡 = −10 and 𝑡 = 10.

Then build the plots of the following functions and see how the shape of the plot slowly changes.
1
 sin 𝑡 + 2 sin 2𝑡
1 1
 sin 𝑡 + 2 sin 2𝑡 + 3 sin 3𝑡
1 1 1
 sin 𝑡 + 2 sin 2𝑡 + 3 sin 3𝑡 + 4 sin 4𝑡

Activity 2
If we want to add yet more functions to the sums as those shown above, it is advisable to use a loop.
The following Matlab code plots the sum of functions sin 𝑘𝑡 for 𝑘 = 1, … ,5.

t = -10:.01:10;
f=0
for k=1:5
f=f+1/k*sin(k.*t);
end
plot(t,f)

Run this code. Then change the code and run it again to plot the sum of functions sin 𝑘𝑡 for 𝑘
changing in the range

 𝑘 = 1, … ,10
 𝑘 = 1, … ,100
 𝑘 = 1, … ,1000

Activity 3
You can try obtaining different shapes by running the code from the previous activity with the
following changes:

 Only run the loop for odd values of 𝑘 (or only run the loop for even values of 𝑘, or only for
the values of 𝑘 which divide by 4, etc.)
 Use functions of the type cos 𝑘𝑡 instead of sin 𝑘𝑡.

For example, some of these variations will produce rectangular waves.

Activity 4
Can we produce triangle waves, that is, waves of the shape shown on the picture below? (For
convenience, in this lab all waves have period equal to 2𝜋, like the sine and the cosine.) It is difficult
to guess what the coefficients should be, so, we need to apply special formulas to find the
coefficients. We can guess that since this waveform is an even function, we need to use only

1
functions of the type cos 𝑘𝑡 to approximate it. The coefficient with each function cos 𝑘𝑡 can be
𝜋 2
found using the integral ∫0 cos 𝑘𝑡 (1 − 𝜋 𝑡) 𝑑𝑡; here, cos 𝑘𝑡 is the function whose coefficient we are
2
trying to find, and 1 − 𝜋 𝑡 is a formula describing the shape of the triangle wave between 𝑡 = 0 and
2
𝑡 = 𝜋. (To be precise, there also should be a certain coefficient in front of the integral, being , but
𝜋
let us ignore it for now.)

Use Matlab to find this integral for some values of 𝑘, say, 𝑘 = 1,2,3. (Remember that to find
integrals in Matlab we use the command int, like we did in the lab in Activity 7 of week 20.) After you
have found the coefficients, plot the graph of the approximated function like you did in Activity 1.
You will obtain a graph which looks as follows.

As I have said above, the amplitude of this approximation of the waveform is wrong: to be exactly
2
from −1 to 1, it should be multiplied by a coefficient . But apart from this, this is a surprisingly good
𝜋
approximation.

The following graph uses values of 𝑘 = 1, … ,5 (this is why it gives a slightly better approximation)
2
and is multiplied by the coefficient (this is why the amplitude is correct). Try reproducing this
𝜋
graph.

You might also like