-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatlabSimulation.m
64 lines (52 loc) · 1.67 KB
/
MatlabSimulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
s= tf('s');
Gol = 1/((2*s+1)*(s+1)*(0.5*s+1)); % defining the open loop transfer function
pidtool(Gol) % using the matlab builtin function pid controller
C = 9.007 + 1.88 * s; %after adjusting the pidtool,kp = 9.007 and kd=1.88 for phase margin of 25
% degree
G_uncompensated_cl = Gol / (1+Gol); % defining the uncompensated closed loop transfer function
G_compensated_cl = (C * Gol) /(1 + (C*Gol)); % defining the compensated closed loop transfer function
% the following gives you the response of the compensated and uncompensated systems
%impulse response
%------------------------
subplot(4,2,1);
impulse(G_uncompensated_cl);
title('impulse response for the uncompensated system');
xlabel('time')
ylabel('Amplitude')
subplot(4,2,2);
impulse(G_compensated_cl);
title('impulse response for the compensated system');
xlabel('time')
ylabel('Amplitude')
%-----------------------
%Step response
%------------------------
subplot(4,2,3);
step(G_uncompensated_cl);
title('step response for the uncompensated system');
xlabel('time')
ylabel('Amplitude')
subplot(4,2,4);
step(G_compensated_cl);
title('step response for the compensated system');
xlabel('time')
ylabel('Amplitude')
%-----------------------------------
% ramp response
%---------------------------------
subplot(4,2,5);
step((1/s) * G_uncompensated_cl);
title('ramp response for the uncompensated system');
xlabel('time')
ylabel('Amplitude')
subplot(4,2,6);
step((1/s)*G_compensated_cl);
title('ramp response for the compensated system');
xlabel('time')
ylabel('Amplitude')
%--------------------------------
%Bode Plot Representation for the compensated and the uncompensated
subplot(4,2,7);
margin(Gol);
subplot(4,2,8);
margin(C * Gol);