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.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Type f(x) as it looks over one period.
- Enter the start and end of that period, for example −pi and pi.
- 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.