Fourier Series

Overview

The Fourier series
{% f(x) \approx \frac{a_0}{2} + \sum_{i=1} ^n (a_n cos \frac{n \pi x}{c} + b_n sin \frac{n \pi x}{c}) %}
converges under a fairly broad set of conditions. Therefore, taking the first {% n %} terms is often used to approximate the target function.

The following demonstrates approximating the function {% f(x) = x^2 %} using the first {% n %} Fourier terms. Moving the slider changes the number of terms taken. (from 0 to 10)

Formal Proof

For an outline of the proof steps to show that a Fourier decomposition converges to the decomposed vector, see Fourier Outline

Implementation

As an example, once one has computed the first 3 cosine coefficients, once could write a function that approximates the target function as follows.

def approx(x): return 0.5 * a0 + a1 * math.cos(x) + a2 * math.cos(2*x);


Then, we can chart the results by creating a set of samples as in the following.

from davinci.python import _from samples = [ {'x':p,'y':approx(p)} for p in _from(-1*math.pi, math.pi, 1000) ]