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

Mathalb 1 Fourier

The document discusses Fourier series and provides examples of using MATLAB code to calculate the Fourier series expansion of different periodic functions over given intervals. The Fourier series representation decomposes a function into the sum of its harmonic components. The examples demonstrate finding the Fourier series for various functions up to a given number of harmonics.

Uploaded by

Puneet Purohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Mathalb 1 Fourier

The document discusses Fourier series and provides examples of using MATLAB code to calculate the Fourier series expansion of different periodic functions over given intervals. The Fourier series representation decomposes a function into the sum of its harmonic components. The examples demonstrate finding the Fourier series for various functions up to a given number of harmonics.

Uploaded by

Puneet Purohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Mathematics

School of Advanced Sciences


MAT 2002 – Applications of Differential and Difference Equations(MATLAB)
Experiment 1–A
Fourier Series

Fourier Series: The Fourier Series of a periodic function f ( x) of period 2l defined on


a 
 nx   nx 
the interval (    2l ) is given by f ( x)  0   a n cos   bn sin   , where the
2 n 1  l   l 
Fourier coefficients a0 , an , bn , n  0,1, 2, ... can be evaluated by the following formulae
  l
1
a0 
l  f ( x)dx ,

  l
1  nx 
an 
l 

f ( x) cos
 l 
dx ,
  l
1  nx 
bn 
l 

f ( x) sin 
 l 
dx .

In the Fourier series the term (a1 cos x  b1 sin x ) is called the Fundamental Harmonic/First
Harmonic, (a2 cos 2 x  b2 sin 2 x) is called the Second Harmonic and so on.

MATLAB Syntax Used:


syms var1 var2 Creates symbolic variables var1 and var2
disp(x) Displays the contents of x without printing the
variable name
int(expr,var,a,b) Evaluates the definite integral of expr with respect
to var from a to b.
ezplot(fun,[xmin,xmax]) Plot the function fun over the domain (xmin,
xmax).

MATLAB Code:

clear all
close all
clc
syms x
f =input('Enter the function of x: ');
I=input('Enter the interval of [a,b]: ');
m=input('Enter the number of Harmonics required: ');
a=I(1);b=I(2);
L=(b-a)/2;
a0=(1/L)*int(f,a,b);
Fx=a0/2;
for n=1:m
figure;
an(n)=(1/L)*int(f*cos(n*pi*x/L),a,b);
bn(n)=(1/L)*int(f*sin(n*pi*x/L),a,b);
Fx=Fx+an(n)*cos(n*pi*x/L)+bn(n)*sin(n*pi*x/L);
Fx=vpa(Fx,4);
ezplot(Fx,[a,b]);

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 1


hold on
ezplot(f,[a,b]);
title(['Fourier Series with ',num2str( n ),'harmonics']);
legend('Fourier Series', 'Function Plot');
hold off
end
disp(strcat('Fourier series with', num2str(n),'harmonics
is:',char(Fx)))

Example: To find the Fourier series expansion of the function f ( x)  x  x 2 ,    x  


upto 3 harmonics.

Input:
Enter the function of x: x-x^2
Enter the interval of [a,b]: [-pi,pi]
Enter the number of Harmonics required: 3

Output:
Fourier series with3harmonics is:0.4444*cos(3.0*x) - 1.0*sin(2.0*x)
- 1.0*cos(2.0*x) + 0.6667*sin(3.0*x)

Example: To find the Fourier series expansion up to 5 harmonics for the function
 2x
1   ;    x  0
f ( x)  
2x
 1 ; 0  x  
 

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 2


Input:
Enter the function of x: (1+2*x/pi)*(heaviside(x+pi)-heaviside(x))+
(1-2*x/pi)*(heaviside(x)-heaviside(x-pi))
Enter the interval of [a,b]: [-pi,pi]
Enter the number of Harmonics required: 5

Output:

Fourier series with5harmonics is:0.03242*cos(5.0*x) +


0.09006*cos(3.0*x) + 0.8106*cos(x)

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 3


Exercise:

1. Find the Fourier series expansion of the following functions:


 1;  2  x  0
a) f ( x)   , f ( x  4)  f ( x)
 1; 0  x  2
 0;  2  x  0
b) f ( x)   , f ( x  4)  f ( x)
 4; 0  x  2
c) f ( x)  e  x in the interval 0  x  2 , given that f ( x  2 )  f ( x) .

2. A sinusoidal voltage E sin  t , where t is time, is passed through a half-wave


rectifier that clips the negative portion of the wave. Find the Fourier series of
 0;   /   t  0
the resulting periodic function f (t )   ,
 E sin  t ; 0  t   / 
f (t  2   f (t ) , with E  5 ,    .

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 4

You might also like