Did I calculate this Fourier series correctly? If we use the definition of the Fourier series in the following way:
$$f(x) = \frac{A_{0}}{2} + \sum_{n=1}^\infty A_n \cos(nx) + B_n \sin(nx)$$
then if $-\pi < x < \pi$, and $f(x) = \operatorname{sgn}(x)$, then I get $\displaystyle\frac{4}{\pi}\sum_{n=0}^\infty \frac{\sin(2n+1)x}{2n+1}$. Does this answer look correct?
Also, if I have a function like,
$f(x) = B$ if $0 < x < l$ and $f(x) = 0$ if $l < x < 2l$, then how would my $A_0$, $A_n$, and $B_n$ be defined? I have only used problems where $-\pi < x < \pi$ so I am not sure how to set them up when $x$ is not between $-\pi$ and $\pi$.
Thanks!
 A: Your solution is correct, but I generally write it as
$$
\frac{4}{\pi}\sum_{n = 1}^{\infty}\frac{\sin[(2n - 1)x]}{2n - 1}
$$
For a range other than $-\pi < x < \pi$, let's take the same problem
The coefficients would be found as
$$
B_n = \frac{2}{\ell}\int_0^{\ell}f(x)\sin\Big(\frac{n\pi x}{\ell}\Big)dx
$$
and similarily for $\cos(nx)$.  In the $\pi$ case, it is
$$
B_n = \frac{2}{2\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx
$$
and 
$$
\frac{2}{2\pi} = \frac{1}{\pi}
$$
This all comes from 
\begin{align}
f(x) &= \sum_{n = 1}^{\infty}B_n\sin(nx)\\
\int_{-\pi}^{\pi}f(x)\sin(mx)dx &= \int_{-\pi}^{\pi}\sum_{n = 1}^{\infty}B_n\sin(nx)\sin(mx)dx\tag{1}
\end{align}
Being a little cavalier, (that is without justification), we swap the integrand and the sum.  All other integrals are zero unless $m = n$.  This comes from the fact the standard orthonormal basis is
$$
\Big\{\frac{1}{\sqrt{2}}, \sin(x), \ldots, \sin(nx), \cos(x), \ldots, \cos(nx)\Big\}
$$
with inner product
$$
\langle f, g\rangle = \frac{1}{\pi}\int_{-\pi}^{\pi}fg \ dx = 
\begin{cases}
0, & \text{if } f\neq g\\
1, & \text{if } f = g
\end{cases}
$$
Therefore, (1) becomes
$$
\int_{-\pi}^{\pi}f(x)\sin(nx) dx = A_n\int_{-\pi}^{\pi}\sin^2(nx)dx = 
\frac{A_n}{2}\int_{-\pi}^{\pi}(1 - \cos(2x))dx 
$$
Thus,
$$
A_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx
$$
We could repeat this process for $0 < x < \ell$ and $\ell < x < 2\ell$ or any bounds given but is always works out to $\frac{2}{L}$ where $L$ is the length of the interval.

Expanding on how to change of bounds when integrating over something other than $(-\pi, \pi)$.
Define $T: (-\pi, \pi)\to (-\ell, \ell)$. Then $u = T(\theta) = m\theta$ where $m = \frac{\ell}{\pi}$. Let $\theta = f(u)$.
$$
\theta\overbrace{\to}^Tu\overbrace{\to}^ff(u)
$$
Therefore, $\theta = \frac{\pi}{\ell}u$ so
\begin{align}
f(\theta) &= A_0 + \sum_{n = 1}^{\infty}\bigg[A_n\cos\Big(\frac{n\pi u}{\ell}\Big) + A_n\sin\Big(\frac{n\pi u}{\ell}\Big)\bigg]\\
A_0 &= \frac{1}{2\ell}\int_{-\ell}^{\ell}f(u)du\\
A_n &= \frac{1}{\ell}\int_{-\ell}^{\ell}f(u)\cos\Big(\frac{n\pi u}{\ell}\Big)du\\
B_n &= \frac{1}{\ell}\int_{-\ell}^{\ell}f(u)\sin\Big(\frac{n\pi u}{\ell}\Big)du
\end{align}
