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

Names:-Ali Nawaz Ranjha: COMSATS-Lancaster Dual Degree Programme

1. The document describes a MATLAB code that models and simulates the response of a two-mass spring system. The code defines transfer functions relating displacement/velocity to force for different masses and inputs an impulse and step function. 2. The code then simulates and plots the system response. It also calculates maximum angular velocities and positions. 3. The code is then modified to input a sinusoidal function instead of a step and simulates the new system response under this input. It again plots and calculates maximums.

Uploaded by

Ali Nawaz Ranjha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Names:-Ali Nawaz Ranjha: COMSATS-Lancaster Dual Degree Programme

1. The document describes a MATLAB code that models and simulates the response of a two-mass spring system. The code defines transfer functions relating displacement/velocity to force for different masses and inputs an impulse and step function. 2. The code then simulates and plots the system response. It also calculates maximum angular velocities and positions. 3. The code is then modified to input a sinusoidal function instead of a step and simulates the new system response under this input. It again plots and calculates maximums.

Uploaded by

Ali Nawaz Ranjha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

COMSATS-Lancaster Dual Degree

Programme

Names:-Ali Nawaz Ranjha

Registeration # DDP-FA10-BTE-008

Control Systems Lab

Lab Session 5:Q#7 of book


(a)Impulse response:Output of system when input is impulse.
Writing our transfer function

Matlab code:%---------------------------% Question#7 ch#3


%---------------------------K=input('enter value of spring constant:\n');
D=input('enter value of coefficient of viscous friction:\n');
J=input('enter value of moment of inertia:\n');
M1=input('enter value of first mass:\n');
M2=input('enter value of second mass:\n');
%relating displacement to force
num1=[K]
den1=[M2.*M1 D.*M2 (K.*M2+K.*M1) D.*K 0]
sys1=tf(num1,den1)
num2=[M1 D K]
den2=[M2.*M1 D.*M2 (K.*M2+K.*M1) D.*K 0]
sys2=tf(num2,den2)
t=0:0.01:10;
x=heaviside(t);
subplot(2,2,1)
lsim(sys1,x,t)
grid on
subplot(2,2,2)
lsim(sys2,x,t)
grid on
%relating velocity to force
num3=[K]
den3=[M2.*M1 D.*M2 (K.*M2+K.*M1) D.*K]
sys3=tf(num3,den3)
num4=[M1 D K]
den4=[M2.*M1 D.*M2 (K.*M2+K.*M1) D.*K]
sys4=tf(num4,den4)
subplot(2,2,3)
lsim(sys3,x,t)
grid on
subplot(2,2,4)
lsim(sys4,x,t)
grid on

Results:-

>>enter value of spring constant:


2
>>enter value of coefficient of viscous friction:
5
>>enter value of moment of inertia:
6
>>enter value of first mass:
10
>>enter value of second mass:
15
num1 =
2

den1 =
150 75 50 10

Transfer function:
2
-------------------------------150 s^4 + 75 s^3 + 50 s^2 + 10 s

num2 =
10

den2 =
150 75

50 10

Transfer function:
10 s^2 + 5 s + 2
-------------------------------150 s^4 + 75 s^3 + 50 s^2 + 10 s

num3 =
2

den3 =
150 75 50 10

Transfer function:
2
---------------------------150 s^3 + 75 s^2 + 50 s + 10

num4 =

10

den4 =
150 75 50 10

Transfer function:
10 s^2 + 5 s + 2
---------------------------150 s^3 + 75 s^2 + 50 s + 10

Linear Simulation Results

Linear Simulation Results

1.5

Amplitude

Amplitude

1.5
1

0.5

1
0.5

10

Time (seconds)
Linear Simulation Results

Linear Simulation Results


1

Amplitude

Amplitude

10

Time (seconds)

0.5

5
Time (seconds)

Q1(manual):Matlab code:-

10

0.5

5
Time (seconds)

10

%---------------------------% Question#2
%---------------------------J=3.2284E-6;
b=3.5077E-6;
Kt=0.0274;
Kb=0.0274;
R=4;
L=2.75E-6;
num=[Kt];
den=[J.*L (b.*L+J.*R) (b.*R+Kb.*Kt)];
sys=tf(num,den)
t=0:0.001:0.4;
for var=-4:1:4
x=var.*heaviside(t);
lsim(sys,x,t)
hold on
grid on
title('step response of speed control')
x=lsim(sys,x,t);
max_angular_velocity=x(length(x)-1)
end
num1=[Kt./R.*J];
den1=[1 (b.*R+Kb.*Kt)./R.*J 0];
sys1=tf(num1,den1)
figure
for var1=-4:1:4
x1=var1.*heaviside(t);
lsim(sys1,x1,t)
hold on
grid on
title('step response of position control')
x1=lsim(sys1,x,t);
max_angular_position=x1(length(x1)-1)
end

Results:Transfer function:
0.0274
----------------------------------------8.878e-012 s^2 + 1.291e-005 s + 0.0007648

max_angular_velocity =
-143.3072

max_angular_velocity =
-107.4804

max_angular_velocity =
-71.6536

max_angular_velocity =
-35.8268

max_angular_velocity =
0

max_angular_velocity =
35.8268

max_angular_velocity =
71.6536

max_angular_velocity =
107.4804

max_angular_velocity =
143.3072

Transfer function:
2.211e-008
-----------------s^2 + 6.173e-010 s

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

max_angular_position =
2.3121e-007

step response of speed control


150

100

Amplitude

50

-50

-100

-150

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.3

0.35

0.4

Time (seconds)

step response of position control


4
3.5
3

Amplitude

2.5
2
1.5
1
0.5
0
-0.5

0.05

0.1

0.15

0.2
Time (seconds)

0.25

Q3(manual):Matlab code:%---------------------------% Question#3


%---------------------------J=3.2284E-6;
b=3.5077E-6;
Kt=0.0274;
Kb=0.0274;
R=4;
L=2.75E-6;
num=[Kt];
den=[J.*L (b.*L+J.*R) (b.*R+Kb.*Kt)];
sys=tf(num,den)
t=0:0.001:0.4;
x=5.*sin(310.*t);
lsim(sys,x,t)
grid on
title('response of speed control using sinusoidal input')
x=lsim(sys,x,t);
max_angular_velocity=x(length(x)-1)
num1=[Kt./R.*J];
den1=[1 (b.*R+Kb.*Kt)./R.*J 0];
sys1=tf(num1,den1)
figure
x1=5.*sin(310.*t);
lsim(sys1,x1,t)
hold on
grid on
title('response of position control using sinusoidal input')
x1=lsim(sys1,x,t);
max_angular_position=x1(length(x1)-1)

Results:-

response of speed control using sinusoidal input


60
50
40
30

Amplitude

20
10
0
-10
-20
-30
-40

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.35

0.4

Time (seconds)

response of position control using sinusoidal input


5
4
3
2

Amplitude

1
0
-1
-2
-3
-4
-5

0.05

0.1

0.15

0.2
Time (seconds)

0.25

0.3

You might also like