Fourier Series Calculator

Enter any function — including a piecewise one such as 0 on (−π, 0) and x on (0, π) — or pick a standard waveform, choose N, and get a0, an, bn, the series written out and a graph of the partial sum.

For a function with period 2L, the Fourier series is f(x) ≈ a₀/2 + Σ [aₙ cos(nπx/L) + bₙ sin(nπx/L)], with a₀ = (1/L)∫f(x)dx, aₙ = (1/L)∫f(x)cos(nπx/L)dx and bₙ = (1/L)∫f(x)sin(nπx/L)dx taken over one full period.

Use the Fourier Series Calculator

Function Settings

12π452π
11020304050

Fourier Series Formula

DC Term (a0/2)

Average value of f(x) over one period.

Partial Sum Approximation

Fourier sum Original

Coefficient Table

n an bn Amplitude

Fourier Coefficients of Common Waveforms

Period 2L, series a₀/2 + Σ[aₙ cos(nπx/L) + bₙ sin(nπx/L)]. Odd functions have only sine terms; even functions only cosine terms.

WaveformOne perioda₀aₙbₙSymmetry
Square wave −1 on (−L, 0), 1 on (0, L) 0 0 4/(nπ), odd n only Odd
Sawtooth x/L on (−L, L) 0 0 2(−1)ⁿ⁺¹/(nπ) Odd
Triangle 1 − 2|x|/L on (−L, L) 0 8/(n²π²), odd n only 0 Even
Full-wave rectified sine |sin(πx/L)| 4/π −4/(π(n²−1)), even n only 0 Even
Half-wave rectified sine sin(πx/L) on (0, L), 0 on (L, 2L) 2/π −2/(π(n²−1)), even n only ½ for n = 1, else 0 Neither
Parabola x² on (−π, π) 2π²/3 4(−1)ⁿ/n² 0 Even

Quick answer

For a function with period 2L, the Fourier series is f(x) ≈ a₀/2 + Σ [aₙ cos(nπx/L) + bₙ sin(nπx/L)], with a₀ = (1/L)∫f(x)dx, aₙ = (1/L)∫f(x)cos(nπx/L)dx and bₙ = (1/L)∫f(x)sin(nπx/L)dx taken over one full period. Odd functions have every aₙ = 0 and even functions have every bₙ = 0. This calculator evaluates those integrals numerically for any function or set of pieces you type in.

Examples

f(x) on one perioda₀aₙbₙ
Square wave −1 on (−π, 0), 1 on (0, π)004/(nπ) for odd n, 0 for even n
x on (−π, π) (sawtooth)002(−1)ⁿ⁺¹/n
x² on (−π, π)2π²/34(−1)ⁿ/n²0
|sin x| (full-wave rectified)4/π−4/(π(n²−1)) for even n0

Choose Custom / piecewise to type your own function, or pick a waveform, then set the number of terms N.

Summary

This Fourier series calculator finds the coefficients a₀, aₙ and bₙ of a periodic function and shows how the partial sum with N terms approaches it. Type your own function of x, or split one period into up to six pieces (for example 0 on (−π, 0) and x on (0, π)), and the coefficients are computed by Simpson's-rule integration over one period. Standard waveforms — square, sawtooth, triangle, full-wave and half-wave rectified sine — use exact closed-form coefficients. The graph overlays the partial sum on the original function so you can see convergence and the Gibbs overshoot at jumps, and the table lists aₙ, bₙ and the amplitude of every harmonic up to N = 50.

How it works

  1. Pick a standard waveform, or choose Custom / piecewise and enter one period as one or more pieces: start, end and f(x) for each. The period is the end of the last piece minus the start of the first, and L is half of it.
  2. You can type x, numbers, + − × ÷ ^, pi (or π), e, and functions such as sin, cos, tan, exp, ln, log (base 10), sqrt and abs, for example 2x^2 − 1 or abs(sin(x)).
  3. The calculator integrates a₀ = (1/L)∫f dx, aₙ = (1/L)∫f cos(nπx/L) dx and bₙ = (1/L)∫f sin(nπx/L) dx over the period with Simpson's rule (4,000 steps per piece). Standard waveforms use their exact formulas.
  4. The partial sum S_N(x) = a₀/2 + Σ from n = 1 to N of [aₙ cos(nπx/L) + bₙ sin(nπx/L)] is drawn over two periods together with the original function.
  5. The table lists aₙ, bₙ and the amplitude √(aₙ² + bₙ²) of each harmonic; the peak of the partial sum shows the Gibbs overshoot next to jumps.

Use cases

  • Check hand-calculated Fourier coefficients for a homework or exam problem, including piecewise functions.
  • See the Gibbs phenomenon: the roughly 9% overshoot that stays at a jump however many terms you add.
  • Find how many terms a square, sawtooth or triangle wave needs for a good approximation.
  • Get the harmonic amplitudes of a periodic signal for a signals and systems course.
  • Confirm symmetry shortcuts: odd functions have only sine terms and even functions only cosine terms.

Frequently Asked Questions

Last updated: 2026-10-10 · Reviewed by Nham Vu