› Fourier Series Simulator Back
Signal Processing / Math

Fourier Series Simulator

Synthesize square, triangle, and sawtooth waves using N=1–50 harmonics. Watch the Gibbs overshoot and harmonic spectrum evolve in real-time.

Parameters
Waveform Type
Number of Harmonics N
Amplitude A
Animation Speed
Gibbs: ~9.0% overshoot
Results
Harmonics N
10
Peak Value
—
RMS Error
—
Waveform Synthesis (Real-time Animation)

Harmonic amplitudes & DC
Spectrum
Theory & Key Formulas

$$f(t) = \frac{a_0}{2}+ \sum_{n=1}^{N}\!\left(a_n\cos\frac{2\pi nt}{T}+ b_n\sin\frac{2\pi nt}{T}\right)$$

Square: $b_n = \tfrac{4A}{n\pi}$ (odd $n$ only)
Triangle: $b_n = \tfrac{8A}{n^2\pi^2}\sin\!\tfrac{n\pi}{2}$
Sawtooth: $b_n = -\tfrac{2A}{n\pi}(-1)^n$
Half-wave sine: $a_0/2=A/\pi$, $b_1=A/2$, $a_n=-2A/[\pi(n^2-1)]$ (even $n\ge2$). All other coefficients are zero.

The period is normalized to 1. N is the highest retained harmonic, not the number of nonzero terms. The rising sawtooth starts at 0 and jumps from +A to −A halfway through the period; jump points use the average of the two limits. RMS error is the full-period integral evaluated by Parseval’s relation. Peak amplitude is a 4096-point numerical estimate. Finite-N overshoot is measured relative to the jump size 2A. The spectrum shows √(aₙ²+bₙ²), with DC = a₀/2 separately.

What is a Fourier Series?

🙋
What exactly is a Fourier series? It sounds like a way to build complex waves, but how does it actually work?
🎓
Basically, it's a mathematical recipe. You take a complicated, repeating pattern—like the square wave in this simulator—and rebuild it by adding together simple sine and cosine waves. The key is that each simple wave has a specific frequency that's an integer multiple of the original wave's frequency. Try selecting the "Square" waveform above and slowly increase the "Number of Harmonics N" slider from 1. You'll see it start as a simple sine wave and gradually become more square.
🙋
Wait, really? So the simulator is literally adding those waves together in real-time? What are those "coefficients" like a_n and b_n you mentioned?
🎓
Exactly! The simulator calculates and sums them live. The coefficients $a_n$ and $b_n$ are the amplitudes—the "volume"—of each cosine and sine component. Their values are unique for each target waveform. For instance, for a square wave, only the odd sine terms matter: $b_n = \frac{4A}{n\pi}$ for odd $n$. That's why the harmonic spectrum on the right shows bars only at odd multiples. Change the "Amplitude A" slider and watch how all the harmonic bars scale together.
🙋
I see the overshoot near the sharp edges, even with many harmonics. That's the Gibbs phenomenon you mentioned? Why doesn't it go away if we're adding more terms?
🎓
Great observation! That's a classic and subtle point. The Gibbs phenomenon is the persistent overshoot (about 9%) near a discontinuity, no matter how many harmonics you add. The series converges to the average at the jump, but it always overshoots first. It's a fundamental limit of approximating a sudden jump with smooth waves. Compare it by switching to the "Triangle" wave, which has no sudden jumps—the Gibbs phenomenon disappears and the approximation gets much smoother, faster.

Physical Model & Key Equations

The core idea is that any periodic function with period $T$ can be constructed from a constant plus a sum of sines and cosines at harmonically related frequencies.

$$f(t) = \frac{a_0}{2}+ \sum_{n=1}^{N}\!\left(a_n\cos\frac{2\pi nt}{T}+ b_n\sin\frac{2\pi nt}{T}\right)$$

Here, $f(t)$ is the synthesized waveform, $N$ is the number of harmonics used (the main simulator control), $T$ is the period, and $a_n$ and $b_n$ are the Fourier coefficients that depend on the target waveform shape.

The coefficients are calculated from the original function $g(t)$ using integration. This is how the simulator "knows" the recipe for a square, triangle, or sawtooth wave.

$$a_n = \frac{2}{T}\int_{0}^{T}g(t)\cos\frac{2\pi nt}{T}\,dt, \quad b_n = \frac{2}{T}\int_{0}^{T}g(t)\sin\frac{2\pi nt}{T}\,dt$$

For a square wave of amplitude $A$, this yields $b_n = \frac{4A}{n\pi}$ for odd $n$ (others zero). For a triangle wave, $a_n$ coefficients follow a $\frac{1}{n^2}$ pattern. This difference explains why the triangle wave converges much faster—its higher harmonic amplitudes decay rapidly.

Frequently Asked Questions

