Sine Fourier coefficients of derivative Let $f$ be a $C^1$-function on $[0,\pi]$ with $f(0)=f(\pi)=0$. We know that the family $(\sin(nx))_{n\in\Bbb N}$ is a complete orthonormal system on $L^2(0,\pi)$ (maybe up to some rescaling). Let $(a_n)$ be the Fourier coefficients of $f$ with respect to this system, i.e. $$a_n=\frac{2}{\pi}\int_0^\pi f(x)\sin(nx)dx$$ Then we have by Parseval's theorem $$\frac{2}{\pi}\int_0^\pi f^2=\sum_{n=1}^\infty a_n^2$$ (for simplicity assume that $f$ only assumes real values, so that we can ignore absolute values)
My question is about this answer. There it is claimed that we also have $$\frac{2}{\pi}\int_0^\pi (f')^2=\sum_{n=1}^\infty n^2a_n^2 \tag{$*$}$$
Why is this the case? Let $b_n$ be the Fourier coefficients of $f'$. So $$b_n=\frac{2}{\pi}\int_0^\pi f'(x)\sin(nx)dx=-\frac{2n}{\pi}\int_0^\pi f(x)\cos(nx)dx$$(Since $f(0)=f(\pi)=0$.)
If we could show that $\int_0^\pi f(x)\cos(nx)dx=\int_0^\pi f(x)\sin(nx)dx$, we would have $b_n=-na_n$ and the result follows again from Parseval's identity, but some examples show that this equality doesn't hold.
The original problem was to show the inequality $\int_0^\pi f^2dx\leq\int_0^\pi (f')^2$. I think we can avoid the problem above by simply choosing the complete orthonormal system $(e^{2ikx})_{k\in\Bbb Z}$ instead of the sine functions, because in this case we get for $k\ne0$ by the same calculation as above: $$\langle f',e^{2ikx}\rangle=2ik\langle f, e^{2ikx}\rangle$$
Unfortunately there is a problem with $k=0$, see also the approach in the linked question.
So I would like to understand the equality $(*)$.
 A: I think that using that $\sin nx$ is a complete orthonormal system of $L^2(0,\pi)$ gets into subtleties that are best treated with classical Fourier series theory.
The way to proceed is using the fact that given $f \in L^2(0,\pi)$, one can extend it to an odd function $F$ on $[-\pi,\pi]$ (ends matter only for continuos functions) and then it has a sine Fourier series which gives the Parseval relation $\frac{2}{\pi}\int_0^\pi f^2=\sum_{n=1}^\infty a_n^2$.
The hypothesis that $f \in C^1, f(0)=f(\pi)=0$ implies that (actually it is equivalent to) $F$ (the odd extension) is absolutely continuous on $[-\pi,\pi]$
(by $C^1$ on $(-\pi,0) \cup (0, \pi)$ and $C^1$ from the sides at the ends, continuity at $0$ and $\pi =-\pi$ modulo circle is equivalent to absolute continuity for $F$ and that in turn is clearly equivalent with $f(0)=f(\pi)=0$).
But then by general Fourier series theory, $F'$ (an even integrable function, possibly discontinuous at $0, \pi$ as a periodic function - with left/right limits though eg take $f(x)=x(\pi-x)$ on $[0, \pi]$) has a cosine Fourier series which is the term by term derivative of the one of $F$, hence its coefficients are indeed $na_n$ and the claim follows by  Parseval and symmetry since $F'=f'$ on $(0, \pi)$
