About the Fourier Series Calculator
A Fourier series writes a periodic function as a sum of sines and cosines. Joseph Fourier introduced the idea in the early 1800s to study heat flow, and it now underpins signal processing, acoustics, electrical engineering, image compression and the solution of differential equations. Any reasonably well-behaved function on an interval can be built from waves of increasing frequency, each with its own amplitude.
This Fourier series calculator finds those amplitudes, the Fourier coefficients a0, an and bn, for a function you enter on the interval [−L, L]. It writes out the first N terms of the series, reports whether the function is odd or even, and, if you choose a point, compares the partial sum there with the function's value so you can see how well the series converges.
How to Use the Fourier Series Calculator
Enter the function f(x). Use x as the variable, ^ for powers, and functions such as sin(x), cos(x), abs(x), e^x or sign(x). sign(x) is −1 for negative x and +1 for positive x, which makes a square wave.
Enter the half-period L. The calculator works on [−L, L], so the period is 2L. Enter pi for the common interval [−π, π].
Enter the number of terms N, from 1 to 50.
Optionally enter a point at which to evaluate the partial sum.
The Formulas
a0 = (1/L) ∫ f(x) dx over [−L, L]
an = (1/L) ∫ f(x) cos(nπx/L) dx
bn = (1/L) ∫ f(x) sin(nπx/L) dx
f(x) ≈ a0/2 + Σ [an cos(nπx/L) + bn sin(nπx/L)], n = 1 … N
Step-by-Step Example
The Fourier series of f(x) = x on [−π, π] with five terms.
a0 = (1/π) ∫ x dx = 0 (x is odd)
an = (1/π) ∫ x cos(nx) dx = 0 (odd × even is odd)
bn = (1/π) ∫ x sin(nx) dx = 2(−1)ⁿ⁺¹ / n
b1 = 2, b2 = −1, b3 = 0.666667, b4 = −0.5, b5 = 0.4
f(x) ≈ 2sin(x) − sin(2x) + 0.666667sin(3x) − 0.5sin(4x) + 0.4sin(5x)
at x = 1: partial sum ≈ 0.862556, while f(1) = 1
The five-term sum is still some way from 1 at x = 1. The coefficients only shrink like 1/n, because the periodic extension of x has a jump at ±π, so convergence is slow.
Odd and Even Functions
Symmetry halves the work. If f is odd, meaning f(−x) = −f(x) as for x, x³ or sin(x), every cosine integral cancels and the series contains only sines; this is a Fourier sine series. If f is even, meaning f(−x) = f(x) as for x², |x| or cos(x), every sine integral cancels and the series contains only cosines plus the constant. Functions with no symmetry need both.
For f(x) = x² on [−1, 1], the calculator returns a0/2 = 1/3 and an = 4(−1)ⁿ/(nπ)², so a1 ≈ −0.405285 and a2 ≈ 0.101321. Those coefficients shrink like 1/n², much faster than for x, because the periodic extension of x² is continuous with no jumps.
Convergence and the Gibbs Phenomenon
Where f is smooth, the partial sums approach f as N grows. At a jump, the series converges to the midpoint of the jump, the average of the left and right limits. For the square wave sign(x), the series gives 0 at x = 0, halfway between −1 and +1.
Near the jump something surprising happens: the partial sums overshoot by about 9% of the jump size, and adding more terms does not reduce the overshoot. It only squeezes it closer to the jump. This is the Gibbs phenomenon, and it explains ringing artefacts near sharp edges in compressed images and filtered audio.
The square wave series is (4/π)[sin(x) + sin(3x)/3 + sin(5x)/5 + …]. With three non-zero terms the partial sum at x = π/2 is about 1.10, above the true value of 1: partial sums oscillate around the square wave, and the ripples shrink everywhere except next to the jumps.
Choosing L and N
Match L to the period of the signal you are modelling. A function repeating every 2 seconds needs L = 1. For a function defined only on [0, L], you can choose to extend it as an odd function, giving a sine series, or as an even function, giving a cosine series; enter the extended function on [−L, L], for example with abs(x) for an even extension.
More terms give a closer fit, but the coefficients of smooth functions fall off quickly, so a handful often suffices. For functions with jumps or corners, many more terms are needed, and the first few coefficients still capture the main shape.
How the Integrals Are Computed
The calculator integrates numerically with composite Simpson's rule over 4,000 subintervals, so it works for functions with no convenient antiderivative. For smooth functions the coefficients are accurate to many digits. Coefficients smaller than a billionth of the function's largest value are shown as zero, which removes rounding noise from terms that are exactly zero by symmetry.
Understanding Your Result
The headline writes the series with its first N non-zero terms.
The constant term gives a0 and the average value of f, which is a0/2.
The coefficients list an and bn for each n.
The symmetry line says whether only sines, only cosines or both appear.
The at the point line compares the partial sum with the function value there.
When Should You Use This Calculator?
Use it to check Fourier coefficients worked out by hand in a calculus or differential equations course.
Use it to see how quickly a series converges as N increases.
Use it to explore the harmonics of square, sawtooth and triangle waves.
Common Mistakes
Forgetting a0/2. The constant term is half of a0.
Using the wrong period. The interval is [−L, L], so the period is 2L.
Expecting convergence at a jump to f. The series converges to the midpoint.
Using degrees. The trigonometric functions use radians.