Fourier Series Calculator

Enter a periodic function or up to five pieces to calculate Fourier coefficients, inspect the partial sum, and compare the reconstruction.

Function over one period

a and b use your x unit; trigonometric arguments are in radians. The period is T = b − a.

Function pieces

Use x, pi, e, + − * / ^, parentheses, sin, cos, tan, exp, ln, log, sqrt, abs, min and max. Multiplication may be written as 2*x or 2x.

Examples

Series and precision

Whole number from 1 to 30.
Even number from 200 to 4000; the stability check repeats at double this resolution.
Optional; uses the same x unit as the period.

Fourier reconstruction

Partial sum

Coefficients

naₙbₙAmplitude

Formula and substitution

SN(x) = a₀/2 + Σ [aₙ cos(nω₀x) + bₙ sin(nω₀x)]

a₀ = (2/T) ∫ f(x) dx

aₙ = (2/T) ∫ f(x) cos(nω₀x) dx

bₙ = (2/T) ∫ f(x) sin(nω₀x) dx

Edit the example, then calculate the series.

Your expressions and calculations stay in this browser and are never uploaded.

FAQ

Which Fourier coefficient convention does this calculator use?

It writes f(x) ≈ a₀/2 + Σ[aₙ cos(nω₀x) + bₙ sin(nω₀x)], with ω₀ = 2π/T. Accordingly, a₀, aₙ and bₙ all use the factor 2/T. Some books put the mean directly in a₀ instead; compare the displayed formula before matching coefficients.

Are the coefficients exact?

No. They are numerical integrals from the composite Simpson rule. The calculator repeats the work at twice the selected resolution and reports the largest coefficient change. A small change supports the displayed digits but is not a formal error bound.

Why does the graph ripple near a jump?

A finite Fourier sum oscillates near a discontinuity. Adding harmonics narrows the affected region but does not remove the characteristic Gibbs overshoot. At the jump, the series approaches the average of the left and right limits under the usual convergence conditions.

Decomposing Periodic Functions into Fourier Series

A Fourier series decomposes a periodic function into an infinite sum of sines and cosines. This mathematical framework allows engineers, students, and math practitioners to analyze the frequency components of complex waveforms.

The Fourier Series Calculator provides a practical environment to compute these coefficients, inspect the resulting partial sum, and visualize the reconstruction of periodic or piecewise functions. By entering a function over a single period or defining it using up to five separate pieces, you can immediately see how sinusoidal components combine to approximate the original waveform.

The Mathematics of Fourier Coefficients

The calculator represents periodic functions using a specific mathematical convention:

f(x) ≈ a₀ / 2 + Σₙ₌₁^N [ aₙ cos(nω₀ x) + bₙ sin(nω₀ x) ]

where the fundamental frequency is defined as ω₀ = 2π/T. Under this convention, the constant term and the harmonic coefficients all utilize the integration factor 2/T:

  • Constant Term (a₀): Calculated via a₀ = 2 / T∫ f(x)dx. The actual constant term added to the series is a₀/2.
  • Cosine Coefficients (aₙ): Represent the amplitudes of the cosine terms.
  • Sine Coefficients (bₙ): Represent the amplitudes of the sine terms.

Different textbook conventions handle the constant term differently. Some textbooks define the constant term directly as a₀ (using an integration factor of 1/T), which changes how the final series is written. It is important to compare the displayed formula in the calculator with your reference material to ensure the coefficients match your expected convention.

Defining Piecewise Functions and Periods

Physical signals in the real world—such as square, triangle, and sawtooth waves—are often represented mathematically as piecewise functions over a single period. The calculator allows you to define these waveforms using two primary input modes:

  1. Function over one period: A single mathematical expression spanning the entire interval.
  2. Function pieces: Up to five separate segments to define complex piecewise functions. You can add segments using "Add piece" or remove them using "Remove piece ‹n›".

Boundary and Expression Rules

For each piece, you must define the boundaries using the "from" and "to" inputs. The mathematical expression $f(x)$ accepts variables, constants, and operators including x, pi, e, +, , *, /, ^, parentheses, sin, cos, tan, exp, ln, log, sqrt, abs, min, and max. Multiplication can be written explicitly (e.g., 2*x) or implicitly (e.g., 2x).

