Fourier Series Calculator

Introduction

Fourier series are one of the most practical ideas in applied mathematics because they let you trade a complicated periodic function for a list of simpler wave ingredients. Instead of trying to reason about the whole shape at once, you break it into harmonics and ask a more manageable question: how much of the first cosine wave is present, how much of the second sine wave is present, and how much of the pattern survives in higher frequencies? This calculator performs exactly that decomposition on the interval [−π, π] and then reports the coefficients of a truncated Fourier series that you can inspect, compare, or reuse in later work.

If you are learning the topic for the first time, it helps to think of the output as a recipe rather than as abstract notation. The function field describes one period of the waveform. The order N tells the calculator how many harmonics to keep. The resulting coefficient table shows the average level and the weights of the cosine and sine terms that best reproduce the waveform over one period. Small values mean a harmonic contributes very little. Larger values point to the frequencies that dominate the signal, the vibration, or the repeating shape you entered.

What Is a Fourier Series?

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 broad structure and average curvature. Higher-order terms capture sharper corners, more rapid oscillations, and the fine detail that makes one waveform feel different from another.

Core Formulas

The standard coefficient formulas on [−π, π] are

  • a₀ = (1/π) ∫−ππ f(x) dx
  • aₙ = (1/π) ∫−ππ f(x) cos(nx) dx, for n ≥ 1
  • bₙ = (1/π) ∫−ππ f(x) sin(nx) dx, for n ≥ 1

Using these coefficients, the full Fourier series is

f(x) = a02 + n=1 [ an cos(nx) + bn sin(nx) ]

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. That makes the tool flexible: it can analyze many expressions that are awkward to integrate by hand, while still preserving the standard Fourier-series interpretation you would use in class or in engineering practice.

How This Fourier Series Calculator Works

The tool expects an input function f(x) defined on [−π, π] using math.js-style syntax with explicit multiplication, such as x^2, abs(x), or sin(3*x) + 0.5*cos(2*x). After you submit the form, the script samples the function at many points between −π and π and uses numerical integration to estimate each coefficient. Specifically, it applies Simpson’s rule on a fine grid to approximate the area in the coefficient formulas above.

That process matters because the reported table is not a symbolic derivation: it is a numerical approximation to the true Fourier coefficients. For smooth, well-behaved functions, the approximation is typically very good. For functions with sharp corners, jumps, or expressions that become undefined at some points, the calculator can still be useful, but the results deserve more care. In those cases the coefficient table becomes a numerical guide to the harmonic structure rather than a proof of an exact closed form.

  1. It samples f(x) at many points between −π and π.
  2. It uses numerical integration to approximate a₀, aₙ, and bₙ.
  3. It computes the truncated series up to the chosen order N.
  4. It outputs the coefficient table so you can inspect the harmonic content directly.

Numerical integration trades exact symbolic formulas for speed and flexibility. You can use many functions that the parser can evaluate, including ones without convenient antiderivatives, and still get a meaningful coefficient table.

How to Use the Fourier Series Calculator

Using the tool is straightforward once you know what each input controls. First, enter the expression for one period of your function on [−π, π]. Then choose the highest harmonic index N that you want to keep. A small N gives a rough approximation quickly. A larger N includes more detail, but it also makes the partial sum more sensitive to numerical error and to the non-smooth features of your function.

  1. Enter the function f(x). Use valid syntax with explicit multiplication. Examples that typically work are:
    • x^2
    • abs(x)
    • sin(3*x) + 0.5*cos(2*x)
  2. Choose the number of terms N. This is the highest harmonic index kept in the truncated series. Typical choices are N = 3–5 for a quick sketch, N = 10–20 for a substantially better approximation of many functions, and larger values only when you understand the numerical trade-offs.
  3. Run the calculation. Click the compute button to evaluate the integrals and assemble the coefficient table.
  4. Read the coefficients. The first row gives a₀/2, the average level of the periodic extension. Each later row lists the cosine coefficient aₙ and sine coefficient bₙ for that harmonic.

The output is especially useful when you want to compare hand work with a numerical check, guess the symmetry of a function from the coefficients, or see how many harmonics are needed before the dominant shape is captured. If a few low-order coefficients are much larger than the rest, the waveform is largely controlled by those harmonics. If substantial weight remains at high n, the function has sharper features or a more demanding shape.

Interpreting Results and Harmonics

Each coefficient corresponds to a specific frequency component. The constant term a₀/2 is the average value over one full period. The coefficients with n = 1 belong to the fundamental frequency. Terms with n ≥ 2 are higher harmonics, meaning oscillations at integer multiples of the fundamental frequency. When those higher harmonics stay small, the function is comparatively smooth. When they remain large, the waveform contains sharper structure.

  • n = 0: a₀/2 is the average value, often called the DC component.
  • n = 1: a₁ and b₁ describe the fundamental oscillation.
  • n ≥ 2: Higher harmonics add increasingly fine detail.

Symmetry is one of the fastest ways to predict what the table should look like:

  • If f(x) is even, then all sine terms vanish and bₙ = 0 for every n.
  • If f(x) is odd, then a₀ = 0 and all cosine terms vanish, so the series contains only sines.

This is why the coefficient table is more than a list of numbers. It acts like a diagnostic report. A nearly zero sine column suggests even symmetry. A nearly zero cosine column suggests odd symmetry. Alternating signs or slowly decaying magnitudes often reveal corners, jumps, or other non-smooth behavior. As N increases, the partial sum SN(x) generally converges to the original function at points of continuity and to the midpoint of the left and right limits at jump discontinuities.

