Vous êtes sur la page 1sur 23

Matlab System Identication Toolbox Quickstart

Chiara Masiero
http://automatica.dei.unipd.it/people/chiara-masiero/teaching.html Department of Information Engineering University of Padova, Italy 16 febbraio 2012 Version 1.0

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

1 / 23

System Identication
We need a better model

No

Data

Identication data

Candidate model

Performances analysis

Are performances ok?

Yes
Done!

Validation data

Matlab System Identication Toolbox: help ident GUI (Graphical User Interface) version: ident
C. Masiero (DEI - UniPD) Matlab SysId tutorial 2 / 23

Outline

Data management Model selection Performances analysis Conclusion

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

3 / 23

Data management

Signals generation - 1/2


Input signals: some examples

e = m+s*randn(100,1) Creates 100 samples of WGN with mean m and variance s 2 . u = idinput(N,TYPE) Generates input signals for identication. In particular:
N = [Ns Nu] Input signal with Nu channels (each of Ns samples); N = [P Nu M] Input signal with Nu channels, with period P, of length M P ; TYPE = RGS Random Gaussian Signal TYPE = RBS Random Binary Sequence TYPE = PRBS Pseudo Random Binary Signal TYPE = SINE Sum-of-sinusoid Signal

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

4 / 23

Data management

Signals generation - 2/2


Output signals: some examples

A(z ) b0 +b1 z +b2 z Fed the lter H (z ) = B (z ) = a0 +a1 z 1 +a2 z 2 +a3 z 3 with input u : A = [a0 a1 a2 a3]; B = [b0 b1 b2]; In order to compute the output signal y in Matlab you can. . .
1 2

. . . use the command filter: y=filter(B,A,u); . . . dene H = H (z ) by means of z=tf(z), then y = lsim(H,u); . . . create a Simulink model.

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

5 / 23

Data management

Data preprocessing - 1/2

Let u and y be the available input/output sequence (arrays or matrices). First, put it in the form of an iddata object data=iddata(y,u,Ts) % Ts is the sampling time. Elaborate example data = iddata(y,u,0.08,InputName,Power,InputUnit,... Watt,OutputName,Temperature,OutputUnit,C); The available data should be split into identication and validation data.

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

6 / 23

Data management

Data preprocessing 2/2

Usually you should remove osets and linear trends from the data (e.g. if you want a linearized model which describes the system in the neighbourhood of an equilibrium point) [detData, Trend]=detrend(data,TYPE) where data is the iddata object to process and TYPE can be either 0 (oset removal) or 1 (linear trend removal) Simulate the identied model in proximity of the working point input = detData(:,[],:) % Input signal ylin = sim(model,input) % No trend is considered ytotal = retrend(ylin,Trend) % Add trend

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

7 / 23

Model selection

System Identication

Our framework: parametric identication Starting point choose a model class (ARMA, AR, BJ, etc. . . ); x the model complexity. Lets give a look to frequently used model classes. . .

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

8 / 23

Model selection

Model classes 1/2

ARX: A(z )y (t ) = B (z )u (t nk ) + e (t ) A(z ) = 1 + a1 z 1 + + ana z na , B (z ) = b1 + b2 z 1 + + bnb z nb +1 . Matlab command model=arx(data,[na nb nk]) ARMAX: A(z )y (t ) = B (z )u (t nk ) + C (z )e (t ) A(z ) = 1 + a1 z 1 + + ana z na , B (z ) = b1 + b2 z 1 + + bnb z nb +1 , C (z ) = 1 + c1 z 1 + + cnc z nc . Matlab command model=armax(data,[na nb nc nk])

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

9 / 23

Model selection

Model classes 2/2


B (z ) F (z ) u (t

OE: y (t ) =

nk ) + e (t )

B (z ) = b1 + b2 z 1 + + bnb z nb +1 , F (z ) = 1 + f1 z 1 + + fnf z nf Matlab command model=oe(data,[nb nf nk]) BJ: y (t ) =


B (z ) F ( z ) u (t

nk ) +

C (z ) D (z ) e (t )

B (z ) = b1 + b2 z 1 + + bnb z nb +1 , F (z ) = 1 + f1 z 1 + + fnf z nf , C (z ) = 1 + c1 z 1 + + cnc z nc , D (z ) = 1 + d1 z 1 + + dnd z nd Matlab command model=bj(data,[nb nc nd nf nk])

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

10 / 23

Model selection

How to select a model class?


Physics can suggest some information about what kind of model we should use; What are our aims? e.g. prediction, control, model reduction, etc. . . ; ARX models If no additional information is provided, starting from an ARX model may a good idea:
1 2 3

Numerically ecients routines; Matlab provides useful tools in order to select the best model order; The identied AR models provides a starting point for the identication of other models.

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

11 / 23

Model selection

Order selection in Matlab - 1/4


Aim Simplicity: use models with low complexity whenever you can. Order selection also depends on delay estimate: NK = delayest(DATA,NA,NB) where NA and NB are the number of coecients of the denominator and the numerator of the candidate transfer function, respectively. The delayest command evaluates the ARX models described by
y (t ) + + an y (t na ) = b1 u (t nk ) + ... + bn u (t nb nk + 1)

for dierent values of nk e selects the value which exhibits the best t.
C. Masiero (DEI - UniPD) Matlab SysId tutorial 12 / 23

Model selection

Order selection in Matlab - 2/4

arxstruc compute the value of a loss function corresponding to ARX models of dierent orders struc generates triples describing the orders of the ARX models to be considered by arxstruc selstruc compares the values of the loss function for dierent choices of the order and select the best Example V = arxstruc(dataId,dataVal,struc(2,2,1:10)); [bestOrders,Vm] = selstruc(V,0);

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

13 / 23

Model selection

Order selection in Matlab - 3/4

V = arxstruc(dataId,dataVal,struc(1:10,1:10,3)); Compute the loss function for ARX models of orders nA and nB from 1 to 10 and xed delay of 3; The best triple is given by bestOrders = selstruc(V,0) Validation data They are fundamental in prevent overtting.

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

14 / 23

Model selection

Order estimation in Matlab - 4/4

selstruc provide an interactive GUI: bestOrders = selstruc(V)


Model Misfit vs number of par's 2.5

Green: MDL Choice Blue: AIC Choice


2 Unexplained output variance (in %)

Red: Best Fit

1.5

0.5

10 15 Number of par's

20

25

selctruc also allows to take into account other criteria in order to select the best order, like AIC and MDL.

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

15 / 23

Performances analysis

Model validation and evaluation 1/6


Use validation data (which were not used to compute the candidate model, previously) to asses the quality of the model For instance, resid(dataVal,model) computes an estimate of the correlation of the residues and the condence interval within they should be (except for the rst one) in case the model is good.
C. Masiero (DEI - UniPD)

Correlation function of residuals. Output Temperature 1 0.5 0 0.5 0

10 lag

15

20

25

Cross corr. function between input Power and residuals from output Temperature 0.5

0.5 30

20

10

0 lag

10

20

30

Matlab SysId tutorial

16 / 23

Performances analysis

Model validation and evaluation 2/6


The command pzmap allows to analyse the zero-poles map of the identied model:
From Power 1 0.8 0.6 0.4 To Temperature 0.2 0.9/T 0.8/T 0.7/T 0.5/T 0.6/T 0.4/T 0.1 0.3/T 0.2 0.3 0.4 0.2/T 0.5 0.6 0.7 0.1/T 0.8 0.9

/T 0 /T 0.2 0.4 0.6 0.8 1 1 0.8/T 0.7/T 0.6/T 0.4/T 0.5/T 0 0.3/T 0.2/T 0.9/T 0.1/T

0.5

0.5

pzmap(arx223,b,arx423,r);
C. Masiero (DEI - UniPD) Matlab SysId tutorial 17 / 23

Performances analysis

Model validation and evaluation 4/6


In order to valuate a model and compare it with others candidates, you can turn to compare:
Temperature. (sim) Measured arx223; fit: 88.74% arx443; fit: 89.29% 10

5 Temperature (o C)

Fit = 100 1

yh y y y

10

15 52

y : real output : sample mean y yh : output provided by the identied model.


54 56 58 60 62 64 66

compare(dataVal,arx223,b,arx423,r)

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

18 / 23

Performances analysis

Model validation and evaluation 4/6


Example Consider an ARX model. Do the orders [4 4 3] perform better the triple [2 2 3]?
From Voltage 1 0.8 0.6 0.4 To Temperature

arx443 = arx(dataId,[4 4 3]); zpplot(arx443,3)

0.2 0 0.2 0.4 0.6 0.8 1 1

0.5

0.5

Overlapping condence intervals suggest the presence of reductions. Therefore, the lower order model could be adequate.
C. Masiero (DEI - UniPD) Matlab SysId tutorial 19 / 23

Performances analysis

Model validation and evaluation 5/6


Example Actually, compare suggests the eectiveness of an ARX model of orders [2 2 3]:
Temperature. (sim) Measured arx223; fit: 88.74% arx443; fit: 89.29% 10

5 Temperature (o C)

10

15 52

54

56

58

60

62

64

66

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

20 / 23

Performances analysis

Model validation and evaluation 6/6


Plot the Bode diagrams in order to analyse the frequency response of the model:
10 Amplitude 10 10 10
0

From Power to Temperature

10

10

10

10

0 Phase (degrees) 200 400 600 1 10

10

10 Frequency (rad/s)

10

bode(arx223,b,arx313,r)
C. Masiero (DEI - UniPD) Matlab SysId tutorial 21 / 23

Conclusion

Suggestions and references

Are you in a hurry? Micro SysId Toolbox manual: help idhelp Come into action! Ocial demos: iddemo Further readings All Matlab SysId can oer: help ident Ocial manual: http://www.mathworks.it/help/toolbox/ident/

C. Masiero (DEI - UniPD)

Matlab SysId tutorial

22 / 23

chiara.masiero@dei.unipd.it
http://automatica.dei.unipd.it/people/chiara-masiero/teaching.html

Vous aimerez peut-être aussi