Fourier Series for $|\cos(x)|$

Although $ \int_0^\pi \cos(x)\,dx = 0$, $a_0\ne 0$ because $$\int_0^{\pi/2} |\cos(x)|\,dx=\int_{\pi/2}^{\pi} |\cos(x)|\,dx. $$

We can evaluate it as follows, as can be seen in the plot below

$$a_0 = \frac 1 \pi \int_{-\pi}^\pi |\cos(x)|\,dx=\frac 2 \pi \int_0^\pi |\cos(x)|\,dx=\frac 4 \pi \int_0^{\pi/2} |\cos(x)|\,dx = \frac 4 \pi \int_0^{\pi/2} \cos(x)\,dx=\frac 4 \pi.$$ $$\tag{1}$$

Plot of $\cos x$ (doted line) and $|\cos x|$ (solid line) in the interval $[-\pi,\pi]$.

enter image description here

The coefficients $b_n=0$ as you concluded. As for the $a_n$ coefficients only the odd ones are equal to $0$ (see below). The functions $\cos(x)$ and $\cos(nx)$ are orthogonal in the interval $[-\pi,\pi]$, but $|\cos(x)|$ and $\cos(nx)$ are not. Since

\begin{equation*} \left\vert \cos (x)\right\vert =\left\{ \begin{array}{c} \cos (x) \\ -\cos (x) \end{array} \begin{array}{c} \text{if} \\ \text{if} \end{array} \begin{array}{c} 0\leq x\leq \pi /2 \\ \pi /2\leq x\leq \pi, \end{array} \right. \tag{2} \end{equation*}

we have that

\begin{eqnarray*} a_{n} &=&\frac{1}{\pi }\int_{-\pi }^{\pi }\left\vert \cos (x)\right\vert\cos (nx)\,dx=\frac{2}{\pi }\int_{0}^{\pi }\left\vert \cos (x)\right\vert \cos (nx)\,dx \\ &=&\frac{2}{\pi }\int_{0}^{\pi /2}\left\vert \cos (x)\right\vert \cos (nx)\,dx+\frac{2}{\pi }\int_{\pi /2}^{\pi }\left\vert \cos (x)\right\vert \cos (nx)\,dx \\ &=&\frac{2}{\pi }\int_{0}^{\pi /2}\cos (x)\cos (nx)\,dx-\frac{2}{\pi } \int_{\pi /2}^{\pi }\cos (x)\cos (nx)\,dx. \\ a_{1} &=&\frac{2}{\pi }\int_{0}^{\pi /2}\cos ^{2}(x)\,dx-\frac{2}{\pi }\int_{\pi /2}^{\pi }\cos ^{2}(x)\,dx=0. \end{eqnarray*}

Using the following trigonometric identity, with $a=x,b=nx$, \begin{equation*} \cos (a)\cos (b)=\frac{\cos (a+b)+\cos (a-b)}{2},\tag{3} \end{equation*}

we find

\begin{eqnarray*} a_{2m} &=&\frac{4}{\pi \left( 1-4m^{2}\right) }\cos (\frac{2m\pi }{2})=\frac{ 4}{\pi \left( 1-4m^{2}\right) }(-1)^{m} \\ a_{2m+1} &=&\frac{4}{\pi ( 1-4(2m+1)^{2}) }\cos (\frac{(2m+1)\pi }{2})=0,\qquad m=1,2,3,\ldots.\tag{4} \end{eqnarray*}

The expansion of $\left\vert \cos (x)\right\vert $ into a trigonometric Fourier series in the interval $[-\pi ,\pi ]$ is thus

\begin{equation*} \left\vert \cos x\right\vert =\frac{a_{0}}{2}+\sum_{n=1}^{\infty }\left( a_{n}\cos (nx)+b_{n}\sin (nx)\right) =\frac{2}{\pi }+\frac{4}{\pi } \sum_{m=1}^{\infty }\frac{(-1)^{m}}{1-4m^{2}}\cos (2mx)\tag{5} \end{equation*}

enter image description here

$$|\sin(x)|\ \text{(blue) and the partial sum }\frac{2}{\pi }+\frac{4}{\pi } \sum_{m=1}^{5 }\frac{(-1)^{m}}{1-4m^{2}}\cos (2mx) \ \text{(red) in }[-\pi,\pi]$$

Setting $x=0$ in $(5)$, we obtain

\begin{equation*} 1=\frac{2}{\pi }+\frac{4}{\pi }\sum_{m=1}^{\infty }\frac{(-1)^{m}}{1-4m^{2}}=\frac{2}{\pi }-\frac{4}{\pi }\sum_{n=1}^{\infty }\frac{(-1)^{n-1}}{1-4n^{2}}.\tag{6} \end{equation*}

Hence

\begin{equation*} \sum_{n=1}^{\infty }\frac{(-1)^{n-1}}{1-4n^{2}}=\frac{1}{2}-\frac{\pi }{4}.\tag{7} \end{equation*}


It is not correct. $$ \int_0^\pi|\cos x|\cos(n\,x)\,dx=\int_0^{\pi/2}\cos x\cos(n\,x)\,dx-\int_{\pi/2}^\pi\cos x\cos(n\,x)\,dx. $$ Compute the integrals and you will see that the result is not $0$.