Problem in Proof of Bessel inequality In the proof of Bessel inequality,how to get:
$$
\int_{-\pi}^{\pi}
{
\left(
\frac{a_0}{2}+\sum_{v=1}^{\infty}{a_v\cos{vx}+b_v\sin{vx}}
\right)^2dx
}=
{}=
\frac{a_0^2}{2}+
\sum_{v=1}^{\infty}{\left( a_v^2+b_v^2 \right)}
$$
I only found that:
$$
\int_{-\pi}^{\pi}
{
\left(
\sum_{v=1}^{\infty}{\left(a_v\cos{vx}+b_v\sin{vx}\right)}
\right)^2dx
}=
\int_{-\pi}^{\pi}
{
{\sum_{v=1}^{\infty}{\left(a_v^2\cos^2{vx}+b_v^2\sin^2{vx}\right)}}
}
$$
Should I expand $a_v$ and $b_v$?
 A: Bessel's Inequality asserts that for any real-valued function $f$ that is square integrable on $[-\pi,\pi]$   
$$\int_{-\pi}^\pi f^2(x)\,dx\ge \sum_{n=1}^\infty \left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2 \tag 1$$
where $\phi_n(x)$ is an orthonormal set of square integrable functions.  If the set $\phi_n(x)$ is complete, then the inequality in $(1)$ becomes an equality.
To show that $(1)$ is true, we start with the inequality 
$$\int_{-\pi}^\pi \left|f(x)-\sum_{n=1}^N \int_{-\pi}^\pi f(x')\phi_n(x')\,dx' \phi_n(x)\right|^2\,dx\ge 0 \tag 2$$
Then, expanding the squared term $S_N(x)=\left|f(x)-\sum_{n=1}^N \int_{-\pi}^\pi f(x')\phi_n(x')\,dx' \phi_n(x)\right|^2$ we find that 
$$\begin{align}
S_N(x)&=\left|f(x)-\sum_{n=1}^N \int_{-\pi}^\pi f(x')\phi_n(x')\,dx' \phi_n(x)\right|^2\\\\
&=\color{blue}{f^2(x)}-\color{red}{2\sum_{n=1}^N \int_{-\pi}^\pi f(x')\phi_n(x')\,dx' \phi_n(x)f(x)}\\\\
&+\color{green}{\sum_{n=1}^N\sum_{m=1}^N \int_{-\pi}^\pi f(x')\phi_n(x')\,dx' \phi_n(x)\int_{-\pi}^\pi f(x'')\phi_m(x'')\,dx'' \phi_m(x)} \tag 3
\end{align}$$
Integrating $(3)$ over $[-\pi,\pi]$ and exploiting the orthonormality of $\phi_n(x)$ as given by $\int_{-\pi}^\pi \phi_n(x)\phi_m(x)\,dx=\delta_{nm}$, where the Kronecker Delta $\delta_{mn}=1$ for $m=n$ and $0$ for $m\ne n$ we find
$$\begin{align}
0&\le \int_{-\pi}^\pi S_n(x)\,dx\\\\
&=\color{blue}{\int_{-\pi}^\pi f^2(x)\,dx}-\color{red}{2\sum_{n=1}^N\left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2}+\color{green}{\sum_{n=1}^N\left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2}\\\\
&=\int_{-\pi}^\pi f^2(x)\,dx-\sum_{n=1}^N\left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2 \tag 4
\end{align}$$
Inasmuch as $(4)$ is true for all $N$, we obtain Bessel's Inequality
$$\bbox[5px,border:2px solid #C0A000]{\int_{-\pi}^\pi f^2(x)\,dx\ge \sum_{n=1}^\infty \left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2} \tag 5$$
If the orthonormal set $\phi_n(x)$ is complete, then $\lim_{N\to \infty}S_N(x)=0$ and the inequality in $(5)$ becomes the equality 
$$\bbox[5px,border:2px solid #C0A000]{\int_{-\pi}^\pi f^2(x)\,dx= \sum_{n=1}^\infty \left(\int_{-\pi}^\pi f(x)\phi_n(x)\,dx\right)^2} \tag 6$$

A proof that the set $\left\{\frac{1}{\sqrt{2\pi}},\frac{\cos(x)}{\sqrt{\pi}},\frac{\sin(x)}{\sqrt{\pi}},\frac{\cos(2x)}{\sqrt{\pi}},\frac{\sin(2x)}{\sqrt{\pi}}, \dots \right\}$ is a complete orthonormal set of square integrable functions on $[-\pi,\pi]$ can be found [Rudin, W. (1986). “Real and Complex Analysis,” 3rd edition, McGrawHill, New York.].

Thus, we find that 
$$\frac1\pi\int_{-\pi}^\pi f^2(x)\,dx=\frac{a_0^2}{2}+\sum_{n=1}^\infty (a_n^2+b_n^2)$$
where the coefficients $a_n$ and $b_n$ are given by
$$a_n=\frac{1}{\pi}\int_{-\pi}^\pi \cos(nx)\,f(x)\,dx\\\\
b_n=\frac{1}{\pi}\int_{-\pi}^\pi \sin(nx)\,f(x)\,dx
$$
