I'm learning about Fourier series, and I have to solve the following exercise:
Exercise: Let $f:[0,2\pi)\to\mathbb{R}$ be given by $f = \mathbb{1}_{[0,\pi]}$. Write $f$ as a series of sines as in example $8.8$ and give an estimate of the $L^2$-error given by $\|f-s_n(f)\|_2^2 = 2\pi\sum_{\left|k\right|>n}\left|\widehat{f}(k)\right|^2$.
Example $8.8$: Let $f:[0,2\pi)\to\mathbb{R}$ be defined by $f(x) = x -\pi$ and extended periodically on $\mathbb{R}$. For $k\in\mathbb{Z}\backslash\{0\}$, by the fundamental theorem of calculus and integration by parts,
$$\widehat{f}(k) = \dfrac{1}{2\pi}\displaystyle\int_0^{2\pi}(x-\pi)e^{-ikx}dx = -\dfrac{1}{ik}.$$ Clearly $\widehat{f}(0) = 0$, and therefore we have that $f = -\sum_{k\in\mathbb{Z}\backslash\{0\}}\dfrac{e_k}{ik}$ with convergence in $L^2(0,2\pi)$. Moreover, using that $2\sin(kx) = \dfrac{e_k - e_{-k}}{i}$ we also find that $f = -2\sum\limits_{k=1}^\infty\dfrac{\sin(k\cdot)}{k}$ with convergence in $L^2(0,2\pi)$.
What I've tried: I think I understand the exercise and the above example correctly. However, using $f = \mathbb{1}_{[0,2\pi]}$ I get $$\widehat{f}(k) = \dfrac{1}{2\pi}\int_0^{2\pi}\mathbb{1}_{[0,\pi]}e^{-ikx}dx = \dfrac{1}{2\pi}\int_0^\pi e^{-ikx}dx.$$ Since I end up with an integral from $0$ to $\pi$, instead from $0$ to $2\pi$ as in the example, the value of the interval depends on the value of $k$. For $k$ even you would get $\widehat{f}(k) = 0$ and for odd $k$ you would get $\widehat{f}(0) = \dfrac{1}{2}$. I'm not sure how I should deal with this!
Question: How should I solve this exercise?
Thanks!
This is just a matter of grinding carefully through the details.
First note that you cannot write $f$ simply as the sum of $\sin$s as $f$ is not odd. Note that $f(0) = {1 \over 2}$. For $k \neq 0$ we have $\hat{f}(k) = {1 \over 2 \pi i k} (1-e^{-i \pi k}) = {1 \over 2 \pi i k} (1-(-1)^k) $.
Hence we have \begin{eqnarray} s_{2n+1}(f)(x) &=& \sum_{|m| \le 2n+1} \hat{f}(m) e^{i m x} \\ &=& {1 \over 2} + \sum_{k=0}^n (\hat{f}(-(2k+1)) e^{-i(2k+1)x} + \hat{f}(2k+1) e^{i (2k+1)x}) \\ &=& {1 \over 2} + \sum_{k=0}^n (\hat{f}(-(2k+1)) e^{-i(2k+1)x} + \hat{f}(2k+1) e^{i (2k+1)x}) \\ &=& {1 \over 2} +\sum_{k=0}^n 2 \operatorname{re} ( \hat{f}(2k+1) e^{i (2k+1)x} ) \\ &=&{1 \over 2} +\sum_{k=0}^n {2 \over \pi (2k+1)} \sin ((2k+1) x) \end{eqnarray}
Parseval gives \begin{eqnarray} \|f-s_{2n+1}(f) \|^2 &=& 2 \pi \sum_{|m| > 2n+1} |\hat{f}(m)|^2 \\ &=& 2 \pi \sum_{k=n+1}^\infty (|\hat{f}(-(2k+1))|^2+ |\hat{f}(2k+1)|^2 ) \\ &=& 4 \pi \sum_{k=n+1}^\infty {1 \over (\pi (2k+1))^2 } \\ &=& {4 \over \pi} \sum_{k=n+1}^\infty {1 \over (2k+1)^2 } \\ &\le& {4 \over \pi} \int_n^\infty {1 \over (2x+1)^2} dx \\ &=& {2 \over \pi} {1 \over 2n+1} \end{eqnarray}