Convert between real and complex Fourier series

Let f be a function with period 2L. To convert between the Fourier series

f(x) = \sum_{n=-\infty}^\infty c_n \exp\left(\frac{\pi i n x}{L}\right)

in terms of complex exponentials and the Fourier series

{f(x) = \frac{a_0}{2} + \sum_{n=1}^\infty
  \Biggl(a_n \cos\left(\frac{\pi n x}{L}\right) + b_n \sin\left(\frac{\pi n x}{L}\right)  \Biggr)

in terms of sines and cosines, the conversions are as follows.


\begin{align*}
  c_n &= \frac{a_n - i b_n}{2} \\
  c_{-n} &= \frac{a_n + i b_n}{2} \\
  a_n &= c_n + c_{-n} \\
  b_n &= i(c_n - c_{-n})
\end{align*}