Fourier Series Calculator

Coefficients by quadrature, symmetry detected, and the partial sum plotted against the true wave.

Fourier Series Calculator

What Is a Fourier Series?

Taylor series build functions from powers of x; a Fourier series builds them from waves. Any reasonable function on [−π, π], extended periodically, decomposes into a sum of sines and cosines of integer frequencies:

f(x) ~ a₀/2 + Σ [aₙ·cos(nx) + bₙ·sin(nx)]

with coefficients extracted by integration: aₙ = (1/π)∫f(x)cos(nx)dx and bₙ = (1/π)∫f(x)sin(nx)dx over one period. Each coefficient measures how much of that frequency lives in f the formula works because the waves are orthogonal: ∫sin(mx)sin(nx)dx = 0 for m ≠ n, so multiplying by a wave and integrating isolates that wave's share, like tuning a radio to one station. Fourier's 1807 claim that essentially any function admits such a decomposition scandalized his examiners and then rebuilt mathematics: much of modern analysis exists to make his claim precise.

How to Use This Calculator

Enter a function on [−π, π] and how many terms to keep. The calculator evaluates every coefficient by high-resolution numerical quadrature, prints the list and the assembled partial sum SN detects even/odd symmetry (cosines-only or sines-only), and plots SN in indigo against the true periodic extension in gray, including the sharp corners and jumps of the extension that the smooth waves are straining to imitate. Increase N and rerun: watching the sum hug the corners ever tighter (and overshoot at jumps) teaches more Fourier analysis than a chapter of formulas.

Worked Example: the Sawtooth

f(x) = x on [−π, π], repeated forever, is the sawtooth wave. Odd symmetry kills a₀ and every aₙ; the sine coefficients integrate (by parts) to bₙ = 2(−1)^(n+1)/n:

x ~ 2[sin x − sin 2x/2 + sin 3x/3 − sin 4x/4 + ⋯]

The calculator's numeric coefficients land on 2, −1, 0.667, −0.5, … exactly as the formula predicts. Two features deserve staring at: coefficients decay like 1/n, slowly, because the periodic extension has jumps at ±π (smoothness of the function controls decay speed of its spectrum), and near those jumps the partial sum overshoots by about 9% no matter how many terms are kept, the celebrated Gibbs phenomenon plainly visible in the plot. Compare the triangle wave |x| (second chip): continuous extension, coefficients decaying like 1/n², visibly faster convergence, no Gibbs horns.

Symmetry Reads the Spectrum in Advance

Before integrating anything, symmetry predicts half the answer. Even functions (f(−x) = f(x), like |x| and x²) contain only cosines, every bₙ integral pairs a symmetric f against an antisymmetric sine and cancels. Odd functions (x, x³ − 3x) contain only sines. The calculator reports the symmetry it detects, and the x² chip shows the even case beautifully: x² ~ π²/3 + 4Σ(−1)ⁿcos(nx)/n², whose evaluation at x = π delivers a famous bonus, Σ1/n² = π²/6, the Basel problem solved by plugging one point into a Fourier series. Coefficient decay tells the other half of the story: 1/n means jumps, 1/n² means corners, 1/n³ means curvature breaks, the smoothness of a signal is legible in how fast its spectrum fades.

Common Mistakes to Avoid

  • Forgetting the periodic extension. The series represents f repeated with period 2π, outside [−π, π] it follows the repetition, not your formula. The gray curve in the plot is the actual object being approximated; x² beyond π is not what the series converges to.
  • Expecting convergence to f at a jump. At discontinuities the series converges to the midpoint of the two one-sided values, the sawtooth's series gives 0 at x = π, not π. This is a theorem (Dirichlet), not a numerical artifact.
  • Treating Gibbs overshoot as fixable by more terms. The 9% horn narrows with N but never shrinks in height. It's a property of approximating jumps with smooth waves; engineering copes via windowing (Fejér/σ-approximation), not more terms.
  • Dropping the ½ on a₀. The constant term is a₀/2 (the function's average value), the price of using a uniform coefficient formula. Off-by-half constants are the most common hand-computation casualty.

Real-World Applications

Fourier series and their descendants (the FFT) are arguably the most-used applied mathematics on Earth. Audio is the plainest case: a musical note's timbre is its Fourier coefficients, same fundamental, different harmonic mix is why violin and flute differ, and MP3 compression discards coefficients your ear won't miss. JPEG does the same to images with the cosine-only variant (DCT). Every equalizer bar, noise-canceling headphone, and pitch-correction plugin is coefficient surgery.

Engineering solves differential equations with it, Fourier invented the series to solve the heat equation, decomposing initial temperature into modes that each decay at their own rate e^(−n²kt); vibration analysis reads machinery health from harmonic spectra (a bearing fault announces itself as a new frequency line); power engineers bill "total harmonic distortion" as the energy in coefficients beyond the fundamental; and communications, from AM radio to 5G's OFDM, transmits data literally as Fourier coefficients. MRI machines record raw data in frequency space and reconstruct your anatomy by an inverse Fourier transform: the picture of your knee is this page's mathematics, inverted.

Frequently Asked Questions

What functions have a convergent Fourier series?

Dirichlet's practical conditions: piecewise smooth on the period (finitely many jumps and corners) guarantees pointwise convergence, to f where continuous, to the jump midpoint elsewhere. Every function an engineering course meets qualifies; the pathological exceptions are analysis-seminar material.

How do I use a period other than 2π?

Rescale: on [−L, L] the waves are cos(nπx/L), sin(nπx/L) with matching coefficient integrals (1/L in front). The theory is identical; this tool works on the standard interval, and substituting u = πx/L converts any other.

What's the complex exponential form?

f ~ Σcₙe^(inx) with cₙ = (1/2π)∫f·e^(−inx)dx, sines and cosines fused via Euler's formula, one formula replacing three. It's the form the FFT computes and the gateway to the Fourier transform where the period → ∞ and the discrete spectrum becomes continuous.

Why do the computed coefficients sometimes show as 0 exactly?

Symmetry: the quadrature returns ~10⁻¹⁶ and the display rounds honestly to 0. Seeing an entire family vanish (all bₙ for |x|) is the numerical shadow of the even/odd theorems, the calculator names the symmetry when it detects the pattern.

What is Parseval's theorem, in audio terms?

Energy bookkeeping: (1/π)∫f² dx = a₀²/2 + Σ(aₙ² + bₙ²), the signal's total power equals the sum of its harmonics' powers. It's why discarding tiny coefficients (MP3) provably loses little energy, and it converts series identities into integral identities (the Basel evaluation again, from x²'s series).

How is this related to Taylor series?

Both expand f in a basis: Taylor in powers (local information, derivatives at one point; excellent nearby, blind to periodicity), Fourier in waves (global information, integrals over the period; built for periodic and bounded behavior). The Taylor tool and this one are the two poles of approximation theory.