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 and period can be defined over one cycle by
Its fundamental frequency is , and its angular frequency is . The peak-to-peak amplitude is .
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
where 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 and a positive voltage . With equal high and low durations, its mean is , whereas the symmetric waveform switching between and has zero mean.
Duty cycle and rectangular waves
The duty cycle is the fraction of a period spent at the high level:
where is the high-state duration. A square wave conventionally has . 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 and , the period average is
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
Equivalently,
Only odd harmonics occur: the fundamental frequency , followed by . 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,
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 , which is greater than . 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 on and on , write the complex Fourier series as
Its coefficients are
and, for ,
This expression shows how duty cycle controls the spectrum. Whenever is an integer, the corresponding nonzero-frequency coefficient vanishes. At , 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 and , 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 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
Its root-mean-square value is consequently
For a symmetric square wave switching between and ,
For a waveform switching between and with 50% duty cycle,
The fundamental component of the symmetric square wave has mean square
It therefore accounts for , or approximately , of the total mean square. The remaining approximately 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,
where 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.