It is a good idea to see computations of some Fourier series of functions that aren't built from sines and cosines. To that end, we consider two simple examples: 1) a "square wave"; and 2) a "triangular wave".
Example: A square wave
Consider the piecewise-defined function is periodic with period 1, and which on is defined by
In other words, this function alternates between the values of and over intervals of length . Although this function is discontinuous (where it "jumps" between the values of and ), if we suggestively connect the values across those jumps with vertical lines we get the following visualization of the graph of :
Based on this image, it's reasonable to call this graph a "rectangular wave", but for some reason the descriptor "square wave" is more popular.
In any case, let's compute the complex Fourier series associated to this function . We first compute
For we compute
Note that we computed the integrals using -substitutions, and simplified some expressions using the facts that whenever is an integer, while is when is even and when is odd; i.e., .
It follows that that Fourier series associated to our function is
If we group together the term at index with the term at index and use the identity , we can rewrite the above series in the sines-and-cosines form as
Some Fourier approximations
Let's truncate our Fourier series after various amounts of terms and see how well the corresponding finite Fourier series approximates our function . If we only use the first term, the finite Fourier series we obtain is
whose graph is
If we truncate instead at (i.e., include all terms with ), the finite Fourier series we obtain is
whose graph is
Finally, if we truncate our series at , the graph of the corresponding finite Fourier series we obtain is
Although our "Fourier approximations" appear to be converging quickly to the original square wave, you might notice those weird little "peaks" at the corners of each wave. There's something a little surprising going on here, but we'll hold off on investigating further until after our next example.
Example: A triangular wave
Now denote the "triangle wave" function, which is periodic with period 1 and is defined on by
As you can see from the graph, it seems reasonable to call this function a "triangle wave":
We first compute
For , we have
To compute these, we make the substitution (so ) and use integration by parts, obtaining
To simplify this mess, recall that for all , and that . So when is even, the above expression simplifies to
When is odd, the expression instead simplifies to
We've shown that the Fourier series for is
Some Fourier approximations
As with the square wave, we can get a sense for how quickly our Fourier series is converging to the original function by looking at some Fourier approximations with increasingly larger values (i.e., more and more terms included). Here are the graphs of those approximations when and , this time with the original graph overlaid for visual comparison: