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

Graph of the Square Wave y=sgn(sinx)y = \operatorname{sgn}(\sin x)

The function y=sgn(sinx)y = \operatorname{sgn}(\sin x) extracts only the sign of the sine, giving a square wave whose value alternates between +1+1 and 1-1.

Definition

The sign function sgn\operatorname{sgn} is defined by

sgn(t)={+1(t>0)0(t=0)1(t<0)\operatorname{sgn}(t) = \begin{cases} +1 & (t > 0) \\ 0 & (t = 0) \\ -1 & (t < 0) \end{cases}

and this function applies it to t=sinxt = \sin x.

Values, domain, and range

Its domain is all real numbers. Where sinx>0\sin x > 0 it equals +1+1, where sinx<0\sin x < 0 it equals 1-1, and where sinx=0\sin x = 0, at x=nπx = n\pi, it is exactly 00. Its range is therefore the three values {1, 0, +1}\{-1,\ 0,\ +1\}.

Periodicity and symmetry

Its period is 2π2\pi, the same as sine: it equals +1+1 on 0<x<π0 < x < \pi and 1-1 on π<x<2π\pi < x < 2\pi. Since sgn(sin(x))=sgn(sinx)=sgn(sinx)\operatorname{sgn}(\sin(-x)) = \operatorname{sgn}(-\sin x) = -\operatorname{sgn}(\sin x), it has the odd symmetry of point symmetry about the origin (away from its discontinuities).

Discontinuities

At each x=nπx = n\pi the value jumps discontinuously between +1+1 and 1-1. The jump has size 22, and the value at the instant of the jump is 00. In contrast to the smooth sine wave, the graph consists only of horizontal segments and vertical jumps — a staircase, or square, shape.

Relation to other functions

The square wave has the Fourier series

sgn(sinx)=4πk=0sin((2k+1)x)2k+1\operatorname{sgn}(\sin x) = \frac{4}{\pi}\sum_{k=0}^{\infty}\frac{\sin((2k+1)x)}{2k+1}

a sum of odd-harmonic sines. Approximating it with finitely many terms leaves an overshoot near the jumps known as the Gibbs phenomenon.

Applications

Square waves are fundamental in engineering as clock signals in digital circuits, in on-off control, in pulse-width modulation (PWM), and in electronic sound synthesis.