+ All Categories
Home > Documents > Matlab SysId Tutorial

Matlab SysId Tutorial

Date post: 22-Oct-2015
Category:
Upload: nguyen-trung
View: 46 times
Download: 0 times
Share this document with a friend
Description:
Matlab System Identification explanation.
23
Matlab System Identification 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
Transcript
Page 1: Matlab SysId Tutorial

Matlab System Identification Toolbox Quickstart

Chiara Masierohttp://automatica.dei.unipd.it/people/chiara-masiero/teaching.html

Department of Information EngineeringUniversity of Padova, Italy

16 febbraio 2012Version 1.0

C. Masiero (DEI - UniPD) Matlab SysId tutorial 1 / 23

Page 2: Matlab SysId Tutorial

System Identification

DataIdentification

data

Validationdata

Candidatemodel

Performancesanalysis

We need abetter model

Areperformances

ok?Done!

No

Yes

Matlab System Identification Toolbox: help ident

GUI (Graphical User Interface) version: ident

C. Masiero (DEI - UniPD) Matlab SysId tutorial 2 / 23

Page 3: Matlab SysId Tutorial

Outline

1 Data management

2 Model selection

3 Performances analysis

4 Conclusion

C. Masiero (DEI - UniPD) Matlab SysId tutorial 3 / 23

Page 4: Matlab SysId Tutorial

Data management

Signals generation - 1/2Input signals: some examples

» e = m+s*randn(100,1)Creates 100 samples of WGN with mean m and variance s2.

» u = idinput(N,TYPE)Generates input signals for identification. 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 SignalTYPE = RBS Random Binary SequenceTYPE = PRBS Pseudo Random Binary SignalTYPE = SINE Sum-of-sinusoid Signal

C. Masiero (DEI - UniPD) Matlab SysId tutorial 4 / 23

Page 5: Matlab SysId Tutorial

Data management

Signals generation - 2/2Output signals: some examples

Fed the filter H(z) = A(z)B(z) = b0+b1z−1+b2z−2

a0+a1z−1+a2z−2+a3z−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 . . . use the command filter: y=filter(B,A,u);2 . . . define H = H(z) by means of z=tf(’z’), then

y = lsim(H,u);3 . . . create a Simulink model.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 5 / 23

Page 6: Matlab SysId Tutorial

Data management

Data preprocessing - 1/2

Let u and y be the available input/output sequence (arrays ormatrices). First, put it in the form of an iddata object» data=iddata(y,u,Ts) % Ts is the sampling time.

“Elaborate” exampledata = iddata(y,u,0.08,’InputName’,’Power’,’InputUnit’,...’Watt’,’OutputName’,’Temperature’,’OutputUnit’,’C’);

The available data should be split into identification and validationdata.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 6 / 23

Page 7: Matlab SysId Tutorial

Data management

Data preprocessing 2/2

Usually you should remove offsets and linear trends from the data (e.g.if you want a linearized model which describes the system in theneighbourhood of an equilibrium point)» [detData, Trend]=detrend(data,TYPE)where data is the iddata object to process and TYPE can be either 0(offset removal) or 1 (linear trend removal)

Simulate the identified 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

Page 8: Matlab SysId Tutorial

Model selection

System Identification

Our framework: parametric identificationStarting point

choose a model class (ARMA, AR, BJ, etc. . . );

fix the model complexity.

Let’s give a look to frequently used model classes. . .

C. Masiero (DEI - UniPD) Matlab SysId tutorial 8 / 23

Page 9: Matlab SysId Tutorial

Model selection

Model classes 1/2

ARX: A(z)y(t) = B(z)u(t − nk) + e(t)

A(z) = 1 + a1z−1 + · · · + anaz−na , B(z) = b1 + b2z−1 + · · · + bnbz−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 + a1z−1 + · · · + anaz−na , B(z) = b1 + b2z−1 + · · · + bnbz−nb+1,

C (z) = 1 + c1z−1 + · · · + cnc z−nc .Matlab command» model=armax(data,[na nb nc nk])

C. Masiero (DEI - UniPD) Matlab SysId tutorial 9 / 23

Page 10: Matlab SysId Tutorial

Model selection

Model classes 2/2

OE: y(t) = B(z)F (z)u(t − nk) + e(t)

B(z) = b1 + b2z−1 + · · · + bnbz−nb+1, F (z) = 1 + f1z−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 + b2z−1 + · · · + bnbz−nb+1, F (z) = 1 + f1z−1 + · · · + fnf z

−nf ,C (z) = 1 + c1z−1 + · · · + cnc z−nc , D(z) = 1 + d1z−1 + · · · + dnd z−nd

Matlab command» model=bj(data,[nb nc nd nf nk])

C. Masiero (DEI - UniPD) Matlab SysId tutorial 10 / 23

Page 11: Matlab SysId Tutorial

Model selection

How to select a model class?

Physics can suggest some information about what kind of model weshould use;

What are our aims? e.g. prediction, control, model reduction, etc. . . ;

ARX modelsIf no additional information is provided, starting from an ARX model may agood idea:

1 Numerically efficients routines;2 Matlab provides useful tools in order to select the best model order;3 The identified AR models provides a starting point for the

identification of other models.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 11 / 23

Page 12: Matlab SysId Tutorial

