Fourier series: Introduction
Calculating a Fourier cosine series
Besides the Fourier sine series, there is also a series expansion with only cosine terms and a constant. As an example, we look at the periodic continuation of the function \[f(x)=\begin{cases} \pi+x & \text{if }-\pi\le x<0 \\ \pi-x & \text{if }0\le x<\pi\end{cases}\] The graph of this function resembles a sawthooth; hence it is called the sawtooth function.
\[a_n = \begin{cases}\displaystyle \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx)\,\dd x & \text{if }n>0 \\ \\ \displaystyle \frac{1}{2\pi}\int_{-\pi}^{\pi}f(x)\,\dd x & \text{if }n=0\end{cases} \]
We also need a constant \(a_0\) because otherwise we have a series expansion of which the average value on the interval \((-\pi,\pi)\) is zero. Generally we take for \(a_0\) the average value of \(f(x)\) on the interval \((-\pi,\pi)\). This average can be calculated with the following integral: \[a_0=\frac{1}{2\pi}\int_{-\pi}^{\pi}f(x)\,\dd x\]
When \[f(x)=\begin{cases} \pi+x & \text{if }-\pi\le x<0 \\ \pi-x & \text{if }0\le x<\pi\end{cases}\] then \[\begin{aligned} a_n &= \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cdot \cos(nx)\,\dd x \\ \\ &= \frac{1}{\pi}\int_{-\pi}^{0} (\pi+x)\cos(nx)\,\dd x +\frac{1}{\pi}\int_{0}^{\pi} (\pi-x)\cos(nx)\,\dd x \\ \\ &= -\frac{1}{\pi}\int_{\pi}^{0} (\pi-u)\cos(nu)\,\dd u +\frac{1}{\pi}\int_{0}^{\pi} (\pi-x)\cos(nx)\,\dd x\\ &\phantom{=}\blue{\text{ substitute in the first integral }x=-u} \\ \\ &= \frac{2}{\pi}\int_{0}^{\pi} (\pi-x)\cos(nx)\,\dd x\\ \\ &= \frac{2}{\pi}\Bigl[\frac{(\pi-x)\sin(nx)}{n}\Bigr]_{0}^{\pi} + \frac{2}{\pi}\int_{0}^{\pi}\frac{\sin(nx)}{n}\,\dd x \\ \\ &= 0 +\frac{2}{\pi}\Bigl[\frac{-\cos(nx)}{n^2}\Bigr]_{0}^{\pi}\\ \\ &= \frac{2\bigl(1-\cos(n\pi)\bigr)}{\pi n^2} \\ \\ & = \begin{cases} 0 & \text{if }n\text{ is even} \\ \\ \dfrac{4}{\pi n^2} & \text{if }n\text{ is odd}\end{cases}\end{aligned}\] The Fourier sine series is then: \[f(x) = \frac{\pi}{2} + \frac{4}{\pi}\left(\cos x + \frac{1}{9}\cos 3x + \frac{1}{25}\cos 5x + \frac{1}{49}\cos 7x + \cdots\right)\] In the following figure are displayed the graphs of the sawtooth function and the Fourier cosine series with 2 and 8 cosine terms, respectively. The approximations of the original function are very good.
The frequency-amplitude spectrum is shown below: You can see at a glance that the even Fourier cosine coefficients are zero and that the frequency levels decrease with increasing \(n\).
You can also use the interactive version below to get an impression of how well the sawtooth function is approximated by a Fourier series and what the frequency-amplitude spectrum looks like.
Some well-known formulas With the above Fourier cosine seres we get the following equation when we substitute \(x=0\): \[\pi=\frac{\pi}{2} + \frac{4}{\pi}\left(1 + \frac{1}{3^2} + \frac{1}{5^2} + \frac{1}{7^2} + \cdots\right)\] In other words, we get the following formula of Fourier: \[\frac{\pi^2}{8} = 1 + \frac{1}{3^2} + \frac{1}{5^2} + \frac{1}{7^2} + \cdots\] This allows us to derive an even more famous formula of Euler, namely: \[\frac{\pi^2}{6} = 1 + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \cdots\] The proof is as follows: Denote the right-hand side of the Euler formula as \(S\). Then: \[\frac{1}{2^2} + \frac{1}{4^2} + \frac{1}{6^2} + \frac{1}{8^2} + \cdots = \frac{1}{4}\left(1 + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \cdots\right)=\frac{S}{4}\] So it follows from the formula of Fourier: \[\frac{\pi^2}{8} = 1 + \frac{1}{3^2} + \frac{1}{5^2} + \frac{1}{7^2} + \cdots = S - \frac{S}{4} =\frac{3}{4}S \] Thus: \[S=\frac{\pi^2}{6}\]