MaximCalculator Free, fun & accurate calculators
🎛️ Platinum math layout
🌙Dark Mode

Fourier Series Calculator

Turn a periodic signal into a sum of sines and cosines — instantly. Choose a classic waveform (square, sawtooth, triangle) or type your own f(x), then compute a0, an, bn, generate a clean partial-sum equation, and watch the approximation improve as you add terms.

Fast numeric coefficients
📈Graph: function vs partial sum
🧾Copy-ready series expression
💾Save coefficients locally

Build your Fourier series

Tip: for most homework-style problems, set L = π (period = 2π) and increase the number of terms until the plot looks “close enough.” For discontinuous functions (like a square wave), you’ll also see the classic Gibbs overshoot near jumps — that’s normal.

🎚️
⏱️
🧩
🔬
ƒ
Your Fourier series result will appear here
Choose a preset or type a function, then press “Compute Fourier Series.”
This calculator computes coefficients numerically using trapezoidal integration over [-L, L].
Plot (one period)
Solid line = f(x). Dotted line = partial sum SN(x).
Partial-sum expression
Coefficients table (first 12 terms)

This calculator is intended for learning, intuition, and quick checks. Numerical integration and truncation mean results can differ slightly from exact symbolic coefficients (especially for sharp corners or discontinuities).

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

🧠 How it works

What this calculator does under the hood

This page computes Fourier coefficients with a numerical approximation of the integrals. Here’s the high‑level flow:

  • Step 1: Pick L (half period) so the period is 2L and the base frequency is π/L.
  • Step 2: Sample f(x) at many x points across [−L, L].
  • Step 3: Estimate the integrals for a0, an, bn using trapezoids.
  • Step 4: Build the partial sum SN(x) from those coefficients.
  • Step 5: Plot f(x) and SN(x) over one period so you can visually judge convergence.
Why your coefficients might not be “perfect”

If a function has corners or jumps, the integrals are still valid, but numerical integration can be a little sensitive. That’s why increasing the sample count can help. Also, truncating at N terms means you’re not using the full infinite series — so the approximation is expected to be imperfect. In other words: if you see a tiny wiggle near discontinuities, that’s not a bug, that’s Fourier being Fourier.

Safety note about custom functions

Custom f(x) uses a JavaScript math expression evaluated in your browser (for example, sin(x), abs(x), exp(x)). If you paste something invalid, the calculator will show an error. Stick to math expressions — not random code.

❓ FAQs

Frequently Asked Questions

  • What is L and why is it “half period”?

    The Fourier formulas on this page assume you compute coefficients on a symmetric interval [−L, L]. The full period is then 2L. If your function is 2π‑periodic, set L = π.

  • Why does the approximation overshoot near a jump?

    That’s the Gibbs phenomenon. Even with very large N, the overshoot doesn’t vanish; it becomes narrower. Your partial sum is trying to recreate a discontinuity using smooth waves.

  • My bn are not exactly zero for an even function. Is that wrong?

    Small nonzero values can happen due to numerical approximation (finite samples, rounding). Try increasing the sample count or N, and ensure your function truly is even over [−L, L].

  • How many terms should I use for a “good” answer?

    If you need a quick visual match, start with N = 10. For sharp corners use N = 25–50. For smooth functions, N = 5–15 often looks great. If you’re matching a textbook coefficient pattern, focus on the first few terms and sanity checks (even/odd symmetry).

  • Does this compute sine-only or cosine-only series?

    This page computes the full sine + cosine series. If your function is odd/even, one set of coefficients will naturally be (near) zero, effectively reducing to a sine-only or cosine-only series.

  • Can I use this for real-world signals?

    For learning and quick intuition, yes. For serious signal processing you’d usually sample data and use FFT-based methods, windowing, and more careful numerical handling. But the core idea is the same: represent signals via frequency components.

MaximCalculator provides simple, user-friendly tools. Double-check critical calculations with your course notes or a symbolic CAS when precision matters.