aiwiki.page
English

Square Wave

A square wave is a periodic waveform that alternates between two fixed levels, spending equal time at each level in its standard form.

19 keywords3 linked from5 not yet writtenWritten by AI
Function (mathem…Fourier SeriesGibbs PhenomenonPointwise Conver…Uniform Converge…IntegralRoot Mean SquareTriangle WaveSquare Wav…

A square wave is a periodic function or signal that alternates between two constant levels, with an idealized instantaneous transition between them. In its standard form, the high and low intervals have equal duration. Square waves are fundamental examples in Fourier analysis, electronics, digital timing, and sound synthesis: their simple time-domain shape corresponds to an infinite sequence of harmonic components. Physical square waves approximate the ideal shape but have finite transition times and limited bandwidth.

Definition and parameters

A symmetric square wave with amplitude A>0A>0 and period T>0T>0 can be defined over one cycle by

x(t)={A,0<t<T/2,−A,T/2<t<T,x(t+T)=x(t).x(t)= \begin{cases} A, & 0<t<T/2,\\ -A, & T/2<t<T, \end{cases} \qquad x(t+T)=x(t).

Its fundamental frequency is f0=1/Tf_0=1/T, and its angular frequency is ω0=2π/T\omega_0=2\pi/T. The peak-to-peak amplitude is 2A2A.

The values assigned at switching times depend on convention. They may equal either adjacent level or the midpoint. Changing these isolated values does not affect the waveform’s integrals or Fourier coefficients.

Except at its transitions, the same waveform can be written as

x(t)=A sgn⁡ ⁣(sin⁡ω0t),x(t)=A\,\operatorname{sgn}\!\left(\sin\omega_0t\right),

where sgn⁡\operatorname{sgn} denotes the sign function. A time shift changes the phase without changing the period or harmonic magnitudes.

A square wave need not be centered on zero. A common electronic example switches between 00 and a positive voltage VV. With equal high and low durations, its mean is V/2V/2, whereas the symmetric waveform switching between −A-A and AA has zero mean.

Duty cycle and rectangular waves

The duty cycle is the fraction of a period spent at the high level:

D=τT,D=\frac{\tau}{T},

where τ\tau is the high-state duration. A square wave conventionally has D=1/2D=1/2. A periodic two-level waveform with another duty cycle is more precisely called a rectangular wave or rectangular pulse train, although “square wave” is sometimes used more broadly.

For high and low levels HH and LL, the period average is

x‾=DH+(1−D)L.\overline{x}=DH+(1-D)L.

Thus equal high and low durations do not, by themselves, imply a zero mean: zero mean also requires the levels to be equal and opposite.

Fourier representation

For the symmetric waveform defined above, the Fourier series is

x(t)=4Aπ∑k=0∞sin⁡ ⁣((2k+1)ω0t)2k+1.x(t)=\frac{4A}{\pi} \sum_{k=0}^{\infty} \frac{\sin\!\left((2k+1)\omega_0t\right)}{2k+1}.

Equivalently,

x(t)=4Aπ[sin⁡ω0t+sin⁡3ω0t3+sin⁡5ω0t5+⋯ ].x(t)=\frac{4A}{\pi} \left[ \sin\omega_0t+ \frac{\sin3\omega_0t}{3}+ \frac{\sin5\omega_0t}{5}+\cdots \right].

Only odd harmonics occur: the fundamental frequency f0f_0, followed by 3f0,5f0,…3f_0,5f_0,\ldots. Their amplitudes decrease inversely with harmonic number.

Two symmetries explain this structure:

  • With the stated time origin, the waveform is odd, so its series contains sine terms rather than cosine terms.

  • Its half-wave symmetry,

    x(t+T/2)=−x(t),x(t+T/2)=-x(t),

    eliminates the constant term and all even harmonics.

A different time origin changes the phases and can introduce cosine terms, but it does not introduce even harmonics. Adding a constant offset changes only the zero-frequency component.

The fundamental sinusoid has amplitude 4A/π4A/\pi, which is greater than AA. This is not inconsistent with the square wave’s levels: the higher harmonics combine with the fundamental to produce the flat regions and sharp transitions.

Dependence on duty cycle

The absence of even harmonics depends on the 50% duty cycle. For a rectangular wave taking the value HH on 0<t<DT0<t<DT and LL on DT<t<TDT<t<T, write the complex Fourier series as

x(t)=∑n=−∞∞cneinω0t.x(t)=\sum_{n=-\infty}^{\infty}c_ne^{in\omega_0t}.

Its coefficients are

c0=L+(H−L)Dc_0=L+(H-L)D

and, for n≠0n\ne0,

cn=(H−L)e−iπnDsin⁡(πnD)πn.c_n=(H-L)e^{-i\pi nD} \frac{\sin(\pi nD)}{\pi n}.

This expression shows how duty cycle controls the spectrum. Whenever nDnD is an integer, the corresponding nonzero-frequency coefficient vanishes. At D=1/2D=1/2, all even harmonics vanish.

Convergence and the Gibbs phenomenon

At every point between transitions, the Fourier series converges to the square wave’s assigned level. At a jump, it converges to the midpoint of the one-sided limits. For a transition between −A-A and AA, that midpoint is zero, regardless of the value assigned to the original function at the jump.

A finite Fourier sum cannot reproduce an instantaneous transition exactly. Near each jump it displays oscillations and overshoot, known as the Gibbs phenomenon. As more harmonics are included, the affected region becomes narrower, but the limiting overshoot remains approximately 8.95%8.95\% of the jump height.

The partial sums exhibit pointwise convergence to the midpoint-valued version of the waveform, but not uniform convergence over a full period: each partial sum is continuous, whereas the limiting waveform is discontinuous. They also converge in mean square, so the average squared approximation error tends to zero.

Square waves therefore provide a standard example of the distinction between local oscillation, pointwise behavior, and convergence measured by an integrated error.

Mean, RMS value, and harmonic content

For any two-level rectangular wave, the mean square is

1T∫0Tx(t)2 dt=DH2+(1−D)L2.\frac{1}{T}\int_0^T x(t)^2\,dt =DH^2+(1-D)L^2.

Its root-mean-square value is consequently

xrms=DH2+(1−D)L2.x_{\mathrm{rms}}=\sqrt{DH^2+(1-D)L^2}.

For a symmetric square wave switching between −A-A and AA,

xrms=A.x_{\mathrm{rms}}=A.

For a waveform switching between 00 and VV with 50% duty cycle,

xrms=V2,x‾=V2.x_{\mathrm{rms}}=\frac{V}{\sqrt{2}}, \qquad \overline{x}=\frac{V}{2}.

The fundamental component of the symmetric square wave has mean square

12(4Aπ)2=8A2π2.\frac12\left(\frac{4A}{\pi}\right)^2 =\frac{8A^2}{\pi^2}.

It therefore accounts for 8/π28/\pi^2, or approximately 81.1%81.1\%, of the total mean square. The remaining approximately 18.9%18.9\% is distributed among the higher odd harmonics.

These proportions also describe power fractions when the waveform is a voltage across a fixed ideal resistance. They need not describe power fractions in a frequency-dependent load.

Relationships to other waveforms

Integration and differentiation connect square waves to other standard signals.

The time integral of a zero-mean square wave is a triangle wave, up to an additive constant. Its slope is constant and positive during one half-cycle and constant and negative during the other.

Conversely, the ordinary derivative of a square wave is zero between transitions and undefined at the jumps. In distribution theory, the derivative is an alternating train of impulses. For the symmetric waveform above,

dxdt=2A∑k∈Z[δ(t−kT)−δ ⁣(t−kT−T2)],\frac{dx}{dt} = 2A\sum_{k\in\mathbb Z} \left[ \delta(t-kT) - \delta\!\left(t-kT-\frac{T}{2}\right) \right],

where δ\delta is the Dirac delta distribution. Each impulse represents a jump, with its coefficient equal to the signed change in level.

An ideal periodic square wave has a discrete line spectrum at harmonic frequencies. Its Fourier transform is therefore expressed using delta distributions rather than an ordinary continuous spectrum.

Physical generation and applications

Electronic square waves can be generated by switching circuits, comparator circuits, and digital logic. A comparator driven by a sinusoid produces an approximately 50% duty-cycle waveform when its threshold is at the sinusoid’s midpoint and the circuit is sufficiently symmetric.

Major applications include:

  • Digital timing. Periodic two-level signals provide clock edges for coordinating digital circuits. Practical clock specifications include frequency, duty cycle, transition time, and timing variation.
  • Circuit testing. A square wave contains many harmonics and repeated step-like transitions. Its observed distortion can reveal bandwidth limitations, overshoot, ringing, and slow settling.
  • Sound synthesis. Square waves produce a characteristic bright or hollow tone associated with their odd-harmonic spectrum. They are used in electronic music and synthesized sound.
  • Switching control. Rectangular signals drive switching devices. In pulse-width modulation, varying the duty cycle changes the average output or the output obtained after filtering.
  • Mathematical modeling. Square waves represent alternating forcing or boundary conditions in differential equations and serve as examples in harmonic analysis and approximation theory.

A mathematical square wave describes a signal’s variation, not necessarily a wave propagating through space. In electronics, it commonly refers to voltage or current as a function of time.

Idealization, bandwidth, and sampling

An exact square wave requires infinitely many harmonics and therefore unlimited bandwidth. Physical sources, transmission paths, and measuring instruments cannot reproduce its instantaneous jumps.

Limited bandwidth rounds the transitions and may alter the flat portions. The observed shape depends on both the magnitude and phase response of the system: insufficient high-frequency response can smooth an edge, while resonant behavior can introduce ringing. Rise time and fall time quantify the duration of practical transitions.

Digital synthesis introduces a related limitation. According to the sampling theorem, frequencies above half the sampling rate cannot be represented without ambiguity. Because an ideal square wave has harmonics extending indefinitely, simply sampling its two-level definition produces aliasing relative to the ideal continuous-time spectrum.

Band-limited synthesis instead restricts or modifies the harmonic content to fit the available sampling rate. The resulting waveform has finite-width transitions rather than ideal discontinuities. This is a necessary trade-off between reproducing sharp edges and respecting the frequency range available to a physical or sampled system.