Professional Documents
Culture Documents
REG.NO : 20BME0672
DIFFERENCE EQUATIONS
GUIDED BY : UDHAYAKUMAR R
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR
AIM:
KEY WORDS:
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR
QUESTION 1 :
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)
harmonic: fs(t) =
GRAPHS
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR
Experiment 1-B
COMPUTATION OF HARMONICS OF FOURIER SERIES
THROUGH NUMERICAL DATA
AIM:
KEY WORDS:
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR
Question 2 :
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
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR
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]
OUTPUT:
a0 =
23.4667
a1 =
-7.7333
b1 =
-1.5588
a2 =
-2.8333
b2 = 0.1155
Graphs :
REGISTER NUMBER : 20BME0672
NAME : CHAITANYA KUMAR