This is a question from an exam I faild and I would really like to know how to solve it:
Let $J\subset\mathbb{Z}$ be a finite set and let $E_{J}=\text{Span}\left\{ e_{n}(x)\mid n\in J\right\} $ where $e_{n}(x)=e^{inx}$.
Now let $f\in R(\mathbb{T})$ (Means that $f$ is integrable and periodic over $\left[0,2\pi\right]$), and let $g\in E_{J}$ be that function such that: $$ \left\Vert f-g\right\Vert =\inf\left\{ \left\Vert f-h\right\Vert \mid h\in E_{J}\right\} $$
Prove that $$ g=\sum_{n\in J}\hat{f}(n)e_{n} $$
Just for clarification:
$\left\Vert \right\Vert $ is the norm of the inner product defined by $\left\langle f,g\right\rangle =\frac{1}{2\pi}\int_{0}^{2\pi}f(x)\overline{g(x)}dx$, and $\hat{f}(n)$ is the $n$'th Fourier Coefficient that is $\hat{f}(n)=\left\langle f,e_{n}\right\rangle =\frac{1}{2\pi}\int_{0}^{2\pi}f(x)e^{-inx}dx$.
This is what I know so far:
Let $N=\max\left\{ \left|n\right|\mid n\in J\right\} $, and let $S_{N}f=\sum_{n=-N}^{N}\hat{f}(n)e_{n}$. Now I already know that $$ \left\Vert f-S_{N}f\right\Vert =\inf\left\{ \left\Vert f-\sum_{n=-N}^{N}a_{n}e_{n}\right\Vert \mid a_{n}\in\mathbb{C}\right\} $$
That is the closest Trigonometric Polynomial of rank $\leq N$ to $f$ by norm. Also we can split $S_{N}f$ by $S_{N}f=\sum_{n\in J}\hat{f}(n)e_{n}+\sum_{n\notin J}\hat{f}(n)e_{n}$.
How can I continue?