Experiment 1 Fourier Series and Its Visualization
Experiment 1 Fourier Series and Its Visualization
Department of Mathematics
December 9, 2019
Fourier series and its visualization Experiment 1
1 Aim
2 Mathematical Description
and τ is called its period. For instance, sin x and cos x are periodic with period 2π.
Let f (t) be periodic function with period 2l satisfying the Dirichlet conditions
on an interval I = [L,U] with U − L = 2l. The Fourier series of f (t) is given by
∞ n
a0 nπt nπt o
f (t) = + ∑ an cos + bn sin for all t ∈ I, (2.2)
2 n=1 l l
The Fourier coefficients are computed by using the following Euler’s formulas:
ZU
1
a0 = f (t) dt, (2.4)
l
L
ZU
1 nπt
an = f (t) cos dt, n = 1, 2, ... (2.5)
l l
L
ZU
1 nπt
bn = f (t) sin dt, n = 1, 2, ... (2.6)
l l
L
3 Example
Example 3.1.
Write a Matlab code to find the Fourier series of periodic function f (t) in (a, b)
upto second harmonic. Then use the above code for f (t) = t − t 2 and (a, b) =
(−π, π), and visualize it.
solution.
(b) Input
Enter the function f ( t ) = t−t ˆ2
Enter Lower l i m i t : −pi
Enter upper l i m i t : pi
(c) Output
Fourier C o e f f i c i e n t s :
a0 =
−(2 * pi ˆ 2 ) / 3
a (n) =
−(2 * ( n ˆ2 * pi ˆ2 * sin ( pi *n)−2 * sin ( pi *n )
+2 *n* pi * cos ( pi *n ) ) ) / ( n ˆ3 * pi )
b(n) =
( 2 * ( sin ( pi *n)−n* pi * cos ( pi *n ) ) ) / ( n ˆ2 * pi )
Harmonics :
fs1 =
4 * cos ( t ) + 2 * sin ( t )
fs2 =
−cos ( 2 * t )− sin ( 2 * t )
F o u r i e r S e r i e s upto second harmonic :
fs ( t ) =
4 * cos ( t−sin ( 2 * t )−cos ( 2 * t ) + 2 * sin ( t )−pi ˆ2/3
(d) Visualization
Fourier Series of f(t))
f(t)
0 fs(t)
-2
-4
-6
-8
-10
-3 -2 -1 0 1 2 3
t
4 Self-check Exercises
Exercise 4.1.
Write a Matlab code to find the Fourier series of periodic function f (t) in (a, b)
upto a given number of harmonics(2, 3 or 4). Given (a, b) and the number of
harmonics, use the above code for each of the following functions:
(a) f (t) = e−t for all −π < t < π, n = 3
(b) f (t) = t + t 2 for all −π < t < π, n = 2
5 Concept-based Exercises
Exercise 5.1.
Given a real valued function f (t) defined for −∞ < t < ∞, write a matlab code
for verifying whether f is odd or even.
Exercise 5.2.
Let f (t) be a periodic function defined in one period −l < t < l. If f is even (or
odd), write a matlab code to represent its Fourier series.
Exercise 5.3.
Identify the errors in the following code and execute the corrected code:
sym x
l =5;
N= 5 ;
p=0
for n = 1 : 2 : 2 *N+1
p=p + ( 1 / n2 ) * sin ( npi / 2 ) cos ( n p i t / l ) sin ( npi x/ l )
end
y = ( 4 * l / pi ˆ 2 ) p