Square wave of period 2*L

def square(x):
    """Square wave of period 2*L"""

    def H(x):
        """Heaveside step function"""

        if x < 0.:
            return 0.
        if x == 0.:
            return 0.5
        if x > 0.:
            return 1.
    return 2 * (H(x / L) - H(x / L - 1)) - 1