# Fourier Series¶

Fourier series is a way to decompose a periodic function with finite period \( 2\ell \) into an infinite sum of its projections onto an orthonormal basis that consists of trigonometric polynomials. Therefore, Fourier series provides a periodic extension of a function initially defined on a finite interval of length \( 2\ell . \) They are named in honour of Jean-Baptiste Joseph Fourier (1768--1830), who used trigonometric series in representing solutions of partial differential equations, after preliminary investigations by Leonhard Euler (1707--1783), Jean le Rond d'Alembert (1717--1783), and Daniel Bernoulli (1700--1782).

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

and another is trigonometric form

The trigonometric form is based on Euler's formulas:

Here, **j** is the unit vector in positive vertical direction on the complex plane, so \( {\bf j}^2 =-1. \)
You can use the following commands to calculate the *n*th partial sum of the Fourier series of the expression *f* on the interval

`syms x k L n`

The next command tells MATLAB that

*k*is an integer. That will allow simple and simplify to evaluate \( \sin \frac{k\pi x}{\ell} \quad\mbox{and}\quad \cos \frac{k\pi x}{\ell} \) for a symbolic integer

*k*.

`evalin(symengine,'assume(k,Type::Integer)');`

*k*th Fourier cosine coefficient

*a*

_{k}of

*f*is given by the command

`a = @(f,x,k,L) int(f*cos(k*pi*x/L)/L,x,-L,L);`

*k*th Fourier sine coefficient

*b*

_{k}of

*f*is given by the command

```
b = @(f,x,k,L) int(f*sin(k*pi*x/L)/L,x,-L,L);
```

*n*th partial sum is given by

```
fs = @(f,x,n,L) a(f,x,0,L)/2 + ...
symsum(a(f,x,k,L)*cos(k*pi*x/L) + b(f,x,k,L)*sin(k*pi*x/L),k,1,n);
```

Sometimes, it is convenient to use polar form:

Computing an integral in *Matlab* is fairly painless, and it's tempting to simply use a partial Fourier sum depending to the number of terms *n*.
Let's consider the following half-wave rectifier:

```
syms x
f = piecewise(0< x< 1, 1-x, 1< x, 0)
```

```
pretty(fs(f,x,10,1))
```

```
[A,how]=simple(a(f,x,k,1))
```

*k*th Fourier sine coefficient.

```
[B,how]=simple(b(f,x,k,1)); B
```

*f*.

```
ezplot(fs(f,x,2,1),-1,1)
hold on
ezplot(f,-1,1)
hold off
title('Partial sum with n=10')
```

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

*N = 20*terms gives a very good approximation:

We show how these commands work by examples.

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

The standard *Mathematica* command **FourierTrigSeries** provides you the Fourier series of the function that is extended by zero outside the given interval (0<x<2 in our case):

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

We can plot the partial sum with say 50 terms:

Plot[curve, {x, -1.5, 3.5}, PlotRange -> 1]

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:

To check, we find the Fourier coefficients manually:

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

*f(x)*in other forms:

Then we plot some finite sums:

Plot[%, {x, -1, 3}]

Then we repeat calculations with 50 terms:

Next we plot the correct Fourier series partial sums:

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:

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.

# Periodic Extension

# Complex Form of Fourier Expansion

# Examples of Fourier Series

# Gibbs Phenomenon

# Cesaro Approximation

# Even and Odd Functions

# Chebyshev expantion

# Legendre expansion

# Bessel--Fourier Series

# Hermite Expansion

# Laguerre Expansion

# Motivated examples

Enter text here