Mathematics · Calculus · Sequences & Series
Fourier Series Calculator
Computes the Fourier series coefficients and partial sum approximation for common periodic functions over a specified period.
Calculator
Formula
f(x) is the periodic function being approximated. a₀ is twice the average value of f over one period: a₀ = (2/L)∫₀ᴸ f(x) dx. The cosine coefficients are aₙ = (2/L)∫₀ᴸ f(x) cos(2πnx/L) dx. The sine coefficients are bₙ = (2/L)∫₀ᴸ f(x) sin(2πnx/L) dx. L is the period of the function. N is the number of harmonic terms included in the partial sum. x is the independent variable evaluated at a chosen point.
Source: Kreyszig, E. — Advanced Engineering Mathematics, 10th ed., Wiley (2011), Chapter 11.
How it works
A Fourier series expresses any well-behaved periodic function as an infinite sum of sines and cosines at integer multiples (harmonics) of a fundamental frequency. The remarkable insight, first published by Jean-Baptiste Joseph Fourier in 1822, is that even discontinuous functions like a square wave can be represented exactly as an infinite trigonometric series — the key is that the series converges to the function's average value at any jump discontinuity. This decomposition transforms a time-domain description of a signal into its frequency-domain components, revealing which harmonics carry the most energy.
The general Fourier series for a periodic function f(x) with period L is: f(x) ≈ a₀/2 + Σ[aₙ cos(2πnx/L) + bₙ sin(2πnx/L)]. The coefficient a₀/2 is the mean value of the function over one period. The cosine coefficients aₙ = (2/L)∫₀ᴸ f(x)cos(2πnx/L)dx capture even-symmetric content, while the sine coefficients bₙ = (2/L)∫₀ᴸ f(x)sin(2πnx/L)dx capture odd-symmetric content. For the three waveforms supported here, these integrals have closed-form solutions: the square wave has only odd-harmonic sine terms (4A/nπ for odd n), the sawtooth wave has all-harmonic sine terms with alternating signs (2A(−1)ⁿ⁺¹/nπ), and the triangle wave has only odd-harmonic cosine terms (8A/(n²π²) for odd n).
In practice, engineers use Fourier series to design audio equalizers and anti-aliasing filters, solve the heat equation and wave equation in physics, analyze structural vibrations and resonance frequencies, synthesize waveforms in digital signal processors, and understand harmonic distortion in power systems. The partial sum with N terms gives the best N-term trigonometric approximation to the original function in the least-squares sense, making it directly applicable to real-world signal reconstruction problems.
Worked example
Problem: Find the first three non-zero Fourier coefficients of a square wave with amplitude A = 1 and period L = 2π, then evaluate the 5-term partial sum at x = π/4.
Step 1 — Identify symmetry: A square wave centered at zero is an odd function, so all cosine coefficients aₙ = 0, and a₀ = 0. Only odd harmonics survive.
Step 2 — Compute b₁: b₁ = 4A/π = 4(1)/π ≈ 1.273240
Step 3 — Compute b₃: b₃ = 4A/(3π) = 4/(3π) ≈ 0.424413
Step 4 — Compute b₅: b₅ = 4A/(5π) = 4/(5π) ≈ 0.254648
Step 5 — Evaluate partial sum at x = π/4 (with L = 2π, so 2πx/L = x):
f(π/4) ≈ (4/π)[sin(π/4) + (1/3)sin(3π/4) + (1/5)sin(5π/4) + (1/7)sin(7π/4) + (1/9)sin(9π/4)]
= (4/π)[0.7071 + 0.2357 − 0.1414 − 0.1010 + 0.0786]
≈ (4/π)(0.7790) ≈ 0.9922
Result: The 5-term partial sum evaluates to approximately 0.9922 at x = π/4, very close to the true value of 1.0, demonstrating rapid convergence away from the discontinuity.
Limitations & notes
Fourier series analysis has several important limitations to keep in mind. First, the Gibbs phenomenon causes the partial sum to overshoot by approximately 9% near jump discontinuities regardless of how many terms are included — this is an intrinsic feature of pointwise convergence, not a numerical error. Second, this calculator provides analytical coefficients for three canonical waveforms only; arbitrary user-defined functions require numerical integration (e.g., the FFT algorithm) which is not implemented here. Third, Fourier series apply strictly to periodic functions — for non-periodic signals, the Fourier transform (continuous or discrete) is the appropriate tool. Fourth, convergence is guaranteed only for functions satisfying the Dirichlet conditions: bounded variation, finite number of discontinuities, and absolute integrability over one period. Fifth, the calculator limits N to 50 terms for performance; while this is sufficient for most engineering approximations, theoretical analysis may require symbolic summation of the infinite series.
Frequently asked questions
What is the difference between Fourier series and Fourier transform?
A Fourier series decomposes a periodic function into a discrete set of harmonically related sinusoids with frequencies that are integer multiples of the fundamental frequency 1/L. The Fourier transform, in contrast, handles non-periodic signals and produces a continuous spectrum of frequencies. The Fourier series can be seen as a special case of the Fourier transform applied to a periodic signal, where the spectrum consists only of impulses at the harmonic frequencies.
Why does the square wave Fourier series only contain odd harmonics?
A standard square wave possesses half-wave symmetry: f(x + L/2) = −f(x). This condition mathematically forces all even-numbered harmonic coefficients (b₂, b₄, b₆, …) to be exactly zero. Only the odd harmonics (1st, 3rd, 5th, …) contribute, each with amplitude 4A/(nπ). This is also why a square wave sounds brighter and harsher than a sine wave — it is rich in high-frequency odd harmonics.
What is the Gibbs phenomenon and how does it affect my calculations?
The Gibbs phenomenon is the persistent overshoot (approximately 8.9% above the true value) that occurs near a jump discontinuity in the Fourier partial sum, regardless of how many terms N are used. Adding more terms does not eliminate the overshoot; it only moves it closer to the discontinuity and makes it narrower. For smooth regions of the waveform, increasing N dramatically improves accuracy. Techniques like Lanczos sigma smoothing or Fejér summation can partially suppress the Gibbs effect.
How many Fourier series terms do I need for a good approximation?
For most engineering applications, 10–20 terms provide a visually good approximation with error below 5% in smooth regions. The required N depends on the waveform: triangle waves converge very rapidly (amplitudes decay as 1/n²), square and sawtooth waves converge more slowly (amplitudes decay as 1/n). For high-fidelity signal reconstruction or audio synthesis, 50–100 terms may be appropriate, while analytical work often uses the closed-form infinite series.
Can Fourier series represent any periodic function?
Fourier series can represent any periodic function satisfying the Dirichlet conditions: the function must be absolutely integrable over one period, have a finite number of maxima, minima, and discontinuities within each period, and have finite one-sided limits at every point. This covers virtually all physically realizable periodic signals encountered in engineering and physics. At points of discontinuity, the Fourier series converges to the average of the left- and right-hand limits.
Last updated: 2025-01-15 · Formula verified against primary sources.