Advanced maths

Fourier series coefficients calculator for a piecewise function

Find continuous sine and cosine Fourier coefficients for a finite piecewise polynomial on a declared period, then plot a truncated series.

Your numbers

One row per piece: lower, upper, c0, c1, ... for c0+c1·x+…. Use 1–5 nonoverlapping intervals within ±100, degree at most six. Fractions or decimals with at most six places; gaps and outside values are zero.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A Fourier series represents the periodic extension of one interval using sine and cosine harmonics. This calculator accepts finite polynomial pieces within a declared period, takes missing subintervals as zero and calculates continuous Fourier coefficients. It reports the constant term, the retained coefficient pairs and the partial sum at a query coordinate. The graph displays the finite harmonic approximation over one period, not a claim that a discontinuous input has become continuous.

THE FORMULAS_N(x)=a0/2+Σ[a_n cos(nωx)+b_n sin(nωx)], ω=2π/T; a_n=(2/T)∫f cos(nωx), b_n=(2/T)∫f sin(nωx).

A worked example

For period [−1,1], take f(x)=−1 on [−1,0] and +1 on [0,1]. Odd symmetry makes a0 and every cosine coefficient zero. The sine coefficient is 4/(nπ) for odd n and zero for even n. With N=5 at x=1/2, the partial sum is (4/π)(1−1/3+1/5)=52/(15π)≈1.10347427. The overshoot above one is a truncation effect, rather than proof that the input exceeds one.

Good to know

Supports 1–5 polynomial pieces of degree at most six, entirely inside a period within ±100 and of width at least 10⁻⁴. Piece entries use exact fractions or at most six decimal places; period endpoints are numeric. Retains 1–30 positive harmonics. The constant integral is exact before conversion; other coefficients use bounded adaptive quadrature. Sampled quadrature estimates are not certified bounds. No DFT, automatic period discovery or infinite-series convergence certificate is provided.

The interval length sets frequency; its left endpoint does not reset phase

The form uses cos(nωx) and sin(nωx) with the original coordinate x. Moving a pulse within a fixed period generally changes both coefficient families. It is not equivalent to silently substituting x minus the left endpoint. A constant function still has only its constant term, but an off-center pulse need not keep the symmetry of a centered pulse. To compare another implementation, first check whether its basis is written in x or in a shifted coordinate.

For the default two-unit square wave, the first five positive harmonic positions include three nonzero sine terms. At x=1/2 their contributions alternate in sign, yielding 52/(15π). At the jump x=0 all the sine terms vanish, so every finite partial sum shown here is zero there. Changing a single endpoint value in the piecewise definition cannot change these integral coefficients. The graph is deliberately labeled as the truncated series to keep that distinction visible.

Five positive harmonic positions give a square-wave partial sum that overshoots its plateau−101S5(1/2) ≈ 1.1035
The dashed segments show the period-two input at −1 and +1. The solid line is the N=5 Fourier partial sum, with nonzero sine terms at n=1,3,5. At x=1/2 it equals 52/(15π), about 1.10347427. At the jump x=0 it is zero.

The Continuous convolution calculator for piecewise functions instead combines two finite-support functions over the real line, without repeating their inputs periodically.

A small coefficient integration estimate does not measure Fourier truncation error

The engine integrates each supplied polynomial piece separately, so known jump locations are not hidden inside one adaptive integration interval. A numerical estimate accompanies the coefficient quadrature. It concerns the sampled integration procedure and can miss behavior not resolved by its evaluations; it does not certify every possible input. Increasing the harmonic count asks for additional integrals and more computation. It is not a tolerance control for the existing coefficients.

The difference between the original periodic function and a finite partial sum is a separate issue. A smooth input and a discontinuous input can respond very differently to the same harmonic count. In the square-wave example the local overshoot remains noticeable even when the broad plateau looks close. Use the coefficient table to inspect symmetry and decay, and the graph to inspect the chosen approximation. A continuous-series coefficient is not a sample-bin magnitude, so a finite-sample transform cannot be substituted without explaining the sampling and normalization.

A few questions, answered

What happens if my pieces do not fill the period?

All unentered portions of the declared period are zero. The page then repeats that complete zero-filled interval periodically; it does not extend the nearest polynomial across a gap.

Does the query need to lie inside the displayed period?

No. The finite series is periodic and accepts query coordinates within ±10⁶. Numerical phase reduction is used, but decimal endpoint and coordinate rounding can still matter for extremely short periods.

Find your calculator

Start typing to explore the library.