N is the highest retained harmonic. Increasing it reduces full-period RMS error. Near square and sawtooth jumps, overshoot approaches about 9% of the jump size 2A while its spatial extent shrinks. The triangle wave is continuous and has no Gibbs overshoot caused by a jump in its value.
The horizontal axis is harmonic order n, not Hz. Each bar shows the combined sine/cosine amplitude √(aₙ²+bₙ²). DC separately shows the absolute mean a₀/2. Square-wave harmonics are odd only, with amplitude proportional to 1/n. This is not power or a measured FFT.
Approximating a periodic jump with finitely many smooth components leaves oscillations near it. At the jump itself, the series converges to the mean of its one-sided limits. The approximately 9% limit is relative to jump size 2A, not amplitude A, and is distinct from the measured overshoot at finite N.
This normalized model teaches how truncation changes the waveform, error and spectrum. Example buttons reproduce exact conditions; pause to compare them. It does not analyze measured FFT data or evaluate real circuit filter performance, bandwidth or standards compliance.

Real-World Applications

Audio Synthesis & Music: Fourier synthesis is the foundation of subtractive synthesis in electronic music. A sawtooth wave, rich in harmonics, is generated and then filtered to create the sounds of synthesizers. The simulator directly shows the harmonic content that defines a sound's timbre.

Signal Processing & Compression: JPEG image and MP3 audio compression rely on a related technique (the Fourier transform). By identifying and keeping only the most significant frequency components (like the strong lower harmonics you see in the spectrum), file sizes can be drastically reduced with minimal perceived quality loss.

Vibration Analysis in Mechanical Engineering: In CAE, irregular vibrations from machinery are decomposed into their harmonic components via Fourier analysis. This allows engineers to identify the source of a vibration—for instance, pinpointing whether it's caused by an unbalanced fan at 30 Hz or bearing defect at 150 Hz—enabling targeted fixes.

Solving Partial Differential Equations: Fourier's original application was solving the heat equation. The temperature distribution in a metal rod can be expressed as a sum of sinusoidal modes. This "separation of variables" method is still a cornerstone for analytical solutions in heat transfer, acoustics, and quantum mechanics.

Common Misconceptions and Points to Note

First, you might think that "increasing N always improves accuracy," but in reality, it's not that simple. While this holds true for smooth waveforms like the triangle wave, for waveforms with discontinuities like the square wave, the approximately 9% overshoot due to the Gibbs phenomenon does not disappear, even if N is increased to 100 or 1000. This is a mathematically proven convergence property. In practice, "how many terms to include" is decided by balancing acceptable error with computational cost. For instance, if a 9% distortion is critical in audio signal reproduction, approximating with a square wave itself might be inappropriate.

Next, note that the "spectrum" you see in the simulator is that of an ideal periodic waveform. The spectrum obtained by applying FFT to actual CAE data (e.g., time-history vibration data) contains noise and non-stationary components and will not show such clean discrete lines. For example, performing FFT on engine vibration data will show peaks corresponding to rotational speed, but there will always be broad noise in the background. It's crucial not to equate the clean spectrum from the tool directly with reality.

Finally, understand the "waveform properties" indicated by the decay rates of the coefficients, such as $1/n$ or $1/n^2$ . A slower decay (like $1/n$ for a square wave) means more high-frequency components and includes sharp changes. Conversely, a waveform with faster decay (like $1/n^2$ for a triangle wave) is smoother. This directly relates to practical decisions like mesh sizing or time-step settings in simulations. To simulate sharp phenomena like shock waves, where fast decay cannot be assumed, very fine meshes or high sampling frequencies become necessary.

How to Use

  1. Select square, triangle, sawtooth or half-wave rectified sine. Set the highest retained harmonic N from 1 to 50; N is not the count of nonzero terms.
  2. Amplitude A ranges from 0.5 to 2.0. This is a normalized period-1 model, with no inputs for Hz or V.
  3. Playback shifts the phase; it does not automatically add harmonics. Speed ranges from 0.1 to 3.0. Pause to compare waveforms.
  4. RMS error covers the entire period; peak amplitude is estimated on 4096 points. Playback speed changes neither metric.

Worked Example

Each button sets A=1, speed=1 and phase=0, then pauses the example.

Practical Notes

  1. The spectrum reports amplitudes, not power or a measured FFT. Sawtooth harmonic n has amplitude 2A/(nπ).
  2. Decreasing RMS error does not imply the same decrease in maximum error near a jump. At a discontinuity the series converges to the average of the two one-sided limits.
  3. Real circuit bandwidth, rise time, sampling and standards compliance are outside this model. It cannot by itself establish a required harmonic count or filter performance for a real application.

References: Mathematics for Quantum Physics: coefficients and half-wave rectification; UC Davis: sawtooth and Parseval exercises. Period and phase conventions have been adapted to this page's normalization.

🎬 Watch it in motion

Fourier Series | spinning circles that draw any picture #Shorts
Fourier Series | spinning circles that draw any picture #Shorts
Fourier Synthesis | building sharp corners from pure sines #Shorts
Fourier Synthesis | building sharp corners from pure sines #Shorts