A Byte of PhysicsLogo

Fourier series

A periodic signal can be represented by a sum of harmonics. Each coefficient is data describing how much of one basis oscillation contributes. A finite program never stores an infinite series: it chooses a harmonic limit, records the omitted content as approximation error, and makes that quality setting visible.

Think like a programmer

Store cosine and sine coefficients in arrays indexed by harmonic number, with one declared period and phase convention. Reconstruct into a new sample array; never overwrite the input while fitting or summing. Treat harmonic count as an explicit quality setting, then calculate a maximum or RMS error against target samples rather than deciding by eye that the plot looks close.

Model checklist

Inputs
Period, target samples or coefficient formula, harmonic limit, sample positions, phase convention, and normalization.
State
Cosine and sine coefficient arrays, reconstructed samples, residual samples, and error metrics.
Rule
Add each retained harmonic to a fresh reconstruction array.
Output
Periodic approximation, residual, dominant harmonic list, and documented error.
Check
A pure harmonic uses only its corresponding coefficient under the declared convention; reconstruction uses no coefficients above the limit; increasing the limit improves a stated error metric for a fixed smooth target.
\[f(x)=a_0+\sum_{n=1}^{\infty}\left(a_n\cos nx+b_n\sin nx\right)\]

The constant term sets an offset. Each harmonic number n repeats n times per fundamental period, so coefficient array index is physical structure as well as implementation detail. A pure bin-aligned sampled sine is a compact fixture: its spectrum contains its paired frequency bins, and the corresponding series reconstruction needs only that harmonic after the convention is accounted for.

Discrete spectrum inspector

Choose a bin-aligned sine wave with 16 samples. The bars are DFT magnitudes; a real sine has matching positive- and negative-frequency bins.

DFT magnitude at each bin
Zero magnitude reference

Input sine bin 2; dominant DFT bins 2 and 14, each magnitude 8.0. All other ideal bins are zero up to floating-point error.

The textual result names the input and dominant bins. The bars are only a visualization of the computed DFT magnitudes.

For a square-like target, adding odd harmonics sharpens its transitions, but finite truncation produces ringing near discontinuities. That overshoot is not automatically a bug: it is a known limit of representing a jump with smooth finite basis functions. The bug would be hiding the harmonic limit, changing the period between fit and reconstruction, or reporting only a rendered curve without a residual array.

Try this experiment

Prediction: Raising the harmonic limit improves a periodic square-like approximation away from its discontinuities, while overshoot remains near each jump.

Choose limits 1, 3, and 9; specify whether only odd harmonics are present; and define RMS residual over a fixed sample grid. Then give a pure-sine fixture and name the exact coefficient index that should dominate.

Where this model breaks

Discontinuities produce overshoot near edges, and a finite series cannot exactly reproduce all sharp features at every point. Sample positions, fitted coefficient method, windowing, period mismatch, and normalization affect results. Nonperiodic finite records need a different boundary interpretation, while aliasing prevents a sampled series from representing frequencies above its resolvable range.

Summary

Fourier series turn periodic shape into finite coefficient data with an intentional approximation limit. Preserve the period and convention, reconstruct separately, measure residuals, and explain ringing instead of presenting it as unexplained simulation behavior.

Glossary

Self-check

  1. What does a coefficient-array index encode?
  2. What changes when harmonic count rises?
  3. Why can overshoot remain near a discontinuity?
  4. How should approximation quality be measured?

Sources

Model contract

Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.

\[\text{observable output} = f(\text{inputs},\,\text{state})\]
Inputs
Quantities you set or measure, with units and useful bounds.
State
Values the program must retain to reproduce the next result.
Rule
The relationship or update that turns inputs and state into a result.
Check
A known limit, unit check, invariant, or measured result that can expose a bad model.

Implement the idea as a model

For Fourier Series, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Waves II — Analysis and Transformations, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.

Guided experiment

Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.

Where this model breaks

This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.

Summary

Treat Fourier Series as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.

Glossary

  • Input: a measured value or chosen parameter supplied to a model.
  • State: the smallest set of values needed to continue or reproduce a model.
  • Validation: comparing an output with a known result, limit, invariant, or measurement.

Self-check

  1. Which values are inputs, and which values must remain state?
  2. What observable result would tell you the model is behaving as expected?
  3. Which assumption would you test first before applying the model to a real system?

Model review: turn Fourier Series into a test

Represent periodic signals as harmonic coefficient arrays and measure finite reconstruction error.

  1. Name the inputs and units that the waves ii — analysis and transformations model needs.
  2. Separate the state you must keep from values you can calculate when needed.
  3. Write one rule that maps the current state and inputs to an observable result.
  4. Choose a limiting case, unit check, invariant, or known result before trusting an output.
  5. State one assumption you would change before using this simplified model for a real decision.

Share to: