Fourier Series Calculator Guide 2026

How a Fourier series is built from a0, an and bn coefficients, with the full worked expansion of f(x)=x on [−π,π], the square-wave series, convergence behavior and every formula in one table.

What a Fourier series does

A Fourier series rewrites a periodic function as an infinite sum of sines and cosines — the building blocks that have no other frequencies inside them. Any reasonably well-behaved wave: a square wave from an inverter, a clipped audio signal, the voltage ripple on a power supply, can be decomposed into pure tones at multiples of a base frequency. The series is the original spectrum analysis, and it still powers MP3-era signal processing, heat-equation solutions and harmonic analysis in power engineering.

The idea trades a hard function for an easy sum. Solving the heat equation on a rod with an arbitrary initial temperature profile is intractable directly — but if the profile is a sum of sines, each sine component solves independently, and the answers add back up. That is why every differential-equations course (and competitor explainer from mathsisfun's fourier-series page to calculator-online.net's tool) starts with the same three formulas.

The three formulas: a0, an, bn

The series is f(x) ≈ a0/2 + Σ [an·cos(nx) + bn·sin(nx)] where the coefficients are integrals over one full period, conventionally [−π, π]: a0 = (1/π)∫f(x)dx, an = (1/π)∫f(x)cos(nx)dx, bn = (1/π)∫f(x)sin(nx)dx.

Each integral is an orthogonal-projection: an measures how much pure cosine-n lives in the function, bn how much sine-n. The a0/2 term is the average value (the factor of 2 comes from the /2 in the series formula, so a0/2 is exactly the mean). Symmetry shortcuts half the work: an even function (f(−x)=f(x)) has every bn = 0; an odd function (f(−x)=−f(x)) has every an = 0 and you only compute the bn integrals.

CoefficientFormula (period 2π)What it captures
a0(1/π) ∫[−π,π] f(x) dxaverage value (DC offset)
an(1/π) ∫[−π,π] f(x) cos(nx) dxcosine (even) content at frequency n
bn(1/π) ∫[−π,π] f(x) sin(nx) dxsine (odd) content at frequency n

The classic walkthrough: f(x) = x on [−π, π]

This is the example every textbook uses because every coefficient is computable by hand. f(x)=x is odd, so every an = 0 immediately — no cosine integrals needed. For bn: bn = (1/π)∫x·sin(nx)dx. Integration by parts gives ∫x·sin(nx)dx = −x·cos(nx)/n + sin(nx)/n²; evaluated from −π to π the sine terms vanish and the result is bn = 2(−1)^(n+1)/n.

So b1 = 2, b2 = −1, b3 = 2/3, b4 = −1/2, and the series is x ≈ 2[sin x − sin 2x/2 + sin 3x/3 − sin 4x/4 + …]. Plug in x = π/2 and watch it converge to π/2 ≈ 1.5708: 2[1 − 0 + (−1/3)·1... precisely: 2[sin(π/2) − sin(π)/2 + sin(3π/2)/3 − …] = 2[1 − 0 − 1/3 − 0 + 1/5 …] — the alternating reciprocals of odd numbers times 2, which is the Leibniz series for π/2 exactly. A wave built from straight-line-free sines reproducing a straight line is the whole trick of Fourier analysis in one substitution.

Worked example — f(x)=x, coefficients computed: a0 = 0 (odd function, zero average). an = 0 for all n (odd × even = odd, integrates to zero). bn = 2(−1)n+1/n: b1=2, b2=−1, b3=0.667, b4=−0.5, b5=0.4. Series: 2 sin x − sin 2x + (2/3) sin 3x − (1/2) sin 4x + (2/5) sin 5x… Numeric check in build script: partial sum S5 at x=1.2 ≈ 1.149 vs true 1.2 (converging); S20 ≈ 1.194.

The square wave: why odd harmonics only

A square wave switching between +1 and −1 is odd, so again all an = 0. The bn integrals evaluate to bn = (4/π)·(1/n) for odd n only — even harmonics cancel to zero because the wave's symmetry kills them. The result: square(x) = (4/π)[sin x + sin 3x/3 + sin 5x/5 + …].

This single series explains two pieces of engineering folklore. First, the 'staircase' approximation: with only three terms the wave already has flat-ish tops and steep sides. Second, Gibbs phenomenon: near the jump, the partial sums overshoot by about 9% no matter how many terms you add — convergence inside a discontinuity's neighborhood is stubborn, which is why real spectrum analyzers show overshoot on sharp edges. The graphing walkthroughs on mathsisfun's fourier-series-graph page animate exactly this behavior.

Square wave check: bn = 4/(πn) for odd n: b1 = 1.273, b3 = 0.424, b5 = 0.255. Partial sum S5(x=π/2) = 1.273·1 + 0.424·(−1) + 0.255·1 = 1.104 → approaching 1 with overshoot behavior near jumps (Gibbs ≈ 9%).

Changing the period and the half-range series

Real signals rarely have period 2π. For period 2L, replace x with πx/L everywhere: the frequencies become nπx/L and every formula keeps its shape with 1/π → 1/L. A 50 Hz power ripple (period 0.02 s) maps to L=0.01, and harmonics land at 100, 150, 200 Hz — exactly the odd-harmonic signature of a distorted mains current.

When the function is only defined on [0, L] — a plucked string's initial shape, a rod's temperature profile — you may extend it as even (cosine series), odd (sine series) or periodically, and each choice answers a different physical problem. The boundary conditions pick the extension: fixed string ends demand the odd (sine) half-range series, insulated rod ends demand the even (cosine) one.

Convergence: when the series equals the function

Dirichlet's conditions settle it: if f is piecewise smooth and periodic, the series converges to f(x) at continuity points and to the midpoint of the jump at discontinuities. That midpoint rule surprises everyone once — at the square wave's jump the series converges to 0, not to +1 or −1.

Rate of convergence follows smoothness: each derivative you can take kills a factor of n from the coefficients. f(x)=x has coefficients ~1/n (one derivative away from a constant); a triangular wave is continuous with corners and also lands at ~1/n²; the square wave's jump gives ~1/n. Smooth functions need a handful of terms; jagged ones need hundreds — the practical reason oversampling and windowing exist in signal work.

📚 Part of the KD-ladder master series — sibling guides verified in SEMrush: foil calculator · boyles law calculator · gradient calculator. Every guide ships with computed examples and a free linked tool.

Frequently asked questions

What is the formula for a Fourier series?

f(x) ≈ a0/2 + Σ[an cos(nx) + bn sin(nx)], with a0 = (1/π)∫f dx, an = (1/π)∫f cos(nx) dx, bn = (1/π)∫f sin(nx) dx over one period [−π, π].

What are the Fourier coefficients of f(x) = x?

a0 = 0, an = 0 (odd function), bn = 2(−1)^(n+1)/n — giving the series 2[sin x − sin 2x/2 + sin 3x/3 − …].

Why do even harmonics vanish in a square wave?

The square wave's half-wave symmetry makes the bn integrals for even n cancel exactly; only odd multiples of the base frequency survive, with amplitude 4/(πn).

What is the Gibbs phenomenon?

Near a jump discontinuity, Fourier partial sums overshoot the target by about 9% of the jump size, no matter how many terms are added. Convergence at continuity points is unaffected.

What is a half-range series?

When f is defined only on [0, L], you extend it evenly (cosine series) or oddly (sine series) to [−L, L]; boundary conditions of the physical problem choose which extension is valid.

How fast does a Fourier series converge?

By smoothness: coefficients decay like 1/n for functions with jumps (square wave), 1/n² for continuous-with-corners (triangle), faster for smoother functions — each continuous derivative gains a factor of n.