Fourier Series


Although there are many methods for signal representations, Fourier analysis involving the resolution of signals into sinusoidal components dominates. Periodic signals occur in a wide range of physical phenomena, a few examples of which are acoustic and electromagnetic waves, periodic vibrations of musical instruments, vertical displacement of a mechanical pendulum, and periodic signals in electrical engineering.

We start with the classical Fourier expansion of a periodic function and then present some important expansions that are widely used in applications. We will assume that all periodic functions have period 2ℓ.

There are two equivalent forms of Fourier series---one is complex form

\begin{equation} \label{EqFourier.1} f(x) \,\sim\, \sum_{k=-\infty}^{\infty} \alpha_k e^{k{\bf j} \pi x/\ell} \end{equation}
where
\begin{equation} \label{EqFourier.2} \alpha_k = \frac{1}{2\ell} \int_{-\ell}^{\ell} f(x)\, e^{-k{\bf j} \pi x/\ell} \,{\text d} x , \qquad k=0, \pm 1, \pm 2, \ldots ; \end{equation}
and another is a trigonometric form

\begin{equation} \label{EqFourier.3} f(x) \,\sim\, \frac{a_0}{2} + \sum_{k=1}^{\infty} \left[ a_k \cos \frac{k \pi x}{\ell} + b_k \sin \frac{k \pi x}{\ell} \right] , \end{equation}
where coefficients are defined according to Euler--Fourier formulas (they were discovered in 1777 by Leonhard Euler many years before Fourier used them in his research):
\begin{align} a_0 &= \frac{1}{\ell} \int_{-\ell}^{\ell} f(x)\,{\text d} x , \notag \\ a_k &= \frac{1}{\ell} \int_{-\ell}^{\ell} f(x)\, \cos \frac{k \pi x}{\ell} \,{\text d} x , \qquad k= 1, 2, 3, \ldots ; \label{EqFourier.4} \\ b_k &= \frac{1}{\ell} \int_{-\ell}^{\ell} f(x)\, \sin \frac{k \pi x}{\ell} \,{\text d} x , \qquad k= 1, 2, 3, \ldots . \notag \end{align}
Sometimes it is convenient to consider a function on interval [0,T]. Let f(x) be a periodic function over the range 0 ≤ x < T. Then its Fourier series becomes
\begin{equation} \label{EqFourier.5} f(x) \,\sim\, \frac{a_0}{2} + \sum_{k\ge 1} \left[ a_k \cos \frac{2k \pi x}{T} + b_k \sin \frac{2k \pi x}{T} \right] , \end{equation}
where coefficients are defined as
\begin{align*} a_k &= \frac{2}{T} \int_{0}^{T} f(x)\, \cos \frac{2k \pi x}{T} \,{\text d} x , \qquad k= 0, 1, 2, 3, \ldots ; \\ b_k &= \frac{2}{T} \int_{0}^{T} f(x)\, \sin \frac{2k \pi x}{T} \,{\text d} x , \qquad k= 1, 2, 3, \ldots . \end{align*}

Example 1: Consider a function f(x) = x² on the interval [0,2]. Its Fourier coefficients can be determined with Mathematica:

Integrate[x^2, {x, 0, 2}]
8/3
Simplify[Integrate[x^2 * Cos[n*Pi*x], {x, 0, 2}], Assumptions -> Element[n, Integers]]
4/(n^2 \[Pi]^2)
Simplify[Integrate[x^2 * Sin[n*Pi*x], {x, 0, 2}], Assumptions -> Element[n, Integers]]
4/(n \[Pi])
Therefore, we get the following Fourier series for function x²:
\[ x^2 = \frac{4}{3} + \sum_{n\ge 1} \left[ \frac{4}{n^2 \pi^2}\,\cos \left( n\pi x \right) - \frac{4}{n\,\pi}\,\sin \left( n\pi x \right) \right] . \]
Next we plot some partial somes along with the given function x²
S10[x_] = 4/3 + Sum[4/n^2/Pi^2 *Cos[n*Pi*x] - 4/n/Pi*Sin[n*Pi*x], {n, 1, 10}];
S20[x_] = 4/3 + Sum[4/n^2/Pi^2 *Cos[n*Pi*x] - 4/n/Pi*Sin[n*Pi*x], {n, 1, 20}];
S100[x_] = 4/3 + Sum[ 4/n^2/Pi^2 *Cos[n*Pi*x] - 4/n/Pi*Sin[n*Pi*x], {n, 1, 100}];
Plot[{x^2, S10[x]}, {x, -0.5, 2.5}, PlotStyle -> {Thick, {Black, Red}}]
Plot[{x^2, S20[x]}, {x, -0.5, 2.5}, PlotStyle -> {Thick, {Black, Orange}}]
Plot[{x^2, S100[x]}, {x, -0.5, 2.5}, PlotStyle -> {Thick, {Black, Blue}}]
   Fourier approximation with 10 terms    Fourier approximation with 20 terms    Fourier approximation with 100 terms
       
