Find the fourier series of a piecewise continuous function 
Consider the function 
  $f(x) =
\begin{cases}
0 & & x \in [-\pi, 0) \\
1 & & x \in [0, \frac{\pi}{2})\\
0 & & x \in [\frac{\pi}{2}, \pi)\\
\end{cases}$
  Calculate its fourier series 

I am unsure if this is correct but i have:
$a_0=\frac{1}{2\pi} \int_{-\pi}^{\pi}f(x)dx=\frac{1}{2\pi} \int_{0}^{\frac{\pi}{2}}1dx=\frac{1}{2\pi}[x]_{0}^{\frac{\pi}{2}}=\frac{1}{4}$
$a_n=\frac{1}{\pi} \int_{-\pi}^{\pi}f(x)\cos(nx)dx=\frac{1}{\pi} \int_{0}^{\frac{\pi}{2}}\cos(nx)dx=\frac{1}{\pi}[\frac{1}{n}\sin(nx)]_{0}^{\frac{\pi}{2}}=\frac{1}{n\pi}$
$b_n=\frac{1}{\pi} \int_{-\pi}^{\pi}f(x)\sin(nx)dx=\frac{1}{\pi} \int_{0}^{\frac{\pi}{2}}\sin(nx)dx=\frac{1}{\pi}[\frac{1}{n}(-\cos(nx))]_{0}^{\frac{\pi}{2}}=\frac{-1}{n\pi}$
So we have $f(x)=\frac{1}{4}+\sum_{n=0}^{\infty}[\frac{1}{n\pi} \cos(nx) - \frac{1}{\pi} \sin(nx)]$
Is this correct?


It should be $$\\ { a }_{ 0 }=\frac { 1 }{ 2 } \\ { a }_{ n }=\frac { \sin { \left( \frac { \pi n }{ 2 }  \right)  }  }{ n\pi  } \\ { b }_{ n }=\frac { 1-\cos { \left( \frac { \pi n }{ 2 }  \right)  }  }{ n\pi  } \\ \\ \\ $$