Model selection

Order selection in Matlab - 1/4

AimSimplicity: 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 coefficients of the denominatorand the numerator of the candidate transfer function, respectively.The delayest command evaluates the ARX models described by

y(t) + · · · + any(t − na) = b1u(t − nk) + ... + bnu(t − nb − nk + 1)

for different values of nk e selects the value which exhibits the best fit.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 12 / 23

Page 13: Matlab SysId Tutorial

Model selection

Order selection in Matlab - 2/4

arxstruc compute the value of a loss function corresponding to ARXmodels of different orders

struc generates triples describing the orders of the ARX models to beconsidered by arxstruc

selstruc compares the values of the loss function for differentchoices 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

Page 14: Matlab SysId Tutorial

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 from1 to 10 and fixed delay of 3;

The best triple is given by» bestOrders = selstruc(V,0)

Validation dataThey are fundamental in prevent overfitting.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 14 / 23

Page 15: Matlab SysId Tutorial

Model selection

Order estimation in Matlab - 4/4

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

0 5 10 15 20 250

0.5

1

1.5

2

2.5Model Misfit vs number of par's

Number of par's

Une

xpla

ined

out

put v

aria

nce

(in %

) Red: Best Fit

Blue: AIC Choice

Green: MDL Choice

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

C. Masiero (DEI - UniPD) Matlab SysId tutorial 15 / 23

Page 16: Matlab SysId Tutorial

Performances analysis

Model validation and evaluation 1/6

Use validation data (which were not used to compute the candidatemodel, previously) to asses the quality of the model

For instance,resid(dataVal,model)computes an estimate ofthe correlation of theresidues and theconfidence interval withinthey should be (exceptfor the first one) in casethe model is good.

0 5 10 15 20 25−0.5

0

0.5

1Correlation function of residuals. Output Temperature

lag

−30 −20 −10 0 10 20 30−0.5

0

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

lag

C. Masiero (DEI - UniPD) Matlab SysId tutorial 16 / 23

Page 17: Matlab SysId Tutorial

Performances analysis

Model validation and evaluation 2/6

The command pzmap allows to analyse the zero-poles map of theidentified model:

−1 −0.5 0 0.5 1−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

0.90.80.70.60.50.40.30.20.1

π/T

0.9π/T

0.8π/T

0.7π/T

0.6π/T0.5π/T

0.4π/T

0.3π/T

0.2π/T

0.1π/T

π/T

0.9π/T

0.8π/T

0.7π/T

0.6π/T0.5π/T

0.4π/T

0.3π/T

0.2π/T

0.1π/T

From Power

To

Tem

pera

ture

» pzmap(arx223,’b’,arx423,’r’);

C. Masiero (DEI - UniPD) Matlab SysId tutorial 17 / 23

Page 18: Matlab SysId Tutorial

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:

52 54 56 58 60 62 64 66−15

−10

−5

0

5

10

Temperature. (sim)

Tem

pera

ture

(o C)

Measuredarx223; fit: 88.74%arx443; fit: 89.29%

Fit = 100×(1− ‖yh−y‖

‖y−y‖

)y : real outputy : sample meanyh: output provided by theidentified model.

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

C. Masiero (DEI - UniPD) Matlab SysId tutorial 18 / 23

Page 19: Matlab SysId Tutorial

Performances analysis

Model validation and evaluation 4/6

Example

Consider an ARX model. Do the orders [4 4 3] perform better thetriple [2 2 3]?

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

−1 −0.5 0 0.5 1−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1From Voltage

To

Tem

pera

ture

Overlapping confidence intervals suggest the presence of reductions.Therefore, the lower order model could be adequate.

C. Masiero (DEI - UniPD) Matlab SysId tutorial 19 / 23

Page 20: Matlab SysId Tutorial

Performances analysis

Model validation and evaluation 5/6

ExampleActually, compare suggests the effectiveness of an ARX model oforders [2 2 3]:

52 54 56 58 60 62 64 66−15

−10

−5

0

5

10

Temperature. (sim)

Tem

pera

ture

(o C)

Measuredarx223; fit: 88.74%arx443; fit: 89.29%

C. Masiero (DEI - UniPD) Matlab SysId tutorial 20 / 23

Page 21: Matlab SysId Tutorial

Performances analysis

Model validation and evaluation 6/6

Plot the Bode diagrams in order to analyse the frequency response ofthe model:

10−1

100

101

102

10−3

10−2

10−1

100

Am

plitu

de

From Power to Temperature

10−1

100

101

102

−600

−400

−200

0

Pha

se (

degr

ees)

Frequency (rad/s)

» bode(arx223,’b’,arx313,’r’)

C. Masiero (DEI - UniPD) Matlab SysId tutorial 21 / 23

Page 22: Matlab SysId Tutorial

Conclusion

Suggestions and references

Are you in a hurry?Micro SysId Toolbox manual: » help idhelp

Come into action!Official demos: » iddemo

Further readingsAll Matlab SysId can offer: » help ident

Official manual: http://www.mathworks.it/help/toolbox/ident/

C. Masiero (DEI - UniPD) Matlab SysId tutorial 22 / 23

Page 23: Matlab SysId Tutorial

[email protected]://automatica.dei.unipd.it/people/chiara-masiero/teaching.html


Recommended