Theorem 1: The following formulas could be helpful for Fourier evaluations (\( \texttt{D} = \texttt{D}_t = {\text d}/{\text d}t \) is the derivative operator):
\begin{align*} \int t^n \cos (at) \,{\text d}t &= - \frac{1}{a} \sum_{k=0}^n \frac{1}{a^k} \, {\texttt D}_t^k \left( t^k \right) \left. {\texttt D}_z^{k+1} \left( \cos z \right) \right\vert_{z=at} \\ &= - \frac{1}{a} \left[ t^n {\texttt D}_z \cos z + \frac{n\,t^{n-1}}{a} \, {\texttt D}_z^2 \cos z + \cdots + \frac{n!}{a^n} \, {\texttt D}_z^{n+1} \cos z \right]_{z=at} , \\ \int t^n \sin (at) \,{\text d}t &= - \frac{1}{a} \sum_{k=0}^n \frac{1}{a^k} \, {\texttt D}_t^k \left( t^k \right) \left. {\texttt D}_z^{k+1} \left( \sin z \right) \right\vert_{z=at} \\ &= - \frac{1}{a} \left[ t^n {\texttt D}_z \sin z + \frac{n\,t^{n-1}}{a} \, {\texttt D}_z^2 \sin z + \cdots + \frac{n!}{a^n} \, {\texttt D}_z^{n+1} \sin z \right]_{z=at} .     \end{align*}

The complex Fourier series is more elegant and shorter to write down than the one expressed in term of sines and cosines, but it has the disadvantage that the coefficients might be complex even if the given function is real-valued. The trigonometric form is based on Euler's formulas:

\[ \sin \theta = \frac{1}{2{\bf j}} \,e^{{\bf j}\theta} - \frac{1}{2{\bf j}} \,e^{-{\bf j}\theta} = \Im \,e^{{\bf j}\theta} = \mbox{Im} \,e^{{\bf j}\theta}, \qquad \cos \theta = \frac{1}{2} \,e^{{\bf j}\theta} - \frac{1}{2} \,e^{-{\bf j}\theta} = \Re \,e^{{\bf j}\theta} = \mbox{Re} \,e^{{\bf j}\theta}. \]

Here, j is the unit vector in the positive vertical direction on the complex plane ℂ, so j² = −1. Mathematica has four default commands to calculate Fourier series:

FourierSeries        (* to calculate complex coefficient expansion *)
FourierTrigSeries  (* to calculate standard Fourier expansion via sine and cosine *)
FourierCosSeries (* to calculate cosine Fourier series *)
FourierSinSeries   (* to calculate sine Fourier series *)

 

Sometimes, it is convenient to use polar form:

\begin{equation} \label{EqFourier.6} f(x) \,\sim\, \frac{a_0}{2} + \sum_{k=1}^{\infty} A_k \sin \left( \frac{k \pi x}{\ell} + \phi_k \right) = \frac{a_0}{2} + \sum_{k=1}^{\infty} A_k \cos \left( \frac{k \pi x}{\ell} - \varphi_k \right) , \end{equation}
where \( A_k = \sqrt{a_k^2 + b_k^2} \quad\mbox{and} \quad \varphi_k = \arctan \left( b_k / a_k \right) , \quad \phi_k = \arctan \left( a_k / b_k \right) . \)

In general, a square integrable function f ∈ 𝔏² on the interval [𝑎, b] of length b−𝑎 (b>𝑎) can be expanded into the Fourier series

\begin{equation} \label{EqFourier.7} f(x) \,\sim\, \frac{a_0}{2} + \sum_{k=1}^{\infty} a_k \cos \left( \frac{2x - a -b}{b-a} \right) + b_k \sin \left( \frac{2x - a -b}{b-a} \right) , \end{equation}
where
\begin{align*} a_k &= \frac{2}{b-a} \int_a^b f(x) \,\cos \left( \frac{2x - a -b}{b-a} \right) {\text d}x , \qquad k=0,1,2,\ldots , \\ b_k &= \frac{2}{b-a} \int_a^b f(x) \,\sin \left( \frac{2x - a -b}{b-a} \right) {\text d}x , \qquad k=1,2,\ldots . \end{align*}

For a real-valued periodic function f ∈ 𝔏²(-π,π), the following Parseval identity holds:

\begin{equation} \label{EqFourier.8} \frac{1}{\pi} \int_{-\pi}^{\pi} f^2 (x) \,{\text d}x = \frac{1}{2}\,a_0 + \sum_{k\ge 1} \left( a_k^2 + b_k^2 \right) . \end{equation}
For a complex Fourier series, we have
\begin{equation} \label{EqFourier.9} \frac{1}{2\pi} \int_{-\pi}^{\pi} \left\vert f (x) \right\vert^2 {\text d}x = \sum_{k=-\infty}^{\infty} \left\vert \alpha_k \right\vert^2 . \end{equation}

Before we get into the topic of convergence, we need to define first a couple of terms that we’ll run into in the rest of the section. First, we say that f(x) has a jump discontinuity at x = 𝑎 if the limit of the function from the left, \( \lim_{t\uparrow a} f(t) , \) denoted \( f(a-0) \ \mbox{ or }\ f(a^{-}) \) and the limit of the function from the right, \( \lim_{t\downarrow a} f(t) , \) denoted \( f(a+0) \ \mbox{ or }\ f(a^{+}) , \) both exist and \( f(a+0) \ne f(a-0) . \) A function f(x) is called piecewise continuous on an interval [𝑎, b], if it is continuous on [𝑎, b] except for at most finitely many points \( x_1 , x_2 , \ldots , x_n \) at each of them the function has both the left-hand and right-hand limits: \( f(x_k -0) \ \mbox{ and }\ f(x_k +0) , \quad k=1,2,\ldots , n . \) Now we give the formal definition.

