Fourier Series Example - A Complicated Function

Previous: The Fourier Series for the Saw Function
Fourier Series List
Next: Mean Squared Error (MSE)


On this page, we'll look at finding the Fourier Series for a complicated function, f(t), shown in Figure 1.
tangent function

Figure 1. A Somewhat Complicated Function.

The mathematical description for the fundamental period (T=2 in this case) is given in Equation [1]:

complicated function
[Equation 1]

Again, we want to find the complex Fourier Coefficients from equation [1] on the complex coefficients page. However, this time, we can't evaluate the integral analytically. If you can evalute the integral of equation [1], you should stop studying math, go outside and get some sun.

In general, the Fourier Series coefficients can always be found - although sometimes it is done numerically. On this page, we'll use f(t) as an example, and numerically (computationally) find the Fourier Series coefficients.

The integral to evaluate the c_n values can be done rather simply. The code I used was done in Matlab, although you could use pretty much anything (C, Java, python, etc). The code is here, if you want to see it. The first three coefficients are easily found: c0 = 0.9124, c1 = c(-1) = 3.6935. The first three coefficients, compared to the original f(t) is shown in Figure 2:

first 3 terms of Fourier expansion

Figure 2. Original f(t) and the first 3 terms of the Fourier Expansion.

Going further, the first 21 terms (n=-10, -9, ..., 9, 10) are shown in Figure 3:

first 10 terms of Fourier expansion

Figure 3. Original f(t) and the first 21 terms of the Fourier Expansion.

The series is converging on the original function. If you plot roughly 100 terms, the Fourier series expansion is more or less indistinguishable from f(t).

To get an idea of how the coefficients are changing, here is a plot of the magnitude of the c_n, n=1,2,...,30. The figures shown how rapidly the c_n die off as n increases. The top graph of Figure 4 is the magnitude of the cn, using a linear scale. The lower graph of Figure 4 is the same plot, but on a log scale, to show the falloff more clearly.

falloff of Fourier Series coefficients with n

Figure 4. Magnitude of Fourier Series Coefficients Versus n. The top graph is using a linear scale; the lower graph uses a log scale of the same function.

To understand how closely a series has converged to the original function, in the next section we will look at mean squared error.


Next: Mean Squared Error (MSE)

Previous: Fourier Series Example - The Saw Function

Fourier Series (Main)

Fourier Transforms (Home)