Matlab Homework on Fourier Series

I. In Matlab perform the following:

a=[0:1:200];

wt=2.*3.14159.*a/200;

z=1 + cos(wt) + 0.5.*cos(20.*wt) + 0.25.*cos(30.*wt) + 0.125.*cos(40.*wt);

plot(wt,z);

b=fft(z);

c=abs(b);

plot(c);

1.     Why is wt an appropriate variable to use in this program?

2.     What is the time average of the signal z?

3.     What does the line b=fft(z) do?

4.     Why is it necessary to take abs(b)?

5.     What is the x-axis in the plot of c?

6.     The the plot of c looks like a series of delta functions.  Why?

Print out the plots of (wt,z) and the plot of c, and turn these in with the answers to the above questions.

II. Use the Fourier series from the book that represents a square wave, and write a program that computes and plots the first n terms of this expansion.  You should be able to call this routine with the line:

>> squarewave(n);

With this routine, calculate and plot the n-term Fourier expansion of the square wave for n=1, n=2, n=10, n=100, and n=1000.

Turn in the plots for these five cases.

How many terms are needed to obtain a reasonable approximation of the square wave.

III. Modify the program you wrote in II above to calculate a triangle wave instead of a square wave.

Now how many terms are required to obtain a reasonable approximation of the triangle wave?

Why is this number so much smaller than the number of terms required for the square wave?