Skip to content
MoneyDeck

Fourier Series Calculator

Find Fourier coefficients and plot partial sums of a periodic function

Updated · Free, no signup

Use x; piecewise rules use condition ? a : b.

A number or expression such as pi or 2.

Fourier series (first N terms)

3.289868 − 4cos(x) + cos(2x) − 0.444444cos(3x) + 0.25cos(4x) − 0.16cos(5x)

Constant term a₀/2

3.289868

a₁

-4

b₁

0

a₂

1

b₂

0

Partial sum S_N(x₀)

0.943712

f(x₀)

1

Symmetry

Even function — cosine series (all bₙ = 0)
  • With 5 terms, S_N(1) = 0.9437119 versus f(1) = 1 (difference 0.05629).
  • The periodic extension of f has no jumps, so the coefficients shrink at least like 1/n² and the partial sums converge to f(x) everywhere — add terms to see the gap close.

f(x) and the N-term Fourier partial sum

Fourier coefficients

naₙ (cosine)bₙ (sine)Amplitude √(aₙ² + bₙ²)
1-404
2101
3-0.4444444400.44444444
40.2500.25
5-0.1600.16

About the Fourier Series Calculator

This Fourier series calculator finds the coefficients of the trigonometric series f(x) ≈ a₀/2 + Σ [aₙ cos(nπx/L) + bₙ sin(nπx/L)] for a function defined on one period from −L to L. Type a function such as x^2, x, abs(x) or a piecewise rule like x < 0 ? 0 : 1, choose the half-period L and the number of terms, and it returns the coefficients, the written series and the value of the partial sum at any point.

It is intended for students in differential equations, signals and physics courses, and for engineers checking the harmonic content of square, sawtooth and triangle waves. The graph overlays the original function and the N-term partial sum so you can watch the approximation improve as you add terms — and see the Gibbs overshoot near jumps.

Coefficients are computed numerically with Gauss–Legendre quadrature (400 panels), which is accurate to about 8 significant figures for smooth or piecewise-smooth functions whose jumps fall at x = 0 or at panel edges. The function is assumed to repeat with period 2L outside the interval. Use radians and write pi for π.

How to use the fourier series calculator

  1. 1Pick a preset wave or choose Custom and type f(x) for one period.
  2. 2Enter the half-period L — use pi for the interval −π to π.
  3. 3Choose how many terms N to include.
  4. 4Read the coefficients, the series and the partial sum at your chosen x₀.
  5. 5Compare f(x) and the partial sum on the graph; increase N to improve the fit.

Formula and method

f(x) ≈ a₀/2 + Σₙ₌₁ᴺ [aₙ cos(nπx/L) + bₙ sin(nπx/L)], aₙ = (1/L)∫₋ₗᴸ f(x) cos(nπx/L) dx, bₙ = (1/L)∫₋ₗᴸ f(x) sin(nπx/L) dx

A periodic function with period 2L can be written as a sum of sines and cosines whose frequencies are whole-number multiples of the fundamental frequency π/L. Because these functions are orthogonal over one period, each coefficient is found by multiplying f by the matching sine or cosine and integrating over [−L, L]. The constant term a₀/2 is the average value of f over the period.

Even functions (f(−x) = f(x)) have only cosine terms and odd functions only sine terms. This calculator evaluates every integral numerically with 5-point Gauss–Legendre quadrature on 400 panels, reusing the same function samples for all coefficients, and then sums the first N harmonics to form the partial sum S_N(x).

L
Half the period (the function repeats every 2L)
aₙ, bₙ
Cosine and sine coefficients of harmonic n
N
Number of harmonics in the partial sum

Worked examples

f(x) = x² on [−π, π] with 5 terms

x² is even, so only cosines appear: a₀/2 = π²/3 ≈ 3.289868 and aₙ = 4(−1)ⁿ/n², giving −4, 1, −4/9 … At x = 1 the five-term sum is ≈ 0.943712, approaching f(1) = 1.

Sawtooth f(x) = x on [−π, π]

x is odd, so only sines appear with bₙ = 2(−1)ⁿ⁺¹/n: 2, −1, 2/3, −1/2, 2/5. Their sum at x = 1 is ≈ 0.862556 — slow convergence, typical of a function with a jump at ±π.

Square wave with 7 terms at x = π/2

For sign(x), bₙ = 4/(nπ) for odd n and 0 for even n, so b₁ = 4/π ≈ 1.27324. Harmonics 1, 3, 5 and 7 sum to ≈ 0.921583 at the top of the wave, where f = 1.

Triangle wave |x| on [−1, 1] at x = 0

With L = 1, a₀/2 = ½ and aₙ = 2((−1)ⁿ − 1)/(nπ)², so a₁ = −4/π² ≈ −0.405285 and even-n terms vanish. Coefficients fall off like 1/n², so five terms already give ≈ 0.0335 at the corner x = 0.

Frequently asked questions

What is a Fourier series?+

A Fourier series writes a periodic function as a constant plus a sum of sine and cosine waves at whole-number multiples of a base frequency. With enough terms it can approximate almost any periodic signal, which is why it underpins signal processing, acoustics and heat-flow problems.

How do you find the Fourier coefficients?+

Integrate the function times the matching cosine or sine over one period and divide by L: aₙ = (1/L)∫ f(x) cos(nπx/L) dx and bₙ = (1/L)∫ f(x) sin(nπx/L) dx. The constant a₀/2 is the average of f over the period.

Why are some coefficients zero?+

Symmetry kills terms. If f is even (like x² or |x|) every bₙ is zero, and if f is odd (like x or a square wave) every aₙ and a₀ are zero. Half-wave symmetry, as in the square wave, also removes the even harmonics.

What is the Gibbs phenomenon?+

Near a jump in the function, Fourier partial sums overshoot by roughly 9% of the jump height. Adding more terms narrows the overshoot but never removes it; at the jump itself the series converges to the average of the left and right values.

How do I enter a piecewise function?+

Use the conditional operator: x < 0 ? 0 : 1 is 0 for negative x and 1 otherwise. You can nest conditions, for example x < -1 ? 0 : (x < 1 ? 1 : 0), or use abs(x) and sign(x) for common shapes.

Related tools