0% found this document useful (0 votes)
4 views21 pages

Control LAB

The document contains MATLAB code for analyzing control systems using root locus and step response techniques. It includes the design of various controllers (PD, PI, and PID) for different transfer functions, along with calculations for settling time, overshoot, and dominant poles. Additionally, it provides graphical representations of the root locus and step responses for both uncompensated and compensated systems.

Uploaded by

leelanikhil14
Copyright
© All Rights Reserved
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)
4 views21 pages

Control LAB

The document contains MATLAB code for analyzing control systems using root locus and step response techniques. It includes the design of various controllers (PD, PI, and PID) for different transfer functions, along with calculations for settling time, overshoot, and dominant poles. Additionally, it provides graphical representations of the root locus and step responses for both uncompensated and compensated systems.

Uploaded by

leelanikhil14
Copyright
© All Rights Reserved
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

%QUESTION-01 Part-A

% Define Laplace variable

s = tf('s');

% Given transfer function


G = (s+6)/((s+2)*(s+3)*(s+5));

% Root locus plot


figure
rlocus(G)
grid on
title('Root Locus of G(s)')

%QUESTION-01 Part-B
% Given damping ratio
zeta = 0.707;

% Plot root locus with damping ratio line


figure
rlocus(G)
sgrid(zeta,20)
grid on
title('Root Locus with \zeta = 0.707')

% Select dominant pole manually


[k, p] = rlocfind(G);

1
Select a point in the graphics window

selected_point =
-2.2995 + 2.4793i

% Display gain
k

k =
5.2955

%QUESTION-01 Part-C
% Closed-loop transfer function
M = feedback(k*G, 1);

2
% Step response
figure
step(M)
grid on
title('Step Response of the Uncompensated System')

% Time-domain specifications
info1 = stepinfo(M);

T_s = [Link]

T_s =
1.7899

T_p = [Link]

T_p =
1.2999

wn = 4/(zeta*T_s)

wn =
3.1610

Kp = dcgain(k*G)

Kp =
1.0591

OS = exp((-zeta*pi)/sqrt(1 - zeta^2)) * 100;

disp(['Percent Overshoot = ', num2str(OS), ' %'])

Percent Overshoot = 4.3255 %

3
%QUESTION-01 Part-D
T_snew = T_s/2;
wn_new = 4/(zeta*T_snew);
wd_new = wn_new * (sqrt(1-(zeta)^2));
Sd = -zeta * wn_new + 1i*wd_new;
angle_at_dominant_pole=(180/pi)*(angle(polyval([1,6],Sd))-
(angle(polyval([1,2],Sd))+angle(polyval([1,3],Sd))
+angle(polyval([1,5],Sd))))

angle_at_dominant_pole =
-239.2412

z_c = 0.707 * wn_new + (wd_new)/tand(-(angle_at_dominant_pole))

z_c =
7.1305

% QUESTION-01 Part-E

Gc = (s + z_c);

G_comp = Gc * G;

figure
rlocus(G_comp)
sgrid(zeta,20)
grid on
title('Root Locus of PD Compensated System')

[kc, p_comp] = rlocfind(G_comp);

4
Select a point in the graphics window

selected_point =
-3.3641 + 3.4380i

M_comp = feedback(kc * G_comp, 1);

figure
step(M_comp)
grid on
title('Step Response of PD Compensated System')

5
info2 = stepinfo(M_comp);

T_s_comp = [Link]

T_s_comp =
1.1040

T_p_comp = [Link]

T_p_comp =
0.7511

OS_comp = [Link]

OS_comp =
5.1718

poles_comp = pole(M_comp);
dom_poles = poles_comp(abs(imag(poles_comp)) > 0);

wn_comp = abs(dom_poles(1))

wn_comp =
4.8259

zeta_comp = -real(dom_poles(1)) / wn_comp

zeta_comp =
0.7115

Question - 2

6
%QUESTION 2
% Define Laplace variable

clc;
clear;
close all;

%% Define plant
s = tf('s');
G = 1/((s)*(s+4)*(s+6)*(s+10));

