Second-Order System Example #3

MATLAB Code




%         ***** MATLAB Code Starts Here
%

%SECOND_ORDER_03_MAT

%

% G(s) = K/[s(s+p)]

%

% Determine the values for K and p so that the

% following specifications are satisfied.

PO_spec = 15; % required percent overshoot

Ts_spec = 2; % required settling time

% Standard form: G(s) = wn^2/[s(s+2*zeta*wn)]

% K = wn^2

% p = 2*zeta*wn

zeta = abs(log(PO_spec/100)) / sqrt(pi^2 + log(PO_spec/100)^2);

wn = 4 / (zeta * Ts_spec);

K = wn^2; % value for gain K

p = 2*zeta*wn; % value for open-loop pole

num = K; % open-loop numerator

den = [1 p 0]; % open-loop denominator

ncl = num; % closed-loop numerator

dcl = den + [0 0 num]; % closed-loop denominator

clp = roots(dcl); % closed-loop poles

slope = imag(clp(1))/abs(real(clp(1)));

t = linspace(0,5,1001);

ys = step(ncl,dcl,t);

PO = 100*(max(ys) - 1);

Ts = timesetl(t,ys);

yr = step(ncl,[dcl 0],t);

ess_ramp = 2*zeta/wn;

figure(1),clf,plot(t,ys),grid,xlabel('Time (s)'),ylabel('Amplitude'),...

title('Closed-Loop Step Response'),...

text(1.1,0.75,['PO = ' num2str(PO,'%0.4g') '%']),...

text(1.1,0.65,['T_s = ' num2str(Ts,'%0.4g') ' sec']),...

set(gcf,'Units','normalized','Position',[0 0.04 0.97 0.77])

figure(2),clf,plot(t,yr,[min(t) max(t)],[min(t) max(t)],'r--'),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('Closed-Loop Ramp Response'),...

text(2.1,0.75,['e_{ss} = ' num2str(ess_ramp,'%0.4g')]),...

set(gcf,'Units','normalized','Position',[0 0.04 0.97 0.77])

figure(3),clf,plot(real(clp),imag(clp),'b^',0,0,'rx',-p,0,'rx'),...

xlabel('Real Axis'),ylabel('Imag Axis'),title('Open-Loop and Closed-Loop Poles'),...

hold on,plot([-2 -2],[-4 4],'k:',[-5 0],slope*[5 0],'k:'),hold off,axis([-5 3 -4 4]),axis('square'),...

plotax,set(gcf,'Units','normalized','Position',[0 0.04 0.97 0.77])

%
%         ***** MATLAB Code Stops Here

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

Lastest revision on Wednesday, June 7, 2006 12:08 PM