Fourier Series Calculator: Formula, Coefficients, and Worked Examples
A Fourier series calculator breaks a periodic function down into an infinite sum of sines and cosines, turning a complicated repeating waveform into a set of simple, individually understandable pieces. Every Fourier series calculator is automating the same three integrals — the coefficients a₀, aₙ, and bₙ — that you can compute by hand for any periodic function once you know the formulas. This guide walks through the Fourier series formula, exactly how to compute each coefficient, three fully worked examples (a square wave, a sawtooth wave, and a parabolic wave), the difference between even and odd symmetry, how many terms you actually need for a good approximation, and the mistakes that most often break a hand calculation.
Contents
- 01What Is a Fourier Series Calculator and How Does It Work?
- 02What Is the Fourier Series Formula and Where Does It Come From?
- 03How Do You Find the Fourier Coefficients a₀, aₙ, and bₙ?
- 04Worked Example 1: Fourier Series of a Square Wave
- 05Worked Example 2: Fourier Series of a Sawtooth Wave
- 06Worked Example 3: Fourier Series of an Even Function (x²)
- 07What's the Difference Between Even, Odd, and General Periodic Functions?
- 08How Many Terms Do You Need for a Good Approximation?
- 09What Mistakes Break a Hand-Computed Fourier Series?
- 10Fourier Series Calculator Practice Problems and FAQ
What Is a Fourier Series Calculator and How Does It Work?
A Fourier series calculator takes a periodic function — one that repeats itself over a fixed interval, called the period — and rewrites it as an infinite sum of sine and cosine waves of increasing frequency. The idea, first developed by Joseph Fourier while studying heat flow, is that almost any reasonable periodic signal, no matter how jagged or discontinuous, can be built up from smooth, well-understood building blocks: a constant term plus waves at frequency 1, 2, 3, 4, and so on times the fundamental frequency. Behind every Fourier series calculator sit three formulas that compute how much of each frequency is present in the original function. These are called the Fourier coefficients: a₀ (the average value, sometimes called the DC component), aₙ (the amount of each cosine wave), and bₙ (the amount of each sine wave). Once you have those numbers, the original function is rebuilt as f(x) = a₀/2 + Σ [aₙ cos(nx) + bₙ sin(nx)], summed over n = 1, 2, 3, and so on to infinity. Engineers use Fourier series to analyze electrical signals, vibration, and sound; physicists use them to solve the heat and wave equations; and students meet them in calculus, differential equations, and signal processing courses, usually with the same handful of test functions — square waves, sawtooth waves, and triangle waves — that this guide works through by hand.
f(x) = a₀/2 + Σₙ₌₁^∞ [aₙ cos(nx) + bₙ sin(nx)] — any reasonable periodic function, rebuilt from a constant plus an infinite stack of sine and cosine waves.
What Is the Fourier Series Formula and Where Does It Come From?
For a function f(x) with period 2π (the standard case taught first, before generalizing to other periods), the Fourier series formula and its three coefficient integrals are: f(x) = a₀/2 + Σₙ₌₁^∞ [aₙ cos(nx) + bₙ sin(nx)] a₀ = (1/π) ∫₋π^π f(x) dx aₙ = (1/π) ∫₋π^π f(x) cos(nx) dx bₙ = (1/π) ∫₋π^π f(x) sin(nx) dx These formulas come from a property called orthogonality: when you multiply two different sine or cosine waves (different frequencies) and integrate over one full period, the result is always zero. Only when you multiply a wave by itself does the integral come out nonzero. That property lets you isolate exactly how much of each individual frequency is 'hiding' inside f(x), one coefficient at a time, the same way you can find the coordinates of a vector by taking dot products against each axis. For a function with a general period 2L instead of 2π, replace cos(nx) and sin(nx) with cos(nπx/L) and sin(nπx/L), and change the integration bounds and the 1/π factor to 1/L. The logic and the orthogonality trick are identical — only the frequency scaling changes.
Orthogonality is the whole trick: ∫₋π^π cos(mx)cos(nx) dx = 0 whenever m ≠ n, which is exactly what lets a₀, aₙ, and bₙ be isolated one at a time.
How Do You Find the Fourier Coefficients a₀, aₙ, and bₙ?
Finding Fourier coefficients by hand is a mechanical process once the function is defined on one period. A Fourier series calculator runs through exactly these steps internally.
1. Step 1 — Identify the period and write f(x) piecewise if needed
Determine the period (2π, 2L, or another value) and write down f(x) explicitly over one full period. Many textbook functions — square waves, sawtooth waves — are defined piecewise, with a different formula on different parts of the interval.
2. Step 2 — Compute a₀ by integrating f(x) over one period
a₀ = (1/π) ∫₋π^π f(x) dx. This is twice the average value of f(x) over one period. If f(x) is an odd function (symmetric about the origin), a₀ = 0 automatically, since the positive and negative areas cancel.
3. Step 3 — Compute aₙ by integrating f(x)cos(nx)
aₙ = (1/π) ∫₋π^π f(x) cos(nx) dx. This usually requires integration by parts when f(x) is a polynomial, or a direct antiderivative when f(x) is piecewise constant. If f(x) is odd, aₙ = 0 for every n — odd functions contain no cosine content.
4. Step 4 — Compute bₙ by integrating f(x)sin(nx)
bₙ = (1/π) ∫₋π^π f(x) sin(nx) dx. If f(x) is even (symmetric about the y-axis), bₙ = 0 for every n — even functions contain no sine content.
5. Step 5 — Assemble the series and check symmetry as a shortcut
Substitute a₀, aₙ, and bₙ back into f(x) = a₀/2 + Σ[aₙcos(nx) + bₙsin(nx)]. Before integrating anything, checking whether f(x) is even, odd, or neither tells you in advance which coefficients will be zero, cutting the work roughly in half.
Odd function → only bₙ survives (a pure sine series). Even function → only a₀ and aₙ survive (a pure cosine series). Checking symmetry first saves half the integration work.
Worked Example 1: Fourier Series of a Square Wave
Consider the square wave defined on one period (-π, π) by f(x) = 1 for 0 < x < π and f(x) = -1 for -π < x < 0. This function is odd (f(-x) = -f(x)), so a₀ = 0 and every aₙ = 0 — only bₙ needs to be computed.
1. Step 1 — Set up the bₙ integral
bₙ = (1/π) ∫₋π^π f(x) sin(nx) dx = (1/π) [∫₋π^0 (-1)sin(nx) dx + ∫₀^π (1)sin(nx) dx]. By symmetry, both halves contribute equally, so this simplifies to bₙ = (2/π) ∫₀^π sin(nx) dx.
2. Step 2 — Integrate
∫₀^π sin(nx) dx = [-cos(nx)/n]₀^π = (-cos(nπ) + cos(0))/n = (1 - cos(nπ))/n. So bₙ = (2/(nπ)) · (1 - cos(nπ)).
3. Step 3 — Evaluate for odd and even n
cos(nπ) = (-1)ⁿ, so 1 - cos(nπ) = 1 - (-1)ⁿ. For even n this is 1 - 1 = 0, so bₙ = 0. For odd n this is 1 - (-1) = 2, so bₙ = 4/(nπ). Only odd harmonics appear — a signature feature of a square wave.
4. Step 4 — Write the series
f(x) = (4/π)[sin x + sin(3x)/3 + sin(5x)/5 + sin(7x)/7 + ...]. Every term is a sine wave at an odd multiple of the fundamental frequency, scaled down as 1/n.
5. Step 5 — Check numerically at x = π/2
The true value is f(π/2) = 1. Using the first four odd terms: S₄ = (4/π)(1 - 1/3 + 1/5 - 1/7) = (4/π)(0.7238) ≈ 0.922. Adding more terms — 1/9, 1/11, and so on — pulls this closer to 1, since 1 - 1/3 + 1/5 - 1/7 + ... converges to π/4 by the Leibniz series, and (4/π)(π/4) = 1 exactly in the limit.
Square wave check: (4/π)(1 - 1/3 + 1/5 - 1/7) ≈ 0.922, converging toward the true value f(π/2) = 1 as more odd harmonics are added.
Worked Example 2: Fourier Series of a Sawtooth Wave
Now take the sawtooth wave f(x) = x on the interval (-π, π), repeated with period 2π. This function is also odd, so again a₀ = 0 and aₙ = 0, and only bₙ needs integration by parts.
1. Step 1 — Set up the bₙ integral
bₙ = (1/π) ∫₋π^π x sin(nx) dx = (2/π) ∫₀^π x sin(nx) dx, using the fact that x sin(nx) is an even integrand (odd × odd = even).
2. Step 2 — Integrate by parts
Let u = x, dv = sin(nx)dx, so du = dx and v = -cos(nx)/n. Then ∫x sin(nx)dx = -x cos(nx)/n + (1/n)∫cos(nx)dx = -x cos(nx)/n + sin(nx)/n². Evaluating from 0 to π: [-π cos(nπ)/n + 0] - [0 + 0] = -π cos(nπ)/n = -π(-1)ⁿ/n.
3. Step 3 — Solve for bₙ
bₙ = (2/π) · (-π(-1)ⁿ/n) = -2(-1)ⁿ/n = 2(-1)ⁿ⁺¹/n. So b₁ = 2, b₂ = -1, b₃ = 2/3, b₄ = -1/2, and so on, alternating sign and shrinking as 1/n.
4. Step 4 — Write the series
f(x) = 2[sin x - sin(2x)/2 + sin(3x)/3 - sin(4x)/4 + ...] = 2 Σₙ₌₁^∞ (-1)ⁿ⁺¹ sin(nx)/n.
5. Step 5 — Check numerically at x = 1 radian
The true value is f(1) = 1. Using the first five terms with sin(1)=0.8415, sin(2)=0.9093, sin(3)=0.1411, sin(4)=-0.7568, sin(5)=-0.9589: S₅ = 2(0.8415 - 0.9093/2 + 0.1411/3 - (-0.7568)/4 + (-0.9589)/5) = 2(0.8415 - 0.4546 + 0.0470 + 0.1892 - 0.1918) = 2(0.4313) = 0.8626. This is oscillating toward the true value of 1 as more terms are added — a slower, alternating convergence that's typical of a function with a jump discontinuity at x = π.
Sawtooth bₙ formula: bₙ = 2(-1)ⁿ⁺¹/n — a clean alternating pattern that comes directly from integrating x sin(nx) by parts.
Worked Example 3: Fourier Series of an Even Function (x²)
For contrast, take f(x) = x² on (-π, π), repeated with period 2π. This function is even (f(-x) = f(x)), so bₙ = 0 for every n, and only a₀ and aₙ need to be computed — this time using cosine terms instead of sine terms.
1. Step 1 — Compute a₀
a₀ = (1/π) ∫₋π^π x² dx = (1/π) · [x³/3]₋π^π = (1/π) · (2π³/3) = 2π²/3 ≈ 6.5797. So a₀/2 = π²/3 ≈ 3.2899.
2. Step 2 — Compute aₙ using integration by parts twice
aₙ = (2/π) ∫₀^π x² cos(nx) dx (doubled since x²cos(nx) is even). Two rounds of integration by parts give ∫x²cos(nx)dx = x²sin(nx)/n + 2x cos(nx)/n² - 2sin(nx)/n³. Evaluated from 0 to π, only the middle term survives at each bound: the result is 2π cos(nπ)/n² = 2π(-1)ⁿ/n².
3. Step 3 — Solve for aₙ
aₙ = (2/π) · (2π(-1)ⁿ/n²) = 4(-1)ⁿ/n². So a₁ = -4, a₂ = 1, a₃ = -4/9, a₄ = 1/4, shrinking as 1/n² — noticeably faster than the 1/n decay of the square and sawtooth waves, because x² has no jump discontinuities.
4. Step 4 — Write the series
f(x) = π²/3 + 4 Σₙ₌₁^∞ (-1)ⁿ cos(nx)/n² = π²/3 - 4cos(x) + cos(2x) - (4/9)cos(3x) + (1/4)cos(4x) - ...
5. Step 5 — Check numerically at x = π/2
True value: f(π/2) = (π/2)² ≈ 2.4674. Using terms through n = 4, with cos(π/2)=0, cos(π)=-1, cos(3π/2)=0, cos(2π)=1: S₄ = 3.2899 + (-4)(0) + (1)(-1) + (-4/9)(0) + (1/4)(1) = 3.2899 - 1 + 0.25 = 2.5399. Already within 0.07 of the true value with just two nonzero terms — a direct result of the faster 1/n² decay.
a₀/2 = π²/3, aₙ = 4(-1)ⁿ/n² — with 1/n² decay instead of 1/n, this cosine series converges noticeably faster than the square or sawtooth wave series.
What's the Difference Between Even, Odd, and General Periodic Functions?
Symmetry is the single fastest shortcut in any hand computation of a Fourier series, and it's the first thing a Fourier series calculator checks internally before doing any integration. An even function satisfies f(-x) = f(x) — its graph is a mirror image across the y-axis, like cos(x) or x². Even functions produce a Fourier cosine series: a₀ and aₙ can be nonzero, but every bₙ is exactly zero, since sine terms are odd and would break the symmetry. An odd function satisfies f(-x) = -f(x) — its graph has 180° rotational symmetry about the origin, like sin(x) or x³. Odd functions produce a Fourier sine series: a₀ = 0 and every aₙ = 0, but bₙ can be nonzero. Most functions are neither purely even nor purely odd, and general periodic functions need all three coefficient types — a₀, aₙ, and bₙ — computed separately. A useful trick: any function can be split into an even part and an odd part, fₑᵥₑₙ(x) = [f(x)+f(-x)]/2 and fₒdd(x) = [f(x)-f(-x)]/2, and each part contributes only the coefficient type that matches its symmetry.
Even function → cosine series only (a₀, aₙ; bₙ = 0). Odd function → sine series only (bₙ; a₀ = aₙ = 0). Neither → compute all three coefficient types.
How Many Terms Do You Need for a Good Approximation?
A Fourier series is an infinite sum, but every practical calculation — by hand or by calculator — truncates it after a finite number of terms, called a partial sum. How many terms are 'enough' depends entirely on how smooth the original function is. For a function with no discontinuities and continuous derivatives, like the x² example above, coefficients shrink quickly (1/n² or faster), so a handful of terms already gets within a small fraction of a percent of the true value almost everywhere. For a function with jump discontinuities, like the square wave or the sawtooth wave, coefficients shrink more slowly (1/n), so convergence away from the jump is still fairly fast, but near the jump itself something different happens: the partial sums overshoot the true value by roughly 9% no matter how many terms you add. This overshoot is called the Gibbs phenomenon, and it never disappears as n → ∞ — it just squeezes into a narrower and narrower region right at the discontinuity. Away from any jump, though, the same partial sums converge normally and can be trusted to within the precision your problem needs. As a rule of thumb: for smooth functions, 5-10 terms are usually plenty for two-decimal accuracy; for functions with jumps, expect slower, oscillating convergence away from the jump and a persistent ~9% overshoot exactly at the jump, regardless of how many terms are included.
The Gibbs phenomenon: near a jump discontinuity, a Fourier partial sum overshoots the true value by about 9% no matter how many terms you add — it's a feature of truncation, not an error to fix.
What Mistakes Break a Hand-Computed Fourier Series?
A few recurring errors account for most incorrect Fourier series calculations.
1. Forgetting the a₀/2 factor
The constant term in the series is a₀/2, not a₀. Dropping the division by 2 shifts the entire reconstructed function up or down by a₀/2 — a common but easy-to-catch error if you check the average value of your final series against the average value of f(x).
2. Skipping the symmetry check
Computing aₙ from scratch for a function that is obviously odd (like a sawtooth) wastes significant algebra and increases the chance of an arithmetic slip. Always test f(-x) against f(x) and -f(x) before integrating.
3. Mismatching the period and the formula
Using cos(nx) and sin(nx) — the period-2π formulas — for a function with period 2L ≠ 2π produces a series that doesn't actually repeat with the right period. Always switch to cos(nπx/L) and sin(nπx/L), and 1/L instead of 1/π, whenever the period isn't 2π.
4. Losing sign errors in integration by parts
Both the sawtooth and x² examples above needed integration by parts, where a sign error in the boundary term (evaluating at the upper vs. lower limit) is the single most common source of a wrong aₙ or bₙ. Recomputing the coefficient for one known value of n and checking it against the original function's known behavior catches this quickly.
The fastest sanity check on any Fourier series: does f(0) — or another easy point — match a₀/2 plus the sum of a handful of terms evaluated at that point? A large mismatch usually means a sign or factor error.
Fourier Series Calculator Practice Problems and FAQ
Try these on your own, then check the answers below. 1) Find the Fourier series of f(x) = |x| on (-π, π). 2) Find bₙ for f(x) = x on (-2, 2), period 4. 3) Without integrating, state which coefficients are automatically zero for f(x) = x³ on (-π, π). Answers: 1) f(x) is even, so bₙ = 0; a₀ = π, aₙ = (2/(n²π))((-1)ⁿ - 1), giving aₙ = -4/(n²π) for odd n and 0 for even n. 2) Using period 2L = 4, so L = 2: bₙ = (2/L)∫₀^L x sin(nπx/L) dx works out to bₙ = 4(-1)ⁿ⁺¹/(nπ). 3) x³ is odd, so a₀ = 0 and every aₙ = 0 — only bₙ needs computing. A Fourier series calculator is genuinely useful for checking these by hand, especially for catching an arithmetic slip in a lengthy integration by parts, but the formulas themselves — a₀, aₙ, bₙ, and the even/odd shortcuts — are what actually let you set the problem up correctly in the first place. If you want every integration step shown explicitly rather than just a final coefficient, Solvify's step-by-step solver walks through each Fourier coefficient calculation the same way this guide does, term by term.
1. Why does a Fourier series only work for periodic functions?
Sine and cosine are themselves periodic, so any finite or infinite sum of them is automatically periodic too. A non-periodic function can still be approximated on a finite interval by treating that interval as one period, but the resulting series will repeat outside that interval even if the original function does not.
2. Can every periodic function be written as a Fourier series?
Most functions encountered in physics and engineering satisfy the Dirichlet conditions (finitely many discontinuities and extrema per period, and finite total variation), which guarantee convergence almost everywhere. At an actual jump discontinuity, the series converges to the midpoint of the jump rather than to either side's value.
The three-integral recipe never changes: find a₀, find aₙ, find bₙ, then substitute. Everything else — symmetry shortcuts, period scaling, convergence behavior — builds on that same base.
Related Articles
Partial Derivative Calculator: Step-by-Step Guide with Worked Examples
Fourier coefficient integrals and partial derivatives both rely on treating one variable at a time — this guide covers the multivariable calculus rules behind that idea.
Projectile Motion Calculator: How to Solve Any Trajectory by Hand
Another physics topic built from decomposing motion into independent components, the same divide-and-conquer approach used to isolate each Fourier coefficient.
Calculus Help: Limits, Derivatives, Integrals, and Series
The broader calculus toolkit — integration by parts, series convergence, and definite integrals — that every Fourier coefficient calculation draws on directly.
Related Math Solvers
Step-by-Step Solutions
Get every integration-by-parts step shown explicitly when computing a₀, aₙ, and bₙ, including the boundary evaluations that most often hide sign errors.
Smart Scan Solver
Snap a photo of a Fourier coefficient integral from a textbook or problem set and get a fully worked solution instantly.
AI Math Tutor
Ask follow-up questions about symmetry shortcuts, convergence, or the Gibbs phenomenon as you work through a specific Fourier series problem.