The period of the function is defined by the boundaries "Start a" and "End b", where the total period is calculated as T = b - a. Trigonometric arguments are evaluated in radians, and the boundary limits a and b must use the same unit as the variable x.

Numerical Integration and Stability via Simpson's Rule

Because analytical integration is not always feasible for arbitrary or highly complex piecewise functions, the calculator computes the Fourier coefficients numerically. It utilizes the composite Simpson rule, which approximates continuous integrals using discrete subintervals.

Precision Settings

  • Harmonics N: A whole number from 1 to 30 that determines how many terms are calculated for the partial sum.
  • Simpson subintervals: An even number from 200 to 4000. Higher values increase the resolution of the numerical integration at the expense of calculation time.
  • Displayed decimals: Controls the precision of the numerical values shown in the output tables.

The Stability Check

To ensure the numerical integration is reliable, the calculator automatically performs a stability check. It repeats the entire integration process at double the selected Simpson subintervals resolution. The tool then compares the two sets of results and reports the maximum coefficient change as ‹delta›.

If the integration is stable, the tool displays the status: *"Calculated. The doubled-resolution coefficient check is stable at the displayed precision."*If the coefficients change significantly when the resolution doubles, it displays a warning: "Calculated, but coefficients changed by ‹delta› when the integration resolution doubled. Increase the subintervals or inspect the function for sharp features."

The Gibbs Phenomenon and Discontinuities

When approximating functions with sharp transitions or jump discontinuities (such as a square wave), the reconstructed Fourier series exhibits distinct ripples and overshoots near the boundaries. This mathematical behavior is known as the Gibbs phenomenon.

Typical Gibbs Phenomenon at a Jump Discontinuity:

   f(x) Value
     ^
     |      / \   / \
  1  +-----+   \_/   \             <-- Fourier approximation S_n(x) ripples
     |                \
     |                 +-------+   <-- Original piecewise function f(x)
  0  +-------------------------+---> x
    a                         b

Increasing the number of harmonics (N) narrows the width of these oscillatory ripples, but it does not eliminate the peak amplitude of the overshoot. Under normal convergence conditions, the Fourier series at a jump discontinuity converges to the average of the left-hand and right-hand limits of the function. When the calculator detects a jump between pieces, it displays the status: "The pieces have a jump. Ripples near the boundary can be Gibbs behavior rather than an integration error."

Troubleshooting and Error Messages

If the calculator encounters mathematical or input errors during computation, it will display one of the following error messages:

Error Message Cause
"Check the expression syntax." The mathematical expression contains unbalanced parentheses, unrecognized operators, or typos.
"The function leaves the real-number domain inside this period." The expression results in complex numbers (e.g., taking the square root of a negative number or the logarithm of a negative number).
"The function divides by zero inside this period." The expression attempts to divide by zero at one or more points where a ≤ x ≤ b.
"The function or a coefficient exceeds the supported number range." The calculated values or intermediate integration steps exceed standard numerical limits.
"Check the period, harmonics and precision ranges." The inputs for a, b, N, or the Simpson subintervals fall outside their allowed boundaries.
"Check the function pieces and their boundaries." The defined pieces overlap, contain gaps, or have invalid boundary limits.

Frequently Asked Questions

Which Fourier coefficient convention does this calculator use?

It writes f(x) ≈ a₀/2 + Σ [aₙ cos(nω₀ x) + bₙ sin(nω₀ x)], with ω₀ = 2π/T. Accordingly, a₀, aₙ and bₙ all use the factor 2/T. Some books put the mean directly in a₀ instead; compare the displayed formula before matching coefficients.

Are the coefficients exact?

No. They are numerical integrals from the composite Simpson rule. The calculator repeats the work at twice the selected resolution and reports the largest coefficient change. A small change supports the displayed digits but is not a formal error bound.

Why does the graph ripple near a jump?

A finite Fourier sum oscillates near a discontinuity. Adding harmonics narrows the affected region but does not remove the characteristic Gibbs overshoot. At the jump, the series approaches the average of the left and right limits under the usual convergence conditions.

Where are my calculation inputs processed?

Your expressions and calculations stay in this browser and are never uploaded. All processing occurs locally on your device.