Computing Fourier Series

With the properties of $\sin(nx)$ and $\cos(nx)$ extablished, we have what's called an orthonormal basis for many functions. This is not a complete basis in the conventional sense, but we can approximate the functions we'll be working with as well as we need to by using enough terms. This is not too different to keeping as many decimal places as you need for accuracy when approximating a non-decimal number.

Recall: We're using the inner product $$ \langle f, g \rangle = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x)g(x) \ dx. $$ How do we compute Fourier Coefficients? They are just inner products between the function in question and the $\sin(nx)$ or $\cos(nx)$ term. Let's go through some examples.




1) The Square Wave

Figure 1: The Square Wave



The function $f(x)$ in question takes on a value of -1 when $x \in [-\pi,0]$ and 1 when $x \in (0,\pi]$.

$f(x)$ is an odd function, so we will only look at $\sin(nx)$ terms because the integrals with $\cos(nx)$ terms would give us odd results (which would be 0).

Similarly, the odd function $f(x)$ being multiplied by $\sin(nx)$ gives us an even function $f(x) \sin(nx)$, so we can double the integral on $[0,\pi]$.

$$ \left\langle f(x), \sin(nx) \right\rangle $$ $$ = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin(nx) \ dx = \frac{1}{\pi} \int_{-\pi}^{0} (-1) \sin(nx) \ dx + \frac{1}{\pi} \int_{0}^{\pi} (1) \sin(nx) \ dx $$ $$ = \frac{2}{\pi} \int_{0}^{\pi} \sin(nx) \ dx $$ $$ = \frac{2}{\pi} \left( \left. -\frac{1}{n} \cos(nx) \ \right|_0^\pi \right) $$ $$ = -\frac{2}{n\pi} \left( (-1)^n - 1 \right) = \frac{2}{n\pi} \left( 1 - (-1)^n \right) $$ $$ = \begin{cases} \frac{2}{n\pi} \cdot 2 & \text{ if } n \text{ is odd} \\ \frac{2}{n\pi} \cdot 0 & \text{ if } n \text{ is even.} \end{cases}$$ $$ = \begin{cases} \frac{4}{n\pi} & \text{ if } n \text{ is odd} \\ \ \ 0 & \text{ if } n \text{ is even.} \end{cases}$$








2) The Sawtooth

This function $f(x)$ takes on a value $x$ on the interval $[-\pi, \pi]$.

Figure 2: Sawtooth Approximation



Similarly to before, we will integrate with only the sine functions because this function is odd. Also, we'll take two of the integral from 0 to $\pi$.

$$ \left\langle f(x), \sin(nx) \right\rangle = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin(nx) \ dx $$ $$ = \frac{1}{\pi} \int_{-\pi}^{\pi} x \sin(nx) \ dx = 2 \cdot \frac{1}{\pi} \int_{0}^{\pi} x \sin(nx) \ dx $$ $$ \left. \frac{2}{\pi} \left( \cancel{\frac{1}{n^2}\sin(nx)} - \frac{1}{n}x\cos(nx) \right) \right|_0^\pi $$ $$ = - \frac{1}{\cancel{\pi}} \frac{2 \cancel{\pi}}{n} (-1)^n $$ $$ = - \frac{2}{n} (-1)^n $$