The Fourier series of a function $f=f(t)$ with period $2L$ is defined by $$Sf(t):=a_0+\sum_{n=1}^{\infty}\left[a_n\cos\frac{n\pi t}{L}+b_n\sin\frac{n\pi t}{L}\right],$$ where \begin{align} a_0&:=\frac{1}{2L}\int_{-L}^{L}f(t)\,dt,\\ a_n&:=\frac{1}{L}\int_{-L}^{L}f(t)\cos\frac{n\pi t}{L}\,dt,\\ b_n&:=\frac{1}{L}\int_{-L}^{L}f(t)\sin\frac{n\pi t}{L}\,dt, \end{align} and $f$ and $f'$ are piecewise continuous on $[-L,L]$.

How this conclusion was achieved will be elaborated upon later. For now, let us apply it to a couple functions.

Example 1: compute the Fourier series of $$f(t):=\left\{\begin{matrix} 1,\qquad\text{for }0<t<\pi;\\ 0,\qquad\text{for }t=0\text{, }\pm\pi;\\ -1,\qquad\text{for }-\pi<t<0; \end{matrix}\right.$$ with $f(t)=f(t+2\pi)$ for all $t$.

Visually, this is what we have:

Note that both $f$ and $f'$ are continuous. Because of this, we can compute its Fourier series.

Also note that $L=\pi$.

To find $a_0$, observe that $f$ is an odd function. Hence, the integral $$a_0=\frac1{2\pi}\int_{-\pi}^\pi f(t)\,dt=0,$$ because the areas "cancel out."

To find $a_n$, observe that the product of $f$ (odd) and $\cos$ (even) is an odd function. Therefore, as with $a_0$, $$a_n=\frac1\pi\int_{-\pi}^\pi f(t)\cos nt\,dt=0.$$ Finally, to compute $b_n$, observe that the product of $f$ (odd) and $\sin$ (odd) is an even function. As a result, $$b_n=\frac1\pi\int_{-\pi}^\pi f(t)\sin nt\,dt=\frac2\pi\int_0^\pi\sin nt\,dt=\frac2{n\pi}\left[-\cos nt\right]_0^\pi=-\frac2{n\pi}\left[\cos n\pi-1\right]=-\frac2{n\pi}\left[(-1)^n-1\right].$$ This implies that $$b_n=\left\{\begin{matrix} 0\qquad\text{if }n\text{ is even},\\ \frac4{n\pi}\qquad\text{if }n\text{ is odd}. \end{matrix}\right.$$ As a result, $Sf(t)$ boils down to $$Sf(t)=\sum_{k=1}^\infty\frac4{(2k-1)\pi}\sin[(2k-1)t].$$ To test this Fourier series' power, if we let the upper bound of summation be equal to just $10$, we will get the following approximation to our function $f$:

I am still trying to get the hang of Fourier series, specially when it comes down to computing the values of the coefficients' integrals based on the functions' products as well as their symmetries. Functional parity is something new to me although I have had the concept in mind for many years. When I get better at them, I will be able to approximate functions in terms of infinite sums! Hopefully this will simplify the study of nonhomogeneous PDEs.