The Fourier series of rectangular oscillations has the following form:
\[ F(z) = \sum_{m=1}^{\infty} \frac{2A}{m\pi} \left( 1 - (-1)^m \right) \sin \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$):

Source code: nb