<s>[INST] Where am I missing the factor $\frac12$ in my fourier series expansion? 
Question: A periodic function $f(t)$, with period $2\pi$ is defined as,
$$
 f(t) = \begin{cases}
 0 & \text{ if } -\pi<t<0, \\
 \pi & \text{ if } 0<t<\pi.
 \end{cases}
 $$
Find the Fourier series expansion of $f$.

Below is my working:
Since $f$ is neither odd nor even, we need to calculate both $a_n$ and $b_n$, the coefficients of cosine and sine respectively.
Note that for $n\geq 1$, we have
\begin{align*}
 a_n & = \frac{2}{\pi}\int_0^\pi f(t)\cos(nt)dt \\ 
 & = \frac{2}{\pi}\int_0^\pi \pi \cos(nt)dt \\ 
 & = 2 \int_0^\pi \cos(nt)dt \\ 
 & = 0.
 \end{align*}
Also,
\begin{align*}
 a_0 & = \frac{1}{\pi}\int_0^\pi f(t)dt \\ 
 & = \frac{1}{\pi}\int_0^\pi \pi dt \\ 
 & = \int_0^\pi dt \\ 
 & = \pi.
 \end{align*}
On the other hand, note that
\begin{align*}
 b_n & = \frac{2}{\pi}\int_0^\pi f(t)\sin(nt)dt \\
 & = \frac{2}{\pi}\int_0^\pi \pi \sin(nt)dt \\
 & = 2\int_0^\pi \sin(nt)dt \\
 & = 2 \left[ \frac{1-(-1)^n}{n} \right] \\
 & = \frac{2[1-(-1)^n]}{n}.
 \end{align*}
Therefore, the Fourier series of $f$ is
$$
 f(t) = \pi +  \sum_{n=1}^\infty \frac{2[1-(-1)^n]}{n} \sin(nt).
 $$
However, based on Wolfram alpha, it seems that I am missing the factor $\frac12$ throughout the fourier expansion.
Wolfram alpha gives
$$2 \sin(t) + \frac23 \sin(3t) + \frac25 \sin(5t) + \frac27 \sin(7t) + \frac{\pi}{2}.$$
I am not able to fathom why this is the case.
Any explanation would be greatly appreciated.
 [/INST] To see that the coefficients are wrong,
The Fourier series for $f(x)$ may be written
\begin{aligned}
f(x) &= a_0 + \sum_{n=1} a_n \cos n x + \sum_{n=1} b_n \sin n x 
\end{aligned}
The coefficients may be calculated
\begin{aligned}
a_0 &= \frac{\int_{-\pi}^{\pi} f(x) dx}{\int_{-\pi}^{\pi} 1 dx} \\
a_n &= \frac{\int_{-\pi}^{\pi} f(x) \cos nx dx}{\int_{-\pi}^{\pi} \cos^2 nx dx}, \quad n \geqslant 1 \\
b_n &= \frac{\int_{-\pi}^{\pi} f(x) \sin nx dx}{\int_{-\pi}^{\pi} \sin^2 nx dx}, \quad n\geqslant 1 \\
\end{aligned}
giving
\begin{aligned}
a_0 = \frac{1}{2 \pi} \int_{-\pi}^{\pi} f(x) dx, \quad a_n = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos n x~dx, \quad b_n = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x~dx.
\end{aligned}
You can easily verify the integrals of $\sin^2nx$ and $\cos^2nx$.
</s>