Skip to main content

Section 25.2 Fourier series

Using the period \(T=1\text{,}\) we find that the functions \(f_k(x) = \exp (2\pi i k x)\) are orthonormal with respect to the inner product

\begin{equation} \langle f, g \rangle = \int_0^1 f(x)\overline{g(x)}\,dx\label{eq-inner-product}\tag{25.2.1} \end{equation}

(For other periods they are orthogonal but not orthonormal.) This makes it easy to compute the Fourier coefficients of a given function \(f\) in the basis \(\{f_k\colon k\in \mathbb Z\}\text{:}\)

\begin{equation} c_k = \langle f, f_k\rangle = \int_0^1 f(x) e^{-2\pi i k x}\,dx\label{eq-fourier-coefficients}\tag{25.2.2} \end{equation}

For sufficiently nice periodic functions (having a continuous derivative is enough), the Fourier series \(\sum c_k f_k\) converges to function \(f\text{.}\)

Use the built-in command integral to compute the Fourier coefficients \(c_k\) for \(k=-3, \dots, 3\) for the complex-valued function

\begin{equation*} f(x) = \sqrt{1+\cos(2\pi x)} + i\log(2+\sin(2\pi x)) \end{equation*}

Then plot both the function and its partial Fourier sum \(\sum_{|k|\le 3} c_k f_k\) for comparison.

Answer

The syntax of integral is integral(@(x) ..., a, b) where \(a, b\) are the limits of integration and the function is expressed in a form that allows vectorized evaluation. Here is the computation of Fourier coefficient

f = @(x) sqrt(1 + cos(2*pi*x)) + 1i*log(2 + sin(2*pi*x));
n = 3;
c = zeros(1, 2*n+1);
for k = -n:n
    c(k+n+1) = integral(@(x) f(x).*exp(-2*pi*1i*k*x), 0, 1);
end
disp(c)

Then we combine both complex plots using different colors.

t = linspace(0, 1, 1000);
k = -n:n;
p = c*exp(2*pi*1i*k'*t);
hold on
plot(f(t))
plot(p, 'r')
hold off

Note that the lack of smoothness at one point slows down the convergence of Fourier series. If the function had sqrt(1.1 + cos(2*pi*x)) instead, the convergence would be much better.