I'm trying to find the Fourier series of the function defined on the interval $(-2,2)$ $$ f(x)=\begin{cases} 0,& \,\,\, |x| <1 \\ 1, & \,\,\, 1<|x|<2 \end{cases} $$ This should be trivial. I have calculated the components to be \begin{eqnarray*} a_0&=&\frac{1}{4}\int _{-2}^2f(x)\mathrm{d}x=\frac{1}{4}\left(\int _{-2}^{-1}\mathrm{d}x+\int _1^2\mathrm{d}x\right)=\frac{1}{4}((-1-(-2))+2-1)=\frac{1}{2}\\ a_n&=&\frac{1}{2}\int _{-2}^2f(x)\cos \frac{n\pi x}{2}\mathrm{d}x=\frac{1}{2}\left(\int _{-2}^{-1}\cos \frac{n\pi x}{2}\mathrm{d}x+\int _1^2 \cos \frac{n\pi x}{2}\mathrm{d}x\right)\\ &=&\frac{1}{2}\cdot \frac{2}{n\pi }\left(-\sin \frac{n\pi }{2}+\sin n\pi +\sin n\pi -\sin \frac{n \pi }{2}\right)=-\frac{2(-1)^{n+1}}{n\pi }=\frac{2(-1)^n}{n\pi } \end{eqnarray*} which give the following series expansion $$f(x)=\frac{1}{2}+\frac{2}{\pi }\sum _{n=1}^{\infty }\frac{(-1)^n\cos \frac{n\pi x}{2}}{n}$$ But when I plot the function for the first 1000 coefficients I get

which doesn't look good. I have went through the calculation many times and I can't find the mistake.
$$\frac{1}{2}\int_{1}^{2}\sin\left(\frac{\pi n x}{2}\right)\,dx = \frac{1}{n\pi}\left(\cos\frac{n\pi}{2}-\cos(n\pi)\right)$$
$$\frac{1}{2}\int_{1}^{2}\cos\left(\frac{\pi n x}{2}\right)\,dx = -\frac{1}{n\pi}\,\sin\frac{n\pi}{2}$$ hence:
Here it is the partial sum till $m=10$:
$\hspace1in$