%% (a) Root locus of uncompensated system


figure;
rlocus(G);
grid on;

zeta = 0.404; % 25% overshoot


sgrid(zeta,20);

%% Desired dominant pole (from specs)


wn = 4/(zeta*2); % Ts = 2 s
wd = wn*sqrt(1-zeta^2);
Sd = -zeta*wn + 1i*wd;

%% (b) PD controller (transient design)


z_d = 2.9;
PD = (s + z_d);

%% PI controller (steady-state design)

7
z_i = 0.01;
PI = (s + z_i)^2 / s^2;

%% Final PID controller


D = PD * PI;

%% Root locus of compensated system


figure;
rlocus(D*G);
grid on;
sgrid(zeta,20);

%% Gain selection
[K, ~] = rlocfind(D*G);

Select a point in the graphics window

8
selected_point =
-1.9240 + 4.8209i

%% (c) Step response


T = feedback(K*D*G,1);
figure;
step(T);
grid on;

%% Ramp response
t = 0:0.01:10;
r = t;

9
[y,t] = lsim(T,r,t);

figure;
plot(t,r,'--',t,y,'LineWidth',1.2);
grid on;
legend('Input ramp','Output');
xlabel('Time (s)');
ylabel('Response');

Question-3

clc;
clear;
close all;

%% Define plant
s = tf('s');
G = (s+5)/((s+2)*(s+3)*(s+7)*(s+10));

%% (a) Root locus of uncompensated system


figure;
rlocus(G);
grid on;

zeta = 0.8;
sgrid(zeta,20);

%% (b) Dominant poles and gain for zeta = 0.8


[K,p] = rlocfind(G);

10
Select a point in the graphics window

selected_point =
-2.4770 + 2.0661i

K =
53.7624

%% (c) Step response of uncompensated system


M = feedback(K*G,1);
figure;
step(M);
grid on;

11
%% Second-order approximation parameters
sigma = -real(p(3));
wd = imag(p(3));

wn = sqrt(sigma^2 + wd^2);
zeta_est = sigma/wn;

OS = exp(-zeta_est*pi/sqrt(1-zeta_est^2))*100;
Ts = 4/(zeta_est*wn)

Ts =
1.6067

Tp = pi/wd

Tp =
1.5197

Kp = dcgain(K*G);
Kp

Kp =
0.6400

%% (d) Lead compensator design (Ts = 1 s, zeta = 0.8)


wn_d = 4/(zeta*1);
Sd = -zeta*wn_d + 1i*wn_d*sqrt(1-zeta^2);

angle_at_dominant_pole = (180/pi)*( ...


angle(polyval([1 5],Sd)) ...
-( angle(polyval([1 2],Sd)) ...

12
+ angle(polyval([1 3],Sd)) ...
+ angle(polyval([1 7],Sd)) ...
+ angle(polyval([1 10],Sd)) ) );

%% Lead compensator (chosen from geometry)


D = (s+5)/(s+15);

%% Root locus of compensated system


figure;
rlocus(D*G);
grid on;
sgrid(zeta,20);

[Kc,pc] = rlocfind(D*G);

Select a point in the graphics window

13
selected_point =
-4.3548 + 3.3058i

%% (e) Step response of compensated system


Mc = feedback(Kc*D*G,1);
figure;
step(Mc);
stepinfo(Mc)

ans = struct with fields:


RiseTime: 0.3911
TransientTime: 1.1852
SettlingTime: 1.1852
SettlingMin: 0.5526
SettlingMax: 0.6391
Overshoot: 4.7178
Undershoot: 0
Peak: 0.6391
PeakTime: 0.8515

grid on;

14
Question-4

clc;
clear;
close all;

s = tf('s');
G = 1 / ((s + 2)*(s + 4)*(s + 6)*(s + 8));
rlocus(G);
zeta_target = 0.5;
sgrid(zeta_target, []);
title('Part (a): Root Locus of the Uncompensated System');
[k,p] = rlocfind(G)

15
Select a point in the graphics window