Let 𝑎 and b be real numbers such that 𝑎 < b. A function \( f\, : \, [a,b] \mapsto \,\mathbb{R} \) is said to be piecewise continuous on \( [a,b] \) if the following conditions are satisfied:
  • there exists a finite set \( \{ x_1 , x_2 , \ldots , x_n \} \subset (a, b) \) such that \( x_1 < x_2 < \cdots < x_n \) and f is continuous and monotone on each subinterval
    \[ \left( a , x_1 \right) , \quad \left( x_k , x_{k+1} \right) , \quad k=1,2,\ldots , n-1, \quad \left( x_n , b \right) ; \]
  • all the following one-sided limits exist
    \[ \lim_{x\downarrow a} f \left( x \right) , \quad \lim_{x\uparrow x_k} f\left( x \right) , \quad \lim_{x\downarrow x_k} f\left( x \right) ,\quad k=1,2,\ldots , n-1, \quad \lim_{x \uparrow b} f\left( x \right) . \]
A function \( f\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) is piecewise continuous on \( \mathbb{R} , \) if it is piecewise continuous on every finite subinterval of \( \mathbb{R} . \)

Next, we say that f(x) is piecewise smooth if the function can be broken into distinct pieces and on each piece both the function and its derivative, f'(x), are continuous. A piecewise smooth function may not be continuous everywhere; however, the only discontinuities that are allowed are at a finite number of jump discontinuities. If derivatives in the above condition are replaced by more weak condition so that function f is piecewise monotonic, then such function is said to satisfy the Dirichlet conditions. A function \( f\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) is piecewise smooth on \( \mathbb{R} , \) if it is piecewise smooth on every finite subinterval of \( \mathbb{R} . \) The tangent function is not piecewise smooth because its discontinuity is of infinite jump. On the other hand, the function sin(1/x) is not piecewise continuous because it has infinite number of maxima and minima in the neighborhood of the origin.

Example 2: The function

\[ f(x) = \begin{cases} 2x , & \ \mbox{ if } 0 < x < 1, \\ 1, & \ \mbox{ if } 1 < x < 2, \end{cases} \]
is piecewise smooth on [0,2], but is not continuous on [0,2]. However, \( f(x) = |x|^{1/2} \) is continuous on [-1,1], but is not piecewise smooth on [-1,1].
f[x_]=Piecewise[{{2*x, 0<x<1},{1,1<x<2}}] Integrate[f[x], {x, 0, 2}]
2
Simplify[Integrate[f[x]*Cos[n*Pi*x], {x, 0, 2}], Assumptions -> Element[n, Integers]]
(2 (-1 + (-1)^n))/(n^2 \[Pi]^2)
Simplify[Integrate[f[x]*Sin[n*Pi*x], {x, 0, 2}], Assumptions -> Element[n, Integers]]
-((1 + (-1)^n)/(n \[Pi]))
Therefore, we get the following Fourier series for function x²:
\[ f(x) = 1 + \sum_{n\ge 1} \left[ \frac{(-1)^n -1}{n^2\pi^2 /2} \,\cos \left( n\pi x \right) - \frac{(-1)^n +1}{n\pi} \,\sin \left( n\pi x \right) \right] . \]
Next, we plot partial sums along with the given function.
   Fourier approximation with 10 terms    Fourier approximation with 20 terms    Fourier approximation with 100 terms
       

The finite sum
\[ F_N (x) = \frac{a_0}{2} + \sum_{k=1}^{N} \left[ a_k \cos \frac{k \pi x}{\ell} + b_k \sin \frac{k \pi x}{\ell} \right] \]
is called a trigonometric polynomial of order N. There are three known (another one will be considered later in Cesàro section) kinds of convergence related to the Fourier series:
  • We say that the series \( \sum_{n\ge 0} f_n (x) \) converges to f(x) pointwise in the interval (a,b), if for each \( x \in (a,b) \)
    \[ \left\vert f(x) - \sum_{n=0}^N f_n (x) \right\vert \,\mapsto \, 0 \quad \mbox{as} \quad N \,\to\,\infty . \]
    That is, for each fixed \( x \in (a,b) , \) the numerical sequence \( \sum_{n\ge 0} f_n (x) \) converges to the number f(x).
  • The infinite sum \( \sum_{n\ge 0} f_n (x) \) converges uniformly in [a,b], if
    \[ \max_{a \le x \le b} \left\vert f(x) - \sum_{n=0}^N f_n (x) \right\vert \,\mapsto \, 0 \quad \mbox{as} \quad N \,\to\,\infty . \]
    That is, the overall “distance” between the function f(x) and the partial sums \( F_N (x) = \sum_{n= 0}^N f_n (x) \) converges to zero. Notice that the endpoints of the interval are included in the definition.
  • We say that the series \( \sum_{n\ge 0} f_n (x) \) converges to f(x) in the mean-square (or L2 sense) in (a,b), if
    \[ \int_a^b \left\vert f(x) - \sum_{n=0}^N f_n (x) \right\vert^2 \,{\text d} x \,\mapsto \, 0 \quad \mbox{as} \quad N \,\to\,\infty . \]
    That is, the the “distance” between f(x) and the partial sums in the mean-square sense converges to zero. ■
