Kolton Ndoj

Building a square wave from sines

Add enough smooth, rounded waves and you can make something with perfectly sharp corners.

4π(sin⁡t+sin⁡3t3+sin⁡5t5+… )=square wave\frac4\pi\left(\sin t+\frac{\sin3t}{3}+\frac{\sin5t}{5}+\dots\right)=\text{square wave}

What the symbols mean

sin⁡(kt)\sin(kt)
smooth waves at odd multiples of the base pitch
1k\frac1k
each one is weaker by this factor

Why it works — the picture

Start with sin t, a gentle hill. Add one third of sin 3t and the hill squares off a little; add one fifth of sin 5t and the corners sharpen. Each new wave pushes the middle flatter and the edges steeper. In the limit the sum is a wave that flips between +1 and -1. Near each jump the partial sums always overshoot by about 9 percent: the Gibbs ringing.

Graph for Building a square wave from sines -771.6-1.6
Turn the extra harmonics down to zero and see a plain sine; turn them up one by one and watch the plateaus flatten. (drawn with the default slider values — move the sliders live)

Try it yourself

Where it’s used in real life

Sound compression (MP3), JPEG, radio and any signal analysis start with splitting into sine waves.

The story behind it

Joseph Fourier introduced the idea in his heat-flow work around 1807.

Related

Play with it live →

Math · Fourier analysis · Stretch