Fourier Series Visualizer Back
Signal Processing & Math

Fourier Series Visualizer

Synthesize square, sawtooth, and triangle waves from rotating phasors. Watch real-time as adding harmonics approximates the target waveform. Experience the Gibbs phenomenon.

Waveform
Parameters
Harmonics N
Animation Speed
×
Display
Results
7
Harmonics used
f₁
Fundamental freq.
Max amplitude
Approx. error
Phasor Animation + Synthesized Waveform
Frequency Spectrum (Harmonic Amplitudes)
Theory & Key Formulas

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.

What is a Fourier Series?

🙋
What exactly is a Fourier series? I see the simulator is drawing a square wave from a bunch of spinning circles.
🎓
Basically, it's a way to build any repeating wave—like a square or triangle wave—from a sum of simple sine waves. Each spinning circle you see is a "harmonic," a sine wave with a specific frequency. Try moving the "Harmonics N" slider above from 1 to 5. See how adding more circles makes the red line look more like a perfect square?
🙋
Wait, really? So any weird, jagged signal can be made from smooth sine waves? Why does the square wave formula only use odd numbers (1, 3, 5...)?
🎓
Great observation! That's a symmetry property. A perfect square wave is "odd symmetric," meaning it flips perfectly around the center. Even-numbered sine waves don't have that symmetry, so they cancel out. In practice, this means we only need half the terms to build it. Switch the wave type to "sawtooth" in the simulator—you'll see it uses all integers, which changes the sound and look completely.
🙋
Okay, I see the wiggly overshoot near the square wave's edges, even with many circles. What's that called, and does it ever go away?
🎓
That's the Gibbs phenomenon! It's a classic result: when you try to approximate a jump (like the square wave's instant rise) with a finite sum of smooth sines, you get about a 9% overshoot that never fully disappears, no matter how many terms you add. Crank the "Harmonics N" slider to the max and slow the "Animation Speed." You'll see the overshoot persist, just in a narrower spike. It's a fundamental limit of Fourier approximation.

Physical Model & Key Equations

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$.

Frequently Asked Questions

This is the Gibbs phenomenon. When approximating a discontinuity with a Fourier series, no matter how many harmonics are added, an overshoot of about 9% remains. With this tool, you can observe how the oscillation does not converge but remains sharp as you change the number of harmonics.
The square wave consists only of odd-order sine waves (1st, 3rd, 5th...), the sawtooth wave includes all orders of sine waves (1st, 2nd, 3rd...), and the triangular wave consists of odd-order sine waves with coefficients decaying rapidly as 1/n². Due to this difference, the triangular wave is characterized by smooth approximation even with few harmonics.
The rotation of each circle corresponds to the cosine/sine component of each harmonic. The radius of the circle represents the Fourier coefficient, and the rotation speed represents the frequency nω. By projecting the trajectories of the centers of all circles onto the time axis, the original periodic waveform is reproduced as the sum of these components.
You can visually understand the relationship between the truncation order of harmonics and the approximation accuracy of the waveform. For example, while a square wave requires many harmonics and is prone to distortion when band-limited, a triangular wave is practical even with a small number of harmonics. This serves as an intuitive reference for timbre design or filter design.

Real-World Applications

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.

Common Misconceptions and Points to Note

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.

How to Use

  1. Set the number of harmonics (vNNum) from 1 to 50; higher values approximate the target waveform more closely and reduce Gibbs overshoot near discontinuities.
  2. Select waveform type (square, sawtooth, or triangle) and adjust fundamental frequency (sN) in Hz, typically 1–10 Hz for clear visualization.
  3. Control phasor rotation speed (vSpeedNum) to slow or accelerate harmonic synthesis; observe real-time convergence and error metrics on the display.

Worked Example

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.

Practical Notes

  1. Sawtooth waves converge slower than triangle waves; use ≥30 harmonics to achieve <2% error for sawtooth in audio synthesis applications.
  2. Set phasor speed to zero (sSpeedNum=0) to freeze animation and inspect individual harmonic amplitudes and phase relationships in the phasor diagram.
  3. Maximum amplitude output scales with waveform type: square wave peak ≈ 1.27×fundamental, sawtooth ≈ 1.0×fundamental, triangle ≈ 0.81×fundamental.