Animation of Fourier Approximation of a Square Wave

Here is a Maple worksheet to illustrate the Fourier Series approximation of a Square Wave. If you don't want to copy the lines below, you can click here to download the source file (very small, and zipped). On the page below, the red lines are the crutial Maple lines .. the green lines are just comments to help clarify what is being done.

> restart; with(plots):
> m:=40: # Number of terms to keep
> # calculate the array of f(x) terms - one for each term up to M (successively smaller!)
> # myseq[1] = the first term of the fourier series
> # myseq[2] = the second term of the fourier series (smaller than the first) .. etc.
> myseq := seq( (2/((2*n-1)*Pi))*sin((2*n-1)*Pi*x),n=1..m): # notice only odd terms calculated
> # calculate the array of the sums of each terms
> myseqsum := seq(sum(myseq[nn],nn=1..n),n=1..m):
> # myseqsum[1] = the sum of only ONE term in series
> # myseqsum[2] = the sum of the first TWO terms in the series (combined)
> # myseqsum[3] = the sum of the first THREE terms - looking more like square wave
> # now plot the above sums individually - animated - shows evolution to the squarewave
> display(seq(plot(myseqsum[i], x=-0.2..2.2,color=blue, thickness=2),i=1..m), insequence=true, title=`Evolution of Fourier series to Square Wave`);

Here is an animation of the sequence as you add more terms to the series .. notice that it starts approaching an square wave, but there is "ringing" at the corners. Because of the discontinuities in the square wave, we can't completely remove those artifacts. (Thus a square wave is never a perfect square wave!)

Look at these other pages :

[Maple Plot]

> # Note: Watch the corners .. the series will never fully match the square wave because of the discontinuity ... that "ringing" at the corners is called the Gibb's Phenomena!


Return to the Maple page.