📚 Formula breakdown
Fourier series formulas (and what the symbols mean)
A Fourier series is a way to represent a periodic function as a sum of simpler oscillations —
sines and cosines. In engineering language, you’re decomposing a waveform into its frequency ingredients.
In math language, you’re expanding a periodic function in an orthogonal basis.
The most common form uses a half‑period L. That means your function repeats every
2L, and we compute coefficients on the interval [−L, L].
The Fourier series for a reasonably well‑behaved periodic function is:
f(x) ≈ a0/2 + Σn=1..∞
[an cos(nπx/L) + bn sin(nπx/L)]
The coefficients tell you “how much” of each cosine and sine frequency is needed. They are computed by integrating
(averaging) the function against cosine/sine over one symmetric period:
- a0 = (1/L) ∫−LL f(x) dx
- an = (1/L) ∫−LL f(x) cos(nπx/L) dx
- bn = (1/L) ∫−LL f(x) sin(nπx/L) dx
This calculator computes those integrals numerically using the trapezoidal rule (think of it as “a lot of tiny rectangles,
but slightly smarter”). That’s why there’s a “samples” setting: more samples generally means more accurate coefficients.
What does “partial sum” mean?
In theory the series has infinitely many terms. In practice we use a finite number N. The result is the
partial sum:
SN(x) = a0/2 + Σn=1..N [an cos(nπx/L) + bn sin(nπx/L)].
As N increases, SN(x) usually gets closer to f(x) — but around jumps it can overshoot (the famous Gibbs phenomenon).
Even/odd shortcuts
- If f(x) is even (symmetric), the sine terms vanish → bn ≈ 0.
- If f(x) is odd (antisymmetric), the cosine terms vanish → a0, an ≈ 0.
- If neither, you generally get both an and bn.
Common choice: L = π
Many textbooks assume the function is 2π‑periodic. That corresponds to L = π, because the period is 2L.
If your problem statement says “period 2π,” keep L set to π and you’ll match the standard formulas:
cos(nx) and sin(nx).
🧪 Examples you can try
Example coefficients + intuition
Want instant “I get it now” intuition? Try these and watch the graph:
1) Square wave (classic)
Select Square wave, keep L = π, and set N = 1, 3, 5, 25.
You’ll see the approximation build sharp corners from smooth sine waves.
Near the jump, you’ll notice a small overshoot that doesn’t disappear — it just gets narrower as N grows.
That’s the Gibbs phenomenon.
2) Triangle wave (fast convergence)
Select Triangle wave and try N = 5. The curve gets close quickly because the function is continuous
and has gentler corners. In many cases, the coefficients shrink much faster than with a square wave.
This is why smoother signals are easier to approximate with fewer terms.
3) Custom function: sin(x) + 0.5 cos(2x)
Choose “Custom f(x)” and type:
sin(x) + 0.5*cos(2*x).
The Fourier series is basically already in Fourier form — so you should see b1 ≈ 1 and a2 ≈ 0.5,
with the rest near zero (small numeric noise is normal).
4) Even function: |sin(x)|
Pick |sin(x)|. Because it’s even, you should see bn values close to 0.
That’s a neat built‑in check that your setup is consistent.
Practical “term count” rule of thumb
- Smooth functions: often 5–15 terms looks great.
- Sharp corners: often 15–50 terms to look “pretty close.”
- Discontinuities: you can’t remove overshoot entirely, but higher N makes it thinner.
If you’re studying signals: think of N as a bandwidth limit — you’re reconstructing a signal using only the first N harmonics.