Fourier Series


This section is devoted to periodic extensions of functions defined on some finite interval. Since Fourier series provide periodic extensions, we need to compare it with corresponding periodic extension of the original function.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340
Return to Part V of the course APMA0340
Introduction to Linear Algebra with Mathematica

Periodic Extension


Let a and b be real numbers such that a < b, and let f be a real-valued function \( f\, : \, (a,b] \mapsto \,\mathbb{R} . \) The function \( F\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) defined by
\[ F(x) = f \left( x - \left\lfloor \frac{x-a}{b-a} \right\rfloor \left( b-a \right) \right) , \quad x \in \mathbb{R} , \]
is called the periodic extension of f.
Here \( \lfloor {\text a} \rfloor \) is the floor of a real number a, which is the largest integer that does not exceed a. There are several known types of periodic extensions, two of which will be discussed later. Periodic extension is very important topic in electrical engineering, called rectification. A rectifier is an electrical device that converts alternating current (AC), which periodically reverses direction, to direct current (DC), which flows in only one direction. Currently, there are two known rectifiers: the half-wave rectifier and full-wave rectifier. While three-phase rectifiers are more common in industry, we are not going to consider them now. Instead, we give mathematical definitions of electrical counterparts that are related to periodic extensions.
Let \( f\, : \, (a,b] \mapsto \,\mathbb{R} \) be a real-valued function defined on a finite interval. Its full-wave rectifier is a periodic function with period b-a, which is obtained by periodic extension of the function f from the original interval. Its half-wave rectifier is a periodic extension with period 2(b-a) of the function
\[ F(x) = \begin{cases} f(x) , & \ \mbox{ if } a < x \le b , \\ 0 , & \ \mbox{ if } b < x \le 2b-a . \end{cases} \]
Let a and b be real numbers such that a < b, and let f be a piecewise continuous real-valued function \( f\, : \, (a,b] \mapsto \,\mathbb{R} . \) The function \( F\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) is said to be the Fourier periodic extension of f if it is its periodic extension with period b-a satisfies the following conditions:
\[ F_{\scriptstyle Fourier} (x) = \begin{cases} F \left( x \right) , & \quad \mbox{if $F(x)$ is continuous at } x , \\ \frac{1}{2} \left[ F(x+0) + F(x-0) \right] , & \quad \mbox{if $F$ is discontinuous at } x, \end{cases} \qquad x \in \mathbb{R} . \]

Here the expression F(a + 0) means the limit value from the right: \( F(a+0) = \lim_{\epsilon \mapsto 0>0} F(a+\epsilon ) . \) Similarly, \( F(a-0) = \lim_{\epsilon \mapsto 0>0} F(a-\epsilon ) . \) The condition at the point of discontinuity follows from the fact that a Fourier series, if it converges at this point, is equal to the average values of left and right limits. Therefore, it does not matter what value f(a) is assigned initially at the point of discontinuity x = a, its Fourier series will define it to be \( \frac{1}{2} \left[ f(a+0) + f(a-0) \right] . \)

Example: Consider the function \( f(x) = 1-x \) on the interval [0,1]. To define its periodic extension, we use Mathematica command Mod:

