A common method for simplifying complex functions around a given point is to expand them into power series, with the Taylor series being one of the most well-known. The more terms that are computed, the more accurate the approximation becomes.
Another important tool, especially for analyzing periodic functions, is the Fourier series, named after the French mathematician Joseph Fourier. Without going into a formal proof, we can state that a function $f$ can be approximated as a sum of harmonic oscillations:
$$
f(x) \approx \frac{a_0}{2} + a_1 \cos(x) + a_2 \cos(2x) + \dots + b_1 \sin(x) + b_2 \sin(2x) + \dots
$$
Using summation notation, this can be written more compactly as:
$$
f(x) \approx \frac{a_0}{2} + \sum_{n=1}^{N} \left( a_n \cos(nx) + b_n \sin(nx) \right)
$$
In the limit $N \to \infty$, the Fourier series would reproduce the original function exactly. In practice, the series is truncated after a finite number of terms $N$, where $N$ is chosen as large as feasible. This gives a powerful way to approximate any function by a fundamental frequency and a set of harmonics.
Before applying this to an example, we must define how to compute the coefficients of the series. Given the properties of the sine and cosine functions, the coefficients are typically defined using integrals over the interval $[-\pi, \pi]$. The integral over all sine and cosine terms vanishes due to orthogonality, leaving only:
$$
a_0 = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x)\, \mathrm{d}x
$$
This normalizes the constant term. The remaining coefficients are:
$$
a_n = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos(nx)\, \mathrm{d}x
$$
$$
b_n = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin(nx)\, \mathrm{d}x
$$
Rectangular (Step) Function
We now demonstrate the calculation of a Fourier series using a periodic rectangular function (or step function) defined as:
$$
f(x) =
\begin{cases}
0 & \text{for } -\pi \leq x \leq 0 \\
1 & \text{for } 0 \leq x \leq \pi
\end{cases}
$$
Before computing the coefficients, we can simplify the function by shifting it downward by 1/2, making it antisymmetric. In this case, the constant term becomes $a_0 = 1$, and all other cosine coefficients $a_n$ vanish.
Calculating the sine coefficients using the formula for $b_n$ gives:
$$
b_n = \frac{1 - (-1)^n}{\pi n}
$$
Therefore, the Fourier series up to term $N$ becomes:
$$
f(x) = \frac{1}{2} + \sum_{n=1}^{N} \left( \frac{1 - (-1)^n}{\pi n} \right) \sin(n x)
$$
This approximation already closely matches the original function with just a few terms. However, at the edges, we observe overshoots—known as the Gibbs phenomenon—which always appear when only a finite number of terms are used. These overshoots cannot be reduced below approximately 10%, no matter how many terms are included.
Spectral Form
Since sine and cosine differ only by a 90° phase shift, the Fourier series can also be written in spectral form as:
$$
f(x) \approx \frac{A_0}{2} + \sum_{n=1}^{N} A_n \cos(nx - \varphi_n)
$$
The new amplitudes $A_n$ are computed using the Pythagorean theorem:
$$
A_n = \sqrt{a_n^2 + b_n^2}
$$
This allows the function to be described in terms of its frequency spectrum, i.e., the amplitude of each contributing frequency. For the step function, the amplitudes decrease in inverse proportion to $n$, as derived above.
Fourier Transform and FFT
Using complex numbers, the Fourier series can be extended to non-periodic functions. This leads to the Fourier transform, which enables the analysis of general signals.
Today, many algorithms exist for performing spectral analysis of signals in near real time. The most widely used algorithm is the Fast Fourier Transform (FFT), which is available in many programming languages.
This enables applications such as frequency analysis in electroencephalography (EEG), where changing electrical potentials in the brain are recorded. The amplitude distribution across frequencies can, for example, be used to study the effects of medication.
Other applications of Fourier analysis include image processing in CT (computed tomography) and MRI (magnetic resonance imaging). However, correctly applying FFT requires some background in systems theory, with key concepts such as padding and mean correction playing important roles.