Fourier Series Calculator

Compute Fourier coefficients a₀, aₙ, bₙ and reconstruct periodic functions. Visualize the original function and its Fourier partial sum up to N harmonics. Perfect for engineers, mathematicians, and students.

 
Supports sin, cos, tan, exp, log, abs, power ^, and constants pi, e.
Supports expressions like pi, pi/2, 2*pi, etc.
Examples:
? sin(x)
? Square wave
△ Triangle wave (|x|)
⚡ Sawtooth (x)
? Parabola x²
? cos(2x)
All calculations are performed locally via numerical integration. No data leaves your device.

Understanding Fourier Series: From Theory to Practice

Fourier series decompose periodic functions into infinite sums of sines and cosines. For a function f(x) with period 2L, the Fourier expansion is:

f(x) = a₀/2 + Σₙ₌₁^∞ [ aₙ cos(nπx/L) + bₙ sin(nπx/L) ]

where a₀ = (1/L)∫₋ᴸᴸ f(x) dx, aₙ = (1/L)∫₋ᴸᴸ f(x) cos(nπx/L) dx, bₙ = (1/L)∫₋ᴸᴸ f(x) sin(nπx/L) dx

This powerful concept bridges the time domain with frequency domain, making it essential in acoustics, electrical engineering, quantum mechanics, and data compression. Our calculator evaluates these integrals numerically using adaptive Simpson‑like quadrature, giving you accurate coefficients for custom functions.

Why Use an Interactive Fourier Calculator?

  • Visual Learning: Watch the Fourier partial sum converge to the original function as you increase N.
  • Gibbs Phenomenon: Observe ringing artifacts near discontinuities (square wave).
  • Engineering Analysis: Quickly obtain harmonic content for periodic signals.
  • Pedagogical Power: Verify analytic coefficients with numerical results.

Step-by-Step Numerical Method

  1. Parse your expression via math.js and create an evaluable function f(x).
  2. Compute a₀, aₙ, bₙ for n = 1 … N using high‑precision Simpson integration (2048 subintervals).
  3. Reconstruct the Fourier partial sum: S(x) = a₀/2 + Σ (aₙ cos(nπx/L) + bₙ sin(nπx/L)).
  4. Plot both f(x) and S(x) over the interval [-L, L] and also two extra periods for context.

Historical & Mathematical Significance

Named after Joseph Fourier (1768–1830), his groundbreaking work "The Analytical Theory of Heat" introduced series expansion to solve partial differential equations. Initially controversial, it later became the foundation of harmonic analysis. The orthogonality of trigonometric functions guarantees uniqueness of coefficients, and the convergence (pointwise, uniform, or L²) depends on function regularity. Fourier series also enable the famous Fast Fourier Transform (FFT), revolutionizing digital signal processing.

Real-World Applications

Audio Synthesis: Additive synthesis builds sounds by summing sinusoidal harmonics.
Electrical Engineering: Analyze AC signals, total harmonic distortion (THD).
Climate Modeling: Periodic temperature patterns modeled via Fourier.
Image Compression: JPEG uses discrete cosine transform (DCT), a relative of Fourier series.

Common Misconceptions & Clarifications

  • "Fourier series only works for smooth functions" → False; even discontinuous periodic functions have convergent Fourier series in the mean-square sense.
  • "More harmonics always improve approximation" → Usually yes, but near discontinuities Gibbs phenomenon never fully vanishes, only oscillates with constant overshoot.
  • "a₀ is the mean value" → Exactly: a₀/2 equals the average value of f over one period.

Accuracy & Numerical Integration

Our calculator uses composite Simpson’s rule with 2048 points per integral to achieve high accuracy. For well‑behaved functions, coefficient errors are below 1e-5. For functions with steep gradients, the error remains minimal. Each integration is performed independently; results are robust for up to N = 25 harmonics.

This tool implements classical Fourier theory as described in standard references (Weisstein, "Fourier Series," MathWorld; Bracewell, "The Fourier Transform and Its Applications"). The numerical integration engine follows best practices from numerical analysis. Reviewed by the GetZenQuery tech team, updated June 2026.

Frequently Asked Questions

Any real‑valued function expression using math.js: polynomials, trigonometric (sin, cos, tan), exponentials, logs, and absolute values. Use 'x' as variable, constants like pi, e.

The Gibbs phenomenon occurs due to the inability of finite trigonometric sums to converge uniformly at a discontinuity, causing ~9% overshoot.

Yes. Adjust the half‑period L (period = 2L). The function is assumed periodic with that interval. You can use expressions like pi, pi/2, 2.5, etc.

Numerical integration uses adaptive Simpson; typical relative error < 1e-5 for smooth functions.
References: Wolfram Fourier Series, Wikipedia, K. F. Riley, "Mathematical Methods for Physics and Engineering".