periodicExtension[func_ , period_, offset_] := func[Abs[Mod[t, period, offset]]];
f[t_]=1-t;
f10=periodicExtension[f,1,0];
Plot[f10,{t,0,4}, PlotStyle -> {Thick, Red}, PlotLabels ->"Expressions"] f1 = periodicExtension[f,1];
Plot[f1,{t,0,4}, PlotStyle -> Thick, ColorFunction -> Function[{x,y}, Hue[y]]]
f12 = periodicExtension[f,1, 1/2];
Plot[f12,{t,0,4}, PlotStyle -> Directive[Opacity[0.5], Thick], Mesh ->20, MeshFunctions -> {#1 &}, MeshShading -> {Red, Green}]
f1m1 = periodicExtension[f,1, -1];
Plot[f1m1,{t,0,4}, PlotStyle ->Orange, Mesh -> All]
f21 = periodicExtension[f,2,1];
Plot[f21,{t,0,4}, PlotStyle->Thick, ColorFunction -> Function[{x,y}, Hue[x]], ColorFunctionScaling->True]
f20 = periodicExtension[f,2,0];
Plot[f20,{t,0,4}, PlotStyle->Thick, Epilog -> {PointSize[0.03], Point[{1,0}], Point[{3,0}]}]
f2m1 = periodicExtension[f,2,-1];
Plot[f2m1,{t,0,4}, PlotStyle -> Thick, Mesh ->{Range[0,1,1/4]}, MeshStyle ->PointSize[Medium]]
Full-wave rectifier.
Periodic expansion f1.
Periodic expansion f12.
Periodic expansion f1m1.
Periodic expansion f21.
Periodic expansion f20.
Periodic expansion f2m1.

To plot half-wave rectifiers, we need to define another piecewise continuous function

\[ g(x) = \begin{cases} 1-x , & \ \mbox{ if } 0 < x \le 1, \\ 0 , & \ \mbox{ if } 1 \le x < 2. \end{cases} \]
g[x_] = Piecewise[{{1-x, 0<x<1}, {0,1<x<2}}]
Then we plot half-wave rectifier of our function.
g10=periodicExtension[g,2,0];
Plot[g10,{t,0,4}, PlotStyle -> {Thick, Red}, PlotLabels ->"Expressions"]
Similarly, we get other extensions.
g4 = periodicExtension[g,4];
Plot[g4,{t,0,4}, PlotStyle -> Thick, ColorFunction -> Function[{x,y}, Hue[y]]]
g2m2 = periodicExtension[g,2, -2];
Plot[g2m2, {t,0,4}, PlotStyle -> Directive[Opacity[0.5], Thick], Mesh ->20, MeshFunctions -> {#1 &}, MeshShading -> {Red, Green}]
g30 = periodicExtension[g,3,0];
Plot[g30 ,{t,0,4}, PlotStyle -> Thick, Mesh ->{Range[0,1,1/4]}, MeshStyle ->PointSize[Medium]]
Half-wave rectifier.
Periodic expansion g4.
Periodic expansion g2m2.
Periodic expansion g30.

In each example below we start with a function defined on an interval, plotted in blue; then we present the periodic extension of this function, plotted in other color; then we present the Fourier expansion of this function, which is a Fourier periodic extension of the given function. The last figure in each example shows in one plot the Fourier expansion and the approximation with the partial sum with 20 terms of the corresponding Fourier series.

Example: Consider the following functions:

We describe periodic extension and its Fourier approximation in the following example.

Example: Consider the piecewise continuous function, defined on the interval \( [-2,2] . \)

\[ \left\{ \begin{array}{ll} 1 , & \ x<0 \\ x^2 , & \ x>0 \end{array} \right. \qquad\mbox{on the interval } (-2,2). \]
To find its Fourier series, we calculate the corresponding Fourier coefficients:
Clear[x,n,ak1,ak2,ak,bk1,bk2,bk,Sn]
ak1 = Integrate[1/2*Cos[n*Pi*x/2], {x,-2,0}];
ak2 = Integrate[1/2*x^2 * Cos[n*Pi*x/2], {x,0,2}];
bk1 = Integrate[1/2*Sin[n*Pi*x/2], {x,-2,0}];
bk2 = Integrate[1/2*x^2 * Sin[n*Pi*x/2], {x,0,2}];
ak = FullSimplify[ak1+ak2, Element[n, Integers]]
bk = FullSimplify[bk1+bk2, Element[n, Integers]]
a0 = FullSimplify[1/2* Integrate[1, {x,-2,0}] + 1/2 * Integrate[x^2 , {x,0,2}]]
Out[6]= (8 (-1 + (-1)^n) - (1 + 3 (-1)^n) n^2 \[Pi]^2)/(n^3 \[Pi]^3)
Out[7]= (8 (-1)^n)/(n^2 \[Pi]^2)
Out[8]= 7/3
Now we define its periodic expansion. This could be achieved in many ways, and we give some approaches to find a periodic expansion.
f[x_] := Which[x > 2, f[x - 2*2], x < -2, f[x + 2*2], -2 < x < 0, 1 + x - x, 0 < x < 2, x^2]
Plot[f[x], {x, -5, 5}, PlotStyle -> {Thick, Black}]

Other options to define periodic function:

f[x_] = Piecewise[{{1, x < 0}, {x^2, x > 0}}]

Out[11]= \[ \left\{ \begin{array}{ll} 1 & \ x<0 \\ x^2 & \ x>0 \\ 0 & \ \mbox{True} \end{array} \right. \]

We define a subroutine that provide periodic extension of a function:

myperiodic[func_, {val_Symbol, min_?NumberQ, max_?NumberQ}] := func /. (val :> Mod[val - min, max - min] + min)
Then we plot it:
Plot[myperiodic[f[x], {x, -2, 2}] // Evaluate , {x, -5, 5}, PlotStyle -> {Thick, Black}]
We demonstrate other options to determine a periodic extension on our old piecewise continuous function.
Clear[f];
f[x_] = Piecewise[{{1, x < 0}, {x^2, x > 0}}]
f[t_ /; t >= 2] := f[t - 4]; f[t_ /; t < -2] := f[t + 4]; Plot[f[t], {t, -10, 10}] , PlotStyle -> {Thick}]
f[x_] = Piecewise[{{1, x < 0}, {x^2, x > 0}}]
g[x_] = f@Mod[x, 4 , -2] (* somehow slow *)
Plot[{f[t], g[t]}, {t, -6, 6}, PlotStyle -> Thick]

A periodic extension can be defined for arbitrary period as the following example shows.
T = 2.5
g[x_ /;0<= x <= T] := x^2 +1;
f[x_] := g[Mod[x, T]]
Plot[f[t], {t, -6, 6}, PlotRange -> {{-5,5}, {-0.1, 8}}, PlotStyle -> Thick]

Example: Consider the following function that we met previously

\[ f(x) = \left\{ \begin{array}{ll} \cos x, & \ \mbox{within interval $[-\pi /2 , \pi /2 ]$}, \\ 0 , & \ \mbox{outside the interval within } [-\pi , \pi ]. \end{array} \right. \]

We can also define the periodic expansion of any function using Mod command. If we need to define a function with period \( 2*\pi , \) we type:

periodicExtension[func_] := func[Abs[Mod[t, 2*Pi, -1*Pi]]]
per = periodicExtension[f]
Out[2] = { Cos[Abs[Mod[t,2*Pi , -Pi]]] -Pi/2 < Abs[Mod[t, 2*Pi , -Pi]] < Pi/2
                 0 True
Plot[per, {t, -10, 10}, PlotStyle -> Thick]
FourierTrigSeries[f[t], t, 5]
Out[6] = 1/\[Pi] + Cos[t]/2 + (2 Cos[2 t])/(3 \[Pi]) - (2 Cos[4 t])/(15 \[Pi])
Plot[%, {t, -3*Pi, 3*Pi}, PlotStyle -> Thick, AspectRatio -> 1/5]


  1. Gregory A. Kriegsmann, A mathematical theory of full-wave rectification, IMA Journal of Applied Mathematics, Volume 36, Issue 1, 1 January 1986, Pages 29--41, https://doi.org/10.1093/imamat/36.1.29
  2. C. Marouchos ; M.K. Darwish ; M. El-Habrouk, New mathematical model for analysing three-phase controlled rectifier using switching functions, IET Power Electronics, Volume: 3, Issue: 1, January 2010, 95--110. doi: 10.1049/iet-pel.2008.0328
  3. Le Hong Lan and Nguyen Thi Hien, Mathematical model written by the canonical system for some electric rectifier circuits using semiconductor diodes, article
  4. Branco Curgus, Fourier periodic extensions of piecewise continuous functions, http://faculty.wwu.edu/curgus/Courses/Math_pages/Math_430/Fourier_periodic_extension.html
  5. Mohammed A. Abbas, Falah H.Hanoon, and Lafy F.Al-Badry, Possibility designing half-wave and full-wave molecular rectifiers by using single benzene molecule, Physics Letters A, Volume 382, Issue 8, 27 February 2018, Pages 608--612. https://doi.org/10.1016/j.physleta.2017.12.017

 

Return to Mathematica page
Return to the main page (APMA0340)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Ordinary Differential Equations
Return to the Part 3 Non-linear Systems of Ordinary Differential Equations
Return to the Part 4 Numerical Methods
Return to the Part 5 Fourier Series
Return to the Part 6 Partial Differential Equations
Return to the Part 7 Special Functions