0% found this document useful (0 votes)
99 views

Experiment 1 Fourier Series and Its Visualization

This document provides instructions and an example for an experiment on Fourier series and its visualization using MATLAB. The aim is to (1) compute Fourier coefficients, (2) obtain the Fourier series, and (3) visualize the Fourier series of periodic functions. An example computes the Fourier series of f(t)=t-t^2 from -π to π up to the second harmonic and visualizes the results. Self-check exercises are provided to practice writing MATLAB code to find Fourier series for other functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Experiment 1 Fourier Series and Its Visualization

This document provides instructions and an example for an experiment on Fourier series and its visualization using MATLAB. The aim is to (1) compute Fourier coefficients, (2) obtain the Fourier series, and (3) visualize the Fourier series of periodic functions. An example computes the Fourier series of f(t)=t-t^2 from -π to π up to the second harmonic and visualizes the results. Self-check exercises are provided to practice writing MATLAB code to find Fourier series for other functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Applications of

Differential and Difference Equations


(MAT2002)
LAB
Experiment 1
Fourier series and its visualization

Department of Mathematics

Vellore Institute of Technology,


Vellore - 632014 (TN)

December 9, 2019
Fourier series and its visualization Experiment 1

1 Aim

The aim of this experiment is to


(a) compute the Fourier coefficients,

(b) obtain the Fourier Series, and

(c) visualize the Fourier series


of a periodic function defined on an interval whose length equals to the period.

2 Mathematical Description

A real-valued function f (t) of real variable t is periodic, if

f (t + τ) = f (x) for all t, for some τ > 0, (2.1)

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

where a0 , an , bn , n = 1, 2, ... are the Fourier coefficients. The linear combinations


 nπt   nπt 
Hn = an cos + bn sin , n = 1, 2, ... (2.3)
l l
are called first, second, ... harmonics.

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

ADDE(MAT2002) - ELA 1 Department of Mathematics


Fourier series and its visualization Experiment 1

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.

(a) Matlab code



clc
clear
close a l l
syms t n
f = input ( ' Enter the f u n c t i o n f ( t ) = ' ) ;
L = input ( ' Enter Lower l i m i t : ' ) ;
U= input ( ' Enter upper l i m i t : ' ) ;
l = (U−L ) / 2 ;
disp ( ' F o u r i e r C o e f f i c i e n t s : ' )
a0 = i n t ( f , t , L , U) / l
a ( n ) = i n t ( f * cos ( ( n* pi * t ) / l ) , t , L , U) / l
b ( n ) = i n t ( f * sin ( ( n* pi * t ) / l ) , t , L , U) / l
disp ( ' Harmonics : ' )
f s 1 = a ( 1 ) * cos ( pi * t / l ) + b ( 1 ) * sin ( pi * t / l )
f s 2 = a ( 2 ) * cos ( 2 * pi * t / l ) + b ( 2 ) * sin ( 2 * pi * t / l )
disp ( ' F o u r i e r S e r i e s upto second harmonic : ' )
f s ( t ) = a0 /2+ f s 1 + f s 2
ezplot ( f , [ L U] )
hold on
grid on
ezplot ( fs , [ L U] )
legend ( ' f ( t ) ' , ' f s ( t ) ' )
t i t l e ( ' Fourier Series of f ( t ) ' )
 

(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

ADDE(MAT2002) - ELA 2 Department of Mathematics


Fourier series and its visualization Experiment 1


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

ADDE(MAT2002) - ELA 3 Department of Mathematics


Fourier series and its visualization Experiment 1

(c) f (t) = t 3 for all −π < t < π, n = 3

(d) f (t) = |t| for all −π < t < π, n = 4

(e) f (t) = sint 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
 

ADDE(MAT2002) - ELA 4 Department of Mathematics

You might also like