It is obvious from the definition that uniform convergence is the strongest of the three, since uniformly convergent series will clearly converge pointwise, as well as in the L² sense. The converse is not true, since not every pointwise or L² convergent series is uniformly convergent. Between the pointwise and L² convergence, neither is stronger than the other, since there are series that converge pointwise, but not in L², and vice versa.

The Euler--Fourier formulas \eqref{EqFourier.2} or \eqref{EqFourier.4} show that the Fourier coefficients are evaluated as integrals over the whole interval where a function is defined (it is convenient to integrate over symmetrical interval [−ℓ ,ℓ]). Therefore, these coefficients are influenced by the behavior of the function over the interval. This is completely different from Taylor series where coefficients are determined by the infinitesimal behavior of the function at the center of expansion because they are calculated as derivatives at the point. On the other hand, integral does not depend on the value of integrand function at discrete number of points. So is is expected that we cannot restore the value of the function at particular point from its Fourier series---Fourier coefficients do not contain this information. In opposite, Taylor series provide such information and pointwise or uniform convergence is appropriate for them. Fourier series are based on another convergence that is called L² (square mean), and it is completely different type of convergence. The advantage of this convergence is obvious: discontinuous functions could be expanded into Fourier series but not into Taylor series.
Theorem 2: Let f(x) be a square integrable function on the interval \( [- \ell , \ell ] , \) that is, \( \| f \|^2 = \int_{_\ell}^{\ell} |f(x)|^2 {\text d}x < \infty . \) Then the Fourier series for his function \( f(x) \,\sim \, \frac{a_0}{2} + \sum_{k\ge 0} \left[ a_k \cos \frac{k \pi x}{\ell} + b_k \sin \frac{k \pi x}{\ell} \right] , \) where its coefficients are determined via Euler--Fourier formulas:
\[ \begin{split} a_k &= \frac{1}{\ell} \, \int_{-\ell}^{\ell} f(x)\,\cos \frac{k \pi x}{\ell} \, {\text d} x , \quad k=0,1,2,\ldots , \\ b_k &= \frac{1}{\ell} \, \int_{-\ell}^{\ell} f(x)\,\sin \frac{k \pi x}{\ell} \, {\text d} x , \quad k=1,2,\ldots ; \end{split} \]
converges to f(x) in the mean square sense.     ⧫

Theorem 3: Every integrable function on a finite interval has a unique Fourier series expansion.     ⧫

Andrey Kolmogorov (1903--1987) from Moscow University (Russia), as a student at the age of 19, in his very first scientific work, constructed an example of an absolutely integrable function whose Fourier series diverges almost everywhere (later improved to diverge everywhere).

The first sufficient conditions for the pointwise convergence of the Fourier series were discovered by a German mathematician Johann Peter Gustav Lejeune Dirichlet (1805--1859). A function that satisfies the Dirichlet conditions is also called piecewise monotone. Such function must have right and left limits at each point of discontinuity.

 

Theorem (P. Dirichlet, 1829): Suppose that a periodic real-valued function f(x) satisfies the following conditions (known as the Dirichlet conditions): Then the function f(x) is represented by a convergent to \( \frac{1}{2} \left( f(a-0) + f(a+0) \right) \) Fourier series at every point x=𝑎.     ⧫

 

Theorem 5: Assume that
\[ F(x) \,=\, \frac{a_0}{2} + \sum_{k= 1}^{\infty} a_k \cos \left( \frac{k \pi x}{\ell} \right) + b_k \sin \left( \frac{k \pi x}{\ell} \right) \]
is the Fourier series for a piecewise continuous function f(x) over the interval [−ℓ, ℓ]. If its derivative f'(x) is piecewise continuous on the interval \( [- \ell , \ell ] \) and has both a left- and right-hand derivative at each point in this interval, then F(x) is pointwise convergent for all x ∈ [−ℓ, ℓ]. The relation \( F(x) = f(x) \) holds at all points x ∈ [−ℓ, ℓ], where f(x) is continuous. If x = 𝑎 is a point of discontinuity of f, then
\[ F(x) \,=\, \frac{f(a+0)+ f(a-0)}{2} , \]
where \( f(a-0) = f(a^{-}) = \lim_{t\uparrow a} f(t) \) and \( f(a+0) = f(a^{+}) = \lim_{t\dowmarrow a} f(t) \) denote the left- and right-hand limits, respectively.    ⧫

 

Theorem 6: Suppose that \( \left\{ (x_k, y_k ) \right\}_{k=0}^N \) are N+1 points, where \( y_k = f(x_k ) , \) and the abscissas are equally spaced:
\[ x_k = -\ell + \frac{2\ell \,k}{N} \qquad \mbox{for} \quad k=0,1,2,\ldots N. \]
If f(x) is periodic with period \( 2\ell \) and 2M < N, then there exists a trigonometric polynomial
\[ F_M (x) = \frac{a_0}{2} + \sum_{j=1}^M \left[ a_j \cos \left( j\pi x \right) + b_j \sin \left( j\pi x \right) \right] \]
that minimizes the quantity
\[ \sum_{k=1}^N \left\vert f(x_k ) - F_M (x_k ) \right\vert^2 . \]
The coefficients ak and bk of this trigonometric polynomial are computed with the formulas:
\begin{align*} a_j &= \frac{2}{N} \,\sum_{k=1}^N f(x_k ) \,\cos \left( j\,\pi \,x_k \right) \qquad\mbox{for}\quad j=0,1,\ldots , M , \\ b_j &= \frac{2}{N} \,\sum_{k=1}^N f(x_k ) \,\sin \left( j\,\pi\, x_k \right) \qquad\mbox{for}\quad j=1,2,\ldots , M . \qquad\qquad ⧫ \end{align*}

