Representation of an element in a Hilbert Space having a total orthonormal set 
Show that if $M=(e_n)$ is a total orthonormal set in a Hilbert Space $H$ then for any $x\in H$ we have $x=\sum_{k=1}^\infty \langle x,e_k\rangle e_k$.

Define $y=\sum_{k=1}^\infty \langle x,e_k\rangle e_k$.
Consider $\langle x-y,e_k\rangle=\langle x,e_k\rangle -\langle y,e_k\rangle=0 $.
Since $M$ is total so $\text{span}(M)$ is dense in $H$. But how to show that $x$ is given by this representation?Please help.
 A: Since $\text{span} M$ is dense so $M^\perp=\{0\}$
Define $y=\sum_k \langle x,e_k\rangle e_k$ where $\langle x,e_k\rangle$ are the non-zero Fourier co-efficients of $x$.
Now for any $e_j\in M$ for which $\langle x,e_k\rangle \neq 0$ we have;
$\langle x-y,e_j\rangle =\langle x,e_j\rangle-\langle y,e_j\rangle=\langle x,e_k\rangle-\langle x,e_k\rangle=0$.
If $e_j\in M$ is such that $\langle x,e_k\rangle= 0\implies \langle x-y,e_j\rangle=\langle x,e_j\rangle-\langle y,e_j\rangle=0-\sum_k\langle x,e_k\rangle\langle e_j,e_k\rangle=0$ (since $(e_n)$ is an orthonormal sequence)
Hence $x-y\in M^\perp=\{0\}\implies x=y\implies x=\sum_{k}\langle x,e_k\rangle e_k$
Check if it solves the issue.
A: Consider, for some $e_j \in M$
$$
\langle y, e_j \rangle = \left\langle \sum_{k=1}^\infty \langle x, e_k\rangle e_k,e_j\right\rangle = \sum_{k=1}^\infty\langle x,e_k\rangle\langle e_k,e_j\rangle = \langle x,e_j\rangle.
$$
Then $\langle y - x,e_j\rangle = 0$ for any $e_j \in M$. Since $M$ is complete, $y-x$ must be the zero element. 
A: Let $y_n = \sum_{i=1}^n \langle x, e_i \rangle e_i$ be the orthogonal projection of $x$ on the span of $e_1, e_2, \dots, e_n$. We need to show that $y_n$ converges to $x$, meaning that
$$
||y_n - x|| \xrightarrow{n \rightarrow \infty} 0.
$$
By the orthogonality of $y_n - x$ and $y_n$, we have
$$
||y_n - x||^2 = ||x||^2 - ||y_n||^2.
$$
This goes to zero as $n\rightarrow \infty$, by Parseval's identity, and shows that $$x = \lim_{n \rightarrow \infty} y_n = \sum_{i=1}^\infty \langle x, e_i \rangle e_i.$$

If you want to prove Parseval's identity at the same time.
Let $y_n$ be as above. You can verify that $||y_n|| \le ||x||$, for all $n$, and therefore $\sum_{i=1}^\infty \langle x, e_i\rangle^2$ converges. This implies (with a calculation) that $\{y_n\}$ is a Cauchy sequence in $H$ and that $$y = \lim_{n \rightarrow \infty}y_n = \sum_{i=1}^\infty \langle x, e_i\rangle e_i$$ exists. Furthermore, using the continuity of the scalar product, we find
$$
\langle y-x, e_i \rangle = 0,
$$
for all $i$, implying that $y = x$.
