A square-wave grating equals its fundamental sinusoid plus odd harmonics (3f, 5f, 7f …), each with amplitude 1/k. Add components and watch the bars appear.
L(x) = L̄ · [ 1 + c · (4/π) ( sin 2πfx + ⅓ sin 2π(3f)x + ⅕ sin 2π(5f)x + ⅐ sin 2π(7f)x + … ) ]
1 component. A single sinusoid already looks bar-like, but the luminance ramps smoothly — there are no flat plateaus and no sharp edges.
Adding 3f. The peaks flatten and the edges steepen. Each added harmonic is finer (higher spatial frequency) and lower in contrast (1/k), so it only sharpens the transitions.
Edges cost high frequencies. Sharp luminance steps require energy at high spatial frequencies. Remove the high harmonics and the edges blur — exactly what low-pass filtering (optical blur, defocus, or a low-frequency-limited visual channel) does.
Gibbs ringing. With any finite number of components the sum overshoots at each edge and ripples along the plateau (≈ 9 % overshoot). Perceptually this relates to Mach-band-like edge effects.
Why only odd harmonics? A square wave is antisymmetric about its half-cycle: shifting by half a period inverts it. Even harmonics (2f, 4f …) are unchanged in sign by that shift, so they cannot contribute. Tick the 2f box to see the symmetry break.
Contrast sensitivity link. At low contrast a square-wave grating becomes visible when its fundamental reaches threshold — the classic result that the visual system responds to the sinusoidal components, not the edges (Campbell & Robson, 1968).
All gratings on screen share one luminance scaling, so contrasts are directly comparable. By default the peak of the fundamental alone (4/π) maps to full contrast; that leaves headroom for the overshoot, so the ideal square wave is drawn at π/4 ≈ 79 % of the display range rather than pure black/white. If a selection would exceed the display range (e.g. with the even harmonic added) the shared gain is reduced just enough to avoid clipping, and the label reads “contrast rescaled”. Fundamental = 3 cycles across the panel width; the profile plot uses the same horizontal scale, so features line up vertically. The plot y-axis is in units of the square wave's own amplitude (±1), independent of display gain.