Back in my TA days (or daze), I helped out on one course that was a mix of numeric methods and MatLab programming. Most students were ok, but there was a bit of a struggle with the Fourier series. Perhaps it was a problem with the integration or it was general issues with their math backgrounds.

A while ago, I read a book on making interactive graphics for the web and I thought it would be a great to use some of this new knowledge to make a tool to help explain key concepts of the Fourier series. So if I ever TA something related to the Fourier series ever again, I would be ready. Also, I thought that it would be a good project for myself so I could remember and practice some different math skills.

I have chosen some of the most popular functions to approximate with a Fourier series including: the square wave, the sawtooth wave, the parabolic wave, and a triangular wave. All of the graphics were implemented using Javascript and D3.

In the future, I am planning to implement some Fourier transform projects. Particularly using FFTs to in image processing.

##### Note about the Visualization

The visualization tool is just to assist in the understanding of the Fourier series. It does not stand alone, since it needs some type of reference (such as a book or a person) to explain key details.

The visualization contained three main components: 1) the original function; 2) the first few terms of the approximation (and with the constant term as well); 3) and the series results produced with the first few, 5, 10, and 15 terms.

The ‘Sum’ curves include the computed terms and the constant term. Hence the ‘Sum of the First Term’ includes the a_0, a_1, and b_1 terms.

##### Fourier Series

There are a ton of books and websites on there about the Fourier series. Recall that a periodic function (or even a portion of a regular function) can be approximated by a series of sine and cosine functions. Mathematically this is written as:

Where a_0, a_n, and b_n are the Fourier coefficients and can be calculated by:

Note that there is a variety of notation and minor differences out there. This includes integrating over the region of -\pi to \pi.

##### Square Wave

The square wave function can be defined over the interval [0, 2) as:

First we can determine a_0. By inspection we can expect it to be zero, but we shall still figure it out for practice. Note that L = 1 and we are considering the interval [0, 2) instead of [-1, 1) since the function is periodic:

Next we shall look at a_n. Again by inspection we can argue that since the function is odd that it cosine components since those are even. Anyways, we shall still work it out for practice. Note that the identity \sin (2n\pi) = 0 was used.

Now working out $b_n$. Note the following identity \cos(n\pi) = -1, 1, -1, 1, \ldots can be written as -1^n, so then:

And the final Fourier series is:

Click here to view the graph on a separate tab.

##### Sawtooth Wave

The square wave function can be defined over the interval [0, 2) as:

The Fourier coefficients can then be determined (using integration by parts) to be:

So the final Fourier series solution is:

Note that the complete mathematical derivations can be found in the following document in the Sawtooth wave section.

Click here to view the graph in a separate tab.

##### Parabolic Wave

The parabolic wave function can be defined over the interval [-1, 1) as:

The Fourier coefficients can then be determined to be:

Therefore the final Fourier series solution is then:

Note that the complete mathematical derivations can be found in the following document in the Parabolic wave section.

Click here to view the graph in a separate tab.

##### Triangular Wave

The triangle wave function can be defined over the interval [-1, 1) as:

The Fourier coefficients can then be determined (using integration by parts) to be:

Therefore the final Fourier series approximation is:

Note that the complete mathematical derivations can be found in the following document in the Triangle wave section.

Click here to view in a separate tab.

##### Code

Note that all of the code for the visualizations is available here.

## No Comments