Fourier Series of a Sawtooth Wave

Consider the $2\pi$-periodic extension of $f(x)=x$ on $-\pi<x<\pi$. Its Fourier series is

$$ f(x)\sim \frac{a_0}{2} +\sum_{k=1}^{\infty}a_k\cos(kx) +\sum_{k=1}^{\infty}b_k\sin(kx). $$

Egison symbolically evaluates the coefficient integrals and builds the first terms of the series.

Symbolic antiderivatives

The coefficients use

$$ a_k=\frac1\pi\int_{-\pi}^{\pi}x\cos(kx)\,dx, \qquad b_k=\frac1\pi\int_{-\pi}^{\pi}x\sin(kx)\,dx. $$

Integration by parts gives explicit primitives for $x\cos(kx)$ and $x\sin(kx)$. We define those formulas directly, keeping the notebook independent of optional integration libraries.

declare symbol x, n : MathValue

def f (x : MathValue) : MathValue := x

def cosinePrimitive (k : MathValue) : MathValue :=
  x * sin (k * x) / k + cos (k * x) / k^2

def sinePrimitive (k : MathValue) : MathValue :=
  (- x) * cos (k * x) / k + sin (k * x) / k^2
sinePrimitive n
$-\cos(n x) n^{-1} x + \sin(n x) n^{-2}$

Fourier coefficients

The sawtooth is odd, so every cosine coefficient is zero. The sine coefficients are $b_k=2(-1)^{k+1}/k$.

def cosineCoefficients : [MathValue] :=
  map
    (\k ->
      let primitive := cosinePrimitive k
       in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)
    nats

def sineCoefficients : [MathValue] :=
  map
    (\k ->
      let primitive := sinePrimitive k
       in (substitute [(x, π)] primitive - substitute [(x, - π)] primitive) / π)
    nats
take 10 cosineCoefficients
$\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\}$
take 10 sineCoefficients
$\{2, -1, \frac{2}{3}, \frac{-1}{2}, \frac{2}{5}, \frac{-1}{3}, \frac{2}{7}, \frac{-1}{4}, \frac{2}{9}, \frac{-1}{5}\}$

Reconstructing the series

Multiplying each $b_k$ by $\sin(kx)$ gives the successive Fourier terms.

def fourierTerms : [MathValue] :=
  map (\(k, b) -> b * sin (k * x)) (zip nats sineCoefficients)
take 10 fourierTerms
$\{2 \sin(x), -\sin(2 x), \frac{2}{3} \sin(3 x), \frac{-1}{2} \sin(4 x), \frac{2}{5} \sin(5 x), \frac{-1}{3} \sin(6 x), \frac{2}{7} \sin(7 x), \frac{-1}{4} \sin(8 x), \frac{2}{9} \sin(9 x), \frac{-1}{5} \sin(10 x)\}$

Thus

$$ x=2\sum_{k=1}^{\infty}\frac{(-1)^{k+1}}{k}\sin(kx) \qquad(-\pi<x<\pi). $$

The separate parity and coefficient cells make clear why no cosine terms survive.

Links

Back to the Table of Contents