Professional Documents
Culture Documents
20bme0672 Exp1
20bme0672 Exp1
20bme0672 Exp1
REGISTER NUMBER:
20BME0676
DIFFERENCE EQUATIONS
LAB SLOT : L43+L44
GUIDED BY : UDHAYAKUMAR R
NAME: Chaitanya Kumar
Reg No.:20BME06762
Reg No.
EQUATIONS (MAT2002) LAB EXPERIMENT -1A
FOURIER SERIES AND ITS VISUALIZATION
AIM:
KEY WORDS:
Harmonics:
NAME: Chaitanya Kumar
Reg No. :20BME0672
MATLAB CODE:
clc
clear
close all
syms t n
f = input ( ' Enter the function f ( t ) = ' ) ;
L= input ( ' Enter Lower limit : ' ) ;
U= input ( ' Enter upper limit : ' ) ;
l = (U-L) / 2 ;
disp ( ' Fourier Coefficients : ' )
a0 = int ( f , t , L ,U)/ l;
a(n) = int (f*cos((n*pi*t)/l),t,L,U)/l
b(n) = int (f*sin((n*pi*t)/l),t,L,U)/l
disp ( ' Harmonics : ' )
fs1 = a ( 1 ) *cos ( pi * t / l ) + b ( 1 ) * sin ( pi * t / l );
fs2 = a ( 2 ) *cos (2 *pi * t / l ) + b ( 2 ) * sin (2 *pi * t / l );
disp ( ' Fourier Series upto second harmonic : ' )
fs ( t ) = a0 /2+ fs1 + fs2;
ezplot ( f , [ L U ] )
hold on
grid on
ezplot ( fs , [ L U ] )
legend ( ' f( t ) ' , ' fs( t ) ' )
title ( ' Fourier Series off ( t ) ' )
INPUT:
OUTPUT:
Fourier Coefficients:
a0 =
-(2*pi^2)/3
a(n) =
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)
fs(t) =
AIM:
To obtain and visualize the first few harmonics of the Fourier
series of a given function f(x) using Matlab.
KEYWORDS:
NAME: Chaitanya Kumar
Reg No. :20BME0672
MATLAB CODE:
clc
clear
close all
syms x
X=input('Enter X= ');
Y=input('Enter Y= ');
n=length(X);
c=(X(n)-X(1))/2;
a0 = 2*sum(Y (1:n-1))/(n-1)
a1 = 2*sum(Y(1:n-1).*cos(1*pi*X(1:n-1)/c))/(n-1)
b1 = 2*sum(Y(1:n-1).*sin(1*pi*X(1:n-1)/c))/(n-1)
a2 = 2*sum(Y(1:n-1).*cos(2*pi*X (1:n-1)/c))/(n-1)
b2 = 2*sum(Y(1:n-1).*sin(2*pi*X(1:n-1)/c))/(n-1)
fs(x)= a0/2+ a1 *cos(1*pi*x/c)+b1*sin(1*pi*x /c) + a2*cos(2*pi*x/c) +
b2*sin(2*pi*x/c);
stem(X,Y)
hold on
grid on
ezplot(fs,[X(1) X(n)])
title('Fourier series fs(X) upto 2nd harmonic ')
legend('Data','fs(x)')
INPUT:
Enter X =
[0 pi/6 2*pi/6 3*pi/6 4*pi/6 5*pi/6 pi]
Enter Y =
[0 9.2 14.4 17.8 17.3 11.7 0]
NAME: Chaitanya Kumar
Reg No. :20BME0672
OUTPUT:
a0 =
23.4667
a1 =
-7.7333
b1 =
-1.5588
a2 =
-2.8333
b2 =
0.1155
NAME: Chaitanya Kumar
Reg No. :20BME0672
GRAPHS: