Fourier series calculator

Enter a function f(x), the interval that makes up one period, and how many terms you want. The calculator finds the Fourier coefficients by numerical integration, writes out the series and plots the partial sum on top of your function.

For example x, x^2, abs(x) or abs(x)/x for a square wave. Points where f is not defined, such as x = 0 in abs(x)/x, are skipped.
One full period from start to end, such as -pi to pi or 0 to 2. The function repeats with period T = end − start.
Harmonics n = 1 … N, up to 50.
Fourier series (partial sum)f(x) ≈ 2 sin(x) − sin(2x) + 0.6666666667 sin(3x) − 0.5 sin(4x) + 0.4 sin(5x)
Mean value a₀ / 2
0
Period T
6.283185307
n = 1
a = 0, b = 2
n = 2
a = 0, b = −1
n = 3
a = 0, b = 0.6666666667
n = 4
a = 0, b = −0.5
n = 5
a = 0, b = 0.4

Coefficients are computed by adaptive numerical integration; values below about 10⁻⁹ of the largest are shown as 0. On the graph, f is the first colour and the partial sum the second.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Type f(x) as it looks over one period.
  2. Enter the start and end of that period, for example −pi and pi.
  3. Choose the number of terms and read the coefficients; the graph compares f with the partial sum.

How it works

Each coefficient is an integral over one period, computed with adaptive Simpson integration. The series is written with sin(nx) and cos(nx) when the period is 2π, and with sin(nπx / L) and cos(nπx / L) otherwise, where L = T / 2 is the half period.

Worked example

f(x) = x on −π to π with N = 3: a₀ = 0 and every aₙ = 0, while b₁ = 2, b₂ = −1 and b₃ = 2/3. So

x ≈ 2 sin(x) − sin(2x) + 0.6666666667 sin(3x).

For f(x) = x² on the same interval: a₀ / 2 = π² / 3 ≈ 3.289868, a₁ = −4, a₂ = 1, a₃ = −4/9, and all bₙ = 0.

Tips

  • Smooth periodic functions need few terms; functions with jumps need many, and their coefficients fall off only like 1/n.
  • The plot shows one period only; the series repeats it to the left and right.

Frequently asked questions

What are the Fourier coefficient formulas?

With period T = b − a and ω = 2π / T: a₀ = (2/T)∫f(x)dx, aₙ = (2/T)∫f(x)cos(nωx)dx and bₙ = (2/T)∫f(x)sin(nωx)dx, each over one period. The series is f(x) ≈ a₀/2 + Σ (aₙcos(nωx) + bₙsin(nωx)).

Why are all the aₙ zero for f(x) = x?

On a symmetric interval such as −π to π, an odd function (f(−x) = −f(x)) has only sine terms and an even function (f(−x) = f(x)) has only cosine terms and the constant. x is odd, so aₙ = 0 and bₙ = 2(−1)ⁿ⁺¹ / n.

Why does the partial sum overshoot at a jump?

That is the Gibbs phenomenon: near a discontinuity the partial sum overshoots by about 9 % of the jump, however many terms you take. The overshoot gets narrower but not smaller.

Are the coefficients exact?

They are computed numerically with an adaptive Simpson rule and are accurate to many decimal places for smooth functions; around jumps the last few digits may differ from the exact formula.

How do I enter a function that is defined in pieces?

There is no piecewise syntax, but abs helps: abs(x)/x is a square wave that is −1 for negative x and 1 for positive x, and (x + abs(x))/2 is 0 for negative x and x for positive x.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.