Fourier Series Coefficient Calculator
A free Fourier series calculator that works out the Fourier coefficients a₀, aₙ and bₙ of any function by numerical integration. Enter an expression, the period interval and the highest harmonic, and see the reconstructed series plotted against the original function.
What this Fourier coefficient calculator does
This tool works out the Fourier coefficients of any function by numerical integration. Enter an expression for f(x), the interval that acts as one period and the highest harmonic you want, and you get the constant term a₀ together with aₙ and bₙ for every harmonic as a table, plus a plot of the reconstructed series drawn over the original function. Classic waveforms such as the square and triangle wave, whose coefficients have a closed form, are covered by our Fourier series visualiser; this page is for trying expressions your textbook does not list.
The integration uses Simpson's rule and divides the period into 2000 pieces by default, so the coefficients shown are approximations rather than exact values. For a smooth function they typically agree to about six significant figures, but a function with a kink — like an absolute value — or one that jumps at the ends of the interval does better with more subdivisions. You can set anything from 10 to 20000, so raise the count until the digits stop moving.
How to use the Fourier coefficient calculator
- Enter a function Type an expression for f(x). The variable is x and pi stands for π. The buttons underneath fill in a few common examples.
- Set the period interval Enter the start and the end. These accept expressions too, so -pi and 2*pi both work. The width of the interval becomes the period T.
- Choose the highest harmonic Use the slider to say how far up the harmonics you want coefficients, anywhere from 1 to 50.
- Read the results You get the coefficient table and a graph with the series drawn over the original function. The smaller the residual, the better that many harmonics reproduce your function.
Tips for getting more out of it
- For a function that jumps at the ends of the interval — f(x) = x, for example — the series overshoots near the jump. Adding harmonics never removes it, so read the shape of the graph alongside the residual figure rather than trusting the number alone.
- Coefficients that should be exactly zero come out around 1e-16 under numerical integration. The table shows anything below 1e-10 in absolute value as 0, so if you see larger values in a column that ought to be empty, try raising the subdivision count.
- For an even function (f(−x) = f(x)) all the bₙ vanish, and for an odd function a₀ and every aₙ vanish. That makes this a quick way to confirm a symmetry argument instead of taking it on trust.
- If you want the coefficients of a square, triangle, sawtooth or half-wave rectified signal, our Fourier series visualiser uses the closed-form expressions and gives exact values.
Where the Fourier coefficient calculator helps
Checking a problem set
Compare the a₀, aₙ and bₙ you worked out by hand against the numbers here, harmonic by harmonic. A dropped sign or a 1/n written where 1/n² belongs shows up immediately.
Trying functions no textbook lists
Expressions such as exp(-x^2) or x*sin(x) are tedious to integrate by hand, but their coefficients are one click away here.
Confirming what symmetry buys you
Swap between even, odd and half-wave symmetric functions and watch which coefficients drop out. It turns the symmetry rules from something memorised into something observed.
Seeing what changing the period does
The same expression has a different angular frequency when the interval changes width. Compare −1 to 1 against −pi to pi and you can see exactly how the coefficients respond.
Terms used in Fourier coefficient calculations
- Fourier coefficients
- The collective name for a₀, aₙ and bₙ. Each one is the integral of the function multiplied by a cosine or a sine over one period, divided by half the period.
- Period T
- The width of the interval you enter. A Fourier series treats the function as repeating with this width, so the choice of interval shapes the result.
- Angular frequency
- The quantity ω = 2π/T. The nth harmonic has angular frequency nω and enters the series as cos(nωx) and sin(nωx).
- Simpson's rule
- A numerical integration method that splits the interval into an even number of pieces and fits a parabola through each set of three points. Its error scales with the fourth power of the step size, so doubling the subdivisions cuts the error by roughly sixteen.
- Amplitude and phase
- The size and horizontal shift you get when aₙcos and bₙsin are combined into a single cosine A·cos(nωx + φ). Here A = √(aₙ² + bₙ²) and φ = atan2(−bₙ, aₙ).
- Residual
- The difference between the original function and the reconstructed series. This page reports the root mean square of that difference at the integration nodes, as a measure of how well the harmonics you asked for reproduce the function.
Frequently asked questions about calculating Fourier coefficients
Side Note — from wine barrels to the FFT, the long road of numerical integration
The Simpson's rule this tool relies on is named after the English mathematician Thomas Simpson, who presented the formula in 1743. The same idea, however, was already in use more than a century earlier by Johannes Kepler — and not for celestial mechanics but for estimating the volume of wine barrels. German-speaking countries still sometimes call it Kepler's barrel rule. Approximating an area bounded by a curve with a series of parabolas turns out to be a very old piece of practical arithmetic.
Computing Fourier coefficients numerically leads straight to the discrete Fourier transform. Done naively with N data points it takes N² multiplications, and bringing that down to N log N is what Cooley and Tukey achieved with the fast Fourier transform in 1965. Not long after their paper appeared, someone noticed that Gauss had written down essentially the same algorithm around 1805. He never published it; it surfaced only in his posthumous collected works, where it had sat unnoticed for over a century and a half.
Estimating the error of a numerical integration is, in practice, how you decide where to stop. Simpson's rule has an error proportional to the fourth power of the step size, so doubling the subdivisions shrinks the error by roughly a factor of sixteen. That estimate assumes the integrand is smooth enough, though, and it breaks down at points where the function is not differentiable. Enter abs(x) into this tool and vary the subdivision count: the accuracy improves noticeably less obediently than it does for a smooth function. Watching how the digits move is a decent way to feel out whether the assumptions behind a theorem are actually being met.