selected_point =
-1.5438 + 2.7273i
k =
371.6240
p = 4×1 complex
-8.5007 + 2.6935i
-8.5007 - 2.6935i
-1.4993 + 2.6935i
-1.4993 - 2.6935i

M = feedback(k*G, 1);

figure; % This opens a new, clean window for the step response
step(M);

16
p = pole(M);
% ... rest of your code
[~, idx] = sort(real(p), 'descend');
dom_p = p(idx(1:2));
wn = abs(dom_p(1))

wn =
3.0827

Kp = dcgain(k*G)

Kp =
0.9678

fprintf('Dominant Poles: %.4f + %.4fi and %.4f - %.4fi\n', ...


real(dom_p(1)), abs(imag(dom_p(1))), real(dom_p(2)),
abs(imag(dom_p(2))));

Dominant Poles: -1.4993 + 2.6935i and -1.4993 - 2.6935i

sys = stepinfo(M)

sys = struct with fields:


RiseTime: 0.5924
TransientTime: 2.8494
SettlingTime: 2.8494
SettlingMin: 0.4461
SettlingMax: 0.5682
Overshoot: 15.5277
Undershoot: 0
Peak: 0.5682
PeakTime: 1.4085

17
sigma = abs(real(dom_p(1)));
wd = abs(imag(dom_p(1)));
zeta_approx = sigma / wn;

OS_approx = exp((-zeta_approx * pi) / sqrt(1 - zeta_approx^2)) * 100

OS_approx =
17.3989

Ts_approx = 4 / sigma

Ts_approx =
2.6679

Tp_approx = pi / wd

Tp_approx =
1.1664

Ts_old = [Link];
Ts_new = Ts_old - 0.5;
fprintf('Old Ts = %.3f\n', Ts_old);

Old Ts = 2.849

fprintf('Required New Ts = %.3f\n', Ts_new);

Required New Ts = 2.349

zeta = 0.5;
wn_new = 4/(zeta*Ts_new);
sigma_new = zeta*wn_new;
wd_new = wn_new*sqrt(1-zeta^2);
Sd = -sigma_new + 1i*wd_new;
disp('Desired Dominant Pole Location = ');

Desired Dominant Pole Location =

disp(Sd);

-1.7026 + 2.9490i

z_lead = 4;
angles_G = -(angle(Sd+2) + angle(Sd+4) + angle(Sd+6) + angle(Sd+8)) *
180/pi;
theta_c = -180 - angles_G;
angle_z_lead = angle(Sd + z_lead) * 180/pi;
angle_p_lead = angle_z_lead - theta_c;
p_lead = sigma_new + (wd_new / tan(angle_p_lead * pi/180))

p_lead =
5.7308

G_lead = (s+z_lead)/(s+p_lead);

18
beta = 30;
z_lag = 0.00000001;
p_lag = z_lag/beta;
G_lag = (s+z_lag)/(s+p_lag);
Gc = G_lead * G_lag;
rlocus(Gc*G);
sgrid(zeta_target,[])
[Kc, poles_c] = rlocfind(Gc*G);

Select a point in the graphics window

selected_point =
-1.6820 + 3.1405i

T_comp = feedback(Kc*Gc*G, 1);

19
figure; % This creates a fresh window for the next plot
step(T_comp)

info_comp = stepinfo(T_comp)

info_comp = struct with fields:


RiseTime: 0.5131
TransientTime: 2.5797
SettlingTime: 2.5797
SettlingMin: 0.4765
SettlingMax: 0.6171
Overshoot: 17.4266
Undershoot: 0
Peak: 0.6171
PeakTime: 1.2428

pole(T_comp)

ans = 6×1 complex


-9.2639 + 3.2386i
-9.2639 - 3.2386i
-4.0000 + 0.0000i
-1.6016 + 3.0780i
-1.6016 - 3.0780i
-0.0000 + 0.0000i

Question-5

s = tf('s');

K = input('Enter the gain K = ');


G = input('Enter the transfer function G(s) = ');

L = K*G;

20
figure;
bode(L);
grid on;

[GM, PM] = margin(L);

GM

GM =
20.1600

PM

PM =
Inf

21

You might also like