Skip to content
Oakfield Operator Calculus Function Reference Site

Square Waves

A square wave alternates between two plateaus each half-period. A canonical 2π2\pi-periodic choice is

s(x)=sgn(sinx)s(x) = \operatorname{sgn}(\sin x)

Defined for periodic time or spatial axes. For the sign-based definition, outputs take values in {1,1}\{-1,1\} (or include 00 at discontinuities depending on the sign convention).


s(x)=4πn odd1nsin(nx)s(x) = \frac{4}{\pi}\sum_{n\ \text{odd}}^\infty \frac{1}{n}\sin(nx)

Odd harmonics dominate with amplitudes decaying as 1/n1/n.

02πs(x)dx=0\int_0^{2\pi} s(x)\,dx = 0

  • Duty cycle DD generalizes to a rectangular pulse train of width 2πD2\pi D.
  • Smooth approximation:
sβ(x)=tanh(βsinx)sgn(sinx)(β)s_\beta(x) = \tanh(\beta \sin x) \to \operatorname{sgn}(\sin x) \quad (\beta \to \infty)

Fourier series connect square waves to sums of sinusoids. Thresholding and smooth saturation functions provide hard and soft versions of the plateau transitions.


Oakfield does not currently ship a dedicated “square wave” stimulus operator.

Closest equivalents in the current runtime:

  • Checkerboard stimulus provides a piecewise-constant periodic pattern over space (useful for Gibbs/aliasing stress tests).
  • User-defined Lua operators can implement time-domain on/off pulses (square waves in time) if needed.
  • Soft thresholding/saturation can approximate hard switching when differentiability is important.

Square waves are a canonical example in Fourier analysis: a simple discontinuous waveform with an explicitly computable harmonic series and a visible Gibbs phenomenon.

They are widely used as test signals and as idealized switching inputs, often paired with smoothing when differentiability is required.


  • Stein & Shakarchi, Fourier Analysis
  • Bracewell, The Fourier Transform and Its Applications