Square wave:
$$x(t) = \frac{4}{\pi}\sum_{n=1,3,5,...}^{}\frac{\sin(n\omega t)}{n}$$Odd harmonics only. Gibbs overshoot ≈ 9% at jumps.
Synthesize square, sawtooth, and triangle waves from rotating phasors. Watch real-time as adding harmonics approximates the target waveform. Experience the Gibbs phenomenon.
Square wave:
$$x(t) = \frac{4}{\pi}\sum_{n=1,3,5,...}^{}\frac{\sin(n\omega t)}{n}$$Odd harmonics only. Gibbs overshoot ≈ 9% at jumps.
The core idea is representing a periodic function $x(t)$ with period $T$ as an infinite sum of sine and cosine waves. The general Fourier series expansion is:
$$x(t) = a_0 + \sum_{n=1}^{\infty}\left[ a_n \cos(n \omega t) + b_n \sin(n \omega t) \right]$$Here, $\omega = 2\pi / T$ is the fundamental angular frequency. The coefficients $a_n$ and $b_n$ are calculated from the original wave's shape, determining the amplitude of each harmonic. For symmetric waves, many coefficients become zero, simplifying the series.
For the square wave shown in the simulator, the symmetry forces all $a_n$ and even $b_n$ terms to zero. The remaining series, using only odd sine terms, is:
$$x_{\text{square}}(t) = \frac{4}{\pi}\sum_{k=0}^{\infty}\frac{\sin\big((2k+1)\omega t\big)}{2k+1}$$In this formula, $k$ is an integer starting at 0, so $(2k+1)$ generates the odd harmonics: 1, 3, 5,... The factor $4/\pi$ scales the sum to match the square wave's amplitude. Each term $\frac{\sin(n\omega t)}{n}$ represents a spinning phasor (circle) in the visualization, with its radius shrinking as $1/n$.
Audio Synthesis & Music: Fourier series are the foundation of subtractive synthesis in electronic music. A synthesizer starts with a rich wave (like a sawtooth, full of harmonics) and uses filters to remove frequencies, shaping the final sound. The different harmonic content is why a square wave sounds "hollow" and a sawtooth sounds "buzzy."
Signal Processing & Compression: JPEG image compression and MP3 audio compression rely heavily on Fourier-type transforms. They break down complex signals (an image's rows of pixels, a song's audio waveform) into frequency components, then discard the least perceptible ones to dramatically reduce file size.
Electrical Engineering & Power Systems: Modern electronic devices (like computers) draw non-sinusoidal current from the wall, creating harmonic distortion on the power grid. Engineers use Fourier analysis to measure these harmonics and design filters to prevent equipment damage and inefficiency.
Medical Imaging (MRI): Magnetic Resonance Imaging machines don't take a direct picture. They measure the Fourier components of spin signals from hydrogen atoms in your body. A computer then performs an inverse Fourier transform to reconstruct the detailed cross-sectional image you see.
When you start using this tool, there are a few points that are easy to misunderstand, so be careful. First, you might think "if you make the number of harmonics N infinite, you get a perfect waveform". However, for waveforms with sharp discontinuities like a square wave, the Gibbs phenomenon leaves an overshoot of about 9%. This is mathematically inescapable; it doesn't change whether N=100 or N=1000. In practical work, you need to design with this "cannot be perfectly reproduced" characteristic in mind.
Next, don't confuse the relationship between the "fundamental frequency" and the "waveform period". For example, if the fundamental frequency $f_1$ is 50Hz, its period $T_1$ is $1/50 = 0.02$ seconds, right? However, the period of the synthesized square wave also becomes 0.02 seconds. In the time of one fundamental period, the synthesized waveform also completes one cycle. Try moving the "Fundamental Frequency" slider in the tool to see how the phasor rotation speed and the waveform repetition speed change in sync.
Finally, as a practical pitfall, there is "truncation error". Because you truncate an infinite series at a finite N, error inevitably occurs. For instance, a square wave with N=9 is a state where terms from n=17 onward in the theoretical formula $$x_{\text{square}}(t) = \frac{4}{\pi}\sum_{n=1,3,5,...}^{\infty}\frac{\sin(n\omega t)}{n}$$ are ignored. This error converges quickly and is small for smooth waves like triangle waves, but tends to remain as oscillation (ringing) for square waves. In practical signal processing, you decide N by considering the trade-off between required accuracy and computational cost.
A square wave at 2 Hz with 15 harmonics shows fundamental amplitude of 1.27 V and peak harmonic energy at the 3rd, 5th, and 7th components. Including only 5 harmonics yields approximation error around 18%; extending to 25 harmonics reduces error below 3%. The Gibbs phenomenon manifests as a 9% overshoot near edges, persisting even at 40 harmonics due to the discontinuous nature of the square wave.