Example 3: Consider the function \( f (x) = x^2 \) on the interval [-1,1]. Let us take 16 equally spaced points \( x_k = -1 + \frac{2k}{15} , \quad k=0,1,2,\ldots , 15. \) Suppose we want to find the trigonometric polynomial approximation for M = 6 to the 15 data points \( \left\{ (x_k, y_k ) \right\}_{k=1}^{15} . \)

Since the periodic extension is assumed, at a point of discontinuity x = 1, the function value f(1) must be computed using the formula

\[ f(1) = \frac{f(1-0) + f(1+0)}{2} = \frac{1+1}{2} =1. \]
The function \( f (x) = x^2 \) is an even continuous function that is extended periodically; hence the coefficients for the sine terms are all zero (i.e. \( b_j =0 \) for all j). The trigonometric polynomial of degree M = 6 involves only the cosine terms, and we get
\[ a_j = \frac{2}{15} \,\sum_{k=1}^{15} \left( \frac{2k}{15} -1 \right)^2 \cos \left( j\,\pi\, x_k \right) \qquad\mbox{for}\quad j=0,1,2,\ldots , 6 . \]
Now we ask Mathematica for help:
Do[a[j_] := (2/15)* Sum[(2*k/15 - 1)^2 *Cos[j*Pi*(2*k/15 - 1)], {k, 1, 15}], {j, 0, 6}]
Then we calculate the trigonometric polynomial and plot it.
C6[x_] := a[0]/2 + Sum[a[j]*Cos[j*Pi*x], {j, 1, 6}]
Plot[{x^2 , FC6[x]}, {x, -1, 1}, PlotRange -> {-0.1, 1}, PlotStyle -> {{Thick, Blue}, {Thick, Orange}}]
As we see from the above graph, six term approximation gives relatively good representation of the given function. ■

Computing an integral in Mathematica is fairly painless, and it's tempting to simply use a partial Fourier sum depending to the number of terms n.

Example 4: Let's consider the following half-wave rectifier:

