A square wave is a kind of basic waveform. Ideally a square wave has instantaneous alternation between a maximum and a minimum (which can be zero or negative) amplitude level.
Origins and uses
Square waves are universally encountered in digital switching circuits.
In musical terms, it is often described as sounding hollow, and is therefore used as the basis for wind instrument sounds created using subtractive synthesis.
Examining the square wave
In contrast to the sawtooth wave, which contains all integer harmonics, the square wave contains only odd integer harmonics.
Using Fourier series we can write an ideal square wave as an infinite series of the form
A curiosity of the convergence of the Fourier series representation of the square wave is the Gibbs phenomenon. Ringing artifacts in non-ideal square waves can be shown to be related to this phenomenon. The Gibbs phenomenon can be prevented by the use of σ-approximation , which uses the Lanczos sigma factor s to help the sequence converge more smoothly.
An ideal square wave requires that the signal changes from the maximum to the minimum state cleanly and instantaneously. This is impossible to achieve in real-world systems, as it would require infinite bandwidth.
Real-world square-waves have only finite bandwidth, and often exhibit ringing effects similar to those of the Gibbs phenomenon, or ripple effects similar to those of the σ-approximation.
For a reasonable approximation to the square-wave shape, at least the fundamental and third harmonic need to be present, with the fifth harmonic being desirable. These bandwidth requirements are important in digital electronics, where finite-bandwidth analog approximations to square-wave-like waveforms are used. (The ringing transients are an important electronic consideration here, as they may go beyond the electrical rating limits of a circuit).
The ratio of the high to low periods of a square wave are called the duty cycle. A true square wave has a 50% duty cycle - equal high and low periods. The average level of a square wave is also given by the duty cycle, so by varying the on to off periods, it is possible to represent any value between the two limiting levels. This is the basis of pulse width modulation.