Let a and b be real numbers such that a < b. A function \( f\, : \, [a,b] \mapsto \,\mathbb{R} \) is said to be piecewise continuous on \( [a,b] \) if the following conditions are satisfied: 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} . \)

Let a and b be real numbers such that a < b. A function \( f\, : \, [a,b] \mapsto \,\mathbb{R} \) is said to be piecewise smooth on \( [a,b] \) if the following conditions are satisfied: 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} . \)

Let a and b be real numbers such that a < b, and let f be a function \( f\, : \, (a,b] \mapsto \,\mathbb{R} . \) The function \( F\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) defined by

\[ F(x) = f \left( x - \left( \left\lfloor \frac{x-a}{b-a} \right\rfloor -1 \right)\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.

Let a and b be real numbers such that a < b, and let f be a piecewise continuous function \( f\, : \, (a,b] \mapsto \,\mathbb{R} . \) Let the function \( F\, : \, \mathbb{R} \mapsto \,\mathbb{R} \) be the periodic extension of f. The Fourier periodic extension of f is the following function

\[ 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 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] . \)

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). \]

Then we calculate its 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 approches 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]


 

Complex Form of Fourier Expansion

Examples of Fourier Series

Gibbs Phenomenon

Cesàro Approximation

Even and Odd Functions

Chebyshev expantion

Legendre expansion

Bessel--Fourier Series

Hermite Expansion

Laguerre Expansion

Motivated examples