Worked Example: f(x) = |x| on [−π, π]

Consider f(x) = |x| on [−π, π]. This is a good demonstration because the function is easy to picture and its symmetry immediately tells you what to expect. Since |x| is even, the Fourier series should contain only cosine terms. In the calculator you can type abs(x), choose N = 10, and compute the table. The sine coefficients should come out very close to zero, with only tiny numerical noise remaining.

  1. Enter abs(x) in the function field.
  2. Set the number of terms to N = 10.
  3. Compute the series and inspect the rows for n = 1 through 10.

The resulting truncated series has the form

SN(x) = a₀/2 + Σn=1N aₙ cos(nx),

with decreasing cosine coefficients as n grows. Even a modest number of terms reproduces the familiar V-shape surprisingly well. The approximation is usually strongest away from the endpoints and around regions where the function is smooth. Near the sharp corner at x = 0, the partial sums can show small ripples. That is not a bug in the calculator. It reflects the broader behavior of Fourier approximations near non-smooth features.

Comparison: Different Function Types

The size and decay of the coefficients depend strongly on the type of function you enter. Smooth periodic functions usually have coefficients that decay quickly, so a small number of terms already gives an excellent approximation. Piecewise smooth functions with corners decay more slowly. Functions with jump discontinuities decay slower still, and the resulting partial sums can show visible overshoot near the jumps.

Typical convergence patterns for common function families
Function type Symmetry Nonzero coefficients Typical coefficient decay Qualitative behavior of SN(x)
Smooth, for example sin(x) Depends on example Both aₙ and bₙ may appear Often faster than 1/n² Rapid convergence; small N often gives high accuracy
Piecewise smooth with corners, for example |x| Even or odd possible Often one family dominates About 1/n² Good convergence with visible ripples near non-smooth points
Functions with jumps, for example a square wave Often odd or even when centered Usually one family dominates About 1/n Persistent overshoot near jumps, known as Gibbs phenomenon

That comparison gives you a practical reading strategy. After you compute the coefficients, look not only at whether they are positive or negative, but also at how quickly their magnitudes drop as n increases. The rate of decay tells you a great deal about how smooth the original function is.

Applications and Typical Use Cases

This calculator is useful for students, instructors, and engineers who want a quick numerical view of harmonic structure. In coursework, it can verify hand calculations, expose symmetry arguments, and show how a partial sum improves when N increases. In technical work, it can provide a fast first look at a custom periodic waveform before you move on to plotting, filtering, or simulation in a more specialized environment.

  • Verify hand-computed Fourier coefficients.
  • Explore how the truncated series changes with N.
  • Analyze the harmonic content of a custom waveform.
  • Generate coefficient tables for coding exercises or numerical experiments.

Common application areas include signal processing, vibration analysis, acoustics, heat flow in periodic settings, and any problem where repeating behavior is easier to study in the frequency domain than directly in the original function.

Assumptions and Limitations

To use the result responsibly, keep several assumptions in mind. The method assumes the function on [−π, π] is extended periodically with period 2π. In other words, the calculator treats the interval you entered as one full repeating cycle. If that is not the physical period you intended, the coefficients will still be mathematically correct for the interpreted period, but they may not match your real-world setup.

  • Periodicity: The function is interpreted as 2π-periodic.
  • Function behavior: The numerical integration works best for bounded, reasonably well-behaved inputs.
  • Truncation order N: Very large N increases run time and can amplify numerical noise.
  • Gibbs phenomenon: Jumps and sharp corners can produce overshoot and ringing in partial sums.
  • Numerical approximation: Simpson’s rule is accurate for many cases but does not guarantee exact symbolic coefficients.
  • Input syntax: Use valid parser syntax with explicit multiplication such as 2*x.
  • Educational scope: The tool is excellent for learning and exploration, but critical design work should be checked with more specialized analysis.

Once you keep those assumptions in view, the calculator becomes much easier to trust and to interpret. The coefficient table is not merely decorative output. It is a compact summary of how a periodic function distributes its energy across harmonics, and that is why Fourier series remain so valuable in mathematics, science, and engineering.

Enter a function on [−π, π] using explicit multiplication, then choose how many harmonics to keep in the partial sum.

Useful test inputs: x^2, abs(x), sign(x), and sin(3*x) + 0.5*cos(2*x).

Enter a function and order.

Mini-Game: Harmonic Match

This optional canvas mini-game turns the same idea behind the calculator into a fast visual challenge. A gold target waveform appears on the screen, and your blue partial sum starts with only the average level locked in. Three harmonic cards then appear at a time. Tap or click the one that best reduces the residual between the current approximation and the target. Correct picks build the waveform, increase your streak, and raise the match percentage. Wrong picks cost time and score. If you have entered a valid function above, the first round tries to use the harmonic fingerprint of that function, so the game feels directly connected to the calculator rather than bolted on as a generic extra.

Score0
Time75s
Streak0
Match0%
Wave1

Click to play Harmonic Match

Build a Fourier approximation by choosing the term card that best reduces the gap between the gold target wave and the blue partial sum. Tap a card or press 1, 2, or 3. Good picks raise your streak; bad picks add ripple pressure and cost time. Runs last 75 seconds.

Best score: 0

How it connects to the calculator: the game asks you to choose Fourier terms that improve a partial sum, which is the same harmonic logic used by the coefficient table above. The game is optional and does not change the calculator result.

Embed this calculator

Copy and paste the HTML below to add the Fourier Series Calculator – Compute Truncated Series on [−π, π] to your website.