A Fourier series represents a periodic function as a weighted sum of simple sine and cosine waves. Instead of working directly with a complicated waveform, you describe it using its harmonics — pure tones at integer multiples of a base frequency. This calculator focuses on functions defined on the interval [−π, π] and assumes they extend periodically with period 2π.
For a function f(x) that is 2π-periodic and integrable on [−π, π], its Fourier series can be written in the form
f(x) = a₀/2 + Σn=1∞ [aₙ cos(nx) + bₙ sin(nx)].
The coefficients aₙ and bₙ tell you how much of each cosine and sine harmonic appears in the signal. Low-order terms capture coarse features; higher-order terms capture sharper details and rapid oscillations.
The standard coefficient formulas on [−π, π] are
Using these coefficients, the full Fourier series is
In practice you almost never sum infinitely many terms. Instead, you use a truncated series of order N:
SN(x) = a₀/2 + Σn=1N [aₙ cos(nx) + bₙ sin(nx)].
This calculator computes such partial sums SN(x) by approximating the integrals numerically.
The tool expects an input function f(x) defined on [−π, π] using math.js syntax (for example, x^2, abs(x), or sin(3*x) + 0.5*cos(2*x)). It then:
Numerical integration trades exact symbolic formulas for speed and flexibility. You can use almost any reasonable function that math.js can evaluate, including ones without elementary antiderivatives.
To compute a truncated Fourier series on [−π, π]:
x^2abs(x)sin(3*x) + 0.5*cos(2*x)The series output helps you see which harmonics dominate the signal and how many terms are required to capture its main shape.
Each coefficient corresponds to a specific frequency component:
Symmetry greatly simplifies the interpretation:
The truncated series SN(x) is an approximation. As N increases, SN(x) generally converges to f(x) at points where f is continuous, and to the midpoint of the left and right limits at jump discontinuities.
Consider f(x) = |x| on [−π, π]. This function is even, so the Fourier series should contain only cosine terms. To reproduce this example with the calculator:
abs(x).The resulting truncated series has the form
SN(x) = a₀/2 + Σn=1N aₙ cos(nx),
with decreasing cosine coefficients as n increases. For relatively small N you already see a good approximation to the characteristic “V” shape of |x|. As N grows, the approximation becomes closer, especially away from the endpoints ±π. Because |x| is continuous but has a sharp corner at 0, you may observe mild overshoot and ripples near that point, a manifestation of Gibbs-type behavior associated with non-smooth features.
The behavior of the Fourier coefficients depends strongly on the nature of f(x). The table below summarizes some typical patterns:
| Function type | Symmetry | Nonzero coefficients | Typical coefficient decay | Qualitative behavior of SN(x) |
|---|---|---|---|---|
| Smooth (many derivatives), e.g., sin(x) | Depends on example | Both aₙ and bₙ may appear | Often faster than 1/n² | Very rapid convergence; small N gives high accuracy |
| Piecewise smooth with corners, e.g., |x| | Even or odd possible | Typically one family (cosines for even, sines for odd) | About 1/n² | Good convergence but visible ripples near non-smooth points |
| Functions with jump discontinuities, e.g., square wave | Often odd or even when centered | Usually only sines for odd, only cosines for even | About 1/n | Convergence with persistent overshoot near jumps (Gibbs phenomenon) |
By comparing the coefficients produced by the calculator to these patterns, you can quickly infer whether your function is smooth, has sharp corners, or has jumps.
This calculator is intended for students, instructors, and engineers who need a quick way to:
Common application domains include signal processing, vibration analysis, acoustics, heat conduction, and other areas where periodic phenomena appear.
To interpret the results correctly, keep the following assumptions and limitations in mind:
Understanding these assumptions helps you use the calculator confidently while remaining aware of its scope. The Fourier series it produces are powerful aids for intuition, visualization, and preliminary analysis, but they should be combined with mathematical judgment and, where necessary, more rigorous verification.