Root Locus Design Example #1

MATLAB Code



%      ***** MATLAB Code Starts Here *****
%

%DSGN_421_ROOT_01_MAT

%

fig_size = [232 84 774 624]; % size for figures

olzp = [-4.7544]; % plant poles and zeros

olpp = [0; -0.04; -0.0839+j*0.9902; -0.0839-j*0.9902; -10.0004];

%

nump = 0.0106 * real(poly(olzp)); % plant numerator

denp = real(poly(olpp)); % and denominator

%

figure(1),clf,root_locus(nump,denp),title('Uncompensated System')

set(gcf,'Position',fig_size)

%

ess_spec = 0.2; % specifications

Ts_spec = 40;

%

Kvp = 0.0106 * abs(olzp / prod(olpp(2:5))); % plant velocity error constant

%

dclp = denp + [0 0 0 0 nump]; % plant closed-loop denominator

clpp = roots(dclp);

%

t = linspace(0,300,1001);

ys_p = step(nump,dclp,t);

figure(2),clf,plot(t,ys_p),grid,xlabel('Time (s)'),ylabel('Step Response')

title('Uncompensated System'),set(gcf,'Position',fig_size)

text(125,0.75,'PO = 40.4%, T_s = 193.2 s')

%

s1 = -0.1 + j*0.1; % desired closed-loop pole

%

figure(3),clf,root_locus(nump,denp),title('Uncompensated System, Zoomed View')

set(gcf,'Position',fig_size),...

axis([-1 1 -1 1]),hold on,plot(s1,'r*'),hold off,text(-0.17,0.16,'s_1')

%

% Design a single-stage phase lead compensator to make the root locus

% go through the point s1 and adjust the gain so that s1 is indeed a

% closed-loop pole

%

% Compute phase of plant at s1 and needed value of additional positive

% phase shift to be provided by the compensator

%

phps1 = (unwrap(angle(polyval(nump,s1))) - unwrap(angle(polyval(denp,s1)))) * 180/pi;

phcs1 = 180 - phps1;

%

zcd = 0.1; % lead compensator zero

phzcs1 = 90;

%

phpcs1 = phzcs1 - phcs1; % angle needed from compensator pole

d = imag(s1) / tan(phpcs1*pi/180);

pcd = d + abs(real(s1)); % lead compensator pole

%

numcd = [1 zcd]; % lead compensator numerator

dencd = [1 pcd]; % and denominator

%

[numf1,denf1] = series(numcd,dencd,nump,denp);

%

kcd = abs(polyval(denf1,s1)) / abs(polyval(numf1,s1)); % lead compensator gain

numf1 = kcd*numf1; numcd = kcd*numcd;

%

figure(4),clf,root_locus(numf1,denf1),title('Lead Compensated System')

set(gcf,'Position',fig_size)

%

figure(5),clf,root_locus(numf1,denf1),title('Lead Compensated System, Zoomed View')

set(gcf,'Position',fig_size),...

axis([-1 1 -1 1]),hold on,plot(s1,'r*'),hold off,text(-0.12,0.18,'s_1')

%

dclf1 = denf1 + numf1; % compensated closed-loop denominator

clpf1 = roots(dclf1);

%

ys_d = step(numf1,dclf1,t/5);

figure(6),clf,plot(t/5,ys_d),grid,xlabel('Time (s)'),ylabel('Step Response')

title('Lead Compensated System'),set(gcf,'Position',fig_size)

text(22,0.5,'PO = 21.2%, T_s = 39.6 s')

%

% Design a single-stage lag compensator to reduce the steady-state error

% to the specified value without moving the dominant closed-loop poles

% away from the point s = s1, other than a negligble amount

%

Kvd = Kvp*kcd*zcd/pcd;

essd = 1/Kvd; % actual steady-state error

%

alfag = essd / ess_spec; % necessary reduction in ess

%

zcg = abs(real(s1)) / 100; % lag compensator zero and pole

pcg = zcg / alfag;

%

numcg = [1 zcg]; % lag compensator numerator

dencg = [1 pcg]; % and denominator

%

[numf,denf] = series(numcg,dencg,numf1,denf1);

%

figure(7),clf,root_locus(numf,denf),title('Lag-Lead Compensated System, Zoomed View')

set(gcf,'Position',fig_size),axis([-1 1 -1 1])

hold on,plot(s1,'r*'),hold off,text(-0.12,0.18,'s_1')

%

figure(8),clf,root_locus(numf,denf),title('Lag-Lead Compensated System, Zoomed View')

set(gcf,'Position',fig_size),axis([-1 1 -1 1]*3e-03)

%

dclf = denf + numf; % compensated closed-loop denominator

clpf = roots(dclf);

%

ys_dg = step(numf,dclf,t/5);

figure(9),clf,plot(t/5,ys_dg),grid,xlabel('Time (s)'),ylabel('Step Response')

title('Lag-Lead Compensated System'),...

set(gcf,'Position',fig_size),text(22,0.5,'PO = 21.2%, T_s = 39.6 s')

%

t = linspace(0,6000,1001); % time vector

%

yrp = step(nump,[dclp 0],t); % ramp responses

yrf1 = step(numf1,[dclf1 0],t);

yrf = step(numf,[dclf 0],t);

%

figure(10),clf,plot(t,yrp,t,yrf1,t,yrf,[5990 6000],[5990 6000],'--'),grid,...

xlabel('Time (s)'),ylabel('Ramp Responses'),set(gcf,'Position',fig_size),...

title('Comparison of Ramp Responses'),axis([5990 6000 5990 6000]),...

text(5998.5,5990.5,'Plant'),text(5996.5,5993.3,'Lead'),text(5996.1,5995.6,'Lag-Lead')

%

%      ***** MATLAB Code Stops Here *****

Click the icon to return to the Dr. Beale's home page

Lastest revision on Friday, May 26, 2006 9:20 PM