You are on page 1of 13

Matlab Tutorial for State Space Analysis and System Identification CS851 Feedback Control for Computing Systems

Vibha Prasad (vibha cs! 1. Overview of Tutorial "evie# of Chapter $ and 1% &'amples follo#ed in the (utorial - S)S* System+ (andem ,ueue &'ample - -)-* System+ .pache /((P Server Specifying 0() systems #ith space1state models Vie#ing system response .nalysis of system Controller 2esign (ools System )dentification

2. Review of C apter ! and 1" "efer to the slides3 #. $%amples followed in t e Tutorial a. SISO System& Tandem 'ueue $%ample

x1 ( k +1! = %315 x1 ( k ! + %3%47u ( k ! x 8 ( k +1! = %364 x1 ( k ! + %345 x 8 ( k ! y ( k ! = x1 ( k ! + x 8 ( k !


% %315 A= %364 %345 %3%47 (= % C = [1 1]

b. MIMO System& Apac e )TT* Server

x1 ( k +1! = %356 x1 ( k ! %311x 8 ( k ! %3%%85u1 ( k ! + %3%%%66u 8 (k ! x 8 ( k +1! = %3%84 x1 ( k ! + %345 x 8 (k ! %3%%%85u1 ( k ! + %3%%%88u 8 (k ! y1 ( k ! = x1 ( k ! y 8 ( k ! = x 8 (k !
%356 A = %3%84 %311 %3%%85 ( = %345 %3%%%85 %3%%%66 1 C = %3%%%88 % % 1

+. Specifyin, -TI systems wit space.state models Commands to cover+ ss9 ssdata9 get9 set9 ss8tf9 ss8:p9 ss8ss9 tf8ss9 :p8ss .fter system identification9 the ne't step is to specify the model of the system mathematically9 #hich #ill help us to understand and analy:e the system3 .s #e already kno# the coefficients and the constants from system )29 #e can directly plug them in to get ready for further analysis3 Sometimes9 #e might be interested in converting the state1space model to a transfer function model or a :ero1pole1gain model3 For e'ample9 in a -)-* system9 the relationship bet#een an input and an output might not be apparent from the state space e;uations or .9 <9 C9 23 Converting to a transfer function model or a :ero1pole1gain model might give us a clearer idea of ho# the output directly relates to the input3 a. Specifyin, a State space model
% Initialize the coefficients for % SISO system: Tandem Queue example A1 = !"1# !$ !"%& !"&#'$ (1 = !"!&)$ !'$ *1 = 1 1'$ % +1 = !'$ tandem = ss,A1- (1- *1- !- -1.$

% Initialize the coefficients for % /I/O system: Apache 0TT1 Ser2er example A3 (3 *3 +3 = = = = !"4% -!"11$ -!"!3& !"&#'$ -!"!!54 !"!!!%%$ -!"!!!34 !"!!!35'$ 1 !$ ! 1'$ ! !$ ! !'$

apache = ss,A3- (3- *3- +3- -1.$ % 6et information a7out the system A- (- *- +- ts' = ssdata,tandem. A- (- *- +- ts' = ssdata,apache. % 6et system properties 8et,tandem.$ 8et,apache-9a9. a = 8et,tandem- 9a9. % set system properties set,tandem- 9a9- : 1 !$ ! 1';. set,apache- 9Input<ame9-:9=eepAli2e9-9/ax*lients9;9Output<ame9-:9*1>9-9/?/9;.$ %print the ne@ 2alues 8et,apache- 9Input<ame9. 8et,apache- 9Output<ame9. 8et,tandem- 9a9.

b. Convertin, from one model to anot er i. /rom state space model


% con2ert the state space model % to other models % transfer function model % SISO System num- den' = ss3tf,A1- (1- *1- !- 1.

% /I/O System

% Transfer functions for the first input num1- den1' = ss3tf,A3- (3- *3- +3- 1. % Transfer functions for the second input num3- den3' = ss3tf,A3- (3- *3- +3- 3. % directly applyin8 tf,sys. % returns a transfer function o7Aect 0 = tf,tandem. % /I/O System 0 = tf,apache. % Bero-pole-8ain model % SISO System B- 1- =' = ss3zp,A1- (1- *1- !- 1. % /I/O System % Bero- 1ole- 6ain for the first input B1- 11- =1' = ss3zp,A3- (3- *3- +3- 1. % Bero- 1ole- 6ain for the second input B3- 13- =3' = ss3zp,A3- (3- *3- +3- 3. % directly applyin8 zpC,sys. % returns a B1= o7Aect 0 = zpC,tandem. % /I/O System 0 = zpC,apache. % State Space model % eDui2alency property % enter 2ector T as parameter % in the eDuation @,C. = Tx,C. % Suppose T = 3 1$ # 3' 3 1$ # 3'.

A- (- *- +' = ss3ss,A1- (1- *1- !-

ii. To state space model

% con2ertin8 to the state space model % from other models % Only applica7le to sin8le input models % Transfer Eunction /odel % SISO System A- (- *- +' = tf3ss,num- den. % SI/O System A- (- *- +' = tf3ss,num1- den1. % Bero-pole-8ain /odel % SISO System A- (- *- +' = zp3ss,B- 1- =. % note: con2ertin8 a system 7acC to state space % from its transfer function % may not 8i2e the same system 7acC ss,tf,tandem.. ss,tf,apache.. ss,zpC,tandem.. ss,zpC,apache..

0. 1iewin, system response Commands to cover+ step9 dstep9 impulse9 dimpulse9 lsim9 ltivie# (he system response describes ho# the output changes over time3 <y looking at the output9 #e might be able to infer additional properties of the system9 like the settling time9 ma'imum overshoot9 steady1state output etc3 =e can compute the value of the property #e are interested in9 and if it is not acceptable (according to the given specification of the system!9 #e can repeat the system identification process to come up #ith a model #hich is a better appro'imation of the system3
step,tandem.$ y- t- x' = step,tandem. %x 8i2es the state traAectories % @e can plot the state 2aria7les @ith the output % and see ho@ they affect the output plot,t- x,:-1.-FrF.$ plot,t- x,:-3.-F8F.$

hold on

plot,t- y-F7F.$ for impulse si8nal of duration 1! impulse,apache- 1:1!.$ % if the second parameter is specified % for the command step or impulse% it indicates the duration for @hich % @e are interested in 2ie@in8 the system response % dstep and dimpulse % let you 2ie@ the effect of one input on the outputs % in a /I/O system % step response for the first input dstep,A3-(3- *3- +3- 1- #!.$ % impulse response for the second input dimpulse,A3-(3- *3- +3- 3- #!.$ % % % % periodic si8nal 8enerator can 8enerate sDuare- sin or pulse sDuare si8nal @ith period 4duration #! and samplin8 time !"1 u- t' = 8ensi8,9sDuare9- 4- #!- !"1.$

plot,t- u- 9r9.$ axis, ! 3! -!"4 1"4'. % lsim allo@s us to 2ie@ the effect of different si8nals % for the inputs on the system lsim,tandem- u.$ lsim,apacheu uG#'.$

% dlsim is specifically for discrete-time linear systems % SISO System dlsim,A1- (1- *1- !- u.$ % /I/O System dlsim,A3- (3- *3- +3-

u uG#'.$

2. Analysis of system Commands to cover+ poles9 eig9 roots9 poly9 p:map9 ctrb9 det9 inv9 obsv 2uring system identification9 the model has to be analy:ed for t#o reasons+

> >

to ensure that the model structure suits the system9 and to iteratively find a model that appro'imates the system #ell3

(he easiest #ay of analy:ing a system is by looking at the poles of the system3 (he location of the poles contains a lot of information about the system3 .s the system analyst kno#s ho# certain properties of the system affect its behavior (in a given model!9 #ith the given range of permissible values given (in the specification!9 the model can be iteratively refined to accurately model the system3 (he state1space models have certain characteristics that are not present in transfer function models3 Controllability means that for any state ' d9 there is a se;uence of inputs that #ill drive the system to that state3 Similarly9 observability means that all the states of the system can be inferred by observing the measured output3 a. Stability Analysis
% analysis of a system % % p r characteristic polynomial det,zI - A. SISO system = poly,A1. = roots,p.

%/I/O system p = poly,A3. r = roots,p. % Or @e can find the ei8en2alues of A % SISO system ei8,A1. %/I/O system ei8,A3. % Or @e can find directly find the poles of the system % SISO system pole,tandem. %/I/O system pole,apache. % It is useful to looC at the pole-zero confi8uration % SISO system pzmap,tandem.

. too large order model #ill sho# up here as the poles and :eros #ill almost cancel leading to pole1:ero cancellation3 =e can use this kno#ledge to reduce the order of the model #ithout losing much accuracy3 b. Controllability
%controlla7ility *O = ctr7,apache. %*O,:- :- A1-""" A<.contain the controlla7ility matrix *O< = *O,:- #:%. % This matrix must 7e in2erti7le for % the system to 7e controlla7le % calculate the determinant of the matrix % to checC @hether the matrix is non-sin8ular det,*O<. %calculate the in2erse of a matrix in2,*O<.

c. Observability
%o7ser2a7ility O = o7s2,apache.$ %O,:- :- A1-""" A<.contain the o7ser2a7ility matrix

O( = O,#:%- :.$
%This matrix must 7e in2erti7le for the system to 7e o7ser2a7le

det,O(.$
in2,O(.$

!. Controller 3esi,n Tools Commands to cover+ rlocus9 rlocusfind9 place9 acker9 l;r9 dl;r 2esigning a controller means choosing the appropriate gains3 (he gain values can be changed by moving the poles of the system3 (his can be done manually #ith command like rlocus and rlocfind or techni;ues like pole placement or 0," control design can be used3 .n important thing to note is that if the computed value of gain is too large9 the system #ill overreact9 resulting in controller1induced variability and possible limit cycles3 *n the other hand9 having smaller gains #ould mean longer settling time3 (hus9 finding the optimal value for gain is the main consideration in controller design3

a. Root locus .ccording to the ?P@ model9 the transfer function can be #ritten as+ /(:! A @(num(:!Bden(:!! #here @ is a gain and num(:! and den(:! contain the coefficients of the e;uation containg the :eros and poles of the system3 (he root locus is a plot of the roots of the closed loop transfer function as the gain is varied3
% compute and plot the root locus rlocus,num- den. % find 8ains for the 8i2en set of roots r- C' = rlocus,tandem.$ % To customize the plot for a specific ran8e of = % say for = ran8in8 from ! to 4 rlocus,num-den- !:4.$ rlocus,tandem- !:4.$ %interacti2ely select the pole location rlocfind,tandem.$ %rlocus and rlocfind can 7e used only for SISO systems

b. *ole placement )f #e #ant to achieve a specific settling time and ma'imum overshoot9 #e can calculate the dominant pole by back1calculating from the e;uations+ ksC A 16Blog(D rD! and -PC A rEBDFD3 (he rest of the poles should be GplacedH so that their effect is negligible3 Suppose that the specification for the tandem ;ueue is that the settling time is no greater than 5 minutes and the ma'imum overshoot does not e'ceed 5I3 Jsing ksC A 5 and -PC A %3%59 #e get the dominant poles as ( %35 K %3551$L!3
% pole placement

% static state feed7acC examples % ?xample 1: Cs = 4- /p = !"!4 Cs = 4$

/p = !"!4$ %findin8 dominant poles r = exp,-%HCs. theta = pi I lo8,r.Hlo8,/p. % con2ertin8 to cartesian form J-K' = pol3cart,theta-r. 1 = JGiIK J-iIK'

% Eindin8 the 8ains usin8 the dominant poles = = place,A1- (1- 1. % A similar function is acCer % acCer @orCs for only SISO system % @hereas place can 7e used for /I/O systems acCer,A1- (1- 1.

Mo# suppose that the specification is modified so that ksC A 1 and -PC A %3%59 #e get the dominant poles as (1 %3%%71 K %3%14L!3
% ?xample 3: Cs = 1- /p = !"!4 Cs = 1$ /p = !"!4$ %findin8 dominant poles r = exp,-%HCs. theta = pi I lo8,r.Hlo8,/p. % con2ertin8 to cartesian form J-K' = pol3cart,theta-r. 1 = JGiIK J-iIK' % Eindin8 the 8ains usin8 the dominant poles = = place,A1- (1- 1. % dynamic state feed7acC example Cs = 4$ /p = !"!4$ % find dominant poles r = exp,-%HCs.

theta = pi I lo8,r.Hlo8,/p.
% con2ertin8 to cartesian form J-K' = pol3cart,theta-r.

%The third pole should 7e at most 34% of the dominant pole !"34 I r % taCin8 the third pole as !"1 1 = JGiIK J-iIK !"1' A# = (# = =# = !"1# ! !$ !"%& !"&# !$ -1 -1 1' !"!&)$ !$ !' ! ! -1'$

% Eindin8 the 8ains = = place,A#- (#- 1.

c. -'R Optimal Control 3esi,n .n alternative approach to look at gains is by considering the trade1off bet#een control effort and control error3 -inimi:ing the control error improves accuracy and reduces both settling time and overshoot3 -inimi:ing the control effort minimi:es systemNs sensitivity to noise3 (he obLective is to minimi:e a #eighted sum of control error and control effort3 Control errors are ;uantified by the s;uared values of the state variables9 #hich are the offsets from the operating point3 Control effort is ;uantified by the s;uare of u(k!9 the difference bet#een the control input and its operating point3
LQM %?xample 1: A = !"1# ! !$ !"%& !"&# !$ 1 1 1' ( = !"!&)$ !$ !' Q = dia8, 1 1 1!!'.

% the cost D,#-#. associated @ith control error x# is 1!! % times the cost of the rest of the control errors" % x# @ill ha2e a hea2y influence on the 8ain 2alues M = 1 % the cost of control effort is the same % as that for control error = = dlDr,A- (- Q- M.

Setting ;595 to 1 and hence giving e;ual #eight to all control errors3
%?xample 3:

Q = dia8, 1 1 1'. = = dlDr,A- (- Q- M.

4. System Identification (he purpose of system identification is to get a model that can be used for controller design3 . lo#est order model #hich appro'imates the system is desirable3 . good model should capture all the essential information about the system3 System Identification Toolbo%

System )dentification (oolbo' is a collection of -.(0.< functions for creating mathematical models of dynamic systems from e'perimental data3 )t has features for processing e'perimental data and is used for testing the appropriateness of various models by optimi:ing the values of model parameters3
ident

.n ."O model is specified in ident as+ .(;! y(t! A <(;!u(t > nk! P e(t! y(t! P a1y(t > 1! P 333 P anay(t > na! A b1u(t > nk! P 333 P bnb(t > nk > nb P 1! P e(t! nb corresponds to the no3 of b parameters and not the degree of the polynomial3 (he parameter nk denote the time delay in the system3 1! )mport data3 (o create a data set from input and output signals available in the #orkspace9 select )mport data1Q(ime domain data )mport data1Q2ata *bLect

8! &'amine the data3 (here are three vie#s for e'amining data sets3 Rou can generate these vie#s for selected data sets by selecting the corresponding checkbo' in the 2ata Vie#s area of the ident #indo#3 (ime Plot

5! Preprocess the data3 Preprocess pop1up menu in the ident #indo# contains commands for creating ne# data sets based on the =orking 2ata set3

Select channels Select e'periments -erge e'periments Select range "emove means "emove trends Filter "esample (ransform data

6! &stimate -odel based on data3 &stimate pop1up menu in the ident #indo# provides methods for estimating models based on the =orking 2ata set3 Parametric models *pens a dialog that allo#s you to generate dynamic linear models #ith different structures9 orders9 and delays3

5! .naly:e the model3 (here are si' vie#s for e'amining models3 Rou can generate these vie#s for selected models by selecting the corresponding check bo' in the -odel Vie#s area of the ident #indo#3 (he vie#s of our interest are+ -odel *utput (ransient "esp (or "esponse! ?eros and Poles 0() Vie#er

4! &'port the data3 2ata and models do not automatically produce a variable in the -.(0.< #orkspace3 Rou must e'port any variables in a data set or model by dragging their icons into the (o =orkspace icon in the ident #indo#

You might also like