The Fourier series of sawtooth (triangular) oscillations has the following form:
\[ F(z) = \frac{A}{2} + \sum_{m=1}^{\infty} \frac{2A}{m^2 \pi^2} (1 - (-1)^m) \cos \left( \frac{m\pi z}{L} \right), \]
where $A$ is the amplitude of oscillations and $2L$ is the period of oscillations.
Animation of partial sums $S_n$ (resulting rectangular oscillations indicated by dashed lines; $A = 1$, $L = 1$), convergence is very fast:

Source code: nb