f[t_] = Piecewise[{{Cos[t], -Pi/2 < t < Pi/2}, {0, -Pi < t < -Pi/2 && Pi/2 < t < Pi}}]
Out[1]= { Cos[t] - Pi/2 < t < Pi/2
             { 0 True
Plot[f[t], {t, -Pi, Pi}, PlotStyle -> Thick]

Mathematica will treat the function f[t] outside the interval [-π , π ] as zero

Plot[f[t], {t, -3*Pi, 3*Pi}, PlotStyle -> Thick]

As we see, Mathematica rescales vertical and horizontal lines so that the picture becomes almost symmetric. You can return to the proper picture by using AspectRatio option:

Plot[f[t], {t, -3*Pi, 3*Pi}, PlotStyle -> Thick, AspectRatio -> 1/3/Pi, Ticks -> {True, None}]

So we get exactly the same graph. Now we are ready to expand this function into Fourier series by finding its Fourier coefficients:

\begin{align*} a_0 &= \frac{1}{\pi} \int_{-\pi /2}^{\pi /2} \cos x\,{\text d} x = \frac{2}{\pi} , \\ a_k &= \frac{1}{\pi} \int_{-\pi /2}^{\pi /2} \cos x\, \cos \left( k\, x \right) {\text d} x = -\frac{2}{\pi}\, \frac{1}{k^2 -1} \, \cos \frac{k\pi}{2} , \qquad k= 2, 3, \ldots ; \\ b_k &= \frac{1}{\pi} \int_{-\pi /2}^{\pi /2} \cos x\, \sin \left( k\, x \right) {\text d} x =0, \qquad k= 1, 2, 3, \ldots . \end{align*}
Then the corresponding Fourier series becomes
\[ f(t) \,=\,\frac{1}{\pi} + \frac{1}{2}\, \cos t - \frac{2}{\pi} \, \sum_{k\ge 1} \frac{1}{k^2 -1} \,\cos \left( k\, x \right) . \]
A partial sum with N = 20 terms gives a very good approximation:

We show how these commands work with other examples.

Example 5: We consider a piecewise continuous function that cannot be extended into Taylor series because it is identically zero on the interval (1,2). However, we can find its Fourier series.

f[x_] = Piecewise[{{1 - x, 0 < x < 1}, {0, 1 < x < 2}}]
Out[2]= { 1-x, if 0<x<1 and 0 for 1<x<2.

The standard Mathematica command FourierTrigSeries provides you the Fourier series of the function that is extended periodically from the standard interval (-π,π):

FourierTrigSeries[f[x], x, 3]
Out[2]= 1/(4 \[Pi]) + (2 Cos[x] Sin[1/2]^2)/\[Pi] + (Cos[2 x] Sin[1]^2)/(2 \[Pi]) + (2 Cos[3 x] Sin[3/2]^2)/(
9 \[Pi]) + ((2 - 2 Sin[1]) Sin[x])/(2 \[Pi]) - ((-2 + Sin[2]) Sin[2 x])/(4 \[Pi]) - ((-3 + Sin[3]) Sin[3 x])/(9 \[Pi])

With option FourierParameters, it is equivalent to

FourierTrigSeries[f[x], x, 3, FourierParameters -> {1, 1}]
We can plot the partial sum with say 50 terms. Since Fourier partial sums oscillate near points of discontinuity exhibiting so called Gibbs phenomenon, we indicate maximum wiggle (overshoot) and minimum one:

curve = FourierTrigSeries[f[x], x, 50];
Plot[curve, {x, -1.5, 13.5}, PlotRange -> {-0.3, 1.3}, Ticks -> {{Pi, 2*Pi, 3*Pi}, {1.09, -0.09}}, PlotStyle -> Thick]

However, it is not what we want: we need the Fourier series of the function f[x] extended periodically from the interval of length 2:

FourierTrigSeries[f[x], x, 3, FourierParameters -> {1, Pi}]
Out[3]= 1/4 + (2 Cos[\[Pi] x])/\[Pi]^2 + (2 Cos[3 \[Pi] x])/(9 \[Pi]^2) + Sin[\[Pi] x]/\[Pi] + Sin[2 \[Pi] x]/(2 \[Pi]) + Sin[3 \[Pi] x]/( 3 \[Pi])

To check, we find the Fourier coefficients manually:

Integrate[f[x]*Cos[n*Pi*x], {x, 0, 2}, Assumptions -> Element[n, Integers]]
Out[4]= (1 - Cos[n \[Pi]])/(n^2 \[Pi]^2)
So
\[ a_0 = \frac{1}{2} , \qquad a_n = \frac{1- (-1)^n}{n^2 \pi^2} , \quad n=1,2,\ldots . \]
Integrate[f[x]*Sin[n*Pi*x], {x, 0, 2}, Assumptions -> Element[n, Integers]]
Out[5]= (n \[Pi] - Sin[n \[Pi]])/(n^2 \[Pi]^2)

which is 1/(n*π). Hence, its Fourier series becomes

\[ f(x) = \frac{1}{4} + \sum_{n\ge 1} \left[ \frac{1- (-1)^n}{n^2 \pi^2} \, \cos \left( n \pi x \right) + \frac{1}{n\pi}\, \sin \left( n \pi x \right) \right] \]
We can also represent f(x) in other forms:
\[ f(x) = \frac{1}{4} + \sum_{n\ge 1} \sqrt{ \left( \frac{1- (-1)^n}{n^2 \pi^2} \right)^2 + \frac{1}{n^2 \pi^2}} \, \sin \left( n \pi x + \arctan \frac{1- (-1)^n}{n \pi} \right) = \frac{1}{4} + \sum_{n\ge 1} \sqrt{ \left( \frac{1- (-1)^n}{n^2 \pi^2} \right)^2 + \frac{1}{n^2 \pi^2}} \, \cos \left( n \pi x - \mbox{arccot} \frac{1- (-1)^n}{n \pi} \right) . \]
Now we plot some partial sums, starting with the given function itself:

Plot[f[x], {x, -1, 3}, PlotRange -> {0, 1}, AspectRatio -> Automatic, Axes -> {True, False}, PlotStyle -> Thick]

Then we plot some finite sums:

curve5Pi = FourierTrigSeries[f[x], x, 5];
Plot[%, {x, -1, 3}]

Then we repeat calculations with 50 terms:


Next we plot the correct Fourier series partial sums:

curve5=FourierTrigSeries[f[x], x, 50, FourierParameters -> {1, Pi}];
Plot[%, {x, -1, 3}]

 

The option FourierParameters has two parameters and when applied, it looks as FourierParameters->{a,b}
In trigonometric form, with setting \( {\bf FourierParameters} \,-> \,\{ a, b \} \) the following series is returned:

\[ \left\vert \frac{b}{\pi} \right\vert^{(1+a)/2} \left[ \frac{a_0}{2} + \sum_{k=1}^n \left( a_k \,\cos (bkt) + b_k \,\sin (bkt) \right) \right] , \]
with
\[ a_k = \left\vert \frac{b}{\pi} \right\vert^{(1+a)/2} \,\int_{-\pi/|b|}^{\pi/|b|} f(t)\,\cos (bkt) \,{\text d}t , \qquad k=0,1,2,\ldots , \]
\[ b_k = \left\vert \frac{b}{\pi} \right\vert^{(1+a)/2} \,\int_{-\pi/|b|}^{\pi/|b|} f(t)\,\sin (bkt) \,{\text d}t , \qquad k=1,2,\ldots . \]

Syntax for the FourierSeries command is: FourierSeries [ function , variable , number of terms ]

Changing the FourierParameters setting allows control over the limits of integration on the coefficients, and therefore, the base frequency of the series. Some work will go into calculating what value for “b” will give the proper limits of integration. There is ordinarily no reason to change “a” from its default setting, which is 1.

Here are two important applications of Fourier series:
\[ \cos \left( a\,\sin x \right) = J_0 (a) + \sum_{k\ge 1} J_{2k} (a) \,\cos \left( 2kx \right) . \]
\[ \delta (x-a) = \frac{1}{2\pi} \, \int_{-\infty}^{\infty} e^{{\bf j} (x-a)t} \, {\text d} t = \lim_{n\to \infty} \, \frac{1}{2\pi} \, \sum_{k=-n}^n \, e^{{\bf j} k(x-a)} \quad \left( = \frac{\sin \left[ \left( n+ \frac{1}{2} \right) (x-a) \right]}{2\pi\, \sin \frac{x-a}{2}} \right) , \]
where j is a unit vector in positive vertical direction on the complex plane, so \( {\bf j}^2 =-1 . \)

We show how these commands work with other examples.

Example 6: Consider the piecewise continuous function on the interval [-2,2]:

\[ f(x) = \begin{cases} 1, & \ \mbox {if } -2 < x < -1 , \\ x^2 -1, & \ \mbox {if } -1< x< 2 , \end{cases} \]
Its Fourier coefficients are evaluated with the aid of Mathematica:
f[x_] = Piecewise[{{1, -2 < x < -1}, {x^2 - 1, -1 < x < 2}}, 0]
Integrate[f[x], {x, -2, 2}]/2
1/4
Other coefficients we find by direct integration:
Simplify[Integrate[f[x]*Sin[n*Pi*x/2], {x, -2, 2}]/2 , Assumptions -> Element[n, Integers]]
-((2 (-1)^n (-4 + n^2 \[Pi]^2) + (8 + n^2 \[Pi]^2) Cos[(n \[Pi])/2] + 4 n \[Pi] Sin[(n \[Pi])/2])/(n^3 \[Pi]^3))
Simplify[Integrate[f[x]*Cos[n*Pi*x/2], {x, -2, 2}]/2 , Assumptions -> Element[n, Integers]]
(8 (-1)^n n \[Pi] + 4 n \[Pi] Cos[(n \[Pi])/2] - (8 + n^2 \[Pi]^2) Sin[(n \[Pi])/ 2])/(n^3 \[Pi]^3)
So
\begin{align*} a_0 &= \frac{1}{2} , \\ a_n &= \frac{8(-1)^n n\pi + 4n\pi \cos \left( \frac{n\pi}{2} \right) - \left( 8 + n^2 \pi^2 \right) \sin \left( \frac{n\pi}{2} \right)}{n^3 \pi^3} , \\ b_n &= - \frac{2 (-1)^n \left( n^2 \pi^2 -4 \right) + \left( 8 + n^2 \pi^2 \right) \cos \left( \frac{n\pi}{2} \right) + 4n\pi\,\sin \left( \frac{n\pi}{2} \right)}{n^3 \pi^3} . \end{align*}
Finally, we build partial Fourier sums with N = 10, 20, and 100 terms
F10[x_] = 1/4 + Sum[(( 8 (-1)^n n \[Pi] + 4 n \[Pi] Cos[(n \[Pi])/2] - (8 + n^2 \[Pi]^2) Sin[(n \[Pi])/ 2])/(n^3 \[Pi]^3))* Cos[n*Pi*x/2] - (( 2 (-1)^n (-4 + n^2 \[Pi]^2) + (8 + n^2 \[Pi]^2) Cos[(n \[Pi])/ 2] + 4 n \[Pi] Sin[(n \[Pi])/2])/(n^3 \[Pi]^3))* Sin[n*Pi*x/2], {n, 1, 10}]
F20[x_] = 1/4 + Sum[(( 8 (-1)^n n \[Pi] + 4 n \[Pi] Cos[(n \[Pi])/2] - (8 + n^2 \[Pi]^2) Sin[(n \[Pi])/ 2])/(n^3 \[Pi]^3))* Cos[n*Pi*x/2] - (( 2 (-1)^n (-4 + n^2 \[Pi]^2) + (8 + n^2 \[Pi]^2) Cos[(n \[Pi])/ 2] + 4 n \[Pi] Sin[(n \[Pi])/2])/(n^3 \[Pi]^3))* Sin[n*Pi*x/2], {n, 1, 20}]
F100[x_] = 1/4 + Sum[(( 8 (-1)^n n \[Pi] + 4 n \[Pi] Cos[(n \[Pi])/2] - (8 + n^2 \[Pi]^2) Sin[(n \[Pi])/ 2])/(n^3 \[Pi]^3))* Cos[n*Pi*x/2] - (( 2 (-1)^n (-4 + n^2 \[Pi]^2) + (8 + n^2 \[Pi]^2) Cos[(n \[Pi])/ 2] + 4 n \[Pi] Sin[(n \[Pi])/2])/(n^3 \[Pi]^3))* Sin[n*Pi*x/2], {n, 1, 100}]
and plot them:
Plot[{f[x], F10[x]}, {x, -2.5, 2.5}, PlotStyle -> {{Thick, Black}, {Thick, Red}}]
Plot[{f[x], F20[x]}, {x, -2.5, 2.5}, PlotStyle -> {{Thick, Black}, {Thick, Orange}}]
Plot[{f[x], F100[x]}, {x, -2.5, 2.5}, PlotStyle -> {{Thick, Black}, {Thick, Blue}}]
   Fourier approximation with 10 terms    Fourier approximation with 20 terms    Fourier approximation with 100 terms
       
   ■

Example 7: Let us consider a periodic step function with period T:

\[ f(x) = \mbox{sign}\left( \sin \frac{2\pi x}{T} \right) = \begin{cases} \phantom{-}1, & \ \mbox{for }\ 0 < x < T /2, \\ -1, & \ \mbox{for }\ T/2 < x < T . \end{cases} \]
Plot[Sign[Sin[Pi*x]], {x, 0, 4}, PlotStyle -> Thick]
Periodic step function with period 2.
Its Fourier series becomes
\[ \mbox{sign}\left( \sin \frac{2\pi x}{T} \right) = \frac{4}{\pi} \sum_{n\ge 1} \frac{1}{2n-1}\,\sin \frac{2\pi x \left( 2n -1 \right)}{T} . \]
   ■

 

Product of Fourier series


Suppose we have two Fourier sum-functions f(x) and g(x). When these functions are defined by trigonometric series \eqref{EqFourier.5}, there is no suitable formula to determine the Fourier coefficients for their product f g(x). However, when these functions are expanded into complex Fourier series
\[ f(x) \,\sim\, \sum_{k=-\infty}^{\infty} \alpha_k e^{k{\bf j} \pi x/\ell} , \qquad g(x) \,\sim\, \sum_{k=-\infty}^{\infty} \beta_k e^{k{\bf j} \pi x/\ell} , \]
then their product is
\[ f(x)\,g(x) \,\sim\, \sum_{k=-\infty}^{\infty} \gamma_k e^{k{\bf j} \pi x/\ell} , \]
where
\[ \gamma_n = \sum_{j=-\infty}^{\infty} \alpha_j \beta_{n-j} \]
is known as the convolution of two Fourier series.

 

  1. Carleson, L., On convergence and growth of partial sums of Fourier series, Acta. Math. 116 (1966), pp. 135–137.
  2. Gibbs, J. W., Fourier Series, Nature, 1899, Vol. 59, 200 and 606.
  3. Hunt, R., On the convergence of Fourier series, Orthogonal Expansions and their Continuous Analogues (Proc. Conf. Edwardsville, IL, 1967), Southern University Press, Carbondale, IL, 1968, pp. 235–255.
  4. R. Hunt and M. Taibleson, Almost everywhere convergence of Fourier series on the ring of integers of a local field, SIAM J. Math. Anal. 2 (1971), pp. 607–625.
  5. Körner, T.W., Fourier Analysis, Cambridge University Press; 1 edition (January 28, 1988).
  6. Tolstov, G.P., Fourier Series, Dover Publications, 2012.
  7. Walker, J.S., Fourier Analysis, 1988, Oxford University Press, New York.

==================== ??????????????? ============


Examples of Fourier Series Square Wave Functions part1%
%i)the example involves graphing three similar heaviside square wqave
%functions, that only differ by a shift. The 3 functions are f,g, and h.
%For the l selected it will be l=1, so function f will equal 1 from (0,1)
%and -1 from (1,2), then g will equal 1 from (0,1) and 0 from (1,2) and h
%will equal 0 from (0,1) and 1 from (1,2)
%To find the fourier series of each function, you will have to find the
%coefficients which for f is different than the other two but g and h share them in common. They must be solved by
%integration of the their function values in a product with cosine and sine
%functions.
%For f(x) the a0 and a1 term are both 0 since f is an odd function. So we
%only need to solve for b1%
syms x
p =@(x,k) sin(k.*x*pi)
b1 = int(p,x,[0,2])
%ii)Using the b1 coefficient found for f, we write the fourier series of f
%and plot it from 0 to 2%
l=1
n=(1:100);
x=linspace(0,2*pi,100);
[N,X] = ndgrid(n,x);
sys = @(n,x) 4.*l./pi.*(1./(2.*n+1).*sin((2.*n+1).*pi.*x./l))   ;
sys_sum = sum(sys(N,X));
plot(x,sys_sum);


%Examples of Fourier Series Square Wave Functions ex2%
%i)Find the coefficients of function g, wihch shares the same as h, by
%using integration of their function from 0 to 2. the integration will be
%a product of a cosin or sine function and the functions themself. The
%coefficients we will find are a0,a1, and b1
syms x
p =@(x,k) cos(k.*x*pi)
q =@(x,k) sin(k.*x*pi)
a0 = 0.50*(int(1,x,[0,2]))
a1 = int(p,x,[0,2])
b1 = int(q,x,[0,2])

%We use the coefficients to plot the fourier series of the g function%
l=1
n=(1:100);
x=linspace(0,2*pi,100);
[N,X] = ndgrid(n,x);
sys = @(n,x) (1/200) + 2.*l./pi.*(1./(2.*n+1).*sin((2.*n+1)*pi.*x./l))
sys_sum = sum(sys(N,X));
plot(x,sys_sum)


%Finally, we also plot the fourier series of the h function using the
%coefficients of a0, a1, and b1 calculated%
l=1
n=(1:100);
x=linspace(0,2*pi,100);
[N,X] = ndgrid(n,x);
sys = @(n,x) (1/200) -2.*l./pi.*(1./(2.*n+1).*sin((2.*n+1)*pi.*x./l))   ;
sys_sum = sum(sys(N,X));
plot(x,sys_sum);


%Gibbs Phenomenon Continuous Piecewise Function Example%
%i)Plot a piecewise function which for f(x) equals 0 from x=-pi to x=0 and
%where f(x) = x from x=0 to x=pi
syms x
y = piecewise(-pi