Fourier Analysis · Fourier series

Fourier series

A Fourier series writes a periodic function as a sum of sines and cosines, a₀/2 + Σ (aₖ cos kx + bₖ sin kx). Each coefficient is measured on its own: multiply the function by one wave and take the area.

Fourier series in this visualization

The top plot draws a function ff of period 2π2\pi in ink and its partial sum SNS_N in yellow: the constant term and every cosine and sine up to frequency NN. The strip below multiplies ff by one probe wave and shades the signed area between the product and the axis. The bottom strip lays out the coefficients found this way, cosines above and sines below.

Each coefficient is an area
ak=1π∫−ππf(x)cos⁡kx dx,bk=1π∫−ππf(x)sin⁡kx dxa_k = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cos kx\,dx, \qquad b_k = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\sin kx\,dx

Why does one area pick out one coefficient when ff holds all the waves at once? Over a full period, any two different waves from 1,cos⁡x,sin⁡x,cos⁡2x,sin⁡2x,…1, \cos x, \sin x, \cos 2x, \sin 2x, \dots multiply to a product with zero area, while a sine or cosine times itself has area π\pi. Multiplying a sum of these waves by sin⁡kx\sin kx and integrating therefore removes every term except bksin⁡kxb_k \sin kx and leaves πbk\pi b_k. In the two-sine highlight the strip splits the product in two, and the part with the other frequency cancels itself. The waves behave like perpendicular axes and each coefficient is the projection onto one of them, so adding a term never changes the coefficients already found.

With enough terms, the partial sums overshoot beside a jump. As NN grows, the peak narrows and moves toward the jump, but the overshoot does not vanish: for the square wave the excess tends to about 8.949% of the jump. Each SNS_N is continuous, so it has to cross the jump over a short stretch, and on any interval containing the jump its largest error cannot shrink to 0. Continuity alone does not fix the size: the 8.949% comes from computing the partial sums, and every jump of a piecewise smooth function ends up with the same fraction.

Smoother functions need fewer terms. Here ff means the function repeated forever, so ends at ±π\pm\pi that do not meet are a jump too. Integrating by parts moves the derivative from the wave onto ff and brings out a factor 1/k1/k. Across a jump the first step leaves a boundary term with a factor 1/k1/k: the square wave has bk=4/(kπ)b_k = 4/(k\pi) for odd kk and 0 for even kk. If ff is continuous but its slope jumps, as at the triangle wave's corners, the first step goes through and the second leaves the term, so the coefficients shrink like 1/k21/k^2. On the log scale, compare the bars with the dashed 1/k1/k and 1/k21/k^2 lines.

The energy readout applies the same perpendicularity to squares. The integral of f2f^2 splits into the squares of the coefficients, with no cross terms:1π∫−ππf(x)2 dx=a022+∑k≥1(ak2+bk2).\frac{1}{\pi}\int_{-\pi}^{\pi} f(x)^2\,dx = \frac{a_0^2}{2} + \sum_{k \ge 1} \left(a_k^2 + b_k^2\right).The readout gives the share of this total that SNS_N already holds; the rest is its squared error, measured the same way. For the square wave S1S_1 holds about 81% and S9S_9 about 96%, while the overshoot is still there: a narrow peak adds little area. A partial sum can be close to ff on average and still miss it near a jump.

Things to notice

  • The constant term is written a0/2a_0/2 so that the cosine formula also covers k=0k = 0. The constant probe reads a0/2a_0/2 directly: the mean of ff.
  • Odd functions such as the square wave have only sine terms and even ones such as ∣sin⁡x∣|\sin x| only cosines, so one row of the spectrum stays empty.

Controls

  • Click a bar in the spectrum to move the probe there.
  • Choose Draw and drag across one period of the top plot. Your points are joined by straight segments and repeated on both sides.

Related