Computation

Visualization
Programming
User ’s Guide
Lennart Ljung
Syst em Ident ificat ion
Toolbox
For Use wi th MA TLAB
®
How to Conta ct The Ma thW orks:
508-647-7000 Phone
508-647-7001 Fax
The Mat hWor ks, Inc. Mail
24 Pr ime Par k Wa y
Nat ick, MA 01760-1500
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP ser ver
comp.soft-sys.matlab Newsgr oup
support@mathworks.com Technical suppor t
suggest@mathworks.com Pr oduct enhancement suggest ions
bugs@mathworks.com Bug r epor t s
doc@mathworks.com Document a t ion er r or r epor t s
subscribe@mathworks.com Subscr ibing user r egist r at ion
service@mathworks.com Or der st at us, license r enewals, pa sscodes
info@mathworks.com Sales, pr icing, and gener al infor mat ion
S yst em Ident ificat ion Toolbox User’s Guide
© COPYRIGHT 1988 - 1997 by The Mat hWor ks, Inc. All Right s Reser ved.
The soft wa r e descr ibed in t his document is fur nished under a license agr eement . The soft wa r e may be used
or copied only under t he t er ms of t he license a gr eement . No par t of t his manual may be phot ocopied or r epr o-
duced in any for m wit hout pr ior wr it t en consent fr om The Mat hWorks, Inc.
U.S. GOVERNMENT: If Licensee is acquir ing t he Pr ogr ams on beha lf of a ny unit or a gency of t he U.S.
Gover nment , t he following sha ll apply: (a ) For unit s of t he Depar t ment of Defense: t he Gover nment shall
ha ve only t he r ight s specified in t he license under which t he commer cial comput er soft war e or commer cial
soft war e document at ion was obt a ined, a s set for t h in subpar a gr aph (a) of t he Right s in Commercial
Comput er Soft war e or Commer cial Soft war e Document at ion Clause at DFARS 227.7202-3, t her efor e t he
r ight s set for t h her ein shall apply; and (b) For any ot her unit or a gency: NOTICE: Not wit hst anding a ny
ot her lease or license agr eement t hat ma y per t ain t o, or accompa ny t he deliver y of, t he comput er soft war e
a nd accompanying document a t ion, t he r ight s of t he Gover nment r egar ding it s use, repr oduct ion, and disclo-
sur e ar e a s set for t h in Clause 52.227-19 (c)(2) of t he FAR.
MATLAB, Simulink, Ha ndle Gr aphics, and Real-Time Wor kshop ar e r egist er ed t ra demar ks and St at eflow
a nd Tar get La nguage Compiler ar e t r ademar ks of The Mat hWor ks, Inc.
Ot her pr oduct or br a nd na mes a re t r adema r ks or r egist er ed t r adema r ks of t heir r espect ive holders.
Pr int ing Hist or y: Apr il 1988 First print ing
J uly 1991 Second pr int ing
May 1995 Thir d pr int ing
August 1995 Repr int
¤
FAX
u
@
i v
Contents
1
The System Identi fi cati on Problem
What is Syst em Ident ifica t ion? . . . . . . . . . . . . . . . . . . . . . . . 1-2
How is t hat done? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
How do you know if t he model is any good? . . . . . . . . . . . . . . 1-2
Can t he qualit y of t he model be t est ed in ot her ways? . . . . . 1-2
What models ar e most common? . . . . . . . . . . . . . . . . . . . . . . 1-2
Do you have t o assume a model of a par t icular t ype? . . . . . . 1-2
What does t he Syst em Ident ificat ion Toolbox cont ain? . . . . 1-2
Isn’t it a big limit at ion t o wor k only wit h linear models? . . . 1-3
How do I get st a r t ed? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Is t his r ea lly all t her e is t o Syst em Ident ificat ion? . . . . . . . . 1-3
The Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
The Ba sic Dynamic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Var iant s of Model Descr ipt ions . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
How t o Int er pr et t he Noise Sour ce . . . . . . . . . . . . . . . . . . . . . . . 1-7
Ter ms t o Char a ct er ize t he Model Pr oper t ies . . . . . . . . . . . . . . . 1-9
Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
St ep Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Fr equency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Zer os and Poles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Model Unst able . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Feedback in Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Noise Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Model Or der . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Addit ional Input s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Nonlinea r Effect s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
St ill Pr oblems? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Fit Bet ween Simula t ed and Mea sur ed Out put . . . . . . . . . . 1-15
Residua l Analysis Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Pole Zer o Cancellat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
What Model St r uct ur es Should be Test ed? . . . . . . . . . . . . . 1-15
Mult ivar iable Syst ems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Available Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Wor king wit h Subset s of t he Input Out put Cha nnels . . . . 1-17
Some Pr a ct ical Advice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17
v Contents
Readi ng More About Sys t e m Ide nti fi cat i on . . . . . . . . . . . . . . . 1-19
2
The Graphi cal User Inte rface
The Model and Dat a Boar ds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
The Wor king Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
The Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
The Validat ion Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
The Wor k Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Management Aspect s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Wor kspace Var iables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Help Text s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Dat a Repr esent at ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Get t ing Dat a int o t he GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Ta king a Look at t he Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Pr epr ocessing Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Det r ending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Select ing Dat a Ra nges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Pr efilt er ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Quickst ar t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Checklist for Dat a Ha ndling . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Simulat ing Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Dir ect Est ima t ion of t he Impulse Response . . . . . . . . . . . . . . . 2-14
Dir ect Est ima t ion of t he Fr equency Response . . . . . . . . . . . . . 2-15
Est imat ion of Par amet r ic Models . . . . . . . . . . . . . . . . . . . . . . . 2-17
Est imat ion Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Result ing Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
How t o Know Which St r uct ur e and Met hod t o Use . . . . . . . 2-19
ARX Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
The St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Ent er ing t he Or der Par amet er s . . . . . . . . . . . . . . . . . . . . . . 2-20
Est imat ing Ma ny Models Simult aneously . . . . . . . . . . . . . . 2-20
Est imat ion Met hods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Mult i-Out put Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
vi
ARMAX, Out put -Er r or and Box-J enkins Models . . . . . . . . . . . 2-22
The Gener al St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
The Special Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Ent er ing t he Model St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Est imat ion Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
St at e-Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
The Model St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Ent er ing Bla ck-Box St at e-Space Model St r uct ur es . . . . . . . 2-24
Est imat ing Ma ny Models Simult aneously . . . . . . . . . . . . . . 2-24
Est imat ion Met hods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
User Defined Model St r uct ur es . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
St at e-Space St r uct ur es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Any Model St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Views and Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
The Plot Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Opt ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
St yle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Fr equency Response and Dist ur bance Spect r a . . . . . . . . . . . . 2-29
Tr ansient Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Poles and Zer os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Compa r e Measur ed and Model Out put . . . . . . . . . . . . . . . . . . . 2-30
Residual Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Text Infor mat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32
Pr esent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32
Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32
Fur t her Ana lysis in t he MATLAB Wor kspace . . . . . . . . . . . . . 2-32
Mouse But t ons and Hot keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
The Main ident Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
Plot Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
Tr oubleshoot ing in Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35
Layout Quest ions and idpr efs.mat . . . . . . . . . . . . . . . . . . . . . . 2-35
Cust omized Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Impor t fr om a nd Expor t t o Wor kspace . . . . . . . . . . . . . . . . . . . 2-36
What Cannot be Done Using t he GUI . . . . . . . . . . . . . . . . . . . 2-37
vi i Contents
3
Tutori al
Impulse Responses, Fr equency Funct ions, and Spect r a . . . . . . 3-8
Polynomial Repr esent at ion of Tr ansfer Funct ions . . . . . . . . . 3-10
St at e-Space Repr esent at ion of Tr ansfer Funct ions . . . . . . . . . 3-13
Cont inuous-Time St a t e-Space Models . . . . . . . . . . . . . . . . . . . 3-14
Est imat ing Impulse Responses . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
Est imat ing Spect r a and Fr equency Funct ions . . . . . . . . . . . . . 3-16
Est imat ing Par amet r ic Models . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
Subspace Met hods for Est imat ing St at e-Space Models . . . . . . 3-18
Dat a Repr esent at ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Cor r ela t ion Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Spect r al Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
ARX Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22
AR Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
Gener al Polynomial Black-Box Models . . . . . . . . . . . . . . . . . . . 3-23
St at e-Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25
Opt ional Va r iables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26
Polynomial Black-Box Models . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Mult ivar iable ARX Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
St at e-Space Models wit h Fr ee Par amet er s . . . . . . . . . . . . . . . 3-33
Discr et e-Time Innova t ions For m . . . . . . . . . . . . . . . . . . . . . 3-33
Syst em Dynamics Expr essed in Cont inuous Time . . . . . . . 3-33
The Bla ck-Box, Discr et e-Time Case . . . . . . . . . . . . . . . . . . . 3-34
St at e-Space Models wit h Coupled Par amet er s . . . . . . . . . . . . 3-36
St at e-Space St r uct ur es: Init ia l Values and
Numer ical Der ivat ives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Some Examples of User -Defined Model St r uct ur es . . . . . . . . . 3-38
Thet a For mat : t h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40
Fr equency Funct ion For ma t : ff . . . . . . . . . . . . . . . . . . . . . . . . . 3-41
Zer o-Pole For mat : zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43
St at e-Space For ma t : ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43
Tr ansfer Funct ion For mat : t f . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
Polynomial For mat : poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45
The ARX For ma t : ar x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45
Tr ansfor mat ions Bet ween Discr et e and Cont inuous Models . 3-46
Cont inuous-Time Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46
Discr et e-Time Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46
Tr ansfor mat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
Simulat ion and Pr edict ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
vi i i
Compa r ing Differ ent St r uct ur es . . . . . . . . . . . . . . . . . . . . . . . . 3-49
Checking Pole-Zer o Cancella t ions . . . . . . . . . . . . . . . . . . . . . . . 3-51
Residual Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-52
Noise-Fr ee Simulat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-53
Assessing t he Model Uncer t aint y . . . . . . . . . . . . . . . . . . . . . . . 3-53
Compa r ing Differ ent Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-54
Condit ioning of t he Pr edict ion Er r or Gr adient . . . . . . . . . . . . 3-55
Select ing Model St r uct ur es for Mult iva r iable Syst ems . . . . . . 3-55
Offset Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-58
Out lier s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-58
Filt er ing Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-58
Feedback in Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-59
Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-59
The Basic Algor it hm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-61
Choosing an Adapt at ion Mecha nism and Ga in . . . . . . . . . . . . 3-62
Availa ble Algor it hms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-65
Segment at ion of Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-67
Time Ser ies Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-68
The Sa mpling Int er va l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-70
Out of Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-71
Memor y-Speed Tr ade-Offs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-72
Regula r izat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-72
Local Minima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-73
Init ia l Par amet er Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-73
Linear Regr ession Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-74
Spect r um Nor malizat ion and t he Sampling Int er val . . . . . . . 3-75
Int er pr et at ion of t he Loss Funct ion . . . . . . . . . . . . . . . . . . . . . 3-77
Enumer at ion of Est imat ed Par amet er s . . . . . . . . . . . . . . . . . . 3-78
Complex-Valued Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-79
St r ange Result s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-79
4
Command Reference
i x Contents

1
The Syst em Ident ificat ion
Pr oblem
Bas i c Que st i ons About Sys te m Ident i fi cat i on . . . . . . . . . . . 1-2
Common Te rms Us e d i n Sys te m Ide nt i fi cat i on . . . . . . . . . . 1-4
Bas i c Informat i on About Dynami c Mode l s . . . . . . . . . . . . . . 1-5
The Basi c Ste ps of Syst e m Ide nt i fi cat i on . . . . . . . . . . . . . . 1-10
A Start up Ide nt i fi cat i on Proce dure . . . . . . . . . . . . . . . . . . . 1-12
Re adi ng More About Sys te m Ide nt i fi cat i on . . . . . . . . . . . . . 1-18
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-2
1. Basic Questions About System Identification
What is System Identification?
Syst em Ident ificat ion allows you t o build ma t hemat ical models of a dynamic
syst em based on measur ed dat a.
How is tha t done?
Essent ia lly by adjust ing pa r amet er s wit hin a given model unt il it s out put
coincides as well as possible wit h t he measur ed out put .
How do you know if the model is a ny good?
A good t est is t o t ake a close look at t he model’s out put compar ed t o t he
measur ed one on a dat a set t ha t wasn’t used for t he fit (“Validat ion Dat a”).
Can the qua lity of the model be tested in other w a ys?
It is also valuable t o look at what t he model couldn’t r epr oduce in t he dat a (“t he
r esiduals”). This should not be cor r elat ed wit h ot her a vailable infor mat ion,
such a s t he syst em's input .
What models are most common?
The t echniques apply t o ver y gener al models. Most common models ar e
differ ence equat ions descr ipt ions, such as ARX and ARMAX models, as well as
all t ypes of linear st at e-space models.
Do you have to assume a model of a par ticular type?
For par amet r ic models, you have t o specify t he st r uct ur e. However , if you just
assume t ha t t he syst em is linear , you can dir ect ly est imat e it s impulse or st ep
r esponse using Cor r elat ion Ana lysis or it s fr equency r esponse using Spect r al
Analysis. This allows useful compar isons wit h ot her est imat ed models.
What does the System Identification Toolbox conta in?
It cont ains a ll t he common t echniques t o adjust par a met er s in all kinds of
linear models. It also allows you t o examine t he models’ pr oper t ies, a nd t o
check if t hey ar e any good, as well as t o pr epr ocess and polish t he measur ed
dat a .
1-3
Isn’t it a big limitation to w ork only w ith linear models?
No, act ually not . Most common model nonlinear it ies ar e such t hat t he
measur ed dat a should be nonlinear ly t r ansfor med (like squar ing a volt age
input if you t hink t hat it ’s t he power t hat is t he st imuli). Use physical insight
about t he syst em you ar e modeling and t r y out such t r a nsfor mat ions on models
t hat a r e linear in t he new var iables, a nd you will cover a lot !
How do I get started?
If you ar e a beginner , br owse t hr ough Cha pt er and t hen t r y out a couple of t he
dat a set s t hat come wit h t he t oolbox. Use t he gr aphical user int er face (GUI)
and check out t he built -in help funct ions t o under st a nd what you a r e doing.
Is this rea lly all there is to System Identification?
Act ually, t her e is a huge amount wr it t en on t he subject . Exper ience wit h r ea l
dat a is t he dr iving for ce t o under st and mor e. It is impor t ant t o r emember t hat
any est imat ed model, no mat t er how good it looks on your scr een, has only
picked up a simple r eflect ion of r ealit y. Sur pr isingly oft en, however , t his is
sufficient for r a t ional decision making.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-4
2. Common Terms Used in System Identification
This sect ion defines some of t he t er ms t hat ar e fr equent ly used in Syst em
Ident ificat ion.
• Es t i mat i on Dat a is t he dat a set t ha t is used t o fit a model t o dat a. In t he
GUI t his is t he same as t he Worki ng Dat a.
• Vali dat i on Dat a is t he da t a set t hat is used for model validat ion pur poses.
This includes simulat ing t he model for t hese dat a and comput ing t he
r esiduals fr om t he model when applied t o t hese dat a.
• Mode l Vi e ws ar e var ious ways of inspect ing t he pr oper t ies of a model. They
include looking at zer os and poles, t r a nsient a nd fr equency r esponse, and
simila r t hings.
• Dat a Vi e ws a r e var ious ways of inspect ing pr oper t ies of dat a set s. A most
common and useful t hing is just t o plot t he dat a and scr ut inize it .
So-called out liers could be det ect ed t hen. These ar e unr elia ble
measur ement s, per ha ps ar ising fr om fa ilur es in t he measur ement
equipment . The fr equency cont ent s of t he da t a signals, in t er ms of
per iodogr a ms or spect r al est imat es, is a lso most r evealing t o st udy.
• Mode l Se t s or Mode l St ruct ure s ar e families of models wit h adjust able
par amet er s. Parame t e r Es t i mati on a mount s t o finding t he “best ” values
of t hese par amet er s. The Syst em Ident ificat ion pr oblem amount s t o finding
bot h a good model st r uct ur e and good numer ical va lues of it s par amet er s.
• Parame t ri c Ide nt i fi cat i on Me thods ar e t echniques t o est imat e
par amet er s in given model st r uct ur es. Basically it is a mat t er of finding (by
numer ical sear ch) t hose numer ical values of t he pa r amet er s t hat give t he
best agr eement bet ween t he model’s (simulat ed or pr edict ed) out put and t he
measur ed one.
• Nonparame tri c Ide nt i fi cati on Met hods ar e t echniques t o est imat e
model beha vior wit hout necessar ily using a given par amet r ized model set .
Typica l nonpar a met r ic met hods include Corre l at i on anal ys i s , which
est imat es a syst em’s impulse r esponse, and Spe ct ral anal ys i s , which
est imat es a syst em’s fr equency r esponse.
• Mode l Val i dati on is t he pr ocess of gaining confidence in a model.
Essent ially t his is achieved by “t wist ing and t ur ning” t he model t o scr ut inize
all aspect s of it . Of par t icular impor t a nce is t he model’s abilit y t o r epr oduce
t he behavior of t he Validat ion Dat a set s. Thus it is impor t ant t o inspect t he
pr oper t ies of t he r esiduals fr om t he model when a pplied t o t he Validat ion
Dat a .
1-5
3. Basic Information About Dynamic Models
Syst em Ident ificat ion is about building Dynami c Mode l s. Some knowledge
about such models is t her efor e necessar y for successful use of t he t oolbox.The
t opic is t r ea t ed in sever al places in t he Chapt er and t her e is a wide r ange of
t ext books availa ble for int r oduct or y and in-dept h st udies. For basic use of t he
t oolbox, it is sufficient t o have quit e super ficial insight s about dynamic models.
This sect ion descr ibes such a basic level of knowledge.
The Signals
Models descr ibe r elat ionships bet ween measur ed signals. It is convenient t o
dist inguish bet ween i nput signals and out put signals. The out put s ar e t hen
par t ly det er mined by t he input s. Think for example of a n air pla ne wher e t he
input s would be t he differ ent cont r ol sur faces, ailer ons, elevat or s, and t he like,
while t he out put s would be t he air plane’s or ient at ion and posit ion. In most
ca ses, t he out put s ar e also affect ed by mor e signals t han t he mea sur ed input s.
In t he air plane example it would be wind gust s a nd t ur bulence effect s. Such
‘‘unmeasur ed input s’’ will be called di s t urbance signa ls or noi se . If we denot e
input s, out put s, and dist ur bances by u, y, a nd e , r espect ively, t he r elat ionship
ca n be depict ed in t he following figur e.
Figure 1-1: Input Signals u, Output Signals y, and Disturbances e
All t hese signals ar e funct ions of t ime, and t he value of t he input at t ime t will
be denot ed by u(t). Oft en, in t he ident ifica t ion cont ext , only discr et e-t ime point s
ar e consider ed, since t he measur ement equipment t ypically r ecor ds t he signals
just at discr et e-t ime inst a nt s, oft en equally spr ead in t ime wit h a
s ampl i ng i nt e rval of T t ime unit s. The modeling pr oblem is t hen t o descr ibe
how t he t hr ee signals r elat e t o ea ch ot her .
y
e
u
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-6
The Basic Dynamic Model
The basic r elat ionship is t he li ne ar di ffe re nce e quat i on. An example of such
an equat ion is t he following one.
y ( t ) - 1. 5 y ( t - T ) +0 . 7 y (t -2 T ) =0 . 9 u ( t - 2 T ) +0 . 5 u ( t - 3 T )+e(t ) (AR X)
Such a r elat ionship t ells us, for example, how t o comput e t he out put y(t) if t he
input is known and t he dist ur bance can be ignor ed:
y ( t ) =1 . 5 y (t -T )- 0 . 7 y (t -2 T ) +0 . 9 u ( t - 2 T ) +0 . 5 u ( t - 3 T )
The out put at t ime t is t hus comput ed as a linea r combina t ion of past out put s
and past input s. It follows, for example, t hat t he out put at t ime t depends on
t he input signal at many pr evious t ime inst ant s. This is what t he wor d
dynami c r efer s t o. The ident ificat ion pr oblem is t hen t o use measur ement s of
u and y t o figur e out
• The coefficient s in t his equa t ion (i.e., -1.5, 0.7, et c.)
How many delayed out put s t o use in t he descr ipt ion (t wo in t he example:
y ( t - T ) a n d y ( t - 2 T ) )
• The t i me de lay in t he syst em is (2T in t he exa mple: you see fr om t he second
equat ion t hat it t akes 2T t ime unit s befor e a change in u will affect y) and
• How many delayed input s t o use (t wo in t he exa mple: u(t -2T) and u(t -3T))
Variants of Model Descriptions
The model given above is called an ARX mode l. Ther e ar e a handful of
va r iant s of t his model known a s Out put -Error (OE) models, ARMAX models,
FIR models, and Box-J enki ns (BJ ) models. These ar e descr ibed lat er on in
t he manual. At a ba sic level it is sufficient t o t hink of t hem a s var iant s of t he
ARX model a llowing also a char act er izat ion of t he pr oper t ies of t he
dist ur bances e.
Ge ne ral li ne ar mode ls can be descr ibed symbolically by
y =Gu +He
which says t hat t he measur ed out put y(t) is a sum of one cont r ibut ion t hat
comes fr om t he measur ed input u(t) and one cont r ibut ion t ha t comes fr om t he
noise He. The symbol G t hen denot es t he dynamic pr oper t ies of t he syst em, t hat
is, how t he out put is for med fr om t he input . For linea r syst ems it is called t he
t r ansfer funct ion fr om input t o out put . The symbol H r efer s t o t he noise
1-7
pr oper t ies, and is called t he noise model. It descr ibes how t he dist ur bances at
t he out put ar e for med fr om some st anda r dized noise sour ce e(t).
Stat e-s pac e mode l s ar e common r epr esent at ions of dyna mical models. They
descr ibe t he sa me t ype of linear differ ence r elat ionship bet ween t he input s and
t he out put s as in t he ARX model, but t hey ar e r ear r anged so t hat only one
delay is used in t he expr essions. To achieve t his, some ext r a va r iables, t he
s tat e vari able s , a r e int r oduced. They ar e not measur ed, but can be
r econst r uct ed fr om t he measur ed input -out put dat a. This is especia lly useful
when t her e ar e sever a l out put signals, i.e., when y(t ) is a vect or . Chapt er gives
mor e det a ils about t his. For basic use of t he t oolbox it is sufficient t o know t hat
t he orde r of t he st at e-spa ce model r ela t es t o t he number of delayed input s and
out put s used in t he cor r esponding linea r differ ence equat ion. The st at e-space
r epr esent at ion looks like
x ( t +1 ) =A x ( t ) +B u (t ) +Ke( t )
y ( t ) =Cx ( t ) +Du ( t ) +e( t )
Her e x(t ) is t he vect or of st at e var iables. The mat r ix K det er mines t he noise
pr oper t ies. Not ice t hat if K = 0, t hen t he noise sour ce e(t ) affect s only t he
out put , a nd no specific model of t he noise pr oper t ies is built . This cor r esponds
t o H = 1 in t he gener a l descr ipt ion a bove, and is usually r efer r ed t o a s a n
Output-Error model. Not ice also t hat D = 0 means t hat t her e is no dir ect
influence fr om u(t ) t o y(t ). Thus t he effect of t he input on t he out put all passes
via x(t ) and will t hus be delayed at least one sample. The fir st value of t he st at e
var iable vect or x(0) r eflect s t he init ial condit ions for t he syst em at t he
beginning of t he dat a r ecor d. When dealing wit h models in st at e-space for m, a
t ypical opt ion is whet her t o est imat e D, K, and x(0) or t o let t hem be zer o.
How to Interpret the Noise Source
In many cases of syst em ident ificat ion, t he effect s of t he noise on t he out put ar e
insignificant compar ed t o t hose of t he input . Wit h good signal-t o-noise r at ios
(SNR), it is less impor t ant t o have an accur at e noise model. Never t heless it is
impor t a nt t o under st and t he r ole of t he noise and t he noise sour ce e(t ), whet her
it appear s in t he ARX model or in t he gener al descr ipt ions given above.
Ther e ar e t hr ee aspect s of t he noise t hat should be st r essed:
• under st anding whit e noise
• int er pr et ing t he noise sour ce
• using t he noise sour ce when wor king wit h t he model
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-8
These aspect s ar e discussed one by one.
How can we under st and whit e noise? Fr om a for mal point of view, t he noise
sour ce e(t ) will nor mally be r egar ded as white noise. This means t hat it is
ent ir ely unpr edict able. In ot her wor ds, it is impossible t o guess t he va lue of e(t )
no mat t er how accur at ely we have measur ed past dat a up t o t ime t -1.
How can we int er pr et t he noise sour ce? The act ual noise cont r ibut ion t o t he
out put , H e(t ), has r ea l significance. It cont ains a ll t he influences on t he
measur ed y, known and unknown, t hat ar e not cont ained in t he input u. It
explains and capt ur es t he fact t ha t even if an exper iment is r epeat ed wit h t he
sa me input , t he out put signal will t ypica lly be somewhat differ ent . However ,
t he noise sour ce e(t) need not have a physical significance. In t he air pla ne
example ment ioned ear lier , t he noise effect s ar e wind gust s and t ur bulence.
Descr ibing t hese a s ar ising fr om a whit e noise sour ce via a t r ansfer funct ion H,
is just a convenient way of ca pt ur ing t heir char a ct er .
How can we deal wit h t he noise sour ce when using t he model? If t he model is
used just for simulat ion, i.e., t he r esponses t o var ious input s ar e t o be st udied,
t hen t he noise model plays no immediat e r ole. Since t he noise sour ce e(t) for
new dat a will be unknown, it is t aken as zer o in t he simula t ions, so as t o st udy
t he effect of t he input alone (a noise-fr ee simulat ion). Ma king anot her
simulat ion wit h e(t) being ar bit r ar y whit e noise will r eveal how r elia ble t he
r esult of t he simulat ion is, but it will not give a mor e a ccur a t e simulat ion r esult
for t he act ual syst em’s r esponse.
The need and use of t he noise model can be summar ized as follows:
• It is, in most cases, r equir ed t o obt a in a bet t er est imat e for t he dynamics, G.
• It indicat es how r elia ble noise-fr ee simulat ions ar e.
• It is r equir ed for r eliable pr edict ions and st ochast ic cont r ol design.
1-9
Terms to Characterize the Model Properties
The pr oper t ies of an input -out put r elat ionship like t he ARX model follow fr om
t he numer ical values of t he coefficient s, and t he number of delays used. This is
however a fair ly implicit way of t alking about t he model pr oper t ies. Inst ead a
number of differ ent t er ms ar e used in pr act ice:
Impulse Response
The impulse r esponse of a dynamical model is t he out put signal t hat r esult s
when t he input is an impulse, i.e., u(t ) is zer o for a ll values of t except t =0,
wher e u(0)=1. It can be comput ed as in t he equat ion following (ARX), by let t ing
t be equal t o 0, 1, 2, ... and t aking y(-T)=y(-2T)=0 and u(0)=1.
Step Response
The st ep r esponse is t he out put signal t hat r esult s fr om a st ep input , i.e., u(t )
is zer o for negat ive values of t a nd equal t o one for posit ive va lues of t . The
impulse and st ep r esponses t oget her ar e called t he model’s t rans i e nt
re s pons e .
Frequency Response
The fr equency r esponse of a linear dynamic model descr ibes how t he model
r eact s t o sinusoidal input s. If we let t he input u(t ) be a sinusoid of a cer t ain
fr equency, t hen t he out put y(t) will also be a sinusoid of t his fr equency. The
amplit ude and t he phase (r elat ive t o t he input ) will however be differ ent . This
fr equency r esponse is most oft en depict ed by t wo plot s; one t hat shows t he
amplit ude change a s a funct ion of t he sinusoid’s fr equency and one t hat shows
t he phase shift as funct ion of fr equency. This is known as a Bode plot .
Zeros and Poles
The zer os and t he poles ar e equivalent ways of descr ibing t he coefficient s of a
linea r differ ence equat ion like t he ARX model. The poles r ela t e t o t he
“out put -side” and t he zer os r ela t e t o t he “input -side” of t his equat ion. The
number of poles (zer os) is equal t o number of sampling int er vals bet ween t he
most and least delayed out put (input ). In t he ARX example in t he beginning of
t his sect ion, t her e ar e consequent ly t wo poles and one zer o.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-10
4. The Basic Steps of System Identification
The Syst em Ident ificat ion pr oblem is t o est imat e a model of a syst em based on
obser ved input -out put dat a. Sever al wa ys t o descr ibe a syst em and t o est ima t e
such descr ipt ions exist . This sect ion gives a br ief account of t he most impor t ant
appr oa ches.
The pr ocedur e t o det er mine a model of a dynamical syst em fr om obser ved
input -out put dat a involves t hr ee basic ingr edient s:
• The input -out put dat a
• A set of candidat e models (t he model st r uct ur e)
• A cr it er ion t o select a par t icular model in t he set , based on t he infor mat ion
in t he dat a (t he ident ificat ion met hod)
The ident ificat ion pr ocess amount s t o r epea t edly select ing a model st r uct ur e,
comput ing t he best model in t he st r uct ur e, and eva luat ing t his model’s
pr oper t ies t o see if t hey ar e sat isfact or y. The cycle can be it emized as follows:
1 Design a n exper iment and collect input -out put da t a fr om t he pr ocess t o be
ident ified.
2 Examine t he dat a. Polish it so as t o r emove t r ends and out lier s, select useful
por t ions of t he or iginal dat a, and apply filt er ing t o enhance impor t ant
fr equency r a nges.
3 Select and define a model st r uct ur e (a set of candidat e syst em descr ipt ions)
wit hin which a model is t o be found.
4 Comput e t he best model in t he model st r uct ur e accor ding t o t he
input -out put dat a and a given cr it er ion of fit .
5 Examine t he obt ained model’s pr oper t ies
6 If t he model is good enough, t hen st op; ot her wise go back t o St ep 3 t o t r y
a not her model set . Possibly also t r y ot her est imat ion met hods (St ep 4) or
wor k fur t her on t he input -out put dat a (St eps 1 and 2).
The Syst em Ident ificat ion Toolbox offer s sever a l funct ions for each of t hese
st eps.
1-11
For St ep 2 t her e a r e r out ines t o plot dat a, filt er dat a, and r emove t r ends in
dat a.
For St ep 3 t he Syst em Ident ificat ion Toolbox offer s a var iet y of nonpar a met r ic
models, a s well as all t he most common black-box input -out put and st at e-spa ce
st r uct ur es, and also gener al t ailor -made linear st a t e-space models in discr et e
and cont inuous t ime.
For St ep 4 gener al pr edict ion er r or (maximum likelihood) met hods as well as
inst r ument a l var iable met hods and sub-space met hods a r e offer ed for
par a met r ic models, while basic cor r elat ion and spect r al a nalysis met hods ar e
used for nonpar amet r ic model st r uct ur es.
To examine models in St ep 5, many funct ions a llow t he comput at ion and
pr esent at ion of fr equency funct ions and poles and zer os, as well as simula t ion
and pr edict ion using t he model. Funct ions ar e also included for
t r ansfor mat ions bet ween cont inuous-t ime and discr et e-t ime model
descr ipt ions and t o for mat s t ha t ar e used in ot her MATLAB t oolboxes, like t he
Cont r ol Syst em Toolbox a nd t he Signal Pr ocessing Toolbox.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-12
5. A Startup Identification Procedure
Ther e ar e no st a ndar d and secur e r out es t o good models in Syst em
Ident ificat ion. Given t he number of possibilit ies, it is easy t o get confused about
what t o do, what model st r uct ur es t o t est , and so on. This sect ion descr ibes one
r out e t hat oft en wor ks well, but t her e a r e no guar ant ees. The st eps r efer t o
funct ions wit hin t he GUI, but you ca6n also go t hr ough t hem in command
mode. See Chapt er for t he basic commands.
Step 1 Looking at the Data
Plot t he dat a. Look at t hem ca r efully. Tr y t o see t he dynamics wit h your own
eyes. Can you see t he effect s in t he out put s of t he changes in t he input ? Can
you see nonlinear effect s, like differ ent r esponses at differ ent levels, or
differ ent r esponses t o a st ep up and a st ep down? Ar e t her e por t ions of t he dat a
t hat appea r t o be “messy” or car r y no infor mat ion. Use t his insight t o select
por t ions of t he dat a for est imat ion and valida t ion pur poses.
Do physical levels play a r ole in your model? If not , det r end t he dat a by
r emoving t heir mean values. The models will t hen descr ibe how changes in t he
input give changes in out put , but not explain t he act ual levels of t he signals.
This is t he nor mal sit uat ion.
The default sit uat ion, wit h good dat a, is t hat you det r end by r emoving means,
and t hen select t he fir st half or so of t he dat a r ecor d for est ima t ion pur poses,
and use t he r emaining dat a for valida t ion. This is what happens when you
apply Qui cks tart under t he pop-up menu Pre proce s s in t he main i de nt
window.
Step 2 Getting a Feel for the Difficulties
Apply Qui ckst art under pop-up menu Es t i mat e in t he main i de nt window.
This will comput e and displa y t he spect r al analysis est ima t e and t he
cor r ela t ion analysis est imat e, as well as a four t h or der ARX model wit h a delay
1-13
est imat ed fr om t he cor r elat ion analysis and a default or der st at e-spa ce model
comput ed by n4sid. This gives t hr ee plot s. Look at t he agr eement bet ween t he
• Spect r al Analysis est imat e and t he ARX and st at e-space models’ fr equency
funct ions
• Cor r elat ion Analysis est ima t e and t he ARX a nd st at e-space models’
t r ansient r esponses
• Measur ed Va lidat ion Da t a out put and t he ARX and st at e-space models’
simula t ed out put s
If t hese a gr eement s a r e r easona ble, t he pr oblem is not so difficult , and a
r elat ively simple linea r model will do a good job. Some fine t uning of model
or der s, and noise models have t o be made and you can pr oceed t o St ep 4.
Ot her wise go t o St ep 3.
Step 3 Ex amining the Difficulties
Ther e may be sever al r easons why t he compar isons in St ep 2 did not look good.
This sect ion discusses t he most common ones, and how t hey can be ha ndled:
Model Unstable
The ARX or st at e-space model ma y t ur n out t o be unst able, but could st ill be
useful for cont r ol pur poses. Change t o a 5- or 10-st ep ahea d pr edict ion inst ead
of simulat ion in t he Mode l Out put Vi e w.
Feedback in Data
If t her e is feedback fr om t he out put t o t he input , due t o some r egulat or , t hen
t he spect r a l and cor r ela t ions analysis est imat es ar e not r elia ble. Discr epancies
bet ween t hese est imat es and t he ARX a nd st at e-spa ce models can t her efor e be
disr egar ded in t his case. In t he Mode l Re s i duals Vi e w of t he par amet r ic
models, feedback in dat a can also be visible a s cor r elat ion bet ween r esiduals
and input for negat ive la gs.
Noise Model
If t he st at e-space model is clear ly bet t er t ha n t he ARX model at r epr oducing
t he measur ed out put , t his is an indica t ion t ha t t he dist ur bances have a
subst ant ial influence, and it will be necessar y t o model t hem car efully.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-14
Model Order
If a four t h or der model does not give a good Mode l Out put plot , t r y eight h
or der . If t he fit clea r ly impr oves, it follows t hat higher or der models will be
r equir ed, but t hat linear models could be sufficient .
Additional Inputs
If t he Mode l Out put fit has not significant ly impr oved by t he t est s so far ,
t hink over t he physics of t he applicat ion. Ar e t her e mor e signa ls t hat have
been, or could be, measur ed t hat might influence t he out put ? If so, include
t hese among t he input s and t r y a gain a four t h or der ARX model fr om all t he
input s. (Not e t hat t he input s need not at all be cont r ol signals, a nyt hing
measur a ble, including dist ur ba nces, should be t r ea t ed as input s).
Nonlinear Effects
If t he fit bet ween measur ed and model out put is st ill ba d, consider t he physics
of t he applicat ion. Ar e t her e nonlinear effect s in t he syst em? In t ha t case, for m
t he nonlinear it ies fr om t he measur ed da t a. This could be a s simple as for ming
t he pr oduct of volt age and cur r ent measur ement s, if you r ealize t hat it is t he
elect r ical power t hat is t he dr iving st imulus in, say, a heat ing pr ocess, and
t emper a t ur e is t he out put . This is of cour se a pplicat ion dependent . It does not
t ake ver y much wor k, however , t o for m a number of a ddit ional input s by
r ea sonable nonlinear t r ansfor mat ions of t he measur ed ones, and just t est if
inclusion of t hem impr oves t he fit .
Still Problems?
If none of t hese t est s leads t o a model t ha t is able t o r epr oduce t he Validat ion
Dat a r easonably well, t he conclusion might be t hat a sufficient ly good model
cannot be pr oduced fr om t he dat a. Ther e may be many r easons for t his. The
most impor t ant one is t hat t he dat a simply do not cont ain sufficient
infor mat ion, e.g., due t o bad signal t o noise r at ios, lar ge and nonst at ionar y
dist ur bances, var ying syst em pr oper t ies, et c. The r eason may also be t hat t he
syst em has some quit e complicat ed nonlinear it ies, which cannot be r ealized on
physical gr ounds. In such cases, nonlinear , black box models could be a
solut ion. Among t he most used models of t his char act er ar e t he Ar t ificial
Neur al Net wor ks (ANN).
Ot her wise, use t he insight s of which input s t o use and which model or der s t o
expect and pr oceed t o St ep 4.
1-15
Step 4 Fine Tuning Orders and Noise Structures
For r eal dat a t her e is no such t hing as a “cor r ect model st r uct ur e.” However ,
differ ent st r uct ur es can give quit e differ ent model qualit y. The only way t o find
t his out is t o t r y out a number of differ ent st r uct ur es and compar e t he
pr oper t ies of t he obt ained models. Ther e ar e a few t hings t o look for in t hese
compar isons:
Fit Betw een Simula ted a nd Measured Output
Keep t he Model Out put Vi e w open and look at t he fit bet ween t he model’s
simulat ed out put and t he measur ed one for t he Valida t ion Dat a. For mally, you
could pick t hat model, for which t his number is t he lowest . In pr a ct ice, it is
bet t er t o be mor e pr agmat ic, a nd also t a ke int o account t he model complexit y,
and whet her t he impor t ant feat ur es of t he out put r esponse ar e capt ur ed.
Residual Ana lysis Test
You should r equir e of a good model, t hat t he cr oss cor r elat ion funct ion bet ween
r esiduals and input does not go significant ly out side t he confidence r egion. A
clear peak at lag k shows t hat t he effect fr om input u(t -k ) on y(t) is not pr oper ly
descr ibed. A r ule of t humb is t hat a slowly var ying cr oss cor r elat ion funct ion
out side t he confidence r egion is an indicat ion of t oo few poles, while shar per
peaks indica t e t oo few zer os or wr ong delays.
Pole Zero Ca ncellations
If t he pole-zer o plot (including confidence int er va ls) indica t es pole-zer o
ca ncellat ions in t he dynamics, t his suggest s t hat lower or der models ca n be
used. In pa r t icula r , if it t ur ns out t hat t he or der s of ARX models ha ve t o be
incr eased t o get a good fit , but t hat pole-zer o cancellat ions a r e indicat ed, t hen
t he ext r a poles a r e just int r oduced t o descr ibe t he noise. Then t r y ARMAX, OE,
or BJ model st r uct ur es wit h an A or F polynomial of an or der equal t o t hat of
t he number of nonca nceled poles.
What Model Structures Should be Tested?
Well, you can spend any amount of t ime t o check out a ver y lar ge number of
st r uct ur es. It oft en t akes just a few seconds t o comput e and eva luat e a model
in a cer t ain st r uct ur e, so t ha t you should have a gener ous at t it ude t o t he
t est ing. However , exper ience shows t hat when t he basic pr oper t ies of t he
syst em’s behavior have been picked up, it is not much use t o fine t une or der s
in absur dum just t o pr ess t he fit by fr act ions of per cent s.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-16
Many ARX mode l s: Ther e is a ver y cheap way of t est ing ma ny ARX st r uct ur es
simult aneously. Ent er in t he Orde rs t ext field many combinat ions of or der s,
using t he colon (“:”) not a t ion. When you select Est i mat e , models for all
combinat ions (ea sily sever al hundr eds) ar e comput ed and t heir (pr edict ion
er r or ) fit t o Valida t ion Dat a is shown in a special plot . By clicking in t his plot
t he best models wit h a ny chosen number of par amet er s will be inser t ed int o t he
Model Boar d, and evaluat ed as desir ed.
Many St at e -s pace mode l s : A similar feat ur e is also available for bla ck-box
st at e-space models, est imat ed using n4sid. When a good or der has been found,
t r y t he PEM est imat ion met hod, which oft en impr oves on t he accur acy.
ARMAX, OE, and BJ model s : Once you ha ve a feel for suit able delays and
dynamics or der s, if is oft en useful t o t r y out ARMAX, OE, and/or BJ wit h t hese
or der s and t est some differ ent or der s for t he noise t r ansfer funct ions (C and D).
Especially for poor ly damped syst ems, t he OE st r uct ur e is suit able.
Ther e is a quit e ext ensive lit er at ur e on or der and st r uct ur e select ion, and
anyone who would like t o know mor e should consult t he r efer ences.
Multivariable Systems
Syst ems wit h many input signals and/or many out put signals ar e called
mult ivariable. Such syst ems ar e oft en mor e challenging t o model. In par t icular
syst ems wit h sever a l out put s could be difficult . A basic r eason for t he
difficult ies is t hat t he couplings bet ween sever al input s and out put s lead t o
mor e complex models. The st r uct ur es involved ar e r icher and mor e par amet er s
will be r equir ed t o obt ain a good fit .
Ava ilable Models
The Syst em Ident ificat ion Toolbox as well as t he GUI ha ndles gener al, linear
mult iva r iable models. All ear lier ment ioned models ar e suppor t ed in t he single
out put , mult iple input ca se. For mult iple out put s ARX models and st a t e-space
models ar e cover ed. Mult i-out put ARMAX and OE models a r e cover ed via
st at e-space r epr esent at ions: ARMAX cor r esponds t o est imat ing t he K-mat r ix,
while OE cor r esponds t o fixing K t o zer o. (These ar e pop-up opt ions in t he GUI
model or der edit or .)
Gener ally spea king, it is pr efer able t o wor k wit h st at e-space models in t he
mult iva r iable case, since t he model st r uct ur e complexit y is ea sier t o deal wit h.
It is essent ially just a mat t er of choosing t he model or der .
1-17
Working w ith Subsets of the Input Output Channels
In t he pr ocess of ident ifying good models of a syst em, it is oft en useful t o select
subset s of t he input and out put channels. Par t ial models of t he syst em’s
behavior will t hen be const r uct ed. It might not , for example, be clear if all
measur ed input s have a significant influence on t he out put s. Tha t is most
easily t est ed by r emoving a n input channel fr om t he dat a, building a model for
how t he out put (s) depends on t he r emaining input channels, and checking if
t her e is a significant det er ior at ion in t he model out put ’s fit t o t he measur ed
one. See also t he discussion under St ep 3 above.
Gener ally speaking, t he fit get s bet t er when mor e input s ar e included and
wor se when mor e out put s ar e included. To under st and t he lat t er fa ct , you
should r ealize t hat a model t hat has t o explain t he behavior of sever al out put s
has a t ougher job t han one t hat just must account for a single out put . If you
have difficult ies obt a ining good models for a mult i-out put syst em, it might be
wise t o model one out put at a t ime, t o find out which ar e t he difficult ones t o
handle.
Models t hat ar e just t o be used for simulat ions could ver y well be built up fr om
single-out put models, for one out put at a t ime. However , models for pr edict ion
and cont r ol will be a ble t o pr oduce bet t er r esult s if const r uct ed for all out put s
simult aneously. This follows fr om t he fact t hat knowing t he set of all pr evious
out put channels gives a bet t er basis for pr edict ion, t han just knowing t he past
out put s in one channel.
Some Practical Advice
The GUI is par t icular ly suit ed for dealing wit h mult iva r iable syst ems since it
will do useful bookkeeping for you, handling differ ent cha nnels. You could
follow t he st eps of t his agenda:
• Impor t da t a a nd cr eat e a dat a set wit h a ll input and out put channels of
int er est . Do t he necessar y pr epr ocessing of t his set in t er ms of det r ending,
pr efilt er ing, et c., and t hen select a Validat ion Da t a set wit h all channels.
• Then select a Wor king Dat a set wit h all channels, and est imat e st at e-space
models of differ ent or der s using n4sid for t hese dat a. Examine t he r esult ing
model pr imar ily using t he Mode l Out put view.
• If it is difficult t o get a good fit in all out put channels or you would like t o
invest igat e how impor t ant t he differ ent input channels ar e, const r uct new
da t a set s using subset s of t he or igina l input /out put channels. Use t he pop-up
menu Pre proce s s > Sel e ct Channe l s for t his. Don’t change t he Va lidat ion
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-18
Dat a . The GUI will keep t r ack of t he input and out put channel number s. It
will “do t he r ight t hing” when evaluat ing t he channel-r est r ict ed models
using t he Valida t ion Dat a . It might also be appr opr iat e t o see if
impr ovement s in t he fit ar e obt ained for var ious model t ypes, built for one
out put at a t ime.
• If you decide for a mult i-out put model, it is oft en easiest t o use st at e-space
models. Use n4sid as a pr imar y t ool and t r y out pem when a good or der has
been found. Not e t hat n4sid does not pr ovide confidence int er vals for t he
model views.
Re a d i n g M o r e A b o u t Sy ste m Id e n ti f i c a ti o n
1-19
Reading More About System Identification
Ther e is subst ant ial lit er at ur e on Syst em Ident ificat ion. The following
t ext book deals wit h ident ificat ion met hods fr om a similar per spect ive as t his
t oolbox, and a lso descr ibes met hods for physical modeling.
• Ljung L. a nd T. Glad. Modeling of Dynamic Systems, Pr ent ice Hall, Englewood
Cliffs, N.J . 1994.
For mor e det ails a bout t he algor it hms a nd t heor ies of ident ifica t ion:
• Ljung L.. System Identification - Theory for the User, Pr ent ice Ha ll, Englewood
Cliffs, N.J . 1987.
• Söder st r öm T. and P. St oica. System Identification, Pr ent ice Hall Int er nat ional,
London. 1989.
For mor e about syst em and signa ls:
• Oppenheim J . a nd A.S. Willsky. Signals and Systems, Pr ent ice Hall, Englewood
Cliffs, N.J . 1985.
The following t ext book deals wit h t he under lying numer ica l t echniques for
par a met er est imat ion.
• Dennis, J .E. J r . and R.B. Schna bel. Numerical Methods for Unconstrained
Optimization and Nonlinear Equations, Pr ent ice Hall, Englewood Cliffs, N.J .
1983.
1 Th e S y ste m Id e n ti f i c a ti o n Pr o b l e m
1-20

2
The Gr aphical User
Int er face
The Bi g Pi ct ure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Handl i ng Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Es ti mat i ng Mode l s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Exami ni ng Mode l s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Some Furthe r GUI Topi cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
2 Th e G r a p h i c a l U se r In te rf a c e
2-2
1. The Big Picture
The Syst em Ident ificat ion Toolbox pr ovides a gr aphical user int er fa ce (GUI) .
The GUI cover s most of t he t oolbox’s funct ions and gives ea sy access t o all
va r iables t hat ar e cr eat ed dur ing a session. It is st ar t ed by t yping
ident
in t he MATLAB command window.
Figure 2-1: The Main ident Information Window
The Model and Data Boards
Syst em Ident ificat ion is about dat a and models and cr eat ing models fr om dat a .
The main infor mat ion and communicat ion window i de nt, is t her efor e
domina t ed by t wo t a bles:
• A t able over a vaila ble dat a set s, each r epr esent ed by an icon.
• A t able over cr eat ed models, each r epr esent ed by an icon.
2-3
These t a bles will be r efer r ed t o as t he “Model Boar d” and t he “Dat a Boar d” in
t his cha pt er . You ent er dat a set s int o t he Da t a Boa r d by
• Opening ea r lier sa ved sessions.
• Impor t ing t hem fr om t he MATLAB wor kspace.
• Cr eat ing t hem by det r ending, filt er ing, select ing subset s, et c., of anot her
da t a set in t he Dat a Boar d.
Impor t s ar e handled under t he pop-up menu Dat a while cr eat ion of new dat a
set s is handled under t he pop-up menu Pre proce s s . “Handling Dat a” on pa ge
2-7 dea ls wit h t his in mor e det ail.
The models ar e ent er ed int o t he summar y boar d by
• Opening ea r lier sa ved sessions.
• Impor t ing t hem fr om t he MATLAB wor kspace.
• Est imat ing t hem fr om dat a.
Impor t s ar e handled under t he pop-up menu Mode l s, while all t he differ ent
est imat ion schemes ar e r eached under t he pop-up menu Es t i mat e . Mor e about
t his in “Est imat ing Models” on page 2-14.
The Dat a and Model Boar ds ca n be r ea r r anged by dr agging and dr opping.
Mor e boar ds open aut omat ica lly when necessar y or when asked for (under
menu Opti ons ).
The Working Data
All dat a set s and models ar e cr ea t ed fr om t he Wor king Dat a set . This is t he
dat a t hat is given in t he cent er of t he i de nt window. To change t he Wor king
Dat a set dr ag and dr op any dat a set fr om t he Dat a Boar d on t he Wor king Dat a
icon.
The View s
Below t he Dat a and Model Boar ds ar e but t ons for differ ent views. These
cont r ol what aspect s of t he dat a set s and models you would like t o examine, and
ar e descr ibed in mor e det ail in “Handling Dat a” on page 2-7 a nd in “Examining
Models” on page 2-27. To select a dat a set or a model, so t hat it s pr oper t ies ar e
displayed, click on it s icon. A select ed object is mar ked by a t hicker line in t he
icon. To deselect , click aga in. An ar bit r ar y number of dat a/model object s can be
examined simult aneously. To have mor e infor mat ion about an object ,
double-click on it s icon.
2 Th e G r a p h i c a l U se r In te rf a c e
2-4
The Validation Data
The t wo model views Mode l Out put and Mode l Re s i dual s illust r at e model
pr oper t ies when applied t o t he Va lidat ion Da t a set . This is t he set mar ked in
t he box below t hese t wo views. To cha nge t he Validat ion Dat a, dr ag and dr op
any dat a set fr om t he Dat a Boar d on t he Validat ion Dat a icon.
It is good and common pr act ice in ident ificat ion t o evaluat e an est imat ed
model’s pr oper t ies using a “fr esh” da t a set , t hat is, one t ha t was not used for
t he est imat ion. It is t hus good advice t o let t he Validat ion Dat a be differ ent
fr om t he Wor king Dat a, but t hey should of cour se be compat ible wit h t hese.
The Work Flow
You st ar t by impor t ing dat a (under pop-up menu Dat a); you exa mine t he dat a
set using t he Dat a Vi e ws . You pr obably r emove t he means fr om t he dat a and
select subset s of dat a for est imat ion and va lidat ion pur poses using t he it ems in
t he pop-up menu Pre proc es s . You t hen cont inue t o est imat e models, using t he
possibilit ies under t he pop-up menu Es t i mate , per haps fir st doing a
quickst ar t . You examine t he obt ained models wit h r espect t o your favor it e
aspect s using t he differ ent Mode l Vi e ws . The basic idea is t ha t any checked
view shows t he pr oper t ies of all select ed models at a ny t ime. This funct ion is
“live” so models and views can be checked in and out at will in an online
fashion. You select /deselect a model by clicking on it s icon.
Inspir ed by t he infor mat ion you ga in fr om t he plot s, you cont inue t o t r y out
differ ent model st r uct ur es (model or der s) unt il you find a model you ar e
sa t isfied wit h.
Management Aspects
Di ary: It is ea sy t o for get wha t you have been doing. By double-clicking on a
dat a /model icon, a complet e diar y will be given of how t his object was cr eat ed,
along wit h ot her key infor ma t ion. At t his point you can a lso add comment s a nd
change t he name of t he object and it s color .
Layout : To have a good over view of t he cr eat ed models and dat a set s, it is good
pr act ice t o t r y r ear r anging t he icons by dr agging and dr opping. In t his wa y
models cor r esponding t o a par t icular da t a set ca n be gr ouped t oget her , et c. You
can also open new boar ds (Opt i ons menu Ext ra mode l /data boards ) t o
fur t her r ear r ange t he icons. These can be dr agged acr oss t he scr een bet ween
differ ent windows. The ext r a boar ds ar e also equipped wit h not epads for your
comment s.
2-5
Se ss i ons: The Model and Dat a Boar ds wit h all models a nd dat a set s t oget her
wit h t heir diar ies can be saved (under menu it em Fi l e ) at any point , and
r eloaded lat er . This is t he count er par t of save/load wor kspa ce in t he
command-dr iven MATLAB. The four most r ecent sessions ar e list ed under Fi l e
for immediat e open.
Cl e anli ne s s : The boar ds will hold an ar bit r ar y number of models and dat a
set s (by cr eat ing clones of t he boar d when necessa r y). It is however advisable
t o clear (delet e) models and dat a set s t ha t no longer ar e of int er est . Do t hat by
dr agging t he object t o t he Tras h Can. (Double-clicking on t he t r ash can will
open it up, and it s cont ent s can be r et r ieved.)
Wi ndow Cult ure : Dialog and plot windows ar e best managed by t he GUI’s
close funct ion (submenu it em under Fi le menu, or select Cl os e , or check/
uncheck t he cor r esponding View box). They may also be”quit t ed” by t he specific
window syst em’s quit /close funct ion. This does no ha r m, but “quit ” will not be
pr oper ly acknowledged by t he GUI, a nd t he window will have t o be r e-cr eat ed
next t ime it is t o be used.
It is gener ally not suit able t o iconify t he windows – t he GUI’s handling and
window management syst em is usually a bet t er alt er nat ive.
Workspace Variables
The models and da t a set s cr eat ed wit hin t he GUI ar e nor mally not availa ble in
t he MATLAB wor kspa ce. Indeed, t he wor kspace is not at all lit t er ed wit h
var iables dur ing t he sessions wit h t he GUI. The var ia bles can however be
expor t ed at any t ime t o t he wor kspace, by dr a gging and dr opping t he object
icon on t he To Works pac e box. They will t hen car r y t he name in t he
wor kspa ce t ha t mar ked t he object icon at t he t ime of expor t . You can wor k wit h
t he var iables in t he wor kspace, using any MATLAB commands, and t hen
per haps impor t modified ver sions back int o t he GUI. Not e t hat models have a
specific int er nal st r uct ur e a nd should be dealt wit h using t he MATLAB
commands present, th2ff, th2ss, et c. See “Model Conver sions” on page 4-5 of
t he "Command Refer ence" chapt er .
The GUI’s names of dat a set s a nd models ar e suggest ed by default pr ocedur es.
Nor mally, you ca n ent er a ny ot her na me of your choice at t he t ime of cr eat ion
of t he var iable. Names can be cha nged (aft er double-clicking on t he icon) at any
t ime. Unlike t he wor kspace sit uat ion, t wo GUI object s can car r y t he same
name (i.e., t he sa me st r ing in t heir icons).
2 Th e G r a p h i c a l U se r In te rf a c e
2-6
The GUI pr oduces a handful of global wor kspace var ia bles for management
pur poses. They all st ar t wit h t he pr efix XID.
NOTE: Do not clear all or clear global dur ing a GUI session! This would
mean t hat you lose cont r ol over t he object s t hat you have cr eat ed. The same
disa st er occur s if you do clg or quit t he main i de nt window. It is however
sa fe t o clear (wit hout adding all or global) t he wor kspace at any t ime.
Help Texts
The GUI cont a ins some 100 help t ext s t hat ar e accessible in a nest ed fashion,
when r equir ed. The main i de nt window cont a ins gener al help t opics under t he
He l p menu. This is a lso t he case for t he var ious plot windows. In addit ion,
ever y dialog box has a He l p push but t on for cur r ent help and advice.
2-7
2. Handling Data
Data Representation
In t he Syst em Ident ificat ion Toolbox (SITB), signals a nd obser ved dat a ar e
r epr esent ed a s column vect or s, e.g.,
The ent r y in r ow number k, i.e., u(k), will t hen be t he signal’s value at sampling
inst ant number k. It is gener ally assumed in t he t oolbox t hat da t a ar e sampled
at equidist ant sampling t imes, and t he sampling int er va l T is supplied a s a
specific ar gument .
We gener ally denot e t he input t o a syst em by t he let t er u a nd t he out put by y.
If t he syst em has sever al input channels, t he input dat a is r epr esent ed by a
mat r ix, wher e t he columns ar e t he input signals in t he differ ent channels:
The same holds for syst ems wit h sever al out put channels.
The obser ved input -out put dat a r ecor d is r epr esent ed in t he SITB by a mat r ix,
wher e t he fir st column(s) is t he out put , followed by t he input column(s):
z = [y u];
When you wor k wit h t he GUI, you only need t o t hink of t hese r epr esent at ion
issues when you inser t t he dat a set int o t he summar y boar d. The GUI will t hen
handle t he dat a r epr esent at ion aut omat ically.
u
u 1 ( )
u 2 ( )


u N ( )
=
u u1 u2 … um =
2 Th e G r a p h i c a l U se r In te rf a c e
2-8
Getting Data into the GUI
The infor mat ion about a dat a set t ha t should be supplied t o t he GUI is as
follows:
1 The input and out put signals
2 The na me you give t o t he dat a set
3 The st ar t ing t ime
4 The sampling int er va l
5 Dat a not es
NOTE: It ems 3 and 4 ar e used only t o ensur e cor r ect t ime and fr equency sca les
when you plot dat a and model char act er ist ics.
These a r e not es for your own infor mat ion and bookkeeping t hat will follow t he
dat a and all models cr eat ed fr om t hem.
2-9
As you select t he pop-up menu Dat a and choose t he it em Import..., a dialog
box will open, wher e you can ent er t he infor mat ion it ems 1 - 5, just list ed. This
box has six fields for you t o fill in:
Figure 2-2: The Dialog for Importing Data into the GUI
Input and Output: Ent er t he var iable names of t he input a nd out put
r espect ively. These should be var iables in your MATLAB wor kspa ce, so you
may ha ve t o load some disk files fir st .
Act ually, you can ent er a ny MATLAB expr essions in t hese fields, and t hey will
be evalua t ed t o comput e t he input and t he out put befor e inser t ing t he dat a int o
t he GUI.
Dat a name : Ent er t he name of t he dat a set t o be used by t he GUI. This name
ca n be changed la t er on.
Start i ng ti me and Sampl i ng i nt e rval: Fill t hese out for cor r ect t ime and
fr equency scales in t he plot s.
Not e t hat you can ent er a ny t ext you want t o accompany t he dat a for
bookkeeping pur poses.
2 Th e G r a p h i c a l U se r In te rf a c e
2-10
Fina lly, select Import t o inser t t he dat a int o t he GUI. When no mor e da t a set s
ar e t o be inser t ed, select Cl os e t o close t he dialog box. Re s e t will empt y all t he
fields of t he box.
Taking a Look at the Data
The fir st t hing t o do aft er having inser t ed t he dat a set int o t he Dat a Boar d is
t o examine it . By checking t he Dat a Vi e w it em Plot Dat a, a plot of t he input
and out put signals will be shown for t he dat a set s t hat ar e select ed. You select /
deselect t he dat a set s by clicking on t hem. For mult ivar iable dat a, t he differ ent
combinat ions of input and out put signals ar e chosen under menu it em
Channel in t he plot window. Using t he zoom funct ion (dr a wing r ect angles wit h
t he left mouse but t on down) differ ent por t ions of t he dat a can be examined in
mor e det ail.
To exa mine t he fr equency cont ent s of t he dat a, check t he Dat a Vi e w it em
Dat a Spe ct ra. The funct ion is a nalogous t o Plot Dat a, but t he signals’ spect r a
ar e shown inst ead. By default t he per iodogr a ms of t he dat a ar e shown, i.e., t he
absolut e squar e of t he Four ier t r ansfor ms of t he da t a. The plot can be changed
t o any chosen fr equency r ange a nd a number of differ ent ways of est imat ing
spect r a, by t he Opti ons menu it em in t he spect r a window.
The pur pose of exa mining t he dat a in t hese wa ys is t o find out if t her e ar e
por t ions of t he dat a t hat ar e not suit able for ident ifica t ion, if t he infor mat ion
cont ent s of t he da t a is suit able in t he int er est ing fr equency r egions, and if t he
dat a have t o be pr epr ocessed in some way, befor e using t hem for est imat ion.
Preprocessing Data
Detrending
Det r ending t he dat a involves r emoving t he mean values or linear t r ends fr om
t he signa ls (t he means and t he linea r t r ends ar e t hen comput ed and r emoved
fr om each signal individually). This funct ion is accessed under t he pop-up
menu Pre proc es s , by select ing it em Re move Me ans or Re move Tre nds .
Mor e advanced det r ending, such as r emoving piecewise linear t r ends or
seasonal var iat ions cannot be accessed wit hin t he GUI. It is gener a lly
r ecommended t hat you always r emove at least t he mean values of t he dat a
befor e t he est imat ion phase, unless physical insight involving act ual signal
levels is built int o t he models.
2-11
Selecting Data Ranges
It is oft en t he case t ha t t he whole dat a r ecor d is not suit able for ident ificat ion,
due t o var ious undesir ed feat ur es (missing or “bad” dat a , out bur st s of
dist ur ba nces, level cha nges et c.), so t ha t only por t ions of t he dat a can be used.
In any case, it is advisable t o select one por t ion of t he measur ed dat a for
est imat ion pur poses and anot her por t ion for validat ion pur poses. The pop-up
menu it em Pre proce ss > Se le ct Range ... opens a dia log box, which facilit at es
t he select ion of differ ent dat a por t ions, by t yping in t he r anges, or mar king
t hem by dr a wing r ect angles wit h t he mouse but t on down.
For mult ivar iable dat a it is oft en adva nt ageous t o st ar t by wor king wit h just
some of t he input a nd out put signals. The menu it em Pre proce s s > Se l e ct
Channe l s ... allows you t o select subset s of t he input s and out put s. This is done
in such a wa y t hat t he input /out put number ing r emains consist ent when you
evaluat e dat a and model pr oper t ies, for models cover ing differ ent subset s of t he
dat a.
Prefiltering
By filt er ing t he input and out put signa ls t hr ough a linea r filt er (t he same filt er
for all signa ls) you can focus t he model’s fit t o t he syst em t o specific fr equency
r a nges. This is done by select ing t he pop-up menu it em Pre proce s s > Fi l te r...
in t he main window. The dialog is quit e analogous t o t hat of select ing da t a
r a nges in t he t ime domain. You mar k wit h a r ect angle in t he spect r al plot s t he
int ended passband or st op ba nd of t he filt er , you select a but t on t o check if t he
filt er ing ha s t he desir ed effect , and t hen you inser t t he filt er ed dat a int o t he
GUI’s Dat a Boar d.
Pr efilt er ing is a good way of r emoving high fr equency noise in t he dat a, and
also a good alt er nat ive t o det r ending (by cut t ing out low fr equencies fr om t he
pass band). Depending on t he int ended model use, you ca n a lso make sur e t hat
t he model concent r a t es on t he impor t ant fr equency r anges. For a model t hat
will be used for cont r ol design, for example, t he fr equency ba nd ar ound t he
int ended closed-loop bandwidt h is of special impor t ance.
Resampling
If t he dat a t ur n out t o be sampled t oo fast , t hey ca n be decimat ed, i.e., ever y
k-t h value is picked, aft er pr oper pr efilt er ing (ant ia lias filt er ing). This is
obt ained fr om menu it em Pre proce s s > Re sample .
2 Th e G r a p h i c a l U se r In te rf a c e
2-12
You can also r esample at a fast er sa mpling r at e by int er pola t ion, using t he
sa me comma nd, and giving a r esampling fact or less t han one.
Quickstart
The pop-up menu it em Pre proce s s > Qui ckst art per for ms t he following
sequence of act ions: It opens t he Time plot Dat a view, r emoves t he mea ns fr om
t he signals, and it split s t hese det r ended da t a int o t wo ha lves. The fir st one is
made Wor king Dat a and t he second one becomes Validat ion Da t a. All t he t hr ee
cr eat ed da t a set s ar e inser t ed int o t he Dat a Boar d.
Checklist for Data Handling
• Inser t da t a int o t he GUI’s Dat a Boar d.
• Plot t he dat a and examine it car efully.
• Typica lly det r end t he dat a by r emoving mean va lues.
• Possibly pr efilt er t he dat a t o enhance and suppr ess var ious fr equency bands.
• Select por t ions of t he dat a for Est imat ion and for Va lidat ion. Dr a g a nd dr op
t hese dat a set s t o t he cor r esponding boxes in t he GUI.
Simulating Data
The GUI is int ended pr ima r ily for wor king wit h r eal dat a set s, and does not
it self pr ovide funct ions for simulat ing synt het ic dat a. That has t o be done in
comma nd mode, and you can use your favor it e pr ocedur e in SIMULINK, t he
Signal Pr ocessing Toolbox, or any ot her t oolbox for simulat ion and t hen inser t
t he simulat ed dat a int o t he GUI as descr ibed a bove.
The Syst em Ident ificat ion Toolbox also has sever al commands for simulat ion.
You should check idinput, idsim, poly2th, modstruc, and ms2th in Cha pt er 4,
"Command Refer ence," for det ails. The following example shows how t he
ARMAX model
y (t )- 1 . 5 y (t -1 ) +0 . 7 y ( t - 2 ) =u (t -1 ) +0 . 5 u ( t - 2 )+e(t )- e( t - 1 )+0 . 2e(t -2 )
is simulat ed wit h a binar y r andom input u:
model1 = poly2th([1 -1.5 0.7],[0 1 0.5],[1 -1 0.2]);
u = idinput(400,’rbs’,[0 0.3]);
e = randn(400,1);
y = idsim([u e],model1);
2-13
The input , u, a nd t he out put , y, can now be impor t ed int o t he Gr aphical User
Int er face as dat a, and t he va r ious est imat ion r out ines can be applied t o t hem.
By also impor t ing t he simulat ion model, model1, int o t he GUI, it s pr oper t ies
ca n be compar ed t o t hose of t he differ ent est imat ed models.
To simulat e a cont inuous-t ime st at e-spa ce model:
y =Cx +e
wit h t he same input , and a sampling int er val of 0.1 seconds, do t he following
in t he Syst em Ident ifica t ion Toolbox:
A=[-1 1;-0.5 0]; B=[1; 0.5]; C=[1 0]; D=0; K=[0.5;0.5];
model2=ms2th(modstruc(A,B,C,D,K),'c');
model2=sett(model2,0.1);
y=idsim([u e],model2);
x
·
Ax Bu Ke + + =
2 Th e G r a p h i c a l U se r In te rf a c e
2-14
3. Estimating Models
The Basics
Est imat ing models fr om dat a is t he cent r a l act ivit y in t he Syst em
Ident ificat ion Toolbox. It is also t he one t ha t offer s t he most va r iet y of
possibilit ies and t hus is t he most demanding one for t he user .
All est ima t ion r out ines ar e accessed fr om t he pop-up menu Es t i mate in t he
i de nt window. The models a r e always est imat ed using t he dat a set t ha t is
cur r ent ly in t he Worki ng Dat a box.
One ca n dist inguish bet ween t wo differ ent t ypes of est imat ion met hods:
• Dir ect est imat ion of t he Impulse or t he Fr equency Response of t he syst em.
These met hods ar e oft en also called nonpar amet r ic est imat ion met hods, and
do not impose any st r uct ur e assumpt ions about t he syst em, ot her t han t hat
it is linear .
• Par amet r ic met hods. A specific model st r uct ur e is assumed, and t he
par amet er s in t his st r uct ur e ar e est imat ed using dat a. This opens up a lar ge
var iet y of possibilit ies, cor r esponding t o differ ent ways of descr ibing t he
syst em. Dominat ing ways ar e st at e-space and sever al var iant s of differ ence
equat ion descr ipt ions.
Direct Estimation of the Impulse Response
A linear syst em ca n be descr ibed by t he impulse r esponse g
t
, wit h t he pr oper t y
t hat
The name der ives fr om t he fa ct t ha t if t he input u(t) is a n impulse, i.e., u(t)=1
when t=0 a nd 0 when t >0 t hen t he out put y(t ) will be y(t)=g
t
. For a
mult iva r iable syst em, t he impulse r esponse g
k
will be a p by m mat r ix, wher e
p is t he number of out put s and m is t he number of input s. It s i-j element t hus
descr ibed t he behavior of t he i-t h out put aft er an impulse in t he j-t h input .
By choosing menu it em Es t i mate > Correl ati on Mode l and t hen select ing
Es ti mat e in t he dialog window t hat opens, impulse r esponse coefficient s ar e
est imat ed dir ect ly fr om t he input /out put dat a using so called correlat ion
y t ( ) g
k
u t k – ( )
k 1 =


=
2-15
analysis. The a ct ual met hod is descr ibed under t he command cra in t he
Command Reference chapt er . An opt ion t hat det er mines t he or der of a
pr ewhit ening filt er can also be set in t he dia log window. It is not ver y sensit ive
in most cases, and t he default choice is oft en good enough. To obt ain t he defa ult
choice wit hout opening t he dialog window, you can also just t ype t he let t er c in
t he i de nt window. This is t he “hot key” for cor r elat ion a nalysis.
The r esult ing impulse r esponse est imat e is placed in t he Model Boar d, under
t he default na me cra_d. (The name can be changed by double-clicking on t he
model icon and t hen t yping in t he desir ed name in t he dia log box t hat opens.)
The best way t o examine t he r esult is t o select t he Mode l Vi e w Trans i e nt
Re s pons e . This gives a gr a ph of t he est imat ed r esponse. This view offer s a
choice bet ween displaying t he Impulse or t he St ep r esponse. For a
mult ivar iable syst em, t he differ ent channels, i.e., t he r esponses fr om a cer t ain
input t o a cer t ain out put , a r e select ed under menu it em Channe l.
The number of lags for which t he impulse r esponse is est imat ed, i.e., t he lengt h
of t he est imat ed r esponse, is det er mined as one of t he opt ions in t he Tr a nsient
Response View.
Direct Estimation of the Frequency Response
The fr equency r esponse of a linear syst em is t he Four ier t r ansfor m of it s
impulse r esponse. This descr ipt ion of t he syst em gives consider able
engineer ing insight int o it s pr oper t ies. The r elat ion bet ween input a nd out put
is oft en wr it t en
y ( t ) =G(z ) u ( t ) +v ( t )
wher e G is t he t r ansfer funct ion a nd v is t he addit ive dist ur bance. The funct ion
as a funct ion of (angular ) fr equency ω is t hen t he fr equency r esponse or
fr equency funct ion. T is t he sampling int er val. If you need mor e det a ils on t he
differ ent int er pr et a t ions of t he fr equency r esponse, consult See “The Syst em
Ident ificat ion Pr oblem” on page 3-8. in t he Tut orial or any t ext book on linear
syst ems.
The syst em’s fr equency r esponse is dir ect ly est imat ed using S pect ral Analysis
by t he menu it em Es ti mat e > Spec tral Mode l , and t hen select ing t he
Es t i mat e but t on in t he dialog box t hat opens. The r esult is placed on t he Model
G e
iωT
( )
2 Th e G r a p h i c a l U se r In te rf a c e
2-16
Boar d under t he defa ult na me spa_d. The best way t o examine it is t o plot it
using t he Mode l Vi e w Freque nc y Re s pons e . This view offer s a number of
differ ent opt ions on how t o gr aph t he cur ves. The fr equencies for which t o
est imat e t he r esponse can a lso be select ed as an opt ion under t he Opt i ons
menu in t his Vi e w window.
The Spect r al Analysis command also est imat es t he spect r um of t he addit ive
dist ur bance v(t) in t he syst em descr ipt ion. This est imat ed dist ur bance
spect r um is examined under t he Mode l Vi e w it em Noi s e Spe ct rum.
The Spect r a l Analysis est imat e is st or ed in t he SITB’s freqfunc for mat . If you
need t o fur t her wor k wit h t he est imat es, you can expor t t he model t o t he
MATLAB wor kspace and r et r ieve t he r esponses by t he command getff. See
freqfunc and getff in Chapt er 4, "Command Refer ence," for mor e
infor mat ion. (A model is expor t ed by dr agging and dr opping it over t he To
Works pace icon.)
Two opt ions t hat a ffect t he spect r al analysis est ima t e can be set in t he dialog
box. The most impor t ant choice is a number , M, (t he size of t he lag window)
t hat affect s t he fr equency r esolut ion of t he est ima t es. Essent ially, t he
fr equency r esolut ion is about 2 /M r a dians/(sampling int er val). The choice of
M is a t r a de-off bet ween fr equency r esolut ion and var ia nce (fluct uat ions). A
lar ge value of M gives good r esolut ion but fluct ua t ing and less r eliable
est imat es. The defa ult choice of M is good for syst ems t hat do not have ver y
shar p r esonances and may have t o be adjust ed for mor e r esonant syst ems.
The opt ions also offer a choice bet ween t he Blackman-Tukey windowing
met hod spa (which is default ) and a met hod based on smoot hing dir ect Four ier
t r ansfor ms, etfe. etfe ha s a n a dvant age for highly r esonant syst ems, in t ha t
it is mor e efficient for lar ge values of M. It however has t he dr awbacks t hat it
r equir es linear ly spaced fr equency values, does not est ima t e t he dist ur bance
spect r um, and does not pr ovide confidence int er vals. The act ua l met hods ar e
descr ibed in mor e det ail in Chapt er 4, "Command Refer ence," under spa and
etfe. To obt ain t he spect r a l analysis model for t he cur r ent set t ings of t he
opt ions, you can just t ype t he hot key s in t he i de nt window.
π
2-17
Estimation of Parametric Models
The SITB suppor t s a wide r ange of model st r uct ur es for linear syst ems. They
ar e all accessed by t he menu it em Est i mat e > Parame t ri c Mode ls ... in t he
i de nt window. This opens up a dialog box Parame t ri c Mode ls , which
cont ains t he basic dialog for all par amet r ic est imat ion as shown on t he
following pa ge
Figure 2-3: The Dialog Box for Estimating Parametric Models
The basic funct ion of t his box is a s follows:
As you select Es t i mat e, a model is est imat ed fr om t he Wor king Dat a. The
st r uct ur e of t his model is defined by t he pop-up menu St ruct ure t oget her wit h
t he edit box Orde rs . It is given a name, which is wr it t en in t he edit box Name .
The GUI will always suggest a default model na me in t he Name box, but you
ca n change it t o any st r ing befor e select ing t he Es t i mate but t on. (If you int end
t o expor t t he model lat er , avoid spaces in t he name.)
2 Th e G r a p h i c a l U se r In te rf a c e
2-18
The int er pr et at ion of t he model st r uct ur e infor ma t ion (t ypically int eger s) in
t he Orde r box, depends on t he select ed St ruct ure in t he pop-up menu. This
cover s, t ypically, six choices:
• ARX models
• ARMAX model
• Out put -Er r or (OE) models
• Box-J enkins (BJ ) models
• St at e-spa ce models
• Model st r uct ur e defined by Init ial Model (User defined st r uct ur es)
These ar e dealt wit h one by one shor t ly.
You can fill out t he Orde r box your self at any t ime, but for assist ance you can
select Orde r Edi tor... This will open up anot her dialog box, depending on t he
chosen St ruct ure , in which t he desir ed model or der and st r uct ur e infor mat ion
can be ent er ed in a simpler fashion.
You can also ent er a na me of a MATLAB wor kspace var iable in t he or der edit
box. This var iable should t hen have a value t hat is consist ent wit h t he
necessar y or der s for t he chosen st r uct ur e.
NOTE: For t he st at e-spa ce st r uct ur e and t he ARX st r uct ur e, sever al or der s
and combinat ion of or der s ca n be ent er ed. Then all cor r esponding models will
be compar ed and displayed in a special dialog window for you t o select
suit able ones. This could be a useful t ool t o select good model or der s. This
opt ion is descr ibed in mor e det a il la t er in t his sect ion. When it is available, a
but t on Orde r se l e ct i on is visible.
Estimation Method
A common a nd gener al met hod of est imat ing t he par amet er s is t he predict ion
error approach, wher e simply t he pa r amet er s of t he model ar e chosen so t hat
t he differ ence bet ween t he model’s (pr edict ed) out put and t he measur ed out put
is minimized. This met hod is available for a ll model st r uct ur es. Except for t he
ARX case, t he est imat ion involves an it er at ive, numer ical sear ch for t he best
fit .
2-19
To obt ain infor mat ion fr om a nd int er act wit h t his sea r ch, select It e rati on
cont rol... This also gives access t o a number of opt ions t hat gover n t he sear ch
pr ocess. (See auxvar in t he Chapt er 4, "Command Refer ence,".)
For some model st r uct ur es (t he ARX model, and black-box st at e-space models)
met hods based on cor r elat ion ar e also available: Inst r ument al Var iable (IV)
and Sub-space (N4SID) met hods. The choice bet ween met hods is made in t he
Parame t ri c Mode l s dialog box.
Resulting Models
The est imat ed model is inser t ed int o t he GUI’s Model Boar d. You can t hen
examine it s va r ious pr oper t ies a nd compar e t hem wit h ot her models’ pr oper t ies
using t he Mode l Vi e w plot s. Mor e about t hat in “Examining Models” on page
2-27.
To t ake a look at t he model it self, double-click on t he model’s icon (middle/r ight
mouse but t on or alt - double-click). The Dat a/Mode l Info window t hat t hen
opens gives you infor mat ion about how t he model was est imat ed. You can t hen
also select Pre se nt but t on, which will list t he model, and it s par a met er s wit h
est imat ed st a ndar d deviat ions in t he MATLAB comma nd window.
If you need t o wor k fur t her wit h t he model, you can expor t it by dr agging and
dr opping it over t he To Workspace icon, and t hen apply any MATLAB a nd
t oolbox commands t o it . (See, in par t icular , t he commands th2ss, th2tf,
th2par, and thd2thc in Cha pt er 4, "Command Refer ence,".)
How to Know Which Structure and Method to Use
Ther e is no simple way t o find out “t he best model st r uct ur e”; in fact , for r ea l
dat a, t her e is no such t hing as a “best ” st r uct ur e. Some r out es t o find good and
accept able model ar e descr ibed in “A St ar t up Ident ificat ion Pr ocedur e” on page
1-12 in t he int r oduct or y chapt er . It is best t o be gener ous at t his point . It oft en
t akes just a few seconds t o est imat e a model, and by t he differ ent validat ion
t ools descr ibed in t he next sect ion, you can quickly find out if t he new model is
any bet t er t han t he ones you had befor e. Ther e is oft en a significant amount of
wor k behind t he dat a collect ion, and spending a few ext r a minut es t r ying out
sever al differ ent st r uct ur es is usually wor t h while.
2 Th e G r a p h i c a l U se r In te rf a c e
2-20
ARX Models
The Structure
The most used model st r uct ur e is t he simple linear differ ence equat ion
which r elat es t he cur r ent out put y(t ) t o a finit e number of past out put s y(t -k )
and input s u(t -k).
The st r uct ur e is t hus ent ir ely defined by t he t hr ee int eger s na, nb, and nk. na
is equal t o t he number of poles and nb–1 is t he number of zer os, while nk is t he
pur e t ime-delay (t he dead-t ime) in t he syst em. For a syst em under
sa mpled-dat a cont r ol, t ypically nk is equal t o 1 if t her e is no dead-t ime.
For mult i-input syst ems nb and nk ar e r ow vect or s, wher e t he i-t h element
gives t he or der /delay associat ed wit h t he i-t h input .
Entering the Order Pa rameters
The or der s na, nb, and nk can eit her be dir ect ly ent er ed int o t he edit box
Orde rs in t he Paramet ri c Mode l s window, or select ed using t he pop-up
menus in t he Orde r Edi t or.
Estimating Many Models Simultaneously
By ent er ing any or all of t he st r uct ur e par amet er s as vect or s, using MATLAB’s
colon not at ion, like na=1:10, et c., you define many differ ent st r uct ur es t hat
cor r espond t o all combinat ions of or der s. When select ing Est i mat e , models
cor r esponding t o all of t hese st r uct ur es ar e comput ed. A special plot window
will t hen open t hat shows t he fit of t hese models t o Validat ion Dat a. By clicking
in t his plot , you can t hen ent er any models of your choice int o t he Model Boar d.
Mult i -i nput mode l s : For mult i-input models you ca n of cour se ent er each of
t he input or der s and delays as a vect or . The number of models r esult ing fr om
all combinat ions of or der s a nd delays can however be ver y la r ge. As an
alt er na t ive, you ma y ent er one vect or (like nb=1:10) for all input s a nd one
vect or for all delays. Then only such models a r e comput ed t hat have t he same
or der s and dela ys fr om all input s.
y t ( ) a
1
y t 1 – ( ) … a
na
y t na – ( ) + + + b
1
u t nk – ( ) … b
nb
u t nk – nb – 1 + ( ) + + =
2-21
Estimation Methods
Ther e ar e t wo met hods t o est imat e t he coefficient s a and b in t he ARX model
st r uct ur e:
Le as t Square s : Minimizes t he sum of squa r es of t he r ight -hand side minus
t he left -hand side of t he expr ession above, wit h r espect t o a a nd b. This is
obt ained by select ing ARX as t he Met hod.
Ins trume nt al Vari abl e s : Det er mines a and b so t hat t he er r or bet ween t he
r ight - and left - hand sides becomes uncor r elat ed wit h cer t ain linear
combinat ions of t he input s. This is obt ained by select ing IV in t he Me t hod box.
The met hods ar e descr ibed in mor e det ail in Chapt er 4, "Command Refer ence,"
under arx and iv4.
Multi-Output Models
For a mult i-out put ARX st r uct ur e wit h NY out put s and NU input s, t he
differ ence equa t ion above is st ill valid. The only change is t ha t t he coefficient s
a a r e NY by NY mat r ices and t he coefficient s b ar e NY by NU mat r ices.
The or der s [NA NB NK] define t he model st r uct ur e as follows:
NA: an NY by NY mat r ix whose i-j ent r y is t he or der of t he polynomial (in t he
delay oper at or ) t hat r elat es t he j-t h out put t o t he i-t h out put
NB: an NY by NU mat r ix whose i-j ent r y is t he or der of t he polynomial t hat
r elat es t he j-t h input t o t he i-t h out put
NK: an NY by NU mat r ix whose i-j ent r y is t he delay fr om t he j-t h input t o t he
i-t h out put
The Order Edi t or dialog box allows t he choices
NA = na∗ones(NY,NY)
NB = nb∗ones(NY,NU)
NK = nk∗ones(NY,NU)
wher e na, nb, and nk ar e chosen by t he pop-up menus.
For t ailor -made or der choices, const r uct a mat r ix [NA NB NK] in t he MATLAB
command window and ent er t he name of t his ma t r ix in t he Order edit box in
t he Parame t ri c Mode l s window.
Not e t hat t he possibilit y t o est imat e many models simult aneously is not
ava ilable for mult i-out put ARX models.
See “Defining Model St r uct ur es” on page 3-29 for mor e infor mat ion on
mult i-out put ARX models.
2 Th e G r a p h i c a l U se r In te rf a c e
2-22
ARMAX, Output-Error and Box -Jenkins Models
Ther e ar e sever al elabor at ions of t he ba sic ARX model, wher e differ ent noise
models ar e int r oduced. These include well known model t ypes, such as
ARMAX, Out put -Er r or , and Box-J enkins.
The General Structure
A gener al input -out put linear model for a single-out put syst em wit h input u
and out put y can be wr it t en:
Her e u
i
denot es input #i, and A, B
i
, C, D, a nd F
i
, ar e polynomials in t he shift
oper at or (z or q). (Don’t get int imidat ed by t his: It is just a compa ct way of
wr it ing differ ence equa t ions; see below.)
The gener al st r uct ur e is defined by giving t he t ime-delays nk and t he or der s of
t hese polynomials (i.e., t he number of poles a nd zer os of t he dynamic model
fr om u t o y, as well as of t he noise model fr om e t o y).
The Special Cases
Most oft en t he choices ar e confined t o one of t he following special cases:
ARX: A(q) y(t ) = B(q) u(t -nk) + e(t )
ARMAX: A(q) y(t ) = B(q) u(t -nk) + C(q) e(t )
OE: y(t ) = [B(q)/F(q)] u(t -nk) + e(t ) (Out put -Er r or )
BJ : y(t ) = [B(q)/F(q)] u(t -nk) + [C(q)/D(q)] e(t ) (Box-J enkins)
The “shift oper a t or polynomia ls” ar e just compact ways of wr it ing differ ence
equat ions. For example t he ARMAX model in longhand would be:
y ( t ) +a
1
( t - 1 )+. . . +a
na
y ( t - n a )=b
1
u ( t - n k )+. . . b
nb
u (t -n k - n b +1 ) +e(t )
+c
1
e(t - 1)
+. . . +e
nc
e(t -n c)
Not e t hat A(q) cor r esponds t o poles t hat ar e common bet ween t he dynamic
model a nd t he noise model (useful if noise ent er s t he syst em “close t o” t he
input ). Likewise F(q) det er mines t he poles t hat ar e unique for t he dyna mics
fr om input # i, and D(q) t he poles t hat ar e unique for t he noise.
A q ( )y t ( ) B
i
q ( ) F
i
q ( ) ] ⁄ u
i
t nk
1
– ( ) C q ( ) D q ( ) ] ⁄ e t ( ) [ + [
i 1 =
nu

=
2-23
The mot ivat ion for int r oducing all t hese model var iant s is t o pr ovide for
flexibilit y in t he noise descr ipt ion and t o allow for common or differ ent poles
(dyna mics) for t he differ ent input s.
Entering the Model Structure
Use t he St ruct ure pop-up menu in t he Parame t ri c Mode l s dialog t o choose
bet ween t he ARX, ARMAX, Out put -Er r or , and Box-J enkins st r uct ur es. Not e
t hat if t he Wor king Dat a set has sever al out put s, only t he fir st choice is
ava ilable. For t ime ser ies (dat a wit h no input signa l) only AR and ARMA ar e
ava ilable a mong t hese choices. These ar e t he t ime ser ies count er par t s of ARX
and ARMAX.
The or der s of t he polynomials ar e select ed by t he pop-up menus in t he Orde r
Edi tor dialog window, or by dir ect ly ent er ing t hem in t he edit box Orde rs in
t he Parame t ri c Mode l s window. When t he or der edit or is open, t he default
or der s, ent er ed as you change t he model st r uct ur e, ar e based on pr eviously
used or der s.
Estimation Method
The coefficient s of t he polynomia ls a r e est imat ed using a pr edict ion er r or /
Maximum Likelihood met hod, by minimizing t he size of t he er r or t er m “e” in
t he expr ession above. Sever al opt ions gover n t he minimizat ion pr ocedur e.
These ar e accessed by act ivat ing It e rat i on Cont rol in t he Parame tri c
Mode l s window, and select ing Opt i on.
The algor it hms ar e fur t her descr ibed in Chapt er 4, "Command Refer ence,"
under armax, auxvar, bj, oe, and pem. See also “Pa r amet r ic Model Est imat ion”
on page 3-22 a nd “Defining Model St r uct ur es” on page 3-29.
NOTE: These model st r uct ur es ar e available only for t he scalar out put case.
For mult i-out put models, t he st at e-spa ce st r uct ur es offer t he same flexibilit y.
Also not e t hat it is not possible t o est imat e many differ ent st r uct ur es
simult aneously for t he input -out put models.
2 Th e G r a p h i c a l U se r In te rf a c e
2-24
State-Space Models
The Model Structure
The basic st at e-space model in innovat ions for m can be wr it t en
x ( t +1) = A x ( t ) + B u (t ) + K e(t )
y ( t ) = C x ( t ) + D u (t ) + e(t )
The SITB suppor t s t wo kinds of pa r amet r izat ions of st at e-space models:
bla ck-box, fr ee par amet r izat ions, and par amet r izat ions t ailor -made t o t he
applicat ion. The la t t er is discussed below under t he heading “User Defined
Model St r uct ur es.” Fir st we will discuss t he bla ck-box case.
Entering Bla ck-Box State-Space Model Structures
The most impor t ant st r uct ur e index is t he model or der , i.e., t he dimension of
t he st at e vect or x.
Use t he pop-up menu in t he Orde r Edi t or t o choose t he model or der , or ent er
it dir ect ly int o t he Orde rs edit box in t he Parame tri c Mode l s window. Using
t he ot her pop-up menus in t he Orde r Edi t or, you can fur t her affect t he chosen
model st r uct ur e:
• Fixing K t o zer o gives an Out put -Er r or met hod, i.e., t he differ ence bet ween
t he model’s simulat ed out put and t he measur ed one is minimized. For mally,
t his cor r esponds t o an a ssumpt ion t ha t t he out put dist ur bance is whit e
noise.
• Fixing D t o zer o means t ha t t her e is a delay of (at least ) one sa mple fr om t he
input t o t he out put . For physical syst ems t hat ar e dr iven by piece-wise
const ant input s, t his is a nat ur al assumpt ion.
• Fixing t he init ial value x(0) t o zer o means t hat t he init ial st at e is not
est imat ed. Ot her wise t his init ial st at e is est imat ed fr om t he dat a. (Not e t hat
t he est imat ed value of x(0) is somet hing t hat r elat es t o t he Wor king Dat a ,
and is not necessar ily a good va lue of x(0) for t he Va lidat ion Da t a.)
Estimating Many Models Simultaneously
By ent er ing a vect or for t he model or der , using MATLAB’s colon not at ion, (such
as “1:10”) all indicat ed or der s will be comput ed using a pr eliminar y met hod.
You ca n t hen ent er models of differ ent or der s int o t he Model Boar d by clicking
in a special gr aph t hat cont ains infor mat ion about t he models.
2-25
Estimation Methods
Ther e ar e t wo basic met hods for t he est imat ion:
PEM: Is a st andar d pr edict ion er r or /maximum likelihood met hod, based on
it er at ive minimizat ion of a cr it er ion. The it er a t ions ar e st a r t ed up at
par a met er values t hat ar e comput ed fr om n4sid. The par amet r izat ion of t he
mat r ices A, B, C, D, and K follows a default canonical for m. The sear ch for
minimum is cont r olled by a number of opt ions. These ar e accessed fr om t he
Opt i on but t on in t he Ite rat i on Control window.
N4SID: Is a subspa ce-based met hod t hat does not use it er at ive sear ch. The
qua lit y of t he r esult ing est imat es may significant ly depend on an auxiliar y
or der (like a pr edict ion hor izon). This auxiliar y or der can be given wit hin
par ent hesis aft er t he or der in t he edit box Orde rs (like “4 (9)”). If t he auxiliar y
or der is not given, a default va lue is used.
If t he auxiliar y or der is given as a vect or (like “4 (5:17)”), models for all t hese
auxiliar y or der s a r e comput ed and evaluat ed using t he Wor king Dat a set . The
model t hat gives t he best fit is chosen. A figur e is shown t ha t illust r at es t he fit
as a funct ion of auxiliar y or der . (The fit is a simulat ion er r or fit if K=0 is
chosen, ot her wise a one-st ep ahead pr edict ion er r or fit .)
See n4sid and pem in Chapt er 4, "Command Refer ence," for mor e infor mat ion.
User Defined Model Structures
Sta te-Space Structures
The SITB suppor t s user -defined linear st at e-space models of ar bit r ar y
st r uct ur e. Using t he command ms2th, known and unknown par amet er s in t he
A, B, C, D, K, and X0 mat r ices ca n be easily defined bot h for discr et e- and
cont inuous-t ime models. The command mf2th a llows you t o use a complet ely
ar bit r a r y st r uct ur e, defined by an M-file. fixpar and unfixpar can be used t o
manipulat e st r uct ur es. See Chapt er 4, "Command Refer ence," and “Defining
Model St r uct ur es” on page 3-29
To use t hese st r uct ur es in conjunct ion wit h t he GUI, just define t he
appr opr iat e st r uct ur e in t he MATLAB comma nd window. Then use t he
Structure pop-up menu t o select By Ini t i al Model and ent er t he var iable
name of t he st r uct ur e in t he edit box Ini t i al Mode l in t he Parame t ri c
Mode l s window and select Est i mat e .
2 Th e G r a p h i c a l U se r In te rf a c e
2-26
Any Model Structure
Ar bit r ar y model st r uct ur es can be defined using sever al commands in t he
Syst em Ident ificat ion Toolbox:
• poly2th: Cr eat es Input -out put st r uct ur es for single-out put models
• ms2th: Cr eat es Linear St at e-space models wit h ar bit r ar y, fr ee par a met er s
• mf2th: Cr eat es complet ely a r bit r ar y par amet r izat ions of linea r syst ems
• arx2th: Cr eat es mult ivar iable ARX st r uct ur es
• fixpar/unfixpar: Modifies st r uct ur es by fixing or unfixing par amet er s
In addit ion, all est imat ion commands cr eat e model st r uct ur es in t er ms of t he
r esult ing models.
Ent er t he name of any model st r uct ur e in t he box Orde rs (or Ini t i al mode l )
in t he window Paramet ri c Mode l s a nd t hen select Es ti mat e . Then t he
par amet er s of t he model st r uct ur e ar e adjust ed t o t he chosen Wor king Dat a
set . The met hod is a st andar d pr edict ion er r or /ma ximum likelihood appr oach
t hat it er at ively sear ches for t he minimum of a cr it er ion. Opt ions t hat gover n
t his sear ch ar e accessed by t he Opt i on but t on in t he Ite rat i on Cont rol
window.
The name of t he init ial model must be a va r iable eit her in t he wor kspace or in
t he Model Boar d. In t he la t t er ca se you can just dr ag a nd dr op it over t he
Orde rs /Ini ti al mode l edit box.
2-27
4. Examining Models
Having est imat ed a model is just a fir st st ep. It must now be exa mined,
compar ed wit h ot her models, and t est ed wit h new dat a set s. This is pr imar ily
done using t he six Mode l Vi e w funct ions, a t t he bot t om of t he main i de nt
window:
• Fr equency r esponse
• Tr ansient r esponse
• Zer os and poles
• Noise spect r um
• Model out put
• Model r esiduals
In addit ion, you can double-click on t he model’s icon t o get Te xt Informat i on
about t he model. Finally, you ca n expor t t he model t o t he MATLAB wor kspa ce
and use any commands for fur t her a nalysis and model use.
View s and Models
The basic idea is t ha t if a cer t ain Vi e w window is open (checked), t hen all
models in t he Model Summar y Boar d t hat ar e select ed will be r epr esent ed in
t he window. The cur ves in t he Vi e w window can be clicked in and out by
select ing and deselect ing t he models in an online fashion. You select and
deselect a model by clicking on it s icon. An select ed model is mar ked wit h a
t hicker line in it s icon.
On color scr eens, t he cur ves ar e color coded along wit h t he model icons in t he
Model Boar d. Befor e pr int ing a plot it might be a good idea t o separ a t e t he line
st yles (menu it em under Style ). This could also be helpful on bla ck and whit e
scr eens.
Not e t hat models t hat ar e obt ained by spect r a l analysis only can be
r epr esent ed a s fr equency r esponse a nd noise spect r a, and t ha t models
est imat ed by cor r elat ion analysis only can be r epr esent ed as t r ansient
r esponse.
2 Th e G r a p h i c a l U se r In te rf a c e
2-28
The Plot Window s
The six views all give similar plot windows, wit h sever a l common feat ur es.
They have a common menu bar , which cover s some basic funct ions.
Fir st of all, not e t hat t her e is a zoom funct ion in t he plot window. By dr agging
wit h t he left mouse but t on down, you can dr aw r ect a ngles, which will be
enlar ged when t he mouse but t on is r eleased. By double-clicking, t he or igina l
axis scales ar e r est or ed. For plot s wit h t wo axes, t he x-axes scales ar e locked t o
each ot her . A single click on t he left mouse but t on zooms in by a fact or of t wo,
while t he middle but t on zooms out . The zoom funct ion can be dea ct ivat ed if
desir ed. J ust select t he menu it em Zoom under St yl e .
Second, by point ing t o any cur ve in t he plot , and pr essing t he r ight mouse
but t on, t he cur ve will be ident ified wit h model name and pr esent coor dinat es.
The common menu ba r cover s t he following funct ions:
File
File a llows you t o copy t he cur r ent figur e t o anot her , st a ndar d MATLAB figur e
window. This might be useful, e.g., when you int end t o pr int a cust omized plot .
Ot her Fi le it ems cover pr int ing t he cur r ent plot and closing t he plot window.
Options
Opt ions fir st of all cover s act ions for set t ing t he a xes sca ling. This menu it em
also gives a number of choices t hat a r e specific for t he plot window in quest ion,
like a choice bet ween st ep r esponse or impulse r esponse in t he Trans i e nt
re spons e window.
A most impor t ant opt ion is t he possibilit y t o show confidence int er vals. Each
model pr oper t y has some uncer t aint y. This ca n also be est imat ed fr om da t a. By
checking Show confi de nce i nt e rval s , a confidence r egion ar ound t he
nominal cur ve (model pr oper t y) will be mar ked (by dash-dot t ed lines). The level
of confidence can also be set under t his menu it em.
NOTE: Confidence int er vals ar e suppor t ed for most models and pr oper t ies,
except models est imat ed using n4sid a nd etfe, and t he k-st ep ahead
pr edict ion-pr oper t y.
2-29
Style
The st yle menu gives access t o var ious ways of affect ing t he plot . You can add
gr idlines, t ur n t he zoom on and off, and change t he linest yles. The menu also
cover s a number of ot her opt ions, like choice of unit s and scale for t he axis.
Channel
For mult ivar iat e syst ems, you ca n choose which input -out put channel t o
examine. The cur r ent choice is mar ked in t he figur e t it le.
Help
The He l p menu has a number of it ems, which explain t he plot and it s opt ions.
Frequency Response and Disturbance Spectra
All linear models t hat ar e est imat ed can be wr it t en in t he for m
y ( t ) =G(z ) u ( t ) +v ( t )
wher e G(z) is t he (discr et e-t ime) t r ansfer funct ion of t he syst em and v(t ) is an
addit ive dist ur bance. The fr equency r esponse or fr equency funct ion of t he
syst em is t he complex-valued funct ion G(e
iωT
) viewed as a funct ion of angular
fr equency ω.
This funct ion is oft en gr aphed as a Bode diagr am, i.e., t he logar it hm of t he
amplit ude (t he absolut e value) G(e
iωT
) a s well as t he phase ar g (t he ar gument )
G(e
iωT
) ar e plot t ed a gainst t he logar it hm of fr equency ω in t wo sepa r at e plot s.
These plot s ar e obt a ined by checking t he Mode l Vi e w Fre que ncy Re s pons e
in t he main i dent window.
The est imat ed spect r um of t he dist ur bance v is plot t ed as a power spect r um by
choosing t he Mode l Vi e w Noi s e Spe ct rum.
If t he dat a is a t ime ser ies y (wit h no input u), t hen t he spect r um of y is plot t ed
under Noi s e Spe ct rum, and no fr equency funct ions ar e given.
Transient Response
Good a nd simple insight int o a model’s dynamic pr oper t ies is obt a ined by
looking at it s st ep r esponse or impulse r esponse. This is t he out put of t he model
when t he input is a st ep or an impulse. These r esponses ar e plot t ed when t he
Mode l Vi e w Trans i e nt Re s pons e is checked.
2 Th e G r a p h i c a l U se r In te rf a c e
2-30
It is quit e infor mat ive t o compar e t he t r ansient r esponse of a par amet r ic
model, wit h t he one t hat wa s est imat ed using cor r elat ion analysis. If t her e is
good agr eement bet ween t he t wo, you can be quit e confident t hat some
essent ially cor r ect feat ur es have been picked up. It is useful t o check t he
confidence int er va ls ar ound t he r esponses t o see what “good agr eement ” could
mean quant it at ively.
Ma ny models pr ovide a descr ipt ion of t he addit ive dist ur bance v(t ):
v ( t ) =H( z )e(t )
Her e H(z) is a t r ansfer funct ion t hat descr ibes how t he dist ur bance v(t ) can be
t hought of as gener at ed by sending whit e noise e(t) t hr ough it . To displa y t he
pr oper t ies of H, you ca n choose channels (in t he Channe l menu) t ha t have
noise component s as input s.
Poles and Zeros
The poles of a syst em a r e t he r oot s of t he denominat or of t he t r ansfer funct ion
G(z), while t he zer os ar e t he r oot s of t he numer at or . In par t icular t he poles
have a dir ect influence on t he dynamic pr oper t ies of t he syst em.
The poles and zer os of G (and H ) ar e plot t ed by choosing t he Mode l Vi e w
Pol e s and Ze ros.
It is useful t o t ur n on t he confidence int er vals in t his case. They will clear ly
r eveal which poles a nd zer os could ca ncel (t heir confidence r egions over lap).
Tha t is an indicat ion t ha t a lower or der dynamic model could be used.
For mult ivar iable syst ems it is t he poles and zer os of t he individual input /
out put channels t hat ar e displa yed. To obt ain t he so called t r ansmission zer os,
you will have t o expor t t he model, ext r act a st at e-spa ce descr ipt ion by th2ss,
and t hen apply t he command tzero fr om t he Cont r ol Syst em Toolbox.
Compare Measured and Model Output
A ver y good way of obt aining insight int o t he qualit y of a model is t o simulat e
it wit h t he input fr om a fr esh dat a set , and compar e t he simulat ed out put wit h
t he measur ed one. This gives a good feel for which pr oper t ies of t he syst em
have been picked up by t he model, and which haven’t .
This t est is obt ained by checking t he Mode l Vi e w Mode l Out put. Then t he
dat a set cur r ent ly in t he Val i dat i on Dat a box will be used for t he compar ison.
2-31
The fit will also be displa yed. This is comput ed as t he r oot of t he mean squa r e
value of t he differ ence bet ween measur ed and simulat ed out put .
If t he model is unst able, or has int egr at ion or ver y slow t ime const ant s, t he
levels of t he simulat ed and t he measur ed out put may dr ift a par t , even for a
model t hat is quit e good (at lea st for cont r ol pur poses). It is t hen a good idea t o
evaluat e t he model’s pr edict ed out put r at her t han t he simula t ed one. Wit h a
prediction horizon of k, t he k-st ep ahead pr edict ed out put is t hen obt ained as
follows:
The pr edict ed value y(t ) is comput ed fr om all a vailable input s (used
accor ding t o t he model) and a ll available out put s up t o t ime t-k, .
The simula t ion case, wher e no past out put s at all ar e used, t hus for mally
cor r esponds t o k=∞. To check if t he model has picked up int er est ing dynamic
pr oper t ies, it is wise t o let t he pr edict ed t ime hor izon (kT, T being t he sampling
int er val) be lar ger t han t he impor t ant t ime const a nt s.
Not e her e t hat differ ent models use t he infor mat ion in past out put dat a in t heir
pr edict or s in differ ent ways. This depends on t he noise model. For example, so
ca lled Out put -Er r or models (obt ained by fixing K t o zer o for st at e-space models
and set t ing na=nc=nd=0 for input out put models, see t he pr evious sect ion) do
not use past out put s at all. The simulat ed and t he pr edict ed out put s, for a ny
value of k, t hus coincide.
Residual Analysis
In a model
t he noise sour ce e(t ) r epr esent s t hat par t of t he out put t hat t he model could not
r epr oduce. It gives t he “left -over s” or , in Lat in, t he residuals. For a good model,
t he r esiduals should be independent of t he input . Ot her wise, t her e would be
mor e in t he out put t hat or iginat es fr om t he input and t hat t he model has not
picked up.
To t est t his independence, t he cr oss-cor r ela t ion funct ion bet ween input and
r esiduals is comput ed by checking t he Mode l Vi e w Mode l Re s i duals . It is
wise t o also display t he confidence r egion for t his funct ion. For a n ideal model
t he cor r elat ion funct ion should lie ent ir ely bet ween t he confidence lines for
posit ive lags. If, for example, t her e is a peak out side t he confidence r egion for
lag k, t his means t hat t her e is somet hing in t he out put y(t ) t hat or iginat es fr om
u(t -k) and t hat has not been pr oper ly descr ibed by t he model. The t est is car r ied
u s ( ) s t ≤ ( )
y s ( ) s t k – ≤ ( )
y t ( ) G z ( )u t ( ) H z ( )e t ( ) + =
2 Th e G r a p h i c a l U se r In te rf a c e
2-32
out using t he Validat ion Dat a . If t hese wer e not used t o est imat e t he model, t he
t est is quit e t ough. See also “Model St r uct ur e Select ion and Validat ion” on page
3-49.
For a model also t o give a cor r ect descr ipt ion of t he noise pr oper t ies (i.e., t he
t r ansfer funct ion H), t he r esiduals should be mut ually independent . This t est
is also car r ied out by t he view Mode l Re s i dual s, by displaying t he
aut o-cor r elat ion funct ion of t he r esiduals (excluding lag zer o, for which t his
funct ion by definit ion is one). For an ideal model, t he cor r elat ion funct ion
should be ent ir ely inside t he confidence r egion.
Tex t Information
By double-clicking (middle/r ight mouse but t on or alt -double-click) on t he model
icon, a Dat a/mode l Info dialog box opens, which cont ains some basic
infor mat ion about t he model. It also gives a diar y of how t he model was cr ea t ed,
along wit h t he not es t hat or igina lly wer e associat ed wit h t he est imat ion dat a
set . At t his point you can do a number of t hings:
Present
Select ing t he Pres e nt but t on displays det ails of t he model in t he MATLAB
comma nd window. The model’s pa r amet er s a long wit h est imat ed st andar d
deviat ions ar e displayed, as well as some ot her not es.
Modify
You can simply t ype in a ny t ext you want anywher e in t he Di ary and Not e s
edit able t ext field of t he dialog box. You can a lso cha nge t he name of t he model
just by edit ing t he t ext field wit h t he model name. The color , which t he model
is associat ed wit h in all plot s, can also be edit ed. Ent er RGB-values or a color
name (like 'y') in t he cor r esponding box.
Further Analysis in the MATLAB Workspace
Any model and dat a object can be expor t ed t o t he MATLAB wor kspace by
dr agging and dr opping it s icon over t he To Works pac e box in t he i de nt
window.
2-33
Once you have expor t ed t he model t o t he wor kspace, t her e ar e lot s of
commands by which you can fur t her t r ansfor m it , exa mine it , and conver t it t o
ot her for mat s for use in ot her t oolboxes. Some examples of such commands a r e
Also, if you need t o pr epa r e specialized plot s t hat ar e not cover ed by t he Vi e ws ,
all t he SITB commands for comput ing a nd ext r act ing simulat ions, fr equency
funct ions, zer os and poles, et c., ar e available. See Chapt er 3, "Tut or ia l," and
Cha pt er 4, "Command Refer ence,".
thd2thc Tr a nsfor m t o cont inuous t ime.
th2ss Conver t t o st at e-space r epr esent at ion.
th2tf Conver t t o t r ansfer funct ion for m.
th2poly Conver t t o polynomial input /out put for m.
2 Th e G r a p h i c a l U se r In te rf a c e
2-34
5. Some Further GUI Topics
This sect ion discusses a number of differ ent t opics.
Mouse Buttons and Hotkeys
The GUI uses t hr ee mouse but t ons. If you have fewer but t ons on your mouse,
t he act ions associa t ed wit h t he middle and r ight mouse but t ons ar e obt ained
by shift -click, alt -click or cont r ol-click, depending on t he comput er .
The Main ident Window
In t he main i de nt window t he mouse but t ons ar e used t o dr ag and dr op, t o
select /deselect models and dat a set s, and t o double-click t o get t ext infor mat ion
about t he object . You can use t he left mouse but t on for all of t his. A cer t ain
speed-up is obt ained if you use t he left but t on for dr a gging and dr opping, t he
r ight one for select ing models and dat a set s, a nd t he middle one for
double-clicking. On a slow machine a double-click fr om t he left but t on might
not be r ecognized.
The i de nt window a lso has a number of hot keys. By pr essing a keyboar d let t er
when it is t he cur r ent window, some funct ions can be quickly act ivat ed. These
ar e
• s: Comput es Spec tral Analysi s Mode l using t he cur r ent opt ions set t ings.
(These can be cha nged in t he dialog window t hat opens when you choose
Spe ct ral Mode l in t he Es ti mat e pop-up menu.)
• c: Comput es Corre l at i on Analys i s Mode l using t he cur r ent opt ions
set t ings. (These can be cha nged in t he dialog window t hat opens when you
choose Corre l at i on Mode l in t he Es t i mate pop-up menu.)
• q: Comput es t he models associat ed wit h t he Qui c ks t art .
• d: Opens a dialog window for impor t ing Data t hat ar e in t he SITB dat a
for mat .
Plot Window s
In t he var ious plot windows t he act ion of t he mouse but t ons depends on
whet her t he zoom is act ivat ed or not :
Zoom Act i ve : Then t he left and middle mouse but t ons a r e associa t ed wit h t he
zoom funct ions as in t he st andar d MATLAB zoom. Left but t on zooms in and t he
middle one zooms out . In a ddit ion, you can dr aw r ect angles wit h t he left
2-35
but t on, t o define t he ar ea t o be zoomed. Double-clicking r est or es t he or iginal
plot . The r ight mouse but t on is associat ed wit h special GUI a ct ions t hat depend
on t he window. In t he Vi e w plot s, t he r ight mouse but t on is used t o ident ify
t he cur ves. Point and click on a cur ve, and a box will display t he name of t he
model/dat a set t hat t he cur ve is associat ed wit h, and also t he cur r ent
coor dinat e va lues for t he cur ve. In t he Mode l Se le c ti on plot s t he r ight mouse
but t on is used t o inspect and select t he var ious models. In t he Pre fi lt e r and
Dat a Range plot s, r ect a ngles ar e dr awn wit h t his mouse but t on down, t o
define t he select ed r ange.
Zoom not act i ve : The special GUI funct ions just ment ioned ar e obt a ined by
any mouse but t on.
The zoom is a ct ivat ed and deact ivat ed under t he menu it em Styl e. The default
set t ing differ s bet ween t he plot s. Don’t act ivat e t he zoom fr om t he command
line! That will dest r oy t he special GUI funct ions. (If you happen t o do so
anyway, “quit ” t he window and open it again.)
Troubleshooting in Plots
The funct ion Aut o-range , which is found under t he menu it em Opti ons , set s
aut omat ic scales t o t he plot s. It is also a good funct ion t o invoke when you t hink
t hat you have lost cont r ol over t he cur ves in t he plot . (This may happen, for
example, if you ha ve zoom in a por t ion of a plot and t hen change t he dat a of t he
plot ).
If t he view plot s don’t r espond t he way you expect t hem t o, you can always
“quit ” t he window a nd open it again. By quit her e we mean using t he
under lying window syst em’s own quit t ing mechanism, which is called differ ent
t hings in t he differ ent plat for ms. This act ion will not be acknowledged by t he
cor r esponding check box in t he i de nt window, so you will have t o fir st uncheck,
and t hen check it . The nor mal way t o close a window is t o use t he Cl ose
funct ion under t he menu it em Fi l e, or t o uncheck t he cor r esponding check box.
Layout Questions and idprefs. mat
The GUI comes wit h a number of pr eset default s. These include t he window
sizes and posit ions, t he color s of t he differ ent models, a nd t he default opt ions
in t he differ ent Vi e w windows.
The window sizes and posit ions, as well as t he opt ions in t he plot windows, can
of cour se be changed dur ing t he session in t he st andar d way. If you want t he
2 Th e G r a p h i c a l U se r In te rf a c e
2-36
GUI t o st ar t wit h your cur r ent window layout and cur r ent plot opt ions, select
menu it em
Options > Save preferences
in t he main i de nt window. This saves t he infor mat ion in a file idprefs.mat.
This file also st or es infor mat ion a bout t he four most r ecent sessions wit h
i de nt. This allows t he session Fi le menu t o be cor r ect ly init ialized. The session
infor mat ion is aut omat ically st or ed upon exit . The layout a nd pr efer ence
infor mat ion is only saved when t he indica t ed opt ion is select ed.
The file idprefs.mat is cr eat ed t he fir st t ime you open t he GUI. It is by default
st or ed in t he same dir ect or y as your startup.m file. If t his defa ult does not
wor k, a wa r ning is issued. This can be ignor ed, but t hen session and pr efer ence
infor mat ion cannot be st or ed.
To change or select a dir ect or y for idprefs.mat, use t he command midprefs.
See Chapt er 4, "Command Refer ence," for det a ils.
To change model color s a nd default opt ions t o your own cust omized choice,
make a copy of t he M-file idlayout.m t o your own dir ect or y (which should be
before t he basic ident dir ect or y in t he MATLABPATH), and edit it a ccor ding t o it s
inst r uct ions.
Customized Plots
If you need t o pr epar e har dcopies of your plot s wit h specia lized t ext s, t it les and
so on, make a copy of t he figur e fir st , using Copy Fi gure under t he Fi le menu
it em. This pr oduces a copy of t he cur r ent figur e in a st andar d MATLAB figur e
for mat .
For plot s t hat ar e not cover ed by t he Vi e w windows, (like, e.g., Nyquist plot s),
you have t o expor t t he model t o t he MATLAB wor kspace and const r uct t he plot s
t her e.
Import from and Ex port to Workspace
As you expor t a model or a dat a set t o t he MATLAB wor kspace by dr opping it s
icon over t he To Wor kspace icon, it will become a wor kspace va r iable wit h t he
sa me na me as in i de nt , say mymodel. At t he same t ime anot her wor kspace
va r iable will be cr eat ed wit h t he name mymodel_info. This cont ains all diar y
and not e infor mat ion. This will be quit e useful if you want t o manipulat e t he
2-37
model using MATLAB commands and t hen impor t it back int o ident . The use is
illust r at ed by t he following example:
Expor t model wit h name mymodel t o wor kspace. Execut e t he following at t he
MATLAB command line:
mymodelc=thd2thc(mymodel);
% converting the model to continuous time
mymodelc_info=str2mat(mymodel_info,...
'mymodelc=thd2thc(mymodel)');
% adding the info of how the new variable was created
Now select pop-up menu Mode l>Import , ent er t he var ia ble name mymodelc,
and select Import.
This will ent er t he cont inuous-t ime model int o i dent along wit h t he r elevant
infor mat ion.
What Cannot be Done Using the GUI
The GUI cover s pr imar ily ever yt hing you would like t o do t o examine dat a ,
est imat e models and evaluat e a nd compar e models. It does not cover
• Gener a t ion (simulat ion) of dat a set s
• Model cr eat ion (ot her t han by est imat ion)
• Model manipulat ion and conver sions
• Recur sive (on-line) est ima t ion algor it hms
Check Cha pt er 3, "Tut or ial," as well as t he headings Si mul at i on and
Pre di ct i on, Mode l St ruct ure Cre ati on, Mani pul at i ng Model
Structures , Mode l Conve rs i ons , and Re curs i ve Parame t er Est i mat i on
in t he beginning of Chapt er 4, "Command Refer ence," t o see what M-files ar e
ava ilable in t he t oolbox for t hese funct ions.
Not e t hat at any point you can expor t a dat a set or a model t o t he MATLAB
wor kspa ce (by dr agging and dr opping it s icon on t he To Workspace icon).
Ther e you can modify a nd manipulat e it any wa y you want and t hen impor t it
back int o i dent . You can, for example, const r uct a cont inuous-t ime model fr om
an est imat ed discr et e-t ime one (using thd2thc) and t hen use t he model views
t o compar e t he t wo.
2 Th e G r a p h i c a l U se r In te rf a c e
2-38

3
Tut or ial
The Toolbox Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
An Int roduc tory Exampl e to Command Mode . . . . . . . . . . . 3-5
The Sys te m Ide nt i fi cat i on Probl e m . . . . . . . . . . . . . . . . . . . . 3-8
Nonparame t ri c Mode l Es t i mat i on . . . . . . . . . . . . . . . . . . . . . 3-19
Parame t ri c Mode l Es t i mat i on . . . . . . . . . . . . . . . . . . . . . . . . 3-22
De fi ni ng Mode l Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Exami ni ng Mode l s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40
Mode l Struc ture Se l e cti on and Vali dat i on . . . . . . . . . . . . . 3-49
De al i ng wi th Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-58
Re curs i ve Parame t e r Es ti mat i on . . . . . . . . . . . . . . . . . . . . . 3-61
Some Spe ci al Topi cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-68
3 Tu to r i a l
3-2
This chapt er has t wo pur poses. It descr ibes t he commands of t he Syst em
Ident ificat ion Toolbox, t heir synt a x a nd use. If you use t he gr aphical user
int er face (GUI), you will not have t o bot her a bout t hese aspect s. The chapt er
also descr ibes t he under lying met hods and algor it hms used. The commands
t hat ar e not r eached fr om t he GUI, i.e., t he r ecur sive algor it hms and mor e
advanced model st r uct ur e definit ions, ar e also t r ea t ed her e.
3-3
1. The Toolbox Commands
It may be useful t o r ecognize sever al layers of t he Syst em Ident ifica t ion
Toolbox. Init ially concent r at e on t he fir st layer of ba sic t ools, which cont ains
t he commands fr om t he Syst em Ident ificat ion Toolbox t hat any user must
mast er . You can pr oceed t o t he next levels whenever an int er est or t he need
fr om t he applica t ions wa r r ant s it . The la yer s ar e descr ibed in t he following
par a gr a phs:
Layer 1: Basic Tools. The fir st layer cont ains t he basic t ools for cor r elat ion and
spect r al analysis, and t he est imat ion of so-called ARX models using t he
least -squar es met hod. It also cont ains t he basic t ools for examining t he
obt ained models. The commands ar e:
ar, arx, bodeplot, compare, cra, dtrend, ffplot
idsim, present, resid, spa, th2arx, th2ff, th2zp, zpplot
The cor r esponding backgr ound is given in t he following sect ions: 3,4,5,6,7 and
8 of t his cha pt er .
Layer 2: Model Structure Selection. The second layer of t he t oolbox cont a ins
some useful t echniques t o select or der s and delays, and t o est imat e mor e
gener al input -out put model st r uct ur es. The commands ar e:
armax, arxstruc, bj, etfe, idfilt, iv4, n4sid
oe, poly2th, selstruc, th2poly
Not e t hat t he commands arx and iv4 also apply t o mult i-input , mult i-out put
syst ems. The cor r esponding backgr ound is given in t he sect ions 3, 5, 6 ,8 a nd 9
of t his chapt er .
Layer 3: More Methods To Ex amine Models and Multi-Input Systems .
This t hir d layer cont ains t r ansfor mat ions bet ween cont inuous and discr et e
t ime, and funct ions for est imat ing complet ely gener al mult i-input model
st r uct ur es. The commands ar e:
pe, pem, predict, th2ss, th2tf, thc2thd, thd2thc
The cor r esponding backgr ound is given in sect ion 7 of t his chapt er .
3 Tu to r i a l
3-4
Layer 4: Recursive Identification. Recur sive (adapt ive, online) met hods of
par amet er est imat ion ar e cover ed by t he comma nds:
rarmax, rarx, rbj, roe, rpem, rplr
The cor r esponding backgr ound is given “Recur sive Pa r amet er Est imat ion” on
page 3-61.
Layer 5: State-Space Modeling. To build models in st at e-space for m (bot h
cont inuous and discr et e t ime), and t o handle mor e advanced mult i-out put
st r uct ur es, t her e ar e t he commands:
canstart, fixpar, mf2th, modstruc, ms2th, unfixpar
The cor r esponding t heor y is cover ed in sect ions 3, 5, 6, and 8 of t his cha pt er .
(See t he beginning of t he Chapt er 4, "Command Refer ence," for a complet e list
of a vailable funct ions.)
3-5
2. An Introductory Example to Command Mode
A demonst r at ion M-file called iddemo.m pr ovides sever al examples of what
might be t ypical sessions wit h t he Syst em Ident ificat ion Toolbox. To st ar t t he
demo, execut e iddemo fr om inside MATLAB.
Befor e giving a for mal t r eat ment of t he capabilit ies and possibilit ies of t he
t oolbox, t his example is designed t o get you using t he soft war e quickly. This
example is essent ially t he sa me as demo #2 in iddemo. You ma y want t o invoke
MATLAB at t his t ime, execut e iddemo1, and follow along.
Dat a have been collect ed fr om a la bor at or y sca le pr ocess. (Feedback’s Pr ocess
Tr ainer PT326; see page 440 in Ljung, 1987 a nd “Rea ding Mor e About Syst em
Ident ificat ion” on page 1-18 for r efer ences.) The pr ocess oper a t es much like a
common ha nd-held hair dr yer . Air is blown t hr ough a t ube aft er being hea t ed
at t he inlet t o t he t ube. The input t o t he pr ocess is t he power applied t o a mesh
of r esist or wir es t hat const it ut es t he heat ing device. The out put of t he pr ocess
is t he air t emper at ur e at t he out let measur ed in volt s by a t her mocouple
sensor .
One t housand input -out put dat a point s wer e collect ed fr om t he pr ocess as t he
input was changed in a r andom fa shion bet ween t wo levels. The sampling
int er val is 80 ms. The dat a wer e loaded int o MATLAB in ASCII for m a nd ar e
now st or ed as t he vect or s y2 (out put ) and u2 (input ) in t he file dryer2.mat.
Fir st load t he dat a:
load dryer2
This example select s t he fir st 300 dat a point s for building a model. For
convenience, t he input -out put vect or s ar e mer ged int o a mat r ix:
z2 = [y2(1:300) u2(1:300)];
Take a look at t he dat a,
idplot(z2)
The t oolbox makes fr equent use of default ar gument s. Default values ar e used
when t r ailing ar gument s ar e omit t ed. In t he case above, by default , all dat a
point s ar e gr aphed and t he sa mpling int er va l is one t ime unit .
3 Tu to r i a l
3-6
You can select t he va lues bet ween sample number s 200 a nd 300 for a close-up,
and at t he sa me t ime obt ain cor r ect t ime scales, wit h
idplot(z2,200:300,0.08)
Remove t he const ant levels a nd make t he dat a zer o mea n wit h
z2 = dtrend(z2);
Now, fit t o t he dat a a model of t he for m:
wher e T is t he sampling int er val (her e 0.08 seconds). This model, known as a n
ARX model, t r ies t o explain or comput e t he value of t he out put at t ime t , given
pr evious values of y and u. La t er on, especia lly in Sect ion 8, ar e discussions of
how t o decide upon suit able model or der s (st r uct ur es).
The best values of t he coefficient s and can be comput ed wit h
th = arx(z2,[2 2 3]);
The number s in t he second ar gument t ell arx t o find a model (2.1) wit h t wo
a-par a met er s, t wo b-par amet er s, and t hr ee delays. The r esult is st or ed in t he
mat r ix th in a somewha t coded for m. To specify t he act ual sampling int er va l,
ent er
th = sett(th,0.08);
Ther e ar e sever al ways t o displa y and illust r a t e t he comput ed model. Wit h
present(th)
t he coefficient values of (2.1) and t heir est imat ed st a ndar d deviat ions ar e
pr esent ed on t he scr een.
Next , you might ask how t o evaluat e how well t he model fit s t he dat a . A simple
t est is t o r un a simula t ion wher eby r eal input dat a is fed int o t he model, and
compa r e t he simulat ed out put wit h t he act ual measur ed out put . For t his, select
a por t ion of t he da t a t hat was not used t o build t he model, for exa mple, fr om
sa mple 700 t o 900:
u = dtrend(u2(700:900));
y = dtrend(y2(700:900));
y t ( ) a
1
y t T – ( ) a
2
y t 2T – ( ) + + b
1
u t 3T – ( ) b
2
u t 4T – ( ) + =
(2.1)
a
1
a
2
b
1
, , b
2
3-7
ysim = idsim(u,th);
plot([y(100:200) ysim(100:200)])
Not e t hat t he funct ion compare does t his sequence of commands mor e
efficient ly.
You see t hat t he model is quit e capable of descr ibing t he syst em, even for dat a
t hat wer e not used in calculat ing t he fit .
To comput e and gr aph t he poles and zer os of t he model, use
zpth = th2zp(th);
zpplot(zpth)
If you want t o know t he fr equency r esponse, you can comput e t he fr equency
funct ion of t he model and pr esent it a s a Bode plot by ent er ing
gth = th2ff(th);
bodeplot(gth)
Compar e t his t r ansfer funct ion wit h a t r ansfer funct ion obt ained fr om a
nonpa r amet r ic, spect r al a nalysis met hod. Such an est ima t e is obt ained dir ect ly
fr om t he dat a
gs = spa(z2);
gs = sett(gs,0.08);
The sampling int er val, 0.08, is set by t he second command in or der t o obt a in
cor r ect fr equency scales. The funct ion spa also allows you t o select window
sizes, fr equency r anges, et c. All t hese have her e been given default values.
You can compar e t he est ima t e of t he t r ansfer funct ion obt a ined by spect r al
ana lysis a nd t he one obt a ined fr om t he model (2.1) wit h
bodeplot([gs gth])
The agr eement is quit e good.
Finally, plot t he st ep r esponse of t he model. The model comes wit h an est ima t e
of it s own uncer t aint y. Ten differ ent st ep r esponses ar e comput ed and gr aphed.
They cor r espond t o “possible” models, dr awn fr om t he dist r ibut ion of t he t r ue
syst em (accor ding t o our model):
step = ones(30,1);
idsimsd(step,th)
3 Tu to r i a l
3-8
3. The System Identification Problem
This sect ion discusses differ ent basic ways t o descr ibe linear dynamic syst ems
and also t he most impor t ant met hods for est imat ing such models.
Impulse Responses, Frequency Functions, and
Spectra
The basic input -out put configur at ion is depict ed in t he figur e a bove. Assuming
unit sampling int er val, t her e is an input signal
u ( t ) ; t =1 , 2 , . . . . . . . . , N
and an out put signal
y ( t ) ; t =1 , 2 , . . . . . . . , . N
Assuming t he signals ar e r elat ed by a linear syst em, t he r ela t ionship can be
wr it t en
wher e q is t he shift oper at or and is shor t for
u
e
y
y t ( ) G q ( )u t ( ) v t ( ) + =
(3.1)
G q ( )u t ( )
G q ( )u t ( ) g k ( )u t k – ( )
k 1 =


=
(3.2)
and
G q ( ) g k ( )q
k –
;
k 1 =


=
q
1 –
u t ( ) u t 1 – ( ) =
(3.3)
3-9
The number s ar e called t he impulse response of t he syst em. Clea r ly,
is t he out put of t he syst em at t ime k if t he input is a single (im)pulse a t
t ime zer o. The funct ion is called t he transfer function of t he syst em. This
funct ion eva luat ed on t he unit cir cle gives t he frequency function
In (3.1) is an addit iona l, unmea sur able dist ur bance (noise). It s pr oper t ies
ca n be expr essed in t er ms of it s (aut o) spect r um
which is defined by
wher e is t he covar iance funct ion of :
and E denot es mat hemat ical expect at ion. Alt er nat ively, t he dist ur bance
ca n be descr ibed as filt er ed whit e noise:
wher e is whit e noise wit h var iance and
Equat ions (3.1) and (3.8) t oget her give a time domain descript ion of t he syst em:
g k ( ) { ¦
g k ( )
G q ( )
q ( e
i ω
) =
G e
i ω
( )
(3.4)
v t ( )
Φ
v
ω ( )
(3.5)
Φ
v
ω ( ) R
v
τ ( )e
iwt –
τ ∞ – =


= (3.6)
R
v
τ ( ) v t ( )
R
v
τ ( ) Ev t ( )v t τ – ( ) =
(3.7)
v t ( )
v t ( ) H q ( )e t ( ) =
(3.8)
e t ( ) λ

(3.9)
Φ
v
ω ( ) λ H e
i ω
( )
2
=
y t ( ) G q ( )u t ( ) H q ( )e t ( ) + =
(3.10)
3 Tu to r i a l
3-10
while (3.4) and (3.5) const it ut e a frequency domain descript ion:
The impulse r esponse (3.3) and t he fr equency domain descr ipt ion (3.11) ar e
called nonparametric model descriptions since t hey ar e not defined in t er ms of
a finit e number of par a met er s. The basic descr ipt ion (3.10) also applies t o t he
mult iva r iable ca se; i.e., t o syst ems wit h sever al (say nu) input signa ls and
sever al (say ny) out put signals. In t hat case is an ny by nu mat r ix while
and ar e ny by ny mat r ices.
Polynomial Representation of Transfer Functions
Rat her t ha n specifying t he funct ions G and H in (3.10) in t er ms of funct ions of
t he fr equency var iable , you can descr ibe t hem a s r at ional funct ions of
and specify t he numer at or and denominat or coefficient s in some way.
A commonly used pa r amet r ic model is t he ARX model t hat cor r esponds t o
wher e B and A ar e polynomials in t he delay oper at or :
Her e, t he number s na and nb ar e t he or der s of t he r espect ive polynomials. The
number nk is t he number of delays fr om input t o out put . The model is usually
wr it t en
G e
i ω
( );
Φ
v
ω ( ) (3.11)
G q ( )
H q ( ) Φ
v
ω ( )
ω q
1 –
G q ( ) q
nk –
=
B q ( )
A q ( )
-----------; H q ( )
1
A q ( )
----------- =
(3.12)
q
1 –
A q ( ) 1 a
1
q
1 –
…… a
na
q
na –
+ + + =
B q ( ) b
1
b
2
q
1 –
…… b
nb
q
nb – 1 +
+ + + =
(3.14)
(3.13)
A q ( )y t ( ) B q ( )u t nk – ( ) e t ( ) + = (3.15)
3-11
or explicit ly
Not e t hat (3.15) -(3.16) a pply a lso t o t he mult ivar iable ca se, wher e and
t he coefficient s become ny by ny mat r ices, and t he coefficient s
become ny by nu mat r ices.
Anot her ver y common, and mor e gener al, model st r uct ur e is t he ARMAX
st r uct ur e
Her e, and ar e as in (3.13)-(3.14), while
An Output-Error (OE) st r uct ur e is obt ained as
wit h
The so-called Box-J enkins (BJ ) model st r uct ur e is given by
wit h
y t ( ) a
1
y t 1 – ( ) …… a
na
y t na – ( ) + + + =
b
1
u t nk – ( ) b
2
u t nk – 1 – ( ) …… b
nb
u t nk – nb – 1 + ( ) e t ( ) + + + +
(3.16)
A q ( )
a
i
B q ( ) b
i
A q ( )y t ( ) B q ( )u t nk – ( ) C q ( )e t ( ) + =
(3.17)
A q ( ) B q ( )
C q ( ) 1 c
1
q
1 –
… c
nc
q
nc –
+ + + = (3.18)
y t ( )
B q ( )
F q ( )
-----------u t nk – ( ) e t ( ) + =
(3.19)
F q ( ) 1 f
1
q
1 –
… f
nf
q
nf –
+ + + =
(3.20)
y t ( )
B q ( )
F q ( )
-----------u t nk – ( )
C q ( )
D q ( )
------------e t ( ) + =
(3.21)
D q ( ) 1 d
1
q
1 –
… d
nd
q
nd –
+ + + =
(3.22)
3 Tu to r i a l
3-12
All t hese models ar e specia l cases of t he gener al par a met r ic model st r uct ur e:
The var iance of t he whit e noise is assumed t o be .
Wit hin t he st r uct ur e of (3.23), vir t ually all of t he usual linear black-box model
st r uct ur es ar e obt ained as special cases. The ARX st r uct ur e is obviously
obt ained for . The ARMAX st r uct ur e cor r esponds t o
. The ARARX st r uct ur e (or t he “gener alized least -squar es model”)
is obt ained for , while t he ARARMAX st r uct ur e (or “ext ended
mat r ix model”) cor r esponds t o . The Out put -Er r or model is obt ained
wit h , while t he Box-J enkins model cor r esponds t o .
(See Sect ion 4.2 in Ljung (1987) for a det ailed discussion.)
The same t ype of models can be defined for syst ems wit h an ar bit r a r y number
of input s. They ha ve t he for m
A q ( )y t ( )
B q ( )
F q ( )
-----------u t nk – ( )
C q ( )
D q ( )
------------e t ( ) + =
(3.23)
e t ( ) { ¦ λ
nc nd nf 0 = = =
nf nd 0 = =
nc nf 0 = =
nf 0 =
na nc nd 0 = = = na 0 =
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) ...+
B
nu
q ( )
F
nu
q ( )
-----------------
·
u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + =
3-13
State-Space Representation of Transfer Functions
A common way of descr ibing linear syst ems is t o use t he st ate-space form:
Her e t he r elat ionship bet ween t he input a nd t he out put is defined via
t he nx-dimensional st at e vect or . In t r ansfer funct ion for m (3.24)
cor r esponds t o (3.1) wit h
Her e is t he nx by nx ident it y ma t r ix. Clear ly (3.24) ca n be viewed as one
way of par a met r izing t he t r ansfer funct ion: Via (3.25) becomes a funct ion
of t he element s of t he mat r ices A, B, C, and D.
To fur t her descr ibe t he char a ct er of t he noise t er m in (3.24) a mor e flexible
innovat ions for m of t he st a t e-space model ca n be used:
This is equivalent t o (3.10) wit h given by (3.25) and by
Her e ny is t he dimension of and .
It is oft en possible t o set up a syst em descr ipt ion dir ect ly in t he innovat ions
for m (3.26). In ot her cases, it might be pr efer able t o descr ibe fir st t he nat ur e of
dist ur ba nces t hat act on t he syst em. Tha t lea ds t o a st ochast ic st at e-spa ce
model:
x t 1 + ( ) Ax t ( ) Bu t ( ) + =
y t ( ) Cx t ( ) Du t ( ) v t ( ) + + =
(3.24a)
(3.24b)
u t ( ) y t ( )
x t ( )
G q ( ) C qI
nx
A – ( )
1 –
B D + =
(3.25)
I
nx
G q ( )
v t ( )
x t 1 + ( ) Ax t ( ) Bu t ( ) Ke t ( ) + + =
y t ( ) Cx t ( ) Du t ( ) e t ( ) + + = (3.26b)
(3.26a)
G q ( ) H q ( )
H q ( ) C qI
nx
A – ( )
1 –
K I
ny
+ = (3.27)
y t ( ) e t ( )
x t 1 + ( ) Ax t ( ) Bu t ( ) w t ( ) + + =
y t ( ) Cx t ( ) Du t ( ) e t ( ) + + =
(3.28a)
(3.28b)
3 Tu to r i a l
3-14
wher e and ar e st ochast ic pr ocesses wit h cer t ain covar ia nce
pr oper t ies. In st at ionar it y and fr om an input -out put view, (3.28) is equivalent
t o (3.26) if t he mat r ix K is chosen as t he st eady-st at e Kalman gain. How t o
comput e K fr om (3.28) is descr ibed in t he Cont r ol Syst em Toolbox.
Continuous-Time State-Space Models
It is oft en ea sier t o descr ibe a syst em fr om physical modeling in t er ms of a
cont inuous-t ime model. The r eason is t hat most physica l laws ar e expr essed in
cont inuous t ime as differ ent ial equat ions. Ther efor e, physical modeling
t ypically lea ds t o st a t e-space descr ipt ions like
Her e, means t he t ime der ivat ive of . If t he input is piece-wise const ant over
t ime int er vals , t hen t he r elat ionship bet ween
and can be exa ct ly expr essed by (3.24) by t a king
and associa t e y(t) wit h y[t ], et c.
If you st ar t wit h a cont inuous-t ime innova t ions for m
t he discr et e-t ime count er par t is given by (3.26) wher e st ill t he r elat ionships
(3.30) hold. The exact connect ion bet ween and K is somewhat mor e
complicat ed, t hough. An ad hoc solut ion is t o use
in analogy wit h G and B. This is a good appr oxima t ion for shor t sampling
int er vals T.
w t ( ) e t ( )
(3.29a)
(3.29b)
x
·
t ( ) Fx t ( ) Gu t ( ) + =
y t ( ) Hx t ( ) Du t ( ) v t ( ) + + =
x
·
x
kT t k 1 + ( )T < ≤ u k [ ] u kT ( ) =
y k [ ] y kT ( ) =
A e
FT
= B e

τ 0 =
T

= ; Gdτ C H = ;
(3.30)
x
·
t ( ) Fx = t ( ) Gu + t ( ) K
˜
+ e t ( )
y t ( ) Hx = t ( ) Du + t ( ) e + t ( )
(3.31a )
(3.31b)
K
˜
K e

τ 0 =
T

= K
˜
dτ;
(3.32)
3-15
Estimating Impulse Responses
Consider t he descr ipt ion (3.1). Suppose t hat t he input is whit e noise; i.e.,
it s covar ia nce funct ion is
Then, t he cr oss covar iance funct ion bet ween t he input and t he out put is
wher e g(τ) is t he impulse r esponse of t he syst em. In t his case, it ca n ea sily be
est imat ed as
based on t he obser ved input -out put da t a.
If t he input is not whit e, a whit ening filt er L(q) ca n be det er mined for it , so
t hat t he filt er ed sequence
is appr oximat ely whit e. By filt er ing t he out put sequence t hr ough t he same
filt er and comput ing (3.33) based on t he filt er ed dat a, a nat ur a l est imat e of t he
impulse r esponse coefficient s g(k) is obt ained. This pr ocedur e is known a s
correlat ion analysis.
u t ( )
R
u
τ ( ) Eu = t τ + ( )u t ( )
λ if τ 0 =
0 else ¹
'
¹
=
R
yu
τ ( ) Ey t τ + ( )u t ( ) λg τ ( ) = =
gˆ τ ( )
1
λN
------- = y
t 1 =
N

t τ + ( )u t ( )
(3.33)
u
F
t ( ) L = q ( )u t ( ) (3.34)
3 Tu to r i a l
3-16
Estimating Spectra and Frequency Functions
This sect ion descr ibes met hods t hat est imat e t he fr equency funct ions and
spect r a (3.11) dir ect ly. The cr oss-covar ia nce funct ion bet ween y(t) and
u(t) was defined a bove. It s Four ier t r ansfor m, t he cr oss spect r um, is
defined analogously t o (3.6). Pr ovided t hat t he input is independent of ,
t he r elat ionship (3.1) implies t he following r elat ionships bet ween t he spect r a:
By est imat ing t he var ious spect r a involved, t he fr equency funct ion and t he
dist ur bance spect r um can be est imat ed as follows:
For m est ima t es of t he covar iance funct ions (as defined in (3.7)) , ,
and , using
and analog expr essions for t he ot her s. Then, for m est imat es of t he
cor r esponding spect r a
and analogously for and . Her e is t he so-ca lled lag window and
M is t he widt h of t he lag window. The est imat es ar e t hen for med as
This pr ocedur e is known as spectral analysis. (See Chapt er 6 in Ljung (1987).)
R
yu
τ ( )
Φ
yu
ω ( )
u t ( ) v t ( )
Φ
y
ω ( ) G e
i ω
( )
2
Φ
u
ω ( ) Φ
v
ω ( ) + =
Φ
yu
ω ( ) G e
i ω
( )Φ
u
ω ( ) =
R
ˆ
y τ ( ) R
ˆ
yu τ ( )
R
ˆ
u
τ ( )
R
ˆ
yu τ ( )
1
N
--- - y t τ + ( )u t ( )
t 1 =
N

=
(3.35)
Φ
ˆ
y ω ( ) R
ˆ
y
τ M – =
M

= τ ( )W
M
τ ( )e
i ωτ –
(3.36)
Φu Φyu
W
M
τ ( )
G
ˆ
N e
i ω
( )
Φ
ˆ
yu ω ( )
Φ
ˆ
u ω ( )
------------------ -; = Φ
ˆ
v ω ( ) Φ
ˆ
y ω ( )
Φ
ˆ
yu ω ( )
2
Φ
ˆ
u ω ( )
------------------------ – =
(3.37)
3-17
Estimating Parametric Models
Given a descr ipt ion (3.10) and having obser ved t he input -out put dat a u, y, t he
(pr edict ion) er r or s in (3.10) can be comput ed as:
These er r or s ar e, for given dat a y and u, funct ions of G and H. These in t ur n
ar e par a met r ized by t he polynomia ls in (3.15)-(3.23) or by ent r ies in t he
st a t e-space mat r ices defined in (3.29)–(3.32). The most common par amet r ic
ident ificat ion met hod is t o det er mine est imat es of G and H by minimizing
t hat is
This is called a predict ion error method. For Gaussian dist ur bances it coincides
wit h t he maximum likelihood met hod. (See Chapt er 7 in Ljung (1987).)
A somewhat differ ent philosophy can be a pplied t o t he ARX model (3.15). By
for ming filt er ed ver sions of t he input
and by mult iplying (3.15) wit h , , 2, , na and ,
, 2, , nb and summing over t , t he noise in (3.15) can be cor r elat ed out
and solved for t he dynamics. This gives t he instrument al variable met hod, and
ar e ca lled t he inst r ument s. (See Sect ion 7.6 in Ljung (1987).)
e t ( )
e t ( ) H
1 –
q ( ) y t ( ) G q ( )u t ( ) – [ ] = (3.38)
V
N
G H , ( ) e
2
t ( )
t 1 =
N

=
(3.39)
G
ˆ
N H
ˆ
N , [ ] argmin e
2
t ( )
t 1 =
N

=
(3.40)
N q ( )s t ( ) M q ( )u t ( ) =
(3.41)
s t k – ( ) k 1 = … u t nk – 1 k – + ( )
k 1 = …
s t ( )
3 Tu to r i a l
3-18
Subspace Methods for Estimating State-Space
Models
The st at e-space ma t r ices A, B, C, D, a nd K in (3.26) can be est imat ed dir ect ly,
wit hout fir st specifying any par t icular par a met r izat ion by efficient subspace
methods. The idea behind t his ca n be expla ined a s follows: If t he sequence of
st at e vect or s x(t ) wer e known, t oget her wit h y(t ) and u(t), eq (3.26b) would be a
linear r egr ession, and C and D could be est imat ed by t he least squar es met hod.
Then e(t ) could be det er mined, and t r eat ed a s a known signa l in (3.26a ), which
t hen would be a not her linear r egr ession model for A, B and K. (One could also
t r eat (3.24) as a linear r egr ession for A, B, C, and D wit h y(t ) and x(t +1) a s
simult aneous out put s, and find t he joint pr ocess and mea sur ement noises as
t he r esiduals fr om t his r egr ession. The Kalman gain K could t hen be comput ed
fr om t he Riccat i equat ion.) Thus, once t he st at es ar e known, t he est imat ion of
t he st at e-space mat r ices is easy.
How t o find t he st at es x(t)? Appendix 4.A of Ljung(1987) shows t hat all st at es
in r epr esent at ions like (3.26) can be for med as linear combina t ions of t he
k-st ep ahead pr edict ed out put s (k=1,2,...,n). It is t hus a mat t er of finding t hese
pr edict or s, and t hen select ing a ba sis among t hem. The subspa ce met hods for m
an efficient and numer ically r elia ble way of det er mining t he pr edict or s by
pr oject ions dir ect ly on t he obser ved dat a sequences. For mor e det ails, see t he
r efer ences under n4sid in Chapt er 4, "Command Refer ence" .
3-19
4. Nonparametric Model Estimation
This and t he following sect ions give an int r oduct ion t o t he basic funct ions in
t he Syst em Ident ificat ion Toolbox. Not all of t he opt ions ava ilable when using
t he funct ions a r e descr ibed her e; see t he Command Reference cha pt er and t he
online Help facilit y.
Data Representation
The obser ved out put and input signals, and , ar e r epr esent ed in t he
Syst em Ident ificat ion Toolbox as column vectors y and u. Row k cor r esponds t o
sample number k. For mult ivar iable syst ems, each input (out put ) component
is r epr esent ed a s a column vect or , so t hat u becomes an N by nu mat r ix (N =
number of sa mpled obser vat ions, nu = number of input signa ls). The
out put -input dat a is collect ively r epr esent ed as a ma t r ix whose fir st column(s)
is t he out put a nd next column(s) is t he input :
z = [y u]
The da t a can be gr aphed by t he command idplot:
idplot(z)
This gives plot s of all combinat ions of input s and out put s for visual inspect ion.
Some of t he funct ions in t he Syst em Ident ificat ion Toolbox apply only t o single
out put da t a ( ) and some only t o single-input -single-out put dat a
( , ). Chapt er 4, "Command Refer ence" gives det a ils about t his.
y t ( ) u t ( )
ny 1 =
ny 1 = nu 1 =
3 Tu to r i a l
3-20
Correlation Analysis
The cor r elat ion analysis pr ocedur e descr ibed in “The Syst em Ident ificat ion
Pr oblem” in Chapt er 3 is implement ed in t he funct ion cra:
ir = cra(z)
This funct ion r et ur ns t he est imat ed impulse r esponse in t he vect or ir. It also
opt iona lly plot s t he est imat ed covar iance funct ions for y and u, so t hat t he
success of t he whit ening filt er (3.34) can be checked. Fr om t he est imat ed
impulse r esponse it is easy t o for m t he st ep r esponse:
ir = cra(z)
sr = cumsum(ir)
plot(sr)
Spectral Analysis
The funct ion spa per for ms spect r al analysis accor ding t o t he pr ocedur e in
(3.35)–(3.37).
[G,PHIV] = spa(z)
Her e z cont ains t he out put -input dat a as above. G a nd PHIV ar e mat r ices t hat
cont ain t he est imat ed fr equency funct ion a nd t he est imat ed dist ur bance
spect r um in (3.37). They ar e coded int o a special for mat , t he freqfunc
format , which allows you t o plot t hem using t he funct ion bodeplot or ffplot:
[G,PHIV] = spa(z)
bodeplot(G)
bodeplot(PHIV)
bodeplot gives logar it hmic amplit ude and fr equency scales (in r ad/sec) and
linear phase scale, while ffplot gives linea r fr equency scales (in Hz). The
det ails of t he freqfunc for mat ar e given in Chapt er 4, "Command Refer ence"
and by t yping help freqfunc. To obt ain cor r ect fr equency scales you ca n
oper at e wit h t he command sett on G or give t he sampling int er va l as a n
opt iona l ar gument t o spa.
By omit t ing t he ar gument PHIV, only t he t r ansfer funct ion est ima t e G is
comput ed:
G = spa(z)
GN
Φv
3-21
When PHIV is included, t he est imat ed st andar d deviat ions of G and PHIV a r e
also r et ur ned by spa and included in t he fr eqfunc for mat .
If z = y is a t ime ser ies, spa r et ur ns an est imat e of t he spect r um of t hat signal:
PHIY = spa(y)
ffplot(PHIY)
In t he comput at ions (3.35)-(3.37), spa uses a Hamming window for wit h
a default lengt h M equal t o t he minimum of 30 a nd a t ent h of t he number of
dat a point s. This window size M can be changed t o a n ar bit r ar y number by
[G,PHIV] = spa(z,M)
The r ule is t hat as M incr eases, t he est imat ed fr equency funct ions show sha r per
det ails, but ar e also mor e affect ed by r andom dist ur bances. A t ypica l sequence
of commands t hat t est differ ent window sizes is
g10 = spa(z,10)
g25 = spa(z,25)
g50 = spa(z,50)
bodeplot([g10 g25 g50])
An empir ical t r a nsfer funct ion est imat e is obt ained as t he r a t io of t he out put
and input Four ier t r ansfor ms wit h
G = etfe(z)
This can also be int er pr et ed as t he spect r al analysis est imat e for a window size
t hat is equal t o t he dat a lengt h. For a single signal etfe gives t he periodogram
as a spect r al est imat e. The funct ion a lso a llows some smoot hing of t he cr ude
est imat e; it can be a good alt er nat ive for signa ls and syst ems wit h shar p
r esonances. See Chapt er 4, "Command Refer ence" for mor e infor ma t ion.
W τ ( )
3 Tu to r i a l
3-22
5. Parametric Model Estimation
The Syst em Ident ificat ion Toolbox cont a ins sever al funct ions for par amet r ic
model est imat ion. They all sha r e t he same command st r uct ur e
th = f unc t i on([y u],ths)
Input var iables y and u ar e column vect or s t hat cont ain t he out put and input
dat a sequences, while t he ma t r ix ths specifies t he par t icular st r uct ur e of t he
model t o be est imat ed. The r esult ing est imat ed model is cont ained in th. It is
coded int o t he thet a format. This is t he basic for mat for r epr esent ing models in
t he Syst em Ident ificat ion Toolbox. It collect s infor ma t ion about t he model
st r uct ur e and t he or der s, delays, pa r amet er s, and est ima t ed covar iances of
est imat ed par amet er s int o a mat r ix. The det ails of t his r epr esent at ion ar e
found in Chapt er 4, "Command Refer ence" or by t yping help theta. The theta
for mat can be t r anslat ed t o ot her useful model r epr esent a t ions. To just display
t he model infor mat ion, use t he command present:
th = function(z,ths)
present(th)
The following sect ions assume t hat you have for med an ar r a y z t hat consist s of
t he out put y and t he input u:
z = [y u]
ARX Models
To est imat e t he par amet er s and of t he ARX model (3.15), use t he funct ion
arx:
th = arx(z,[na nb nk])
Her e na, nb, and nk ar e t he cor r esponding or der s and delays in (3.16) t hat
define t he exact model st r uct ur e. The funct ion arx implement s t he
least -squa r es est imat ion met hod, using t he MATLAB “/” oper at or for
over det er mined linear equat ions.
An alt er na t ive is t o use t he Inst r ument al Var ia ble (IV) met hod descr ibed in
connect ion wit h (3.41). This is obt ained wit h
th = iv4(z,[na nb nk])
a
i
b
i
3-23
which gives an aut omat ic (and appr oximat ely opt imal) choice of t he filt er s N
and M in (3.41). (See t he pr ocedur e (15.21)-(15.26) in Ljung (1987).)
Bot h arx and iv4 ar e applicable t o ar bit r ar y mult ivar iable syst ems. If you have
ny out put s and nu input s, t he or der s ar e defined accor dingly: na is an
ny by ny mat r ix whose i -j ent r y gives t he or der of t he polynomial t hat r elat es
past va lues of t o t he cur r ent va lue of (i.e., past values of up t o
ar e used when pr edict ing . Similar ly t he i -j ent r ies of t he
ny by nu mat r ices nu and nk, r espect ively, give t he or der and delay fr om input
number j when pr edict ing out put number i. (See “Defining Model St r uct ur es”
on page 3-29 a nd Chapt er 4, "Command Refer ence" for exact det a ils.)
AR Models
For a single signal t he count er par t of t he ARX model is t he AR model:
The arx command also cover s t his special case
th = arx(y,na)
but for scalar signa ls mor e opt ions ar e offer ed by t he command
th = ar(y,na)
which has an opt ion t hat a llows you t o choose t he algor it hm fr om a gr oup of
sever al popular t echniques for comput ing t he least -squar es AR model. Among
t hese ar e Bur g’s met hod, a geomet r ic lat t ice met hod, t he Yule-Walker
appr oach, a nd a modified covar iance met hod. (See Chapt er 4, "Command
Refer ence" for det ails.) The count er par t of t he iv4 command is
th = ivar(y,na)
which uses an inst r ument a l var ia ble t echnique t o comput e t he AR par t of a
t ime ser ies.
General Polynomial Black-Box Models
Based on t he pr edict ion er r or met hod (3.40), you can const r uct models of
basically a ny st r uct ur e. For t he gener al model (3.23), t her e is t he funct ion
th = pem(z,nn)
y
j
y
i
y
j
y
j
t na i j , ( ) – ( ) y
i
t ) ( )
y t ( )
A q ( )y t ( ) e t ( ) =
(5.1)
3 Tu to r i a l
3-24
wher e nn gives all t he or der s and delays
nn = [na nb nc nd nf nk]
The pem command cover s all cases of bla ck-box linear syst em models. Mor e
efficient r out ines ar e available, however , for t he common special cases
th = armax(z,[na nb nc nk])
th = oe(z,[nb nf nk])
th = bj(z,[nb nc nd nf nk])
These handle t he model st r uct ur es (3.17), (3.19) and (3.21), r espect ively.
All t he r out ines also cover single-out put , mult i-input syst ems of t he t ype
wher e nb, nf, and nk ar e r ow vect or s of t he same lengt hs as t he number of input
channels cont aining each of t he or der s and delays
nb = [nb1 ... nbnu];
nf = [nf1 ... nfnu];
nk = [nk1 ... nknu];
These par a met er est imat ion r out ines r equir e a n it er at ive sear ch for t he
minimum of t he funct ion (3.39). This sear ch uses a special st ar t -up pr ocedur e
based on least squar es and inst r ument al var iables (t he det ails ar e given as
equat ion (10.75) in Ljung (1987)). Fr om t he init ial est imat e, a Gauss-Newt on
minimizat ion pr ocedur e is car r ied out unt il t he nor m of t he Gauss-Newt on
dir ect ion is less t han a cer t ain t oler a nce. See Ljung (1987), Sect ion 11.2 or
Dennis and Schnabel(1983) for det a ils. See also t he ent r y on opt ional var ia bles
associat ed wit h t he sear ch at t he end of t his sect ion.
The r out ines pem, armax, oe, and bj can also be st ar t ed at any init ial value thi
specified in t he t het a for mat by r eplacing nn by thi. For example
th = pem(z,thi)
While t he sear ch is t ypica lly init ialized using t he built -in st ar t -up pr ocedur e
giving just or der s and delays (as descr ibed above), t he a bilit y t o for ce a specific
init ial condit ion is useful in sever al cont ext s. Some examples ar e ment ioned in
“Some Specia l Topics” on page 3-68.
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
-----------------u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
(5.2)
3-25
If a last ar gument ’trace’ is a dded, as in
th = armax(z,nn,’trace’)
t hese r out ines give st at us r epor t s t o t he scr een dur ing t he minimizat ion,
cont aining cur r ent and pr evious est ima t es, t he associat ed loss funct ions, and
t he Gauss-Newt on updat e vect or and it s nor m. The est imat es ar e t hen
r epr esent ed by a column vect or , list ing t he par a met er s in alphabet ica l or der .
The number t hen flicker ing in t he upper left cor ner shows how many t imes t he
suggest ed upda t e dir ect ion has been bisect ed dur ing t he sear ch. It is a healt hy
sign if t his number is small.
These r out ines r et ur n t he est imat ed covar iance ma t r ix of t he est imat ed
par a met er vect or as par t of th. This r eflect s t he r eliabilit y of t he est imat es. The
covar iance mat r ix est imat e is comput ed under t he assumpt ion t hat it is
possible t o obt ain a “t r ue” descr ipt ion in t he given st r uct ur e.
State-Space Models
Black-box , discrete-time, parametrizations. Suppose fir st t hat t her e is no
par t icular knowledge about t he int er nal st r uct ur e of t he discr et e-t ime
st a t e-space model (3.16). Any linear model of a given or der is sought . Then
t her e ar e essent ially t wo differ ent ways t o est imat e st at e-space models, like
(3.26). The simplest one is t o use n4sid:
th = n4sid(z,order);
which cr eat es a model in st at e-space for m (coded as usua l in t he t het a for mat )
in a r ealizat ion t hat is aut omat ically chosen t o be r easonably well condit ioned.
The basic idea behind t his subspace algor it hm was descr ibed in “The Syst em
Ident ificat ion Pr oblem” on page 3-8.
The ot her alt er nat ive is t o use a pr edict ion er r or met hod, minimizing t he
cr it er ion (5.3) below. Init ializing t he sear ch at t he n4sid model is t hen a good
idea. This is obt a ined by
thi = canstart(z,order,nu)
th = pem(z,thi)
3 Tu to r i a l
3-26
Arbitrarily parameterized models in discrete and continuous time. For
st at e-space models of given st r uct ur e, most of t he effor t involved r elat es t o
defining and manipulat ing t he st r uct ur e. This is discussed in “Defining Model
St r uct ur es” on pa ge 3-29. Once t he st r uct ur e is defined in t he t het a for mat as
ths, you can est imat e it s par amet er s wit h
th = pem(z,ths)
When t he syst ems ar e mult i-out put , t he following cr it er ion is used for t he
minimizat ion:
which is t he maximum likelihood cr it er ion for Gaussian noise wit h unknown
covar iance mat r ix.
The numer ical minimizat ion of t he pr edict ion er r or cr it er ion (3.39) or (5.3) can
be a difficult pr oblem for gener al model par a met r izat ions. The cr it er ion, as a
funct ion of t he fr ee par amet er s, ca n define a complicat ed sur face wit h ma ny
local minima, na r r ow valleys and so on. This may r equir e subst ant ial
int er act ion fr om t he user , in pr oviding r easonable init ial par amet er values,
and also by fr eezing cer t ain par amet er values while allowing ot her s t o be fr ee.
Not e t hat pem easily allows t he fr eezing of any pa r amet er s t o t heir nominal
va lues. The funct ions fixpar and unfixpar ar e also useful. A pr ocedur e t hat is
oft en used for st at e-spa ce models is t o allow t he noise par a met er in t he K
mat r ix fr ee, only when a r easonable model of t he dynamic pa r t has been
obt ained. See a lso “Some Special Topics” on pa ge 3-68.
Optional Variables
The funct ions pem, armax, oe, and bj can accept t hr ee addit ional input opt ions
t hat affect t he minimizat ion, as well as one ext r a out put a r gument . For
example,
[th, iter_info] = bj(z,nn,maxiter,tol,lim)
The for mat is t he same for t he ot her funct ions. If t hese var iables ar e not given,
default values ar e assigned t o t hem.
det e t ( )e
T
t ( )
t 1 =
N

min (5.3)
3-27
maxiter: This var iable det er mines t he maximum number of it er at ions
per for med in t he sear ch for t he minimum. The default value is 10. Set t ing t he
value of maxiter t o zer o r esult s in t he r et ur n of t he est imat e fr om t he st ar t -up
pr ocedur e.
tol: The it er at ions ar e cont inued unt il t he nor m of t he Gauss-Newt on updat e
vect or is less t han tol. The default value is 0.01. The it er at ions also t er minat e
when maxit er is r eached or when no decr ease in t he cr it er ion ca n be found a long
t he sear ch dir ect ion aft er it has been bisect ed 10 t imes. (Aft er t he 10 fir st
bisect ions, t he sear ch dir ect ion is changed t o t he gr adient one, and 10 new
bisect ions ar e t r ied.)
The par amet er s associat ed wit h t he noise dynamics, (C and D), ar e oft en mor e
difficult t o est imat e t han t he dynamics par amet er s, A, B, and F. Major
cont r ibut ions t o t he nor m of t he updat e dir ect ion t hen come fr om t he ent r ies
cor r esponding t o t he noise pa r amet er s. The Gauss-Newt on vect or can be
monit or ed t o see if it is r easonable t o incr ea se tol on t his gr ound.
lim: The quadr at ic cr it er ion (3.39) gives a consider able r elat ive weight t o la r ge
pr edict ion er r or s. You may want t o limit t heir influence, using robust
est imat ion techniques. In t he est imat ion funct ions ar, bj, max, oe, and pem, a
pr edict ion er r or t hat is lar ger t han lim
*
(est imat ed st a ndar d deviat ion of e)
ca r r ies a linear , r at her t han a quadr at ic, weight .
The default value of lim is 1.6. lim=0 disables t he r obust est ima t ion a nd
applies a pur ely quadr a t ic cr it er ion. The st andar d deviat ion is est imat ed
r obust ly as t he median of t he a bsolut e devia t ions fr om t he median, divided by
0.7. (See eq (15.9)-(15.10) in Ljung (1987).)
Not e t hat t he loss funct ion displayed by present(th) is quadr at ic and t hat t he
dat a-dependent delimit er is comput ed only once, befor e t he minimizat ion
st a r t s.
iter_info: This a a r ow vect or wit h t hr ee ent r ies t hat give infor mat ion about
t he it er at ion pr ocess. The fir st ent r y is t he number of used it er at ions. The
second one is t he impr ovement of t he fit over t he last it er at ion, and t he t hir d
var iable is t he nor m of t he Gauss-Newt on sear ch vect or . If t he number of used
it er at ions is less t han maxiter, at t he same t ime as t his nor m is lar ger t hen
tol, it means t hat t he it er a t ions have been a bor t ed because no bet t er fit could
be obt ained along t he indicat ed sear ch dir ect ion.
3 Tu to r i a l
3-28
For t he spect r al analysis est imat e, you can comput e t he fr equency funct ions a t
ar bit r ar y fr equencies. If t he fr equencies ar e specified in a r ow vect or w, t hen
[G,PHIV] = spa(z,M,w)
r esult s in G and PHIV being comput ed at t hese fr equencies. This comput at ion is
somewhat slower , however , t han using t he default fr equencies.
You can gener at e logar it hmically spaced fr equencies using t he MATLAB
logspace funct ion. For example
w = logspace(–3,pi,128)
The opt ional t r a iling ar gument s can be omit t ed, in which case default values
ar e used. Ent er ing t hem a s empt y mat r ices, [ ], a lso causes funct ions t o r ely
upon default s.
3-29
6. Defining Model Structures
Since t he Syst em Ident ificat ion Toolbox handles a wide va r iet y of differ ent
model st r uct ur es, it is impor t ant t ha t t hese can be defined in a flexible way. In
t he pr evious sect ion you saw how model st r uct ur es t ha t ar e specia l ca ses of t he
gener al model (3.23) can be defined by specifying t he or der s and delays in t he
var ious est imat ion r out ines arx, iv4, oe, bj, armax, and pem. This sect ion
descr ibes how model st r uct ur es and models can be dir ect ly defined. For
black-box models (3.23) t his may be r equir ed, for example, when cr eat ing a
model for simula t ion. Commands for cr ea t ing st at e-space model st r uct ur es ar e
discussed in t his sect ion.
The gener a l way of r epr esent ing models a nd model st r uct ur es in t he Syst em
Ident ificat ion Toolbox is t he thet a format . This sect ion int r oduces t he
commands (a par t fr om t he par amet r ic est imat ion funct ions t hemselves) t hat
cr eat e models in t he t het a for mat .
Polynomial Black-Box Models
The gener a l input -out put for m (3.23):
is defined by t he five polynomials A(q), B(q), C(q), D(q), and F(q). These ar e
r epr esent ed in t he st andar d MATLAB for mat for polynomials. Polynomia l
coefficient s ar e st or ed as r ow vect or s or der ed by descending power s. For
example, t he polynomial
is r epr esent ed a s
A = [1 a1 a2 ... an]
Delays in t he syst em ar e indicat ed by leading zer os in t he polynomial. For
example, t he ARX model
A q ( )y t ( )
B q ( )
F q ( )
-----------u t nk – ( )
C q ( )
D q ( )
------------e t ( ) + =
(6.1)
A q ( ) 1 a1q
1 –
a2q
2 –
… anq
n –
+ + + + =
B q ( )
y t ( ) 1.5y t 1 – ( ) – 0.7y t 2 – ( ) + 2.5u t 2 – ( ) 0.9u t 3 – ( ) + = (6.2)
3 Tu to r i a l
3-30
is r epr esent ed by t he polynomia ls
A = [1 –1.5 0.7]
B = [0 0 2.5 0.9]
The t het a for ma t r epr esent at ion of (6.1) is now cr ea t ed by t he command
th = poly2th(A,B,C,D,F,lam,T)
lam is her e t he var iance of t he whit e noise sour ce and T is t he sampling
int er val. Tr ailing ar gument s ca n be omit t ed for default values. The syst em
(6.2) can for example be r epr esent ed by
th = poly2th([1 –1.5 0.7],[0 0 0.5 0.7])
In t he mult i-input case (5.2) B and F a r e mat r ices, whose r ow number k
cor r esponds t o t he k-t h input . The command poly2th can also be used t o define
t ime-cont inuous syst ems. See t he Command Reference chapt er for det ails.
Multivariable ARX Models
A mult ivar iable ARX model is given by
Her e A(q) is an ny by ny mat r ix whose ent r ies ar e polynomials in t he delay
oper at or q
-1
. You can r epr esent it as
as well as t he mat r ix
e t ( )
A q ( )y t ( ) B q ( )u t ( ) e t ( ) + =
(6.3)
A q ( ) I
ny
A
1
q
1 –
… A
na
q
na –
+ + + =
(6.4)
a
11
(q) . . .
a
21
(q)
a
ny1
(q)
.

.

.
a
12
(q)
a
22
(q)
a
ny2
(q)
.

.

.
a
1ny
(q)
a
2ny
(q)
a
nyny
(q)
.

.

.
. . .
.

.

.
.

.

.
A(q) =
3-31
wher e t he ent r ies ar e polynomials in t he delay oper at or :
This polynomial descr ibes how old values of out put number j a ffect out put
number k. Her e is t he Kr onecker -delt a; it equals 1 when , ot her wise,
it is 0. Similar ly is an ny by nu mat r ix
or
wit h
The dela y fr om input number j t o out put number k is . To link wit h t he
st r uct ur e definit ion in t er ms of [na nb nk] in t he arx and iv4 commands, not e
t hat na is a ma t r ix whose kj-element is , while t he kj-element s of nb and nk
ar e and r espect ively.
The t het a for mat r epr esent at ion of t he model (6.3) can be cr ea t ed by
th = arx2th(A,B,ny,nu)
wher e ny a nd nu a r e t he number of out put s and input s, r espect ively, and A and
B ar e mat r ices t hat define t he ma t r ix polynomials (6.4) and (6.7):
A = [eye(ny) A1 A2 .. Ana]
B = [B0 B1 .. Bnb]
a
kj
q
1 –
a
kj
q ( ) δ
kj
a
kj
1
q
1 –
… a
kj
na
kj
q
na
kj

+ + + =
(6.6)
δ
kj
k j =
B q ( )
B q ( ) B
0
B
1
q
1 –
…B
nb
q
nb –
+ + = (6.7)
b
11
(q) . . .
b
21
(q)
b
ny1
(q)
.

.

.
b
12
(q)
b
22
(q)
b
ny2
(q)
.

.

.
b
1nu
(q)
b
2nu
(q)
b
nynu
(q)
.

.

.
. . .
.

.

.
.

.

.
B(q) =
b
kj
q b
1
kj
q
nk
kj
– = b
kj
nb –
q
nk
ij
– nb
i j
– 1 +
+
nk
kj
na
kj
nb
kj
nk
kj
3 Tu to r i a l
3-32
Consider t he following syst em wit h t wo out put s and t hr ee input s:
This syst em is defined and simulat ed for a cer t ain input u, a nd t hen est imat ed
in t he cor r ect ARX st r uct ur e by t he following st r ing of commands:
A0 = eye(2);
A1 = [–1.5 0.4; –0.2 0];
A2 = [0.7 0 ; 0.01 –0.7];
B0 = [0 0.4 0;1 0 0];
B1 = [0 –0.1 0;0 0 3];
B2 = [0 0.15 0;0 0 4];
B3 = [0 0 0;0 0 0];
B4 = [0.2 0 0;0 2 0];
B5 = [0.3 0 0;0 0 0];
A = [A0 A1 A2];
B = [B0 B1 B2 B3 B4 B5];
th0 = arx2th(A,B,2,3);
e = randn(200,2);
u = [idinput(200),idinput(200),idinput(200)];
y = idsim([u e],th0);
na = [2 1;2 1];
nb = [2 3 0;1 1 2];
nk = [4 0 0;0 4 1];
the = arx([y u],[na nb nk]);
[Ae, Be] = th2arx(the);
You can use t he t wo comma nds fixpar and unfixpar t o manipulat e ARX
st r uct ur es, so t hat cer t ain par amet er s in t he st r uct ur e ar e fixed t o cer t ain
known values and not est imat ed. See Chapt er 4, "Command Refer ence"for
mor e infor mat ion.
y
1
t ( ) 1.5y
1
t 1 – ( ) – 0.4y
2
t 1 – ( ) 0.7y
1
t 2 – ( ) + + 0.2u
1
t 4 – ( ) + =
0.3u
1
t 5 – ( ) 0.4u
2
t ( ) 0.1u
2
t 1 – ( ) – 0.15u
2
t 2 – ( ) e
1
t ( ) + + +
2u
2
t 4 – ( ) 3u
3
t 1 – ( ) 4u
3
t 2 – ( ) e
2
t ( ) + + +
y
2
t ( ) 0.2 ( )y
1
t 1 – ( ) – 0.7
y2
t 2 – ( ) – 0.01
y1
t 2 – ( ) u
1
t ( ) + = +
3-33
State-Space Models w ith Free Parameters
The ba sic st at e-space models ar e t he following ones: (See also “The Syst em
Ident ificat ion Pr oblem” on page 3-8.)
Discrete-Time Innovations Form
Her e T is t he sampling int er va l, is t he input at t ime inst ant and
is t he out put at t ime . (See Ljung (1987) page 87.)
System Dyna mics Ex pressed in Continuous Time
(See Ljung (1987) page 82.) It is oft en easier t o define a pa r amet r ized
st at e-space model in cont inuous t ime because physical laws a r e most oft en
descr ibed in t er ms of differ ent ial equat ions. The mat r ices F, G, H, and D
cont ain element s wit h physical significance (for example, ma t er ial const a nt s).
The numer ical values of t hese may or may not be known. To est imat e unknown
par amet er s based on sampled dat a (assuming T is t he sampling int er va l) fir st
t r ansfor m (6.9) t o (6.8) using t he for mulas (3.30). The value of t he Kalman-ga in
mat r ix K in (6.8) or in (6.9) depends on t he assumed cha r act er of t he a ddit ive
noises and in (3.28), and it s cont inuous-t ime count er par t . Disr egar d
t hat link and view K in (6.8) (or in (6.9)) as t he basic t ool t o model t he noise
pr oper t ies. This gives t he direct ly paramet rized innovations form. (See Ljung
(1987) pa ge 88.) If t he int er nal noise st r uct ur e is impor t ant , you could use
user -defined st r uct ur es as in Example 6.4.
The Syst em Ident ificat ion Toolbox a llows you t o define ar bit r ar y
par amet er izat ions of t he mat r ices in (6.8) or (6.9). When defining t he st r uct ur e,
t he known element s in t he mat r ices ar e ent er ed wit h t heir numer ical values,
x kT T + ( ) Ax kT ( ) Bu kT ( ) Ke kT ( ) + + =
y kT ( ) Cx kT ( ) Du kT ( ) e kT ( ) + + =
x 0 ( ) x0 =
(6.8a)
(6.8b)
(6.8c)
u kT ( ) kT y kT ( )
kT
x
·
t ( ) Fx t ( ) Gu t ( ) K
˜
w t ( ) + + =
y t ( ) Hx t ( ) Du t ( ) w t ( ) + + =
x 0 ( ) x0 =
(6.9a)
(6.9b)
(6.9c)
K
~
w t ( ) e t ( )
K
~
3 Tu to r i a l
3-34
while t he unknown element s ar e ent er ed as NaN. Use t he commands modstruc
and ms2th.
The Black-Box , Discrete-Time Case
For a discr et e-t ime model, like (6.8) wit hout a ny par t icular int er nal st r uct ur e,
it is easier and mor e nat ur al t o use canstart or n4sid t o est ima t e t he model,
wit hout any pr ior specifica t ion of t he par amet r iza t ion.
Example 6.1: A Discrete-Time Structure. Consider t he discr et e-t ime model
wit h five unknown par a met er s , i=1, ...,3. This st r uct ur e is defined in t he
t het a for mat by
A = [1 NaN; 0 1];
B = [NaN;NaN];
C = [1 0];
D = 0;
K = [NaN;NaN];
x0 = [0;0];
ms1 = modstruc(A,B,C,D,K,x0);
th1 = ms2th(ms1,'d')
The definit ion t hus follows in t wo st eps. Fir st t he a ct ual st r uct ur e (known and
unknown par a met er values) is coded in t he mat r ix ms1 and t hen a t het a for mat
mat r ix is cr eat ed by ms2th. The ar gument 'd' denot es t ha t t he st r uct ur e is a
discr et e-t ime st r uct ur e. Ot her opt ional ar gument s allow definit ion of guessed
va lues of t he unknown pa r amet er s, as well as specificat ion of t he cova r iance
mat r ix of and of t he sampling int er va l T. You can also specify unknown
element s in t he init ia l value vect or .
x t 1 + ( )
1 θ
1
0 1
x t ( )
θ
2
θ
3
u t ( )
θ
4
θ
5
e t ( ) + + =
y t ( )
1 0
x t ( ) e t ( ) + =
x 0 ( )
0
0
=
θ
i
e t ( )
x 0 ( )
3-35
For models t hat ar e par amet r ized as ca nonical for ms, use canform inst ead of
modstruc t o define t he model st r uct ur e.
Ex ample 6.2: A Continuous-Time Model Structure. Consider t he following
model st r uct ur e
This cor r esponds t o an elect r ical mot or , wher e is t he angular
posit ion of t he mot or shaft and is t he angular velocit y. The
par a met er is t he inver se t ime const a nt of t he mot or and is t he
st a t ic gain fr om t he input t o t he angular velocit y. (See page 84 in Ljung (1987).)
The mot or is a t r est at t ime 0 but at a n unknown angula r posit ion. Suppose
t hat is a r ound -1 a nd is a r ound 0.25. If you also know t ha t t he va r iance
of t he er r or s in t he posit ion mea sur ement is 0.01 a nd in t he angular velocit y
measur ement s is 0.1, you can t hen define a t het a st r uct ur e using
F = [0 1; 0 NaN]
G = [0 ;NaN]
H = eye(2)
D = zeros(2,1)
K = zeros(2,2)
x0 = [NaN;0]
ms2 = modstruc(F,G,H,D,K,x0);
thguess=[–1, 0.25, 0]
noisevar = [0.01 0; 0 0.1]
th2 = ms2th(ms2,'c',thguess,noisevar)
The st r uct ur e th2 can now be used t o est imat e t he unknown par amet er s
fr om obser ved dat a z = [y1 y2 u] by
model = pem(z,th2)
x
·
t ( )
0 1
0 θ
1
x t ( )
0
θ
2
u t ( ) + =
y t ( )
1 0
0 1
x t ( ) e t ( ) + =
x 0 ( )
θ
3
0
=
y
1
t ( ) x
1
t ( ) =
y
2
t ( ) x
2
t ( ) =
θ
1
– θ
2
θ
1
⁄ –
θ
1
θ
2
θ
i
3 Tu to r i a l
3-36
The it er at ive sear ch for minimum is t hen init ia lized a t thguess. The st r uct ur e
can also be used t o simula t e t he syst em above wit h sampling int er val T=0.1 for
input u and noise r ea lizat ion e:
e=randn(300,2)
u=idinput(300);
th2 = sett(th2,0.1) % setting the sampling interval
y = idsim([u e],th2)
The nominal par a met er values thguess ar e t hen used, and t he noise sequence
is scaled a ccor ding t o t he mat r ix noisevar.
When est imat ing models, you can t r y a number of “neighbor ing” st r uct ur es,
like “what happens if I fix t his pa r amet er t o a cer t ain value” or “what happens
if I let loose t hese par amet er s.” Rat her t han going t hr ough t he whole pr ocedur e
in r edefining t he st r uct ur e, you can use t he commands fixpar and unfixpar.
For example, t o fr ee t he par amet er x
2
(0) (per haps t he mot or wasn’t a t r est
aft er all) you can use
th = unfixpar(th2,'x0',[2,1])
To manipulat e init ial condit ions, t he funct ion thinit is also useful.
State-Space Models with Coupled Parameters
In some sit uat ions you may want t he unknown par amet er s in t he mat r ices in
(6.8) or (6.9) t o be linked t o each ot her . Then t he NaN feat ur e is not sufficient t o
descr ibe t hese links. Inst ea d you need t o wr it e an M-file t hat descr ibes t he
st r uct ur e. The for mat is
[A,B,C,D,K,x0] = mymfile(par,T,aux);
wher e mymfile is t he user -defined name for t he M-file, par cont ains t he
par amet er s, T is t he sampling int er val, and aux cont ains a uxiliar y var ia bles.
The lat t er var iables ar e used t o house opt ions, so t hat some differ ent cases can
be t r ied out wit hout having t o edit t he M-file. The mat r ices A, B, C, D, K, and x0
r efer t o t he discr et e-t ime descr ipt ion (6.8). If t he under lying pa r amet er izat ion
is in cont inuous t ime, as in (6.9), it is desir able t o wr it e t he M-file so t hat a
negat ive value of T inhibit s t he sampling. This means t hat A, B, C and D should
be r et ur ned as t he mat r ices in (6.9) when mymfile is called wit h a negat ive T.
To obt a in t he same st r uct ur e as in t he Example 6.2 , you can do t he following:
3-37
function [A,B,C,D,K,x0] = mymfile(par,T,aux)
F = [0 1; 0 par(1)];
G = [0;par(2)];
C = eye(2);
D = zeros(2,2);
K = zeros(2,1);
x0 =[par(3);0];
if T>0, [A,B] = c2d(F,G,T); else A=F; B=G; end
Her e c2d is t he sampling funct ion fr om t he Cont r ol Syst em Toolbox, which
consequent ly is r equir ed t o r un t his example.
Once t he M-file has been wr it t en, t he cor r esponding t het a st r uct ur e is defined
by t he comma nd mf2th (M-file t o t het a):
th = mf2th('mymfile','c',par,aux);
wher e par cont ains t he nominal (init ia l) values of t he cor r esponding ent r ies in
t he st r uct ur e. 'c' signa ls t hat t he under lying par amet r izat ion is cont inuous
t ime, and t hat t he M-file is equipped wit h sampling inhibit ion (for ). aux
cont ains t he values of t he auxiliar y pa r amet er s.
Fr om her e on, est imat e models and evaluat e r esult s as for any ot her model
st r uct ur e. Not e, t hough t hat t he fea t ur es fixpar and unfixpar ar e not
ava ilable for t hese gener a l st r uct ur es. Some fur t her examples of user -defined
model st r uct ur es ar e given below.
State-Space Structures: Initial Values and Numerical
Derivatives
It is somet imes difficult t o find good init ial par amet er values a t which t o st ar t
t he numer ical sear ch for a minimum of (3.38). It is always best t o use physical
insight , whenever possible, t o suggest such va lues wit h thguess. For r andom
init ializat ion, t he comma nd thinit is a useful alt er nat ive a nd complement t o
thguess. Since t her e is always a r isk t hat t he numer ical minimizat ion may get
st uck in a local minimum, it is advisable t o t r y sever al differ ent init ializat ion
values for .
In t he sear ch for t he minimum, t he gr adient of t he pr edict ion er r or s is
comput ed by numer ical differ ent iat ion. The st ep-size is det er mined by t he
M-file nuderst. In it s default ver sion t he st ep-size is simply t imes t he
absolut e value of t he par amet er in quest ion (or t he number if t his is
T 0 <
θ
e t ( )
10
4 –
10
7 –
3 Tu to r i a l
3-38
lar ger ). When t he model st r uct ur e cont ains par amet er s wit h differ ent or der s of
magnit ude, t r y t o scale t he var iables so t hat t he pa r amet er s ar e a ll r oughly t he
sa me magnit ude. In any case, you may need t o edit t he M-file nuderst t o
addr ess t he pr oblem of suit able st ep sizes for numer ical differ ent iat ion.
Some Examples of User-Defined Model Structures
Wit h user -defined st r uct ur es, you have complet e fr eedom in t he choice of
models of linea r syst ems. This sect ion gives t wo examples of such st r uct ur es.
Example 6.3: Heat Diffusion. Consider a syst em dr iven by t he heat -diffusion
equat ion (see also Example 4.3 in Ljung (1987)).
This is a met al r od wit h heat -diffusion coefficient which is insulat ed at t he
nea r end a nd heat ed by t he power u (W) at t he far end. The out put of t he
syst em is t he t emper at ur e at t he nea r end. This syst em is descr ibed by a par t ial
differ ent ial equat ion in t ime and space. Replacing t he space-second der ivat ive
by a cor r esponding differ ence appr oximat ion gives a t ime-cont inuous
st at e-space model (6.9), wher e t he dimension of x depends on t he st ep-size in
space used in t he appr oxima t ion. This is descr ibed by t he following M-file:
function [A,B,C,D,K,x0] = heatd(pars,T,aux)
N = aux(1); % Number of points in the
% space–discretization
L = aux(2); % Length of the rod
temp = aux(3); % Assuming uniform initial
% temperature of the rod
deltaL = L/N; % Space interval
kappa = pars(1); % The heat–diffusion coefficient
K = pars(2); % Heat transfer coefficient at
% far end of rod
F=zeros(N,N);
for kk=2:N–1
F(kk,kk–1)=1;
F(kk,kk)=–2;
F(kk,kk+1)=1;
end
F(1,1)=–1; F(1,2)=1; % Near end of rod
% insulated
F(N,N–1)=1; F(N,N)=–1;
F=F∗kappa/deltaL/deltaL;
κ
3-39
G=zeros(N,1);
G(N,1)=K/deltaL;
C=zeros(1,N);
C(1,1)=1;
D=0;
K=zeros(N,1);
x0=temp∗ones(N,1);
if T>0 [A,B]=c2d(F,G,T);else A=F;B=G;end
You can t hen get st ar t ed wit h t he t het a for mat wit h
th = mf2th('heatd','c',[0.27 1],[10,1,22],[],10)
for a 10t h or der appr oximat ion of a heat r od one met er in lengt h, wit h an init ial
t emper at ur e of 22 degr ees and a sampling int er val of 10 seconds. The init ial
est imat e of t he heat conduct ivit y is 0.27, and of t he heat t r ansfer coefficient is
1. The cova r iance mat r ix of t he pr edict ion er r or s is given a default value.
Ex ample 6.4: Parametrized Noise Models. Consider a discr et e-t ime model
x ( t +1 ) =A x ( t ) +B u (t ) +w (t )
y (t )=Cx (t )+e(t )
wher e w and e ar e independent whit e noises wit h covar iance ma t r ices R1 and
R2, r espect ively. Suppose t hat you know t he var iance of t he measur ement
noise R2, and t ha t only t he fir st component of is nonzer o. This can be
handled by t he following M-file:
function [A,B,C,D,K,x0] = mynoise(par,T,aux)
R2 = aux(1); % The assumed known measurement
% noise variance
A = [par(1) par(2);1 0];
B = [1;0];
C=[par(3) par(4)];
D=0;
R1= [par(5) 0;0 0];
K = A∗dlqe(A,eye(2),C,R1,R2); % from the
% Control System Toolbox
x0=[0;0];
w t ( )
3 Tu to r i a l
3-40
7. Ex amining Models
Once you have est imat ed a model, you need t o invest igat e it s pr oper t ies. You
have t o simulat e it , t est it s pr edict ions, and comput e it s poles and zer os and so
on. You t hus ha ve t o t r ansfor m t he model fr om t he t het a for mat t o ot her ways
of r epr esent ing and pr esent ing it .
Theta Format: th
The basic for mat for r epr esent ing models in t he Syst em Ident ificat ion Toolbox
is called t he t het a format . It st or es all r elevant infor mat ion about t he model
st r uct ur e used, including t he values of t he est imat ed par amet er s, t he
est imat ed covar iances of t he par amet er s, and t he est imat ed innovat ions
va r iance and so on. It also cont ains some infor ma t ion about how and when t he
model was cr eat ed. The det a ils of t he r epr esent at ion can be found in t he
Chapt er 4, "Command Refer ence" or by t yping help theta (for st at e-space
based st r uct ur es t ype help thss). The r epr esent a t ion should, however , be
t hought of a s an int er nal one; unless you ar e an advanced user , you do not need
t o wor r y about t he det a ils. “Defining Model St r uct ur es” on pa ge 3-29 descr ibes
how t o cr eat e models in t he t het a for mat using sever al differ ent commands.
The infor mat ion in t he t het a for mat is displayed by t he present command:
present(th)
This spells out t he infor mat ion in th. Depending on t he char act er of t he
under lying model st r uct ur e, t he infor mat ion is given in t er ms of t he
polynomials in (6.1), in t er ms of t he mat r ices in (6.8) or (6.9), or in t er ms of t he
ARX polynomials in (6.3). Est imat ed st andar d deviat ions for t he par a met er s
ar e always supplied. For mult ivar iable ARX models and for st at e-space
mat r ices, t he st andar d devia t ions a r e given as ima ginar y number s added t o t he
par amet er s. For t he polynomials t hey ar e given as a second r ow. For example,
t he following pr int out fr om present
The polynomial coefficients and their standard deviations are
B =
0.0000 0.0000 1.7345
0.0000 0.0000 0.0563
A =
1.0000 –1.5312 0.6983
0.0000 0.0214 0.0022
3-41
is int er pr et ed as and t he st andar d deviat ion
of “1” is zer o (nat ur ally enough , since it is not est imat ed). The st andar d
deviat ion of is 0.0214. Not e t hat leading zer os in t he B polynomial indicat e
t he delay, a s defined in “Defining Model St r uct ur es” on page 3-29.
The act ual par amet er s can be ext r act ed fr om t he t het a for mat by
[par,P] = th2par(th)
Her e par is a r ow vect or cont aining t he pa r amet er s, and P is t he est imat ed
covar iance mat r ix of t he par amet er s. The par amet er s ar e list ed in
“alphabet ical or der .” See “Some Special Topics” on page 3-68. For t he
polynomia l model (6.1) t he coefficient s of t he A, B, C, D, a nd F polynomials ar e
given in t he or der of incr easing power s of . (See for exa mple (6.2).) Not e t hat
leading 0’s of B and t he leading 1 in t he ot her polynomials a r e omit t ed since
t hey do not cor r espond t o est imat ed par amet er s. For t he st at e-space model
(6.8) t he par amet er s ar e given in t he or der obt ained as t he ma t r ix A is fir st
sear ched for est imat ed par amet er s r ow by r ow, t hen B and t hen C, et c. The
same is t r ue for t he cont inuous model (6.9). For user -defined st r uct ur es, t he
or der ing in par is t he same as defined in t he cor r esponding M-file. For
mult ivar iable ARX models, t he or der ing of par a met er s is somewhat t r icky and
it is safer use th2arx. (See “The ARX For mat : ar x” on page 3-45.)
The sampling int er val can be ext r act ed fr om t he t het a for ma t by
T = gett(th)
A negat ive T means t hat th r epr esent s a t ime-cont inuous syst em. Then syst em
abs(T) indicat es t he sampling int er val for t he dat a for which t he model was
est imat ed. It is also t he sampling int er val t hat applies when th is used for
simulat ion or pr edict ion.
Frequency Function Format: ff
The fr equency funct ion and t he dist ur bance spect r um cor r esponding t o a model
th in t he t het a for mat is comput ed by
[G,PHIV] = th2ff(th)
This gives G and in (3.11) along wit h t heir est ima t ed st andar d deviat ions,
which ar e t r anslat ed fr om t he covar ia nce mat r ix of t he est imat ed pa r amet er s.
If th cor r esponds t o a t ime-cont inuous model, t he fr equency funct ions ar e
comput ed accor dingly.
A q ( ) 1 1.5312q
1 –
– 0.6983q
2 –
+ =
a
1
q
1 –
Φ
ˆ
v
3 Tu to r i a l
3-42
The r esult ing mat r ices G and PHIV a r e given in t he freqfunc format . This for mat
st or es t he fr equency funct ions and spect r a (3.11) and t heir st andar d devia t ions
as column vect or s. The fir st r ow is r eser ved for a dminist r at ive infor mat ion,
giving det a ils about input and out put number s. The fr equency values can be
chosen ar bit r ar ily, but default t o 128 va lues equally spaced bet ween 0
(excluded) and t he Nyquist fr equency. For t ime-cont inuous models, t he default
fr equency r ange ext ends t o a deca de over t he Nyquist fr equency for t he
sa mpled dat a upon which t he model is ba sed. Typing help freqfunc descr ibes
t he det ails of t he for ma t , which, however , is not impor t ant for basic use of t he
t oolbox.
The funct ion th2ff has opt ions t hat allow t he select ion of specific input -out put
pair s, and t he comput at ion of fr equency funct ions and spect r a at ar bit r ar y
fr equencies.
If th cor r esponds t o a model of a t ime ser ies, it s spect r um is obt a ined a s
PHIY = th2ff(th)
Models in t he fr eqfunc for mat a r e also obt ained by t he nonpa r amet r ic
est imat ion r out ines spa and etfe, as descr ibed in “Nonpar a met r ic Model
Est imat ion” on page 3-19.
Thr ee funct ions offer gr aphic display of t he fr equency funct ions and spect r a:
bodeplot, ffplot, and nyqplot.
bodeplot(G)
plot s t he Bode diagr am of G (logar it hmic scales and fr equencies in r ad/sec). If G
is a spect r um, only an amplit ude plot is given. Sever al cur ves in t he same
diagr am ar e obt ained wit h
bodeplot([G1 G2 ... Gn])
If infor ma t ion about st andar d deviat ions is included in G, confidence int er vals
cor r esponding t o sd st anda r d deviat ions ar e gr aphed wit h
bodeplot(G,sd)
The comma nd ffplot has t he same synt ax as bodeplot but wor ks wit h linear
fr equency sca les and Her t z as t he unit . The command nyqplot also has t he
sa me synt ax, but pr oduces Nyquist plot s; i.e., gr aphs of t he fr equency funct ion
in t he complex pla ne.
For t he cr eat ion of own fr equency plot s, t he command getff ext r act s t he
r elevant por t ions of t he fr eqfunc for ma t . (See Chapt er 4, "Comma nd
Refer ence"for mor e infor mat ion.)
3-43
Zero-Pole Format: zp
The command th2zp comput es t he zer os, poles, and st at ic gains of t he syst em
associat ed wit h th:
[zepo,K] = th2zp(th)
The mat r ix zepo now cont ains infor mat ion about t he zer os and t he poles of t he
model, along wit h t heir est imat ed st anda r d deviat ions. It also cont a ins (in t he
fir st r ow) administ r a t ive infor mat ion about input and out put number s, which
is used for plot t ing. Similar ly, K cont ains t he st at ic gains and t heir st andar d
deviat ions. The best way of using t he infor mat ion in zepo is t o gr aph t he zer os
and poles by
zpplot(zepo)
Confidence r egions (lines a nd ellipsoids) cor r esponding t o sd st andar d
deviat ions ar e illust r at ed by
zpplot(zepo,sd)
Compar isons bet ween sever al models ar e obt ained by
zp1 = th2zp(th1)
zp2 = th2zp(th2)
zpplot(zpform(zp1,zp2))
zpplot has sever al opt ions t hat det er mine how infor mat ion about differ ent
models a nd differ ent input -out put pair s is depict ed. It also keeps t r ack of
whet her t he under lying model is in discr et e or cont inuous t ime and dr aws t he
complex plane accor dingly. The command th2zp also allows t he select ion of
specific input -out put subsyst ems in t he case of mult ivar iable models.
The funct ion getzp allows you t o ext r a ct t he zer os and t he poles explicit ly fr om
t he zer o-pole for ma t .
State-Space Format: ss
The command
[A,B,C,D,K,X0] = th2ss(th)
comput es t he mat r ices of a st at e-spa ce r epr esent at ion of th. The
r epr esent at ion is in discr et e t ime as (6.8) or in cont inuous t ime as (6.9)
depending on t he st at us of th. If t he under lying model st r uct ur e is a
3 Tu to r i a l
3-44
st at e-space one, t he mat r ices A, B, et c. ar e given in t he same basis as or igina lly
defined. If t he under lying model is defined in t er ms of input -out put
polynomials, t he st a t e-space r epr esent at ion is in obser ver canonical for m. The
st at e-space mat r ices ca n be used for fur t her ana lysis and design in t he Cont r ol
Syst em Toolbox and t he Signa l Pr ocessing Toolbox.
The command th2ss can also comput e t he st andar d deviat ions of t he element s
in st at e-space mat r ices.
Transfer Function Format: tf
The t r a nsfer funct ions associat ed wit h t he model th ar e comput ed by
[NUM,DEN] = th2tf(th)
NUM and DEN ar e given in t he same for mat t hat is used in t he Cont r ol Syst em
Toolbox and t he Syst em Pr ocessing Toolbox. The common denominat or DEN as
a r ow mat r ix and t he k-t h r ow of NUM gives t he numer a t or polynomial
associat ed wit h out put number k. If t he model th ha s sever al input s, specify
t he input number as an ar gument . The polynomia ls a r e r epr esent ed as r ow
vect or s in descending power s of s (in cont inuous t ime) or z or q (in discr et e
t ime). It t hus differ s fr om t he polynomia l for mat . (See below.) For example, t he
cont inuous-t ime syst em
is r epr esent ed as
NUM = [0 0 1] (or just 1)
DEN = [1 2 0]
while t he discr et e-t ime syst em
is r epr esent ed as
NUM = 1
DEN = [1 –1.5 0.7 0]
1
s s 2 + ( )
-------------------
q
3 –
1 1.5q
1 –
– 0.7q
2 –
+
-----------------------------------------------
1
q
3
1.5q
2
– 0.7q +
------------------------------------------ =
(7.1)
3-45
Polynomial Format: poly
In t he polynomial for mat , t he polynomials A, B, C, D, and F in (3.23) ar e given
as follows: Polynomial coefficient s ar e st or ed in r ow vect or s, or der ed by
ascending power s in t he delay oper at or , , 1, , always st ar t ing wit h
. This means t hat (7.1) is r epr esent ed by
B = [0 0 0 1]
A = [1 –1.5 0.7]
Delays ar e t hus denot ed by leading zer os in B. Not e t he differ ence wit h t he
t r ansfer funct ion r epr esent at ion, in t hat leading zer os must be explicit ly given.
Only when t he lengt hs of A and B ar e t he sa me do t he for mat s coincide. See also
Sect ion 6. The polynomials cor r esponding t o th ar e ext r a ct ed by
[A,B,C,D,F] = th2poly(th)
This is consequent ly t he “inver se” of poly2th descr ibed in “Defining Model
St r uct ur es” on page 3-29.
Cont inuous-t ime syst ems can also be r epr esent ed in t he polynomial for mat .
Then t he polynomials ar e given a s r ow vect or s in descending power s of t he
Laplace var iable s just as in t he t r ansfer funct ion case.
The ARX Format: arx
To obt ain an ARX descr ipt ion fr om a model th t hat cor r esponds t o such a
descr ipt ion (i.e., it has or iginally been gener at ed by arx, iv4, or arx2th), use
[A,B] = th2arx(th)
The mat r ices A a nd B t hen cont ain t he ARX polynomials as descr ibed in Sect ion
6. th2arx is t hus an inver se of arx2th.
q
k –
k 0 = …
k 0 =
3 Tu to r i a l
3-46
Transformations Betw een Discrete and Continuous
Models
Continuous-Time Models
A model in t he t het a for ma t can be int er nally r epr esent ed a s a cont inuous-t ime
model. This occur s if t he st r uct ur e was or iginally defined a s a st at e-space
st r uct ur e wit h ms2th or mf2th using t he ar gument 'c'. (See “Defining Model
St r uct ur es” on page 3-29 a nd t he Chapt er 4, "Comma nd Refer ence".) The model
t hen r emains a cont inuous-t ime one dur ing t he est imat ion phases wit h pem
even t hough t he est imat ion is per for med using sa mpled dat a. A
cont inuous-t ime model of t he t ype (6.1) in polynomial for m also r esult s when
poly2th is used wit h a negat ive value of t he sampling int er val. This st r uct ur e
cannot , however , be used for fur t her est imat ion. Finally, cont inuous-t ime
models ar e obt ained by t he comma nd thd2thc. (See below.)
Cont inuous-t ime models ar e indicat ed by a negat ive sa mpling int er va l. A quick
check can t hus be given by
gett(th)<0
All t he model t r a nsfor ma t ions th2ff, th2zp, th2ss, th2tf, a nd th2poly r esult
in t he cor r esponding char act er ist ics in cont inuous t ime for models th t hat ar e
indicat ed a s cont inuous. For simulat ion and pr edict ion, however , t he model is
fir st t r a nsfor med t o discr et e t ime.
The absolut e value of t he sa mpling int er val of a cont inuous-t ime model is t he
sa mpling int er val of t he da t a for which t he model was est imat ed. It is also used
t o select suit able default fr equency int er vals in th2ff (t he default being fr om
zer o up t o 10
*
π/ | T| r ad/sec). The absolut e value of T also applies when t he
model is used for simulat ion a nd pr edict ion.
Discrete-Time Models
These models a r e obt ained fr om t he est imat ion funct ions ar, armax, arx, bj,
ivar, iv4, n4sid, and oe. They ar e a lso obt ained fr om pem when applied t o (6.1)
and t o st at e-space st r uct ur es gener at ed by ms2th a nd mf2th wit h t he ar gument
'd'. Discr et e-t ime models also r esult fr om poly2th wit h posit ive or default
va lues of t he sampling int er val. Finally discr et e-t ime models ar e obt ained wit h
t he command thc2thd. (See below.)
3-47
The sa mpling int er val T is obt a ined by T = gett(th). It indicat es t he sampling
int er val of t he model as well as of t he dat a t o which t he model wa s adjust ed. It
is also used for appr opr ia t e fr equency sca les in t he fr eqfunc for mat .
Transformations
Tr ansfor mat ions bet ween cont inuous-t ime and discr et e-t ime model
r epr esent at ions ar e achieved by thc2thd and thd2thc. The cor r esponding
uncer t aint y mea sur e (t he est imat ed covar iance mat r ix of t he int er nal
par a met er s) is also t r ansfor med in most cases. The synt ax is
thc = thd2thc(thd)
thd = thc2thd(thc,T)
If t he discr et e-t ime model has some pur e t ime delays ( ) t he default
command r emoves t hem befor e for ming t he cont inuous-t ime model. They
should t hen be appended as an ext r a dead t ime. This is done aut oma t ically by
th2ff. thd2thc offer s as an opt ion t o appr oximat e t he dead t ime by a finit e
dimensional syst em. Not e t hat t he noise pr oper t ies ar e t r anslat ed by t he
somewhat quest iona ble for mula (3.32). The cova r iance mat r ix is t r anslat ed by
Gauss’ appr oximat ion for mula using numer ical der ivat ives. The M-file
nuderst is t hen invoked. You may want t o edit it for applicat ions wher e t he
par a met er s have ver y differ ent or der s of magnit ude. See t he comment s in
“Defining Model St r uct ur es” on pa ge 3-29.
Her e is an example which compar es t he Bode plot s of an est imat ed model and
it s cont inuous-t ime count er par t :
th = armax(z,[2 3 1 2]);
gd = th2ff(th);
thc = thd2thc(th);
gc = th2ff(thc);
bodeplot([gd gc])
Simulation and Prediction
Any model, when given in t he t het a for ma t , ca n be simulat ed wit h
y = idsim([u e],th)
wher e u and e ar e column vect or s (or mat r ices) cont a ining t he input and noise
sequences. The out put is r et ur ned in a column vect or y of t he same lengt h.
Not ice t ha t th cont ains infor ma t ion about t he noise var iance so e should be a
nk 1 >
3 Tu to r i a l
3-48
zer o-mean, unit -var iance sequence. If e is omit t ed, a noise-fr ee simulat ion is
obt ained. Her e is a t ypical st r ing of commands:
A = [1 –1.5 0.7];
B = [0 1 0.5];
th0 = poly2th(A,B,[1 –1 0.2]);
u = idinput(400,’rbs’,[0 0.3]);
e = randn(400,1);
y = idsim([u e],th0);
plot(y)
The “inver se model” (3.38), which comput es t he pr edict ion er r or s fr om given
input -out put dat a, is simulat ed wit h
e = pe([y u],th)
To comput e t he k-st ep ahead pr edict ion of t he out put signal based on a model
th, t he pr ocedur e is as follows:
yhat = predict([y u],th,k)
The pr edict ed value is comput ed using t he infor mat ion in up t o
t ime and infor mat ion in up t o t ime . The act ual way t hat
t he infor mat ion in past out put s is used depends on t he noise model in th. For
example, a n out put er r or model maint ains t hat t her e is no
infor mat ion in past out put s, t her efor e, pr edict ions and simulat ions coincide.
predict can eva luat e how well a t ime ser ies model is capable of pr edict ing
fut ur e values of t he dat a. Her e is an example, wher e y is t he or iginal ser ies of,
sa y, mont hly sa les figur es. A model is est imat ed based on t he fir st half, and
t hen it s abilit y t o pr edict half a year ahead is checked out on t he second half of
t he obser vat ions:
idplot(y)
y1 = y(1:48), y2 = y(49:96)
th = ar(y1,4)
yhat = predict(y2,th4,6)
plot([y2 yhat])
The command compare is useful for any compar isons involving idsim and
predict.
yˆ t t k – ( ) u s ( )
s t = y s ( ) s t k – =
A C D 1 = = =
3-49
8. Model Structure Selection and Validation
Aft er you have been analyzing dat a for some t ime, you t ypically end up wit h a
lar ge collect ion of models wit h differ ent or der s and st r uct ur es. You need t o
decide which one is best , and if t he best descr ipt ion is an adequat e model for
your pur poses. These a r e t he pr oblems of model validation.
Model validat ion is t he hear t of t he ident ificat ion pr oblem, but t her e is no
absolut e pr ocedur e for appr oaching it . It is wise t o be equipped wit h a var iet y
of differ ent t ools wit h which t o evaluat e model qualit ies. This sect ion descr ibes
t he t echniques you ca n use t o evaluat e model qualit ies using t he Syst em
Ident ificat ion Toolbox.
Comparing Different Structures
It is nat ur al t o compar e t he r esult s obt ained fr om model st r uct ur es wit h
differ ent or der s. For st at e-space models t his is easily obt ained by using a vect or
ar gument for t he or der in n4sid:
th = n4sid(z,1:10)
This invokes a plot fr om which a “best ” or der is chosen.
For models of ARX t ype, var ious or der s a nd dela y can be efficient ly st udied
wit h t he command arxstruc. Collect in a mat r ix NN all of t he ARX st r uct ur es
you wa nt t o invest igat e, so t hat each r ow of NN is of t he t ype
[na nb nk]
Wit h
V = arxstruc(ze,zv,NN)
an ARX model is fit t ed t o t he dat a set ze for each of t he st r uct ur es in NN. Next ,
for each of t hese models, t he sum of squar ed pr edict ion er r or s is comput ed, as
t hey ar e a pplied t o t he dat a set zv. The r esult ing loss funct ions a r e st or ed in V
t oget her wit h t he cor r esponding st r uct ur es.
To select t he st r uct ur e t ha t has t he sma llest loss funct ion for t he validat ion set
zv, use
nn = selstruc(V,0)
3 Tu to r i a l
3-50
Such a pr ocedur e is known as cross validat ion and is a good way t o appr oach
t he model select ion pr oblem.
It is usually a good idea t o visually inspect how t he fit cha nges wit h t he number
of est imat ed par amet er s. A gr aph of t he fit ver sus t he number of par amet er s is
obt ained wit h
nn = selstruc(V)
This r out ine pr ompt s you t o choose t he number of par a met er s t o est imat e,
based upon visua l inspect ion of t he gr aph, and t hen it select s t he st r uct ur e
wit h t he best fit for t hat number of par amet er s.
The command struc helps gener at e t ypica l st r uct ur e mat r ices NN for
single-input syst ems. A t ypical sequence of commands is
V = arxstruc(ze,zv,struc(2,2,1:10));
nn = selstruc(V,0);
nk = nn(3);
V = arxstruc(ze,zv,struc(1:5,1:5,nk–1:nk+1));
nn = selstruc(V)
wher e you fir st est ablish a suit a ble value of t he delay nk by t est ing second
or der models wit h dela ys bet ween one and t en. The best fit select s t he delay,
and t hen all combinat ions of ARX models wit h up t o five a and b pa r amet er s
ar e t est ed wit h delays ar ound t he chosen value (a t ot al of 75 models).
If t he model is validat ed on t he same dat a set fr om which it wa s est ima t ed; i.e.,
if ze = zv, t he fit always impr oves as t he model st r uct ur e incr eases. You need
t o compensat e for t his aut omat ic decr ea se of t he loss funct ions. Ther e ar e
sever al appr oaches for t his. Pr obably t he best known t echnique is Akaike’s
Fina l Pr edict ion Er r or (FPE) cr it er ion and his closely r elat ed Infor mat ion
Theor et ic Cr it er ion (AIC). Bot h simulat e t he cr oss valida t ion sit uat ion, wher e
t he model is t est ed on anot her dat a set .
The FPE is for med a s
FPE
1 n + N ⁄
1 n – N ⁄
-------------------- = *V
3-51
wher e n is t he t ot al number of est imat ed par amet er s and N is t he lengt h of t he
dat a r ecor d. V is t he loss funct ion (quadr at ic fit ) for t he st r uct ur e in quest ion.
The AIC is for med as
(See Sect ion 16.4 in Ljung (1987).)
Accor ding t o Akaike’s t heor y, in a collect ion of differ ent models, choose t he one
wit h t he sma llest FPE (or AIC). The FPE va lues ar e displayed by t he present
command and ar e also given as t he ent r y (2,1) of t he th mat r ix. The st r uct ur e
t hat minimizes t he AIC is obt ained wit h
nn = selstruc(V,'AIC')
wher e V was gener at ed by arxstruc.
A r ela t ed cr it er ion is Rissanen’s minimum descr ipt ion lengt h (MDL) appr oach,
which select s t he st r uct ur e t hat a llows t he shor t est over -all descr ipt ion of t he
obser ved dat a . This is obt ained wit h
nn = selstruc(V,'MDL')
If subst ant ia l noise is pr esent , t he ARX models may need t o be of high or der t o
descr ibe simult aneously t he noise char a ct er ist ics and t he syst em dynamics.
(For ARX models t he noise model 1/A(q) is dir ect ly coupled t o t he dyna mics
model B(q)/A(q).) An alt er nat ive is t o comput e t he dynamics model only, using
an IV t echnique, a nd t o comput e t he fit bet ween t he model’s simulat ed out put
and t he out put in t he valida t ion dat a set zv. This is accomplished wit h
V = ivstruc(ze,zv,NN)
The infor mat ion in V can t hen be handled as descr ibed above. In t his case, V
also cont ains t he condit ion number of t he mat r ix fr om which t he IV est ima t es
ar e solved. Poor condit ioning of t his ma t r ix indicat es unnecessa r ily high model
or der s. (See page 415 in Ljung, 1987).
Checking Pole-Zero Cancellations
A near pole-zer o cancellat ion in t he dynamics model is an indicat ion t hat t he
model or der may be t oo high. To judge if a “near ” cancellat ion is a r eal
ca ncellat ion, t ake t he uncer t aint ies in t he pole- and zer o-loca t ions int o
AIC log 1 2n + N ⁄ ( )*V [ ] ≈
3 Tu to r i a l
3-52
consider at ion. The funct ion th2zp comput es confidence r egions for t he poles
and zer os, which ar e gr aphed by
zpplot(th2zp(th),1)
wher e t he 1 indicat es how many st anda r d-deviat ions wide t he confidence
int er val is. If t he confidence r egions over lap, t r y lower model or der s.
This check is especially useful when t he models have been gener at ed by arx. As
ment ioned under “Compar ing Differ ent St r uct ur es,” t he or der s can be pushed
up due t o t he r equir ement t hat 1/A(q) descr ibe t he noise char act er ist ics.
Checking cancellat ions in B(q)/A(q) t hen gives a good indicat ion of which or der s
t o chose fr om model st r uct ur es like armax, oe, and bj.
Residual Analysis
The r esiduals associat ed wit h t he da t a and a given model, as in (3.38), ar e
ideally whit e and independent of t he input for t he model t o cor r ect ly descr ibe
t he syst em. The funct ion
e = resid(z,th)
comput es t he r esiduals e and per for ms whit eness and independence analyses.
The aut o cor r elat ion funct ion of e and t he cr oss cor r elat ion funct ion bet ween e
and u ar e comput ed and displayed for up t o lag 25. Also displayed ar e 99%
confidence int er va ls for t hese var iables, assuming t hat e is indeed whit e and
independent of u.
The r ule is t hat if t he cor r elat ion funct ions go significant ly out side t hese
confidence int er va ls, do not a ccept t he cor r esponding model a s a good
descr ipt ion of t he syst em. Some qualificat ions of t his st at ement ar e necessar y:
• Model st r uct ur es like t he OE st r uct ur e (3.19) and met hods like t he IV
met hod (3.41) focus on t he dynamics G and less about t he noise pr oper t ies H.
If you ar e int er est ed pr imar ily in G, focus on t he independence of e a nd u
r at her t han t he whit eness of e.
• Cor r elat ion bet ween e and u for negat ive lags, or cur r ent affect ing
fut ur e , is an indicat ion of out put feedback. This is not a r eason t o r eject
t he model. Cor r ela t ion at negat ive lags is of int er est , since cer t ain met hods
do not wor k well when feedba ck is pr esent in t he input -out put da t a, (see
e t ( )
u t ( )
3-53
“Dealing wit h Dat a” on page 3-58), but concent r at e on t he posit ive lags in t he
cr oss-cor r elat ion plot for model validat ion pur poses.
• When using t he ARX model (3.15), t he least -squar es pr ocedur e
a ut omat ically ma kes t he cor r elat ion bet ween and zer o for
, , , for t he dat a used for t he est imat ion.
As par t of t he validat ion pr ocess, you ca n gr a ph t he r esiduals using
plot(e)
for a simple visual inspect ion of ir r egula r it ies and out lier s. (See also “Dea ling
wit h Dat a ” on page 3-58.)
Noise-Free Simulations
To check whet her a model is capable of r epr oducing t he obser ved out put when
dr iven by t he act ual input , you can r un a simulat ion:
yh = idsim(u,th)
plot([y yh])
The same r esult is obt a ined by
compare([y,u],th)
It is a much t ougher a nd r evealing t est t o per for m t his simulat ion, as well as
t he r esidual t est s, on a fr esh dat a set [y u] t hat was not used for t he est imat ion
of t he model th. This is ca lled cross validat ion. (Not e t hat ivstruc for ms t he
squar ed differ ence of y and yh for IV-comput ed models th.)
Assessing the Model Uncertainty
The est imat ed model is always uncer t ain, due t o dist ur ba nces in t he obser ved
dat a, a nd due t o t he lack of an a bsolut ely cor r ect model st r uct ur e. The
var iabilit y of t he model t hat is due t o t he r andom dist ur bances in t he out put is
est imat ed by most of t he est imat ion pr ocedur es, and it can be displayed and
illuminat ed in a number of ways. This var iabilit y a nswer s t he quest ion of how
differ ent ca n t he model be if I r epeat t he ident ificat ion pr ocedur e, using t he
same model st r uct ur e, but wit h a differ ent dat a set t hat uses t he same input
sequence. It does not account for syst emat ic er r or s due t o an inadequat e choice
of model st r uct ur e. Ther e is no guar ant ee t hat t he “t r ue syst em” lies in t he
confidence int er val.
e t ( ) u t k – ( )
k nk = nk 1 + …nk nb 1 – +
3 Tu to r i a l
3-54
The uncer t aint y in t he fr equency r esponse is calcula t ed wit h
[g,phiv] = th2ff(th)
and can subsequent ly be gr aphed wit h bodeplot. The uncer t aint y in t he t ime
r esponse is displayed by
idsimsd(u,th)
Ten possible models a r e dr awn fr om t he asympt ot ic dist r ibut ion of t he model
th. The r esponse of each of t hem t o t he input u is gr aphed on t he same dia gr a m.
The uncer t aint y of t hese r esponses concer ns t he ext er nal, input -out put
pr oper t ies of t he model. It r eflect s t he effect s of inadequat e excit at ion and t he
pr esence of dist ur bances.
You can also dir ect ly get t he st a ndar d deviat ion of t he simulat ed r esult by
[ysim,ysimsd] = idsim(u,th)
The uncer t aint y in int er nal r epr esent at ions is manifest ed in t he covar iance
mat r ix of t he est imat ed pa r amet er s,
present(th)
and in t he st anda r d deviat ions of t he pole- and zer o-locat ions, which ar e
comput ed wit h
zepo = th2zp(th)
and displayed using zpplot. Lar ge uncer t aint ies in t hese r epr esent a t ions ar e
caused by excessively high model or der s, inadequat e excit at ion, or bad
signal-t o-noise r at ios.
Comparing Different Models
It is a good idea t o display t he model pr oper t ies in t er ms of quant it ies t hat have
mor e physical meaning t han t he pa r amet er s t hemselves. Bode plot s, zer o-pole
plot s, and model simulat ions all give a sense of t he pr oper t ies of t he syst em
t hat have been picked up by t he model.
If sever al models of differ ent char act er s give ver y similar Bode plot s in t he
fr equency r ange of int er est , you can be fa ir ly confident t hat t hese must r eflect
feat ur es of t he t r ue, unknown syst em. You can t hen choose t he simplest model
among t hese.
3-55
A t ypical ident ificat ion session includes est imat ion in sever a l differ ent
st r uct ur es, and compar isons of t he model pr oper t ies. Her e is an example:
a1 = arx(z,[1 1]);
[gs,nss] = spa(z);
[ga1,nsa1] = th2ff(a1);
bodeplot([gs ga1])
bodeplot([nss nsa1])
zpa1 = th2zp(a1);
am2 = armax(z,[2 2 2 1]);
[gam2,nsam2] = th2ff(am2);
bodeplot([gs gam2])
zpam2 = th2zp(am2);
zpplot(zpform(zpa1,zpam2))
Conditioning of the Prediction Error Gradient
When t he model or der s in (3.23) ar e over est imat ed, so t hat a pole-zer o
ca ncellat ion can t ake place in t he model, t he pr edict ion er r or gr adient
t heor et ically becomes r ank deficient . The mat r ix t hat is inver t ed when
est imat ing t he covar iance mat r ix becomes singular , and t he Gauss-Newt on
sear ch dir ect ion becomes ambiguous.
Due t o t he high numer ic pr ecision in MATLAB, you ar e unlikely t o encount er
messages a bout singular and r a nk deficient mat r ices. Inst ead, over est imat ed
model or der s usually show up a s lar ge est ima t ed par amet er var iances and
lar ge nor ms of t he Gauss-Newt on vect or (alt hough only minor decr eases in t he
cr it er ion value r esult ). Consequent ly, t hese ar e good indicat or s t ha t you have
gone t oo far in incr easing t he model or der s. See also “Some Special Topics” on
page 3-68.
Selecting Model Structures for Multivariable
Systems
Mult iva r iable syst ems ar e oft en mor e difficult t o model. Some basic aspect s
and advice wer e given in “The Basic St eps of Syst em Ident ificat ion” on page
1-10. The gr aphical user int er fa ce (GUI) offer s par t icular ly useful suppor t for
t he mult ivar iable case. In t his sect ion we give some mor e t echnical comment s
about t he ident ifica t ion of mult ivar iable syst ems.
3 Tu to r i a l
3-56
The basic comment s given so fa r in t his sect ion also apply t o such syst ems.
Ther e ar e, however , a lar ge number of possible st r uct ur es for syst ems wit h
sever al out put s, and syst emat ic t est s of t he many possibilit ies a r e impr act ical.
This pr oblem is a difficult one, and for a mor e compr ehensive t r eat ment , r efer
t o Appendix 4.A of Ljung (1987).
Fir st of all, physical insight is mor e impor t ant t han anyt hing else. Whenever
t her e is pr ior knowledge sufficient t o for m physically par amet r ized st at e-spa ce
models, you should t est t hat . Even lacking mor e pr ecise knowledge, some
physical insight might help you t o come up wit h fir st suggest ions of or der s and
delays.
For mult i-out put black-box models, it is easiest t o fir st t r y st at e-space models
using n4sid for t he model est imat ion.
Mult ivar ia ble ARX models ar e also easy t o dea l wit h. When building such
models, a simple st ar t -up pr ocedur e is t o t r y arx wit h a st r uct ur e t hat is filled
wit h par a met er s. Then consider t hose est imat es t hat ar e of t he same
magnit ude as t heir st andar d deviat ions, a nd t r y or der s a nd delays t hat
aut omat ically set t hem t o zer o. Not e t hat for arx each r ow is est imat ed
independent ly of t he ot her s. Changing or der s and delays associa t ed wit h
out put number i (i.e. t he i-t h r ow of na, nb, a nd nk) does not cha nge t he
par amet er est imat es associa t ed wit h t he ot her r ows. When a r easonable
st r uct ur e has been found, t r y iv4 wit h it and evaluat e t he models in t he usua l
ways.
If t he signal t o noise level is not good, and it is impor t ant t o have models t hat
descr ibe t he noise char a ct er ist ics, t r y st a t e-space models. (These a r e
equivalent t o mult ivar iable ARMAX models.) Again, it is easier t o est imat e
st at e-space models dir ect ly wit hout specifying t he pa r t icula r st r uct ur e. This is
done using n4sid.
An alt er na t ive is t o apply t he pr edict ion er r or met hod using ca nonical
st at e-space for ms. These ar e obt ained by t he command canstart. This defines
a canonical for m st r uct ur e fr om t he pseudo-obser vabilit y indices. These indices
for m a vect or wit h t he sa me number of ent r ies as t he number of out put s.
Loosely speaking, index number k descr ibes how many delayed va lues of y
k

affect t he cur r ent value of y
k
. The sum of t he indices is equal t o t he or der of t he
3-57
syst em. The number of possible pseudo-obser vabilit y indices for a syst em of
or der n wit h p out put s is
It is, however , r eassur ing t o know t hat almost ever y syst em of or der n can be
descr ibed in a st r uct ur e cor r esponding t o a ny set of pseudo-obser vabilit y
indices whose sum is n. You can est imat e t he or der of t he syst em (or , r at her ,
t r y sever al differ ent or der s) and pick a ny set of pseudo-obser vabilit y indices
cor r esponding t o t hat or der . A default choice of indices can be made by
canstart if only t he or der is specified. Only if t he minimizat ion in pem shows
signs of poor condit ioning of t he involved mat r ices do you need t o t r y ot her
indices.
Not e t hat t he canonical for m par amet r izat ions cannot handle input delays. To
deal wit h specific delays fr om t he input (s), shift t he input sequences
accor dingly.
Also not e t hat wit h fixpar any canonical for m par a met er izat ion can be
t r ansfor med t o a cor r esponding out put -er r or st r uct ur e, by fixing t he mat r ix K
t o zer o.
n
p . ,
| `
3 Tu to r i a l
3-58
9. Dealing w ith Data
Ext r act ing infor ma t ion fr om da t a is not a n ent ir ely st r aight for wa r d t ask. In
addit ion t o t he decisions r equir ed for model st r uct ur e select ion and validat ion,
t he dat a may need t o be ha ndled car efully. This sect ion gives some a dvice on
handling sever a l common sit uat ions.
Offset Levels
When t he dat a have been collect ed fr om a physical plant , t hey ar e t ypically
measur ed in physical unit s. The levels in t hese r aw input s and out put s may not
mat ch in any consist ent way. This will for ce t he models t o wast e some
par amet er s cor r ect ing t he levels.
Offset s a r e easily dealt wit h; always subt r act t he mean levels fr om t he input
and out put sequences befor e t he est imat ion. It is best if t he mean levels
cor r espond t o a physical equilibr ium, but if such values ar e not known, use t he
sa mple means:
z = dtrend(z);
Sect ion 14.6 in Ljung (1987) discusses t his in mor e det a il. Wit h t he dtrend
comma nd, you can also r emove piece-wise linear t r ends.
Outliers
Real dat a ar e also subject t o possible bad dist ur bances; an unusually lar ge
dist ur bance, a t empor a r y sensor or t r ansmit t er failur e, et c. It is impor t ant t ha t
such out lier s ar e not allowed t o affect t he models t oo st r ongly.
The r obust ificat ion of t he er r or cr it er ion (descr ibed under lim in “Opt ional
Var iables” on page 3-26) helps her e, but it is always good pr act ice t o exa mine
t he r esiduals for unusually lar ge values, and t o go back and cr it ically evaluat e
t he or iginal dat a r esponsible for t he la r ge va lues. If t he r aw dat a ar e obviously
in er r or , t hey ca n be smoot hed, and t he est imat ion pr ocedur e r epea t ed.
Filtering Data
Depending upon t he applicat ion, int er est in t he model can be focused on
specific fr equency ba nds. Filt er ing t he da t a befor e t he est ima t ion, t hr ough
filt er s t hat enhance t hese bands, impr oves t he fit in t he int er est ing r egions.
This is used in t he Syst em Ident ificat ion Toolbox funct ion idfilt. For
3-59
example, t o enhance t he dat a in t he fr equency band bet ween 0.02
*
π and
0.1
*
π, execut e
zf = idfilt(z,5,[0.02 0.1]);
This comput es and uses a fift h or der But t er wor t h ba ndpass filt er wit h
passband bet ween t he indicat ed fr equencies. Chapt er 13 in Ljung (1987)
discusses t he r ole of filt er ing in mor e det a il.
The SITB cont ains ot her useful commands for r elat ed pr oblems. For exa mple,
if you want t o lower t he sampling r at e by a fact or of 5, use
z5 = idresamp(z,5);
Feedback in Data
If t he syst em was oper at ing in closed loop (feedback fr om t he past out put s t o
t he cur r ent input ) when t he da t a wer e collect ed, some car e ha s t o be exer cised.
Basically, all t he pr edict ion er r or met hods wor k equally well for closed-loop
dat a. Not e, however , t ha t t he Out put -Er r or model (3.19) and t he Box-J enkins
model (3.21) ar e nor mally capable of giving a cor r ect descr ipt ion of t he
dynamics G, even if H (which equa ls 1 for t he out put er r or model) does not
allow a cor r ect descr ipt ion of t he noise pr oper t ies. This is no longer t r ue for
closed-loop dat a. You t hen need t o model t he noise pr oper t ies car efully.
The spect r al analysis met hod and t he inst r ument a l va r iable t echniques (wit h
defa ult inst r ument s) give unr eliable r esult s when applied t o closed-loop da t a.
These t echniques should be avoided when feedba ck is pr esent .
To det ect if feedback is pr esent , use t he basic met hod of applying cra t o
est imat e t he impulse r esponse. Significant values of t he impulse r esponse a t
negat ive lags is a clea r indicat ion of feedback. When a par amet r ic model ha s
been est imat ed and t he resid command is applied, a gr aph of t he cor r elat ion
bet ween r esidua ls and input s is given. Significant cor r ela t ion at negat ive la gs
aga in indicat es out put feedback in t he gener at ion of t he input . Test ing for
feedba ck is, t her efor e, a nat ur al par t of model va lidat ion.
Delays
The select ion of t he delay nk in t he model st r uct ur e is a ver y impor t ant st ep in
obt aining good ident ificat ion r esult s. You can get an idea about t he delays in
t he syst em by t he impulse r esponse est imat e fr om cra.
3 Tu to r i a l
3-60
Incor r ect delays ar e also visible in par amet r ic models. Under est imat ed delays
(nk t oo small) show up a s small values of leading est imat es, compar ed t o
t heir st andar d deviat ions. Over est imat ed delays (nk t oo lar ge) ar e usually
visible as a significant cor r elat ion bet ween t he r esiduals and t he input a t t he
lags cor r esponding t o t he missing t er ms.
A good pr ocedur e is t o st ar t by using arxstruc t o t est a ll feasible delays
t oget her wit h a second-or der model. Use t he dela y t hat gives t he best fit for
fur t her modeling. When you have found an ot her wise sa t isfact or y st r uct ur e,
va r y nk ar ound t he nomina l value wit hin t he st r uct ur e, and eva luat e t he
r esult s.
b
k
b
k
3-61
10. Recursive Parameter Estimation
In ma ny cases it may be necessar y t o est imat e a model on line a t t he same t ime
as t he input -out put da t a is r eceived. You may need t he model t o make some
decision on line, as in adapt ive cont r ol, adapt ive filt er ing, or adapt ive
pr edict ion. It may be necessar y t o invest igat e possible t ime var iat ion in t he
syst em’s (or signal’s) pr oper t ies dur ing t he collect ion of dat a. Ter ms like
recursive identificat ion, adaptive parameter est imation, sequent ial est imation,
and online algorithms ar e used for such algor it hms. Chapt er 11 in Ljung (1987)
deals wit h such algor it hms in some det ail.
The Basic Algorithm
A t ypical r ecur sive ident ifica t ion algor it hm is
Her e is t he pa r amet er est imat e at t ime t , and is t he obser ved out put
at t ime t . Mor eover , is a pr edict ion of t he value based on obser vat ions
up t o t ime and also based on t he cur r ent model (a nd possibly also ear lier
ones) at t ime . The gain det er mines in what way t he cur r ent
pr edict ion er r or affect s t he upda t e of t he par amet er est imat e. It is
t ypically chosen as
wher e is (an appr oximat ion of) t he gr adient wit h r espect t o of .
The lat t er symbol is t he pr edict ion of accor ding t he model descr ibed by .
Not e t hat model st r uct ur es like AR and ARX t hat cor r espond t o linear
r egr essions can be wr it t en as
wher e t he regression vect or cont ains old values of obser ved input s and
out put s, and r epr esent s t he t r ue descr ipt ion of t he syst em. Mor eover ,
is t he noise sour ce (t he innovat ions). Compar e wit h (3.15). The nat ur al
pr edict ion is and it s gr adient wit h r espect t o becomes
exact ly .
θ
ˆ
t ( ) θ
ˆ
t 1 – ( ) K t ( ) y t ( ) y
ˆ
t ( ) – ( ) + = (10.1)
θ
ˆ
t ( ) y t ( )
y
ˆ
t ( )
y t ( )
t 1 –
t 1 – K t ( )
y t ( ) yˆ t ( ) –
K t ( ) Q t ( )ψ t ( ) = (10.2)
ψ t ( ) θ yˆ t θ ( )
y t ( ) θ
y t ( ) ψ
T
t ( )θ
0
t ( ) e t ( ) + =
(10.3)
ψ t ( )
θ
0
t ( )
e t ( )
yˆ t ( ) ψ
T
t ( )θ t 1 – ( ) = θ
ψ t ( )
3 Tu to r i a l
3-62
For models t hat cannot be wr it t en as linear r egr essions, you cannot r ecur sively
comput e t he exact pr edict ion a nd it s gr adient for t he cur r ent est imat e .
Then appr oximat ions and must be used inst ead. Sect ion 11.4 in
Ljung (1987) descr ibes suit able ways of comput ing such a ppr oximat ions for
gener al model st r uct ur es.
The mat r ix t hat affect s bot h t he adapt at ion gain and t he dir ect ion in
which t he updat es ar e made, can be chosen in sever al differ ent wa ys. This is
discussed in t he following sect ion.
Choosing an Adaptation Mechanism and Gain
The most logical a ppr oach t o t he adapt at ion pr oblem is t o assume a cer t a in
model for how t he “t r ue” par amet er s cha nge. A t ypica l choice is t o descr ibe
t hese par amet er s as a r a ndom walk:
Her e is assumed t o be whit e Gaussian noise wit h covar ia nce mat r ix
θ
ˆ
t 1 – ( )
yˆ t ( ) ψ t ( )
Q t ( )
θ
0
θ
0
t ( ) θ
0
t 1 – ( ) w t ( ) + = (10.4)
w t ( )
Ew t ( )w
T
t ( ) R
1
= (10.5)
3-63
Suppose t hat t he under lying descr ipt ion of t he obser vat ions is a linea r
r egr ession (10.3). An opt ima l choice of in (10.1)-(10.2) can t hen be
comput ed fr om t he Kalman filt er , and t he complet e a lgor it hm becomes
Her e is t he var iance of t he innovat ions in (10.3): (a scalar ).
The algor it hm (10.6) will be called t he Kalman Filt er (KF) Appr oach t o
adapt at ion, wit h drift mat rix . See eq (11.66)-(11.67) in Ljung (1987). The
algor it hm is ent ir ely specified by , , , , and t he sequence of dat a
, , , 2,…. Even t hough t he algor it hm was mot ivat ed for a linear
r egr ession model st r uct ur e, it can also be applied in t he gener al case wher e
is comput ed in a differ ent way fr om (10.6b).
Anot her appr oach is t o discount old measur ement s exponent ially, so t hat a n
obser vat ion t hat is samples old car r ies a weight t ha t is of t he weight of
t he most r ecent obser vat ion. This means t hat t he following funct ion is
minimized r at her t han (3.39):
at t ime t. Her e is clear ly is a posit ive number ≤ 1. The measur ement s t hat
ar e older t han car r y a weight in (10.7) t ha t is less t han about 0.3.
Think of a s t he memory horizon of t he a ppr oach. Typica l values
of ar e in t he r ange 0.97– 0.995.
Q t ( )
θ
ˆ
t ( ) θ
ˆ
t 1 – ( ) K t ( ) y t ( ) yˆ t ( ) – ( ) + =
yˆ t ( ) ψ
T
t ( )θ
ˆ
t 1 – ( ) =
K t ( ) Q t ( )ψ t ( ) =
Q t ( )
P t 1 – ( )
R
2
ψ t ( )
T
P t 1 – ( )ψ t ( ) +
--------------------------------------------------------- =
P t ( ) P t 1 – ( ) R
1
P t 1 – ( )ψ t ( )ψ t ( )
T
P t 1 – ( )
R
2
ψ t ( )
T
P t 1 – ( )ψ t ( ) +
----------------------------------------------------------------- – + =
(10.6a)
(10.6b)
(10.6c)
(10.6d)
(10.6e)
R
2
e t ( ) R
2
Ee
2
t ( ) =
R
1
R
1
R
2
P 0 ( ) θ 0 ( )
y t ( ) ψ t ( ) t 1 =
yˆ t ( )
τ λ
τ
λ
t k –
e
2
k ( )
k 1 =
t

(10.7
λ
τ 1 1 λ – ( ) ⁄ =
τ 1 1 λ – ( ) ⁄ =
λ
3 Tu to r i a l
3-64
The cr it er ion (10.7) can be minimized exact ly in t he linear r egr ession case
giving t he algor it hm (10.6abc) wit h t he following choice of :
This algor it hm will be called t he For get t ing Fact or (FF) Appr oach t o
adapt a t ion, wit h t he forget ting fact or . See eq (11.63) in Ljung (1987). The
algor it hm is also known as RLS, recursive least squares in t he linear r egr ession
case. Not e t hat in t his appr oach gives t he same algor it hm as
in t he Ka lman filt er appr oach.
A t hir d appr oach is t o allow t he mat r ix t o be a mult iple of t he ident it y
mat r ix:
It ca n also be nor malized wit h r espect t o t he size of :
See eqs (11.45) a nd (11.46), r espect ively in Ljung (1987). These choices of
move t he upda t es of in (10.1) in t he nega t ive gr adient dir ect ion (wit h r espect
t o ) of t he cr it er ion (3.39). Ther efor e, (10.9) will be called t he Unnor malized
Gr adient (UG) Appr oach and (10.10) t he Nor malized Gr adient (NG) Appr oach
t o a da pt at ion, wit h gain . The gr a dient met hods ar e also known as LMS, least
mean squares in t he linear r egr ession case.
Q t ( )
Q t ( ) P t ( )
P t 1 – ( )
λ ψ t ( )
T
P t 1 – ( )ψ t ( ) +
------------------------------------------------------ = =
P t ( )
P t 1 – ( )
P t 1 – ( )ψ t ( )ψ t ( )
T
P t 1 – ( )
λ ψ t ( )
T
P t 1 – ( )ψ t ( ) +
---------------------------------------------------------------- - –
. ,

| `
= λ ⁄
(10.8a)
(10.8b)
λ
λ 1 =
R
1
0 R
2
, 1 = =
Q t ( )
Q t ( ) ϒI =
(10.9)
ψ
Q t ( )
ϒ
ψ t ( )
2
----------------I =
(10.10)
Q t ( )
θ
ˆ
θ
ϒ
3-65
Available Algorithms
The Syst em Ident ificat ion Toolbox pr ovides t he following funct ions t hat
implement all common r ecur sive ident ifica t ion algor it hms for model st r uct ur es
in t he family (6.1): rarmax, rarx, rbj, rpem, rplr, and roe. They all shar e t he
following basic synt ax:
[thm,yh] = rfcn(z,nn,adm,adg)
Her e z cont a ins t he out put -input da t a as usual. nn specifies t he model
st r uct ur e, exact ly as for t he cor r esponding offline a lgor it hm. The ar gument s
adm a nd adg select t he adapt at ion mechanism and adapt at ion gain list ed above.
adm = 'ff'; adg = lam
gives t he for get t ing fact or algor it hm (10.8), wit h for get t ing fa ct or lam.
adm = 'ug'; adg = gam
gives t he unnor malized gr adient appr oach (10.9) wit h gain gam. Similar ly,
adm = 'ng'; adg = gam
gives t he nor malized gain appr oach (10.10). To obt ain t he Kalman filt er
appr oach (10.6) wit h dr ift mat r ix R1 ent er
adm = 'kf'; adg = R1
The value of is a lways 1. Not e t hat t he est imat es in (10.6) ar e not affect ed
if a ll t he ma t r ices and ar e sca led by t he same number . You can
t her efor e always scale t he or iginal pr oblem so t hat becomes 1.
The out put ar gument thm is a mat r ix t hat cont ains t he cur r ent models at t he
differ ent samples. Row k of thm cont ains t he model par amet er s, in alphabet ical
or der at sample t ime k, cor r esponding t o r ow k in t he dat a mat r ix z. The
or der ing of t he par amet er s is t he sa me as th2par would give when applied t o
t he t het a for mat of a cor r esponding offline model.
The out put ar gument yh is a column vect or t hat cont ains, in r ow k, t he
pr edict ed va lue of , based on past obser va t ions and cur r ent model. The
vect or yh t hus cont ains t he adapt ive pr edict ions of t he out put s, and is useful
also for noise cancelling and ot her adapt ive filt er ing applicat ions.
The funct ions also have opt ional input ar gument s t hat allow t he specificat ion
of , and . Opt ional out put ar gument s include t he last value of
t he mat r ix P and of t he vect or .
R
2
θ
ˆ
R
1
R
2
, P 0 ( )
R
2
y k ( )
θ 0 ( ) P 0 ( ) , ψ 0 ( )
ψ
3 Tu to r i a l
3-66
Now, rarx is a r ecur sive var iant of arx; similar ly rarmax is t he r ecur sive
count er par t of armax and so on. Not e, t hough t hat rarx does not ha ndle
mult i-out put syst ems, and rpem does not handle st at e-spa ce st r uct ur es.
The funct ion rplr is a var iant of rpem, and uses a differ ent appr oximat ion of
t he gr adient . It is known as t he recursive pseudo-linear regression approach,
and cont ains some well known special cases. See equat ion (11.57) in Ljung
(1987). When applied t o t he out put er r or model (nn=[0 nb 0 0 nf nk]) it
r esult s in met hods known as HARF ('ff'–case) and SHARF ('ng'–case). The
common extended least squares (ELS) met hod is a n rplr algor it hm for t he
ARMAX model (nn=[na nb nc 0 0 nk]).
The following example shows a second or der out put er r or model, which is built
r ecur sively and it s t ime var ying par amet er est ima t es plot t ed as funct ions of
t ime:
thm = roe(z,[2 2 1],'ff',0.98);
plot(thm)
A second or der ARMAX model is r ecur sively est imat ed by t he ELS met hod,
using Kalman filt er a da pt at ion. The r esult ing st at ic gains of t he est ima t ed
models ar e t hen plot t ed as a funct ion of t ime:
[N,dum]=size(z);
thm = rplr(z,[2 2 2 0 0 1],'kf',0.01∗eye(6));
nums = sum(thm(:,3:4)')';
dens = ones(N,1)+sum(thm(:,1:2)')';
stg = nums./dens;
plot(stg)
So far , t he examples of applicat ions wher e a bat ch of dat a is examined cover
st udies of t he va r iabilit y of t he syst em. The algor it hms ar e, however , also
pr epar ed for t r ue online applicat ions, wher e t he comput ed model is used for
some online decision. This is accomplished by st or ing t he updat e infor mat ion
in and infor mat ion about past da t a in (and )
and using t hat infor mat ion a s init ial dat a for t he next t ime st ep. The following
example shows t he r ecur sive least -squar es algor it hm being used on line (just
t o plot one cur r ent par amet er est imat e):
%Initialization, first i/o pair y,u (scalars)
[th,yh,P,phi] = rarx([y u],[2 2 1],'ff',0.98);
axis([1 50 –2 2])
plot(1,th(1),'∗'),hold
ψ
θ t 1 – ( ) P t 1 – ( ) , φ t 1 – ( ) ψ t 1 – ( )
3-67
%The online loop:
for k = 2:50
% At time k receive y,u
[th,yh,P,phi] = ...
rarx([y u],[2 2 1],'ff',0.98,th',P,phi);
plot(k,th(1),'∗')
end
Execut ing iddemo 6 illust r a t es t he r ecur sive a lgor it hms.
Segmentation of Data
Somet imes t he syst em or signal exhibit s abr upt changes dur ing t he t ime when
t he dat a is collect ed. It may be impor t ant in cer t ain applicat ions t o find t he
t ime inst ant s when t he changes occur and t o develop models for t he differ ent
segment s dur ing which t he syst em does not change. This is t he segment ation
problem. Fault det ect ion in syst ems a nd det ect ion of t r end br eaks in t ime
ser ies can ser ve as t wo examples of t ypical pr oblems.
The Syst em Ident ificat ion Toolbox offer s t he funct ion segment t o deal wit h t he
segment at ion pr oblem. The ba sic synt ax is
thm = segment(z,nn)
wit h a for mat like rarx or rarmax. The mat r ix thm cont ains t he piecewise
const ant models in t he same for mat as for t he algor it hms descr ibed ear lier in
t his sect ion.
The algor it hm t hat is implement ed in segment is based on a model descr ipt ion
like (10.4), wher e t he change t er m is zer o most of t he t ime, but now and
t hen it a br upt ly changes t he syst em par amet er s . Sever a l Kalman filt er s
t hat est imat e t hese par amet er s ar e r un in pa r allel, each of t hem cor r esponding
t o a par t icular a ssumpt ion about when t he syst em act ually changed. The
r elat ive r eliabilit y of t hese assumed syst em behavior s is const ant ly judged, a nd
unlikely hypot heses ar e r eplaced by new ones. Opt ional a r gument s allow t he
specificat ion of t he measur ement noise var iance in (10.3), of t he pr oba bilit y
of a jump, of t he number of par a llel models in use, and also of t he gua r ant eed
lifespan of each hypot hesis. See iddemo 7 in Chapt er 4, "Command Refer ence"
also.
w t ( )
θ
0
t ( )
R
2
3 Tu to r i a l
3-68
11. Some Special Topics
This sect ion descr ibes a number of miscellaneous t opics. Most of t he
infor mat ion her e is a lso cover ed in ot her par t s of t he manual, but since
manuals seldom ar e r ea d fr om t he beginning, you can also check if a par t icular
t opic is br ought up her e.
Time Series Modeling
When t her e is no input pr esent , t he gener al model (6.1) r educes t o t he ARMA
model st r uct ur e:
Wit h you have an AR model st r uct ur e.
Basically all commands st ill apply t o t hese t ime ser ies models, but wit h na t ur al
modifica t ions. They ar e list ed as follows:
th = poly2th(A,[],C,1,[],lam)
y = idsim(e,th)
Spect r al analysis (etfe and spa) a nd t he th2ff funct ion now r et ur n t he
spect r al est imat e of y as t heir fir st out put ar gument s:
PHIY = th2ff(th)
PHIY = spa(y)
PERIOD = etfe(y)
Not e t hat etfe gives t he periodogram est imat e of t he spect r um.
armax a nd arx wor k t he same way, but need no specificat ion of nb and nk:
th = arx(y,na)
th = armax(y,[na nc])
Not e t hat arx also handles mult ivar iat e signals. St at e-spa ce models of t ime
ser ies can be built simply by specifying B = [], D = [] in modstruc, mf2th, and
ms2th. resid wor ks t he same wa y for t ime ser ies models, but does not pr ovide
any input -r esidual cor r elat ion plot s:
e = resid(y,th)
A q ( )y t ( ) C q ( )e t ( ) =
(11.1)
C q ( ) 1 =
3-69
In addit ion t her e a r e t wo commands t hat ar e specifically const r uct ed for
building scalar AR models of t ime ser ies. One is
th = ar(y,na)
which has an opt ion t hat a llows you t o choose t he algor it hm fr om a gr oup of
sever al popular t echniques for comput ing t he least -squar es AR model. Among
t hese ar e Bur g’s met hod, a geomet r ic lat t ice met hod, t he Yule-Walker
appr oach, a nd a modified covar iance met hod. See Chapt er 4, "Command
Refer ence" for det ails. The ot her command is
th = ivar(y,na)
which uses an inst r ument a l var ia bles t echnique t o comput e t he AR par t of a
t ime ser ies.
Finally, when no input is pr esent , t he funct ions bj, iv, iv4, a nd oe ar e not
defined.
Her e is an example wher e you ca n simulat e a t ime ser ies, compar e spect r al
est imat es a nd covar iance funct ion est imat es, and also t he pr edict ions of t he
model.
ts0 = poly2th([1 –1.5 0.7],[]);
% The true spectrum:
spe0 = th2ff(ts0);
ir = idsim([1;zeros(24,1)],ts0);
% The true covariance function:
Ry0 = conv(ir,ir(25:–1:1));
e = randn(200,1);
y = idsim(e,ts0);
plot(y)
per = etfe(y);
speh = spa(y);
ffplot([per,speh,spe0])
% A second order AR model:
ts2 = ar(y,2);
sp2 = th2ff(ts2);
ffplot([speh,sp2,spe0,3])
% The covariance function estimates:
Ryh = covf(y,24);
ir2 = idsim([1;zeros(24,1)],ts2);
Ry2 = conv(ir2,ir2(25:–1:1));
3 Tu to r i a l
3-70
plot([–24:24]∗ones(1,3),[Ryh,Ry2,Ry0])
% The prediction ability of the model:
compare(y,th2,5)
The Sampling Interval
The Syst em Ident ificat ion Toolbox assumes a nor malized sampling int er val of
, unless you specify ot her wise. This means t hat t he fr equency unit
becomes “r adians per sampling int er val,” and t hat all t he t r ansfor mat ions
bet ween cont inuous- and discr et e-t ime models give numer ical par amet er
va lues cor r esponding t o t he unit “... per sampling int er val” r a t her t han “... per
second.” To obt ain cor r ect physical unit s in t hese cases, t he sampling int er val
must be specified accor dingly.
All models in t he t het a for ma t cont ain t he sampling int er val T as t he (1,2)
element . It can be r ead by
T = gett(th)
and it is changed by
thnew = sett(thold,T)
Not e t hat t he va lue of T is just changed; no t r ansfor mat ion of par amet er s is
car r ied out by sett.
A nega t ive value of T indicat es t hat t he cor r esponding model is given in
cont inuous t ime. The absolut e value of T denot es, in t hat case, t he sampling
int er val of t he dat a, for which t his model was est imat ed. This is also t he
sa mpling int er val used when t he model is used for simulat ion or pr edict ion. All
ot her t r ansfor mat ions (t o t he fr equency funct ion, t o poles a nd zer os, t o t r a nsfer
funct ions and t o st at e-space mat r ices) will be in t er ms of t he cont inuous-t ime
model. In t he ca se of th2ff, abs(T) is used for t he default choice of fr equency
r ange.
You can specify t he sampling int er val as an opt ional ar gument in all t he
funct ions t ha t cr eat e t het a st r uct ur es. It is gener ally t he last ar gument . Not e
t hat in ms2th and mf2th, it is t he sampling int er va l of t he dat a t hat you need
t o specify, even if t he model it self in par amet r ized in cont inuous t ime. If t he
init ial st r uct ur e in pem, armax, bj, a nd oe is given by a mat r ix th in t he t het a
for mat , t he defa ult value of T is t he one given by th. An explicit ly given
sa mpling int er val (as an a r gument t o pem, for example) over r ides t he default
va lue in th.
T 1 =
3-71
The sampling int er val T is also used by etfe, spa, and th2ff t o det er mine
defa ult fr equency r anges. For discr et e-t ime syst ems, t his default is [1:128]/
128
*
pi/T and for cont inuous-t ime syst ems, it is
logspa ce(log10(pi/abs(T)/100),log10(10
*
pi/abs(T)),128).
Discr et e-t ime default fr equency r anges can be changed by sett, like in
g = spa(z);
g = sett(g,T);
Out of Memory
If you r un out of memor y on comput er s wit h memor y limit at ions, clear
unnecessar y var iables and use t he pack funct ion. When you ar e using t he
it er at ive pr ocedur es armax, bj, oe, and pem, it is a good idea t o use pack t o
clean up a ft er t he st ar t -up est imat ion pr ocedur e using, for example
th = armax(z,nn,0);
pack
th = armax(z,th);
All t he r eleva nt Syst em Ident ificat ion Toolbox funct ions have an opt ional
var iable MAXSIZE t hat cont r ols t he memor y/speed t r ade-off and is set
aut omat ica lly, ba sed upon t he best values for t he machine you ar e using. The
r out ines do not a llow any mat r ix of size lar ger t han MAXSIZE t o for m. Inst ead
t hey go int o for -loops t o handle t he sit uat ion.
The default value of MAXSIZE is set in t he M-file idmsize. Theor et ica lly,
MAXSIZE is 8188 on t he smaller machines, but since ma ny mat r ices may for m,
it best t o set t he default value for t hese machines t o MAXSIZE = 4096.
If you have memor y pr oblems, you ca n use t he ar gument MAXSIZE, or edit
idmsize, wit h values lower t han t he default .
If you ha ve a lar ge amount of input -out put dat a, so t hat t he memor y delimit er
gives you a slower r esponse, use a por t ion of t he dat a t o calculat e a good init ia l
condit ion for t he minimizat ion, for exa mple
th = armax(z(1:500,:),[na nb nc],10,0.1);
th = armax(z,th);
3 Tu to r i a l
3-72
On a small machine, if you ha ve collect ed mor e t han 8188 da t a point s so t hat
you cannot for m z=[y u], no memor y help is offer ed. You t hen have t o build
separ at e models for separ at e par t s of t he dat a and r econcile t he models.
Memory-Speed Trade-Offs
On machines wit h no for mal memor y limit at ions, it is st ill of int er est t o
monit or t he sizes of t he mat r ices t hat ar e for med. The t ypical sit uat ion is when
an over det er mined set of linear equat ions is solved for t he lea st -squar es
solut ion. The solut ion t ime depends, of cour se, on t he dimensions of t he
cor r esponding mat r ix. The number of r ows cor r esponds t o t he number of
obser ved dat a, while t he number of columns cor r esponds t o t he number of
est imat ed par amet er s. The a r gument MAXSIZE used wit h all t he r elevant
M-files, guar ant ees t hat no mat r ix wit h mor e t han MAXSIZE element s is for med.
Lar ger dat a set s and/or higher or der models ar e handled by for -loops. For -loops
give linear incr ea se in t ime when t he dat a r ecor d is incr eased, plus some
over head (a nd somewhat wor se numer ica l pr oper t ies).
If you r egular ly wor k wit h lar ge dat a set s and/or high or der models, it is
advisable t o t ailor t he memor y and speed t r ade-off t o your machine by choosing
t he default value of MAXSIZE in t he M-file idmsize car efully. Not e t hat t his
va lue is allowed t o depend on t he number of r ows a nd columns of t he mat r ices
for med.
Regularization
The Gauss-Newt on dir ect ion is usually defined as
wher e is t he gr adient ma t r ix of t he pr edict ions wit h r espect t o t he
par amet er s, and e is t he vect or of r esiduals.
When t he inver t ed mat r ix is ill-condit ioned, you can add a sma ll fr act ion of t he
ident it y mat r ix t o it . This is called regularizat ion. See Ljung (1987), Sect ion
10.2.
The r out ines in t he Syst em Ident ificat ion Toolbox comput e t he Gauss-Newt on
dir ect ion wit h
g=psi\e
gn Ψ

Ψ ( )
1 –
= *
* Ψ′
*e
Ψ N n ×
N 1 ×
3-73
which uses t he MATLAB mechanism for dealing wit h under det er mined,
over det er mined syst ems of equat ions. An adva nced ver sion of r egular izat ion is
t hus aut oma t ica lly included.
Because of t he high pr ecision of MATLAB, r egular izat ion is not invoked easily.
You may see some ver y lar ge norm of gn–vector values befor e you see t he
MATLAB message t hat t he mat r ix is r ank deficient .
A lar ge va lue for t he gn–vector suggest s t hat you decr ease t he model or der s.
However , if you ar e int er est ed in how t he r egular iza t ion wor ks, you can
decr ea se t he value of t he machine epsilon. For example, set
eps = 0.000001
and r un t he ident ificat ion a gain.
Local Minima
The it er at ive sear ch pr ocedur es in pem, armax, oe, and bj lead t o t het a values
cor r esponding t o a local minimum of t he cr it er ion funct ion (3.39). Not hing
guar ant ees t hat t his local minimum is also a global minimum. The st ar t -up
pr ocedur e for black-box models in t hese r out ines is, however , r easonably
efficient in giving init ial est imat es t hat lead t o t he global minimum.
If t her e is an indicat ion t hat a minimum is not as good as you expect ed, t r y
st a r t ing t he minimizat ion at sever al differ ent init ial condit ions, t o see if a
smaller value of t he loss funct ion can be found.
Initial Parameter Values
When only or der s and delays ar e specified, t he funct ions armax, bj, oe, a nd pem
use a st ar t -up pr ocedur e t o pr oduce init ial values. The st ar t -up pr ocedur e goes
t hr ough t wo t o four lea st squar es and inst r ument a l var ia bles st eps. It is
r easonably efficient in t ha t it usua lly saves sever al it er a t ions in t he
minimizat ion pha se. Somet imes it may, however , pay t o use ot her init ial
condit ions. For example, you ca n use an iv4 est imat e comput ed ear lier as an
init ial condit ion for est imat ing an out put -er r or model of t he sa me st r uct ur e:
th1 = iv4(z,[na nb nk]);
[a,b] = th2poly(th1);
th2 = poly2th(1,b,1,1,a);
th3 = oe(z,th2);
3 Tu to r i a l
3-74
Anot her example is when you want t o t r y a model wit h one mor e delay (for
example, t hr ee inst ead of t wo) because t he leading b-coefficient is quit e small:
th1 = armax(z,[3 3 2 2]);
[a,b,c] = th2poly(th1);
b(3) = 0;
th2 = poly2th(a,b,c);
th3 = armax(z,th2);
If you decr ease t he number of delays, r emember t hat poly2th st r ips away
leading zer os. Suppose you go fr om t hr ee t o t wo delays in t he a bove exa mple:
th1 = armax(z,[3 3 2 3]);
[a,b,c] = th2poly(th1);
b(3) = 0.00001;
th2 = poly2th(a,b,c);
th3 = armax(z,th2);
Not e t hat when const r uct ing home-made init ial condit ions, t he condit ions
must cor r espond t o a st able pr edict or (C and F being Hur wit z polynomials),
and t hat t hey should not cont ain any exact pole-zer o cancellat ions.
For st at e-space and mult i-out put models, you must pr ovide t he init ia l
par amet er values eit her when defining t he st r uct ur e in ms2th or mf2th, or wit h
t he special init ializat ion funct ion thinit. The basic appr oach is t o use physical
insight t o choose init ial values of t he pa r amet er s wit h physical significa nce,
and t r y some differ ent (r andomized) init ial values for t he ot her s. For models
par amet r ized in ca nonical st at e-spa ce for m, use canstart t o get st ar t ed.
Linear Regression Models
A linear r egr ession model is of t he t ype
wher e and ar e measur ed var iables and r epr esent s noise. Such
models ar e ver y useful in most applicat ions. They allow, for example, t he
inclusion of nonlinea r effect s in a simple way. The Syst em Ident ifica t ion
Toolbox funct ion arx allows an ar bit r a r y number of input s. You ca n t her efor e
handle ar bit r ar y linear r egr ession models wit h arx. For example, if you want
t o build a model of t he t ype
y t ( ) θ
T
ϕ t ( ) e t ( ) + =
(11.2)
y t ( ) ϕ t ( ) e t ( )
3-75
ca ll
z = [y ones(u) u u.^2 u.^3];
th = arx(z,[0 1 1 1 1 0 0 0 0])
This is for mally a model wit h one out put and four input s, but all t he model
t est ing in t er ms of compare, idsim, and resid oper at e in t he nat ur al way for
t he model (11.2), once t he dat a mat r ix z is defined as above.
Not e t hat when pem is applied t o linear r egr ession st r uct ur es, by default a
r obust ified quadr at ic cr it er ion is used. The sear ch for a minimum of t he
cr it er ion funct ion is car r ied out by it er at ive sear ch. Nor mally, use t his
r obust ified cr it er ion. If you insist on a quadr at ic cr it er ion, t hen set t he
ar gument lim in pem t o zer o. Then pem also conver ges in one st ep.
Spectrum Normalization and the Sampling Interval
In t he funct ion spa t he spect r um est imat e is nor malized wit h t he sampling
int er val T as
wher e
(See also (3.3)). The nor malizat ion in etfe is consist ent wit h (11.4). This
nor malizat ion means t ha t t he unit of is “power per r a dians/t ime unit ”
and t hat t he fr equency scale is “r adians/t ime unit .” You t hen have
y t ( ) b
0
b
1
u t ( ) b
2
u
2
t ( ) b
3
u
3
t ( ) + + + = (11.3)
Φ
y
ω ( ) T R
ˆ
y
k M – =
M

= kT ( )e
i ωT –
W
M
k ( )
(11.4)
R
ˆ
y kT ( )
1
N
--- - y lT kT – ( )y lT ( )
l 1 =
N

=
Φ
y
ω ( )
Ey
2
t ( )
1

------ Φ
y
w ( ) w d
π T ⁄ –
π T ⁄

=
(11.5)
3 Tu to r i a l
3-76
In MATLAB language, t her efor e, you have wher e
sp = spa(y); sp = sett(sp,T);
[om,PHIY] = getff(sp);
S1 = sum(PHIY)/length(PHIY)/T;
S2 = sum(y.^2)/length(y);
Not e t hat PHIY cont ains bet ween and wit h a fr equency
st ep of π / T / (length(PHIY)). The sum S 1 is, t her efor e, t he r ect a ngular
appr oximat ion of t he int egr al in (11.5). The spect r um nor malizat ion differ s
fr om t he one used by spectrum in t he Signal Pr ocessing Toolbox, and t he above
example shows t he nat ur e of t he differ ence.
The nor malizat ion wit h T in (11.4) also gives consist ent r esult s when t ime
ser ies ar e decimat ed. If t he ener gy a bove t he Nyquist fr equency is r emoved
befor e decimat ion (as is done in idresamp), t he spect r al est imat es coincide;
ot her wise you see folding effect s.
Tr y t he following sequence of commands:
th0 = poly2th(1,[],[1 1 1 1]);
% 4th order MA–process
y = idsim(randn(2000,1),th0);
g1 = spa(y);
g2 = spa(y(1:4:2000));g2 = sett(g2,4);
ffplot([g1 g2]) % Folding effects
g3 = spa(idresamp(y,4)); % Prefilter applied
g3 = sett(g3,4);
ffplot([g1 g3]) % No folding
For a pa r amet r ic noise (t ime ser ies) model
t he spect r um is comput ed as
which is consist ent wit h (11.4) and (11.5). Think of as t he spect r al densit y
of t he whit e noise sour ce .
When a par amet r ic noise model is t r a nsfor med bet ween cont inuous t ime and
discr et e t ime and/or r esampled at anot her sampling r at e, t he funct ions
S1 S2 ≈
Φ
y
ω ( ) ω 0 = ω π T ⁄ =
y t ( ) H q ( )e t ( ) =
Ee
2
t ( ) λ =
Φy w ( ) λ T H e
i wt
( )
2
⋅ ⋅ =
(11.6)
λT
e t ( )
3-77
thc2thd and thd2thc in t he Syst em Ident ificat ion Toolbox use for mulas t hat
ar e for mally cor r ect only for piecewise const ant input s. (See (3.32)). This
appr oximat ion is good when T is small compar ed t o t he bandwidt h of t he noise.
Dur ing t hese t r ansfor mat ions t he var ia nce of t he innova t ions is
changed so t ha t t he spect r al densit y T
.
r emains const ant . This has t wo
effect s:
• The spect r um scalings ar e consist ent , so t hat t he noise spect r um is
essent ia lly invar ia nt (up t o t he Nyquist fr equency) wit h r espect t o
r esampling.
• Simula t ions wit h noise using idsim has a higher noise level when per for med
a t fast er sampling.
This lat t er effect is well in line wit h t he st andar d descr ipt ion t hat t he
under lying cont inuous-t ime model is subject t o cont inuous-t ime whit e noise
dist ur ba nces (which have infinit e, inst ant aneous var iance), and appr opr iat e
low-pass filt er ing is applied befor e sampling t he measur ement s. If t his effect is
unwant ed in a par t icular applicat ion, scale t he noise sour ce a ppr opr iat ely
befor e a pplying idsim.
Not e t he following caut ions r elat ing t o t hese t r ansfor mat ions of noise models.
Cont inuous-t ime noise models must have a whit e noise component . Ot her wise
t he under lying st at e-space model, which is for med and used in thc2thd and
thd2thc, is ill-defined. War nings about t his ar e issued by poly2th and t hese
funct ions. Modify t he C-polynomial accor dingly. Make t he degr ee of t he monic
C-polynomia l in cont inuous t ime equal t o t he sum of t he degr ees of t he monic
A- and D-polynomials; i.e., in cont inuous t ime
length(C)–1 = (length(A)–1)+(length(D)–1).
Interpretation of the Loss Function
The value of t he quadr a t ic loss funct ion is given as element 1,1 in t he t het a
for mat , and a lso displayed by present. For mult i-out put syst ems, t his is equal
t o t he det er mina nt of t he est ima t ed covar iance mat r ix of t he innovat ions.
For most models t he est imat ed covar iance ma t r ix of t he innovat ions is obt ained
by for ming t he cor r esponding sample mean of t he pr edict ion er r or s, comput ed
(using pe) fr om t he model wit h t he dat a for which t he model was est imat ed.
λ e t ( )
λ
3 Tu to r i a l
3-78
Not e t he discr epancy bet ween t his value and t he va lues shown dur ing t he
minimizat ion pr ocedur e (in pem, armax, bj, or oe, since t hese ar e t he values of
t he robustified loss funct ion (see under lim in Sect ion 5).
Be car eful when compa r ing loss funct ion values bet ween differ ent st r uct ur es
t hat use ver y differ ent noise models. An Out put -Er r or model ma y have a bet t er
input -out put fit , even t hough it displays a higher value of t he loss funct ion
t han, say, a n ARX model.
Not e t hat for ARX models comput ed using iv4, t he covar iance mat r ix of t he
innovat ions is est ima t ed using t he pr ovisional noise model t hat is used t o for m
t he opt imal inst r ument s. The loss funct ion t her efor e differ s fr om what would
be obt ained if you comput ed t he pr edict ion er r or s using t he model dir ect ly fr om
t he dat a . It is st ill t he best available est imat e of t he innovat ions covar iance. In
par t icular , it is difficult t o compar e t he loss funct ion in an ARX model
est imat ed using arx and one est imat ed using iv4.
Enumeration of Estimated Parameters
In some ca ses t he par amet er s of a model ar e given just as an or der ed list . This
is t he case for th2par, and also when online infor mat ion fr om t he minimizat ion
r out ines ar e given. Fur t her mor e, in ms2th, you ar e asked t o give a list of
nominal/init ial par amet er values. In t hese cases it is impor t ant t o know in
what or der t he par amet er ar e list ed. The basic t hr ee cases ar e as follows:
• For t he input -out put model (3.23) or it s mult i-input var iant (5.2), you have
t he following a lphabet ical or der ing
Her e super scr ipt r efer s t o t he input number .
• For a st at e-space st r uct ur e, defined by ms2th, t he par amet er s in pars ar e
obt ained in t he following or der . The A mat r ix is fir st scanned r ow by r ow for
fr ee par amet er s. Then t he B mat r ix is scanned r ow by r ow, a nd so on for t he
C, D, K, and X0 mat r ices. (See ms2th in t he Command Reference chapt er .)
• For a st at e-space mat r ix t ha t is defined by mf2th, t he or der ing of t he
par amet er s is t he same as in t he user -wr it t en M-file.
b
1
nu
… b
nbnu
nu
c
1
… c
nc
d
1
… d
nc
, , , , , , , , ,
pars a
1
… a
na
b
1
1
… b ,
nb1
1
b
1
2
…b
nb2
2
… , , , , , , , [ =
f
1
1
…f
nf 1
1
… f ,
1
nu
… f
nf nu
nu
] , , , ,
3-79
Mult iva r iat e ARX models ar e int er nally r epr esent ed in st at e-space for m. The
par a met er or der ing follows t he one descr ibed above. The or der ing of t he
par a met er s may, however , not be t r anspar ent so it is bet t er t o use th2arx and
arx2th inst ead of th2par and ms2th.
Complex-Valued Data
Some a pplicat ions of syst em ident ificat ion wor k wit h complex valued dat a, and
t hus cr eat e complex-valued models. Most of t he r out ines in t he SITB suppor t
complex dat a and models. This is t r ue for t he est imat ion r out ines ar, armax,
arx, bj, covf, ivar, iv4, oe, pem, and spa, but (cur r ent ly) not for canstart and
n4sid. The t r ansfor mat ion r out ines, like th2ff, th2zp, et c. also wor k for
complex-valued models, but no pole-zer o confidence r egions ar e given. Not e
also t ha t t he pa r amet er va r iance-covar ia nce infor mat ion t hen r efer s t o t he
complex va lued par amet er s, so no sepa r at e infor mat ion about t he accur a cy of
t he r eal a nd ima gina r y par t s will be given. Some display funct ions like compare
and
idplot do not wor k for t he complex ca se. Use idsim and plot r eal and
imaginar y par t s separ at ely.
Strange Results
St r ange r esult s ca n of cour se be obt ained in any number of ways. We only point
out t wo ca ut ions: It is t empt ing in ident ificat ion applicat ions t o call t he
r esiduals “eps.” Don’t do t hat . This cha nges t he machine , which cer t ainly
will give you st r ange r esult s.
It is also nat ur a l t o use names like step, phase, et c., for cer t ain var ia bles. Not e
t hough t ha t t hese var iables t ake pr ecedence over M-files wit h t he same name
so be sur e you don’t use var iable names t ha t a lso ar e names of M-files.
ε
3 Tu to r i a l
3-80

4
Command Refer ence
4 C o m m a n d Re f e r e n c e
4-2
This chapt er cont ains det ailed descr ipt ions of all of t he funct ions in t he Syst em
Ident ificat ion Toolbox. It begins wit h a list of funct ions gr ouped by subject a r ea
and cont inues wit h t he ent r ies in alphabet ical or der . Infor mat ion is also
available t hr ough t he online Help facilit y.
By t yping a funct ion name wit hout ar gument s, you also get immediat e synt ax
help about it s ar gument s.
For ease of use, most funct ions ha ve sever al default ar gument s. The Synopsis
fir st list s t he funct ion wit h t he necessar y input ar gument s and t hen wit h all
t he possible input ar gument s. The funct ions can be used wit h any number of
ar gument s bet ween t hese ext r emes. The r ule is t hat missing, t r a iling
ar gument s ar e given default values, as defined in t he manual. Defa ult values
ar e also obt ained by ent er ing t he ar gument s as t he empt y mat r ix [ ].
MATLAB does not r equir e t hat you specify all of t he out put ar gument s; t hose
not specified ar e not r et ur ned. For funct ions wit h sever a l out put ar gument s in
t he Syst em Ident ificat ion Toolbox, missing ar gument s ar e, as a r ule, not
comput ed, in or der t o save t ime.
The Graphi cal Use r Int e rface
ident Open t he int er face.
midprefs Set dir ect or y wher e t o st or e st ar t -up infor mat ion.
Si mulati on and Pre di ct i on
idinput Gener at e input signa ls.
idsim Simulat e a gener al linear syst em.
pe Comput e pr edict ion er r or s.
poly2th Cr eat e a model st r uct ur e for input -out put models
defined as numer at or and denomina t or polynomials.
predict Comput e pr edict ions accor ding t o model.
4-3
Data Mani pul at i on
dtrend Remove t r ends fr om da t a.
idfilt Filt er dat a.
idresamp Resample dat a.
Nonparame tri c Es t i mati on
covf Est imat e covar ia nce funct ion.
cra Est imat e impulse r esponse and covar iance funct ions
using cor r elat ion a nalysis.
etfe Est imat e spect r a and t r ansfer funct ions using dir ect
Four ier t echniques.
spa Est imat e spect r a and t r ansfer funct ions using
spect r al analysis.
Parame te r Est i mat i on
ar Est imat e AR model.
armax Est imat e ARMAX model.
arx Est imat e ARX model using lea st squar es.
bj Est imat e Box-J enkins model.
canstart Est imat e mult ivar iat e models in canonica l
st at e-space for m.
ivar Est imat e AR model using inst r ument al var iable
met hods.
ivx Est imat e ARX model using gener al inst r ument s.
iv4 Est imat e ARX model using four-st age inst r ument a l
var iable met hod.
4 C o m m a n d Re f e r e n c e
4-4
oe Est imat e Out put -Er r or model.
n4sid Est imat e st at e-space model using subspace met hod.
pem Est imat e gener al linear model.
Mode l St ruct ure Cre at i on
arx2th Define (mult ivar iat e) ARX st r uct ur es.
canform Gener at e canonical for ms.
mf2th Cr eat e a r bit r ar y linear model st r uct ur e via an M-file
t ha t you wr it e.
modstruc Define st at e-space models wit h known and unknown
par a met er s.
ms2th Cr eat e model st r uct ur e for linear st a t e-space models
wit h known and unknown par amet er s.
poly2th Cr eat e a model st r uct ur e for input -out put models
defined as numer at or and denomina t or polynomials.
Mani pul at i ng Mode l St ruct ure s
fixpar Fix par amet er s in st r uct ur es t o given values.
sett Set t he sampling int er val.
ss2th Tr ansfor m a st at e-space model t o a par a met r ized
canonical for m.
thinit Select or r a ndomize init ia l par amet er values.
unfixpar Allow cer t ain ear lier fixed pa r amet er s be est ima t ed.
Parame t e r Es ti mat i on
4-5
Model Conversions
idmodred Reduce a model t o lower or der.
thc2thd Tr ansfor m fr om cont inuous t o discr et e t ime.
thd2thc Tr ansfor m fr om discr et e t o cont inuous t ime.
th2arx Thet a t o ARX par amet er s.
th2ff Thet a t o fr equency funct ions and spect r a.
th2par Thet a t o est imat ed par amet er s and var ia nces.
th2poly Thet a t o t r ansfer funct ion polynomials.
th2ss Thet a t o st at e-space mat r ices.
th2tf Thet a t o t r ansfer funct ions.
th2zp Thet a t o zer os, poles, and st a t ic gains.
Mode l Pre s e ntati on
bodeplot Plot Bode diagr ams.
ffplot Plot fr equency funct ions and spect r a.
idplot Display input -out put dat a.
nyqplot Plot Nyquist diagr ams.
present Display model on scr een.
zpplot Plot zer os and poles.
4 C o m m a n d Re f e r e n c e
4-6
Informati on Ext racti on
getff Ext r act t he fr equency funct ions fr om t he fr eqfunc
for mat .
gett Ext r act t he sampling int er val fr om t he t het a for mat .
getmfth Ext r act t he M-file name t hat defines t he model
st r uct ur e.
getncap Ext r act fr om t he t het a for mat t he number of dat a
upon which model is based.
getzp Ext r act t he zer os a nd poles fr om t he zepo for mat .
th2par Ext r act est imat ed pa r amet er s a nd var iances fr om
t he t het a for ma t .
Mode l Val i dati on
compare Compar e model’s simulat ed or pr edict ed out put wit h
act ual out put .
idsim Simulat e a model.
pe Comput e pr edict ion er r or s.
predict Pr edict fut ur e out put s.
resid Comput e and t est model r esiduals.
As s e s s i ng Mode l Unce rt ai nty
idsimsd Simulat e r esponses fr om sever al possible models.
th2ff Comput e fr equency funct ion and it s st andar d
deviat ion.
th2zp Comput e zer os, poles, st at ic gains, and t heir
st andar d deviat ions.
4-7
Mode l St ruct ure Sel e ct i on
arxstruc Comput e loss funct ions for set s of ARX model
st r uct ur e.
ivstruc Comput e loss funct ions for set s of out put er r or model
st r uct ur es.
selstruc Select st r uct ur e.
struc Gener at e set s of st r uct ur es.
Rec urs i ve Parame t e r Es t i mati on
rarmax Est imat e ARMAX or ARMA models r ecur sively.
rarx Est imat e ARX or AR models r ecur sively.
rbj Est imat e Box-J enkins models r ecur sively.
roe Est imat e Out put -Er r or models (IIR-filt er s)
r ecur sively.
rpem Est imat e gener al input -out put models using a
r ecur sive pr edict ion er r or met hod.
rplr Est imat e gener al input -out put models using a
r ecur sive pseudo-linear r egr ession met hod.
segment Segment dat a and est imat e models for each segment .
4 C o m m a n d Re f e r e n c e
4-8
ar
4-9
ar
Purpose Est imat e t he par amet er s of an AR model for scalar t ime ser ies.
Syntax th = ar(y,n)
[th,refl] = ar(y,n,approach,win,maxsize,T)
Description The pa r amet er s of t he AR model st r uct ur e
ar e est ima t ed using var ia nt s of t he least -squar es met hod.
Column vect or y cont ains t he t ime ser ies dat a. Scalar n specifies t he or der of
t he model t o be est imat ed (t he number of A pa r amet er s in t he AR model).
Not e t hat t he r out ine is for scalar t ime ser ies only. For mult ivar iat e dat a use
arx.
The est imat e is r et ur ned in th and st or ed in t het a for mat . For t he t wo
lat t ice-based appr oaches, 'burg' and 'gl' (see below), var iable refl is
r et ur ned cont aining t he r eflect ion coefficient s in t he fir st r ow, and t he
cor r esponding loss funct ion va lues in t he second. The fir st column is t he zer o-t h
or der model, so t hat t he (2,1) element of refl is t he nor m of t he t ime ser ies
it self.
Var iable approach a llows you t o choose an algor it hm fr om a gr oup of sever al
popular t echniques for comput ing t he least -squar es AR model. Available
met hods ar e as follows:
approach = 'fb': The for war d-backwar d a ppr oach. This is t he default
appr oach. The sum of a least -squar es cr it er ion for a for war d model and t he
ana logous cr it er ion for a t ime-r ever sed model is minimized.
approach = 'ls': The least -squar es a ppr oach. The st andar d sum of squar ed
for wa r d pr edict ion er r or s is minimized.
approach = 'yw': The Yule-Walker appr oach. The Yule-Walker equat ions,
for med fr om sa mple covar ia nces, ar e solved.
approach = 'burg': Bur g’s la t t ice-ba sed met hod. The lat t ice filt er equat ions
ar e solved, using t he har monic mean of for war d and ba ckwar d squar ed
pr edict ion er r or s.
A q ( )y t ( ) e t ( ) =
ar
4-10
approach = 'gl': A geomet r ic la t t ice appr oa ch. As in Bur g’s met hod, but t he
geomet r ic mean is used inst ead of t he har monic one. .
The comput a t ion of t he covar iance mat r ix ca n be suppr essed in any of t he
above met hods by ending t he approach ar gument wit h 0 (zer o), for example,
'burg0'.
Windowing, wit hin t he cont ext of AR modeling, is a t echnique for dea ling wit h
t he fact t hat infor mat ion about past a nd fut ur e dat a is la cking. Ther e ar e a
number of var iant s ava ilable:
window = 'now': No windowing. This is t he default value, except when
approach = 'yw'. Only act ually measur ed dat a ar e used t o for m t he r egr ession
vect or s. The summat ion in t he cr it er ia st a r t s only a t t ime n.
window = 'prw': Pr e-windowing. Missing past dat a ar e r eplaced by zer os, so
t hat t he summa t ion in t he cr it er ia can be st ar t ed at t ime zer o.
window = 'pow': Post -windowing. Missing end dat a ar e r eplaced by zer os, so
t hat t he summa t ion can be ext ended t o t ime N + n. (N being t he number of
obser vat ions.)
window = 'ppw': Pr e- and post -windowing. This is used in t he Yule-Walker
appr oach.
The combinat ions of a ppr oaches a nd windowing have a var iet y of names. The
least -squar es appr oach wit h no windowing is also known as t he covariance
met hod. This is t he same met hod t hat is used in t he arx r out ine. The MATLAB
default met hod, for war d-backwar d wit h no windowing, is oft en ca lled t he
modified covariance met hod. The Yule-Walker a ppr oach, least -squar es plus
pr e- and post -windowing, is also known as t he correlat ion method.
ar only ha ndles sca lar t ime ser ies. For mult ivar ia t e ser ies, use arx.
See auxvar for an expla nat ion of t he input ar gument s maxsize and T.
ar
4-11
Examples Compar e t he spect r al est imat es of Bur g’s met hod wit h t hose found fr om t he
for wa r d-backwar d nonwindowed met hod, given a sinusoid in noise signal:
y = sin([1:300]') + 0.5*randn(300,1);
thb = ar(y,4,'burg');
thfb = ar(y,4);
sgb = th2ff(thb);
sfb = th2ff(thfb);
bodeplot([sgb sfb])
See Also auxvar, arx, etfe, ivar, spa, theta
References Mar ple, J r ., S. L. Digit al S pectral Analysis wit h Applicat ions, Pr ent ice Hall,
Englewood Cliffs, 1987, Chapt er 8.
armax
4-12
ar ma x
Purpose Est imat e t he pa r amet er s of an ARMAX or ARMA model.
Syntax th = armax(z,nn)
th = armax(z,nn,’trace’)
[th, iter_info] = armax(z,nn,maxiter,tol,lim,maxsize,T,’trace’)
Description The pa r amet er s of t he ARMAX model st r uct ur e
ar e est ima t ed using a pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u a r e column
vect or s (u is a mat r ix in t he mult i-input case). nn can be given eit her as
nn = [na nb nc nk]
or as
nn = thi
In t he for mer case na, nb, and nc ar e t he or der s of t he ARMAX model, and nk
is t he dela y. In t he lat t er ca se thi is an init ial value, given in t het a for ma t . See
Sect ion 3 in t he Tutorial for an exact definit ion of t he or der s.
For mult i-input syst ems, nb and nk ar e r ow vect or s, such t hat t he k-t h ent r y
cor r esponds t o t he or der and delay associat ed wit h t he k-t h input .
If z = y and nn = [na nc], armax calcula t es an ARMA model for y:
th is r et ur ned wit h t he r esult ing par amet er est imat es, t oget her wit h est imat ed
covar ia nces, st or ed in t het a for mat .
armax does not suppor t mult i-out put models. Use st at e-space model for t his
ca se (see canstart, n4sid, and pem)
If a last ar gument ‘trace’ is supplied, infor mat ion about t he pr ogr ess of t he
it er at ive sear ch for t he model will be fur nished t o t he MATLAB comma nd
window.
The opt iona l auxiliar y var iables iter_info, lim, maxiter, tol, maxsize, and T
ar e explained under auxvar.
A q ( )y t ( ) B q ( )u t nk – ( ) C q ( )e t ( ) + =
A q ( )y t ( ) C q ( )e t ( ) =
armax
4-13
Algorithm A r obust ified quadr a t ic pr edict ion er r or cr it er ion is minimized using an
it er at ive Gauss-Newt on algor it hm. The Gauss-Newt on vect or is bisect ed up t o
10 t imes unt il a lower value of t he cr it er ion is found. If no such value is found,
a gr adient sear ch dir ect ion is used inst ead, and t he pr ocedur e is r epeat ed. The
it er at ions ar e t er minat ed when maxiter is r eached, when t he Ga uss-Newt on
vect or has a nor m less t han tol, or when a lower value of t he cr it er ion cannot
be found.
The init ial condit ions for t he it er at ive sea r ch, if not specified in nn, ar e
const r uct ed in a special four -st a ge LS-IV algor it hm.
The cut -off value for t he r obust ificat ion is based on t he par a met er lim as well
as on t he est imat ed st a ndar d deviat ion of t he r esiduals fr om t he init ial
par a met er est imat e. It is not r ecalculat ed dur ing t he minimizat ion. The value
r et ur ned in element th(1,1) is t he nonr obust ified, quadr at ic cr it er ion.
A st abilit y t est of t he pr edict or is per for med, so as t o assur e t hat only models
cor r esponding t o st able pr edict or s ar e t est ed. Gener ally, bot h and (if
applicable) must have all t heir zer os inside t he unit cir cle. Not e t hat if an
init ial par amet er est imat e is given in nn, it s pr edict or st abilit y is t aken for
gr ant ed (not t est ed).
Infor ma t ion about t he minimizat ion is fur nished t o t he scr een in case t he
ar gument ‘trace’ is specified.. Cur r ent and pr evious par amet er est ima t es (in
column vect or for m, list ing par amet er s in alphabet ical or der ) as well as t he
values of t he cr it er ion funct ion ar e given. The Gauss-Newt on vect or and it s
nor m ar e a lso displayed. The number in t he upper left cor ner is t he number of
t imes t he sear ch vect or ha s been bisect ed.
See Also arx, auxvar, bj, oe, pem, theta
References Ljung (1987), equat ions (10.41), (10.42), (10.46), (10.75)
C q ( ) F
i
q ( )
arx
4-14
ar x
Purpose Est imat e t he pa r amet er s of an ARX or AR model.
Syntax th = arx(z,nn)
th = arx(z,nn,maxsize,T)
Description The pa r amet er s of t he ARX model st r uct ur e
ar e est ima t ed using t he least -squar es met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u a r e column
vect or s. nn is given as
nn = [na nb nk]
defining t he or der s and delay of t he ARX model. See Sect ion 6 in t he Tut orial
for exact definit ions of t he or der s and delays.
th is r et ur ned as t he least -squar es est imat es of t he pa r amet er s, st or ed in t het a
for mat .
Wit h z = y a nd nn = na, a n AR model of or der na for y is comput ed:
Models wit h sever al input s
ar e ha ndled by a llowing u t o cont ain ea ch input as a column vect or ,
u = [u1 ... unu]
and by allowing nb and nk t o be r ow vect or s defining t he or der s and delays
associat ed wit h each input .
Models wit h sever al input s and sever al out put s ar e handled by a llowing nn t o
cont ain one r ow for each out put number . See “Defining Model St r uct ur es” on
page 3-29 for exact definit ions.
The opt ional auxiliar y par amet er s maxsize and T ar e expla ined under
auxvar.
A q ( )y t ( ) B q ( )u t nk – ( ) e t ( ) + =
A q ( )y t ( ) e t ( ) =
A q ( )y t ( ) B
1
q ( )u
1
t nk
1
– ( ) …B
nu
u
nu
t nk
nu
– ( ) e t ( ) + + =
arx
4-15
When t he t r ue noise t er m in t he ARX model st r uct ur e is not whit e noise
and na is nonzer o, t he est imat e does not give a cor r ect model. It is t hen bet t er
t o use armax, bj, iv4, or oe.
Examples Her e is an example t hat gener at es and est imat es a n ARX model:
A = [1 –1.5 0.7]; B = [0 1 0.5];
th0 = poly2th(A,B);
u = idinput(300,'rbs');
y = idsim([u,randn(300,1)],th0);
z = [y,u];
th = arx(z,[2 2 1]);
Algorithm The lea st -squar es est imat ion pr oblem is an over det er mined set of linear
equat ions t hat is solved using t he MATLAB \ oper a t or .
The r egr ession mat r ix is for med so t hat only measur ed quant it ies ar e used (no
fill-out wit h zer os). When t he r egr ession mat r ix is lar ger t han maxsize, t he
nor mal equat ions ar e for med in a for -loop and subsequent ly solved.
See Also auxvar, ar, iv, iv4, theta
e t ( )
arxstruc
4-16
ar xst r uc
Purpose Comput e loss funct ions for a set of differ ent model st r uct ur es of single-out put
ARX t ype.
Syntax v = arxstruc(ze,zv,NN)
v = arxstruc(ze,zv,NN,maxsize)
Description NN is a ma t r ix t hat defines a number of differ ent st r uct ur es of t he ARX t ype.
Each r ow of NN is of t he for m
nn = [na nb nk]
wit h t he same int er pr et at ion a s descr ibed for arx. See struc for easy
gener at ion of t ypical NN mat r ices for single-input syst ems.
Each of ze and zv a r e ma t r ices cont aining out put -input dat a [y u]. For
mult i-input syst ems, u ha s t he cor r esponding number of columns, while for
t ime ser ies, no u is pr esent . Models for each of t he model st r uct ur es defined by
NN ar e est imat ed using t he dat a set ze. The loss funct ions (nor malized sum of
squar ed pr edict ion er r or s) a r e t hen comput ed for t hese models when applied t o
t he va lidat ion dat a set zv. The dat a set s, ze and zv, need not be of equal size.
They could, however , be t he same set s, in which case t he comput at ion is fa st er .
Not e t hat arxstruc is int ended for single-out put syst ems only.
v is r et ur ned wit h t he loss funct ions in it s fir st r ow. The r emaining r ows of v
cont ain t he t r anspose of NN, so t hat t he or der s a nd delays a r e given just below
t he cor r esponding loss funct ions. The last column of v cont ains t he number of
dat a point s in ze. The select ion of a suit able model st r uct ur e based on t he
infor mat ion in v is best done using selstruc. See Sect ion 8 in t he Tut orial for
advice on model st r uct ur e select ion, cr oss-validat ion, and t he like.
See auxvar for an expla nat ion of maxsize.
Examples Compar e fir st t o fift h or der models wit h one delay using cr oss-validat ion on t he
second half of t he dat a set , and t hen select t he or der t hat gives t he best fit t o
t he va lidat ion dat a set :
NN = struc(1:5,1:5,1);
V = arxstruc(z(1:200,:),z(201:400,:),NN);
nn = selstruc(V,0);
th = arx(z,nn);
See Also arx, ivstruc, selstruc, struc
arx 2th
4-17
ar x2t h
Purpose Const r uct t het a for mat ma t r ix fr om ARX polynomials.
Syntax th = arx2th(A,B,ny,nu)
th = arx2th(A,B,ny,nu,lam,T)
Description arx2th cr eat es a mat r ix cont aining par amet er s t hat descr ibe t he gener al
mult i-input , mult i-out put model st r uct ur e of ARX t ype:
Her e a nd ar e ma t r ices of dimensions ny by ny and ny by nu, r espect ively
(ny is t he number of out put s, i.e., t he dimension of t he vect or and nu is t he
number of input s). “Defining Model St r uct ur es” on page 3-29.
The ar gument s A a nd B ar e mat r ices t ha t cont a in t he A mat r ices and t he B
mat r ices of t he model:
A = [I A1 A2 ... Ana]
B = [B0 B1 ... Bnb]
Not e t hat A alwa ys st ar t s wit h t he ident it y mat r ix, and t hat delays in t he model
ar e defined by set t ing t he cor r esponding lea ding ent r ies in B t o zer o. For a
mult ivar iat e t ime ser ies t ake B = [].
The ar gument s ny and nu denot e t he number of out put s a nd input s,
r espect ively.
The opt ional ar gument lam set s t he covar iance mat r ix of t he dr iving noise
sour ce in t he model above. The default value is t he ident it y mat r ix.
The opt ional ar gument T defines t he sa mpling int er val (Defa ult 1).
th is r et ur ned as a model st r uct ur e in t he t het a for mat . See theta.
The use of arx2th is t wofold. You can use it t o cr eat e models t ha t ar e simulat ed
(using idsim) or analyzed (using th2ff, th2zp, et c.). You can also use it t o
define init ia l value models t hat ar e fur t her adjust ed t o da t a (using pem). The
fr ee pa r amet er s in t he st r uct ur e ar e consist ent wit h t he st r uct ur e of A a nd B,
i.e., leading zer os in t he r ows of B ar e r egar ded a s fixed delays, and t r ailing
zer os in A and B ar e r egar ded as a definit ion of lower or der polynomials. These
y t ( ) A
1
y t 1 – ( ) A
2
y t 2 – ( ) … A
na
y t na – ( ) + + + + =
B
0
u t ( ) B
1
u t 1 – ( ) … B
nb
u t nb – ( ) e t ( ) + + + +
A
k
B
k
y t ( )
e t ( )
arx2th
4-18
zer os ar e fixed, while all ot her par amet er s ar e fr ee. The nominal values of t hese
fr ee pa r amet er s a r e set equal t o t he values in A and B. The fr ee pa r amet er s can
be cha nged by thinit and t he st r uct ur e can be ma nipulat ed by fixpar and
unfixpar.
For a model wit h one out put , arx2th is compat ible wit h poly2th. The int er nal
r epr esent at ion is however differ ent , a nd only a model st r uct ur e t hat has been
defined by arx2th can be manipulat ed by fixpar a nd unfixpar.
Examples Simulat e a second or der ARX model wit h one input and t wo out put s, and t hen
est ima t e a model using t he simula t ed dat a :
A1 = [–1.5 0.1;–0.2 1.5];
A2 = [0.7 –0.3;0.1 0.7];
B1 = [1;–1];
B2 = [0.5;1.2];
th0 = arx2th([eye(2) A1 A2],[[0;0],B1 B2],2,1);
u = idinput(300);
e = randn(300,2);
y = idsim([u e],th0);
th = arx([y u],[[2 2;2 2],[2;2],[1;1]]);
See Also arx, fixpar, poly2th, th2arx, unfixpar
auxvar
4-19
auxvar
Purpose Descr ibe auxilia r y var iables iter_info, lim, maxiter, maxsize, tol, and T.
Syntax help auxvar
Description Most of t he funct ions have a n opt ional ar gument maxsize t hat allows a
t r ade-off bet ween memor y usage a nd speed. Sever al of t he funct ions allow t he
sampling int er val T t o be specified. The it er at ive sear ch pr ocedur es in armax,
bj, oe, and pem ar e cont r olled by t he t hr ee par amet er s lim, maxiter, and lim.
maxsize: No mat r ix for med by t he funct ion is allowed t o cont ain mor e t han
maxsize element s. Inst ead, t he algor it hms split t he calculat ions int o for -loops,
which ar e slower . The default value of maxsize is set in t he M-file idmsize. On
small machines, it is maxsize=4096. The main use of maxsize is t o limit
var iable sizes when t he algor it hms r un out of memor y. See “Some Special
Topics” on page 3-68 for mor e infor mat ion.
T: Specifying t he sampling int er va l T gives cor r ect fr equency sca les on
fr equency funct ion plot s, and cor r ect t ime scales when t r ansfor ming t o
cont inuous t ime using thd2thc. The default value is T=1.
maxiter: This va r iable det er mines t he maximum number of it er at ions
per for med dur ing a sear ch for a minimum. The default value is maxiter=10.
maxiter=0 r et ur ns t he r esult s of t he special st ar t up pr ocedur e.
tol: The it er at ions ar e cont inued unt il t he nor m of t he Gauss-Newt on upda t e
vect or is less t han TOL. The it er at ions also t er minat e when t he algor it hm fa ils
t o find a lower value of t he cr it er ion and when t he maximum number of
it er at ions ar e r ea ched. The default value is tol=0.01.
lim: This var iable det er mines how t he cr it er ion is modified fr om quadr at ic t o
one t hat gives linear weight t o lar ge er r or s. See “Par amet r ic Model Est imat ion”
on pa ge 3-22 for a mor e pr ecise definit ion. The default value of lim is 1.6. lim=0
disables t he r obust ificat ion and leads t o a pur ely quadr at ic cr it er ion.
Default values of t hese par amet er s ar e obt ained eit her by omit t ing t r ailing
ar gument s or by ent er ing t hem as t he empt y mat r ix [ ].
auxvar
4-20
iter_info: This out put ar gument fr om t he it er at ive numer ical sear ch
algor it hms armax, bj, oe, and pem, supplies infor mat ion about t he it er a t ions. It
is a r ow vect or
iter_info = [last_iteration#, last_fit_improvement,
norm_of_last_search_vector]
cont aining t he indicat ed infor mat ion. If t he nor m of t he last sear ch vect or is
lar ger t ha n tol, and t he number of t he last it er at ion is less t han maxiter, t hen
t he it er at ions wer e st opped since no smaller value of t he cr it er ion could be
found along t he sear ch dir ect ion.
See Also armax, bj, oe, pem
bj
4-21
bj
Purpose Est imat e t he par amet er s of a Box-J enkins model.
Syntax th = bj(z,nn)
th = bj(z,nn,’trace’)
[th, iter_info]= bj(z,nn,maxiter,tol,lim,maxsize,T,’trace’)
Description The pa r amet er s of t he Box-J enkins model st r uct ur e
ar e est ima t ed using a pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input dat a z = [y u] wher e y and u ar e column
vect or s. In t he mult i-input case, u is a mat r ix cont aining t he differ ent input s as
columns. nn can be given eit her as
nn = [nb nc nd nf nk]
or as
nn = thi
In t he for mer ca se, nb, nc, nd, and nf a r e t he or der s of t he Box-J enkins model
and nk is t he dela y. In t he lat t er case, thi is an init ial value, given in t het a
for mat . See“The Syst em Ident ificat ion Pr oblem” on page 3-8 for exa ct
definit ions of t he model or der s.
th is r et ur ned wit h t he r esult ing par amet er est ima t es a nd est imat ed
covar iances, st or ed in t het a for mat .
The opt ional var iables iter_info, lim, maxiter, maxsize, tol, a nd T ar e
explained under auxvar.
For mult i-input syst ems, nb, nf, and nk ar e r ow vect or s wit h as many ent r ies
as t her e ar e input channels. Ent r y number i t hen descr ibed t he or der s and
delays associat ed wit h t he i-t h input .
bj does not suppor t mult i-out put models. Use st at e-spa ce model for t his case
(see canstart, n4sid, and pem)
y t ( )
B q ( )
F q ( )
-----------u t nk – ( )
C q ( )
D q ( )
------------e t ( ) + =
bj
4-22
If a last ar gument ‘trace’ is supplied, infor mat ion about t he pr ogr ess of t he
it er at ive sear ch for t he model will be fur nished t o t he MATLAB comma nd
window.
Examples Her e is an example t hat gener at es dat a and st or es t he r esult s of t he st a r t up
pr ocedur e separ a t ely:
B = [0 1 0.5];
C = [1 –1 0.2];
D = [1 1.5 0.7];
F = [1 –1.5 0.7];
th0 = poly2th(1,B,C,D,F,0.1);
e = randn(200,1);
u = idinput(200);
y = idsim([u e],th0);
z = [y u];
thi = bj(z,[2 2 2 2 1],0);
th = bj(z,thi);
present(th)
Algorithm bj uses essent ially t he same algor it hm as armax wit h modificat ions t o t he
comput at ion of pr edict ion er r or s and gr adient s.
See Also armax, auxvar, oe, pem, theta
bodeplot
4-23
bodeplot
Purpose Plot fr equency funct ions in Bode diagr am for m.
Syntax bodeplot(g)
bodeplot([g1 g2 ... gn])
bodeplot(g,sd,C,mode)
Description g cont ains t he fr equency dat a t o be gr aphed. See freqfunc for t he for mat . The
fr equency funct ions do not have t o be specified at t he same fr equencies, but
have t o have t he same number of values.
If t he fr equency funct ions ar e gener at ed by th2ff or spa, and sd is specified as
a number lar ger t han zer o, confidence int er vals for t he funct ions ar e added t o
t he gr aph as dash-dot t ed cur ves (of t he same color a s t he est imat e cur ve). They
indicat e t he confidence r egions cor r esponding t o sd st andar d deviat ions.
On amplit ude plot s, t he loga r it hm of t he absolut e value, plus and minus t he
st a ndar d deviat ion you indicat e, is gr a phed. The la t t er value can somet imes be
negat ive, which r esult s in an er r or messa ge fr om t he plot t ing r out ine. The
r esult ing plot is st ill meaningful, however .
By default , amplit ude and phase plot s ar e shown simult a neously for each input
(noise spect r um) pr esent in g. For spect r a, phase plot s ar e omit t ed. Pr essing
t he Re t urn key advances t he plot fr om one input t o t he next .
To show amplit ude plot s only, use C = 'A'. For phase plot s only, use
C = 'P'. The default is C = 'B' for bot h plot s.
To obt ain all plot s on t he same diagr am use mode = 'same'.
Not e t hat if g cont ains infor ma t ion about sever al out put s, t hese plot s ar e
always given separ at ely.
See Also etfe, ffplot, freqfunc, getff, nyqplot, spa, th2ff
canform
4-24
ca nfor m
Purpose Define mult ivar iable st a t e-space canonical for m model st r uct ur es.
Syntax ms = canform(orders,nu)
ms = canform(orders,nu,dkx)
Description canform is, like modstruc, a funct ion t hat defines model par amet er iza t ions in
st a t e-space for m, which ar e used in ms2th t o cr ea t e model st r uct ur es in t he
t het a for mat . The only use of t he r esult ing mat r ix ms is as an input t o ms2th.
The model consider ed is in st at e-spa ce for m:
The funct ion applies bot h t o t he cont inuous- and discr et e-t ime cases; which one
is det er mined only when t he st r uct ur e is for med wit h ms2th.
orders: The (pseudo-obser vabilit y) indices orders define which mat r ix
element s ar e fixed (t o zer o or one) a nd which ar e left fr ee as par amet er s.
orders is a r ow vect or wit h as many ent r ies as t her e ar e out put s. Element k of
orders descr ibes how many dela yed values of t he out put ar e r equir ed t o
appr opr iat ely pr edict t he k-t h component of t he out put . The sum of t he or der
indices is t he or der of t he syst em (t he dimension of x):
n = sum(orders)
The exact st r uct ur e is defined in Appendix 4.A of Ljung (1987). Br iefly, t he A
mat r ix cont a ins p ∗ n pa r amet er s, wher e p is t he number of out put s and n is
t he number of st at es. The C mat r ix cont a ins only zer os a nd ones, while t he B
mat r ix is filled wit h par amet er s.
nu: The number of input s.
dkx: The a r gument dkx det er mines some addit ional st r uct ur e of t he ma t r ices
of t he st at e-space model t o be est imat ed. It is a r ow vect or wit h t hr ee ent r ies:
dkx = [d, k, x]
The ent r ies r efer t o t he mat r ices K, D, and t he init ia l st at e x(0) of t he
st a t e-space model given above.
x
·
t ( ) A θ ( )x t ( ) B θ ( )u t ( ) K θ ( )e t ( ) + + =
y t ( ) C θ ( )x t ( ) D θ ( )u t ( ) e t ( ) + + =
canform
4-25
k = 1 indicat es t hat t he K-mat r ix in t he model (t he Kalma n Gain) will be fully
par a met er ized, while k = 0 means t hat t his mat r ix will be fixed t o zer o. This
will give a so-called out put er r or model.
d = 1 indicat es t hat D-mat r ix in t he model (t he dir ect t er m fr om input t o
out put ) will be fully par amet r ized, while d = 0 mea ns t hat t his mat r ix will be
fixed t o zer o. This also implies t hat t her e will be a dela y of (at lea st ) one sample
bet ween t he input and t he out put .
x = 1 indicat es t hat t he init ial st at e x(0) will be par amet er ized, while x = 0
means t hat t he init ial st at e will be fixed t o zer o.
Default is
dkx = [0, 1, 0]
An alt er na t ive t o canform is t he funct ion canstart. It also pr ovides good init ial
est imat es for t he fr ee par amet er s.
Examples Wr it e out t he st a t e-space mat r ices for a sixt h or der syst em wit h t hr ee out put s
and t wo input s wit h NaN denot ing fr ee par amet er s:
ps = [2 1 3];
ms = canform(ps,2);
th = ms2th(ms,'c',ones(1,18+12+18)∗NaN);
[A,B,C,D,K] = th2ss(th)
See Also canstart, fixpar, modstruc, ms2th, unfixpar
References Ljung (1987), Appendix 4.A.
canstart
4-26
ca nst ar t
Purpose Define and init ialize st a t e-space canonical for m model st r uct ur es.
Syntax th = canstart(z,orders,nu)
th = canstart(z,orders,nu,dkx)
Description orders,nu,dkx: These ar gument s define t he st at e-space model
par amet er izat ion exact ly as for t he funct ion canform. In t he pr esent case
orders ca n also be t aken as a scalar , giving t he model or der (dimension of st at e
vect or ). Then a default choice of par amet er izat ion is made.
The out put th is a mat r ix in t he t het a for mat . It defines a st at e-space model
par amet er izat ion a ccor ding t o t he ar gument s orders, nu and dkx. The values
of t he par amet er s in th ar e est ima t ed fr om t he dat a mat r ix
z = [y u]
wher e y is t he mat r ix of out put signals, one column for each out put , a nd u is
t he mat r ix of input signals, again one column for each input .
Choosing t he or der indices for many syst ems is not cr it ical in t he sense t hat
most n-t h or der syst ems can be descr ibed by any set of or der
(pseudo-obser vabilit y) indices whose sum is n. See “Model St r uct ur e Select ion
and Valida t ion” on page 3-49 for mor e infor mat ion.
The model th could be fur t her r efined by using pem.
Algorithm The st at e-space model is fir st est imat ed using n4sid, and t hen t r ansfor med t o
t he chosen ca nonical for m using ss2th.
Examples A syst em wit h t wo input s and t wo out put s is est imat ed wit h a t hir d or der
model:
th = canstart(z,3,2);
th = pem(z,th);
resid(z,th);
See Also canform, pem
compare
4-27
compar e
Purpose Compar e measur ed out put s wit h model out put s.
Syntax compare(z,th);
[yh,fit] = compare(z,th,k,sampnr,leveladj)
Description z is t he out put -input dat a in t he usual for mat
z = [y u]
wher e y is a mat r ix whose r-t h column is t he r-t h out put signal a nd
cor r espondingly for t he input u. compare comput es t he out put yh t ha t r esult s
when t he model th is simulat ed wit h t he input u. The r esult is plot t ed (yellow/
solid) t oget her wit h t he cor r esponding measur ed out put y (magent a/dashed).
The mea n squa r e fit
fit = norm(yh – y)/sqrt(length(y))
is also comput ed and displa yed. For mult i-out put syst ems t his is done
separ at ely for ea ch out put . Pr essing t he Re t urn key advances t he plot s.
The ar gument k comput es t he k-st ep ahead pr edict ion of y accor ding t o t he
model th inst ead of t he simula t ed out put . In t he calculat ion of , t he model
ca n use out put s up t o t ime : , , (and input s up t o
t he cur r ent t ime t). The default va lue of k is inf, which obt ains a pur e
simulat ion fr om t he input only.
The ar gument sampnr indicat es t hat only t he sample number s in t his r ow
vect or ar e plot t ed and used for t he calculat ion of t he fit . The whole dat a r ecor d
is used for t he simulat ion/pr edict ion, t hough. If t he opt ional ar gument
leveladj is set t o 'yes', t he simulat ed/pr edict ed out put and t he measur ed
out put ar e level adjust ed so t ha t t hey bot h st ar t a t level zer o. (This applies also
t o t he ca lculat ion of t he fit .) This a llows for discount ing of dr ift phenomena in
t he dat a.
Examples Split t he dat a r ecor d int o t wo par t s. Use t he fir st one for est imat ing a model
and t he second one t o check t he model’s abilit y t o pr edict six st eps ahead:
ze = z(1:250,:);
zv = z(251:500,:);
th = armax(ze,[2 3 1 0]);
compare(zv,th,6);
See Also idsim, predict
yh t ( )
t k – y s ( ) s , t k – = t k – 1 – …
covf
4-28
covf
Purpose Est imat e t ime ser ies covar iance funct ions.
Syntax R = covf(z,M)
R = covf(z,M,maxsize)
Description z is an N by nz mat r ix and M is t he maximum delay -1 for which t he covar iance
funct ion is est imat ed.
R is r et ur ned as an nz
2
x M mat r ix wit h ent r ies
wher e is t he j-t h column of z and missing values in t he sum ar e r eplaced by
zer o.
The opt ional ar gument maxsize cont r ols t he memor y size as explained under
auxvar.
The ea siest way t o descr ibe and unpa ck t he r esult is t o use
reshape(R(:,k+1),nz,nz) = E z(t)∗z'(t+k)
Her e ' is complex conjuga t e t r anspose, which also explains how complex dat a
ar e ha ndled. The expect at ion symbol E cor r esponds t o t he sample means.
Algorithm When nz is a t most t wo, and when per mit t ed by maxsize, a fast Four ier
t r ansfor m t echnique is applied. Ot her wise, st r aight for war d summing is used.
See Also spa
R
ˆ
i j
k ( )
1
N
--- - z
i
t 1 =

= = t ( )z
j
t k + ( )
R(i + ( j −1)nz, k +1)
z
j
cra
4-29
cr a
Purpose Per for m cor r elat ion analysis and est imat e impulse r esponse.
Syntax cra(z);
[ir,R,cl] = cra(z,M,na,plot);
cra(R);
Description The out put -input dat a ar e given as
z = [y u]
wit h y as t he out put column vect or and u as t he input column vect or . The
r out ine only handles single-input -single-out put da t a pa ir s. (For t he
mult ivar iat e case, apply cra t o t wo signals at a t ime.) cra pr ewhit ens t he input
sequence, i.e., filt er s u t hr ough a filt er chosen so t hat t he r esult is as
uncor r elat ed (whit e) as possible. The out put y is subject ed t o t he same filt er ,
and t hen t he covar iance funct ions of t he filt er ed y a nd u ar e comput ed and
gr aphed. The cr oss cor r elat ion funct ion bet ween (pr ewhit ened) input and
out put is a lso comput ed and gr aphed. Posit ive va lues of t he lag var ia ble t hen
cor r esponds t o an influence fr om u t o lat er va lues of y. In ot her wor ds,
significant cor r elat ion for negat ive lags is an indicat ion of feedba ck fr om y t o u
in t he dat a.
A pr oper ly scaled ver sion of t his cor r elat ion funct ion is also a n est imat e of t he
syst em’s impulse r esponse ir. This is also gr aphed along wit h 99% confidence
levels. The out put ar gument ir is t his impulse r esponse est imat e, so t ha t it s
fir st ent r y cor r esponds t o la g zer o. (Negat ive lags ar e excluded in ir.)
The out put ar gument R cont ains t he covar iance/cor r ela t ion infor mat ion as
follows: The fir st column of R cont ains t he lag indices. The second column
cont ains t he covar iance funct ion of t he (possibly filt er ed) out put . The t hir d
column cont ains t he covar iance funct ion of t he (possibly pr ewhit ened) input ,
and t he four t h column cont ains t he cor r elat ion funct ion. The plot s can be
r edisplayed by cra(R).
The out put ar gument cl is t he 99% confidence level for t he impulse r esponse
est imat e.
The opt ional ar gument M defines t he number of lags for which t he covar iance/
cor r elat ion funct ions ar e comput ed. These ar e fr om –M t o M, so t hat t he lengt h
of R is 2M+1. The impulse r esponse is comput ed fr om 0 t o M. The default value
of M is 20.
cra
4-30
For t he pr ewhit ening, t he input is fit t ed t o an AR model of or der na. The t hir d
ar gument of cra can cha nge t his or der fr om it s default value na = 10. Wit h na
= 0 t he covar ia nce and cor r elat ion funct ions of t he or iginal dat a sequences ar e
obt ained.
plot: plot = 0 gives no plot s. plot = 1 (default ) gives a plot of t he est imat ed
impulse r esponse t oget her wit h a 99% confidence r egion. plot = 2 gives a plot
of all t he covar iance funct ions.
Examples Compar e a second or der ARX model’s impulse r esponse wit h t he one obt a ined
by cor r elat ion analysis:
ir = cra(z);
th = arx(z,[2 2 1]);
imp = [1;zeros(19,1)];
irth = idsim(imp,th);
subplot(211)
plot([ir irth])
title('impulse responses')
subplot(212)
plot([cumsum(ir),cumsum(irth)])
title('step responses')
See Also covf, spa
dtrend
4-31
dt r end
Purpose Remove t r ends fr om out put -input da t a.
Syntax zd = dtrend(z)
zd = dtrend(z,o,brkp)
Description z is a mat r ix, wit h dat a or ganized in column vect or s. dtrend r emoves t he t r end
fr om ea ch column and r et ur ns t he r esult in zd.
The defa ult (o = 0) r emoves t he zer o-t h or der t r ends, i.e., t he sample means ar e
subt r a ct ed.
Wit h o = 1, linear t r ends ar e r emoved, aft er a least -squar es fit . Wit h brkp not
specified, one single line is subt r a ct ed fr om t he ent ir e dat a r ecor d. A
cont inuous piecewise linea r t r end is subt r act ed if brkp cont ains br eakpoint s at
sample number s given in a r ow vect or .
Not e t hat dtrend differ s somewha t fr om detrend in t he Signal Pr ocessing
Toolbox.
Examples Remove a V-shaped t r end fr om t he out put wit h it s peak at sample number 119,
and r emove t he sample mean fr om t he input :
zd(:,1) = dtrend(z(:,1),1,119);
zd(:,2) = dtrend(z(:,2));
etfe
4-32
et fe
Purpose Est imat e empir ica l t r ansfer funct ions and per iodogr ams.
Syntax g = etfe(z)
g = etfe(z,M,N,T)
Description etfe est imat es t he t r ansfer funct ion g of t he gener a l linear model
The mat r ix z cont ains t he out put -input dat a z = [y u], wher e y and u ar e
column vect or s. The r out ine wor ks only for single-input , single-out put syst ems.
For a t ime ser ies, z = y. Then g is r et ur ned as t he per iodogr am of y.
g is given in fr equency funct ion for mat (see freqfunc), wit h t he est imat e of
at t he fr equencies
w = [1:N]/N∗pi/T
The defa ult va lues of N and T ar e 128 and 1, r espect ively. N must be a power of
t wo.
When M is specified ot her t han t he default value M = [ ], a smoot hing oper at ion
is per for med on t he r aw spect r al est imat es. The effect of M is t hen similar t o t he
effect of M in spa. This can be a useful alt er nat ive t o spa for na r r owband spect r a
and syst ems, which ot her wise r equir e lar ge values of M.
When etfe is applied t o t ime ser ies, t he cor r esponding spect r al est imat e is
nor malized in t he way t hat is defined in “Some Special Topics” on page 3-68.
Not e t hat t his nor maliza t ion may differ fr om t he one used by spectrum in t he
Signal Pr ocessing Toolbox.
Examples Compar e an empir ical t r ansfer funct ion est imat e t o a smoot hed spect r al
est ima t e:
ge = etfe(z);
gs = spa(z);
bodeplot([ge gs])
Algorithm The empir ica l t r ansfer funct ion est imat e is comput ed as t he r at io of t he out put
Four ier t r a nsfor m t o t he input Four ier t r ansfor m, using fft. The per iodogr am
y t ( ) G q ( )u t ( ) v t ( ) + =
G e
i ω
( )
etfe
4-33
is comput ed as t he nor ma lized absolut e squar e of t he Four ier t r a nsfor m of t he
t ime ser ies.
The smoot hed ver sions (M less t han t he lengt h of z) ar e obt ained by applying a
Hamming window t o t he out put FFT t imes t he conjugat e of t he input FFT, a nd
t o t he absolut e squar e of t he input FFT, r espect ively, a nd subsequent ly
for ming t he r at io of t he r esult s. The lengt h of t his Hamming window is equal
t o t he number of dat a point s in z divided by M, plus one.
See Also freqfunc, spa
ffplot
4-34
ffplot
Purpose Plot fr equency funct ions and spect r a.
Syntax ffplot(g)
ffplot([g1 g2 ... gn])
ffplot(g,sd,C,mode)
Description This funct ion has exact ly t he same synt ax as bodeplot. The only differ ence is
t hat it gives gr aphs wit h linear fr equency scales and Hz as t he fr equency unit .
See Also bodeplot, freqfunc, getff
fix par
4-35
fi xpar
Purpose Fix par amet er s in st r uct ur es defined by ms2th a nd arx2th.
Syntax thn = fixpar(tho,matrix)
thn = fixpar(tho,matrix,elements,parval)
Description The fixpar funct ion pr oduces a new model st r uct ur e thn in t he t het a for mat
fr om a n old one tho, by fixing cer t ain par amet er s t o cer t ain values. The mat r ix
tho must be or iginally defined by arx, arx2th, canstart, iv4, or ms2th but may
have been modified lat er on by fixpar, pem, thinit, or unfixpar.
To modify a st at e-space st r uct ur e
t he ar gument matrix is set equa l t o one of 'A', 'B', 'C', 'D','K', or 'x0'. The
ar gument elements is a mat r ix wit h t wo columns, in which each r ow specifies
t he indices of t he element in t he chosen syst em ma t r ix t hat need t o be fixed.
For example, t o fix t he 1,2-element and t he 3,5-element of t he A mat r ix use
thn = fixpar(tho,'A',[1,2;3,5]);
If t he ar gument elements is omit t ed (or ent er ed as t he empt y mat r ix) all
element s of t he indicat ed mat r ix will be fixed. In t his case parval can be given
a sca lar number , a nd a ll t he indicat ed element s will be fixed t o t hat number .
The default is t ha t t he element s ar e fixed t o t heir nominal (init ial or cur r ent ly
est imat ed) value. To fix t hem t o somet hing else use t he four t h input ar gument
parval. The r-t h ent r y of t his vect or cont ains t he value cor r esponding t o t he
element defined by t he r-t h r ow of elements.
To modify an ARX model
t he ar gument matrix is set equal t o one of 'A1', 'A2', ..., 'B0', 'B1', .... The
ar gument elements is t hen a mat r ix wit h t wo columns, wher e ea ch r ow gives
x
·
t ( ) A θ ( )x t ( ) B θ ( )u t ( ) K θ ( )e t ( ) + + =
y t ( ) C θ ( )x t ( ) D θ ( )u t ( ) e t ( ) + + =
y t ( ) A
1
y t 1 – ( ) A
2
y t 2 – ( ) … A
na
y t na – ( ) + + + + =
B
0
u t ( ) B
1
u t 1 – ( ) … B
nb
u t nb – ( ) e t ( ) + + + +
fix par
4-36
t he indices of t he element in t he chosen ARX ma t r ix t hat need t o be fixed. The
r ole of parval is t he same as for t he st at e-space case above.
The r out ine does not a pply t o special model st r uct ur es t ha t you have or iginally
defined using mf2th, or t o black-box input -out put models ot her t han ARX
models. Fixing cer t ain par amet er s ca n, in t hose ca ses, be achieved by using t he
t hir d ar gument in pem dur ing t he est ima t ion phase.
Examples Conver t ing a st at e-space st r uct ur e wit h a ll element s in t he Kalman gain
mat r ix K fr ee t o an out put er r or st r uct ur e in which K is fixed t o zer o.
thn = fixpar(thn,'K',[],0)
Fixing t he par a met er t o 1 in a scalar ARX model, and t hen est imat ing t he
r emaining pa r amet er s:
th = arx(z,[2 3 0]);
th = fixpar(th,'B2',[1,1],1);
th = pem(z,th);
See Also theta, thinit, unfixpar
b
2
freqfunc
4-37
fr eqfunc
Purpose Descr ibe t he fr equency-funct ion for ma t .
Syntax help freqfunc
Description Fr equency funct ions ar e cr eat ed by etfe, spa, and th2ff, and used by
bodeplot, ffplot, and nyqplot. The int er nal for mat of t he fr eqfunc for mat is
int ended t o be t r anspar ent . The basic way t o display t he infor mat ion is t o use
t he plot commands. You can also r et r ieve t he infor mat ion fr om t he for mat by
t he funct ion getff. This ent r y gives det ails of t he int er nal r epr esent at ion, but
t his infor mat ion is not necessar y for nor mal use of t he Syst em Ident ificat ion
Toolbox.
The fr eqfunc for mat cont ains infor mat ion about fr equency values, amplit udes,
and phases, as well as t heir st andar d deviat ions. These ar e all given as
columns. The fir st r ow of a freqfunc mat r ix cont ains int eger s, t hat , in coded
for m, descr ibe t he significance of t he column in quest ion. The int er pr et at ion of
t hese int eger s is as follows:
For t r ansfer funct ions and spect r a associat ed wit h out put number 1:
n = 0 : The column is a spect r um.
n = 50: The column cont ains st anda r d deviat ions of a spect r um.
n = 100: The column cont a ins fr equencies for t he spect r um.
n = k, wher e k is value bet ween 1 and 19: The column cont ains amplit ude
values for t he t r ansfer funct ion associat ed wit h input number k.
n = k + 20: The column cont ains phase values (in degr ees) for input number k.
n = k + 50: The column cont ains amplit ude st andar d deviat ions for input
number k.
n = k + 70: The column cont ains phase st andar d deviat ions for input number
k.
n = k + 100: The column cont ains t he fr equency values for input number k.
For t he same quant it ies associa t ed wit h out put number , add ∗1000
t o t he number s above.
ky ky 1 – ( )
freqfunc
4-38
The specified fr equencies ar e for a discr et e-t ime model, which is by default ,
equa lly spaced fr om 0 (excluded) t o over 128 values. Her e T is t he
sampling int er va l (default = 1). For a cont inuous-t ime model, t he fr equencies
ar e 128 values, logar it hmica lly spr ea d over t hr ee deca des, up t o a decade over
t he under lying Nyquist fr equency (see th2ff).
Examples You can comput e and gr aph t he fr equency funct ions a t ar bit r ar y fr equency w (a
r ow vect or wit h an ar bit r ar y number of element s) wit h
g = spa(z,M,w)
g = th2ff(th,ku,w)
The MATLAB funct ion logspace is useful for cr eat ing such fr equency vect or s.
See Also bodeplot, etfe, ffplot, getff, nyqplot, sett, spa, th2ff
π T ⁄
getff
4-39
get ff
Purpose Ret r ieve fr equency funct ions and spect r a fr om t he fr eqfunc for mat .
Syntax [w,amp,phas] = getff(g)
[w,amp,phas,sdamp,sdphas] = getff(g,ku,ky)
Description This funct ion ext r act s infor mat ion fr om t he fr eqfunc for mat for plot t ing as an
alt er nat ive t o bodeplot, ffplot, and nyqplot. Result s in t he fr eqfunc for mat
ar e obt ained by etfe, spa, and th2ff.
The ar gument g is t he fr equency funct ion or spect r um given in t he fr eqfunc
for mat . ku is t he chosen input number (only one) and ky is t he chosen out put
number . The noise sour ce is count ed as input number 0, so t hat ku = 0 will
ext r act spect r a l infor mat ion.
w is a vect or cont aining t he fr equency values (in r adians/second). amp cont ains
t he values of t he magnit ude (amplit ude) of t he fr equency funct ion and phas
cont ains t he phase values (in degr ees). The out put ar gument s sdamp and
sdphas cont ain t he cor r esponding st andar d deviat ions. All t his infor mat ion is
for input number ku and out put number ky. If sever al ent r ies in g cor r espond
t o t he same input -out put pair , t hen w, amp, phas, sdamp, and sdphas have t he
cor r esponding number of columns. The defa ult values of ku and ky a r e bot h 1,
unless g cont ains only spect r a. In t hat ca se getff ext r a ct s infor mat ion about
t he spect r um cor r esponding t o out put number ky.
Examples Make your own plot of t he per iodogr am wit h linear scales:
per = etfe(y);
[w,amp] = getff(per);
plot(w,amp)
title('Periodogram of seismic data')
getzp
4-40
get zp
Purpose Ext r act zer os and poles fr om t he zepo for mat .
Syntax [ze,po] = getzp(zepo)
[ze,po] = getzp(zepo,ku,ky)
Description The basic use of getzp is t o ext r a ct t he poles a nd zer os of t he coded for mat t hat
th2zp r esult s in. zepo cont ains t his infor mat ion and is t ypically t he out put of
th2zp. ku cont ains t he input number (just one) and ky t he out put number . The
noise sour ce number k is her e count ed a s input number –k.
ze cont ains t he zer os and po t he poles of t he dynamics associa t ed wit h input
number ku and out put number ky. The default values of ku and ky ar e bot h 1.
Not e t hat for t he noise dyna mics, zepo nor mally just cont a ins infor mat ion
about t he zer os a nd poles fr om noise sour ce k t o out put number k, (no cr oss
t er ms). To ext r act t his infor mat ion ent er
[ze,po] = getzp(zepo,0,k)
See Also th2zp, zpform, zpplot
getmfth, getncap, gett
4-41
get mft h , get ncap, get t
Purpose Ext r act infor mat ion fr om t he t het a for mat .
Syntax mymfile = getmfth(th)
N = getncap(th)
T = gett(th)
Description These funct ions r et r ieve some infor mat ion t hat is coded int o t he t het a for mat .
mymfile is t he name of t he M-file t hat you wr it e t o define a model st r uct ur e
cr eat ed by mf2th.
N is t he number of dat a, fr om which a cer t ain model th is est ima t ed. If t he
model is not est imat ed N is r et ur ned as [].
T is t he sampling int er va l of t he model th. If T is negat ive, t he model is a
cont inuous-t ime one t hat has been est imat ed fr om dat a wit h t he sa mpling
int er val abs(T).
See Also mf2th, sett
ident
4-42
ident
Purpose Open t he gr aphical user int er face
Syntax ident
ident(session,directory)
Description ident by it self opens t he main int er face window, or br ings it for war d if it is
alr eady open.
session is t he name of a pr evious session wit h t he gr a phical int er fa ce, and
t ypically has ext ension .sid. directory is t he complet e pat h for t he locat ion of
t his file. If t he session file is on t he MATLABPATH, directory can be omit t ed.
When t he session is specified, t he int er face will open wit h t his session act ive.
Typing ident(session,directory) on t he MATLAB comma nd line, when t he
int er face is act ive, will load and open t he session in quest ion.
For mor e infor mat ion about t he gr aphical user int er face, see Chapt er 2 of t his
manual.
Examples ident(‘iddata1.sid’)
ident(‘mydata.sid’,’\matlab\data\cdplayer\’)
idfilt
4-43
idfil t
Purpose Filt er dat a using But t er wor t h filt er s.
Syntax zf = idfilt(z,ord,Wn)
[zf,thf] = idfilt(z,ord,Wn,hs)
Description idfilt comput es a But t er wor t h filt er of or der ord and filt er s all columns of t he
dat a mat r ix
z = [y u]
t hr ough t his filt er .
If hs is not specified and Wn cont ains just one element , a low pass filt er wit h
cut off fr equency Wn (measur ed as a fr act ion of t he Nyquist fr equency) is
obt ained. If hs =' high' a high pass filt er wit h t his cut off fr equency is
obt ained inst ead.
If Wn = [Wnl Wnh] is a vect or wit h t wo element s, a filt er (of or der 2*ord) wit h
passband bet ween Wnl and Wnh is obt ained is hs is not specified. If
hs = 'stop' a bandst op filt er wit h st op band bet ween t hese t wo fr equencies is
obt ained inst ead.
The out put ar gument thf is t he filt er given in t he t het a for mat .
It is common pr act ice in ident ificat ion t o select a fr equency band wher e t he fit
bet ween model a nd da t a is concent r at ed. Oft en t his cor r esponds t o bandpass
filt er ing wit h a pass band over t he int er est ing br eakpoint s in a Bode diagr am.
If ord is a posit ive int eger , a non-causa l, zer o-phase filt er is used for t he
filt er ing. If or d is a negat ive int eger , a causal filt er (of or der abs(ord)) is used
inst ead.
Algorithm The used filt er is t he same as butter in t he Signal Pr ocessing Toolbox would
give. Also, t he zer o-phase filt er is equiva lent t o filtfilt in t hat t oolbox.
References Ljung (1987), Chapt er 13.
idinput
4-44
idinput
Purpose Gener at e signals, t ypically t o be used as input s for ident ificat ion.
Syntax u = idinput(N)
u = idinput(N,type,band,levels)
u = idinput(N,'sine',band,levels,auxvar)
Description idinput gener at es input signals of differ ent kinds, t hat ar e t ypically used for
ident ificat ion pur poses. Only scala r input s ar e gener at ed.
N is t he number of dat a point s gener at ed, i.e., t he lengt h of u.
type defines t he t ype of input signal t o be gener at ed. This ar gument t akes one
of t he following values:
• type = 'rs' : This gives a r andom, Gaussian signal.
• type = 'rbs': This gives a r andom, binar y signal.
• type = 'prbs': This gives a pseudo-r andom, bina r y signal.
• type = 'sine': This gives a signal which is a sum of sinusoids.
Default is type = 'rbs'.
The fr equency cont ent s of t he signal is det er mined by t he a r gument band. For
t he choices type = 'rs', 'rbs', a nd 'sine', t his ar gument is a r ow-vect or wit h
t wo ent r ies
band = [wlow, whigh]
t hat det er mine t he lower and upper bound of t he pass-band. The fr equencies
wlow and whigh ar e expr essed in fr act ions of t he Nyquist fr equency. A whit e
noise char act er input is t hus obt ained for band = [0 1], which also is t he
default va lue.
For t he choice type = 'prbs' we have
band = [twologp, M]
wher e t he per iodicit y of t he gener at ed PRBS is 2^twologp –1, and M is such
t hat t he signal is const ant over int er vals of lengt h 1/M. twologp = 0 gives t he
maximum lengt h PRBS, cor r esponding t o twologp = 18. Also in t his ca se t he
default is band = [0 1].
idinput
4-45
The ar gument levels defines t he input level. It is a r ow vect or
levels = [minu, maxu]
such t hat t he signal u will a lways be bet ween t he values minu and maxu for t he
choices type = 'rbs', 'prbs' and 'sine'. For type = 'rs', t he signal level
is such t hat minu is t he mean value of t he signal, minus one st andar d deviat ion,
while maxu is t he mean value plus one st andar d deviat ion. Gaussian whit e
noise wit h zer o mean a nd var iance one is t hus obt ained for
levels = [–1, 1], which is also t he default value.
For t he opt ion type = 'sine', t her e is a four t h ar gument
auxvar = [no_of_sinusoids, no_of_trials]
det er mining t he number of sinusoids t o be used in t he input signal. The
var iable no_of_trials det er mines how many t r ials t o be made t o minimize t he
signal amplit ude by assigning r andom phases t o t he differ ent sinusoids.
Default is auxvar = [10, 10].
Algorithm Ver y simple algor it hms ar e used. The fr equency cont ent s is achieved for 'rs'
by an eight h or der But t er wor t h, non-causal filt er , using idfilt. This is quit e
r elia ble. The same filt er is used for t he 'rbs' case, befor e making t he signal
binar y. This means t hat t he fr equency cont ent s is not guar ant eed t o be pr ecise
in t his case.
For t he 'sine' case, t he fr equencies ar e select ed t o be equally spr ea d over t he
chosen pass band, and each sinusoid is given a r andom phase. A number of
t r ials ar e made, and t he pha ses t hat give t he smallest signal amplit ude ar e
select ed. (The amplit ude is t hen sca led so as t o sat isfy t he specifica t ions of
levels.)
See Also The Fr equency Domain Syst em Ident ificat ion Toolbox cont ains sever al
commands for input design t hat ut ilize mor e sophist icat ed algor it hms.
Reference For PRBS, see, e.g., Söder st r öm and St oica (1989), Chapt er C5.3.
idmodred
4-46
idmodr ed
Purpose Reduce t he or der of a model in t het a for mat .
Syntax THRED = idmodred(TH)
THRED = idmodred(TH,ORDER,OE)
Description This funct ion r educes t he or der of any model TH given in t he t het a for mat . The
r esult ing r educed or der model THRED is also in t he t het a for mat . This r educed
model is always r epr esent ed int er na lly in st at e-space for m wit h no fr ee
par amet er s, r egar dless of t he nat ur e of t he model TH.
The funct ion r equir es sever al r out ines in t he Cont r ol Syst ems Toolbox.
ORDER: The desir ed or der (dimension of t he st at e-space r epr esent at ion). If
ORDER = [], which is t he default , a plot will show how t he diagonal element s
of t he obser vabilit y and cont r ollabilit y Gr amians decay wit h t he or der of t he
r epr esent at ion. You will t hen be pr ompt ed t o select an or der based on t his plot .
The idea is t hat such a small element will have a negligible influence on t he
input -out put beha vior of t he model. It is t hus suggest ed t hat an or der is chosen,
such t hat only lar ge element s in t hese mat r ices ar e r et ained.
OE: If t he ar gument OE has t he va lue ’oe’, t hen an out put er r or model THRED is
pr oduced, t hat is, one wit h t he Ka lman gain equal t o zer o (see (3.27) a nd (3.31)
in Chapt er 3, "Tut or ial"). Ot her wise (default ), also t he noise model is r educed.
The funct ion will r ecognize whet her TH is a cont inuous- or discr et e-t ime model
and per for m t he r educt ion accor dingly. The r esult ing model THRED will be of t he
same kind in t his r espect as TH.
Algorithm The funct ions (d)balreal and (d)modred fr om t he Cont r ol Syst ems Toolbox
ar e used. The plot , in case ORDER = [], shows t he vect or g as r et ur ned fr om
(d)balreal.
Examples Build a high or der mult ivar iable ARX model, r educe it s or der t o 3 and compar e
t he fr equency r esponses of t he or iginal and r educed models:
TH = arx([y u],[4∗ones(3,3),4∗ones(3,2),ones(3,2)]);
THRED = idmodred(TH,3);
bodeplot([trf(TH),trf(THRED)])
idmodred
4-47
Use t he r educed or der model a s init ia l condit ion for a t hir d or der st at e-space
model:
THI = ss2th(THRED);
THSS = pem([y u],THI);
See Also ss2th
idplot
4-48
idpl ot
Purpose Plot input -out put dat a.
Syntax idplot(z)
idplot(z,int,T,ny,pc)
Description z is t he out put -input da t a z = [y u] t o be gr aphed. A split plot is obt ained wit h
t he out put on t op and t he input s, one by one if sever a l, at t he bot t om. Pr essing
t he Re t urn key advances t he plot .
The dat a point s specified in t he r ow vect or int a r e gr a phed. The default value
of int is a ll t he dat a. You can use t he sampling int er va l T (default T = 1) t o
give cor r ect t ime axes.
The ar gument ny is t he number of out put s in t he dat a mat r ix. Default is
ny = 1. The input is piecewise const ant bet ween sampling point s, and it is
gr aphed accor dingly. If you pr efer linear int er polat ion bet ween input dat a
point s, use pc = 'li'. The default value is pc = 'pc'.
Examples Plot only a por t ion of t he dat a point s:
idplot(z,100:200)
idresamp
4-49
idr esamp
Purpose Resample dat a by int er polat ion and decima t ion.
Syntax zr = idresamp(z,R)
[zr, R_act] = idresamp(z,R,filter_order,tol)
Description z : The dat a t o be r esampled. Each column of z cont ains a signal.
zr : The r esampled dat a. The columns of zr cor r espond t o t hose of z.
R : The r esa mpling fact or . The new dat a r ecor d will cor r espond t o a new
sampling int er val of R t imes t he or iginal one. R > 1 t hus cor r esponds t o
decimat ion and R < 1 cor r esponds t o int er polat ion. Any posit ive r eal number
for R is allowed, but it will be r eplaced by a r at ional appr oxima t ion (R_act).
R_act : The act ually achieved r esampling fa ct or .
filter_order: The or der of t he pr esampling filt er s used befor e int er polat ion
and decimat ion. Default is 8.
tol : The t oler ance in t he r a t ional appr oximat ion of R. Default is 0.1.
Algorithm The r esampling fact or is fir st appr oximat ed by a r at iona l number by
[num,den] = rat(R,tol). The dat a ar e t hen int er polat ed by a fact or den and
t hen decimat ed by a fa ct or num. The int er polat ion and decima t ion ar e pr eceded
by pr efilt er ing, and follow t he same a lgor it hms a s in t he r out ines interp a nd
decimate in t he Signal Pr ocessing Toolbox.
Caution For signals t hat have much ener gy ar ound t he Nyquist fr equency (like
piece-wise const ant input s), t he r esampled wavefor m may look “ver y differ ent ,”
due t o t he pr efilt er ing effect s. The fr equency and infor mat ion cont ent s for
ident ificat ion is, however , not mishandled.
Example Resample by a fa ct or 1.5 and compar e t he signals.
plot(t,u)
[ur,ra] = idresamp(u,1.5);
plot(t,u,ra∗t,ur)
idsim
4-50
idsi m
Purpose Simulat e syst ems specified in t het a for mat .
Syntax y = idsim([u e],th)
[y, ysd] = idsim(u,th)
Description th descr ibes an ar bit r ar y model in t he t het a for mat . idsim r et ur ns y cont aining
t he simulat ed out put , cor r esponding t o t he input sequence u (one column for
each input ) and t he noise e. If e is omit t ed, a noise-fr ee simulat ion is obt ained.
The noise-sequence e is scaled by , wher e is t he noise var iance (loss
funct ion) as specified by th. To a chieve t he cor r ect noise effect , give e zer o mean
and unit var iance.
For mult i-out put syst ems simulat ed wit h noise, e should have as many
columns as t he number s of out put s. The noise is aga in sca led using t he noise
covar ia nce mat r ix in th.
The second out put ar gument is t he st andar d deviat ion of t he simulat ed out put .
This opt ion is however not available for st at e-space models.
If th is a cont inuous-t ime model, it is fir st conver t ed t o discr et e t ime wit h
sampling int er va l abs(T). See “Some Specia l Topics” on page 3-68
Examples Simulat e a given syst em th0 (for example cr eat ed by poly2th):
e = randn(500,1);
u = idinput(500,’prbs’);
y = idsim([u e],th0);
Validat e a model by compar ing a measur ed out put y wit h one simulat ed using
an est imat ed model th:
yh = idsim(u,th);
plot([y yh])
Algorithm In ca se t he model is of input -out put t ype, idsim uses t he MATLAB filter
funct ion. For st at e-space models, it uses ltitr.
See Also idsimsd, poly2th
λ λ
idsimsd
4-51
idsi msd
Purpose Simulat e t het a for mat syst em wit h uncer t aint y.
Syntax idsimsd(u,th)
idsimsd(u,th,N,noise)
Description u is a column vect or (mat r ix) cont aining t he input (s). th is a model given in t he
t het a for ma t (see theta). N r andom models ar e cr eat ed, a ccor ding t o t he
covar iance infor mat ion given in th. The r esponses of ea ch of t hese models t o
t he input u ar e comput ed and gr aphed in t he same diagr am. If
noise = 'noise', noise is added t o t he simulat ion, in accor dance wit h t he noise
model of th, and it s own uncer t aint y.
The default values a r e
N = 10
noise = 'nonoise'
Examples Plot t he st ep r esponse of t he model th and evaluat e how it var ies in view of t he
model’s uncer t aint y:
step1 = [zeros(5,1); ones(20,1)];
idsimsd(step1,th)
See Also idsim, th2ff, th2zp
ivar
4-52
ivar
Purpose Est imat e t he pa r amet er s of an AR model using an appr oximat ely opt imal
choice of inst r ument a l var ia ble pr ocedur e.
Syntax th = ivar(y,na)
th = ivar(y,na,nc,maxsize,T)
Description The pa r amet er s of an AR model st r uct ur e
ar e est ima t ed using t he inst r ument al var iable met hod. y is t he signa l t o be
modeled, ent er ed as a column vect or . na is t he or der of t he A polynomial (t he
number of A par amet er s). The r esult ing est ima t e is r et ur ned as th, in t het a
for mat . The r out ine is for scalar signa ls only.
In t he above model, is an ar bit r ar y pr ocess, assumed t o be a moving
aver age pr ocess of or der nc, possibly t ime var ying. (Default is nc = na.)
Inst r ument s ar e chosen as appr opr iat ely filt er ed out put s, delayed nc st eps.
The opt ional ar gument s maxsize and T ar e expla ined under auxvar.
Examples Compar e spect r a for sinusoids in noise, est imat ed by t he IV met hod and
est ima t ed by t he for war d-ba ckwar d least -squar es met hod:
y = sin([1:500]'∗1.2) + sin([1:500]'∗1.5)...
+ 0.2∗randn(500,1);
thiv = ivar(y,4);
thls = ar(y,4);
giv = th2ff(thiv);
gls = th2ff(thls);
bodeplot([giv gls])
See Also ar, etfe, spa
References St oica, P. et al., Opt imal Inst rumental variable est imates of the AR-paramet ers
of an ARMA process, IEEE Tr ans. Aut om. Cont r ol, Vol AC-30, 1985, pp.
1066-1074.
A q ( )y t ( ) v t ( ) =
v t ( )
ivstruc
4-53
ivst r uc
Purpose Comput e fit bet ween simulat ed a nd measur ed out put for a gr oup of model
st r uct ur es.
Syntax v = ivstruc(ze,zv,NN)
v = ivstruc(ze,zv,NN,p,maxsize)
Description NN is a mat r ix t hat defines a number of differ ent st r uct ur es of t he ARX t ype.
Each r ow of NN is of t he for m
nn = [na nb nk]
wit h t he same int er pr et at ion as descr ibed for arx. See struc for easy
gener at ion of t ypica l NN mat r ices for single-input syst ems.
Each of ze and zv ar e ma t r ices cont a ining out put -input dat a [y u]. For
mult i-input syst ems, u has t he cor r esponding number of columns. Models for
each model st r uct ur e defined in NN a r e est imat ed using t he inst r ument al
var iable (IV) met hod on dat a set ze. The est imat ed models a r e simulat ed using
t he input s fr om dat a set zv. The nor malized quadr at ic fit bet ween t he
simulat ed out put and t he measur ed out put in zv is for med and r et ur ned in v.
The r ows below t he fir st r ow in v ar e t he t r anspose of NN, and t he last r ow
cont ains t he logar it hms of t he condit ion number s of t he IV ma t r ix
A lar ge condit ion number indicat es t hat t he st r uct ur e is of unnecessar ily high
or der (see page 415 in Ljung (1987)).
The infor mat ion in v is best ana lyzed using selstruc.
If p is equal t o zer o, t he comput a t ion of condit ion number s is suppr essed. For
t he use of maxsize, see auxvar.
The r out ine is for single-out put syst ems only.
IMPORTANT: The IV met hod used does not guar ant ee t hat t he obt ained
models a r e st able. The out put -er r or fit calcula t ed in v may t hen be mislea ding.
ς t ( )ϕ
T
t ( )

ivstruc
4-54
Examples Compar e t he effect of differ ent or der s and delays, using t he same dat a set for
bot h t he est imat ion and va lidat ion:
v = ivstruc(z,z,struc(1:3,1:2,2:4));
nn = selstruc(v)
th = iv4(z,nn);
Algorithm A maximum or der ARX model is comput ed using t he least -squar es met hod.
Inst r ument s ar e gener at ed by filt er ing t he input (s) t hr ough t his model. The
models ar e subsequent ly obt ained by oper at ing on submat r ices in t he
cor r esponding lar ge IV mat r ix.
See Also arxstruc, iv4, selstruc, struc
ivx
4-55
ivx
Purpose Est imat e t he pa r amet er s of an ARX model using t he inst r ument al var iable (IV)
met hod wit h a r bit r ar y inst r ument s.
Syntax th = ivx(z,nn,x)
th = ivx(z,nn,x,maxsize,T)
Description ivx is a r out ine a nalogous t o t he iv4 r out ine, except t hat you can use ar bit r a r y
inst r ument s. These a r e cont a ined in t he mat r ix x. Ma ke t his t he same size as
t he out put , i.e., t he fir st column(s) of z. The inst r ument s used ar e t hen
ana logous t o t he r egr ession vect or it self, except t ha t y is r eplaced by x.
Not e t hat ivx does not r et ur n any est imat ed covar iance mat r ix for th, since
t hat r equir es addit ional infor mat ion.
Use iv4 as t he basic IV r out ine for ARX model st r uct ur es. The ma in int er est in
ivx lies in it s use for nonst a ndar d sit uat ions; for example when t her e is
feedba ck pr esent in t he dat a , or when ot her inst r ument s need t o be t r ied out .
Not e t ha t t her e is also an IV ver sion t hat aut omat ica lly gener a t es inst r ument s
fr om cer t ain filt er s you define (t ype help iv).
See Also iv4, ivar
References Ljung (1987), page 198.
iv4
4-56
iv4
Purpose Est imat e t he pa r amet er s of an ARX model using a n appr oximat ely opt imal
four -st age inst r ument al var iable (IV) pr ocedur e.
Syntax th = iv4(z,nn)
th = iv4(z,nn,maxsize,T)
Description This r out ine is an alt er nat ive t o arx and t he use of t he ar gument s ar e ent ir ely
analogous t o t he arx funct ion. The main differ ence is t hat t he pr ocedur e is not
sensit ive t o t he color of t he noise t er m in t he model equat ion.
For an int er pr et at ion of t he loss funct ion (innova t ions covar iance mat r ix),
consult “Some Special Topics” on pa ge 3-68.
Examples Her e is an example of a t wo-input one-out put syst em wit h differ ent delays on
t he input s and :
z = [y u1 u2];
nb = [2 2];
nk = [0 2];
th = iv4(z,[2 nb nk]);
Algorithm The fir st st age uses t he arx funct ion. The r esult ing model gener at es t he
inst r ument s for a second-st age IV est imat e. The r esiduals obt ained fr om t his
model ar e modeled as a high-or der AR model. At t he four t h st age, t he
input -out put dat a ar e filt er ed t hr ough t his AR model a nd t hen subject ed t o t he
IV funct ion wit h t he same inst r ument -filt er s a s in t he second st a ge.
For t he mult i-out put case, opt imal inst r ument s ar e obt a ined only if t he noise
sour ces at t he differ ent out put s have t he same color . The est ima t es obt ained
wit h t he r out ine ar e r easonably accur at e t hough even in ot her cases.
See Also arx, oe
References Ljung (1987), equat ions (15.21)-(15.26).
e t ( )
u
1
u
2
mf2th
4-57
mf2t h
Purpose Package model st r uct ur es you define int o t he t het a model for mat .
Syntax th = mf2th(model,cd,parval)
th = mf2th(model,cd,parval,aux,lambda,T)
Description th is r et ur ned as a model st r uct ur e in t he t het a for mat . model is t he name of
an M-file t ha t defines how t he st at e-spa ce ma t r ices depend on t he par amet er s
t o be est imat ed. The for mat of t his M-file is given below. The ar gument cd must
be a ssigned eit her t he value 'c' which designat es t hat t he under lying
par a met er izat ion r efer s t o a cont inuous-t ime model, or t he va lue 'd',
indicat ing t ha t t he model par amet er izat ion is inher ent ly a discr et e-t ime one.
The a r gument parval cont ains t he nominal values of t he par amet er s. This is a
r ow vect or of t he same lengt h as t he number of fr ee par amet er s in t he model
st r uct ur e. The a r gument aux is a mat r ix of auxiliar y var iables t ha t t he M-file
ca n use for var ious pur poses.
T denot es t he sampling int er val of t he dat a, for which t he model is going t o be
est imat ed (and t he sampling int er va l t hat is used when t he model is used for
simulat ion and pr edict ion). Give T a posit ive value even if t he under lying model
is defined t o be cont inuous t ime.
The model st r uct ur e cor r esponds t o t he gener al linea r st at e-spa ce st r uct ur e
The mat r ices in t his t ime-discr et e model can be par a met er ized in an ar bit r ar y
way by t he vect or . Wr it e t he for mat for t he M-file a s follows:
[A,B,C,D,K,x0] = mymfile(pars,T,aux)
Her e t he r ow vect or pars cont ains t he par amet er s , and t he out put
ar gument s A, B, C, D, K, and x0 ar e t he mat r ices in t he discr et e-t ime model
descr ipt ion t hat cor r espond t o t his value of t he par amet er s.
x t T + ( ) A θ ( )x t ( ) B θ ( )u t ( ) K θ ( )e t ( ) + + =
x 0 ( ) x
0
θ ( ) =
y t ( ) C θ ( )x t ( ) D θ ( )u t ( ) e t ( ) + + =
θ
θ
mf2th
4-58
T is t he sa mpling int er val, and aux is any mat r ix of auxiliar y var iables wit h
which you want t o wor k. (In t hat wa y you can change cer t ain const ant s and
ot her aspect s in t he model st r uct ur e wit hout having t o edit t he M-file.) Not e
t hat t he t wo ar gument s T and aux must be included in t he funct ion head of t he
M-file, even if t hey ar e not ut ilized wit hin t he M-file.
If t he under lying pa r amet er izat ion is a cont inuous-t ime one, it is st ill t he
discr et e-t ime model mat r ices, cor r esponding t o t he sampling int er val T t ha t
should be deliver ed by t he M-file. However . it is desir able t hat if t he M-file
myfile is called wit h a negat ive value of T, it out put s t he mat r ices of t he
cor r esponding cont inuous-t ime st at e-space model. If such a feat ur e is included
in t he M-file, use cd = 'c'. This allows for easy t r a nsfor ma t ions bet ween
cont inuous and discr et e t ime using t he nor mal funct ions thc2thd and thd2thc.
“Defining Model St r uct ur es” on page 3-29 cont ains sever al examples of t ypical
M-files t hat define model st r uct ur es.
Examples Use t he M-file 'mynoise' given in Sect ion 6 t o obt ain a physica l
par amet r iza t ion of t he Ka lman gain:
thn = mf2th('mynoise','d',[0.1,–2,1,3,0.2],1)
th = pem(z,thn)
midprefs
4-59
midpr efs
Purpose Select a dir ect or y for idprefs.mat, a file t hat st or es t he gr aphica l user
int er face’s st ar t -up infor mat ion.
Syntax midprefs
midprefs(path)
Description The gr a phica l user int er face ident allows a lar ge number of var iables for
cust omized choices. These include t he window layout , t he defa ult choices of
plot opt ions, and names and dir ect or ies of t he four most r ecent sessions wit h
ident. This infor mat ion is st or ed in t he file idprefs.mat, which should be
placed on t he user ’s MATLABPATH. The default , aut omat ic locat ion for t his file is
in t he sa me dir ect or y as t he user ’s startup.m file.
midprefs is used t o select or change t he dir ect or y wher e you st or e
idprefs.mat. Eit her t ype midprefs, and follow t he inst r uct ions, or give t he
dir ect or y name as t he ar gument . Include all dir ect or y delimit er s as in t he PC
ca se
midprefs('c:\matlab\toolbox\local\')
or in t he UNIX case
midprefs('/home/ljung/matlab/')
Warning The file idprefs.mat cont ains a var iable wit h t he dir ect or y name, which also
needs t o be updat ed. Ther efor e, do not just move it using t he file syst em.
Alwa ys use midprefs t o cha nge t he dir ect or y for idprefs.mat.
modstruc
4-60
modst r uc
Purpose Define st a t e-space st r uct ur e wit h unknown element s.
Syntax ms = modstruc(A,B,C,D,K)
ms = modstruc(A,B,C,D,K,x0)
Description modstruc is, like canform, a funct ion t hat defines model par amet er iza t ions in
st a t e-space for m, which ar e used in ms2th t o cr ea t e model st r uct ur es in t he
t het a for mat . The only use of t he r esult ing ma t r ix ms is as an input t o ms2th.
The model consider ed is in st at e-spa ce for m:
The funct ion applies bot h t o t he cont inuous and discr et e-t ime cases; which one
is det er mined only when t he st r uct ur e is for med wit h ms2th.
The input ar gument s A, B, C, D, K, and x0 ar e t he ma t r ices of t he above
st a t e-space model. Numer ical values in t hese mat r ices indicat e fixed (known)
ent r ies, while t he symbol NaN ma r ks an element t hat is not known and you
need t o est imat e.
The default value of t he init ial st at e vect or x0 is t he zer o vect or , but it may a lso
cont ain par amet er s you need t o est imat e.
Examples Define a cont inuous-t ime model st r uct ur e in diagonal for m wit h t he t wo
(r eal) poles a nd t he numer at or unknown:
A = [NaN,0;0,NaN];
B = [NaN;NaN];
C = [1,1];
D = 0;
K = [0;0];
ms = modstruc(A,B,C,D,K)
th = ms2th(ms,'c');
See Also canform, fixpar, ms2th, thinit, unfixpar
x
·
t ( ) A θ ( )x t ( ) B θ ( )u t ( ) K θ ( )e t ( ) + + =
x 0 ( ) x
0
θ ( ) =
y t ( ) C θ ( )x t ( ) D θ ( )u t ( ) e t ( ) + + =
ms2th
4-61
ms2t h
Purpose Package st a ndar d st at e-space par amet er izat ions int o t he t het a model for mat .
Syntax th = ms2th(ms)
th = ms2th(ms,cd,parval,lambda,T)
Description The funct ion r et ur ns th as a model st r uct ur e in t he t het a for mat for fur t her use
in est ima t ing, simulat ing, and a nalyzing models. The ar gument ms defines
which par a met er s ar e fixed and which ones you need t o est ima t e. It is t ypically
for med by modstruc or canform.
The ar gument cd indicat es whet her t he st at e-space mat r ices in ms r efer t o a
cont inuous-t ime model (cd = 'c') or a discr et e-t ime model (cd = 'd').
cd = 'd' is t he defa ult .
For a cont inuous-t ime model t her e ar e t wo opt ions for how t o sa mple it , as it is
fit t ed t o obser ved sample dat a (in pem): By select ing cd = ‘czoh’ (cont inuous,
zer o or der hold) t he input is assumed t o be piecewise const a nt over t he
sampling int er val. By select ing cd = ‘cfoh’ (cont inuous, fir st or der hold), t he
input is supposed t o be piecewise linear bet ween t he samples. This means t hat
t he cont inuous-t ime input u(t ) is obt ained by linea r int er polat ion bet ween t he
sampled values. Use cd = ‘czoh’ (which is t he default for cont inuous-t ime
models) if t he syst em has been cont r olled using a piece-wise const ant input .
Use cd = 'cfoh' if t he input has been a cont inuous funct ion dur ing t he dat a
acquisit ion.
The r ow vect or parval cont a ins t he nominal values of t he fr ee par amet er s
(t hose t hat cor r espond t o NaN in ms). These nominal va lues ar e used as init ial
est imat es when t he par amet er s in th ar e ident ified wit h pem. They ar e also
used whenever t he model th is simulat ed or analyzed. The default value of
parval is all zer os.
The number ing of t he par amet er s in parval (as well as in all ot her cont ext s
in which t he model par a met er s ar e list ed) is as follows. The mat r ix A is fir st
scanned, r ow by r ow, for fr ee par amet er s, t hen t he mat r ix B is scanned, again
r ow by r ow, and t hen C, D, K, a nd X0 ea ch of t hem r ow by r ow. The or der in
which t he fr ee par amet er s ar e found by t his scanning defines t he or der ing in
parval.
ms2th
4-62
Not e t hat set t ing all init ial est imat es equal t o zer o is not a good st ar t ing point
for t he it er a t ive sear ch for par amet er est imat es in pem, since t his case oft en
cor r esponds t o a nonobser vable/noncont r olla ble model. It is bet t er t o give mor e
r ealist ic values of parval or t o r andomize t hem using thinit.
The a r gument lambda gives t he covar iance ma t r ix of t he innovat ion for t he
sampling int er val indicat ed in T. The default value of lambda is t he unit mat r ix.
T denot es t he sampling int er val of t he dat a, for which t he model is going t o be
est ima t ed (and t he sampling int er va l t hat is used when t he model is used for
simulat ion and pr edict ion). Give T a posit ive value even if t he under lying model
is defined t o be cont inuous t ime.
Examples Define a cont inuous-t ime model st r uct ur e cor r esponding t o
wit h init ial values
and est ima t e t he fr ee par a met er s:
A = [NaN,0;0,NaN];
B = [NaN;NaN];
C = [1,1];
ms = modstruc(A,B,C,0,[0;0]);
th = ms2th(ms,'c',[–0.2,–0.3,2,4]);
th = pem(z,th);
See Also canform, fixpar, modstruc, pem, thinit, unfixpar
e t ( )
x
·
θ
1
0
0 θ
2
x
θ
3
θ
4
u + =
y
1 1
x e + =
θ
0.2 – 0.3 – 2 4
=
nuderst
4-63
nuder st
Purpose Select t he st ep size for numer ica l differ ent iat ion.
Syntax nds = nuderst(pars)
Description The funct ion pem uses numer ica l differ ent iat ion wit h r espect t o t he model
par a met er s when a pplied t o st at e-space st r uct ur es. The same is t r ue for t he
funct ions th2ff and th2zp when t he par amet er covar iance infor mat ion is
t r anslat ed t o fr equency funct ion and zer o-pole accur acy (again only for
st a t e-space st r uct ur es). Finally, t he comma nd thd2thc uses numer ical
differ ent iat ion when t r anslat ing t he covar iance infor mat ion for any model
st r uct ur e.
The st ep size used in t hese numer ical der ivat ives is det er mined by t he M-file
nuderst. The out put ar gument nds is a r ow vect or whose k-t h ent r y gives t he
incr ement t o be used when differ ent iat ing wit h r espect t he k-t h element of t he
par a met er vect or pars.
The default ver sion of nuderst uses a ver y simple met hod. The st ep size is t he
maximum of and t imes t he absolut e value of t he cur r ent pa r amet er .
You can adjust t his t o t he act ual va lue of t he cor r esponding par amet er by
edit ing nuderst. Not e t ha t t he nominal va lue, for example 0, of a par amet er
may not r eflect it s nor ma l size.
10
7 –
10
4 –
nyqplot
4-64
nyqplot
Purpose Plot Nyquist cur ve of fr equency funct ion.
Syntax nyqplot(g)
nyqplot([g1 g2 ... gn])
nyqplot(g,sd,mode)
Description nyqplot is an alt er na t ive t o bodeplot and ffplot t o gr aph fr equency funct ions
in t he fr eqfunq for ma t . The Nyquist diagr am of a fr equency funct ion is a gr aph
of it s imaginar y par t against it s r eal par t .
The ar gument g is t he fr equency funct ion in quest ion, given in t he fr eqfunc
for mat , t ypically as t he out put of th2ff, spa, or etfe. Sever al plot s ar e
obt ained in t he same diagr am by simply list ing t he differ ent fr equency
funct ions aft er each ot her . These need not be specified at t he same fr equencies
(alt hough t hey have t o be of t he same lengt h).
If t he fr equency funct ion(s) cont ains infor mat ion about sever al differ ent
input -out put pair s, t he default is t hat t he Nyquist plot for each pair is gr a phed
separ at ely. Pr essing t he Re t urn key advances fr om one pair t o t he next . Wit h
mode = 'same' all plot s cor r esponding t o t he same input ar e given in t he same
diagr am.
If sd is given a value lar ger t han 0, a confidence r egion ar ound t he nominal
Nyquist plot is mar ked wit h dash-dot t ed lines. This r egion cor r esponds t o sd
st a ndar d deviat ions. (The infor mat ion in g does not cont ain t he cor r elat ion
bet ween t he magnit ude and phase est imat es. The confidence r egion is
t her efor e only appr oximat e. It is comput ed by plot t ing t he t wo cur ves ,
wher e is t he st a ndar d deviat ion (ma gnit ude a nd phase) of g.)
Examples g = th2ff(thmod)
nyplot(g,3)
See Also bodeplot, etfe, ffplot, freqfunc, spa, th2ff
g sd g ∆ t
g ∆
n4sid
4-65
n4sid
Purpose Est imat e st at e-space models using a subspace met hod.
Syntax TH = n4sid(z)
[TH,AO] = n4sid(z,order,ny,auxord,dkx,maxsize,T,'trace')
Description The funct ion n4sid est imat es models in st at e-space for m, and r et ur ns t hem in
t he t het a for mat . It handles an ar bit r ar y number of input and out put s,
including t he t ime ser ies case (no input ). The st a t e-space model is in t he
innovat ions for m:
x(t+1) = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
TH: The r esult ing model in t het a for mat . No covar iance infor mat ion a bout t he
uncer t aint y of t he model is cont ained in TH.
AO: See under auxord below.
z: A ma t r ix t hat cont ains t he out put -input dat a: z = [y u], wher e y and u ar e
column vect or s. In t he mult i-var iable case, u a nd y cont ain one column for each
out put a nd input . In t he t ime ser ies ca se z = y.
order: The desir ed or der of t he st at e-space model. If order is ent er ed as a r ow
vect or (like order = [1:10], which is t he default choice), pr elimina r y
ca lculat ions for all t he indicat ed or der s ar e car r ied out . A plot will t hen be
given t hat shows t he r ela t ive impor t ance of t he dimension of t he st a t e vect or .
Mor e pr ecisely, t he singular values of t he Hankel mat r ices of t he impulse
r esponse for differ ent or der s ar e gr a phed. You will be pr ompt ed t o select t he
or der , based on t his plot . The idea is t o choose an or der such t hat t he singular
values for higher or der s ar e compar a t ively small. If order = 'best', a model
of “best ” (default choice) or der is comput ed, among t he or der s 1:10.
ny: The number of out put s in t he dat a set z. Default is ny = 1.
auxord: An “auxiliar y or der ” used by t he algor it hm. This can be seen as a
pr edict ion hor izon, and it should be lar ger t ha n t he or der . The default value is
auxord = 1.2∗order+3. The choice of auxord could ha ve a subst ant ial influence
on t he model qualit y, and t her e ar e no simple r ules for how t o choose it . If you
ent er auxord as a r ow vect or (like auxord = [5:15]), models for all t hese values
will be comput ed. The pr edict ion er r or for each of t he models ar e comput ed
using t he dat a z, and t hat va lue of auxord t hat minimizes t he fit will be
select ed. This value is r et ur ned a s t he out put ar gument AO. If t he last given
n4sid
4-66
ar gument t o n4sid is 'trace', infor mat ion a bout t he differ ent choices of
auxord will be given t o t he scr een. Not e t hat auxord can be chosen a s a vect or ,
only if order is a given value (no vect or ).
dkx: The ar gument dkx det er mines some addit iona l st r uct ur e of t he mat r ices
of t he st at e-space model t o be est imat ed. It is a r ow vect or wit h t hr ee ent r ies:
dkx = [d, k, x]
The ent r ies r efer t o t he mat r ices K, D, and t he init ia l st at e X(0) of t he
st a t e-space model given above.
k = 1 indicat es t hat t he K-mat r ix in t he model (t he Kalman Gain) will be
est ima t ed, while k = 0 means t ha t t his mat r ix will be fixed t o zer o. This will
give a so called out put er r or model.
d = 1 indicat es t hat D-mat r ix in t he model (t he dir ect t er m fr om input t o
out put ) will be est imat ed, while d = 0 mea ns t hat t his mat r ix is fixed t o zer o.
This also implies t ha t t her e will be a delay of (at least ) one sa mple bet ween t he
input and t he out put .
x = 1 indicat es t hat t he init ial st at e x(0) will be est imat ed and st or ed in t he
model TH, while x = 0 means t hat t he init ial st at e will be t a ken as zer o. Not e
t hat t he init ial st at e is somet hing t ha t r elat es t o t he par t icula r da t a set for
which t he model was est imat ed, and may not be r elevant when t he model is
evaluat ed on a new set of da t a.
Default is
dkx = [0, 1, 0]
The opt ional var iables maxsize a nd T ar e explained under AUXVAR.
trace: Let t ing t he last input ar gument be 'trace', gives infor mat ion t o t he
command line a bout t he choice of auxiliar y or der , in case t his is given as a
vect or .
Algorithm The funct ion implement s t he met hods descr ibed in P. Van Over schee a nd B. De
Moor : N4SID:Subspace algor it hms for t he ident ica t ion of combined
det eminist ic-st ochast ic syst ems. Automat ica, Vol. 30, No 1, pp. 75-93, 1994.
The algor it hm is complement ed wit h a separ at e linear lea st -squar es st ep t o
r e-est imat e t he ma t r ices B, D, and X(0), which ent er linear ly.
n4sid
4-67
Examples Build a fift h or der model fr om dat a wit h t hr ee input s and t wo out put s. Tr y
sever al choices of auxiliar y or der s. Look a t t he fr equency r esponse of t he model.
(Not e t hat t her e will be no confidence int er vals!)
z = [y1 y2 u1 u2 u3];
th = n4sid(z,5,2,7:15,’trace’);
bodeplot(trf(th))
Use t he r esult ing model as init ial values for est imat ing a st at e-space model of
t he same or der using t he pr edict ion er r or met hod:
thi = ss2th(th);
thp = pem(z,thi);
See Also auxvar, canstart, pem, theta
oe
4-68
oe
Purpose Est imat e t he pa r amet er s of an Out put -Er r or model.
Syntax th = oe(z,nn)
th = oe(z,nn,’trace’)
[th, iter_info] = oe(z,nn,maxiter,tol,lim,maxsize,T,'trace')
Description The pa r amet er s of t he Out put -Er r or model st r uct ur e
ar e est ima t ed using a pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u a r e column
vect or s. nn can be given eit her as
nn = [nb nf nk]
or as
nn = thi
In t he for mer case, nb, and nf a r e t he or der s of t he Out put -Er r or model and nk
is t he delay. In t he lat t er case, t his is an init ial value for t he est imat e, given in
t het a for mat . See “The Syst em Ident ificat ion Pr oblem” on page 3-8 for an exact
definit ion of t he or der s and delay.
th is r et ur ned wit h t he r esult ing pa r amet er est imat es and est imat ed
covar ia nces, st or ed in t het a for mat .
The opt ional var iables iter_info, lim, maxiter, maxsize, tol, and T ar e
explained under auxvar.
For mult i-input models, nb, nf, and nk ar e r ow vect or s, such t hat ent r y number
i gives t he or der s and delays associat ed wit h t he i-t h input .
oe does not suppor t mult i-out put models. Use st at e-space model for t his case
(see canstart, n4sid, and pem)
If a last ar gument 'trace' is supplied, infor mat ion about t he pr ogr ess of t he
it er at ive sear ch for t he model will be fur nished t o t he MATLAB comma nd
window.
y t ( )
B q ( )
F q ( )
----------- u t nk – ( ) e t ( ) + =
oe
4-69
Algorithm oe uses essent ially t he same algor it hm a s armax wit h modificat ions t o t he
comput at ion of pr edict ion er r or s and gr adient s.
See Also armax, auxvar, bj, pem, theta
pe
4-70
pe
Purpose Comput e t he pr edict ion er r or s associat ed wit h a model and a dat a set .
Syntax e = pe(z,th)
Description Mat r ix z is t he out put -input dat a set , z = [y u], a nd th is a model specified in
t het a for mat . e is r et ur ned cont aining t he pr edict ion er r or s t hat r esult when
model th is applied t o t he dat a,
See Also resid, theta
e t ( ) H
1 –
q ( ) y t ( ) G q ( )u t ( ) – [ ] =
pem
4-71
pem
Purpose Est imat e t he par amet er s of gener al linear models.
Syntax th = pem(z,nn)
th = pem(z,nn,'trace')
[th, iter_info] = pem(z,nn,index,maxiter,tol,lim,...
maxsize,T,'trace')
Description The funct ion pem handles all model st r uct ur es, including t he gener a l
mult i-input -single-out put st r uct ur e
and gener al st r uct ur es defined by fixpar, mf2th, ms2th, thinit, and
unfixpar. Mult ivar iable ARX st r uct ur es defined by arx2th ar e also cover ed.
The mat r ix z cont ains t he out put -input dat a z = [y u], wher e y a nd u ar e
column vect or s (in t he mult i-var iable case u and y cont ain one column for each
input and out put ).
nn is given eit her as
nn = [na nb nc nd nf nk]
or as
nn = thi
In t he for mer case, na, nb, nc, nd, and nf ar e t he or der s of t he model a nd nk is
t he delay(s). For mult i-input syst ems, nb, nf, and nk a r e r ow vect or s giving t he
or der s and delays of each input . (See Sect ion 3 of t he Tutorial for exact
definit ions of t he or der s).
In t he lat t er case, thi defines a model st r uct ur e and an init ial value for t he
est imat e, given in t het a for mat .
th is r et ur ned wit h t he r esult ing par amet er est ima t es a nd est imat ed
covar iances, st or ed in t het a for mat .
The opt ional ar gument index is a r ow vect or t hat cont ains t he indices of t he
par a met er s t hat ar e t o be est imat ed. The ot her s r emain fixed t o t heir nominal
values. The or der ing of t he par amet er s is defined under th2par. The default
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
----------------- u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
pem
4-72
value of index is t ha t all fr ee par amet er s ar e est ima t ed. The opt ional var iables
iter_info, lim, maxiter, maxsize, tol, and T ar e explained under auxvar.
If a last ar gument ‘trace’ is supplied, infor mat ion about t he pr ogr ess of t he
it er at ive sear ch for t he model will be fur nished t o t he MATLAB comma nd
window.
For t he special cases of single-input models of Out put -Er r or , ARMAX, and
Box-J enkins t ype, it is mor e efficient t o use oe, armax, and bj.
Examples Her e is an example of a syst em wit h t hr ee input s and t wo out put s. A canonical
for m st at e-spa ce model of or der 5 is sought .
z = [y1 y2 u1 u2 u3];
thc = canstart(z,5,3)
th = pem(z,thc);
Algorithm pem uses essent ially t he same algor it hm as armax wit h modificat ions t o t he
comput at ion of pr edict ion er r or s and gr adient s.
See Also armax, auxvar, bj, oe, theta
poly2th
4-73
poly2t h
Purpose Const r uct t het a for mat ma t r ix for input -out put models.
Syntax th = poly2th(A,B)
th = poly2th(A,B,C,D,F,lam,T)
Description poly2th cr eat es a mat r ix cont aining par a met er s t hat descr ibe t he gener al
mult i-input -single-out put model st r uct ur e:
A, B, C, D, and F specify t he polynomial coefficient s.
For single-input syst ems, t hese ar e all r ow vect or s in t he st andar d MATLAB
for mat :
A = [1 a1 a2 ... ana]
A, C, D, and F all st ar t wit h 1, while B cont ains leading zer os t o indicat e t he
delays. See “Defining Model St r uct ur es” on page 3-29.
For mult i-input syst ems, B and F ar e mat r ices wit h one r ow for each input .
For t ime ser ies, B a nd F ar e ent er ed as empt y mat r ices:
B = []; F = [];
lam is t he va r iance of t he whit e noise sequence , while T is t he sampling
int er val.
A negat ive value of T indicat es t hat t he model is a cont inuous-t ime one. Then
t he int er pr et a t ion of t he ar gument s is t ha t
A = [1 2 3 4]
cor r esponds t o t he polynomia l in t he Laplace var ia ble s, and so
on. For cont inuous-t ime syst ems lam indicat es t he level of t he spect r al densit y
of t he innova t ions. (A sa mpled ver sion of t he model has t he innovat ions
var iance lam/T, wher e T is t he sa mpling int er val. The cont inuous-t ime model
must ha ve a whit e noise component in it s noise descr ipt ion. See “Some Special
Topics” on page 3-68.
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) =
B
nu
q ( )
F
nu
q ( )
-----------------u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + +
e t ( )
s
3
2s
2
3s 4 + + +
poly2th
4-74
Tr ailing ar gument s C, D, F, lam, and T can be omit t ed, in which case t hey ar e
t aken as 1. (If B=[], t hen F is t aken as [].)
For discr et e-t ime models (T>0), not e t he following: poly2th st r ips a ny t r ailing
zer os fr om t he polynomials when det er mining t he or der s. It also st r ips leading
zer os fr om t he B polynomial t o det er mine t he delays. Keep t his in mind when
you use poly2th and th2poly t o modify ear lier est ima t es t o ser ve a s init ia l
condit ions for est ima t ing new st r uct ur es. See “Some Special Topics” on page
3-68.
Examples To cr eat e a syst em of ARMAX t ype (t he “Åst r öm syst em”):
A = [1 –1.5 0.7];
B = [0 1 0.5];
C = [1 –1 0.2];
th0 = poly2th(A,B,C);
This gives a syst em wit h one delay (nk = 1).
Cr eat e t he cont inuous-t ime model
Sample it wit h T=0.1 and t hen simulat e it wit hout noise:
B=[0 1;1 3];
F=[1 1 0;1 2 4]
th=poly2th(1,B,1,1,F,1,–1)
thd=thc2thd(th,0.1)
y=idsim([u1 u2],thd);
See Also idsim, theta

y(t ) ·
1
s(s+ 1)
u
1
t ( ) +
s+ 3
s
2
+ 2s+ 4
u
2
(t) + e(t )
predict
4-75
pr edict
Purpose Pr edict t he out put k-st ep ahead.
Syntax p = predict(z,th)
[yp,thpred] = predict(z,th,k)
Description z is t he out put -input dat a in t he usual for mat
z = [y u]
wher e y is a mat r ix whose r-t h column is t he r-t h out put signal a nd
cor r espondingly for t he input u.
The ar gument k indicat es t hat t he k -st ep ahead pr edict ion of y accor ding t o t he
model th (in t he t het a for mat ) is comput ed. In t he calculat ion of yp(t) t he model
ca n use out put s up t o t ime
: ,
and input s up t o t he cur r ent t ime t . The default value of k is 1.
The out put yp is a mat r ix of t he same size a s y, and it s i,j element cont ains t he
pr edict ed va lue of t he cor r esponding element in y. The out put ar gument
thpred cont ains t he k-st ep a head pr edict or in t he t het a for mat , in t he case t hat
th cor r esponds t o a n input -out put model. (The pr edict or is a syst em wit h
input s and out put s, being t he number of out put s and t he
number of input s t o th.)
An impor t ant use of predict is t o eva luat e a model’s pr oper t ies in t he
mid-fr equency r ange. Simula t ion wit h idsim (which concept ua lly cor r esponds
t o k = inf) can lead t o levels t ha t dr ift apar t , since t he low fr equency behavior
is emphasized. One st ep ahead pr edict ion is not a power ful t est of t he model’s
pr oper t ies, since t he high fr equency beha vior is st r essed. The t r ivial pr edict or
can give good pr edict ions in ca se t he sampling of t he da t a is fast .
Anot her impor t ant use of predict is t o evaluat e models of t ime ser ies. The
nat ur al way of st udying a t ime ser ies model’s abilit y t o r epr oduce obser va t ions
is t o compar e it s k-st ep ahead pr edict ions wit h act ual dat a.
Not e t hat for out put -er r or models, t her e is no differ ence bet ween t he k-st ep
ahead pr edict ions a nd t he simulat ed out put , since, by definit ion, out put -er r or
models only use past input s t o pr edict fut ur e out put s.
t k – y s ( ) s , t k – = t k – 1 – … ,
ny nu + ny ny nu
yˆ t ( ) y t 1 – ( ) =
predict
4-76
Algorithm For a model th t hat is an input -out put model, t he for mula (3.31) in Ljung
(1987) is applied t o comput e t he pr edict or . For st at e-space models, t he st at e
equa t ions ar e simulat ed k-st eps ahead wit h init ial value ,
wher e is t he Kalman filt er st a t e est imat e.
Examples Simulat e a t ime ser ies, est imat e a model based on t he fir st half of t he dat a, and
evaluat e t he four st ep ahead pr edict ions on t he second half:
th0 = poly2th([1 –0.99],[],[1 –1 0.2]);
y = idsim(randn(400,1),th0);
th = armax(y(1:200),[1 2]);
yp = predict(y,th,4);
plot([y(201:400),yp(201:400)])
Not e t hat t he last t wo commands also ar e achieved by
compare(y,th,4,201:400);
See Also compare, idsim, pe
x t k – ( ) xˆ t k – ( ) =
xˆ t k – ( )
present
4-77
pr esent
Purpose Display t he infor mat ion in a t het a mat r ix.
Syntax present(th)
Description This funct ion displays t he polynomials of t he model th, t oget her wit h t heir
st a ndar d deviat ions, loss funct ion, a nd Akaike’s Final Pr edict ion Er r or
Cr it er ion (FPE) (which essent ially equals t he AIC). It also displa ys infor mat ion
about how th was cr ea t ed.
Lea ding zer os in B cor r espond t o dela ys; t her efor e, t he delay is nk if B st ar t s
wit h nk exact zer os.
For input -out put models, t he est imat ed st anda r d deviat ions ar e given just
below t he est imat ed par a met er s. (Not e t hat leading zer os and ones ar e exact
and ha ve zer o st andar d devia t ion.)
For st at e-space models and mult ivar iable ARX models, t he st a ndar d
deviat ions ar e given a s fake, imagina r y par t s of t he par a met er est imat es.
See Also theta
rarmax
4-78
r a r max
Purpose Est imat e r ecur sively t he par a met er s of an ARMAX or ARMA model.
Syntax thm = rarmax(z,nn,adm,adg)
[thm,yhat,P,phi,psi] = ...
rarmax(z,nn,adm,adg,th0,P0,phi0,psi0)
Description The pa r amet er s of t he ARMAX model st r uct ur e
ar e est ima t ed using a r ecur sive pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u a r e column
vect or s. nn is given a s
nn = [na nb nc nk]
wher e na, nb, a nd nc ar e t he or der s of t he ARMAX model, and nk is t he delay.
See equa t ions (3.16)-(3.18) in Chapt er 3, "Tut or ial" for an exact definit ion of t he
or der s.
If z = y and nn = [na nc], rarmax est imat es t he par amet er s of an ARMA
model for y:
Only single-input , single-out put models ar e handled by rarmax. Use rpem for
t he mult i-input case.
The est imat ed par a met er s ar e r et ur ned in t he mat r ix thm. The k-t h r ow of thm
cont ains t he par amet er s associat ed wit h t ime k, i.e., t hey ar e based on t he da t a
in t he r ows up t o and including r ow k in z. Each r ow of thm cont ains t he
est ima t ed par amet er s in t he following or der :
thm(k,:) = [a1,a2,...,ana,b1,...,bnb,c1,...,cnc]
See equat ions (3.16),(3.18) in Chapt er 3, "Tut or ial" for mor e infor mat ion.
yhat is t he pr edict ed value of t he out put , accor ding t o t he cur r ent model, i.e.,
r ow k of yhat cont ains t he pr edict ed value of z(k,1) based on all past dat a.
A q ( )y t ( ) B q ( )u t nk – ( ) C q ( )e t ( ) + =
A q ( )y t ( ) C q ( )e t ( ) =
rarmax
4-79
The act ual algor it hm is select ed wit h t he t wo ar gument s adm a nd adg. These
ar e descr ibed under rarx.
The input ar gument th0 cont ains t he init ial value of t he par amet er s, a r ow
vect or , consist ent wit h t he r ows of thm. The default va lue of th0 is all zer os.
The ar gument s P0 and P ar e t he init ial and final values, r espect ively, of t he
scaled covar iance mat r ix of t he par amet er s. See rarx. The default value of P0
is 10
4
t imes t he unit mat r ix. The a r gument s phi0, psi0, phi, and psi cont ain
init ial and final values of t he dat a vect or and t he gr adient vect or , r espect ively.
The sizes of t hese depend in a r at her complica t ed wa y on t he chosen model
or der s. The nor mal choice of phi0 a nd psi0 is t o use t he out put s fr om a
pr evious call t o rarmax wit h t he same model or der s. (This call could of cour se
be a dummy call wit h default input ar gument s.) The default values of phi0 a nd
psi0 ar e all zer os.
Not e t ha t t he funct ion r equir es t hat t he delay nk be lar ger t han 0. If you want
nk=0, shift t he input sequence appr opr iat ely and use nk=1.
Algorithm The gener a l r ecur sive pr edict ion er r or algor it hm (11.44), (11.47)-(11.49) of
Ljung (1987) is implement ed. See “Recur sive Par amet er Est ima t ion” on page
3-61 for mor e infor mat ion.
Examples Comput e a nd plot , as funct ions of t ime, t he four par amet er s in a second or der
ARMA model of a t ime ser ies given in t he vect or y. The for get t ing fa ct or
algor it hm wit h a for get t ing fact or of 0.98 is a pplied.
thm = rarmax(y,[2 2],'ff',0.98);
plot(thm)
rarx
4-80
r a r x
Purpose Est imat e r ecur sively t he par a met er s of an ARX or AR model.
Syntax thm = rarx(z,nn,adm,adg)
[thm,yhat,P,phi] = rarx(z,nn,adm,adg,th0,P0,phi0)
Description The pa r amet er s of t he ARX model st r uct ur e
ar e est ima t ed using differ ent var iant s of t he r ecur sive lea st -squar es met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u ar e column
vect or s. nn is given as
nn = [na nb nk]
wher e na and nb ar e t he or der s of t he ARX model, and nk is t he delay. See
equa t ion (3.16) in t he Tut orial for an exact definit ion of t he or der s.
If z = y and nn = na, rarx est imat es t he par amet er s of an AR model for y:
Models wit h sever al input s
ar e ha ndled by a llowing u t o cont ain ea ch input as a column vect or ,
u = [u1 ... unu]
and by allowing nb and nk t o be r ow vect or s defining t he or der s and delays
associat ed wit h each input .
Only single-out put models ar e handled by rarx.
The est imat ed par amet er s ar e r et ur ned in t he mat r ix thm. The k-t h r ow of thm
cont ains t he par amet er s associat ed wit h t ime k, i.e., t hey ar e based on t he da t a
A q ( )y t ( ) B q ( )u t nk – ( ) e t ( ) + =
A q ( )y t ( ) e t ( ) =
A q ( )y t ( ) B
1
q ( )u
1
t nk
1
– ( ) …B
nu
u
nu
t nk
nu
– ( ) e t ( ) + + =
rarx
4-81
in t he r ows up t o and including r ow k in z. Each r ow of thm cont ains t he
est imat ed par amet er s in t he following or der :
thm(k,:) = [a1,a2,...,ana,b1,...,bnb]
See equat ion (3.16) in Chapt er 3, "Tut or ial". In t he case of a mult i-input model,
all t he b par amet er s associat ed wit h input number 1 ar e given fir st , a nd t hen
all t he b par amet er s associat ed wit h input number 2, and so on.
yhat is t he pr edict ed value of t he out put , accor ding t o t he cur r ent model, i.e.,
r ow k of yhat cont ains t he pr edict ed va lue of z(k,1) based on a ll past da t a.
The act ual algor it hm is select ed wit h t he t wo ar gument s adg and adm. These
ar e descr ibed in “Recur sive Par amet er Est imat ion” on page 3-61. The opt ions
ar e as follows:
Wit h adm ='ff' and adg = lam t he forgett ing fact or algor it hm (10.6abd)+(10.8)
is obt ained wit h for get t ing fact or = lam. This is what is oft en r efer r ed t o as
Recur sive Least Squar es, RLS. In t his case t he mat r ix P (see below) has t he
following int er pr et at ion: /2 ∗ P is appr oximat ely equal t o t he cova r iance
mat r ix of t he est imat ed pa r amet er s. Her e is t he var iance of t he innovat ions
(t he t r ue pr edict ion er r or s e(t) in (10.3)).
Wit h adm ='ug' and adg = gam t he unnormalized gradient algor it hm
(10.6abc)+(10.9) is obt ained wit h gain gamma= gam. This algor it hm is
commonly known as unnor malized Least Mean Squar es, LMS. Similar ly
adm ='ng' a nd adg = gam gives t he normalized gradient or Nor malized Least
Mean Squar es, NLMS algor it hm (10.6abc) + (10.10). In t hese cases P is not
defined or applicable.
Wit h adm ='kf' and adg = R1 t he Kalman Filt er Based algor it hm (10.6) is
obt ained wit h R
2
=

1 a nd R
1
= R1. If t he var iance of t he innovat ions e(t ) is not
unit y but , t hen ∗ P is t he covar iance mat r ix of t he par amet er est imat es,
while =R1 / is t he covar ia nce ma t r ix of t he par a met er changes in (10.4).
The input ar gument th0 cont ains t he init ial value of t he par amet er s; a r ow
vect or , consist ent wit h t he r ows of thm. (See above.) The default value of th0 is
all zer os.
The ar gument s P0 and P ar e t he init ial and final values, r espect ively, of t he
scaled covar iance mat r ix of t he par amet er s. The default value of P0 is 10
4
t imes
t he ident it y mat r ix.
λ
R
2
R
2
R
2
R
2
R
1
R
2
rarx
4-82
The ar gument s phi0 and phi cont a in init ial and final values, r espect ively, of
t he dat a vect or :
Then, if
z = [y(1),u(1); ... ;y(N),u(N)]
you have phi0 = and phi = . The default value of phi0 is all zer os. For
online use of rarx, use phi0, th0, and P0 a s t he pr evious out put s phi, thm (last
r ow), and P.
Not e t hat t he funct ion r equir es t hat t he dela y nk be la r ger t han 0. If you wa nt
nk=0, shift t he input sequence appr opr iat ely and use nk=1.
Examples Adapt ive noise canceling: The signal y cont ains a component t ha t has it s
or igin in a known signal r. Remove t his component by est imat ing, r ecur sively,
t he syst em t hat r ela t es r t o y using a sixt h or der FIR model t oget her wit h t he
NLMS algor it hm:
z = [y r];
[thm,noise] = rarx(z,[0 6 1],'ng',0.1);
%noise is the adaptive estimate of the noise
%component of y
plot(y–noise)
ϕ t ( ) y t 1 – ( ) … y t na – ( ) u t 1 – ( ) …u t nb – nk – 1 + ( ) , , , , [ ] =
ϕ 1 ( ) ϕ N ( )
rarx
4-83
If t he above applicat ion is a t r ue online one, so t hat you want t o plot t he best
est imat e of t he signal y – noise at t he same t ime as t he dat a y and u become
ava ilable, pr oceed as follows:
phi = zeros(6,1); P=1000∗eye(6);
th = zeros(1,6); axis([0 100 –2 2]);
plot(0,0,'∗'), hold
%The loop:
while ~abort
[y,r,abort] = readAD(time);
[th,ns,P,phi] = rarx([y r],'ff',0.98,th,P,phi);
plot(time,y–ns,'∗')
time = time +Dt
end
This example uses a for get t ing fact or algor it hm wit h a for get t ing fact or of 0.98.
readAD r epr esent s an M-file t ha t r eads t he value of an A/D conver t er at t he
indicat ed t ime inst a nce.
rbj
4-84
r bj
Purpose Est imat e r ecur sively t he par a met er s of a Box-J enkins model.
Syntax thm = rbj(z,nn,adm,adg)
[thm,yhat,P,phi,psi] = ...
rbj(z,nn,adm,adg,th0,P0,phi0,psi0)
Description The pa r amet er s of t he ARMAX model st r uct ur e
ar e est ima t ed using a r ecur sive pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input da t a z = [y u] wher e y and u a r e column
vect or s. nn is given as
nn = [nb nc nd nf nk]
wher e nb, nc, nd, and nf ar e t he or der s of t he Box-J enkins model, a nd nk is t he
delay. See equa t ions (3.21) and (3.14),(3.18), (3.22) and (3.29) in t he Tutorial
for an exact definit ion of t he or der s.
Only single-input , single-out put models ar e handled by rbj. Use rpem for t he
mult i-input case.
The est imat ed par amet er s ar e r et ur ned in t he mat r ix thm. The k-t h r ow of thm
cont ains t he par amet er s associat ed wit h t ime k, i.e., t hey ar e based on t he da t a
in t he r ows up t o and including r ow k in z. Each r ow of thm cont ains t he
est ima t ed par amet er s in t he following or der :
thm(k,:) = [b1,...,bnb,c1,...,cnc,d1,...,dnd,f1,...,fnf]
(See equat ions (3.14),(3.18),(3.22) a nd (3.20) in t he Tut orial.)
yhat is t he pr edict ed value of t he out put , accor ding t o t he cur r ent model, i.e.,
r ow k of yhat cont ains t he pr edict ed value of z(k,1) based on all past dat a.
The act ual algor it hm is select ed wit h t he t wo ar gument s adm and adg. These
ar e descr ibed under rarx.
y t ( )
B q ( )
F q ( )
----------- u t nk – ( )
C q ( )
D q ( )
------------e t ( ) + =
rbj
4-85
The input ar gument th0 cont ains t he init ial value of t he par amet er s, a r ow
vect or , consist ent wit h t he r ows of thm. (See above.) The default value of th0 is
all zer os.
The ar gument s P0 and P ar e t he init ial and final values, r espect ively of t he
scaled covar iance mat r ix of t he par amet er s. See rarx. The default value of P0
is 10
4
t imes t he unit mat r ix. The a r gument s phi0, psi0, phi, and psi cont ain
init ial and final values of t he dat a vect or and t he gr adient vect or , r espect ively.
The sizes of t hese depend in a r at her complica t ed wa y on t he chosen model
or der s. The nor mal choice of phi0 a nd psi0 is t o use t he out put s fr om a
pr evious call t o rbj wit h t he same model or der s. (This call could, of cour se, be
a dummy ca ll wit h default input ar gument s.) The defa ult values of phi0 and
psi0 ar e all zer os.
Not e t hat t he funct ion r equir es t hat t he dela y nk is lar ger t ha n 0. If you want
nk=0, shift t he input sequence appr opr iat ely and use nk=1.
Algorithm The gener a l r ecur sive pr edict ion er r or algor it hm (11.44) of Ljung (1987) is
implement ed. See also “Recur sive Par amet er Est imat ion” on page 3-61.
resid
4-86
r esi d
Purpose Comput e and t est t he r esiduals (pr edict ion er r or s) of a model.
Syntax [e,r] = resid(z,th)
[e,r] = resid(z,th,M,maxsize)
resid(r);
Description Mat r ix z cont a ins t he out put -input da t a z = [y u], wher e y a nd u ar e column
vect or s. In t he mult ivar iable case, y a nd u ar e mat r ices, wit h columns
cor r esponding t o t he differ ent input s and out put s.
th is t he model t o be evaluat ed on t he given dat a set , defined in t het a for mat .
e is r et ur ned wit h t he r esiduals (pr edict ion er r or s) associat ed wit h t he model
and t he dat a.
The aut ocor r ela t ion funct ion of e and t he cr oss cor r elat ion bet ween e and t he
input (s) u ar e comput ed and displayed. The 99% confidence int er vals for t hese
values ar e also comput ed and displayed as dot t ed (r ed) cur ves. The
comput at ion of t hese values is done assuming e t o be whit e and independent of
u. The funct ions ar e displa yed up t o lag M, which is 25 by default .
The cor r elat ion infor mat ion is r et ur ned wit h r. The plot s can t hen be r eviewed
by
resid(r);
See “Model St r uct ur e Select ion and Va lidat ion” on page 3-49 for mor e
infor mat ion.
The ar gument maxsize is explained under auxvar.
Examples Her e a r e some t ypical model va lidat ion comma nds:
e = resid(z,th);
plot(e)
compare(z,th);
See Also auxvar, compare, pem, theta
References Ljung (1987), Sect ion 16.5.
roe
4-87
r oe
Purpose Est imat e r ecur sively t he par amet er s of an Out put -Er r or model.
Syntax thm = roe(z,nn,adm,adg)
[thm,yhat,P,phi,psi] = roe(z,nn,adm,adg,th0,P0,phi0,psi0)
Description The pa r amet er s of t he Out put -Er r or model st r uct ur e
ar e est ima t ed using a r ecur sive pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input dat a z = [y u] wher e y and u a r e column
vect or s. nn is given as
nn = [nb nf nk]
wher e nb and nf ar e t he or der s of t he Out put -Er r or model, and nk is t he delay.
See equat ions (3.14) and (3.19)-(3.20) in t he Tutorial for an exa ct definit ion of
t he or der s.
Only single-input , single-out put models ar e handled by roe. Use rpem for t he
mult i-input case.
The est imat ed par amet er s ar e r et ur ned in t he mat r ix thm. The k-t h r ow of thm
cont ains t he par amet er s associat ed wit h t ime k, i.e., t hey ar e based on t he da t a
in t he r ows up t o and including r ow k in z.
Each r ow of thm cont ains t he est ima t ed par amet er s in t he following or der :
thm(k,:) = [b1,...,bnb,f1,...,fnf]
See equat ions (3.14), (3.20) in t he Tutorial.
yhat is t he pr edict ed value of t he out put , accor ding t o t he cur r ent model, i.e.,
r ow k of yhat cont ains t he pr edict ed va lue of z(k,1) based on a ll past da t a.
The act ual algor it hm is select ed wit h t he t wo ar gument s adg and adm. These
ar e descr ibed under rarx.
The input ar gument th0 cont ains t he init ial value of t he par amet er s, a r ow
vect or , consist ent wit h t he r ows of thm. (See above.) The default value of th0 is
all zer os.
y t ( )
B q ( )
F q ( )
-----------u t nk – ( ) =
roe
4-88
The ar gument s P0 and P ar e t he init ia l and final values, r espect ively, of t he
scaled covar iance mat r ix of t he par amet er s. See rarx. The default va lue of P0
is 10
4
t imes t he unit mat r ix. The ar gument s phi0, psi0, phi, and psi cont ain
init ial and final values of t he dat a vect or and t he gr adient vect or , r espect ively.
The sizes of t hese depend in a r at her complicat ed way on t he chosen model
or der s. The nor mal choice of phi0 and psi0 is t o use t he out put s fr om a
pr evious call t o roe wit h t he same model or der s. (This call could be a dummy
ca ll wit h default input ar gument s.) The defa ult values of phi0 a nd psi0 ar e all
zer os.
Not e t hat t he funct ion r equir es t hat t he dela y nk is lar ger t han 0. If you want
nk=0, shift t he input sequence a ppr opr iat ely a nd use nk=1.
Algorithm The gener al r ecur sive pr edict ion er r or algor it hm (11.44) of Ljung (1987) is
implement ed. See also “Recur sive Par amet er Est imat ion” on page 3-61.
See Also oe, rarx, rbj, rplr,
rpem
4-89
r pem
Purpose Est imat e r ecur sively t he par amet er s of a gener al mult i-input single-out put
linea r model.
Syntax thm = rpem(z,nn,adm,adg)
[thm,yhat,P,phi,psi] = rpem(z,nn,adm,adg,th0,P0,phi0,psi0)
Description The pa r amet er s of t he gener al linear model st r uct ur e
ar e est ima t ed using a r ecur sive pr edict ion er r or met hod.
Mat r ix z cont ains t he out put -input dat a z = [y u] wher e y and u a r e column
vect or s (in t he mult i-input case u cont ains one column for each input ). nn is
given as
nn = [na nb nc nd nf nk]
wher e na, nb, nc, nd, a nd nf ar e t he or der s of t he model, and nk is t he dela y.
For mult i-input syst ems nb, nf, and nk ar e r ow vect or s giving t he or der s and
delays of each input . See equat ions (3.13)-(3.23) in t he Tutorial for an exact
definit ion of t he or der s.
The est imat ed par amet er s ar e r et ur ned in t he mat r ix thm. The k-t h r ow of thm
cont ains t he par amet er s associat ed wit h t ime k, i.e., t hey ar e based on t he da t a
in t he r ows up t o and including r ow k in z. Each r ow of thm cont ains t he
est imat ed par amet er s in t he following or der :
thm(k,:) = [a1,a2,...,ana,b1,...,bnb,...
c1,...,cnc,d1,...,dnd,f1,...,fnf]
See equa t ions (3.13)-(3.23) in t he Tutorial. For mult i-input syst ems t he B par t
in t he above expr ession is r epeat ed for each input befor e t he C par t begins, and
also t he F par t is r epeat ed for each input . This is t he same or der ing as in
th2par.
yhat is t he pr edict ed value of t he out put , accor ding t o t he cur r ent model, i.e.,
r ow k of yhat cont a ins t he pr edict ed value of z(k,1) based on all past dat a.
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
----------------- u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
rpem
4-90
The act ual algor it hm is select ed wit h t he t wo ar gument s adg and adm. These
ar e descr ibed under rarx
The input ar gument th0 cont ains t he init ial value of t he par amet er s;, a r ow
vect or , consist ent wit h t he r ows of thm. (See above.) The default value of th0 is
all zer os.
The ar gument s P0 and P ar e t he init ia l and final values, r espect ively, of t he
scaled covar iance mat r ix of t he par amet er s. See rarx. The default va lue of P0
is 10
4
t imes t he unit ma t r ix. The a r gument s phi0, psi0, phi, and psi cont ain
init ial and final values of t he dat a vect or and t he gr adient vect or , r espect ively.
The sizes of t hese depend in a r at her complicat ed way on t he chosen model
or der s. The nor mal choice of phi0 and psi0 is t o use t he out put s fr om a
pr evious call t o rpem wit h t he same model or der s. (This call could be a dummy
ca ll wit h default input ar gument s.) The defa ult values of phi0 a nd psi0 ar e all
zer os.
Not e t hat t he funct ion r equir es t hat t he dela y nk is lar ger t han 0. If you want
nk=0 , shift t he input sequence appr opr iat ely and use nk=1.
Algorithm The gener al r ecur sive pr edict ion er r or algor it hm (11.44) of Ljung (1987) is
implement ed. See also “Recur sive Par amet er Est imat ion” on page 3-61.
For t he special cases of ARX/AR models, and of single-input ARMAX/ARMA,
Box-J enkins, and Out put -Er r or models, it is mor e efficient t o use rarx,
rarmax, rbj, and roe.
See Also pem, rarmax, rarx, rbj, roe, rplr
rplr
4-91
r plr
Purpose Est imat e r ecur sively t he par amet er s of a gener al mult i-input single-out put
linea r model.
Syntax thm = rplr(z,nn,adm,adg)
[thm,yhat,P,phi] = rplr(z,nn,adm,adg,th0,P0,phi0)
Description This is a dir ect a lt er nat ive t o rpem and has essent ially t he sa me synt ax. See
rpem for a n explana t ion of t he input and out put a r gument s.
rplr differ s fr om rpem in t hat it uses anot her gr adient appr oximat ion. See
Sect ion 11.5 in Ljung (1987). Sever al of t he special cases ar e well known
algor it hms.
When applied t o ARMAX models, (nn = [na nb nc 0 0 nk]), rplr gives t he
Ext ended Least Squar es, ELS met hod. When applied t o t he out put er r or
st r uct ur e (nn = [0 nb 0 0 nf nk]) t he met hod is known as HARF in t he adm
= 'ff' case and SHARF in t he adm = 'ng' case.
rplr can also be applied t o t he t ime ser ies case in which an ARMA model is
est imat ed wit h
z = y
nn = [na nc]
You can t hus use rplr as an alt er nat ive t o rarmax for t his case.
See Also pem, rarmax, rarx, rbj, roe, rpem
segment
4-92
segment
Purpose Segment da t a a nd est imat e models for each segment .
Syntax segm = segment(z,nn)
[segm,V,thm,R2e] = segment(z,nn,R2,q,R1,M,th0,P0,ll,mu)
Description segment builds models of AR, ARX, or ARMAX/ARMA,
assuming t hat t he model pa r amet er s a r e piece-wise const ant over t ime. It
r esult s in a model t hat has split t he dat a r ecor d int o segment s over which t he
model r emains const a nt . The funct ion models signals and syst ems t hat may
under go abr upt changes.
The ar gument z is t he out put -input dat a
z = [y u]
wher e y is a column vect or cont aining t he out put s and u is a column vect or
cont aining t he input s. If t he syst em ha s sever al input s, u ha s t he cor r esponding
number of columns.
The ar gument nn defines t he model or der . For t he ARMAX model
nn = [na nb nc nk]
wher e na, nb, and nc ar e t he or der s of t he cor r esponding polynomials. See
(3.13)-(3.18) in Chapt er 3, "Tut or ial". Mor eover nk is t he delay. If t he model has
sever al input s, nb and nk ar e r ow vect or s, giving t he or der s and delays for ea ch
input .
For an ARX model (nc = 0) ent er
nn = [na nb nk]
For an ARMA model of a t ime ser ies
z = y
nn = [na nc]
and for an AR model
nn = na
A q ( )y t ( ) B q ( )u t nk – ( ) C q ( )e t ( ) + =
segment
4-93
The out put ar gument segm is a mat r ix, whose k-r ow cont ains t he par amet er s
cor r esponding t o t ime k. This is analogous t o t he out put ar gument thm in rarx
and rarmax. The out put ar gument thm of segment cont ains t he cor r esponding
model par amet er s t hat have not yet been segment ed. That is, t hey ar e not
piecewise const a nt , a nd t her efor e cor r espond t o t he out put s of t he funct ions
rarmax and rarx. In fact , segment is an alt er nat ive t o t hese t wo algor it hms,
and ha s a bet t er capabilit y t o deal wit h t ime var iat ions t hat may be a br upt .
The out put ar gument V cont ains t he sum of t he squa r ed pr edict ion er r or s of t he
segment ed model. It is a measur e of how successful t he segment at ion ha s been.
The input ar gument R2 is t he a ssumed var iance of t he innovat ions e(t ) in t he
model. The default value of R2 is t ha t it is est imat ed. Then t he out put
ar gument R2e is a vect or whose k-t h element cont a ins t he est imat e of R2 at t ime
k.
The ar gument q is t he pr obabilit y t hat t he model under goes at an abr upt
change at any given t ime. The default value is 0.01.
R1 is t he a ssumed covar ia nce mat r ix of t he par a met er jumps when t hey occur .
The default value is t he ident it y ma t r ix wit h dimension equal t o t he number
of est imat ed par amet er s.
M is t he number of par allel models used in t he algor it hm (see below). It s default
value is 5.
th0 is t he init ial value of t he par amet er s. It s default is zer o. P0 is t he init ia l
covar iance mat r ix of t he par amet er s. The default is 10 t imes t he ident it y
mat r ix.
ll is t he gua r ant eed life of each of t he models. That is, a ny cr eat ed candida t e
model is not abolished unt il a ft er at lea st ll t ime st eps. The default is ll = 1.
Mu is a for get t ing par amet er t hat is used in t he scheme t hat est imat es R2. The
defa ult is 0.97.
The most cr it ical par amet er for you t o choose is R2. It is usually mor e r obust
t o have a r easonable guess of R2 t han t o est imat e it . Typically, you need t o t r y
differ ent va lues of R2 and evaluat e t he r esult s. (See t he example below.)
sqrt(R2) cor r esponds t o a cha nge in t he value y(t ) t hat is nor mal, giving no
indicat ion t hat t he syst em or t he input might have changed.
segment
4-94
Algorithm The algor it hm is based on M par allel models, each r ecur sively est imat ed by an
algor it hm of Kalman filt er t ype. Each is updat ed independent ly, and it s
post er ior pr obabilit y is comput ed. The t ime var ying est imat e thm is for med by
weight ing t oget her t he M differ ent models wit h weight s equal t o t heir post er ior
pr obabilit y. At ea ch t ime st ep t he model (among t hose t hat have lived at least
ll samples) t hat has t he lowest post er ior pr obabilit y is abolished. A new model
is st ar t ed, assuming t hat t he syst em par a met er s have jumped, wit h pr obabilit y
q, a r andom jump fr om t he most likely among t he models. The cova r iance
mat r ix of t he par amet er change is set t o R1.
Aft er a ll t he dat a ar e exa mined, t he sur viving model wit h t he highest post er ior
pr obabilit y is t r acked back and t he t ime inst ances wher e it jumped ar e mar ked.
This defines t he differ ent segment s of t he dat a. (If no models had been
abolished in t he algor it hm, t his would have been t he maximum likelihood
est ima t es of t he jump inst ances.) The segment ed model segm is t hen for med by
smoot hing t he par amet er est imat e, assuming t hat t he jump inst ances ar e
cor r ect . In ot her wor ds, t he last est imat e over a segment is chosen t o r epr esent
t he whole segment .
Examples Check how t he a lgor it hm segment s a sinusoid int o segment s of const ant levels.
Then use a ver y simple model y(t ) = b
1
* 1, wher e 1 is a faked input a nd
descr ibes t he piecewise const ant level of t he signal y(t ) (which is simula t ed as
a sinusoid).
y = sin([1:50]/3)';
thm = segment([y,ones(y)],[0 1 1],0.1);
plot([thm,y])
By t r ying var ious values of R2 (0.1 in t he above example), mor e levels ar e
cr eat ed a s R2 decr eases.
b
1
selstruc
4-95
selst r uc
Purpose Select model or der (st r uct ur e).
Syntax [nn,vmod] = selstruc(v)
[nn,vmod] = selstruc(v,c)
Description selstruc is a funct ion t o help choose a model st r uct ur e (or der ) fr om t he
infor mat ion cont ained in t he mat r ix v obt ained as t he out put fr om arxstruc or
ivstruc.
The default va lue of c is 'plot'. This gr aphs t he values of t he loss funct ions in
v against t he t ot al number of par amet er s in t he cor r esponding model st r uct ur e.
If v was gener at ed by ivstruc, so t hat it also cont ains t he condit ion number s
of t he IV mat r ices, t hen t hese ar e also gr aphed aga inst t he number of
par a met er s. Ba sed on inspect ion of t hese plot s, you can choose a suit able
number of par amet er s, and nn r et ur ns t he best st r uct ur e wit h t his number of
par a met er s.
If c = 'log', t he logar it hms of t he loss funct ions ar e gr aphed inst ead.
c = 'aic' gives no plot s, but r et ur ns in nn t he st r uct ur e t hat minimizes
Akaike’s Infor ma t ion Theor et ic Cr it er ion (AIC),
wher e V is t he loss funct ion, d is t he t ot al number of par amet er s in t he
st r uct ur e in quest ion, and N is t he number of dat a point s used for t he
est imat ion.
c = 'mdl' r et ur ns in nn t he st r uct ur e t hat minimizes Rissanen’s Minimum
Descr ipt ion Lengt h (MDL) cr it er ion.
When c equals a numer ical va lue, t he st r uct ur e t hat minimizes
is select ed.
The out put ar gument vmod has t he same for mat as v, but it cont ains t he
logar it hms of t he accor dingly modified cr it er ia.
V
mod
V

1 2

d N ⁄ ( ) + ( ) =
V
mod
V

1 N ( ) log

d N ⁄ + ( ) =
V
mod
V

1 c

d n ⁄ + ( ) =
selstruc
4-96
The for mal gr ounds for applying AIC or MDL r equir e t hat v be gener a t ed by
arxstruc wit h ze = zv. When cr oss-validat ion is used (ze differ ent fr om zv),
t he logical choice is c = 0.
When select ing model st r uct ur es, it is impor t a nt t o assess ca r efully whet her
t he benefit of a bet t er fit is wor t h t he addit ional complexit y of a higher or der
model. See Chapt er 3, "Tut or ial" for mor e infor mat ion.
Examples Her e is a t ypical sequence of commands for finding a suit able model st r uct ur e:
NN = struc(2,2,1:8);
v = arxstruc(z(1:200,:),z(201:400,:),NN);
nn = selstruc(v,0);
nk = nn(3);
NN = struc(1:4,1:4,nk);
va = arxstruc(z(1:200,:),z(201:400,:),NN);
vi = ivstruc(z(1:200,:),z(201:400,:),NN);
nna = selstruc(va);
nni = selstruc(vi);
See Also arxstruc, ivstruc, struc
sett
4-97
set t
Purpose Set t he sampling int er val dir ect ly.
Syntax modn = sett(mod,T)
Description All funct ions t hat cr eat e model descr ipt ions in t he t het a or fr eqfunc for mat set
t he sampling int er val T in t heir last ar gument . For convenience sett offer s an
alt er nat ive t o set it dir ect ly. It can be applied bot h t o t he case wher e mod is a
model in t he t het a for mat and t o t he ca se wher e mod is a fr equency funct ion or
spect r um in t he fr eqfunc for mat , wit h a default choice of fr equencies.
th = armax(z,nn);
th = sett(th,T);
is equivalent t o
th = armax(z,nn,[],[],[],[],T)
Simila r ly,
g = spa(z);
g = sett(g,T);
is equivalent t o
g = spa(z,[],[],[],T)
Not e t hat you cannot use sett t o r ecalculat e models t o a new sampling
int er val. Use thc2thd or thd2thc inst ead.
See Also freqfunc, theta
spa
4-98
spa
Purpose Est imat e fr equency r esponse and spect r um by spect r al ana lysis.
Syntax [g,phiv] = spa(z)
[g,phiv,z_spe] = spa(z,M,w,maxsize,T)
Description spa est imat es t he t r a nsfer funct ion g and t he noise spect r um phiv = of t he
gener al linear model
wher e is t he spect r um of ν(t).
Mat r ix z cont ains t he out put -input dat a z = [y u], wher e y and u ar e column
vect or s. If t her e ar e sever al input s, u is a ma t r ix wit h one column for each
input . The dat a may be complex-valued.
g is r et ur ned in t he fr equency funct ion for mat (see freqfunc) wit h t he
est ima t e of at t he fr equencies specified by r ow vect or w. The default
value of w is
w = [1:128]/128∗pi/T
phiv is r et ur ned wit h t he aut ospect r um est imat e of at t he same
fr equencies. Bot h out put s ar e r et ur ned wit h est imat ed st a ndar d deviat ions
(see freqfunc).
M is t he lengt h of t he lag window used in t he calculat ions. The default value is
M = min(30,length(z)/10)
Cha nging t he va lue of M exchanges bias for var iance in t he spect r al est imat e.
As M is incr ea sed, t he est imat ed funct ions show mor e det ail, but ar e mor e
cor r upt ed by noise. The shar per pea ks a t r ue fr equency funct ion has, t he
higher M it needs. See etfe as an alt er nat ive for nar r owband signals and
syst ems.
T is t he sa mpling int er val a nd maxsize cont r ols t he memor y-speed t r ade-off
(see auxvar).
Φ
v
y t ( ) G q ( )u t ( ) v t ( ) + =
Φ
v
ω ( )
G e
i ω
( ) ω
Φ
v
ω ( )
spa
4-99
For t ime ser ies z = y, g is r et ur ned wit h t he est imat ed out put spect r um and
it s est imat ed st andar d devia t ion.
IMPORTANT: For mult i-out put dat a t he ar gument M must be ent er ed as a r ow
vect or of t he same lengt h as t he number of out put s. This is t he way t he
dist inct ion bet ween input s and out put s in z is clar ified. For default window
size use in t he mult i-out put case
M = [–1, –1, ..., –1]
The opt ional t hir d out put ar gument z_spe gives dir ect ly t he spect r um mat r ix
of z as follows:
reshape(z_spe(:,k),nz,nz) = The spect r um S at fr equency W(k)
wher e nz is t he number of channels in t he dat a mat r ix z a nd
Her e win(m) is weight at lag m of a n M-size Hamming window and W(k ) is t he
fr equency value i r ad/s. Not e t hat ' denot es complex-conjugat e t r anspose.
The nor malizat ion of t he spect r um differ s fr om t he one used by spectrum in t he
Signal Pr ocessing Toolbox . See “Some Special Topics” on pa ge 3-68 for a mor e
pr ecise definit ion.
Examples Wit h default fr equencies
g = spa(z);
bodeplot(g)
Wit h loga r it hmica lly spaced fr equencies
w = logspace(–2,pi,128);
[g,phiv] = spa(z,[],w);
% (empty matrix gives default)
bodeplot([g phiv],3)
plot s t he est imat ed spect r um t oget her wit h confidence int er vals of t hr ee
st a ndar d deviat ions.
S Ez t m + ( )z t ( )′ iW k ( )mT – ( ) exp win m ( )
m M – =
M

=
spa
4-100
Algorithm The covar iance funct ion est ima t es a r e comput ed using covf. These ar e
mult iplied by a Hamming window of lag size M and t hen Four ier t r ansfor med.
The r elevant r at ios and differ ences ar e t hen for med. For t he default
fr equencies, t his is done using FFT, which is mor e efficient t han for
user -defined fr equencies. For mult i-var iable syst ems, a st r aight for war d
for -loop is used.
Not e t hat M = is in Table 6.1 of Ljung (1987). The st andar d deviat ions a r e
comput ed as on pages 155-156 a nd 264 of Ljung (1987).
See Also auxvar, bodeplot, etfe, ffplot, freqfunc, th2ff
References Ljung (1987), Sect ion 6.4.
ϒ
ss2th
4-101
ss2t h
Purpose Cr eat e a model st r uct ur e pa r amet r ized in canonical for m.
Syntax THS = ss2th(TH)
THS = ss2th(TH,orders)
Description This funct ion conver t s any model in t het a for mat t o a canonically
par a met er ized st at e-space model, also in t het a for mat . It is useful when a
model has been obt a ined in some wa y, and you want t o use it as an init ial model
for pr edict ion er r or est imat ion using pem.
TH: The given model, which can be any model in t het a for mat .
THS: The r esult ing model, also in t het a for mat . A ca nonical pa r amet r izat ion in
obser ver for m, based on t he pseudo-obser vabilit y indices orders.
orders: The pseudo-obser vabilit y indices. A r ow vect or , wit h as many element s
as t her e ar e out put s in t he model TH. Their sum must be equal t o t he or der of
t he model TH. See canform for mor e det ails. If orders is omit t ed, a default
choice of indices is made.
If t he model TH is an out put er r or model (it s Ka lman gain equal t o zer o), t hen
so is THS. Also if t her e is a delay fr om input t o out put in TH (cor r esponding t o a
st a t e-space r epr esent at ion (3.27) in t he Tutorial wit h D=0) t hen THS will also
have such a st r uct ur e.
Ex amples Make a par amet r ized st a t e-space model fr om given ma t r ices A, B, C, D, and K
and use it as init ial condit ion for pem est imat ion:
th1 = ms2th(modstruc(A,B,C,D,K),’d’);
thi = ss2th(th1);
th = pem(z,thi);
Let t he model obt ained fr om n4sid be used a s t he init ia l value for pr edict ion
er r or est imat ion:
thn = n4sid(z,3);
thp = pem(z,ss2th(thn));
See Also canform, canstart, ms2th, n4sid
struc
4-102
st r uc
Purpose Gener at e model st r uct ur e ma t r ices.
Syntax NN = struc(NA,NB,NK)
Description struc r et ur ns in NN t he set of model st r uct ur es compr ised of all combinat ions
of t he or der s and delays given in r ow vect or s NA, NB, a nd NK. The for mat of NN
is consist ent wit h t he input for mat used by arxstruc and ivstruc. The
command is int ended for single-input syst ems only.
Examples The st at ement
NN = struc(1:2,1:2,4:5);
pr oduces
NN =
1 1 4
1 1 5
1 2 4
1 2 5
2 1 4
2 1 5
2 2 5
thc2thd
4-103
t h c2t hd
Purpose Conver t a model fr om cont inuous t ime t o discr et e t ime.
Syntax thd = thc2thd(thc,T)
Description thc is a cont inuous-t ime model in t he t het a for mat . thd is what is obt ained
when it is sampled wit h sampling int er val T. If thc is of input -out put t ype, t he
covar iance mat r ix of t he par amet er s is not t r anslat ed.
Not e t hat t he innovat ions var iance of t he cont inuous-t ime model is
int er pr et ed as t he int ensit y of t he spect r al densit y of t he noise spect r um. The
innovat ions var iance in thd will t hus be given as /T.
Examples Define a cont inuous-t ime syst em and st udy t he poles and zer os of t he sampled
count er pa r t :
thc = poly2th(1,1,1,1,[1 1 0],1,–1);
thd = thc2thd(thc,0.5);
zpplot(th2zp(thd))
See Also thd2thc
λ
λ
thd2thc
4-104
t h d2t hc
Purpose Conver t a model fr om discr et e t o cont inuous t ime.
Syntax thc = thd2thc(thd)
thc = thd2thc(thd,delay,NoP)
Description The discr et e-t ime model thd, given in t he t het a for mat , is conver t ed t o a
cont inuous-t ime count er par t thc. The covar iance ma t r ix of t he par amet er s in
t he model is also t r anslat ed using Gauss’ a ppr oximat ion for mula and
numer ical der ivat ives of t he t r ansfor mat ion. The st ep sizes in t he numer ica l
der ivat ives ar e det er mined by t he funct ion nuderst. To inhibit t he t r anslat ion
of t he covar iance mat r ix and sa ve t ime, ent er NoP = 1.
If t he discr et e-t ime model cont a ins pur e t ime delays, i.e., , t hen t hese ar e
fir st r emoved befor e t he t r ansfor mat ion is made. These delays should t hen be
appended as pur e t ime-dela y (deadt ime) t o t he cont inuous-t ime model. This is
done aut omat ically by th2ff. To have t he t ime delay appr oxima t ed by a
finit e-dimensiona l cont inuous syst em, ent er delay = 'del'. The default is
delay = 'nodel'.
If t he innovat ions var iance is in thd, a nd it s sa mpling int er val is T, t hen t he
cont inuous-t ime model has an indicat ed level of innovat ions spect r al densit y
equa l t o T ∗ .
IMPORTANT: The t r ansfor mat ion fr om discr et e t o cont inuous t ime is not
unique. thd2thc select s t he cont inuous-t ime count er par t wit h t he slowest
t ime const ant s, consist ent wit h t he discr et e-t ime model. The lack of
uniqueness also means t hat t he t r ansfor mat ion may be ill-condit ioned or even
singular. In par t icular, poles on t he negat ive r ea l a xis, in t he or igin, or in t he
point 1, ar e likely t o cause pr oblems. Int er pr et t he r esult s wit h car e.
Examples Tr ansfor m an ident ified model t o cont inuous t ime and compar e t he fr equency
r esponses of t he t wo models:
gd = th2ff(th);
thc = thd2thc(th);
gc = th2ff(thc);
bodeplot([gd, gc],3)
See Also nuderst, thc2thd
References See “Some Special Topics” on pa ge 3-68.
nk 1 >
λ
λ
theta
4-105
t h et a
Purpose Descr ibe t he t het a for mat .
Syntax help theta
help thss
Description theta is a packed mat r ix cont aining infor ma t ion a bout bot h a model st r uct ur e
and it s nominal or est imat ed par a met er s. It also cont ains ot her r elevant
infor mat ion about t he ident ifica t ion r esult .
This model for mat is t he basic for ma t wit h t he Syst em Ident ificat ion Toolbox.
It is used by a ll par amet r ic ident ificat ion met hods and it can be t r ansfor med t o
many ot her model r epr esent a t ions. See t he t ables in t he beginning of t his
chapt er for mor e det a ils.
The int er nal for mat of t he t het a for mat is int ended t o be t r anspar ent t o t he
user . The basic wa y t o display t he infor mat ion is t o use t he present command.
Some specific infor mat ion is r et r ieved fr om t he for mat by t he funct ions
getmfth, getncap, gett, a nd th2par. This ent r y gives t he det ails of t he int er na l
r epr esent at ion, but t his infor mat ion is not necessar y for most user s of t he
Syst em Ident ificat ion Toolbox. The for ma t s differ whet her t he under lying
model is in st at e-space for m or of t he input -out put black box char act er .
I. For t he general mult i-input single-out put linear model struct ure
A, B, C, D, and F a r e polynomials in t he delay oper at or of or der s na, nb, nc, nd,
and nf, r espect ively. If t he syst em has nu input s, nb, nf and nk ar e r ow vect or s
of dimension nu cont aining infor ma t ion about t he or der s and delays associat ed
wit h ea ch of t he input s. In t he ca se of a t ime ser ies (no u), B and F ar e not
defined.
Let n be t he sum of a ll t he or der s (t he number of est imat ed par amet er s) and let
r = max(n, 7, 6 + 3 nu )
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
----------------- u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
theta
4-106
Then theta is a (3+n) r mat r ix or ganized as follows:
• Row 1 has ent r ies: est imat ed var iance of e, sampling int er val T, nu, na, nb,
nc, nd, nf, and nk .
• Row 2 has ent r ies: FPE (Akaike’s Final Pr edict ion Er r or ), yea r , mont h,
dat e, hour , minut e and command by which t he model was gener at ed. The
mat r ix ent r y (2,7) t hus cont a ins t he coded number of which command gener -
at ed t he model. This number is less t han 20 for t he black-box models of t he
t ype above.
• Row 3 is t he vect or of est imat ed par amet er s, A, B ,C, D, a nd F, (excluding
leading 1s a nd 0s).
• Rows 4 t o 3+n cont ain t he est imat ed covar iance mat r ix.
• For cont inuous-t ime models, a possible element (4+n,1) cont ains a dead-t ime
for t he syst em. This is used when comput ing fr equency funct ions in th2ff.
II. For models t hat ar e defined as st at e-space st r uct ur es t her e is an under lying
M-file t hat defines t he st r uct ur e. This M-file is ca lled by
[A,B,C,D,K,X0] = mfname(par,T,aux)
(See mf2th.) For model st r uct ur es t hat ar e defined by ms2th, t he name of t his
M-file is ssmodx9 or ssmodx8 and t he a r gument aux is t he act ua l model
st r uct ur e ms cr eat ed by modstruc. Not ice in par t icular t hat mult i-out put ARX
models ar e int er nally r epr esent ed as st a t e-space models wit h t he aid of
ssmodx9.
Suppose t hat t he number of est imat ed par a met er s is n and t hat t he lengt h of
t he name of your M-file mfname is r. Suppose also t hat t he model has ny out put s
and t hat t he size of t he ar gument aux above is nr t imes nc. Then theta is a
mat r ix of dimension
max(n, ny, nc, 7 + r) by 3+ n + nr + ny)
or ganized as follows:
• Row 1 has ent r ies: det er mina nt of innovat ions covar ia nce, sampling int er -
val, number of input s, number of out put s, number of est imat ed par amet er s,
number of r ows of aux, number of columns of aux, and name of
M-file t hat defines t he st r uct ur e.
theta
4-107
• Row 2 cont ains t he ent r ies: FPE (Akaike’s Fina l Pr edict ion Er r or ), year ,
mont h, dat e, hour , minut e, and command by which t he model was gener at ed.
This last one is a number lar ger t han 20 for st a t e-space st r uct ur es.
• Ent r y (2,8) is int er pr et ed as follows: “1” means t hat t he under lying par am-
et er izat ion is in cont inuous t ime, using ssmodx9. “ll” means t hat t he under -
lying pa r amet er izat ion is in cont inuous t ime, t o be sampled by
fir st -or der -hold, using ssmodx8. “2” mea ns t hat it is in discr et e t ime, again
using ssmodx9. ‘3” means t hat t he model is a mult iva r iat e ARX model. “4”
mea ns t hat t he under lying par amet er izat ion is in discr et e t ime and user de-
fined. “5” means t hat t he model is a user -defined cont inuous-t ime par ame-
t er izat ion, equipped wit h sampling inhibit ion when called wit h a negat ive
value of T.
• Row 3 cont ains t he est imat ed (nominal) values of t he par amet er s.
• Rows 4 t o 3 + n cont ain t he est ima t ed covar ia nce mat r ix of t he par amet er s.
• Rows 4 + n t o 3 + n + nr cont ain t he mat r ix aux.
• Rows 4 +n + nr t o 3+n + nr + ny cont ain t he covar iance ma t r ix of t he inno-
vat ions of t he model.
thinit
4-108
t h init
Purpose Set init ial values for t he par amet er s t o be est imat ed.
Syntax th = thinit(th0)
th = thinit(th0,R,pars,sp)
Description This funct ion r andomizes init ial par amet er est imat es for model st r uct ur es th0
in t he t het a for mat t hat cor r espond t o st at e-space models. th is t he same model
st r uct ur e a s th0, but wit h a differ ent nomina l par amet er vect or . This vect or is
used as t he init ial est ima t e by pem.
The par amet er s a r e r a ndomized ar ound pars wit h var iances given by t he r ow
vect or R. Par amet er number k is r andomized as pars(k) + e*sqrt(R(k)),
wher e e is a nor mal r a ndom va r iable wit h zer o mean and a va r iance of 1. The
default va lue of R is a ll ones, and t he default value of pars is t he nominal
par amet er vect or in th0.
Only models t hat give st able pr edict or s ar e accept ed. If sp = 'b', only models
t hat ar e bot h st able and have st able pr edict or s ar e accept ed.
sp = 's' r equir es st abilit y only of t he model, and sp = 'p' r equir es st abilit y
only of t he pr edict or . Sp = 'p' is t he default .
A maximum of 100 t r ials ar e made by thinit. It may be difficult t o find a st able
pr edict or for high or der syst ems just by t r ia l and er r or . An alt er na t ive is t hen
t o comput e t he Kalman filt er pr edict or for a r andomized model.
See Also canstart, mf2th, ms2th, pem
th2arx
4-109
t h 2ar x
Purpose Ext r act t he ARX pa r amet er s fr om a t het a for mat model.
Syntax [A,B] = th2arx(th)
[A,B,dA,dB] = th2arx(th)
Description th is t he model in t he t het a for mat . A and B ar e r et ur ned a s t he ma t r ices t hat
define t he ARX st r uct ur e:
A = [I A1 A2 ... Ana]
B = [B0 B1 ... Bnb]
wher e
Delays in t he syst em ar e indica t ed by leading zer os in t he B mat r ices. See
Sect ion 6 in t he Tut orial.
dA and dB ar e t he st anda r d deviat ions of A and B.
See Also arx2th
y t ( ) A
1
y t 1 – ( ) … A
na
y t na – ( ) + + + B
0
u t ( ) B
1
u t 1 – ( ) … B
nb
u t nb – ( ) + + + =
th2ff, trf
4-110
t h 2ff, t r f
Purpose Comput e t he fr equency r esponse and st a ndar d deviat ions of a t het a for ma t
model.
Syntax [g,phiv] = th2ff(th)
[g,phiv] = th2ff(th,ku,w,ky)
Description th2ff comput es t he fr equency funct ions of th, wher e th is a mat r ix in t het a
for mat cont aining a gener al model.
g is r et ur ned wit h t he t r ansfer funct ion est ima t e (see (3.4), (3.23), and (3.25) in
t he Tut orial)
comput ed at t he fr equencies given in r ow vect or w. If th has sever al input s
and out put s, g is comput ed for t he input and out put number s specified in r ow
vect or s ku and ky, r espect ively. The for mat of g is det ailed under freqfunc.
The default values of ku a nd ky ar e all input and out put pair s cont ained in th.
For a t ime cont inuous model t he fr equency funct ion is obt ained inst ead.
Phiv ( ) is r et ur ned wit h t he est imat ed noise spect r um for each of t he out put s
wher e is t he est imat ed var iance of e(t) (t he loss funct ion) specified by th.
phiv is comput ed at t he same fr equencies as g. The nor malizat ion of t he
spect r um differ s fr om t he one used by spectrum in t he Signal Pr ocessing
Toolbox. See “Some Special Topics” on page 3-68, for a pr ecise definit ion. Not e
t hat no cr oss-spect r a bet ween differ ent out put s ar e comput ed.
The st andar d deviat ions of t he fr equency funct ion(s) and t he spect r a ar e also
comput ed, using t he Ga uss appr oximat ion for mula. For models wit h
complicat ed par amet er dependencies, numer ica l differ ent iat ion is applied. The
st ep sizes for t he numer ica l der ivat ives ar e det er mined by nuderst.
G e

( )
ω
G iω ( )
Φ
v
Φ
v
ω ( ) λ

T

H e
i wt
( )
2
=
λ
th2ff, trf
4-111
The default values of t he fr equencies ar e in t he discr et e-t ime ca se ar e
w = [1:128]/128∗pi/T
wher e T is t he sampling int er val specified by th (default = 1) and for t he
cont inuous-t ime ca se
w = logspace(log10(pi/abs(T)/100),log10(10*pi/ abs(T)),128)
wher e abs(T)is t he “under lying” sampling int er val for t he cont inuous-t ime
model.
The fr equency funct ions can be gr aphed wit h bodeplot, ffplot, and
nyqplot.
IMPORTANT: The command trf has t he same synt ax as th2ff but does not
ca lculat e t he st anda r d deviat ions, and can be consider ably fast er.
Examples Compar e t he r esult s fr om spect r al ana lysis and a n ARMAX model
(input -out put dynamics only).
th = armax(z,[2 2 2 1]);
gp = th2ff(th);
gs = spa(z);
bodeplot([gs gp])
Plot , but don’t st or e, t he fr equency funct ion g associat ed wit h th:
bodeplot(th2ff(th))
See Also bodeplot, etfe, ffplot, nyqplot, sett, spa
th2par
4-112
t h 2pa r
Purpose Ext r act t he pa r amet er s fr om t he t het a for mat .
Syntax [par,P,lam] = th2par(th)
Description th is a model, defined in t he t het a for ma t . par is r et ur ned as t he nominal or
est ima t ed va lues of t he fr ee par amet er s in th. The covar iance mat r ix of t he
par amet er s is obt ained as P, and lam is t he var iance (covar ia nce mat r ix) of t he
innovat ions.
The or der ing for t he par amet er s is as follows. For t he gener al input -out put
model (7.2), you have
Her e, super scr ipt r efer s t o t he input number .
For a st at e-space st r uct ur e, defined by ms2th, t he par amet er s in pars ar e
obt ained in t he following or der : The A mat r ix is fir st scanned r ow by r ow for
fr ee par amet er s. Then t he B ma t r ix is sca nned r ow by r ow, and so on for t he C,
D, K, and X0 mat r ices. (See ms2th.)
For a st at e-space mat r ix t hat is defined by mf2th, t he or der ing of t he
par amet er s is t he same as in your M-file.
Mult ivar iat e ARX models ar e int er nally r epr esent ed in st at e-space for m. The
or der ing of t he par amet er s may not be t r anspa r ent in t his ca se; it is bet t er t o
use th2arx.
pars a
1
… a
na
b
1
1
… b
nb1
1
… b
1
2
… b
nb2
2
… , , , , , , , , , , [ =
b
1
nu
… b
nbnu
nu
… c
1
… c
nc
d
1
… d
nc
f
1
1
… f
nf 1
1
… f
1
nu
… f
nf nu
nu
] , , , , , , , , , , , , , , , ,
th2poly
4-113
t h 2poly
Purpose Conver t t het a mat r ix int o it s component polynomials.
Syntax [A,B,C,D,F,LAM,T] = th2poly(th)
Description This is essent ially t he inver se of t he poly2th funct ion. It r et ur ns t he
polynomia ls of t he gener al model
as cont ained by t he mat r ix th in t het a for mat . See “Examining Models” on page
3-40.
LAM is t he noise var iance and T is t he sampling int er va l.
See Also poly2th, th2tf, theta
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
-----------------u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
th2ss
4-114
t h 2ss
Purpose Tr ansfor m a model t o st at e-space for m.
Syntax [A,B,C,D,K,X0] = th2ss(th)
[A,B,C,D,K,X0,dA,dB,dC,dD,dK,dX0] = th2ss(th)
Description th is t he model given in t he t het a for mat . A, B, C, D,K, and X0 ar e t he mat r ices
in t he st at e-space descr ipt ion
wher e is or depending on whet her th is a cont inuous or
discr et e-t ime model.
dA, dB, dC, dD, dK, and dX0 a r e t he st andar d deviat ions of t he st at e-space
mat r ices.
If t he under lying model it self is a st at e-space model, t he mat r ices cor r espond
t o t he same basis. If t he under lying model is a n input -out put model, an
obser ver canonical for m r epr esent at ion is obt ained.
Algorithm The comput at ion of t he st andar d deviat ions in t he input -out put case assumes
t hat an A polynomial is not used t oget her wit h a F or D polynomial in (7.2). For
t he comput at ion of st anda r d deviat ions in t he case t hat t he st at e-space
par amet er s ar e complicat ed funct ions of t he par amet er s, Gauss appr oximat ion
for mula is used t oget her wit h numer ical der ivat ives. The st ep sizes for t his
differ ent iat ion ar e det er mined by nuderst.
See Also mf2th, ms2th, nuderst
x
˜
t ( ) Ax t ( ) Bu t ( ) Ke t ( ) + + =
x 0 ( ) x0 =
y t ( ) Cx t ( ) Dx t ( ) e t ( ) + + =
x
˜
t ( ) x
·
x t 1 + ( )
th2tf
4-115
t h 2t f
Purpose Tr ansfor m a model t o t r ansfer funct ion for m.
Syntax [num,den] = th2tf(th)
[num,den] = th2tf(th,iu)
Description th is a model given in t he t het a for mat . num is a mat r ix whose r ow number k gives
t he numer at or polynomial associat ed wit h t he t r ansfer funct ion fr om input
number iu t o out put number k. den is a r ow vect or giving t he (common)
denominat or polynomial for t hese t r ansfer funct ions. The default value of iu is 1.
The for mat s of num and den ar e t he same as t hose used by t he Signal Pr ocessing
Toolbox and t he Cont r ol Syst ems Toolbox, bot h for cont inuous-t ime and
discr et e-t ime models. See “Examining Models” on page 3-40.
To obt ain t he t r ansfer funct ion fr om noise sour ce number k, ent er iu = –k.
Ex amples For a cont inuous-t ime model
num = [1 2]
den = [1 3 0]
cor r esponds t o t he t r ansfer funct ion
For a discr et e-t ime model
num = [2 4 0]
den = [1 2 3 5]
cor r esponds t o t he t r ansfer funct ion
which is t he same as
See Also th2poly
G s ( )
s 2 +
s
2
3s +
---------------- - =
H z ( )
2z
2
4z +
z
3
2z
2
3z 5 + + +
----------------------------------------- =
H q ( )
2q
1 –
4q
2 –
+
1 2q
1 –
3q
2 –
5q
3 –
+ + +
-------------------------------------------------------- =
th2zp, zp
4-116
t h 2zp, zp
Purpose Comput e zer os, poles, and st at ic gains of a t het a for mat model.
Syntax [zepo,k] = th2zp(th)
[zepo,k] = th2zp(th,ku,ky,thresh)
Description For any model descr ibed in t het a for mat by th, t he poles and zer os and st at ic
gains, along wit h t heir st a ndar d deviat ions ar e comput ed. The poles and zer os
ar e st or ed in coded for m in t he mat r ix zepo, while t he st at ic gains a r e r et ur ned
in k.
The best wa y t o display t he infor mat ion in zepo is t o plot it using zpplot. The
infor mat ion can also be r et r ieved wit h getzp.
The fir st r ow of k cont ains t he int eger (jy-1)∗1000+ju, wher e jy is t he out put
number and ju is t he input number for t he gain in quest ion. The second r ow of
k cont ains t he cor r esponding gains, and t he t hir d r ow t he st anda r d deviat ion
of t he gain in quest ion.
NOTE: The gain her e is t he st at ic gain, i.e., t he st eady st at e gain fr om a st ep in
input number ju t o out put number jy. It is t hus t he same for a discr et e-t ime
and a cont inuous-t ime r epr esent at ion of t he same model. This is differ ent
fr om t he r out ines ss2zp and zp2ss in t he Signal Pr ocessing Toolbox, which
use t he t ransfer function gain, i.e., t he coefficient of t he highest power in t he
numer at or.
Row vect or s ku and ky cont ain t he indices of t he input s and out put s,
r espect ively, for which t he zer os, poles and gains a r e t o be comput ed. In t his
cont ext , t he noise e(t ) is count ed as input s wit h negat ive number s. Tha t is,
noise sour ce number ju (t he ju-t h component of e(t) is count ed as input
number ju. The value 0 in t he vect or ku is t he default for “all noise sour ces.”
The default values of ku and ky ar e all input s and a ll out put s (no noise input s).
The opt ional a r gument thresh is a t hr eshold for t he comput a t ion of t he zer os.
Zer os a t infinit y may, due t o t he numer ical pr ocedur e, end up a s lar ge, finit e
values. To a void t his, any zer o whose absolut e value is la r ger t han thresh is
r egar ded t o be at infinit y. The default va lue of thresh is 100000.
The pr ocedur e handles bot h models in cont inuous and discr et e t ime.
th2zp, zp
4-117
For t he gener al discr et e-t ime mult i-input , single-out put model
t he zer os ar e t he r oot s of (wit h z r eplacing t he for wa r d shift
oper at or q), and t he poles ar e t he r oot s of . The st at ic gain is
k =B(1)/ (A(1)F(1)).
For models t hat ar e int er nally r epr esent ed in st at e-space for m, t he poles ar e
t he eigenvalues of t he syst em mat r ix. The zer os ar e t he zer os of t he
cor r esponding t r ansfer funct ion. These zer os may t hus differ fr om t he
t ransmission zeros associat ed wit h t he mult iva r iable syst em. To find t he
t r ans-mission zer os, fir st use th2ss and t hen apply tzero fr om t he Cont r ol
Syst em Toolbox.
Not e t hat you cannot r ely on infor mat ion a bout zer os and poles a t t he or igin
and at infinit y. (This is a somewhat confusing issue anyway.)
zepo is r et ur ned in a for ma t t hat a llows ea sy plot t ing wit h zpplot. (Then zer os
and poles at t he or igin and at infinit y ar e ignor ed.) The r out ine zpform is useful
when compar ing differ ent models.
The alt er nat ive r out ine zp has t he same synt ax as th2zp but does not comput e
st a ndar d deviat ions. This can be a useful alt er nat ive, when t he st a ndar d
deviat ions ar e not of int er est , and comput at ion t ime for th2zp is long.
Mor eover , zp uses ss2zp fr om t he Signa l Pr ocessing Toolbox, which may give
bet t er numer ical accur acy in difficult cases.
Not e : Alt hough zp comput es zer os and poles for all combinat ions of noise
sour ces and out put s, pr esent in t he indices ky, ku, t he command th2zp only
gives infor mat ion about poles and zer os fr om noise sour ce number ju t o out put
number ju (if ku cont ains t he number -ju).
Algorithm The st anda r d deviat ions a r e comput ed using Gauss’s appr oximat ion for mula,
using t he par amet er cova r iance mat r ix cont ained in th. When t he t r ansfer
funct ion depends on t he par a met er s in a complicat ed way, numer ical
A q ( )y t ( )
B
1
q ( )
F
1
q ( )
--------------u
1
t nk
1
– ( ) …
B
nu
q ( )
F
nu
q ( )
-----------------u
nu
t nk
nu
– ( )
C q ( )
D q ( )
------------e t ( ) + + + =
z
nb nk +
B z ( )
z
na nf +
A z ( )F z ( )
th2zp, zp
4-118
differ ent iat ion is applied. The st ep sizes for t he differ ent iat ion ar e det er mined
in t he M-file nuderst.
Not e t hat Gauss’s appr oximat ion for mula gives infinit e var iance t o poles a nd
zer os t hat ar e exact ly r epeat ed.
Examples The st at ement
zpplot(th2zp(th))
plot s, but does not st or e, t he poles and zer os.
To compa r e t he zer os a nd poles of second and t hir d or der ARX models
(input -out put dynamics only), use
th2 = arx(z,[2 2 1]);
th3 = arx(z,[3 3 1]);
zp2 = th2zp(th2);
zp3 = th2zp(th3);
zpplot(zpform(zp2,zp3))
See Also getzp, theta, zepo, zpform, zpplot
unfix par
4-119
unfixpar
Purpose Fr ee par amet er s in st r uct ur es defined by ms2th and arx2th.
Syntax thn = unfixpar(tho,matrix)
thn = unfixpar(tho,matrix,elements)
Description This funct ion is t he inver se of fixpar. The int er pr et at ion of t he ar gument s is
t he same. unfixpar makes t he indicat ed par amet er s fr ee par amet er s t o be
est imat ed. The nominal/init ial values of t hese par a met er s ar e t aken t o be
equal t o t heir a ct ual values in t he st r uct ur e tho.
See Also fixpar, ms2th, theta, thinit
zepo
4-120
zepo
Purpose Descr ibe t he zer os and pole for mat .
Syntax help zepo
Description The zepo for mat is cr eat ed by th2zp and zp and used by zpplot. It cont a ins
infor mat ion about zer os and poles and t heir st andar d devia t ions. The int er na l
for mat is int ended t o be t r anspar ent t o t he user . The basic way t o display t he
infor mat ion is t o use t he zpplot command. Some specific infor -ma t ion is
r et r ieved fr om t he for ma t by t he funct ion getzp. This ent r y gives t he det ails of
t he int er nal r epr esent at ion, but t his infor mat ion is not necessar y for most
user s of t he Syst em Ident ificat ion Toolbox.
The fir st r ow of t he mat r ix consist s of int eger s t hat give infor mat ion a bout
what t he column below cont ains. The int eger s a r e coded in t he following way:
• The zer os associa t ed wit h input number ku and out put number ky cor r e-
spond t o t he number (ky - 1)*1000 + ku.
• The st andar d deviat ions of t hese zer os cor r espond t o t he number
(ky-1)*1000 + ku +60.
• The poles associat ed wit h input number ku a nd out put number ky cor r e-
spond t o t he number (k y - 1)*1000 + ku + 20.
• The st andar d deviat ion of t hese poles cor r espond t o t he number
(ky - 1)*1000 + ku + 80.
• The zer os associat ed wit h noise input number ky and out put number ky (only
t hese ar e nor mally r epr esent ed) cor r espond t o t he number 500 + ky.
• The st andar d deviat ion of t hese, t he cor r esponding poles, and t heir st andar d
deviat ions ar e obt ained by adding 60, 20, and 80, r espect ively t o t his num-
ber .
• Posit ions cor r esponding t o nonexist ing zer os and poles (as well as zer os and
poles a t infinit y) ar e r epr esent ed by inf.
• If any of t he a bove number s is negat ive, it indicat es t hat t he pole or zer o r ep-
r esent at ion cor r esponds t o a cont inuous-t ime model. Then t he absolut e val-
ue of t he number has t he int er pr et at ion a bove.
zepo
4-121
• For complex conjugat ed pair s, t he fir st r ow in t he cor r esponding ent r y for t he
st andar d deviat ion cont ains a complex number whose r eal and imagina r y
pa r t s ar e t he st andar d deviat ions of t he r eal and imaginar y pa r t s, r espec-
t ively, of t he pole or zer o in quest ion. The next r ow ent r y (cor r es-ponding t o
t he conjugat e pole or zer o) cont ains a r eal number t ha t is t he cor r elat ion be-
t ween t he r eal and imagina r y par t s.
See Also getzp, th2zp, zpform, zpplot
zpform
4-122
zpfor m
Purpose Mer ge zer o-pole infor ma t ion fr om differ ent models.
Syntax zepo = zpform(zepo1,zepo2,...,ku)
Description The zer os a nd poles in zepo1, zepo2, ... fr om differ ent models ar e mer ged int o
one ma t r ix t o be used by zpplot. zepo1, zepo2, ... have t he for mat as pr oduced
by th2zp. ku is an opt ional r ow vect or cont aining t he input number s t o be
picked out when for ming zepo. The default value is ku is equal t o all input s
pr esent in zepo1, zepo2, ... A ma ximum of five input ar gument s t o
zpform is possible.
Examples The st at ement
zpplot(zpform(zpbj2,zpbj4,zpax2,zpax4,0))
compar es t he noise char act er ist ics fr om four differ ent models.
See Also th2zp, zpplot
zpplot
4-123
zpplot
Purpose Plot zer os a nd poles.
Syntax zpplot(zepo)
zpplot(zpform(zepo1,zepo2, ..., zepon))
zpplot(zepo,sd,mode,axis)
Description The zer os and poles specified by zepo (see zepo for t he for mat ) ar e gr aphed,
wit h o denot ing zer os and x denot ing poles. Poles and zer os associat ed wit h t he
same input , but differ ent models, a r e always gr a phed in t he same dia gr a m, and
pr essing t he Re t urn key advances t he plot fr om one model t o t he next . On
color scr eens poles, zer os and t heir confidence r egions, cor r esponding t o t he
same model all have t he same color . Poles and zer os at infinit y ar e ignor ed. For
discr et e-t ime models, zer os and poles a t t he or igin ar e also ignor ed.
If sd ha s a va lue lar ger t han zer o, confidence r egions ar ound t he poles and
zer os ar e also gr aphed. The r egions cor r esponding t o sd st a ndar d deviat ions
ar e ma r ked. The default value is sd = 0. Not e t hat t he confidence r egions ma y
somet imes st r et ch out side t he plot , but t hey a r e always symmet r ic a r ound t he
indicat ed zer o or pole.
If t he poles and zer os a r e associat ed wit h a discr et e-t ime model, a unit cir cle is
also dr awn.
When zepo cont ains infor mat ion a bout sever al differ ent input s, t her e ar e some
opt ions:
mode = 'sub' split s t he scr een int o sever a l plot s.
mode = 'same' gives all plot s in t he sa me diagr am. Pr essing t he Re t urn key
advances t he plot s.
mode = 'sep' er ases t he pr evious plot befor e t he next input is t r eat ed.
The default value is mode = 'sub'.
axis = [x1 x2 y1 y2] fixes t he axis sca ling accor dingly. axis = m is t he same
as
axis = [–m m –m m]
zpplot
4-124
Examples zpbj = th2zp(thbj2);
zpax = th2zp(tharmax4);
zpoe = th2zp(thoe3);
zpplot(zpform(zpoe,zpax,zpbj),3)
show a ll zer os a nd poles of t hr ee models along wit h t he confidence r egions
cor r esponding t o t hr ee st a ndar d deviat ions.
See Also th2zp, zpform
I-125
I ndex
A
adapt ive noise cancelling 4-82
Akaike’s Final Pr edict ion Er r or (FPE) 3-50
AR model 3-23
ARARMAX st r uct ur e 3-12
ARMAX model 2-22
ARMAX st r uct ur e 3-11
ARX model 1-6, 2-20, 3-6, 3-10, 3-17, 3-22, 3-29
B
basic t ools 3-3
Bode diagr am 2-29
Bode plot 1-9
Box-J enkins (BJ ) st r uct ur e 3-11
Box-J enkins model 2-22
Bur g’s met hod 3-23
C
canonical for ms 3-35
communicat ion window ident 2-2
compar isons using compare 3-48
complex-valued dat a 3-79
cor r elat ion analysis 1-4, 2-14, 3-15, 3-20
covar iance funct ion 3-9
covar iance met hod 3-23
cr eat ing models fr om dat a 2-2
cr oss cor r elat ion funct ion 3-52
cr oss spect r um 3-16
D
Dat a Boar d 2-3
dat a handling checklist 2-12
dat a r epr esent at ion 2-7, 3-19
dat a views 1-4
delays 3-10, 3-31
det r ending t he dat a 2-10
dist ur bance 1-5
dr ift mat r ix 3-63
dynamic models, int r oduct ion 1-5
E
est imat ion dat a 1-4
est imat ion met hod
inst ument al var iables 3-17
pr edict ion er r or appr oach 2-18, 3-17
est imat ion met hods
dir ect 2-14
par amet r ic 2-14
subspace met hod 3-18, 3-25
expor t ing t o t he MATLAB wor kspace 2-32
ext ended least squar es (ELS) 3-66
F
fault det ect ion 3-67
feedback 1-13
fr eqfunc for mat 3-20
fr equencies 3-28
fr equency
funct ion 2-15
funct ions 3-8, 3-20
plot s 3-8
r ange 3-8
r esponse 2-15
scales 3-8
fr equency domain descr ipt ion 3-10
fr equency r esponse 1-9
In d e x
I-126
G
Gauss-Newt on minimizat ion 3-24
geomet r ic lat t ice met hod 3-23
gr aphical user int er face (GUI) 2-2
GUI 2-2
t opics 2-34
H
Hamming window 3-21
I
ident window 2-34
ident ificat ion pr ocess, basic st eps 1-10
impor t ing dat a int o t he GUI 2-9
impulse r esponse 1-9, 2-29, 3-8, 3-9, 3-15
Infor mat ion Theor et ic Cr it er ion (AIC) 3-50
init ial condit ion 3-24
init ial par amet er values 3-37
innovat ions for m 3-13, 3-33
input signals 1-5
inst r ument al var iable 3-17
(IV) met hod 3-22
t echnique 3-23
it er at ions 3-27
it er at ive sear ch 3-24
K
Kalman-gain mat r ix 3-33
L
lag widow 3-16
layout 2-35
M
main ident window 2-34
maximum likelihood
cr it er ion 3-26
met hod 3-17
memor y hor izon 3-63
model
out put -er r or 1-7
pr oper t ies 1-9
set 1-4
st at e-space 1-7
st r uct ur e 2-17, 3-3
st r uct ur e select ion 3-3
st r uct ur es 3-29
uncer t aint y 3-53
validat ion 1-4
view funct ions 2-27
views 1-4, 1-7, 2-4
Model Boar d 2-3
mult ivar iable ARX model 3-30
mult ivar iable syst ems 1-16, 3-23
N
noise 1-5
noise model 1-7
noise sour ce 1-7, 2-31
noise-fr ee simulat ion 1-8
noise-fr ee simulat ions 3-53
nonpar amet r ic 3-10, 3-19
nonpar amet r ic ident ificat ion 1-4
Nor malized Gr adient (NG) Appr oach 3-64
numer ical differ ent iat ion 3-37
O
offset s 3-58
In d e x
I-127
out lier s
signals 1-4
out put signals 1-5
Out put -Er r or (OE) st r uct ur e 3-11
Out put -Er r or model 1-7, 2-22
P
par amet r ic ident ificat ion 1-4
per iodogr am 3-21
poles 1-9
pr edict ion
er r or ident ificat ion 2-18
er r or met hod 3-17
pr efilt er ing 2-11
pr efilt er ing signals 2-11
Q
Quickst ar t menu it em 2-12
R
r ecur sive
ident ificat ion 3-4, 3-61
least squar es 3-64
par amet er est imat ion 3-61
r efer ences list 1-19
r esampling 2-11
r obust est imat ion t echniques 3-27
S
sampling int er val 3-30
select ing dat a r anges 2-11
Sessions 2-5
shift oper at or 3-8
simulat ing dat a 2-12
spect r a 3-8, 3-16
spect r al analysis 1-4, 3-16, 3-20
spect r um 3-9, 3-20
st ar t up ident ificat ion pr ocedur e 1-12
st at e vect or 3-13
st at e-space
for m 3-13
model 1-7, 2-24
modeling 3-4
models 3-33
st ep r esponse 1-9, 2-29
st r uct ur e 1-4
subspace met hod 3-18, 3-25
T
t het a for mat 3-22, 3-29
t ime domain descr ipt ion 3-9
t ime-cont inuous syst ems 3-30
t r ansfer funct ion 1-6
t r ansient r esponse 1-9, 2-29
U
Unnor malized Gr adient (UG) Appr oach 3-64
V
validat ion dat a 1-4
W
whit e noise 3-9
window sizes 3-21
Wor king Dat a set 2-3
wor kspace var iables 2-6
In d e x
I-128
Y
Yule-Walker appr oach 3-23
Z
zer os 1-9

How to Contact The MathWorks:

¤
FAX

508-647-7000 508-647-7001

Phone Fax Mail

u

The MathWorks, Inc. 24 Prime Park Way Natick, MA 01760-1500
http://www.mathworks.com ftp.mathworks.com comp.soft-sys.matlab

Web Anonymous FTP server Newsgroup Technical support Product enhancement suggestions Bug reports Documentation error reports Subscribing user registration Order status, license renewals, passcodes Sales, pricing, and general information

@

support@mathworks.com suggest@mathworks.com bugs@mathworks.com doc@mathworks.com subscribe@mathworks.com service@mathworks.com info@mathworks.com

System Identification Toolbox User’s Guide © COPYRIGHT 1988 - 1997 by The MathWorks, Inc. All Rights Reserved.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. U.S. GOVERNMENT: If Licensee is acquiring the Programs on behalf of any unit or agency of the U.S. Government, the following shall apply: (a) For units of the Department of Defense: the Government shall have only the rights specified in the license under which the commercial computer software or commercial software documentation was obtained, as set forth in subparagraph (a) of the Rights in Commercial Computer Software or Commercial Software Documentation Clause at DFARS 227.7202-3, therefore the rights set forth herein shall apply; and (b) For any other unit or agency: NOTICE: Notwithstanding any other lease or license agreement that may pertain to, or accompany the delivery of, the computer software and accompanying documentation, the rights of the Government regarding its use, reproduction, and disclosure are as set forth in Clause 52.227-19 (c)(2) of the FAR. MATLAB, Simulink, Handle Graphics, and Real-Time Workshop are registered trademarks and Stateflow and Target Language Compiler are trademarks of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.

Printing History: April 1988 July 1991 May 1995 August 1995

First printing Second printing Third printing Reprint

Contents
The System Identification Problem

1

What is System Identification? . . . . . . . . . . . . . . . . . . . . . . . 1-2 How is that done? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 How do you know if the model is any good? . . . . . . . . . . . . . . 1-2 Can the quality of the model be tested in other ways? . . . . . 1-2 What models are most common? . . . . . . . . . . . . . . . . . . . . . . 1-2 Do you have to assume a model of a particular type? . . . . . . 1-2 What does the System Identification Toolbox contain? . . . . 1-2 Isn’t it a big limitation to work only with linear models? . . . 1-3 How do I get started? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Is this really all there is to System Identification? . . . . . . . . 1-3 The Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 The Basic Dynamic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Variants of Model Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 How to Interpret the Noise Source . . . . . . . . . . . . . . . . . . . . . . . 1-7 Terms to Characterize the Model Properties . . . . . . . . . . . . . . . 1-9 Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Step Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Zeros and Poles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Model Unstable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Feedback in Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Noise Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13 Model Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Additional Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Nonlinear Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Still Problems? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Fit Between Simulated and Measured Output . . . . . . . . . . 1-15 Residual Analysis Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Pole Zero Cancellations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 What Model Structures Should be Tested? . . . . . . . . . . . . . 1-15 Multivariable Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16 Available Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16 Working with Subsets of the Input Output Channels . . . . 1-17 Some Practical Advice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

iv

Reading More About System Identification . . . . . . . . . . . . . . . 1-19

The Graphical User Interface

2

The Model and Data Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 The Working Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 The Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 The Validation Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 The Work Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Management Aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Workspace Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Help Texts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Data Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Getting Data into the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Taking a Look at the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Preprocessing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Detrending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Selecting Data Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Prefiltering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Checklist for Data Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Simulating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14 Direct Estimation of the Impulse Response . . . . . . . . . . . . . . . 2-14 Direct Estimation of the Frequency Response . . . . . . . . . . . . . 2-15 Estimation of Parametric Models . . . . . . . . . . . . . . . . . . . . . . . 2-17 Estimation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Resulting Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 How to Know Which Structure and Method to Use . . . . . . . 2-19 ARX Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 The Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 Entering the Order Parameters . . . . . . . . . . . . . . . . . . . . . . 2-20 Estimating Many Models Simultaneously . . . . . . . . . . . . . . 2-20 Estimation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21 Multi-Output Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21

v

Contents

ARMAX, Output-Error and Box-Jenkins Models . . . . . . . . . . . The General Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Special Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Entering the Model Structure . . . . . . . . . . . . . . . . . . . . . . . . Estimation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . State-Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Model Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Entering Black-Box State-Space Model Structures . . . . . . . Estimating Many Models Simultaneously . . . . . . . . . . . . . . Estimation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User Defined Model Structures . . . . . . . . . . . . . . . . . . . . . . . . . State-Space Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Any Model Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Views and Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Plot Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frequency Response and Disturbance Spectra . . . . . . . . . . . . Transient Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Poles and Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compare Measured and Model Output . . . . . . . . . . . . . . . . . . . Residual Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Text Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Present . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Further Analysis in the MATLAB Workspace . . . . . . . . . . . . . Mouse Buttons and Hotkeys . . . . . . . . . . . . . . . . . . . . . . . . . . . The Main ident Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plot Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Troubleshooting in Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Layout Questions and idprefs.mat . . . . . . . . . . . . . . . . . . . . . . Customized Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Import from and Export to Workspace . . . . . . . . . . . . . . . . . . . What Cannot be Done Using the GUI . . . . . . . . . . . . . . . . . . .

2-22 2-22 2-22 2-23 2-23 2-24 2-24 2-24 2-24 2-25 2-25 2-25 2-26 2-27 2-28 2-28 2-28 2-29 2-29 2-29 2-29 2-29 2-30 2-30 2-31 2-32 2-32 2-32 2-32 2-34 2-34 2-34 2-35 2-35 2-36 2-36 2-37

vi

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 Correlation Analysis . . . . 3-47 Simulation and Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and Spectra . . . . 3-38 Theta Format: th . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Tutorial 3 Impulse Responses. . . . . . . . . . . . . . . . . . . . . . . . 3-8 Polynomial Representation of Transfer Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 General Polynomial Black-Box Models . . . . . . . . . . 3-13 Continuous-Time State-Space Models . . . . 3-33 The Black-Box. . . . . . . . . 3-16 Estimating Parametric Models . . . . . . . . . . . . . . . . . 3-36 State-Space Structures: Initial Values and Numerical Derivatives . . . . . . . . . . . . . . . . . . . . . . . 3-29 Multivariable ARX Models . . . . Frequency Functions. . . . . . . . . . . 3-45 Transformations Between Discrete and Continuous Models . . . . . . . . . . . . . . . . . . . . . . 3-44 Polynomial Format: poly . . . . . . . . . . . . . . 3-47 vii Contents . . . . . . . . 3-46 Continuous-Time Models . . . . . . . . . . . . . . . . . . 3-30 State-Space Models with Free Parameters . . . . . . . . . . . . . . . . . . . . 3-20 Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 Estimating Impulse Responses . . . . . . . . . . . . . . . . . . . . . . . 3-18 Data Representation . . . . . . . . . . . . . . . . . 3-10 State-Space Representation of Transfer Functions . . . . . . . . . . . 3-40 Frequency Function Format: ff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Discrete-Time Case . 3-46 Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37 Some Examples of User-Defined Model Structures . . . . . . . . . . . . . . . . 3-23 State-Space Models . . . . . . . . . . . . . . . . . . . . 3-20 ARX Models . . . . . . . . . . . . . . . 3-43 State-Space Format: ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45 The ARX Format: arx . . . . . . . 3-26 Polynomial Black-Box Models . . . . 3-43 Transfer Function Format: tf . . . . . . . . . . . . . . . . . . 3-34 State-Space Models with Coupled Parameters . . . . . . . . . . 3-25 Optional Variables . . . . . . . . . 3-22 AR Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46 Discrete-Time Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41 Zero-Pole Format: zp . . . . . . . . . . . 3-17 Subspace Methods for Estimating State-Space Models . . . . . . . . . . . . 3-15 Estimating Spectra and Frequency Functions . . . . 3-33 System Dynamics Expressed in Continuous Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33 Discrete-Time Innovations Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . Local Minima . . . . . . . . . Spectrum Normalization and the Sampling Interval . . . . . . . . . . . . . . . Regularization . . . . . . . . . . . . . . . . . . . Offset Levels . . . . . . . . . . . . . . . . . . . Initial Parameter Values . . Available Algorithms . . . . . . Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strange Results . . . . . . . . . Conditioning of the Prediction Error Gradient . . . Complex-Valued Data . . . . . . . . The Sampling Interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Choosing an Adaptation Mechanism and Gain . . . . . . . . . . . .Comparing Different Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Residual Analysis . . . . . . . . . Interpretation of the Loss Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Basic Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparing Different Models . . . . . . . . . . . . . . . . . 3-49 3-51 3-52 3-53 3-53 3-54 3-55 3-55 3-58 3-58 3-58 3-59 3-59 3-61 3-62 3-65 3-67 3-68 3-70 3-71 3-72 3-72 3-73 3-73 3-74 3-75 3-77 3-78 3-79 3-79 Command Reference 4 viii . . . . . . . . . . . . . . . . . . . . . . . . Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noise-Free Simulations . . . . . . . . . . Out of Memory . . . . . . . . . . . . . . . . . . . Segmentation of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assessing the Model Uncertainty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear Regression Models . . . . . . . Enumeration of Estimated Parameters . . . . . . . . . . . . . . . . . . . . . . . . . Feedback in Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking Pole-Zero Cancellations . . . . Selecting Model Structures for Multivariable Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory-Speed Trade-Offs . . . . . . . . . . . . . . . . . . . . . . Time Series Modeling . . . Filtering Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ix Contents .

. 1-18 . . . . . . . . . . 1-5 The Basic Steps of System Identification . . . . . . . 1-2 Common Terms Used in System Identification . . . . . . . . . . . . . . . . . . . . . . . . 1-12 Reading More About System Identification. . .1 The System Identification Problem Basic Questions About System Identification . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Basic Information About Dynamic Models . . . . . . . . 1-10 A Startup Identification Procedure . . . . .

as well as to preprocess and polish the measured data. This should not be correlated with other available information. Do you have to assume a model of a particular type? For parametric models. if you just assume that the system is linear. as well as all types of linear state-space models. such as ARX and ARMAX models. you can directly estimate its impulse or step response using Correlation Analysis or its frequency response using Spectral Analysis. What does the System Identification Toolbox contain? It contains all the common techniques to adjust parameters in all kinds of linear models.1 The System Identification Problem 1. What models are most common? The techniques apply to very general models. you have to specify the structure. This allows useful comparisons with other estimated models. Can the quality of the model be tested in other ways? It is also valuable to look at what the model couldn’t reproduce in the data (“the residuals”). How is that done? Essentially by adjusting parameters within a given model until its output coincides as well as possible with the measured output. such as the system's input. However. and to check if they are any good. How do you know if the model is any good? A good test is to take a close look at the model’s output compared to the measured one on a data set that wasn’t used for the fit (“Validation Data”). Most common models are difference equations descriptions. 1-2 . It also allows you to examine the models’ properties. Basic Questions About System Identification What is System Identification? System Identification allows you to build mathematical models of a dynamic system based on measured data.

1-3 . browse through Chapter and then try out a couple of the data sets that come with the toolbox. has only picked up a simple reflection of reality. Most common model nonlinearities are such that the measured data should be nonlinearly transformed (like squaring a voltage input if you think that it’s the power that is the stimuli). there is a huge amount written on the subject. actually not. however.Isn’t it a big limitation to work only with linear models? No. Use physical insight about the system you are modeling and try out such transformations on models that are linear in the new variables. Surprisingly often. Experience with real data is the driving force to understand more. It is important to remember that any estimated model. this is sufficient for rational decision making. no matter how good it looks on your screen. Use the graphical user interface (GUI) and check out the built-in help functions to understand what you are doing. and you will cover a lot! How do I get started? If you are a beginner. Is this really all there is to System Identification? Actually.

Common Terms Used in System Identification This section defines some of the terms that are frequently used in System Identification. These are unreliable measurements. and similar things. • Estimation Data is the data set that is used to fit a model to data. In the GUI this is the same as the Working Data. is also most revealing to study. • Model Sets or Model Structures are families of models with adjustable parameters. They include looking at zeros and poles. which estimates a system’s impulse response. Basically it is a matter of finding (by numerical search) those numerical values of the parameters that give the best agreement between the model’s (simulated or predicted) output and the measured one. which estimates a system’s frequency response. Of particular importance is the model’s ability to reproduce the behavior of the Validation Data sets. and Spectral analysis.1 The System Identification Problem 2. • Data Views are various ways of inspecting properties of data sets. • Nonparametric Identification Methods are techniques to estimate model behavior without necessarily using a given parametrized model set. • Validation Data is the data set that is used for model validation purposes. Thus it is important to inspect the properties of the residuals from the model when applied to the Validation Data. So-called outliers could be detected then. transient and frequency response. Parameter Estimation amounts to finding the “best” values of these parameters. 1-4 . • Model Validation is the process of gaining confidence in a model. Essentially this is achieved by “twisting and turning” the model to scrutinize all aspects of it. in terms of periodograms or spectral estimates. • Parametric Identification Methods are techniques to estimate parameters in given model structures. perhaps arising from failures in the measurement equipment. This includes simulating the model for these data and computing the residuals from the model when applied to these data. Typical nonparametric methods include Correlation analysis. The frequency contents of the data signals. A most common and useful thing is just to plot the data and scrutinize it. The System Identification problem amounts to finding both a good model structure and good numerical values of its parameters. • Model Views are various ways of inspecting the properties of a model.

since the measurement equipment typically records the signals just at discrete-time instants. elevators. Often. This section describes such a basic level of knowledge. outputs. often equally spread in time with a sampling interval of T time units. Think for example of an airplane where the inputs would be the different control surfaces. In most cases. the relationship can be depicted in the following figure. The modeling problem is then to describe how the three signals relate to each other. In the airplane example it would be wind gusts and turbulence effects.3. Output Signals y. e u y Figure 1-1: Input Signals u. only discrete-time points are considered. The outputs are then partly determined by the inputs. ailerons. Some knowledge about such models is therefore necessary for successful use of the toolbox. The Signals Models describe relationships between measured signals. It is convenient to distinguish between input signals and output signals. 1-5 . Such ‘‘unmeasured inputs’’ will be called disturbance signals or noise. If we denote inputs. respectively. and Disturbances e All these signals are functions of time. y. and the value of the input at time t will be denoted by u(t). For basic use of the toolbox. Basic Information About Dynamic Models System Identification is about building Dynamic Models. it is sufficient to have quite superficial insights about dynamic models. and e. and disturbances by u. in the identification context. and the like.The topic is treated in several places in the Chapter and there is a wide range of textbooks available for introductory and in-depth studies. the outputs are also affected by more signals than the measured inputs. while the outputs would be the airplane’s orientation and position.

7 y (t -2 T) = 0 .0 . There are a handful of variants of this model known as Output-Error (OE) models.9 u( t.T) a nd y( t.e.5 u( t. 5 y( t.7. This is what the word dynamic refers to.2 T) + 0 .9 u( t.7 y (t -2 T) + 0 . At a basic level it is sufficient to think of them as variants of the ARX model allowing also a characterization of the properties of the disturbances e. y( t) . etc. General linear models can be described symbolically by y= G u + He which says that the measured output y(t) is a sum of one contribution that comes from the measured input u(t) and one contribution that comes from the noise He.5 y (t -T ).5.3 T) The output at time t is thus computed as a linear combination of past outputs and past inputs. These are described later on in the manual.T) + 0 . It follows.5 u( t.2 T) ) • The time delay in the system is (2T in the example: you see from the second equation that it takes 2T time units before a change in u will affect y) and • How many delayed inputs to use (two in the example: u(t-2T) and u(t-3T)) Variants of Model Descriptions The model given above is called an ARX model. that is.2 T) + 0 .3 T)+ e (t ) (ARX) Such a relationship tells us. The symbol G then denotes the dynamic properties of the system. -1. how the output is formed from the input. that the output at time t depends on the input signal at many previous time instants. how to compute the output y(t) if the input is known and the disturbance can be ignored: y( t) = 1 . FIR models. and Box-Jenkins (BJ) models. for example.. 0. The identification problem is then to use measurements of u and y to figure out • The coefficients in this equation (i.) How many delayed outputs to use in the description (two in the example: y( t. An example of such an equation is the following one. For linear systems it is called the transfer function from input to output. The symbol H refers to the noise 1-6 . ARMAX models.1. for example.1 The System Identification Problem The Basic Dynamic Model The basic relationship is the linear difference equation.

They describe the same type of linear difference relationship between the inputs and the outputs as in the ARX model. The matrix K determines the noise properties. This corresponds to H = 1 in the general description above. some extra variables. The first value of the state variable vector x(0) reflects the initial conditions for the system at the beginning of the data record. To achieve this. the state variables. Thus the effect of the input on the output all passes via x(t) and will thus be delayed at least one sample. State-space models are common representations of dynamical models. Notice that if K = 0. When dealing with models in state-space form. Chapter gives more details about this. This is especially useful when there are several output signals. the effects of the noise on the output are insignificant compared to those of the input. are introduced. For basic use of the toolbox it is sufficient to know that the order of the state-space model relates to the number of delayed inputs and outputs used in the corresponding linear difference equation. and is usually referred to as an Output-Error model. Nevertheless it is important to understand the role of the noise and the noise source e(t). then the noise source e(t) affects only the output. The state-space representation looks like x ( t+ 1 ) = A x( t) + B u(t ) +K e( t) y ( t) = C x( t) + D u( t) + e( t) Here x(t) is the vector of state variables. and no specific model of the noise properties is built. It describes how the disturbances at the output are formed from some standardized noise source e(t). whether it appears in the ARX model or in the general descriptions given above. How to Interpret the Noise Source In many cases of system identification. Notice also that D = 0 means that there is no direct influence from u(t) to y(t). but they are rearranged so that only one delay is used in the expressions. K. when y(t) is a vector.. and is called the noise model. and x(0) or to let them be zero. but can be reconstructed from the measured input-output data.properties. There are three aspects of the noise that should be stressed: • understanding white noise • interpreting the noise source • using the noise source when working with the model 1-7 . a typical option is whether to estimate D. They are not measured. it is less important to have an accurate noise model. With good signal-to-noise ratios (SNR). i.e.

e. then the noise model plays no immediate role. However. In other words. • It is required for reliable predictions and stochastic control design. the responses to various inputs are to be studied. that are not contained in the input u.. It explains and captures the fact that even if an experiment is repeated with the same input. known and unknown. It contains all the influences on the measured y. but it will not give a more accurate simulation result for the actual system’s response. the noise effects are wind gusts and turbulence. i. the noise source e(t) will normally be regarded as white noise. The need and use of the noise model can be summarized as follows: • It is. the output signal will typically be somewhat different. How can we understand white noise? From a formal point of view. Since the noise source e(t) for new data will be unknown. 1-8 .1 The System Identification Problem These aspects are discussed one by one. How can we deal with the noise source when using the model? If the model is used just for simulation. has real significance. Describing these as arising from a white noise source via a transfer function H. H e(t). In the airplane example mentioned earlier. the noise source e(t) need not have a physical significance. it is taken as zero in the simulations. it is impossible to guess the value of e(t) no matter how accurately we have measured past data up to time t-1. Making another simulation with e(t) being arbitrary white noise will reveal how reliable the result of the simulation is. so as to study the effect of the input alone (a noise-free simulation). in most cases. This means that it is entirely unpredictable. • It indicates how reliable noise-free simulations are. How can we interpret the noise source? The actual noise contribution to the output. G. is just a convenient way of capturing their character. required to obtain a better estimate for the dynamics.

In the ARX example in the beginning of this section. The impulse and step responses together are called the model’s transient response. Step Response The step response is the output signal that results from a step input. i. i. there are consequently two poles and one zero.. The poles relate to the “output-side” and the zeros relate to the “input-side” of this equation. Zeros and Poles The zeros and the poles are equivalent ways of describing the coefficients of a linear difference equation like the ARX model. and the number of delays used. Instead a number of different terms are used in practice: Impulse Response The impulse response of a dynamical model is the output signal that results when the input is an impulse.. and taking y(-T)=y(-2T)=0 and u(0)=1. 2. 1. This is however a fairly implicit way of talking about the model properties. where u(0)=1. by letting t be equal to 0.. This frequency response is most often depicted by two plots. then the output y(t) will also be a sinusoid of this frequency.e. u(t) is zero for all values of t except t=0. Frequency Response The frequency response of a linear dynamic model describes how the model reacts to sinusoidal inputs. u(t) is zero for negative values of t and equal to one for positive values of t. It can be computed as in the equation following (ARX). 1-9 .e.. This is known as a Bode plot. one that shows the amplitude change as a function of the sinusoid’s frequency and one that shows the phase shift as function of frequency. . The number of poles (zeros) is equal to number of sampling intervals between the most and least delayed output (input).Terms to Characterize the Model Properties The properties of an input-output relationship like the ARX model follow from the numerical values of the coefficients. If we let the input u(t) be a sinusoid of a certain frequency. The amplitude and the phase (relative to the input) will however be different.

This section gives a brief account of the most important approaches. select useful portions of the original data. 2 Examine the data. 3 Select and define a model structure (a set of candidate system descriptions) within which a model is to be found. The procedure to determine a model of a dynamical system from observed input-output data involves three basic ingredients: • The input-output data • A set of candidate models (the model structure) • A criterion to select a particular model in the set. The cycle can be itemized as follows: 1 Design an experiment and collect input-output data from the process to be identified. Several ways to describe a system and to estimate such descriptions exist. The System Identification Toolbox offers several functions for each of these steps. Polish it so as to remove trends and outliers. and evaluating this model’s properties to see if they are satisfactory. then stop. Possibly also try other estimation methods (Step 4) or work further on the input-output data (Steps 1 and 2). otherwise go back to Step 3 to try another model set. computing the best model in the structure. based on the information in the data (the identification method) The identification process amounts to repeatedly selecting a model structure. 1-10 . The Basic Steps of System Identification The System Identification problem is to estimate a model of a system based on observed input-output data. 5 Examine the obtained model’s properties 6 If the model is good enough. and apply filtering to enhance important frequency ranges.1 The System Identification Problem 4. 4 Compute the best model in the model structure according to the input-output data and a given criterion of fit.

For Step 4 general prediction error (maximum likelihood) methods as well as instrumental variable methods and sub-space methods are offered for parametric models. and remove trends in data. as well as all the most common black-box input-output and state-space structures. like the Control System Toolbox and the Signal Processing Toolbox. as well as simulation and prediction using the model. To examine models in Step 5. while basic correlation and spectral analysis methods are used for nonparametric model structures. For Step 3 the System Identification Toolbox offers a variety of nonparametric models. many functions allow the computation and presentation of frequency functions and poles and zeros. 1-11 . Functions are also included for transformations between continuous-time and discrete-time model descriptions and to formats that are used in other MATLAB toolboxes.For Step 2 there are routines to plot data. and also general tailor-made linear state-space models in discrete and continuous time. filter data.

The steps refer to functions within the GUI. and then select the first half or so of the data record for estimation purposes. Can you see the effects in the outputs of the changes in the input? Can you see nonlinear effects. Look at them carefully. Step 1 Looking at the Data Plot the data. See Chapter for the basic commands. Step 2 Getting a Feel for the Difficulties Apply Quickstart under pop-up menu Estimate in the main ident window. The models will then describe how changes in the input give changes in output. but there are no guarantees. it is easy to get confused about what to do. A Startup Identification Procedure There are no standard and secure routes to good models in System Identification. This section describes one route that often works well. The default situation. Do physical levels play a role in your model? If not. Use this insight to select portions of the data for estimation and validation purposes. is that you detrend by removing means. detrend the data by removing their mean values. This is what happens when you apply Quickstart under the pop-up menu Preprocess in the main ident window. like different responses at different levels. Given the number of possibilities. as well as a fourth order ARX model with a delay 1-12 . or different responses to a step up and a step down? Are there portions of the data that appear to be “messy” or carry no information. and use the remaining data for validation.1 The System Identification Problem 5. with good data. what model structures to test. but not explain the actual levels of the signals. This will compute and display the spectral analysis estimate and the correlation analysis estimate. This is the normal situation. but you ca6n also go through them in command mode. Try to see the dynamics with your own eyes. and so on.

Look at the agreement between the • Spectral Analysis estimate and the ARX and state-space models’ frequency functions • Correlation Analysis estimate and the ARX and state-space models’ transient responses • Measured Validation Data output and the ARX and state-space models’ simulated outputs If these agreements are reasonable. This section discusses the most common ones. due to some regulator. Some fine tuning of model orders.estimated from the correlation analysis and a default order state-space model computed by n4sid.or 10-step ahead prediction instead of simulation in the Model Output View. 1-13 . and how they can be handled: Model Unstable The ARX or state-space model may turn out to be unstable. Discrepancies between these estimates and the ARX and state-space models can therefore be disregarded in this case. Feedback in Data If there is feedback from the output to the input. feedback in data can also be visible as correlation between residuals and input for negative lags. In the Model Residuals View of the parametric models. Change to a 5. this is an indication that the disturbances have a substantial influence. then the spectral and correlations analysis estimates are not reliable. Step 3 Examining the Difficulties There may be several reasons why the comparisons in Step 2 did not look good. and a relatively simple linear model will do a good job. but could still be useful for control purposes. the problem is not so difficult. Otherwise go to Step 3. and noise models have to be made and you can proceed to Step 4. and it will be necessary to model them carefully. Noise Model If the state-space model is clearly better than the ARX model at reproducing the measured output. This gives three plots.

Are there nonlinear effects in the system? In that case. try eighth order. think over the physics of the application. This could be as simple as forming the product of voltage and current measurements. etc. it follows that higher order models will be required. 1-14 . There may be many reasons for this.g. varying system properties. The most important one is that the data simply do not contain sufficient information. say. Among the most used models of this character are the Artificial Neural Networks (ANN). (Note that the inputs need not at all be control signals. This is of course application dependent. and just test if inclusion of them improves the fit. or could be. due to bad signal to noise ratios. Otherwise. however. the conclusion might be that a sufficiently good model cannot be produced from the data. nonlinear. should be treated as inputs). to form a number of additional inputs by reasonable nonlinear transformations of the measured ones.1 The System Identification Problem Model Order If a fourth order model does not give a good Model Output plot. Additional Inputs If the Model Output fit has not significantly improved by the tests so far.. It does not take very much work. use the insights of which inputs to use and which model orders to expect and proceed to Step 4. which cannot be realized on physical grounds. large and nonstationary disturbances. black box models could be a solution. a heating process. anything measurable. Nonlinear Effects If the fit between measured and model output is still bad. The reason may also be that the system has some quite complicated nonlinearities. consider the physics of the application. including disturbances. Are there more signals that have been. Still Problems? If none of these tests leads to a model that is able to reproduce the Validation Data reasonably well. If the fit clearly improves. measured that might influence the output? If so. form the nonlinearities from the measured data. include these among the inputs and try again a fourth order ARX model from all the inputs. e. if you realize that it is the electrical power that is the driving stimulus in. but that linear models could be sufficient. In such cases. and temperature is the output.

A rule of thumb is that a slowly varying cross correlation function outside the confidence region is an indication of too few poles. while sharper peaks indicate too few zeros or wrong delays. Then try ARMAX.” However. for which this number is the lowest. you can spend any amount of time to check out a very large number of structures. Residual Analysis Test You should require of a good model. it is not much use to fine tune orders in absurdum just to press the fit by fractions of percents. and also take into account the model complexity. It often takes just a few seconds to compute and evaluate a model in a certain structure. 1-15 . then the extra poles are just introduced to describe the noise. this suggests that lower order models can be used. There are a few things to look for in these comparisons: Fit Between Simulated and Measured Output Keep the Model Output View open and look at the fit between the model’s simulated output and the measured one for the Validation Data. or BJ model structures with an A or F polynomial of an order equal to that of the number of noncanceled poles. The only way to find this out is to try out a number of different structures and compare the properties of the obtained models. Pole Zero Cancellations If the pole-zero plot (including confidence intervals) indicates pole-zero cancellations in the dynamics. What Model Structures Should be Tested? Well. Formally. you could pick that model. different structures can give quite different model quality. experience shows that when the basic properties of the system’s behavior have been picked up. In practice. and whether the important features of the output response are captured. However. if it turns out that the orders of ARX models have to be increased to get a good fit.Step 4 Fine Tuning Orders and Noise Structures For real data there is no such thing as a “correct model structure. In particular. that the cross correlation function between residuals and input does not go significantly outside the confidence region. so that you should have a generous attitude to the testing. it is better to be more pragmatic. OE. A clear peak at lag k shows that the effect from input u(t-k) on y(t) is not properly described. but that pole-zero cancellations are indicated.

which often improves on the accuracy. estimated using n4sid. ARMAX. A basic reason for the difficulties is that the couplings between several inputs and outputs lead to more complex models. Especially for poorly damped systems. try the PEM estimation method. For multiple outputs ARX models and state-space models are covered. All earlier mentioned models are supported in the single output. if is often useful to try out ARMAX.1 The System Identification Problem Many ARX models: There is a very cheap way of testing many ARX structures simultaneously. There is a quite extensive literature on order and structure selection. Such systems are often more challenging to model. In particular systems with several outputs could be difficult. It is essentially just a matter of choosing the model order. Available Models The System Identification Toolbox as well as the GUI handles general. 1-16 . Multivariable Systems Systems with many input signals and/or many output signals are called multivariable. By clicking in this plot the best models with any chosen number of parameters will be inserted into the Model Board. using the colon (“:”) notation. and BJ models: Once you have a feel for suitable delays and dynamics orders. models for all combinations (easily several hundreds) are computed and their (prediction error) fit to Validation Data is shown in a special plot. When a good order has been found. it is preferable to work with state-space models in the multivariable case. Enter in the Orders text field many combinations of orders. Many State-space models: A similar feature is also available for black-box state-space models. the OE structure is suitable. (These are pop-up options in the GUI model order editor. multiple input case. When you select Estimate. The structures involved are richer and more parameters will be required to obtain a good fit. and anyone who would like to know more should consult the references. Multi-output ARMAX and OE models are covered via state-space representations: ARMAX corresponds to estimating the K-matrix. and evaluated as desired. while OE corresponds to fixing K to zero. linear multivariable models. and/or BJ with these orders and test some different orders for the noise transfer functions (C and D).) Generally speaking. OE. OE. since the model structure complexity is easier to deal with.

to find out which are the difficult ones to handle. This follows from the fact that knowing the set of all previous output channels gives a better basis for prediction. handling different channels. That is most easily tested by removing an input channel from the data. and then select a Validation Data set with all channels. and estimate state-space models of different orders using n4sid for these data.. you should realize that a model that has to explain the behavior of several outputs has a tougher job than one that just must account for a single output. It might not. models for prediction and control will be able to produce better results if constructed for all outputs simultaneously. for example. and checking if there is a significant deterioration in the model output’s fit to the measured one. construct new data sets using subsets of the original input/output channels. the fit gets better when more inputs are included and worse when more outputs are included. than just knowing the past outputs in one channel. Partial models of the system’s behavior will then be constructed. it might be wise to model one output at a time. However. for one output at a time. If you have difficulties obtaining good models for a multi-output system. building a model for how the output(s) depends on the remaining input channels. etc. See also the discussion under Step 3 above. Examine the resulting model primarily using the Model Output view. prefiltering. Generally speaking. be clear if all measured inputs have a significant influence on the outputs. To understand the latter fact. Do the necessary preprocessing of this set in terms of detrending. • If it is difficult to get a good fit in all output channels or you would like to investigate how important the different input channels are. You could follow the steps of this agenda: • Import data and create a data set with all input and output channels of interest. Don’t change the Validation 1-17 . • Then select a Working Data set with all channels. Models that are just to be used for simulations could very well be built up from single-output models.Working with Subsets of the Input Output Channels In the process of identifying good models of a system. it is often useful to select subsets of the input and output channels. Use the pop-up menu Preprocess > Select Channels for this. Some Practical Advice The GUI is particularly suited for dealing with multivariable systems since it will do useful bookkeeping for you.

1 The System Identification Problem Data. Use n4sid as a primary tool and try out pem when a good order has been found. built for one output at a time. It will “do the right thing” when evaluating the channel-restricted models using the Validation Data. • If you decide for a multi-output model. It might also be appropriate to see if improvements in the fit are obtained for various model types. Note that n4sid does not provide confidence intervals for the model views. it is often easiest to use state-space models. 1-18 . The GUI will keep track of the input and output channel numbers.

1983.J. and A. N. and also describes methods for physical modeling. London. Englewood Cliffs. Prentice Hall International. Signals and Systems. System Identification. System Identification . Willsky.E. J. N.J. For more details about the algorithms and theories of identification: • Ljung L. • Ljung L. Englewood Cliffs.J. Prentice Hall. The following textbook deals with identification methods from a similar perspective as this toolbox. N. The following textbook deals with the underlying numerical techniques for parameter estimation. Englewood Cliffs. Glad. Prentice Hall. and T. Schnabel. Modeling of Dynamic Systems.. • Dennis. and P. Jr. Numerical Methods for Unconstrained Optimization and Nonlinear Equations.J. Prentice Hall. N. 1989. Prentice Hall.Reading More About System Identification Reading More About System Identification There is substantial literature on System Identification. • Söderström T.B. Stoica.Theory for the User. 1994. 1985. 1-19 .S. 1987. For more about system and signals: • Oppenheim J. Englewood Cliffs. and R.

1 The System Identification Problem 1-20 .

. . . . . . . . . 2-27 Some Further GUI Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14 Examining Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34 . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Handling Data . . . . .2 The Graphical User Interface The Big Picture . . . . . . . . . . 2-7 Estimating Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

It is started by typing ident in the M ATLAB command window. each represented by an icon. The GUI covers most of the toolbox’s functions and gives easy access to all variables that are created during a session. Figure 2-1: The Main ident Information Window The Model and Data Boards System Identification is about data and models and creating models from data.2 The Graphical User Interface 1. 2-2 . each represented by an icon. The main information and communication window ident. The Big Picture The System Identification Toolbox provides a graphical user interface (GUI) . • A table over created models. is therefore dominated by two tables: • A table over available data sets.

You enter data sets into the Data Board by • Opening earlier saved sessions. More about this in “Estimating Models” on page 2-14. The Views Below the Data and Model Boards are buttons for different views. double-click on its icon.These tables will be referred to as the “Model Board” and the “Data Board” in this chapter. • Importing them from the M ATLAB workspace. More boards open automatically when necessary or when asked for (under menu Options). • Creating them by detrending. click on its icon. “Handling Data” on page 2-7 deals with this in more detail. so that its properties are displayed. selecting subsets. Imports are handled under the pop-up menu Data while creation of new data sets is handled under the pop-up menu Preprocess. To change the Working Data set drag and drop any data set from the Data Board on the Working Data icon. of another data set in the Data Board. • Importing them from the M ATLAB workspace. while all the different estimation schemes are reached under the pop-up menu Estimate.. The models are entered into the summary board by • Opening earlier saved sessions. The Data and Model Boards can be rearranged by dragging and dropping. Imports are handled under the pop-up menu Models. To select a data set or a model. • Estimating them from data. A selected object is marked by a thicker line in the icon. click again. filtering. 2-3 . To deselect. and are described in more detail in “Handling Data” on page 2-7 and in “Examining Models” on page 2-27. The Working Data All data sets and models are created from the Working Data set. An arbitrary number of data/model objects can be examined simultaneously. To have more information about an object. etc. This is the data that is given in the center of the ident window. These control what aspects of the data sets and models you would like to examine.

perhaps first doing a quickstart. By double-clicking on a data/model icon. At this point you can also add comments and change the name of the object and its color. In this way models corresponding to a particular data set can be grouped together. It is good and common practice in identification to evaluate an estimated model’s properties using a “fresh” data set. along with other key information. drag and drop any data set from the Data Board on the Validation Data icon. You probably remove the means from the data and select subsets of data for estimation and validation purposes using the items in the pop-up menu Preprocess. Management Aspects Diary: It is easy to forget what you have been doing. you examine the data set using the Data Views. you continue to try out different model structures (model orders) until you find a model you are satisfied with. You select/deselect a model by clicking on its icon. You then continue to estimate models. This is the set marked in the box below these two views. Inspired by the information you gain from the plots. You can also open new boards (Options menu Extra model/data boards) to further rearrange the icons. 2-4 . The Work Flow You start by importing data (under pop-up menu Data). that is. etc. it is good practice to try rearranging the icons by dragging and dropping. one that was not used for the estimation. but they should of course be compatible with these.2 The Graphical User Interface The Validation Data The two model views Model Output and Model Residuals illustrate model properties when applied to the Validation Data set. Layout: To have a good overview of the created models and data sets. These can be dragged across the screen between different windows. This function is “live” so models and views can be checked in and out at will in an online fashion. using the possibilities under the pop-up menu Estimate. a complete diary will be given of how this object was created. The extra boards are also equipped with notepads for your comments. The basic idea is that any checked view shows the properties of all selected models at any time. It is thus good advice to let the Validation Data be different from the Working Data. To change the Validation Data. You examine the obtained models with respect to your favorite aspects using the different Model Views.

or check/ uncheck the corresponding View box).) Window Culture: Dialog and plot windows are best managed by the GUI’s close function (submenu item under File menu. th2ff. and reloaded later. but “quit” will not be properly acknowledged by the GUI. (Double-clicking on the trash can will open it up. two GUI objects can carry the same name (i. Cleanliness: The boards will hold an arbitrary number of models and data sets (by creating clones of the board when necessary). you can enter any other name of your choice at the time of creation of the variable. Note that models have a specific internal structure and should be dealt with using the MATLAB commands present. and its contents can be retrieved. It is generally not suitable to iconify the windows – the GUI’s handling and window management system is usually a better alternative. This does no harm. and then perhaps import modified versions back into the GUI. See “Model Conversions” on page 4-5 of the "Command Reference" chapter.. by dragging and dropping the object icon on the To Workspace box. The GUI’s names of data sets and models are suggested by default procedures. Normally. the workspace is not at all littered with variables during the sessions with the GUI. the same string in their icons). using any M ATLAB commands. 2-5 . etc. You can work with the variables in the workspace. th2ss. This is the counterpart of save/load workspace in the command-driven MATLAB. The four most recent sessions are listed under File for immediate open.e. Indeed. Unlike the workspace situation. They will then carry the name in the workspace that marked the object icon at the time of export. Names can be changed (after double-clicking on the icon) at any time. and the window will have to be re-created next time it is to be used. Workspace Variables The models and data sets created within the GUI are normally not available in the MATLAB workspace.Sessions: The Model and Data Boards with all models and data sets together with their diaries can be saved (under menu item File) at any point. They may also be”quitted” by the specific window system’s quit/close function. Do that by dragging the object to the Trash Can. The variables can however be exported at any time to the workspace. It is however advisable to clear (delete) models and data sets that no longer are of interest. or select Close.

The same disaster occurs if you do clg or quit the main ident window. NOTE: Do not clear all or clear global during a GUI session! This would mean that you lose control over the objects that you have created. when required. They all start with the prefix XID. This is also the case for the various plot windows. 2-6 . Help Texts The GUI contains some 100 help texts that are accessible in a nested fashion. The main ident window contains general help topics under the Help menu. It is however safe to clear (without adding all or global) the workspace at any time. In addition.2 The Graphical User Interface The GUI produces a handful of global workspace variables for management purposes. every dialog box has a Help push button for current help and advice.

g. The GUI will then handle the data representation automatically. will then be the signal’s value at sampling instant number k.. Handling Data Data Representation In the System Identification Toolbox (SITB). and the sampling interval T is supplied as a specific argument. signals and observed data are represented as column vectors. you only need to think of these representation issues when you insert the data set into the summary board. If the system has several input channels. 2-7 . followed by the input column(s): z = [y u].. u(k). When you work with the GUI. The observed input-output data record is represented in the SITB by a matrix. We generally denote the input to a system by the letter u and the output by y. where the columns are the input signals in the different channels: u = u1 u2 … um The same holds for systems with several output channels. where the first column(s) is the output. u( 1) u( 2) u = … … u( N ) The entry in row number k.2. It is generally assumed in the toolbox that data are sampled at equidistant sampling times. i. the input data is represented by a matrix.e. e.

These are notes for your own information and bookkeeping that will follow the data and all models created from them. 2-8 .2 The Graphical User Interface Getting Data into the GUI The information about a data set that should be supplied to the GUI is as follows: 1 The input and output signals 2 The name you give to the data set 3 The starting time 4 The sampling interval 5 Data notes NOTE: Items 3 and 4 are used only to ensure correct time and frequency scales when you plot data and model characteristics.

5. and they will be evaluated to compute the input and the output before inserting the data into the GUI. a dialog box will open. Note that you can enter any text you want to accompany the data for bookkeeping purposes. Starting time and Sampling interval: Fill these out for correct time and frequency scales in the plots. This name can be changed later on. This box has six fields for you to fill in: Figure 2-2: The Dialog for Importing Data into the GUI Input and Output: Enter the variable names of the input and output respectively. Data name: Enter the name of the data set to be used by the GUI. just listed.. Actually.. you can enter any MATLAB expressions in these fields.As you select the pop-up menu Data and choose the item Import. These should be variables in your MATLAB workspace. 2-9 . so you may have to load some disk files first.. where you can enter the information items 1 .

This function is accessed under the pop-up menu Preprocess. by selecting item Remove Means or Remove Trends. and if the data have to be preprocessed in some way. Preprocessing Data Detrending Detrending the data involves removing the mean values or linear trends from the signals (the means and the linear trends are then computed and removed from each signal individually). When no more data sets are to be inserted.. the absolute square of the Fourier transforms of the data. The purpose of examining the data in these ways is to find out if there are portions of the data that are not suitable for identification. More advanced detrending. unless physical insight involving actual signal levels is built into the models. by the Options menu item in the spectra window. It is generally recommended that you always remove at least the mean values of the data before the estimation phase. Reset will empty all the fields of the box. 2-10 . For multivariable data.e. By default the periodograms of the data are shown. To examine the frequency contents of the data. a plot of the input and output signals will be shown for the data sets that are selected. but the signals’ spectra are shown instead. The plot can be changed to any chosen frequency range and a number of different ways of estimating spectra. check the Data View item Data Spectra.2 The Graphical User Interface Finally. The function is analogous to Plot Data. select Close to close the dialog box. the different combinations of input and output signals are chosen under menu item Channel in the plot window. such as removing piecewise linear trends or seasonal variations cannot be accessed within the GUI. before using them for estimation. By checking the Data View item Plot Data. Using the zoom function (drawing rectangles with the left mouse button down) different portions of the data can be examined in more detail. select Import to insert the data into the GUI. i. if the information contents of the data is suitable in the interesting frequency regions. Taking a Look at the Data The first thing to do after having inserted the data set into the Data Board is to examine it. You select/ deselect the data sets by clicking on them.

The menu item Preprocess > Select Channels.. you can also make sure that the model concentrates on the important frequency ranges. it is advisable to select one portion of the measured data for estimation purposes and another portion for validation purposes. so that only portions of the data can be used.e.Selecting Data Ranges It is often the case that the whole data record is not suitable for identification.. and also a good alternative to detrending (by cutting out low frequencies from the pass band). which facilitates the selection of different data portions. You mark with a rectangle in the spectral plots the intended passband or stop band of the filter. 2-11 . This is done in such a way that the input/output numbering remains consistent when you evaluate data and model properties. the frequency band around the intended closed-loop bandwidth is of special importance. Resampling If the data turn out to be sampled too fast. by typing in the ranges. This is obtained from menu item Preprocess > Resample. Prefiltering By filtering the input and output signals through a linear filter (the same filter for all signals) you can focus the model’s fit to the system to specific frequency ranges.). Depending on the intended model use. allows you to select subsets of the inputs and outputs. they can be decimated. due to various undesired features (missing or “bad” data. For a model that will be used for control design.. opens a dialog box.. outbursts of disturbances. every k-th value is picked. for example.. and then you insert the filtered data into the GUI’s Data Board. you select a button to check if the filtering has the desired effect. In any case. The pop-up menu item Preprocess > Select Range. for models covering different subsets of the data. or marking them by drawing rectangles with the mouse button down. level changes etc.. The dialog is quite analogous to that of selecting data ranges in the time domain. in the main window. This is done by selecting the pop-up menu item Preprocess > Filter. i. For multivariable data it is often advantageous to start by working with just some of the input and output signals.. Prefiltering is a good way of removing high frequency noise in the data. after proper prefiltering (antialias filtering).

2 )+ e (t ). Drag and drop these data sets to the corresponding boxes in the GUI. 2-12 .e( t. idsim. and ms2th in Chapter 4. Simulating Data The GUI is intended primarily for working with real data sets.5 y (t -1 ) + 0 . Quickstart The pop-up menu item Preprocess > Quickstart performs the following sequence of actions: It opens the Time plot Data view. using the same command. y = idsim([u e].5 u( t. and you can use your favorite procedure in S IMULINK. and it splits these detrended data into two halves. "Command Reference. • Possibly prefilter the data to enhance and suppress various frequency bands.7 y( t. poly2th. and giving a resampling factor less than one.2 The Graphical User Interface You can also resample at a faster sampling rate by interpolation.1 )+ 0 . All the three created data sets are inserted into the Data Board. • Typically detrend the data by removing mean values.’rbs’." for details. • Plot the data and examine it carefully. e = randn(400.[0 1 0. Checklist for Data Handling • Insert data into the GUI’s Data Board.7]. 2e (t -2 ) is simulated with a binary random input u: model1 = poly2th([1 -1. • Select portions of the data for Estimation and for Validation. That has to be done in command mode. u = idinput(400.5]. The following example shows how the ARMAX model y (t ). the Signal Processing Toolbox.1).2 ) = u(t -1 ) + 0 . You should check idinput.1 .[1 -1 0. The first one is made Working Data and the second one becomes Validation Data. or any other toolbox for simulation and then insert the simulated data into the GUI as described above. The System Identification Toolbox also has several commands for simulation. removes the means from the signals.2]).5 0. and does not itself provide functions for simulating synthetic data.[0 0.3]).model1). modstruc.

C. its properties can be compared to those of the different estimated models. y=idsim([u e].D. can now be imported into the Graphical User Interface as data.0. 0. and the output.-0. do the following in the System Identification Toolbox: A=[-1 1. By also importing the simulation model.'c'). into the GUI. 2-13 .model2).5.1).5]. and a sampling interval of 0. and the various estimation routines can be applied to them. D=0. K=[0. model2=sett(model2.1 seconds. model2=ms2th(modstruc(A. u.5].B.The input. To simulate a continuous-time state-space model: · x = Ax + Bu + Ke y = C x+ e with the same input.5 0].K). C=[1 0]. y.0. model1. B=[1.

Its i-j element thus described the behavior of the i-th output after an impulse in the j-th input.2 The Graphical User Interface 3. All estimation routines are accessed from the pop-up menu Estimate in the ident window. and the parameters in this structure are estimated using data.e. A specific model structure is assumed. i. other than that it is linear.. By choosing menu item Estimate > Correlation Model and then selecting Estimate in the dialog window that opens. One can distinguish between two different types of estimation methods: • Direct estimation of the Impulse or the Frequency Response of the system. Direct Estimation of the Impulse Response A linear system can be described by the impulse response gt. impulse response coefficients are estimated directly from the input/output data using so called correlation 2-14 . Dominating ways are state-space and several variants of difference equation descriptions. u(t)=1 when t=0 and 0 when t>0 then the output y(t) will be y(t)=gt. • Parametric methods. It is also the one that offers the most variety of possibilities and thus is the most demanding one for the user. with the property that y( t)= ∞ ∑ gku( t – k ) k=1 The name derives from the fact that if the input u(t) is an impulse. where p is the number of outputs and m is the number of inputs. This opens up a large variety of possibilities. Estimating Models The Basics Estimating models from data is the central activity in the System Identification Toolbox. the impulse response gk will be a p by m matrix. The models are always estimated using the data set that is currently in the Working Data box. For a multivariable system. and do not impose any structure assumptions about the system. corresponding to different ways of describing the system. These methods are often also called nonparametric estimation methods.

The system’s frequency response is directly estimated using Spectral Analysis by the menu item Estimate > Spectral Model. An option that determines the order of a prewhitening filter can also be set in the dialog window. i. consult See “The System Identification Problem” on page 3-8. the responses from a certain input to a certain output. The result is placed on the Model 2-15 . This gives a graph of the estimated response.) The best way to examine the result is to select the Model View Transient Response. the different channels. in the Tutorial or any textbook on linear systems. and the default choice is often good enough. and then selecting the Estimate button in the dialog box that opens. the length of the estimated response. The resulting impulse response estimate is placed in the Model Board. To obtain the default choice without opening the dialog window. This view offers a choice between displaying the Impulse or the Step response. T is the sampling interval. The function G ( e iω T ) as a function of (angular) frequency ω is then the frequency response or frequency function. The relation between input and output is often written y ( t) = G(z) u( t) + v( t) where G is the transfer function and v is the additive disturbance. The actual method is described under the command cra in the Command Reference chapter.. This is the “hotkey” for correlation analysis.. under the default name cra_d. If you need more details on the different interpretations of the frequency response.e. This description of the system gives considerable engineering insight into its properties. Direct Estimation of the Frequency Response The frequency response of a linear system is the Fourier transform of its impulse response. It is not very sensitive in most cases. For a multivariable system.e. i. (The name can be changed by double-clicking on the model icon and then typing in the desired name in the dialog box that opens. The number of lags for which the impulse response is estimated. you can also just type the letter c in the ident window. is determined as one of the options in the Transient Response View. are selected under menu item Channel.analysis.

This view offers a number of different options on how to graph the curves. "Command Reference. It however has the drawbacks that it requires linearly spaced frequency values. The options also offer a choice between the Blackman-Tukey windowing method spa (which is default) and a method based on smoothing direct Fourier transforms." for more information. To obtain the spectral analysis model for the current settings of the options. (the size of the lag window) that affects the frequency resolution of the estimates. The default choice of M is good for systems that do not have very sharp resonances and may have to be adjusted for more resonant systems. the frequency resolution is about 2 π /M radians/(sampling interval). you can export the model to the MATLAB workspace and retrieve the responses by the command getff. Essentially. etfe has an advantage for highly resonant systems. etfe. you can just type the hotkey s in the ident window. The choice of M is a trade-off between frequency resolution and variance (fluctuations). The frequencies for which to estimate the response can also be selected as an option under the Options menu in this View window. See freqfunc and getff in Chapter 4. and does not provide confidence intervals. This estimated disturbance spectrum is examined under the Model View item Noise Spectrum.) Two options that affect the spectral analysis estimate can be set in the dialog box. The Spectral Analysis estimate is stored in the SITB’s freqfunc format.2 The Graphical User Interface Board under the default name spa_d. The most important choice is a number. If you need to further work with the estimates. (A model is exported by dragging and dropping it over the To Workspace icon. in that it is more efficient for large values of M. "Command Reference. A large value of M gives good resolution but fluctuating and less reliable estimates. M. does not estimate the disturbance spectrum. The actual methods are described in more detail in Chapter 4. 2-16 . The best way to examine it is to plot it using the Model View Frequency Response." under spa and etfe. The Spectral Analysis command also estimates the spectrum of the additive disturbance v(t) in the system description.

avoid spaces in the name. but you can change it to any string before selecting the Estimate button. This opens up a dialog box Parametric Models.. They are all accessed by the menu item Estimate > Parametric Models.Estimation of Parametric Models The SITB supports a wide range of model structures for linear systems. The GUI will always suggest a default model name in the Name box. which is written in the edit box Name. (If you intend to export the model later. The structure of this model is defined by the pop-up menu Structure together with the edit box Orders. in the ident window.. which contains the basic dialog for all parametric estimation as shown on the following page Figure 2-3: The Dialog Box for Estimating Parametric Models The basic function of this box is as follows: As you select Estimate.) 2-17 . a model is estimated from the Working Data. It is given a name.

This will open up another dialog box. When it is available. six choices: • ARX models • ARMAX model • Output-Error (OE) models • Box-Jenkins (BJ) models • State-space models • Model structure defined by Initial Model (User defined structures) These are dealt with one by one shortly. but for assistance you can select Order Editor. Estimation Method A common and general method of estimating the parameters is the prediction error approach. You can also enter a name of a MATLAB workspace variable in the order edit box. a button Order selection is visible. depending on the chosen Structure. This option is described in more detail later in this section. NOTE: For the state-space structure and the ARX structure. depends on the selected Structure in the pop-up menu. typically. This method is available for all model structures. the estimation involves an iterative.. Except for the ARX case. You can fill out the Order box yourself at any time.. where simply the parameters of the model are chosen so that the difference between the model’s (predicted) output and the measured output is minimized. This covers. several orders and combination of orders can be entered. Then all corresponding models will be compared and displayed in a special dialog window for you to select suitable ones.2 The Graphical User Interface The interpretation of the model structure information (typically integers) in the Order box. This variable should then have a value that is consistent with the necessary orders for the chosen structure. in which the desired model order and structure information can be entered in a simpler fashion. 2-18 . numerical search for the best fit. This could be a useful tool to select good model orders.

Resulting Models The estimated model is inserted into the GUI’s Model Board. and its parameters with estimated standard deviations in the MATLAB command window. you can quickly find out if the new model is any better than the ones you had before.".double-click). "Command Reference. This also gives access to a number of options that govern the search process. More about that in “Examining Models” on page 2-27. 2-19 .". th2par. The choice between methods is made in the Parametric Models dialog box. The Data/Model Info window that then opens gives you information about how the model was estimated. and then apply any M ATLAB and toolbox commands to it. and thd2thc in Chapter 4. you can export it by dragging and dropping it over the To Workspace icon. in fact. and by the different validation tools described in the next section. (See. You can then also select Present button. th2tf. which will list the model. and spending a few extra minutes trying out several different structures is usually worth while. (See auxvar in the Chapter 4... and black-box state-space models) methods based on correlation are also available: Instrumental Variable (IV) and Sub-space (N4SID) methods. It is best to be generous at this point. there is no such thing as a “best” structure. the commands th2ss. for real data. select Iteration control. There is often a significant amount of work behind the data collection. double-click on the model’s icon (middle/right mouse button or alt. To take a look at the model itself. It often takes just a few seconds to estimate a model.) For some model structures (the ARX model.To obtain information from and interact with this search. in particular. Some routes to find good and acceptable model are described in “A Startup Identification Procedure” on page 1-12 in the introductory chapter. You can then examine its various properties and compare them with other models’ properties using the Model View plots.) How to Know Which Structure and Method to Use There is no simple way to find out “the best model structure”. If you need to work further with the model. "Command Reference.

Estimating Many Models Simultaneously By entering any or all of the structure parameters as vectors. and nk can either be directly entered into the edit box Orders in the Parametric Models window. For a system under sampled-data control. and nk. using MATLAB’s colon notation. The structure is thus entirely defined by the three integers na. Multi-input models: For multi-input models you can of course enter each of the input orders and delays as a vector. For multi-input systems nb and nk are row vectors..2 The Graphical User Interface ARX Models The Structure The most used model structure is the simple linear difference equation y ( t ) + a 1 y ( t – 1 ) + … + a n a y ( t – na ) = b 1 u ( t – nk ) + … + b nb u ( t – nk – nb + 1 ) which relates the current output y(t) to a finite number of past outputs y(t-k) and inputs u(t-k). 2-20 . nb. When selecting Estimate. you define many different structures that correspond to all combinations of orders. nb. Entering the Order Parameters The orders na. As an alternative. Then only such models are computed that have the same orders and delays from all inputs. typically nk is equal to 1 if there is no dead-time. like na=1:10. A special plot window will then open that shows the fit of these models to Validation Data. models corresponding to all of these structures are computed. na is equal to the number of poles and nb–1 is the number of zeros. while nk is the pure time-delay (the dead-time) in the system. By clicking in this plot. you may enter one vector (like nb=1:10) for all inputs and one vector for all delays. etc. The number of models resulting from all combinations of orders and delays can however be very large. or selected using the pop-up menus in the Order Editor. where the i-th element gives the order/delay associated with the i-th input. you can then enter any models of your choice into the Model Board.

Multi-Output Models For a multi-output ARX structure with NY outputs and NU inputs. The methods are described in more detail in Chapter 4.NY) NB = nb∗ones(NY.NU) where na. nb. The orders [NA NB NK] define the model structure as follows: NA: an NY by NY matrix whose i-j entry is the order of the polynomial (in the delay operator) that relates the j-th output to the i-th output NB: an NY by NU matrix whose i-j entry is the order of the polynomial that relates the j-th input to the i-th output NK: an NY by NU matrix whose i-j entry is the delay from the j-th input to the i-th output The Order Editor dialog box allows the choices NA = na∗ones(NY." under arx and iv4.hand sides becomes uncorrelated with certain linear combinations of the inputs. 2-21 .Estimation Methods There are two methods to estimate the coefficients a and b in the ARX model structure: Least Squares: Minimizes the sum of squares of the right-hand side minus the left-hand side of the expression above. This is obtained by selecting ARX as the Method. "Command Reference. with respect to a and b. Note that the possibility to estimate many models simultaneously is not available for multi-output ARX models.and left. construct a matrix [NA NB NK] in the MATLAB command window and enter the name of this matrix in the Order edit box in the Parametric Models window.NU) NK = nk∗ones(NY. Instrumental Variables: Determines a and b so that the error between the right. the difference equation above is still valid. and nk are chosen by the pop-up menus. For tailor-made order choices. See “Defining Model Structures” on page 3-29 for more information on multi-output ARX models. The only change is that the coefficients a are NY by NY matrices and the coefficients b are NY by NU matrices. This is obtained by selecting IV in the Method box.

Likewise F(q) determines the poles that are unique for the dynamics from input # i.. and A. are polynomials in the shift operator (z or q). and Fi.nb + 1 ) + e(t ) + c 1e(t . Bi.) The general structure is defined by giving the time-delays nk and the orders of these polynomials (i. as well as of the noise model from e to y). Output-Error. see below.2 The Graphical User Interface ARMAX. (Don’t get intimidated by this: It is just a compact way of writing difference equations.. D.+ a nay ( t.1 )+ . 2-22 .nk )+ .. the number of poles and zeros of the dynamic model from u to y. Output-Error and Box-Jenkins Models There are several elaborations of the basic ARX model. .na )= b 1u( t. These include well known model types.b nbu (t -nk .e.. where different noise models are introduced. C. . For example the ARMAX model in longhand would be: y( t) + a 1( t.. + e nce (t -nc ) Note that A(q) corresponds to poles that are common between the dynamic model and the noise model (useful if noise enters the system “close to” the input). and Box-Jenkins. and D(q) the poles that are unique for the noise.1) + . The General Structure A general input-output linear model for a single-output system with input u and output y can be written: A ( q )y ( t ) = ∑ [ B i ( q ) ⁄ Fi ( q ) ] u i( t – nk1 ) + [ C ( q ) ⁄ D ( q ) ] e ( t ) i=1 nu Here ui denotes input #i. such as ARMAX. The Special Cases Most often the choices are confined to one of the following special cases: ARX: A(q) y(t) = B(q) u(t-nk) + e(t) ARMAX: A(q) y(t) = B(q) u(t-nk) + C(q) e(t) OE: BJ: y(t) = [B(q)/F(q)] u(t-nk) + e(t) (Output-Error) y(t) = [B(q)/F(q)] u(t-nk) + [C(q)/D(q)] e(t) (Box-Jenkins) The “shift operator polynomials” are just compact ways of writing difference equations.

only the first choice is available. Note that if the Working Data set has several outputs. "Command Reference. by minimizing the size of the error term “e” in the expression above. Entering the Model Structure Use the Structure pop-up menu in the Parametric Models dialog to choose between the ARX. and Box-Jenkins structures. the default orders. Several options govern the minimization procedure. NOTE: These model structures are available only for the scalar output case.The motivation for introducing all these model variants is to provide for flexibility in the noise description and to allow for common or different poles (dynamics) for the different inputs. entered as you change the model structure." under armax. Output-Error. and pem. The orders of the polynomials are selected by the pop-up menus in the Order Editor dialog window. See also “Parametric Model Estimation” on page 3-22 and “Defining Model Structures” on page 3-29. are based on previously used orders. or by directly entering them in the edit box Orders in the Parametric Models window. When the order editor is open. auxvar. and selecting Option. 2-23 . Also note that it is not possible to estimate many different structures simultaneously for the input-output models. These are the time series counterparts of ARX and ARMAX. For multi-output models. These are accessed by activating Iteration Control in the Parametric Models window. Estimation Method The coefficients of the polynomials are estimated using a prediction error/ Maximum Likelihood method. the state-space structures offer the same flexibility. The algorithms are further described in Chapter 4. bj. For time series (data with no input signal) only AR and ARMA are available among these choices. oe. ARMAX.

or enter it directly into the Orders edit box in the Parametric Models window. this is a natural assumption. • Fixing D to zero means that there is a delay of (at least) one sample from the input to the output. you can further affect the chosen model structure: • Fixing K to zero gives an Output-Error method. Use the pop-up menu in the Order Editor to choose the model order. You can then enter models of different orders into the Model Board by clicking in a special graph that contains information about the models. free parametrizations. this corresponds to an assumption that the output disturbance is white noise. (such as “1:10”) all indicated orders will be computed using a preliminary method. For physical systems that are driven by piece-wise constant inputs.e.. Entering Black-Box State-Space Model Structures The most important structure index is the model order.e. using MATLAB’s colon notation.. (Note that the estimated value of x(0) is something that relates to the Working Data. Otherwise this initial state is estimated from the data. the dimension of the state vector x. the difference between the model’s simulated output and the measured one is minimized. and parametrizations tailor-made to the application.” First we will discuss the black-box case.2 The Graphical User Interface State-Space Models The Model Structure The basic state-space model in innovations form can be written x ( t+ 1) = A x( t) + B u (t ) + K e(t ) y( t) = C x( t) + D u (t ) + e(t ) The SITB supports two kinds of parametrizations of state-space models: black-box. and is not necessarily a good value of x(0) for the Validation Data. i. 2-24 . The latter is discussed below under the heading “User Defined Model Structures. Formally. • Fixing the initial value x(0) to zero means that the initial state is not estimated.) Estimating Many Models Simultaneously By entering a vector for the model order. i. Using the other pop-up menus in the Order Editor.

The parametrization of the matrices A. K. The search for minimum is controlled by a number of options. and X0 matrices can be easily defined both for discrete. D. The command mf2th allows you to use a completely arbitrary structure. The model that gives the best fit is chosen. Using the command ms2th. This auxiliary order can be given within parenthesis after the order in the edit box Orders (like “4 (9)”). and K follows a default canonical form." for more information. The quality of the resulting estimates may significantly depend on an auxiliary order (like a prediction horizon). See Chapter 4. These are accessed from the Option button in the Iteration Control window. N4SID: Is a subspace-based method that does not use iterative search. 2-25 . C. just define the appropriate structure in the MATLAB command window. C. If the auxiliary order is given as a vector (like “4 (5:17)”). Then use the Structure pop-up menu to select By Initial Model and enter the variable name of the structure in the edit box Initial Model in the Parametric Models window and select Estimate. a default value is used. B. If the auxiliary order is not given. D. otherwise a one-step ahead prediction error fit. "Command Reference. "Command Reference. based on iterative minimization of a criterion. (The fit is a simulation error fit if K=0 is chosen.Estimation Methods There are two basic methods for the estimation: PEM: Is a standard prediction error/maximum likelihood method. fixpar and unfixpar can be used to manipulate structures.) See n4sid and pem in Chapter 4. known and unknown parameters in the A. A figure is shown that illustrates the fit as a function of auxiliary order. The iterations are started up at parameter values that are computed from n4sid. B. User Defined Model Structures State-Space Structures The SITB supports user-defined linear state-space models of arbitrary structure. models for all these auxiliary orders are computed and evaluated using the Working Data set. defined by an M-file." and “Defining Model Structures” on page 3-29 To use these structures in conjunction with the GUI.and continuous-time models.

2 The Graphical User Interface Any Model Structure Arbitrary model structures can be defined using several commands in the System Identification Toolbox: • poly2th: Creates Input-output structures for single-output models • ms2th: Creates Linear State-space models with arbitrary. 2-26 . Then the parameters of the model structure are adjusted to the chosen Working Data set. Options that govern this search are accessed by the Option button in the Iteration Control window. free parameters • mf2th: Creates completely arbitrary parametrizations of linear systems • arx2th: Creates multivariable ARX structures • fixpar/unfixpar: Modifies structures by fixing or unfixing parameters In addition. In the latter case you can just drag and drop it over the Orders/Initial model edit box. The name of the initial model must be a variable either in the workspace or in the Model Board. all estimation commands create model structures in terms of the resulting models. Enter the name of any model structure in the box Orders (or Initial model) in the window Parametric Models and then select Estimate. The method is a standard prediction error/maximum likelihood approach that iteratively searches for the minimum of a criterion.

Note that models that are obtained by spectral analysis only can be represented as frequency response and noise spectra. you can double-click on the model’s icon to get Text Information about the model. Before printing a plot it might be a good idea to separate the line styles (menu item under Style). 2-27 . at the bottom of the main ident window: • Frequency response • Transient response • Zeros and poles • Noise spectrum • Model output • Model residuals In addition. You select and deselect a model by clicking on its icon. On color screens. then all models in the Model Summary Board that are selected will be represented in the window. compared with other models. This could also be helpful on black and white screens.4. and tested with new data sets. Examining Models Having estimated a model is just a first step. you can export the model to the M ATLAB workspace and use any commands for further analysis and model use. The curves in the View window can be clicked in and out by selecting and deselecting the models in an online fashion. Finally. An selected model is marked with a thicker line in its icon. and that models estimated by correlation analysis only can be represented as transient response. Views and Models The basic idea is that if a certain View window is open (checked). This is primarily done using the six Model View functions. the curves are color coded along with the model icons in the Model Board. It must now be examined.

which covers some basic functions. 2-28 . The common menu bar covers the following functions: File File allows you to copy the current figure to another. This can also be estimated from data. like a choice between step response or impulse response in the Transient response window. and pressing the right mouse button. This menu item also gives a number of choices that are specific for the plot window in question. They have a common menu bar. The zoom function can be deactivated if desired. and the k-step ahead prediction-property. By double-clicking. Second. Each model property has some uncertainty. A most important option is the possibility to show confidence intervals. e. the x-axes scales are locked to each other.. note that there is a zoom function in the plot window. The level of confidence can also be set under this menu item. By checking Show confidence intervals.g. Other File items cover printing the current plot and closing the plot window. A single click on the left mouse button zooms in by a factor of two.2 The Graphical User Interface The Plot Windows The six views all give similar plot windows. the curve will be identified with model name and present coordinates. By dragging with the left mouse button down. For plots with two axes. while the middle button zooms out. with several common features. you can draw rectangles. a confidence region around the nominal curve (model property) will be marked (by dash-dotted lines). standard MATLAB figure window. This might be useful. when you intend to print a customized plot. First of all. which will be enlarged when the mouse button is released. Just select the menu item Zoom under Style. Options Options first of all covers actions for setting the axes scaling. NOTE: Confidence intervals are supported for most models and properties. the original axis scales are restored. by pointing to any curve in the plot. except models estimated using n4sid and etfe.

turn the zoom on and off. Frequency Response and Disturbance Spectra All linear models that are estimated can be written in the form y ( t) = G(z) u( t) + v( t) where G(z) is the (discrete-time) transfer function of the system and v(t) is an additive disturbance. You can add gridlines. The estimated spectrum of the disturbance v is plotted as a power spectrum by choosing the Model View Noise Spectrum. which explain the plot and its options.. i. and no frequency functions are given. the logarithm of the amplitude (the absolute value) G(eiωT) as well as the phase arg (the argument) G(eiωT) are plotted against the logarithm of frequency ω in two separate plots. then the spectrum of y is plotted under Noise Spectrum. Transient Response Good and simple insight into a model’s dynamic properties is obtained by looking at its step response or impulse response.e. This function is often graphed as a Bode diagram. like choice of units and scale for the axis. you can choose which input-output channel to examine. These responses are plotted when the Model View Transient Response is checked. Help The Help menu has a number of items. The frequency response or frequency function of the system is the complex-valued function G(eiωT) viewed as a function of angular frequency ω. 2-29 . If the data is a time series y (with no input u). These plots are obtained by checking the Model View Frequency Response in the main ident window. The menu also covers a number of other options. The current choice is marked in the figure title.Style The style menu gives access to various ways of affecting the plot. This is the output of the model when the input is a step or an impulse. and change the linestyles. Channel For multivariate systems.

2 The Graphical User Interface It is quite informative to compare the transient response of a parametric model. This gives a good feel for which properties of the system have been picked up by the model. It is useful to turn on the confidence intervals in this case. This test is obtained by checking the Model View Model Output. extract a state-space description by th2ss. 2-30 . and compare the simulated output with the measured one. Many models provide a description of the additive disturbance v(t): v( t) = H( z)e (t ) Here H(z) is a transfer function that describes how the disturbance v(t) can be thought of as generated by sending white noise e(t) through it. Compare Measured and Model Output A very good way of obtaining insight into the quality of a model is to simulate it with the input from a fresh data set. The poles and zeros of G (and H ) are plotted by choosing the Model View Poles and Zeros. In particular the poles have a direct influence on the dynamic properties of the system. For multivariable systems it is the poles and zeros of the individual input/ output channels that are displayed. you can be quite confident that some essentially correct features have been picked up. with the one that was estimated using correlation analysis. If there is good agreement between the two. To display the properties of H. That is an indication that a lower order dynamic model could be used. and then apply the command tzero from the Control System Toolbox. you can choose channels (in the Channel menu) that have noise components as inputs. They will clearly reveal which poles and zeros could cancel (their confidence regions overlap). and which haven’t. It is useful to check the confidence intervals around the responses to see what “good agreement” could mean quantitatively. To obtain the so called transmission zeros. Then the data set currently in the Validation Data box will be used for the comparison. you will have to export the model. Poles and Zeros The poles of a system are the roots of the denominator of the transfer function G(z). while the zeros are the roots of the numerator.

in Latin. there is a peak outside the confidence region for lag k. where no past outputs at all are used. The simulation case. It is wise to also display the confidence region for this function. T being the sampling interval) be larger than the important time constants. so called Output-Error models (obtained by fixing K to zero for state-space models and setting na=nc=nd=0 for input output models. for any value of k. the cross-correlation function between input and residuals is computed by checking the Model View Model Residuals. there would be more in the output that originates from the input and that the model has not picked up. the residuals. thus coincide. If. for example. or has integration or very slow time constants. It gives the “left-overs” or. For a good model. it is wise to let the predicted time horizon (kT. Residual Analysis In a model y ( t ) = G ( z )u ( t ) + H ( z )e ( t ) the noise source e(t) represents that part of the output that the model could not reproduce. the levels of the simulated and the measured output may drift apart. If the model is unstable. see the previous section) do not use past outputs at all. With a prediction horizon of k. The test is carried 2-31 . the residuals should be independent of the input. This depends on the noise model. Note here that different models use the information in past output data in their predictors in different ways. For an ideal model the correlation function should lie entirely between the confidence lines for positive lags. even for a model that is quite good (at least for control purposes). It is then a good idea to evaluate the model’s predicted output rather than the simulated one. the k-step ahead predicted output is then obtained as follows: The predicted value y(t) is computed from all available inputs u ( s ) ( s ≤ t ) (used according to the model) and all available outputs up to time t-k. This is computed as the root of the mean square value of the difference between measured and simulated output. thus formally corresponds to k=∞.The fit will also be displayed. To test this independence. The simulated and the predicted outputs. this means that there is something in the output y(t) that originates from u(t-k) and that has not been properly described by the model. Otherwise. y ( s ) ( s ≤ t – k ) . To check if the model has picked up interesting dynamic properties. For example.

which the model is associated with in all plots. along with the notes that originally were associated with the estimation data set. You can also change the name of the model just by editing the text field with the model name. If these were not used to estimate the model. by displaying the auto-correlation function of the residuals (excluding lag zero. It also gives a diary of how the model was created. The model’s parameters along with estimated standard deviations are displayed. 2-32 .. for which this function by definition is one). At this point you can do a number of things: Present Selecting the Present button displays details of the model in the MATLAB command window. The color. a Data/model Info dialog box opens. as well as some other notes. the test is quite tough.2 The Graphical User Interface out using the Validation Data. Modify You can simply type in any text you want anywhere in the Diary and Notes editable text field of the dialog box. See also “Model Structure Selection and Validation” on page 3-49. Further Analysis in the M ATLAB Workspace Any model and data object can be exported to the MATLAB workspace by dragging and dropping its icon over the To Workspace box in the ident window. This test is also carried out by the view Model Residuals.e. Text Information By double-clicking (middle/right mouse button or alt-double-click) on the model icon. Enter RGB-values or a color name (like 'y') in the corresponding box. the correlation function should be entirely inside the confidence region. can also be edited. the residuals should be mutually independent. which contains some basic information about the model. the transfer function H). For a model also to give a correct description of the noise properties (i. For an ideal model.

Once you have exported the model to the workspace, there are lots of commands by which you can further transform it, examine it, and convert it to other formats for use in other toolboxes. Some examples of such commands are
thd2thc th2ss th2tf th2poly

Transform to continuous time. Convert to state-space representation. Convert to transfer function form. Convert to polynomial input/output form.

Also, if you need to prepare specialized plots that are not covered by the Views, all the SITB commands for computing and extracting simulations, frequency functions, zeros and poles, etc., are available. See Chapter 3, "Tutorial," and Chapter 4, "Command Reference,".

2-33

2

The Graphical User Interface

5. Some Further GUI Topics
This section discusses a number of different topics.

Mouse Buttons and Hotkeys
The GUI uses three mouse buttons. If you have fewer buttons on your mouse, the actions associated with the middle and right mouse buttons are obtained by shift-click, alt-click or control-click, depending on the computer.

The Main ident Window
In the main ident window the mouse buttons are used to drag and drop, to select/deselect models and data sets, and to double-click to get text information about the object. You can use the left mouse button for all of this. A certain speed-up is obtained if you use the left button for dragging and dropping, the right one for selecting models and data sets, and the middle one for double-clicking. On a slow machine a double-click from the left button might not be recognized. The ident window also has a number of hotkeys. By pressing a keyboard letter when it is the current window, some functions can be quickly activated. These are • s: Computes Spectral Analysis Model using the current options settings. (These can be changed in the dialog window that opens when you choose Spectral Model in the Estimate pop-up menu.) • c: Computes Correlation Analysis Model using the current options settings. (These can be changed in the dialog window that opens when you choose Correlation Model in the Estimate pop-up menu.) • q: Computes the models associated with the Quickstart. • d: Opens a dialog window for importing Data that are in the SITB data format.

Plot Windows
In the various plot windows the action of the mouse buttons depends on whether the zoom is activated or not: Zoom Active: Then the left and middle mouse buttons are associated with the zoom functions as in the standard MATLAB zoom. Left button zooms in and the middle one zooms out. In addition, you can draw rectangles with the left

2-34

button, to define the area to be zoomed. Double-clicking restores the original plot. The right mouse button is associated with special GUI actions that depend on the window. In the View plots, the right mouse button is used to identify the curves. Point and click on a curve, and a box will display the name of the model/data set that the curve is associated with, and also the current coordinate values for the curve. In the Model Selection plots the right mouse button is used to inspect and select the various models. In the Prefilter and Data Range plots, rectangles are drawn with this mouse button down, to define the selected range. Zoom not active: The special GUI functions just mentioned are obtained by any mouse button. The zoom is activated and deactivated under the menu item Style. The default setting differs between the plots. Don’t activate the zoom from the command line! That will destroy the special GUI functions. (If you happen to do so anyway, “quit” the window and open it again.)

Troubleshooting in Plots
The function Auto-range, which is found under the menu item Options, sets automatic scales to the plots. It is also a good function to invoke when you think that you have lost control over the curves in the plot. (This may happen, for example, if you have zoom in a portion of a plot and then change the data of the plot). If the view plots don’t respond the way you expect them to, you can always “quit” the window and open it again. By quit here we mean using the underlying window system’s own quitting mechanism, which is called different things in the different platforms. This action will not be acknowledged by the corresponding check box in the ident window, so you will have to first uncheck, and then check it. The normal way to close a window is to use the Close function under the menu item File, or to uncheck the corresponding check box.

Layout Questions and idprefs.mat
The GUI comes with a number of preset defaults. These include the window sizes and positions, the colors of the different models, and the default options in the different View windows. The window sizes and positions, as well as the options in the plot windows, can of course be changed during the session in the standard way. If you want the

2-35

2

The Graphical User Interface

GUI to start with your current window layout and current plot options, select menu item
Options > Save preferences

in the main ident window. This saves the information in a file idprefs.mat. This file also stores information about the four most recent sessions with ident. This allows the session File menu to be correctly initialized. The session information is automatically stored upon exit. The layout and preference information is only saved when the indicated option is selected. The file idprefs.mat is created the first time you open the GUI. It is by default stored in the same directory as your startup.m file. If this default does not work, a warning is issued. This can be ignored, but then session and preference information cannot be stored. To change or select a directory for idprefs.mat, use the command midprefs. See Chapter 4, "Command Reference," for details. To change model colors and default options to your own customized choice, make a copy of the M-file idlayout.m to your own directory (which should be before the basic ident directory in the MATLABPATH), and edit it according to its instructions.

Customized Plots
If you need to prepare hardcopies of your plots with specialized texts, titles and so on, make a copy of the figure first, using Copy Figure under the File menu item. This produces a copy of the current figure in a standard MATLAB figure format. For plots that are not covered by the View windows, (like, e.g., Nyquist plots), you have to export the model to the MATLAB workspace and construct the plots there.

Import from and Export to Workspace
As you export a model or a data set to the M ATLAB workspace by dropping its icon over the To Workspace icon, it will become a workspace variable with the same name as in ident, say mymodel. At the same time another workspace variable will be created with the name mymodel_info. This contains all diary and note information. This will be quite useful if you want to manipulate the

2-36

model using MATLAB commands and then import it back into ident. The use is illustrated by the following example: Export model with name mymodel to workspace. Execute the following at the MATLAB command line:
mymodelc=thd2thc(mymodel); % converting the model to continuous time mymodelc_info=str2mat(mymodel_info,... 'mymodelc=thd2thc(mymodel)'); % adding the info of how the new variable was created

Now select pop-up menu Model>Import, enter the variable name mymodelc, and select Import. This will enter the continuous-time model into ident along with the relevant information.

What Cannot be Done Using the GUI
The GUI covers primarily everything you would like to do to examine data, estimate models and evaluate and compare models. It does not cover • Generation (simulation) of data sets • Model creation (other than by estimation) • Model manipulation and conversions • Recursive (on-line) estimation algorithms Check Chapter 3, "Tutorial," as well as the headings Simulation and Prediction, Model Structure Creation, Manipulating Model Structures, Model Conversions, and Recursive Parameter Estimation in the beginning of Chapter 4, "Command Reference," to see what M-files are available in the toolbox for these functions. Note that at any point you can export a data set or a model to the MATLAB workspace (by dragging and dropping its icon on the To Workspace icon). There you can modify and manipulate it any way you want and then import it back into ident. You can, for example, construct a continuous-time model from an estimated discrete-time one (using thd2thc) and then use the model views to compare the two.

2-37

2 The Graphical User Interface 2-38 .

. . . . . . . 3-5 The System Identification Problem . . . . . 3-29 Examining Models . . . . . . . . . . . . . . . . . . . 3-58 Recursive Parameter Estimation . . . . . . . . . . . . . . . . . . 3-22 Defining Model Structures . . . . . . . . 3-61 Some Special Topics . . . . . . . . . . . . 3-49 Dealing with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40 Model Structure Selection and Validation . . . . . . . . 3-68 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Tutorial The Toolbox Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 Parametric Model Estimation . 3-8 Nonparametric Model Estimation . . . . . . 3-3 An Introductory Example to Command Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

If you use the graphical user interface (GUI). 3-2 .3 Tutorial This chapter has two purposes. It describes the commands of the System Identification Toolbox.. i. you will not have to bother about these aspects. The chapter also describes the underlying methods and algorithms used. are also treated here. the recursive algorithms and more advanced model structure definitions. their syntax and use. The commands that are not reached from the GUI.e.

3-3 . compare. This third layer contains transformations between continuous and discrete time. thd2thc The corresponding background is given in section 7 of this chapter. and to estimate more general input-output model structures. arx. and functions for estimating completely general multi-input model structures.8 and 9 of this chapter. th2ff. The Toolbox Commands It may be useful to recognize several layers of the System Identification Toolbox.6. selstruc. th2poly Note that the commands arx and iv4 also apply to multi-input. present. bodeplot. th2zp. spa.5. The second layer of the toolbox contains some useful techniques to select orders and delays. iv4. resid. etfe. The corresponding background is given in the sections 3.1. th2arx. predict. The layers are described in the following paragraphs: Layer 1: Basic Tools. dtrend. pem. thc2thd. poly2th. Layer 3: More Methods To Examine Models and Multi-Input Systems . zpplot The corresponding background is given in the following sections: 3. bj. th2ss. idfilt. The commands are: armax. It also contains the basic tools for examining the obtained models. arxstruc. You can proceed to the next levels whenever an interest or the need from the applications warrants it. Initially concentrate on the first layer of basic tools. th2tf. which contains the commands from the System Identification Toolbox that any user must master. The commands are: ar. 6 .7 and 8 of this chapter. The first layer contains the basic tools for correlation and spectral analysis. 5. Layer 2: Model Structure Selection. The commands are: pe. and the estimation of so-called ARX models using the least-squares method. cra.4. ffplot idsim. n4sid oe. multi-output systems.

there are the commands: canstart. modstruc." for a complete list of available functions. mf2th. rarx. unfixpar The corresponding theory is covered in sections 3. (See the beginning of the Chapter 4. ms2th. "Command Reference. To build models in state-space form (both continuous and discrete time). and to handle more advanced multi-output structures. rbj. rplr The corresponding background is given “Recursive Parameter Estimation” on page 3-61. Recursive (adaptive. roe. Layer 5: State-Space Modeling. online) methods of parameter estimation are covered by the commands: rarmax. and 8 of this chapter. 6. rpem.) 3-4 . 5.3 Tutorial Layer 4: Recursive Identification. fixpar.

Default values are used when trailing arguments are omitted. and follow along. An Introductory Example to Command Mode A demonstration M-file called iddemo.m provides several examples of what might be typical sessions with the System Identification Toolbox. 3-5 . In the case above. this example is designed to get you using the software quickly. Before giving a formal treatment of the capabilities and possibilities of the toolbox. One thousand input-output data points were collected from the process as the input was changed in a random fashion between two levels. by default. Air is blown through a tube after being heated at the inlet to the tube. 1987 and “Reading More About System Identification” on page 1-18 for references. You may want to invoke MATLAB at this time. Take a look at the data. Data have been collected from a laboratory scale process. The output of the process is the air temperature at the outlet measured in volts by a thermocouple sensor. all data points are graphed and the sampling interval is one time unit. First load the data: load dryer2 This example selects the first 300 data points for building a model. The input to the process is the power applied to a mesh of resistor wires that constitutes the heating device. see page 440 in Ljung. (Feedback’s Process Trainer PT326. The data were loaded into M ATLAB in ASCII form and are now stored as the vectors y2 (output) and u2 (input) in the file dryer2. the input-output vectors are merged into a matrix: z2 = [y2(1:300) u2(1:300)].mat. execute iddemo from inside MATLAB. idplot(z2) The toolbox makes frequent use of default arguments. The sampling interval is 80 ms.) The process operates much like a common hand-held hair dryer. This example is essentially the same as demo #2 in iddemo. execute iddemo1.2. To start the demo. For convenience.

3

Tutorial

You can select the values between sample numbers 200 and 300 for a close-up, and at the same time obtain correct time scales, with
idplot(z2,200:300,0.08)

Remove the constant levels and make the data zero mean with
z2 = dtrend(z2);

Now, fit to the data a model of the form: y ( t ) + a 1 y ( t – T ) + a 2 y ( t – 2T ) = b 1 u ( t – 3T ) + b 2 u ( t – 4T ) (2.1)

where T is the sampling interval (here 0.08 seconds). This model, known as an ARX model, tries to explain or compute the value of the output at time t, given previous values of y and u. Later on, especially in Section 8, are discussions of how to decide upon suitable model orders (structures). The best values of the coefficients a 1, a 2, b 1 and b 2 can be computed with
th = arx(z2,[2 2 3]);

The numbers in the second argument tell arx to find a model (2.1) with two a-parameters, two b-parameters, and three delays. The result is stored in the matrix th in a somewhat coded form. To specify the actual sampling interval, enter
th = sett(th,0.08);

There are several ways to display and illustrate the computed model. With
present(th)

the coefficient values of (2.1) and their estimated standard deviations are presented on the screen. Next, you might ask how to evaluate how well the model fits the data. A simple test is to run a simulation whereby real input data is fed into the model, and compare the simulated output with the actual measured output. For this, select a portion of the data that was not used to build the model, for example, from sample 700 to 900:
u = dtrend(u2(700:900)); y = dtrend(y2(700:900));

3-6

ysim = idsim(u,th); plot([y(100:200) ysim(100:200)])

Note that the function compare does this sequence of commands more efficiently. You see that the model is quite capable of describing the system, even for data that were not used in calculating the fit. To compute and graph the poles and zeros of the model, use
zpth = th2zp(th); zpplot(zpth)

If you want to know the frequency response, you can compute the frequency function of the model and present it as a Bode plot by entering
gth = th2ff(th); bodeplot(gth)

Compare this transfer function with a transfer function obtained from a nonparametric, spectral analysis method. Such an estimate is obtained directly from the data
gs = spa(z2); gs = sett(gs,0.08);

The sampling interval, 0.08, is set by the second command in order to obtain correct frequency scales. The function spa also allows you to select window sizes, frequency ranges, etc. All these have here been given default values. You can compare the estimate of the transfer function obtained by spectral analysis and the one obtained from the model (2.1) with
bodeplot([gs gth])

The agreement is quite good. Finally, plot the step response of the model. The model comes with an estimate of its own uncertainty. Ten different step responses are computed and graphed. They correspond to “possible” models, drawn from the distribution of the true system (according to our model):
step = ones(30,1); idsimsd(step,th)

3-7

3

Tutorial

3. The System Identification Problem
This section discusses different basic ways to describe linear dynamic systems and also the most important methods for estimating such models.

Impulse Responses, Frequency Functions, and Spectra
e

u

y

The basic input-output configuration is depicted in the figure above. Assuming unit sampling interval, there is an input signal u( t) ; t = 1 ,2 ,.. ... ... ,N and an output signal y( t) ; t= 1 ,2 ,. ... ... ,.N Assuming the signals are related by a linear system, the relationship can be written y ( t ) = G ( q )u ( t ) + v ( t ) where q is the shift operator and G ( q )u ( t ) is short for G ( q )u ( t ) = and G( q ) = (3.1)

∑ g ( k )u ( t – k )
k=1 –k

(3.2)

∑ g ( k )q
k=1

;

q u( t ) = u( t – 1 )

–1

(3.3)

3-8

The numbers { g ( k ) } are called the impulse response of the system. Clearly, g ( k ) is the output of the system at time k if the input is a single (im)pulse at time zero. The function G ( q ) is called the transfer function of the system. This iω function evaluated on the unit circle ( q = e ) gives the frequency function G( e )

(3.4)

In (3.1) v ( t ) is an additional, unmeasurable disturbance (noise). Its properties can be expressed in terms of its (auto) spectrum Φv ( ω ) which is defined by Φv ( ω ) = (3.5)

τ = –∞

R v ( τ )e

– iwt

(3.6)

where R v ( τ ) is the covariance function of v ( t ) : R v ( τ ) = Ev ( t )v ( t – τ ) (3.7)

and E denotes mathematical expectation. Alternatively, the disturbance v ( t ) can be described as filtered white noise: v ( t ) = H ( q )e ( t ) where e ( t ) is white noise with variance λ and Φv ( ω ) = λ H ( e )
iω 2

(3.8)

(3.9)

Equations (3.1) and (3.8) together give a time domain description of the system: y ( t ) = G ( q )u ( t ) + H ( q )e ( t ) (3.10)

3-9

3

Tutorial

while (3.4) and (3.5) constitute a frequency domain description: G ( e );

Φv ( ω )

(3.11)

The impulse response (3.3) and the frequency domain description (3.11) are called nonparametric model descriptions since they are not defined in terms of a finite number of parameters. The basic description (3.10) also applies to the multivariable case; i.e., to systems with several (say nu) input signals and several (say ny) output signals. In that case G ( q ) is an ny by nu matrix while H ( q ) and Φ v ( ω ) are ny by ny matrices.

Polynomial Representation of Transfer Functions
Rather than specifying the functions G and H in (3.10) in terms of functions of –1 the frequency variable ω , you can describe them as rational functions of q and specify the numerator and denominator coefficients in some way. A commonly used parametric model is the ARX model that corresponds to G ( q) = q
– nk

B(q ) -----------; A(q )

1 H ( q ) = ----------A(q)
–1

(3.12) : (3.13) (3.14)

where B and A are polynomials in the delay operator q A( q) = 1 + a1q
–1

+ …… + a na q

–n a

B(q ) = b1 + b2q

–1

+ …… + b nb q

– nb + 1

Here, the numbers na and nb are the orders of the respective polynomials. The number nk is the number of delays from input to output. The model is usually written A ( q )y ( t ) = B ( q )u ( t – nk ) + e ( t ) (3.15)

3-10

where A ( q ) and the coefficients a i become ny by ny matrices.18) An Output-Error (OE) structure is obtained as B(q) y ( t ) = -----------u ( t – nk ) + e ( t ) F(q) with F ( q ) = 1 + f1 q –1 (3.20) The so-called Box-Jenkins (BJ) model structure is given by B( q) C(q ) y ( t ) = -----------u ( t – nk ) + ----------.22) 3-11 . model structure is the ARMAX structure A ( q )y ( t ) = B ( q )u ( t – nk ) + C ( q )e ( t ) Here.21) + … + d nd q –n d (3.19) + … + f nf q – nf (3. while C ( q ) = 1 + c1 q –1 (3.or explicitly y ( t ) + a 1 y ( t – 1 ) + …… + a na y ( t – na ) = b 1 u ( t – nk ) + b 2 u ( t – nk – 1 ) + …… + b nb u ( t – nk – nb + 1 ) + e ( t ) Note that (3. and more general.17) + … + c nc q – nc (3.16) apply also to the multivariable case.15) -(3. Another very common.e ( t ) F( q) D( q ) with D ( q ) = 1 + d1 q –1 (3.16) (3.13)-(3. B ( q ) and the coefficients b i become ny by nu matrices.14). A ( q ) and B ( q ) are as in (3.

e ( t ) D( q ) F1( q ) F nu ( q ) (3. Within the structure of (3.2 in Ljung (1987) for a detailed discussion. The Output-Error model is obtained withna = nc = nd = 0 while the Box-Jenkins model corresponds to na = 0 .. ..23) 3-12 . virtually all of the usual linear black-box model structures are obtained as special cases.u nu ( t – nk nu ) + ----------. The ARARX structure (or the “generalized least-squares model”) is obtained for nc = nf = 0 .3 Tutorial All these models are special cases of the general parametric model structure: B(q) C(q ) A ( q )y ( t ) = -----------u ( t – nk ) + ----------. while the ARARMAX structure (or “extended matrix model”) corresponds to nf = 0 .u 1 ( t – nk 1 ) + . The ARX structure is obviously obtained for nc = nd = nf = 0 .e ( t ) F(q) D( q ) The variance of the white noise { e ( t ) } is assumed to be λ . They have the form · B nu ( q ) B1( q ) C(q ) A ( q )y ( t ) = ------------. The ARMAX structure corresponds to nf = nd = 0 . (See Section 4.+ ---------------.) The same type of models can be defined for systems with an arbitrary number of inputs.23).

and D.26b) (3.28a) (3.State-Space Representation of Transfer Functions A common way of describing linear systems is to use the state-space form: x ( t + 1 ) = Ax ( t ) + Bu ( t ) y ( t ) = Cx ( t ) + Du ( t ) + v ( t ) (3.24) can be viewed as one way of parametrizing the transfer function: Via (3.24) corresponds to (3. It is often possible to set up a system description directly in the innovations form (3. In transfer function form (3.26a) (3.28b) –1 (3.27) 3-13 . To further describe the character of the noise term v ( t ) in (3. Clearly (3.25) Here I nx is the nx by nx identity matrix. That leads to a stochastic state-space model: x ( t + 1 ) = Ax ( t ) + Bu ( t ) + w ( t ) y ( t ) = Cx ( t ) + Du ( t ) + e ( t ) (3.24b) Here the relationship between the input u ( t ) and the output y ( t ) is defined via the nx-dimensional state vector x ( t ) . In other cases.25) G ( q ) becomes a function of the elements of the matrices A.25) and H ( q ) by H ( q ) = C ( qI nx – A ) K + I ny Here ny is the dimension of y ( t ) and e ( t ). it might be preferable to describe first the nature of disturbances that act on the system.24a) (3.26).1) with G ( q ) = C ( qI nx – A ) B + D –1 (3. C. B.24) a more flexible innovations form of the state-space model can be used: x ( t + 1 ) = Ax ( t ) + Bu ( t ) + Ke ( t ) y ( t ) = Cx ( t ) + Du ( t ) + e ( t ) This is equivalent to (3.10) with G ( q ) given by (3.

29b) · Here. Continuous-Time State-Space Models It is often easier to describe a system from physical modeling in terms of a continuous-time model. then the relationship between u [ k ] = u ( kT ) and y [ k ] = y ( kT ) can be exactly expressed by (3.24) by taking A=e FT .29a) (3. The exact connection between K and K is somewhat more complicated.31a) (3. If you start with a continuous-time innovations form ˜ · x ( t ) = Fx ( t ) + Gu ( t ) + K e ( t ) y ( t ) = Hx ( t ) + Du ( t ) + e ( t ) (3. In stationarity and from an input-output view. T Fτ (3.B = ∫τ = 0 e T Fτ Gdτ .30) hold. x means the time derivative of x .30) and associate y(t) with y[t].26) if the matrix K is chosen as the steady-state Kalman gain.26) where still the relationships ˜ (3.28) is described in the Control System Toolbox. etc.C = H (3. Therefore. If the input is piece-wise constant over time intervals kT ≤ t < ( k + 1 )T . physical modeling typically leads to state-space descriptions like · x ( t ) = Fx ( t ) + Gu ( t ) y ( t ) = Hx ( t ) + Du ( t ) + v ( t ) (3. This is a good approximation for short sampling intervals T.3 Tutorial where w ( t ) and e ( t ) are stochastic processes with certain covariance properties.28) is equivalent to (3.31b) the discrete-time counterpart is given by (3. 3-14 . The reason is that most physical laws are expressed in continuous time as differential equations. though. (3.32) in analogy with G and B. How to compute K from (3. An ad hoc solution is to use K= ˜ ∫τe= 0Kd τ.

In this case. i. If the input is not white. 3-15 .Estimating Impulse Responses Consider the description (3. This procedure is known as correlation analysis.e. so that the filtered sequence u F ( t ) = L ( q )u ( t ) (3.33) based on the observed input-output data. Suppose that the input u ( t ) is white noise. its covariance function is  R u ( τ ) = Eu ( t + τ )u ( t ) =  λ if τ = 0  0 else Then.1). a whitening filter L(q) can be determined for it.33) based on the filtered data. By filtering the output sequence through the same filter and computing (3. the cross covariance function between the input and the output is R yu ( τ ) = Ey ( t + τ )u ( t ) = λg ( τ ) where g(τ) is the impulse response of the system..34) is approximately white. it can easily be estimated as 1 ˆ g ( τ ) = -----λN ∑ y ( t + τ )u ( t ) t=1 N (3. a natural estimate of the impulse response coefficients g(k) is obtained.

Provided that the input u ( t ) is independent of v ( t ). R y u ( τ ) . Its Fourier transform. Here W M ( τ ) is the so-called lag window and M is the width of the lag window.11) directly. the cross spectrum. form estimates of the corresponding spectra ˆ Φy( ω) = τ = –M ∑ M ˆ – iωτ R y ( τ )W M ( τ )e (3. the relationship (3. Φ y u ( ω ) is defined analogously to (3.1) implies the following relationships between the spectra: Φy ( ω ) = G ( e ) Φu ( ω ) + Φv ( ω ) Φ yu ( ω ) = G ( e )Φ u ( ω ) By estimating the various spectra involved.. ˆ Φu ( ω ) 2 ˆ ˆ ˆ Φ yu ( ω ) Φ v ( ω ) = Φ y ( ω ) – ----------------------ˆ Φu ( ω ) (3.7)) R y ( τ ).35) and analog expressions for the others. ˆ and R u ( τ ) . (See Chapter 6 in Ljung (1987). The estimates are then formed as ˆ ˆ iω Φy u ( ω ) G N ( e ) = -----------------.) 3-16 .6). using ˆ 1 R y u ( τ ) = --N iω iω 2 ∑ y ( t + τ )u ( t ) t=1 N (3. Then. the frequency function and the disturbance spectrum can be estimated as follows: ˆ ˆ Form estimates of the covariance functions (as defined in (3.37) This procedure is known as spectral analysis.36) and analogously for Φ u and Φ yu . The cross-covariance function R yu ( τ ) between y(t) and u(t) was defined above.3 Tutorial Estimating Spectra and Frequency Functions This section describes methods that estimate the frequency functions and spectra (3.

(See Section 7.41) and by multiplying (3. The most common parametric identification method is to determine estimates of G and H by minimizing V N ( G.15)-(3. and s ( t ) are called the instruments.32). These in turn are parametrized by the polynomials in (3.15) can be correlated out and solved for the dynamics. … .29)–(3. 2. the (prediction) errors e ( t ) in (3. … .39) that is ˆ ˆ [ G N. By forming filtered versions of the input N ( q )s ( t ) = M ( q )u ( t ) (3. y.40) This is called a prediction error method. k = 1 . the noise in (3. k = 1 .10) can be computed as: e ( t ) = H ( q ) [ y ( t ) – G ( q )u ( t ) ] –1 (3. nb and summing over t. For Gaussian disturbances it coincides with the maximum likelihood method. na and u ( t – nk + 1 – k ) .) 3-17 .38) These errors are. H ) = ∑e t=1 N 2 ( t) (3. for given data y and u.15) with s ( t – k ) . 2.Estimating Parametric Models Given a description (3. functions of G and H. (See Chapter 7 in Ljung (1987).6 in Ljung (1987).15).) A somewhat different philosophy can be applied to the ARX model (3.10) and having observed the input-output data u. This gives the instrumental variable method. H N ] = argmin ∑e t=1 N 2 (t) (3.23) or by entries in the state-space matrices defined in (3.

eq (3. without first specifying any particular parametrization by efficient subspace methods.. and K in (3.A of Ljung(1987) shows that all states in representations like (3. together with y(t) and u(t). C. Then e(t) could be determined.n).26b) would be a linear regression. and find the joint process and measurement noises as the residuals from this regression. (One could also treat (3. D. The Kalman gain K could then be computed from the Riccati equation. B. It is thus a matter of finding these predictors. B.26a). which then would be another linear regression model for A. and treated as a known signal in (3. B and K. and D with y(t) and x(t+1) as simultaneous outputs.) Thus.. the estimation of the state-space matrices is easy.26) can be formed as linear combinations of the k-step ahead predicted outputs (k=1.. see the references under n4sid in Chapter 4. "Command Reference" .24) as a linear regression for A.26) can be estimated directly. The idea behind this can be explained as follows: If the sequence of state vectors x(t) were known. The subspace methods form an efficient and numerically reliable way of determining the predictors by projections directly on the observed data sequences.3 Tutorial Subspace Methods for Estimating State-Space Models The state-space matrices A. C. 3-18 . How to find the states x(t)? Appendix 4. For more details. once the states are known. and then selecting a basis among them.2.. and C and D could be estimated by the least squares method.

nu = 1 ). Not all of the options available when using the functions are described here. Some of the functions in the System Identification Toolbox apply only to single output data ( ny = 1 ) and some only to single-input-single-output data ( ny = 1 . "Command Reference" gives details about this. Nonparametric Model Estimation This and the following sections give an introduction to the basic functions in the System Identification Toolbox. The output-input data is collectively represented as a matrix whose first column(s) is the output and next column(s) is the input: z = [y u] The data can be graphed by the command idplot: idplot(z) This gives plots of all combinations of inputs and outputs for visual inspection. see the Command Reference chapter and the online Help facility. Row k corresponds to sample number k. For multivariable systems. Chapter 4. Data Representation The observed output and input signals. nu = number of input signals). are represented in the System Identification Toolbox as column vectors y and u. 3-19 .4. y ( t ) and u ( t ). so that u becomes an N by nu matrix (N = number of sampled observations. each input (output) component is represented as a column vector.

They are coded into a special format. [G.3 Tutorial Correlation Analysis The correlation analysis procedure described in “The System Identification Problem” in Chapter 3 is implemented in the function cra: ir = cra(z) This function returns the estimated impulse response in the vector ir. which allows you to plot them using the function bodeplot or ffplot: [G.34) can be checked. It also optionally plots the estimated covariance functions for y and u. By omitting the argument PHIV. To obtain correct frequency scales you can operate with the command sett on G or give the sampling interval as an optional argument to spa. only the transfer function estimate G is computed: G = spa(z) 3-20 . so that the success of the whitening filter (3. while ffplot gives linear frequency scales (in Hz). G and PHIV are matrices that contain the estimated frequency function G N and the estimated disturbance spectrum Φ v in (3.37). From the estimated impulse response it is easy to form the step response: ir = cra(z) sr = cumsum(ir) plot(sr) Spectral Analysis The function spa performs spectral analysis according to the procedure in (3. the freqfunc format. "Command Reference" and by typing help freqfunc. The details of the freqfunc format are given in Chapter 4.PHIV] = spa(z) bodeplot(G) bodeplot(PHIV) bodeplot gives logarithmic amplitude and frequency scales (in rad/sec) and linear phase scale.35)–(3.PHIV] = spa(z) Here z contains the output-input data as above.37).

but are also more affected by random disturbances. 3-21 . The function also allows some smoothing of the crude estimate.10) g25 = spa(z.PHIV] = spa(z. the estimated frequency functions show sharper details. A typical sequence of commands that test different window sizes is g10 = spa(z.When PHIV is included.37). spa uses a Hamming window for W ( τ ) with a default length M equal to the minimum of 30 and a tenth of the number of data points. For a single signal etfe gives the periodogram as a spectral estimate. This window size M can be changed to an arbitrary number by [G. See Chapter 4.50) bodeplot([g10 g25 g50]) An empirical transfer function estimate is obtained as the ratio of the output and input Fourier transforms with G = etfe(z) This can also be interpreted as the spectral analysis estimate for a window size that is equal to the data length. the estimated standard deviations of G and PHIV are also returned by spa and included in the freqfunc format.35)-(3. it can be a good alternative for signals and systems with sharp resonances. If z = y is a time series.M) The rule is that as M increases. spa returns an estimate of the spectrum of that signal: PHIY = spa(y) ffplot(PHIY) In the computations (3.25) g50 = spa(z. "Command Reference" for more information.

The details of this representation are found in Chapter 4. It is coded into the theta format. using the M ATLAB “/” operator for overdetermined linear equations. use the function arx: th = arx(z. and estimated covariances of estimated parameters into a matrix.ths) present(th) The following sections assume that you have formed an array z that consists of the output y and the input u: z = [y u] ARX Models To estimate the parameters a i and b i of the ARX model (3. The function arx implements the least-squares estimation method. nb.15). use the command present: th = function(z. This is obtained with th = iv4(z. "Command Reference" or by typing help theta. It collects information about the model structure and the orders.[na nb nk]) Here na. To just display the model information. and nk are the corresponding orders and delays in (3.16) that define the exact model structure. The theta format can be translated to other useful model representations. Parametric Model Estimation The System Identification Toolbox contains several functions for parametric model estimation. parameters.[na nb nk]) 3-22 .ths) Input variables y and u are column vectors that contain the output and input data sequences. This is the basic format for representing models in the System Identification Toolbox.3 Tutorial 5. while the matrix ths specifies the particular structure of the model to be estimated. An alternative is to use the Instrumental Variable (IV) method described in connection with (3. They all share the same command structure th = function([y u]. The resulting estimated model is contained in th.41). delays.

the orders are defined accordingly: na is an ny by ny matrix whose i -j entry gives the order of the polynomial that relates past values of y j to the current value of y i (i. there is the function th = pem(z. General Polynomial Black-Box Models Based on the prediction error method (3.23).na) which uses an instrumental variable technique to compute the AR part of a time series. j ) )are used when predicting y i ( t ) ) . and a modified covariance method. (See “Defining Model Structures” on page 3-29 and Chapter 4. the Yule-Walker approach.na) (5.na) which has an option that allows you to choose the algorithm from a group of several popular techniques for computing the least-squares AR model..41). respectively.) Both arx and iv4 are applicable to arbitrary multivariable systems. "Command Reference" for exact details.) The counterpart of the iv4 command is th = ivar(y. (See Chapter 4. (See the procedure (15.40). a geometric lattice method.nn) 3-23 . If you have ny outputs and nu inputs. past values of y j up to y j ( t – na ( i. "Command Reference" for details.e.) AR Models For a single signal y ( t ) the counterpart of the ARX model is the AR model: A ( q )y ( t ) = e ( t ) The arx command also covers this special case th = arx(y. Among these are Burg’s method. For the general model (3. give the order and delay from input number j when predicting output number i.which gives an automatic (and approximately optimal) choice of the filters N and M in (3. you can construct models of basically any structure. Similarly the i -j entries of the ny by nu matrices nu and nk.26) in Ljung (1987).1) but for scalar signals more options are offered by the command th = ar(y.21)-(15.

and bj can also be started at any initial value thi specified in the theta format by replacing nn by thi. for the common special cases th = armax(z. All the routines also cover single-output.75) in Ljung (1987)).u n u ( t – nk nu ) + ----------. This search uses a special start-up procedure based on least squares and instrumental variables (the details are given as equation (10. a Gauss-Newton minimization procedure is carried out until the norm of the Gauss-Newton direction is less than a certain tolerance. These parameter estimation routines require an iterative search for the minimum of the function (3..39). respectively. nfnu].[nb nf nk]) th = bj(z.. For example th = pem(z.2 or Dennis and Schnabel(1983) for details. See also the entry on optional variables associated with the search at the end of this section. the ability to force a specific initial condition is useful in several contexts. Section 11. oe. 3-24 .. armax. nk = [nk1 . More efficient routines are available.. nbnu].19) and (3.thi) While the search is typically initialized using the built-in start-up procedure giving just orders and delays (as described above). See Ljung (1987). Some examples are mentioned in “Some Special Topics” on page 3-68.17).. however. nf.u 1 ( t – nk 1 ) + … + ---------------.21).[nb nc nd nf nk]) These handle the model structures (3.3 Tutorial where nn gives all the orders and delays nn = [na nb nc nd nf nk] The pem command covers all cases of black-box linear system models. multi-input systems of the type B nu ( q ) B1 (q ) C(q ) A ( q )y ( t ) = ------------. From the initial estimate. (3.2) where nb. nf = [nf1 .[na nb nc nk]) th = oe(z. and nk are row vectors of the same lengths as the number of input channels containing each of the orders and delays nb = [nb1 .. nknu].e ( t ) D( q ) F1 (q ) F nu ( q ) (5. The routines pem.

It is a healthy sign if this number is small. The estimates are then represented by a column vector. Suppose first that there is no particular knowledge about the internal structure of the discrete-time state-space model (3. the associated loss functions. The covariance matrix estimate is computed under the assumption that it is possible to obtain a “true” description in the given structure. The number then flickering in the upper left corner shows how many times the suggested update direction has been bisected during the search.26).3) below. These routines return the estimated covariance matrix of the estimated parameter vector as part of th. discrete-time. as in th = armax(z.nu) th = pem(z. listing the parameters in alphabetical order. and the Gauss-Newton update vector and its norm. Then there are essentially two different ways to estimate state-space models. The other alternative is to use a prediction error method. This reflects the reliability of the estimates. Initializing the search at the n4sid model is then a good idea.nn. which creates a model in state-space form (coded as usual in the theta format) in a realization that is automatically chosen to be reasonably well conditioned. containing current and previous estimates.order. This is obtained by thi = canstart(z.’trace’) these routines give status reports to the screen during the minimization.order). like (3. minimizing the criterion (5. Any linear model of a given order is sought.16). The simplest one is to use n4sid: th = n4sid(z.If a last argument ’trace’ is added. parametrizations. The basic idea behind this subspace algorithm was described in “The System Identification Problem” on page 3-8.thi) 3-25 . State-Space Models Black-box.

in providing reasonable initial parameter values.3) can be a difficult problem for general model parametrizations. For example. See also “Some Special Topics” on page 3-68. and also by freezing certain parameter values while allowing others to be free. This may require substantial interaction from the user. iter_info] = bj(z. as well as one extra output argument. as a function of the free parameters.39) or (5.maxiter. [th. the following criterion is used for the minimization: min det ∑ e ( t )e t=1 N T (t) (5. This is discussed in “Defining Model Structures” on page 3-29. Note that pem easily allows the freezing of any parameters to their nominal values. The functions fixpar and unfixpar are also useful. you can estimate its parameters with th = pem(z. can define a complicated surface with many local minima. only when a reasonable model of the dynamic part has been obtained. If these variables are not given. 3-26 . The criterion.tol.3 Tutorial Arbitrarily parameterized models in discrete and continuous time. and bj can accept three additional input options that affect the minimization. The numerical minimization of the prediction error criterion (3. oe. armax. narrow valleys and so on.lim) The format is the same for the other functions.nn. Optional Variables The functions pem. default values are assigned to them.3) which is the maximum likelihood criterion for Gaussian noise with unknown covariance matrix. A procedure that is often used for state-space models is to allow the noise parameter in the K matrix free. For state-space models of given structure. most of the effort involved relates to defining and manipulating the structure.ths) When the systems are multi-output. Once the structure is defined in the theta format as ths.

weight. are often more difficult to estimate than the dynamics parameters. bj.01. (See eq (15. 3-27 .6. (After the 10 first bisections. B. and the third variable is the norm of the Gauss-Newton search vector. If the number of used iterations is less than maxiter. oe.) The parameters associated with the noise dynamics. at the same time as this norm is larger then tol. The first entry is the number of used iterations. lim=0 disables the robust estimation and applies a purely quadratic criterion. The default value is 0. it means that the iterations have been aborted because no better fit could be obtained along the indicated search direction. lim: The quadratic criterion (3. You may want to limit their influence. Major contributions to the norm of the update direction then come from the entries corresponding to the noise parameters. The default value of lim is 1. In the estimation functions ar. before the minimization starts. the search direction is changed to the gradient one. and F. using robust estimation techniques. The iterations also terminate when maxiter is reached or when no decrease in the criterion can be found along the search direction after it has been bisected 10 times. tol: The iterations are continued until the norm of the Gauss-Newton update vector is less than tol. (C and D). iter_info: This a a row vector with three entries that give information about the iteration process. and pem. The second one is the improvement of the fit over the last iteration.7. The standard deviation is estimated robustly as the median of the absolute deviations from the median.9)-(15. The Gauss-Newton vector can be monitored to see if it is reasonable to increase tol on this ground. a prediction error that is larger than lim* (estimated standard deviation of e) carries a linear.10) in Ljung (1987). max.maxiter: This variable determines the maximum number of iterations performed in the search for the minimum. The default value is 10. rather than a quadratic.39) gives a considerable relative weight to large prediction errors. divided by 0. A.) Note that the loss function displayed by present(th) is quadratic and that the data-dependent delimiter is computed only once. Setting the value of maxiter to zero results in the return of the estimate from the start-up procedure. and 10 new bisections are tried.

3 Tutorial For the spectral analysis estimate. you can compute the frequency functions at arbitrary frequencies.pi. For example w = logspace(–3.128) The optional trailing arguments can be omitted. Entering them as empty matrices.w) results in G and PHIV being computed at these frequencies. in which case default values are used. then [G.PHIV] = spa(z.M. 3-28 . however. You can generate logarithmically spaced frequencies using the MATLAB logspace function. This computation is somewhat slower. also causes functions to rely upon defaults. If the frequencies are specified in a row vector w. [ ]. than using the default frequencies.

This section introduces the commands (apart from the parametric estimation functions themselves) that create models in the theta format. Defining Model Structures Since the System Identification Toolbox handles a wide variety of different model structures. B(q). Commands for creating state-space model structures are discussed in this section. The general way of representing models and model structures in the System Identification Toolbox is the theta format. oe..1) is defined by the five polynomials A(q). For example.e ( t ) F(q) D( q ) (6. In the previous section you saw how model structures that are special cases of the general model (3. it is important that these can be defined in a flexible way. For black-box models (3. D(q). These are represented in the standard MATLAB format for polynomials. armax. This section describes how model structures and models can be directly defined.9u ( t – 3 ) (6.23) can be defined by specifying the orders and delays in the various estimation routines arx.23): B(q) C(q ) A ( q )y ( t ) = -----------u ( t – nk ) + ----------. the ARX model y ( t ) – 1. Polynomial Black-Box Models The general input-output form (3. when creating a model for simulation. and F(q).6.23) this may be required.5u ( t – 2 ) + 0.7y ( t – 2 ) = 2. For example. iv4. Polynomial coefficients are stored as row vectors ordered by descending powers. for example.. the polynomial A ( q ) = 1 + a1q is represented as A = [1 a1 a2 . C(q).5y ( t – 1 ) + 0. an] –1 + a2q –2 + … + anq –n Delays in the system are indicated by leading zeros in the B ( q ) polynomial. bj. and pem.2) 3-29 .

2) can for example be represented by th = poly2th([1 –1. a1ny(q) a2ny(q) .5 0..7]..lam. The system (6..2) B and F are matrices. .B...[0 0 0.1) is now created by the command th = poly2th(A... any1(q) any2(q) .3) Here A(q) is an ny by ny matrix whose entries are polynomials in the delay operator q-1.C.5 0. Trailing arguments can be omitted for default values. The command poly2th can also be used to define time-continuous systems. You can represent it as A ( q ) = In y + A 1 q –1 + … + A na q – na (6..3 Tutorial is represented by the polynomials A = [1 –1. ..F. whose row number k corresponds to the k-th input..7]) In the multi-input case (5. .7] B = [0 0 2. .T) lam is here the variance of the white noise source e ( t ) and T is the sampling interval.5 0.. See the Command Reference chapter for details.4) as well as the matrix a11(q) A(q) = a21(q) a12(q) a22(q) ..9] The theta format representation of (6.. anyny(q) 3-30 . Multivariable ARX Models A multivariable ARX model is given by A ( q )y ( t ) = B ( q )u ( t ) + e ( t ) (6. .5 0.D.

note that na is a matrix whose kj-element is na k j . .. Ana] B = [B0 B1 .nu) where ny and nu are the number of outputs and inputs.. while the kj-elements of nb and nk are nb kj and nk kj respectively.. Here δ kj is the Kronecker-delta. otherwise. it equals 1 when k = j . it is 0.where the entries a kj are polynomials in the delay operator q a kj ( q ) = δ kj + a k j q 1 –1 –1 : (6... respectively...B.7): A = [eye(ny) A1 A2 . . The theta format representation of the model (6.7) b11(q) B(q) = b21(q) b12(q) b22(q) . 3-31 . and A and B are matrices that define the matrix polynomials (6. . b1nu(q) b2nu(q) . Similarly B ( q ) is an ny by nu matrix B ( q ) = B0 + B1q or –1 + …B n b q – nb (6.. bnynu(q) 1 – nb – n k ij – nb i j + 1 b k j q = b q – nk k j + b k j q kj The delay from input number j to output number k is nk kj .. .6) + … + a kj q na k j –n a kj This polynomial describes how old values of output number j affect output number k. bny1(q) with bny2(q) ... Bnb] ...4) and (6.ny..3) can be created by th = arx2th(A. To link with the structure definition in terms of [na nb nk] in the arx and iv4 commands..

B4 = [0.0 0 4].B. B5 = [0. [Ae.3 Tutorial Consider the following system with two outputs and three inputs: y 1 ( t ) – 1.1 1 2]. See Chapter 4. Be] = th2arx(the).4 0.2 0 0.4. u = [idinput(200).2). B3 = [0 0 0.1 0. B2 = [0 0.0 2 0].idinput(200)].7 0 .01 y 1 ( t – 2 ) = u 1 ( t ) + 2u 2 ( t – 4 ) + 3u 3 ( t – 1 ) + 4u 3 ( t – 2 ) + e 2 ( t ) This system is defined and simulated for a certain input u.0 4 1].4y 2 ( t – 1 ) + 0. B0 = [0 0.7]. nk = [4 0 0.0 0 0].3 0 0.5 0. 3-32 .2. A1 = [–1.idinput(200). B = [B0 B1 B2 B3 B4 B5].5y 1 ( t – 1 ) + 0.[na nb nk]). so that certain parameters in the structure are fixed to certain known values and not estimated.7 y 2 ( t – 2 ) + 0.15u 2 ( t – 2 ) + e 1 ( t ) y 2 ( t ) – ( 0. e = randn(200. y = idsim([u e].4u 2 ( t ) – 0.01 –0. 0.1u 2 ( t – 1 ) + 0. and then estimated in the correct ARX structure by the following string of commands: A0 = eye(2). A2 = [0.0 0 3].th0). –0. nb = [2 3 0. B1 = [0 –0. na = [2 1.3u 1 ( t – 5 ) + 0. the = arx([y u].2 1].2u 1 ( t – 4 ) + 0.3).1 0 0].0 0 0]. th0 = arx2th(A.2 )y 1 ( t – 1 ) – 0. "Command Reference"for more information.2 0].7y 1 ( t – 2 ) = 0. A = [A0 A1 A2].15 0. You can use the two commands fixpar and unfixpar to manipulate ARX structures.

30). (See Ljung (1987) page 87.9) depends on the assumed character of the additive noises w ( t ) and e ( t ) in (3. 3-33 . The value of the Kalman-gain ~ matrix K in (6. Disregard ~ that link and view K in (6.9b) (6. and its continuous-time counterpart. The System Identification Toolbox allows you to define arbitrary parameterizations of the matrices in (6. This gives the directly parametrized innovations form.9) to (6. G.8) (or K in (6. material constants).9)) as the basic tool to model the noise properties. H.8b) (6.9).) System Dynamics Expressed in Continuous Time ˜ · x ( t ) = Fx ( t ) + Gu ( t ) + K w ( t ) y ( t ) = Hx ( t ) + Du ( t ) + w ( t ) x ( 0 ) = x0 (6.8) or (6.State-Space Models with Free Parameters The basic state-space models are the following ones: (See also “The System Identification Problem” on page 3-8. (See Ljung (1987) page 88.) It is often easier to define a parametrized state-space model in continuous time because physical laws are most often described in terms of differential equations.) Discrete-Time Innovations Form x ( kT + T ) = Ax ( kT ) + Bu ( kT ) + Ke ( kT ) y ( kT ) = Cx ( kT ) + Du ( kT ) + e ( kT ) x ( 0 ) = x0 (6.9a) (6.8c) Here T is the sampling interval. u ( kT ) is the input at time instant kT and y ( kT ) is the output at time kT .28).8a) (6. To estimate unknown parameters based on sampled data (assuming T is the sampling interval) first transform (6. When defining the structure. you could use user-defined structures as in Example 6.8) using the formulas (3.4. The numerical values of these may or may not be known. and D contain elements with physical significance (for example.8) or K in (6. the known elements in the matrices are entered with their numerical values. The matrices F.9c) (See Ljung (1987) page 82.) If the internal noise structure is important.

The Black-Box. Consider the discrete-time model x(t + 1 ) = 1 θ1 0 1 x( t) + θ2 θ3 u (t ) + θ4 θ5 e( t) y( t) = 1 0 x( t ) + e( t) x( 0) = 0 0 with five unknown parameters θ i . D = 0. Use the commands modstruc and ms2th.8) without any particular internal structure..NaN]. Example 6. K = [NaN.. like (6. 3-34 . it is easier and more natural to use canstart or n4sid to estimate the model.D. ms1 = modstruc(A.NaN]. x0 = [0. th1 = ms2th(ms1. i=1. B = [NaN. This structure is defined in the theta format by A = [1 NaN. Discrete-Time Case For a discrete-time model.K. without any prior specification of the parametrization.0].. The argument 'd' denotes that the structure is a discrete-time structure. You can also specify unknown elements in the initial value vector x ( 0 ) .'d') The definition thus follows in two steps. as well as specification of the covariance matrix of e ( t ) and of the sampling interval T.C. 0 1].1: A Discrete-Time Structure.3.B. .3 Tutorial while the unknown elements are entered as NaN. C = [1 0]. Other optional arguments allow definition of guessed values of the unknown parameters. First the actual structure (known and unknown parameter values) is coded in the matrix ms1 and then a theta format matrix is created by ms2th.x0).

NaN] H = eye(2) D = zeros(2.1) K = zeros(2.G.noisevar) The structure th2 can now be used to estimate the unknown parameters θ i from observed data z = [y1 y2 u] by model = pem(z.2: A Continuous-Time Model Structure. Example 6.th2) 3-35 . 0. (See page 84 in Ljung (1987).'c'. If you also know that the variance of the errors in the position measurement is 0.1] th2 = ms2th(ms2. 0] noisevar = [0. you can then define a theta structure using F = [0 1.D.1.K. Consider the following model structure 0 1 0 · x( t) = x(t) + u( t) 0 θ1 θ2 y( t) = 1 0 x( t) + e(t ) 0 1 x( 0 )= θ3 0 This corresponds to an electrical motor. 0 0. use canform instead of modstruc to define the model structure.0] ms2 = modstruc(F.25.25.For models that are parametrized as canonical forms. 0 NaN] G = [0 .thguess.) The motor is at rest at time 0 but at an unknown angular position. The parameter – θ 1 is the inverse time constant of the motor and – θ 2 ⁄ θ 1 is the static gain from the input to the angular velocity.01 0. Suppose that θ 1 is around -1 and θ 2 is around 0.H.x0).2) x0 = [NaN.01 and in the angular velocity measurements is 0. thguess=[–1. where y 1 ( t ) = x 1 ( t ) is the angular position of the motor shaft and y 2 ( t ) = x 2 ( t ) is the angular velocity.

D. B.9) to be linked to each other. If the underlying parameterization is in continuous time.T.B. State-Space Models with Coupled Parameters In some situations you may want the unknown parameters in the matrices in (6.2 .th2) The nominal parameter values thguess are then used. B. K.1 for input u and noise realization e: e=randn(300. Instead you need to write an M-file that describes the structure. like “what happens if I fix this parameter to a certain value” or “what happens if I let loose these parameters.2) u=idinput(300).C. you can try a number of “neighboring” structures.9). as in (6. and aux contains auxiliary variables. C. The structure can also be used to simulate the system above with sampling interval T=0. to free the parameter x2(0) (perhaps the motor wasn’t at rest after all) you can use th = unfixpar(th2. the function thinit is also useful.[2. For example.” Rather than going through the whole procedure in redefining the structure.1) % setting the sampling interval y = idsim([u e].K.'x0'. par contains the parameters. The latter variables are used to house options.x0] = mymfile(par. The matrices A.3 Tutorial The iterative search for minimum is then initialized at thguess.aux). and x0 refer to the discrete-time description (6.0. so that some different cases can be tried out without having to edit the M-file.8).9) when mymfile is called with a negative T. you can use the commands fixpar and unfixpar.8) or (6.1]) To manipulate initial conditions. When estimating models. where mymfile is the user-defined name for the M-file. To obtain the same structure as in the Example 6. and the noise sequence is scaled according to the matrix noisevar. Then the NaN feature is not sufficient to describe these links. The format is [A. C and D should be returned as the matrices in (6. th2 = sett(th2. it is desirable to write the M-file so that a negative value of T inhibits the sampling. T is the sampling interval. you can do the following: 3-36 . This means that A.D.

G = [0. It is always best to use physical insight.0]. the corresponding theta structure is defined by the command mf2th (M-file to theta): th = mf2th('mymfile'. State-Space Structures: Initial Values and Numerical Derivatives It is sometimes difficult to find good initial parameter values at which to start the numerical search for a minimum of (3.T). For random initialization. if T>0. 'c' signals that the underlying parametrization is continuous time. whenever possible.x0] = mymfile(par.function [A.'c'.1).B] = c2d(F. estimate models and evaluate results as for any other model structure.38).aux) F = [0 1.aux). K = zeros(2. though that the features fixpar and unfixpar are not available for these general structures.B. [A. Note. the gradient of the prediction errors e ( t ) is computed by numerical differentiation. and that the M-file is equipped with sampling inhibition (for T < 0 ). In its default version the step-size is simply 10 – 4 times the absolute value of the parameter in question (or the number 10 –7 if this is 3-37 . which consequently is required to run this example. 0 par(1)]. the command thinit is a useful alternative and complement to thguess. x0 =[par(3).G. From here on.D.K.C. where par contains the nominal (initial) values of the corresponding entries in the structure.2). to suggest such values with thguess. In the search for the minimum. C = eye(2). else A=F. end Here c2d is the sampling function from the Control System Toolbox. The step-size is determined by the M-file nuderst. D = zeros(2.par. Since there is always a risk that the numerical minimization may get stuck in a local minimum. it is advisable to try several different initialization values for θ . Once the M-file has been written.par(2)]. Some further examples of user-defined model structures are given below. B=G.T. aux contains the values of the auxiliary parameters.

end F(1. Replacing the space-second derivative by a corresponding difference approximation gives a time-continuous state-space model (6. % Assuming uniform initial % temperature of the rod deltaL = L/N. you may need to edit the M-file nuderst to address the problem of suitable step sizes for numerical differentiation.2)=1.N–1)=1.N)=–1.3 Tutorial larger).3: Heat Diffusion. where the dimension of x depends on the step-size in space used in the approximation.kk)=–2. The output of the system is the temperature at the near end. This section gives two examples of such structures. F=F∗kappa/deltaL/deltaL. F(kk.1)=–1.D. When the model structure contains parameters with different orders of magnitude. This is a metal rod with heat-diffusion coefficient κ which is insulated at the near end and heated by the power u (W) at the far end.9). In any case.aux) N = aux(1). % Length of the rod temp = aux(3). % Heat transfer coefficient at % far end of rod F=zeros(N. try to scale the variables so that the parameters are all roughly the same magnitude. % Near end of rod % insulated F(N.x0] = heatd(pars.N). This is described by the following M-file: function [A.C.kk+1)=1.T. F(N. Example 6.kk–1)=1. 3-38 . Consider a system driven by the heat-diffusion equation (see also Example 4. you have complete freedom in the choice of models of linear systems. Some Examples of User-Defined Model Structures With user-defined structures.K. F(1. % Space interval kappa = pars(1). F(kk. for kk=2:N–1 F(kk.3 in Ljung (1987)). This system is described by a partial differential equation in time and space. % Number of points in the % space–discretization L = aux(2). % The heat–diffusion coefficient K = pars(2).B.

D. and of the heat transfer coefficient is 1. % from the % Control System Toolbox x0=[0.1). C(1.27 1]. with an initial temperature of 22 degrees and a sampling interval of 10 seconds. 3-39 . C=[par(3) par(4)]. This can be handled by the following M-file: function [A.end You can then get started with the theta format with th = mf2th('heatd'.C. x0=temp∗ones(N.0 0]. respectively. and that only the first component of w ( t ) is nonzero. Example 6.eye(2). K = A∗dlqe(A. D=0.B.[].0].B=G.1). B = [1. K=zeros(N.T).10) for a 10th order approximation of a heat rod one meter in length.4: Parametrized Noise Models.else A=F.B]=c2d(F. % The assumed known measurement % noise variance A = [par(1) par(2). G(N.1)=K/deltaL.1)=1.C. Suppose that you know the variance of the measurement noise R2.'c'.T.[10. if T>0 [A.0]. R1= [par(5) 0.1 0].1.K.N). The covariance matrix of the prediction errors is given a default value.1).[0. The initial estimate of the heat conductivity is 0.R1.27.aux) R2 = aux(1).x0] = mynoise(par.G=zeros(N.22]. D=0. C=zeros(1.G.R2). Consider a discrete-time model x ( t+ 1 ) = A x( t) + B u(t ) +w (t ) y (t )= C x (t )+ e (t ) where w and e are independent white noises with covariance matrices R1 and R2.

The information in the theta format is displayed by the present command: present(th) This spells out the information in th. The representation should. the following printout from present The polynomial coefficients and their standard deviations are B = 0. You have to simulate it. Depending on the character of the underlying model structure. For multivariable ARX models and for state-space matrices.0000 0.3). you do not need to worry about the details.0214 0. however.0000 0. Estimated standard deviations for the parameters are always supplied.1). unless you are an advanced user.0000 1.3 Tutorial 7.5312 0. Theta Format: th The basic format for representing models in the System Identification Toolbox is called the theta format.0022 3-40 .0000 –1. the information is given in terms of the polynomials in (6. It stores all relevant information about the model structure used. and compute its poles and zeros and so on. including the values of the estimated parameters. you need to investigate its properties. It also contains some information about how and when the model was created. For example.6983 0.9). For the polynomials they are given as a second row.0563 A = 1. The details of the representation can be found in the Chapter 4. or in terms of the ARX polynomials in (6. be thought of as an internal one.0000 0.7345 0. You thus have to transform the model from the theta format to other ways of representing and presenting it. test its predictions.0000 0. Examining Models Once you have estimated a model. in terms of the matrices in (6. the estimated covariances of the parameters. "Command Reference" or by typing help theta (for state-space based structures type help thss).8) or (6. “Defining Model Structures” on page 3-29 describes how to create models in the theta format using several different commands. the standard deviations are given as imaginary numbers added to the parameters. and the estimated innovations variance and so on.

8) the parameters are given in the order obtained as the matrix A is first searched for estimated parameters row by row. For multivariable ARX models.11) along with their estimated standard deviations. etc.5312q + 0.0214. 3-41 . Frequency Function Format: ff The frequency function and the disturbance spectrum corresponding to a model th in the theta format is computed by [G.9). B. then B and then C. (See for example (6. D. For the polynomial model (6. which are translated from the covariance matrix of the estimated parameters. C. It is also the sampling interval that applies when th is used for simulation or prediction.1) the coefficients of the A. the ordering in par is the same as defined in the corresponding M-file. The actual parameters can be extracted from the theta format by [par. If th corresponds to a time-continuous model. and P is the estimated covariance matrix of the parameters.) Note that leading 0’s of B and the leading 1 in the other polynomials are omitted since they do not correspond to estimated parameters. the frequency functions are computed accordingly.6983q and the standard deviation of “1” is zero (naturally enough .) The sampling interval can be extracted from the theta format by T = gett(th) A negative T means that th represents a time-continuous system. since it is not estimated). and F polynomials are –1 given in the order of increasing powers of q . For user-defined structures. (See “The ARX Format: arx” on page 3-45.2).P] = th2par(th) –1 –2 Here par is a row vector containing the parameters. the ordering of parameters is somewhat tricky and it is safer use th2arx. The parameters are listed in “alphabetical order. The same is true for the continuous model (6.PHIV] = th2ff(th) ˆ This gives G and Φ v in (3. The standard deviation of a 1 is 0. Then system abs(T) indicates the sampling interval for the data for which the model was estimated. Note that leading zeros in the B polynomial indicate the delay. For the state-space model (6.” See “Some Special Topics” on page 3-68. as defined in “Defining Model Structures” on page 3-29.is interpreted as A ( q ) = 1 – 1.

This format stores the frequency functions and spectra (3. however. but produces Nyquist plots.. i.11) and their standard deviations as column vectors.sd) The command ffplot has the same syntax as bodeplot but works with linear frequency scales and Hertz as the unit. For time-continuous models.3 Tutorial The resulting matrices G and PHIV are given in the freqfunc format. and nyqplot.. If G is a spectrum. graphs of the frequency function in the complex plane. giving details about input and output numbers. but default to 128 values equally spaced between 0 (excluded) and the Nyquist frequency. Three functions offer graphic display of the frequency functions and spectra: bodeplot. its spectrum is obtained as PHIY = th2ff(th) Models in the freqfunc format are also obtained by the nonparametric estimation routines spa and etfe. Gn]) If information about standard deviations is included in G. as described in “Nonparametric Model Estimation” on page 3-19. The frequency values can be chosen arbitrarily. Several curves in the same diagram are obtained with bodeplot([G1 G2 .) 3-42 .. bodeplot(G) plots the Bode diagram of G (logarithmic scales and frequencies in rad/sec). is not important for basic use of the toolbox. confidence intervals corresponding to sd standard deviations are graphed with bodeplot(G. (See Chapter 4. ffplot. Typing help freqfunc describes the details of the format. which.e. If th corresponds to a model of a time series. For the creation of own frequency plots. The first row is reserved for administrative information. The command nyqplot also has the same syntax. "Command Reference"for more information. and the computation of frequency functions and spectra at arbitrary frequencies. the command getff extracts the relevant portions of the freqfunc format. the default frequency range extends to a decade over the Nyquist frequency for the sampled data upon which the model is based. only an amplitude plot is given. The function th2ff has options that allow the selection of specific input-output pairs.

K contains the static gains and their standard deviations. The representation is in discrete time as (6. The command th2zp also allows the selection of specific input-output subsystems in the case of multivariable models. The function getzp allows you to extract the zeros and the poles explicitly from the zero-pole format. It also contains (in the first row) administrative information about input and output numbers.K] = th2zp(th) The matrix zepo now contains information about the zeros and the poles of the model.8) or in continuous time as (6.sd) Comparisons between several models are obtained by zp1 = th2zp(th1) zp2 = th2zp(th2) zpplot(zpform(zp1.9) depending on the status of th. and static gains of the system associated with th: [zepo. which is used for plotting. State-Space Format: ss The command [A.X0] = th2ss(th) computes the matrices of a state-space representation of th. If the underlying model structure is a 3-43 . It also keeps track of whether the underlying model is in discrete or continuous time and draws the complex plane accordingly.D.K.C. along with their estimated standard deviations. poles. Similarly.Zero-Pole Format: zp The command th2zp computes the zeros.zp2)) zpplot has several options that determine how information about different models and different input-output pairs is depicted. The best way of using the information in zepo is to graph the zeros and poles by zpplot(zepo) Confidence regions (lines and ellipsoids) corresponding to sd standard deviations are illustrated by zpplot(zepo.B.

The polynomials are represented as row vectors in descending powers of s (in continuous time) or z or q (in discrete time). The state-space matrices can be used for further analysis and design in the Control System Toolbox and the Signal Processing Toolbox. specify the input number as an argument.7q q – 1. The common denominator DEN as a row matrix and the k-th row of NUM gives the numerator polynomial associated with output number k. The command th2ss can also compute the standard deviations of the elements in state-space matrices.7q is represented as NUM = 1 DEN = [1 –1.7 0] –3 (7.3 Tutorial state-space one.1) 3-44 . the continuous-time system 1 -----------------s(s + 2) is represented as NUM = [0 0 1] (or just 1) DEN = [1 2 0] while the discrete-time system q 1 ---------------------------------------------.5q + 0. Transfer Function Format: tf The transfer functions associated with the model th are computed by [NUM.5 0.DEN] = th2tf(th) NUM and DEN are given in the same format that is used in the Control System Toolbox and the System Processing Toolbox. If the model th has several inputs. B. the state-space representation is in observer canonical form.) For example. If the underlying model is defined in terms of input-output polynomials.= ----------------------------------------–1 –2 3 2 1 – 1. the matrices A. It thus differs from the polynomial format. etc. are given in the same basis as originally defined.5q + 0. (See below.

B.7] Delays are thus denoted by leading zeros in B. the polynomials A. th2arx is thus an inverse of arx2th. 1. k = 0 . 3-45 . Continuous-time systems can also be represented in the polynomial format. See also Section 6.1) is represented by B = [0 0 0 1] A = [1 –1. D.D.23) are given as follows: Polynomial coefficients are stored in row vectors. and F in (3. Note the difference with the transfer function representation. Only when the lengths of A and B are the same do the formats coincide.B.B] = th2arx(th) The matrices A and B then contain the ARX polynomials as described in Section 6.F] = th2poly(th) This is consequently the “inverse” of poly2th described in “Defining Model Structures” on page 3-29. Then the polynomials are given as row vectors in descending powers of the Laplace variable s just as in the transfer function case. use [A. This means that (7. iv4. … . in that leading zeros must be explicitly given. or arx2th).Polynomial Format: poly In the polynomial format. C. The polynomials corresponding to th are extracted by [A. The ARX Format: arx To obtain an ARX description from a model th that corresponds to such a description (i. it has originally been generated by arx.C..5 0. ordered by ascending powers in the delay operator q – k.e. always starting with k = 0.

arx. A quick check can thus be given by gett(th)<0 All the model transformations th2ff. It is also used to select suitable default frequency intervals in th2ff (the default being from zero up to 10 * π/ |T| rad/sec). the model is first transformed to discrete time. n4sid. however. however. (See below. "Command Reference". bj. ivar. Discrete-time models also result from poly2th with positive or default values of the sampling interval. Discrete-Time Models These models are obtained from the estimation functions ar. For simulation and prediction. The absolute value of the sampling interval of a continuous-time model is the sampling interval of the data for which the model was estimated. th2ss. continuous-time models are obtained by the command thd2thc. and th2poly result in the corresponding characteristics in continuous time for models th that are indicated as continuous.) Continuous-time models are indicated by a negative sampling interval.) 3-46 .1) and to state-space structures generated by ms2th and mf2th with the argument 'd'. iv4. th2zp. They are also obtained from pem when applied to (6. (See “Defining Model Structures” on page 3-29 and the Chapter 4. Finally. Finally discrete-time models are obtained with the command thc2thd. This structure cannot. be used for further estimation.3 Tutorial Transformations Between Discrete and Continuous Models Continuous-Time Models A model in the theta format can be internally represented as a continuous-time model. and oe. The absolute value of T also applies when the model is used for simulation and prediction. (See below.1) in polynomial form also results when poly2th is used with a negative value of the sampling interval.) The model then remains a continuous-time one during the estimation phases with pem even though the estimation is performed using sampled data. A continuous-time model of the type (6. th2tf. armax. This occurs if the structure was originally defined as a state-space structure with ms2th or mf2th using the argument 'c'.

It is also used for appropriate frequency scales in the freqfunc format. See the comments in “Defining Model Structures” on page 3-29. thc = thd2thc(th). Here is an example which compares the Bode plots of an estimated model and its continuous-time counterpart: th = armax(z. You may want to edit it for applications where the parameters have very different orders of magnitude. This is done automatically by th2ff. thd2thc offers as an option to approximate the dead time by a finite dimensional system.The sampling interval T is obtained by T = gett(th). The M-file nuderst is then invoked. when given in the theta format. gd = th2ff(th).32).[2 3 1 2]). bodeplot([gd gc]) Simulation and Prediction Any model. Note that the noise properties are translated by the somewhat questionable formula (3. They should then be appended as an extra dead time. Notice that th contains information about the noise variance so e should be a 3-47 . The output is returned in a column vector y of the same length. can be simulated with y = idsim([u e]. The corresponding uncertainty measure (the estimated covariance matrix of the internal parameters) is also transformed in most cases. Transformations Transformations between continuous-time and discrete-time model representations are achieved by thc2thd and thd2thc. The covariance matrix is translated by Gauss’ approximation formula using numerical derivatives.T) If the discrete-time model has some pure time delays ( nk > 1 ) the default command removes them before forming the continuous-time model.th) where u and e are column vectors (or matrices) containing the input and noise sequences. It indicates the sampling interval of the model as well as of the data to which the model was adjusted. The syntax is thc = thd2thc(thd) thd = thc2thd(thc. gc = th2ff(thc).

y2 = y(49:96) th = ar(y1.[0 0. Here is a typical string of commands: A = [1 –1. predictions and simulations coincide. th0 = poly2th(A. plot(y) The “inverse model” (3. y = idsim([u e]. monthly sales figures. the procedure is as follows: yhat = predict([y u]. Here is an example.5].7]. an output error model A = C = D = 1 maintains that there is no information in past outputs. A model is estimated based on the first half. say. e = randn(400. unit-variance sequence.th) To compute the k-step ahead prediction of the output signal based on a model th. If e is omitted. The actual way that the information in past outputs is used depends on the noise model in th. and then its ability to predict half a year ahead is checked out on the second half of the observations: idplot(y) y1 = y(1:48). where y is the original series of.5 0.4) yhat = predict(y2.1).th0).3]).’rbs’.2]).th. a noise-free simulation is obtained. 3-48 . which computes the prediction errors from given input-output data.6) plot([y2 yhat]) The command compare is useful for any comparisons involving idsim and predict. is simulated with e = pe([y u]. predict can evaluate how well a time series model is capable of predicting future values of the data.38). u = idinput(400.k) ˆ The predicted value y ( t t – k ) is computed using the information in u ( s ) up to time s = t and information in y ( s ) up to time s = t – k . For example. B = [0 1 0.[1 –1 0.th4.B.3 Tutorial zero-mean. therefore.

use nn = selstruc(V. Model Structure Selection and Validation After you have been analyzing data for some time. Next. Collect in a matrix NN all of the ARX structures you want to investigate.zv.8. but there is no absolute procedure for approaching it. so that each row of NN is of the type [na nb nk] With V = arxstruc(ze. for each of these models. For state-space models this is easily obtained by using a vector argument for the order in n4sid: th = n4sid(z. Comparing Different Structures It is natural to compare the results obtained from model structures with different orders. These are the problems of model validation.NN) an ARX model is fitted to the data set ze for each of the structures in NN.0) 3-49 . To select the structure that has the smallest loss function for the validation set zv. This section describes the techniques you can use to evaluate model qualities using the System Identification Toolbox. You need to decide which one is best. It is wise to be equipped with a variety of different tools with which to evaluate model qualities. For models of ARX type. Model validation is the heart of the identification problem. The resulting loss functions are stored in V together with the corresponding structures.1:10) This invokes a plot from which a “best” order is chosen. and if the best description is an adequate model for your purposes. as they are applied to the data set zv. you typically end up with a large collection of models with different orders and structures. various orders and delay can be efficiently studied with the command arxstruc. the sum of squared prediction errors is computed.

struc(2. A graph of the fit versus the number of parameters is obtained with nn = selstruc(V) This routine prompts you to choose the number of parameters to estimate. where the model is tested on another data set.0). i. nn = selstruc(V) where you first establish a suitable value of the delay nk by testing second order models with delays between one and ten. The command struc helps generate typical structure matrices NN for single-input systems.3 Tutorial Such a procedure is known as cross validation and is a good way to approach the model selection problem.e. There are several approaches for this. A typical sequence of commands is V = arxstruc(ze.struc(1:5. if ze = zv. and then all combinations of ARX models with up to five a and b parameters are tested with delays around the chosen value (a total of 75 models). Probably the best known technique is Akaike’s Final Prediction Error (FPE) criterion and his closely related Information Theoretic Criterion (AIC)..1:10)). nn = selstruc(V. Both simulate the cross validation situation. based upon visual inspection of the graph. You need to compensate for this automatic decrease of the loss functions.nk–1:nk+1)). and then it selects the structure with the best fit for that number of parameters.*V 1–n⁄N 3-50 .zv. The FPE is formed as 1+n⁄N FPE = ------------------. nk = nn(3). the fit always improves as the model structure increases.2. The best fit selects the delay.1:5. V = arxstruc(ze. It is usually a good idea to visually inspect how the fit changes with the number of estimated parameters.zv. If the model is validated on the same data set from which it was estimated.

(For ARX models the noise model 1/A(q) is directly coupled to the dynamics model B(q)/A(q).and zero-locations into 3-51 . V also contains the condition number of the matrix from which the IV estimates are solved. in a collection of different models. The FPE values are displayed by the present command and are also given as the entry (2. This is accomplished with V = ivstruc(ze. 1987).where n is the total number of estimated parameters and N is the length of the data record.1) of the th matrix. Poor conditioning of this matrix indicates unnecessarily high model orders. A related criterion is Rissanen’s minimum description length (MDL) approach. The structure that minimizes the AIC is obtained with nn = selstruc(V. Checking Pole-Zero Cancellations A near pole-zero cancellation in the dynamics model is an indication that the model order may be too high. using an IV technique.'AIC') where V was generated by arxstruc.) According to Akaike’s theory. (See page 415 in Ljung.zv. choose the one with the smallest FPE (or AIC). and to compute the fit between the model’s simulated output and the output in the validation data set zv.'MDL') If substantial noise is present.NN) The information in V can then be handled as described above. The AIC is formed as AIC ≈ log [ ( 1 + 2n ⁄ N )*V ] (See Section 16. the ARX models may need to be of high order to describe simultaneously the noise characteristics and the system dynamics. take the uncertainties in the pole. This is obtained with nn = selstruc(V. To judge if a “near” cancellation is a real cancellation. In this case.) An alternative is to compute the dynamics model only.4 in Ljung (1987). V is the loss function (quadratic fit) for the structure in question. which selects the structure that allows the shortest over-all description of the observed data.

or current e ( t ) affecting future u ( t ). • Correlation between e and u for negative lags. Correlation at negative lags is of interest. do not accept the corresponding model as a good description of the system. and bj.38). If the confidence regions overlap. are ideally white and independent of the input for the model to correctly describe the system. focus on the independence of e and u rather than the whiteness of e. try lower model orders. This is not a reason to reject the model. The rule is that if the correlation functions go significantly outside these confidence intervals. as in (3. oe. since certain methods do not work well when feedback is present in the input-output data. Also displayed are 99% confidence intervals for these variables. If you are interested primarily in G. The auto correlation function of e and the cross correlation function between e and u are computed and displayed for up to lag 25. which are graphed by zpplot(th2zp(th). The function th2zp computes confidence regions for the poles and zeros. Residual Analysis The residuals associated with the data and a given model.41) focus on the dynamics G and less about the noise properties H. Checking cancellations in B(q)/A(q) then gives a good indication of which orders to chose from model structures like armax. assuming that e is indeed white and independent of u.3 Tutorial consideration. (see 3-52 . As mentioned under “Comparing Different Structures.19) and methods like the IV method (3.” the orders can be pushed up due to the requirement that 1/A(q) describe the noise characteristics.1) where the 1 indicates how many standard-deviations wide the confidence interval is. Some qualifications of this statement are necessary: • Model structures like the OE structure (3. This check is especially useful when the models have been generated by arx. is an indication of output feedback. The function e = resid(z.th) computes the residuals e and performs whiteness and independence analyses.

but with a different data set that uses the same input sequence.u]. (Note that ivstruc forms the squared difference of y and yh for IV-computed models th. …nk + nb – 1 for the data used for the estimation. As part of the validation process. It does not account for systematic errors due to an inadequate choice of model structure. The variability of the model that is due to the random disturbances in the output is estimated by most of the estimation procedures. 3-53 . but concentrate on the positive lags in the cross-correlation plot for model validation purposes. This variability answers the question of how different can the model be if I repeat the identification procedure. you can run a simulation: yh = idsim(u. There is no guarantee that the “true system” lies in the confidence interval. using the same model structure.th) It is a much tougher and revealing test to perform this simulation. as well as the residual tests. nk + 1 . the least-squares procedure automatically makes the correlation between e ( t ) and u ( t – k ) zero for . and due to the lack of an absolutely correct model structure.) Noise-Free Simulations To check whether a model is capable of reproducing the observed output when driven by the actual input. you can graph the residuals using plot(e) for a simple visual inspection of irregularities and outliers.“Dealing with Data” on page 3-58). k = nk . (See also “Dealing with Data” on page 3-58.15). on a fresh data set [y u] that was not used for the estimation of the model th.) Assessing the Model Uncertainty The estimated model is always uncertain.th) plot([y yh]) The same result is obtained by compare([y. • When using the ARX model (3. This is called cross validation. due to disturbances in the observed data. and it can be displayed and illuminated in a number of ways.

3

Tutorial

The uncertainty in the frequency response is calculated with
[g,phiv] = th2ff(th)

and can subsequently be graphed with bodeplot. The uncertainty in the time response is displayed by
idsimsd(u,th)

Ten possible models are drawn from the asymptotic distribution of the model th. The response of each of them to the input u is graphed on the same diagram. The uncertainty of these responses concerns the external, input-output properties of the model. It reflects the effects of inadequate excitation and the presence of disturbances. You can also directly get the standard deviation of the simulated result by
[ysim,ysimsd] = idsim(u,th)

The uncertainty in internal representations is manifested in the covariance matrix of the estimated parameters,
present(th)

and in the standard deviations of the pole- and zero-locations, which are computed with
zepo = th2zp(th)

and displayed using zpplot. Large uncertainties in these representations are caused by excessively high model orders, inadequate excitation, or bad signal-to-noise ratios.

Comparing Different Models
It is a good idea to display the model properties in terms of quantities that have more physical meaning than the parameters themselves. Bode plots, zero-pole plots, and model simulations all give a sense of the properties of the system that have been picked up by the model. If several models of different characters give very similar Bode plots in the frequency range of interest, you can be fairly confident that these must reflect features of the true, unknown system. You can then choose the simplest model among these.

3-54

A typical identification session includes estimation in several different structures, and comparisons of the model properties. Here is an example:
a1 = arx(z,[1 1]); [gs,nss] = spa(z); [ga1,nsa1] = th2ff(a1); bodeplot([gs ga1]) bodeplot([nss nsa1]) zpa1 = th2zp(a1); am2 = armax(z,[2 2 2 1]); [gam2,nsam2] = th2ff(am2); bodeplot([gs gam2]) zpam2 = th2zp(am2); zpplot(zpform(zpa1,zpam2))

Conditioning of the Prediction Error Gradient
When the model orders in (3.23) are overestimated, so that a pole-zero cancellation can take place in the model, the prediction error gradient theoretically becomes rank deficient. The matrix that is inverted when estimating the covariance matrix becomes singular, and the Gauss-Newton search direction becomes ambiguous. Due to the high numeric precision in M ATLAB, you are unlikely to encounter messages about singular and rank deficient matrices. Instead, overestimated model orders usually show up as large estimated parameter variances and large norms of the Gauss-Newton vector (although only minor decreases in the criterion value result). Consequently, these are good indicators that you have gone too far in increasing the model orders. See also “Some Special Topics” on page 3-68.

Selecting Model Structures for Multivariable Systems
Multivariable systems are often more difficult to model. Some basic aspects and advice were given in “The Basic Steps of System Identification” on page 1-10. The graphical user interface (GUI) offers particularly useful support for the multivariable case. In this section we give some more technical comments about the identification of multivariable systems.

3-55

3

Tutorial

The basic comments given so far in this section also apply to such systems. There are, however, a large number of possible structures for systems with several outputs, and systematic tests of the many possibilities are impractical. This problem is a difficult one, and for a more comprehensive treatment, refer to Appendix 4.A of Ljung (1987). First of all, physical insight is more important than anything else. Whenever there is prior knowledge sufficient to form physically parametrized state-space models, you should test that. Even lacking more precise knowledge, some physical insight might help you to come up with first suggestions of orders and delays. For multi-output black-box models, it is easiest to first try state-space models using n4sid for the model estimation. Multivariable ARX models are also easy to deal with. When building such models, a simple start-up procedure is to try arx with a structure that is filled with parameters. Then consider those estimates that are of the same magnitude as their standard deviations, and try orders and delays that automatically set them to zero. Note that for arx each row is estimated independently of the others. Changing orders and delays associated with output number i (i.e. the i-th row of na, nb, and nk) does not change the parameter estimates associated with the other rows. When a reasonable structure has been found, try iv4 with it and evaluate the models in the usual ways. If the signal to noise level is not good, and it is important to have models that describe the noise characteristics, try state-space models. (These are equivalent to multivariable ARMAX models.) Again, it is easier to estimate state-space models directly without specifying the particular structure. This is done using n4sid. An alternative is to apply the prediction error method using canonical state-space forms. These are obtained by the command canstart. This defines a canonical form structure from the pseudo-observability indices. These indices form a vector with the same number of entries as the number of outputs. Loosely speaking, index number k describes how many delayed values of yk affect the current value of yk. The sum of the indices is equal to the order of the

3-56

system. The number of possible pseudo-observability indices for a system of order n with p outputs is  n  p It is, however, reassuring to know that almost every system of order n can be described in a structure corresponding to any set of pseudo-observability indices whose sum is n. You can estimate the order of the system (or, rather, try several different orders) and pick any set of pseudo-observability indices corresponding to that order. A default choice of indices can be made by canstart if only the order is specified. Only if the minimization in pem shows signs of poor conditioning of the involved matrices do you need to try other indices. Note that the canonical form parametrizations cannot handle input delays. To deal with specific delays from the input(s), shift the input sequences accordingly. Also note that with fixpar any canonical form parameterization can be transformed to a corresponding output-error structure, by fixing the matrix K to zero.

3-57

3

Tutorial

9. Dealing with Data
Extracting information from data is not an entirely straightforward task. In addition to the decisions required for model structure selection and validation, the data may need to be handled carefully. This section gives some advice on handling several common situations.

Offset Levels
When the data have been collected from a physical plant, they are typically measured in physical units. The levels in these raw inputs and outputs may not match in any consistent way. This will force the models to waste some parameters correcting the levels. Offsets are easily dealt with; always subtract the mean levels from the input and output sequences before the estimation. It is best if the mean levels correspond to a physical equilibrium, but if such values are not known, use the sample means:
z = dtrend(z);

Section 14.6 in Ljung (1987) discusses this in more detail. With the dtrend command, you can also remove piece-wise linear trends.

Outliers
Real data are also subject to possible bad disturbances; an unusually large disturbance, a temporary sensor or transmitter failure, etc. It is important that such outliers are not allowed to affect the models too strongly. The robustification of the error criterion (described under lim in “Optional Variables” on page 3-26) helps here, but it is always good practice to examine the residuals for unusually large values, and to go back and critically evaluate the original data responsible for the large values. If the raw data are obviously in error, they can be smoothed, and the estimation procedure repeated.

Filtering Data
Depending upon the application, interest in the model can be focused on specific frequency bands. Filtering the data before the estimation, through filters that enhance these bands, improves the fit in the interesting regions. This is used in the System Identification Toolbox function idfilt. For

3-58

These techniques should be avoided when feedback is present. Chapter 13 in Ljung (1987) discusses the role of filtering in more detail.19) and the Box-Jenkins model (3. To detect if feedback is present. all the prediction error methods work equally well for closed-loop data. Note.1 * π. You then need to model the noise properties carefully. use the basic method of applying cra to estimate the impulse response. For example. The spectral analysis method and the instrumental variable techniques (with default instruments) give unreliable results when applied to closed-loop data. 3-59 . This computes and uses a fifth order Butterworth bandpass filter with passband between the indicated frequencies. Feedback in Data If the system was operating in closed loop (feedback from the past outputs to the current input) when the data were collected. Basically. a natural part of model validation. Testing for feedback is.02 0.[0. Significant correlation at negative lags again indicates output feedback in the generation of the input. if you want to lower the sampling rate by a factor of 5. some care has to be exercised.example.02 * π and 0. even if H (which equals 1 for the output error model) does not allow a correct description of the noise properties. therefore.21) are normally capable of giving a correct description of the dynamics G. that the Output-Error model (3. Delays The selection of the delay nk in the model structure is a very important step in obtaining good identification results.5. however.1]). This is no longer true for closed-loop data. execute zf = idfilt(z. use z5 = idresamp(z. You can get an idea about the delays in the system by the impulse response estimate from cra. to enhance the data in the frequency band between 0. The SITB contains other useful commands for related problems. Significant values of the impulse response at negative lags is a clear indication of feedback. a graph of the correlation between residuals and inputs is given. When a parametric model has been estimated and the resid command is applied.5).

3-60 . Underestimated delays (nk too small) show up as small values of leading b k estimates.3 Tutorial Incorrect delays are also visible in parametric models. Overestimated delays (nk too large) are usually visible as a significant correlation between the residuals and the input at the lags corresponding to the missing b k terms. Use the delay that gives the best fit for further modeling. vary nk around the nominal value within the structure. compared to their standard deviations. When you have found an otherwise satisfactory structure. A good procedure is to start by using arxstruc to test all feasible delays together with a second-order model. and evaluate the results.

and θ 0 ( t ) represents the true description of the system. as in adaptive control. and online algorithms are used for such algorithms.15). sequential estimation. y ( t ) is a prediction of the value y ( t ) based on observations up to time t – 1 and also based on the current model (and possibly also earlier ones) at time t – 1 . e ( t ) is the noise source (the innovations). 3-61 . Moreover. adaptive parameter estimation. adaptive filtering. or adaptive prediction. Chapter 11 in Ljung (1987) deals with such algorithms in some detail. Compare with (3. You may need the model to make some decision on line. It may be necessary to investigate possible time variation in the system’s (or signal’s) properties during the collection of data.10.1) ˆ Here θ ( t ) is the parameter estimate at time t. Recursive Parameter Estimation In many cases it may be necessary to estimate a model on line at the same time as the input-output data is received. The gain K ( t ) determines in what way the current ˆ prediction error y ( t ) – y ( t ) affects the update of the parameter estimate. The Basic Algorithm A typical recursive identification algorithm is ˆ ˆ ˆ θ( t ) = θ(t – 1) + K( t) (y( t ) – y( t )) (10. The latter symbol is the prediction of y ( t ) according the model described by θ . Terms like recursive identification.2) ˆ where ψ ( t ) is (an approximation of) the gradient with respect to θ of y ( t θ ) . Moreover. Note that model structures like AR and ARX that correspond to linear regressions can be written as y ( t ) = ψ ( t )θ 0 ( t ) + e ( t ) T (10. It is typically chosen as K ( t ) = Q ( t )ψ ( t ) (10. and y ( t ) is the observed output ˆ at time t. The natural T ˆ prediction is y ( t ) = ψ ( t )θ ( t – 1 ) and its gradient with respect to θ becomes exactly ψ ( t ) .3) where the regression vector ψ ( t ) contains old values of observed inputs and outputs.

4 in Ljung (1987) describes suitable ways of computing such approximations for general model structures. Section 11. The matrix Q ( t ) that affects both the adaptation gain and the direction in which the updates are made. can be chosen in several different ways.4) Here w ( t ) is assumed to be white Gaussian noise with covariance matrix Ew ( t )w ( t ) = R 1 T (10. you cannot recursively ˆ compute the exact prediction and its gradient for the current estimate θ ( t – 1 ) .5) 3-62 . ˆ Then approximations y ( t ) and ψ ( t ) must be used instead. A typical choice is to describe these parameters as a random walk: θ0 ( t ) = θ 0 ( t – 1 ) + w ( t ) (10.3 Tutorial For models that cannot be written as linear regressions. This is discussed in the following section. Choosing an Adaptation Mechanism and Gain The most logical approach to the adaptation problem is to assume a certain model for how the “true” parameters θ 0 change.

P ( 0 ) . The algorithm is entirely specified by R 1 . An optimal choice of Q ( t ) in (10.7) that is less than about 0. Here λ is clearly is a positive number ≤ 1. t = 1 . 3-63 . Think of τ = 1 ⁄ ( 1 – λ ) as the memory horizon of the approach. ψ ( t ) .3).Suppose that the underlying description of the observations is a linear regression (10.3): R 2 = Ee ( t )(a scalar). so that an τ observation that is τ samples old carries a weight that is λ of the weight of the most recent observation. This means that the following function is minimized rather than (3. See eq (11.2) can then be computed from the Kalman filter.6c) (10.97– 0.995.6) will be called the Kalman Filter (KF) Approach to adaptation.66)-(11. and the sequence of data y ( t ) . it can also be applied in the general case where ˆ y ( t ) is computed in a different way from (10.6b) (10.7 at time t. The measurements that are older than τ = 1 ⁄ ( 1 – λ ) carry a weight in (10.39): ∑λ k=1 t t–k 2 e (k) (10. Typical values of λ are in the range 0.…. θ ( 0 ) . R 2 .67) in Ljung (1987). Another approach is to discount old measurements exponentially. and the complete algorithm becomes ˆ ˆ ˆ θ ( t ) = θ ( t – 1 ) + K ( t ) ( y( t ) – y ( t ) ) T ˆ ˆ y ( t ) = ψ ( t )θ ( t – 1 ) (10.6d) K ( t ) = Q ( t )ψ ( t ) P(t – 1) Q ( t ) = --------------------------------------------------------T R 2 + ψ ( t ) P ( t – 1 )ψ ( t ) P ( t – 1 )ψ ( t )ψ ( t ) P ( t – 1 ) P ( t ) = P ( t – 1 ) + R 1 – ---------------------------------------------------------------T R 2 + ψ ( t ) P ( t – 1 )ψ ( t ) 2 T (10.1)-(10. 2.6e) Here R 2 is the variance of the innovations e ( t ) in (10.6b). The algorithm (10.3.6a) (10. with drift matrix R 1. Even though the algorithm was motivated for a linear regression model structure.

3 Tutorial The criterion (10.7) can be minimized exactly in the linear regression case giving the algorithm (10.I 2 ψ( t) (10.10) the Normalized Gradient (NG) Approach to adaptation.6abc) with the following choice of Q ( t ) : P( t – 1 ) Q ( t ) = P ( t ) = -----------------------------------------------------T λ + ψ ( t ) P ( t – 1 )ψ ( t ) P ( t – 1 )ψ ( t )ψ ( t ) P ( t – 1 )  P ( t – 1 ) – ---------------------------------------------------------------- T P(t) =  ⁄λ λ + ψ ( t ) P ( t – 1 )ψ ( t )    T (10.1) in the negative gradient direction (with respect to θ ) of the criterion (3. (10. least mean squares in the linear regression case. respectively in Ljung (1987).8b) This algorithm will be called the Forgetting Factor (FF) Approach to adaptation. A third approach is to allow the matrix Q ( t ) to be a multiple of the identity matrix: Q ( t ) = ϒI It can also be normalized with respect to the size of ψ : ϒ Q ( t ) = --------------. with the forgetting factor λ .63) in Ljung (1987).46). recursive least squares in the linear regression case.8a) (10. 3-64 .9) will be called the Unnormalized Gradient (UG) Approach and (10.39). See eq (11. Note that λ = 1 in this approach gives the same algorithm as R 1 = 0. The gradient methods are also known as LMS. The algorithm is also known as RLS. R 2 = 1 in the Kalman filter approach. with gain ϒ .10) (10. These choices of Q ( t ) ˆ move the updates of θ in (10.9) See eqs (11. Therefore.45) and (11.

1): rarmax. rbj. R 2 and P ( 0 ) are scaled by the same number. rarx.adm.6) are not affected if all the matrices R 1. exactly as for the corresponding offline algorithm. and is useful also for noise cancelling and other adaptive filtering applications. The output argument thm is a matrix that contains the current models at the different samples. and roe.nn. You can therefore always scale the original problem so that R 2 becomes 1. the predicted value of y ( k ) . adg = gam gives the normalized gain approach (10.Available Algorithms The System Identification Toolbox provides the following functions that implement all common recursive identification algorithms for model structures in the family (6. and ψ ( 0 ) . P ( 0 ) .adg) Here z contains the output-input data as usual. rpem. adm = 'ng'. in row k. adg = lam gives the forgetting factor algorithm (10. nn specifies the model structure.yh] = rfcn(z.8). The output argument yh is a column vector that contains. 3-65 . Row k of thm contains the model parameters. The functions also have optional input arguments that allow the specification of θ ( 0 ). Optional output arguments include the last value of the matrix P and of the vector ψ . corresponding to row k in the data matrix z. with forgetting factor lam. adm = 'ff'.6) with drift matrix R1 enter adm = 'kf'. adg = gam gives the unnormalized gradient approach (10.9) with gain gam. adg = R1 ˆ The value of R 2 is always 1. The arguments adm and adg select the adaptation mechanism and adaptation gain listed above. The vector yh thus contains the adaptive predictions of the outputs. rplr. They all share the following basic syntax: [thm. To obtain the Kalman filter approach (10. The ordering of the parameters is the same as th2par would give when applied to the theta format of a corresponding offline model. in alphabetical order at sample time k. based on past observations and current model. Note that the estimates θ in (10. Similarly. adm = 'ug'.10).

P. thm = rplr(z. The algorithms are.'ff'.[2 2 1]. This is accomplished by storing the update information in θ ( t – 1 ). See equation (11.th(1). The resulting static gains of the estimated models are then plotted as a function of time: [N.[2 2 1]. and contains some well known special cases. When applied to the output error model (nn=[0 nb 0 0 nf nk]) it results in methods known as HARF ('ff'–case) and SHARF ('ng'–case). rarx is a recursive variant of arx. The common extended least squares (ELS) method is an rplr algorithm for the ARMAX model (nn=[na nb nc 0 0 nk]).57) in Ljung (1987).3 Tutorial Now.u (scalars) [th.'ff'.hold 3-66 .1:2)')'. stg = nums.01∗eye(6)). also prepared for true online applications. using Kalman filter adaptation. though that rarx does not handle multi-output systems./dens.1)+sum(thm(:. nums = sum(thm(:.98). first i/o pair y.dum]=size(z). which is built recursively and its time varying parameter estimates plotted as functions of time: thm = roe(z.'kf'. axis([1 50 –2 2]) plot(1. It is known as the recursive pseudo-linear regression approach.0. where the computed model is used for some online decision. Note.98).[2 2 2 0 0 1].0. and rpem does not handle state-space structures. plot(stg) So far. dens = ones(N.phi] = rarx([y u].0. similarly rarmax is the recursive counterpart of armax and so on. however. plot(thm) A second order ARMAX model is recursively estimated by the ELS method. P ( t – 1 ) and information about past data in φ ( t – 1 ) (and ψ ( t – 1 ) ) and using that information as initial data for the next time step.3:4)')'.'∗'). and uses a different approximation of the gradient ψ . The following example shows a second order output error model.yh. The function rplr is a variant of rpem. The following example shows the recursive least-squares algorithm being used on line (just to plot one current parameter estimate): %Initialization. the examples of applications where a batch of data is examined cover studies of the variability of the system.

3). Fault detection in systems and detection of trend breaks in time series can serve as two examples of typical problems.. Several Kalman filters that estimate these parameters are run in parallel. See iddemo 7 in Chapter 4.th'. but now and then it abruptly changes the system parameters θ 0 ( t ) .[2 2 1].'∗') end Executing iddemo 6 illustrates the recursive algorithms. of the number of parallel models in use. Optional arguments allow the specification of the measurement noise variance R 2 in (10.nn) with a format like rarx or rarmax. This is the segmentation problem. "Command Reference" also.P. rarx([y u].P.'ff'. Segmentation of Data Sometimes the system or signal exhibits abrupt changes during the time when the data is collected. plot(k.u [th. and also of the guaranteed lifespan of each hypothesis.th(1).98. where the change term w ( t ) is zero most of the time. of the probability of a jump.phi). The relative reliability of these assumed system behaviors is constantly judged. 3-67 ..yh. and unlikely hypotheses are replaced by new ones. The algorithm that is implemented in segment is based on a model description like (10.%The online loop: for k = 2:50 % At time k receive y.4). The matrix thm contains the piecewise constant models in the same format as for the algorithms described earlier in this section. The System Identification Toolbox offers the function segment to deal with the segmentation problem.0. It may be important in certain applications to find the time instants when the changes occur and to develop models for the different segments during which the system does not change. each of them corresponding to a particular assumption about when the system actually changed. The basic syntax is thm = segment(z.phi] = .

th) (11. and ms2th.lam) y = idsim(e. you can also check if a particular topic is brought up here. State-space models of time series can be built simply by specifying B = []. but with natural modifications. but need no specification of nb and nk: th = arx(y.th) 3-68 . but does not provide any input-residual correlation plots: e = resid(y.1. but since manuals seldom are read from the beginning. D = [] in modstruc.1) Spectral analysis (etfe and spa) and the th2ff function now return the spectral estimate of y as their first output arguments: PHIY = th2ff(th) PHIY = spa(y) PERIOD = etfe(y) Note that etfe gives the periodogram estimate of the spectrum.C.[na nc]) Note that arx also handles multivariate signals. Some Special Topics This section describes a number of miscellaneous topics. Basically all commands still apply to these time series models. mf2th. Most of the information here is also covered in other parts of the manual. resid works the same way for time series models. Time Series Modeling When there is no input present. the general model (6.3 Tutorial 11.[].na) th = armax(y.[]. armax and arx work the same way. They are listed as follows: th = poly2th(A.1) reduces to the ARMA model structure: A ( q )y ( t ) = C ( q )e ( t ) With C ( q ) = 1 you have an AR model structure.

One is th = ar(y. and a modified covariance method.ts0).sp2. and oe are not defined.ts0).na) which uses an instrumental variables technique to compute the AR part of a time series. e = randn(200. plot(y) per = etfe(y). ffplot([per.1)]. ir = idsim([1.spe0]) % A second order AR model: ts2 = ar(y. compare spectral estimates and covariance function estimates.zeros(24. and also the predictions of the model.speh.3]) % The covariance function estimates: Ryh = covf(y. the Yule-Walker approach. % The true spectrum: spe0 = th2ff(ts0). Finally. "Command Reference" for details.In addition there are two commands that are specifically constructed for building scalar AR models of time series.ir2(25:–1:1)).24). the functions bj.5 0. iv.7]. Here is an example where you can simulate a time series. See Chapter 4. speh = spa(y).1). a geometric lattice method. The other command is th = ivar(y.zeros(24. % The true covariance function: Ry0 = conv(ir. iv4.ir(25:–1:1)). Ry2 = conv(ir2. when no input is present.2). Among these are Burg’s method.spe0.ts2). y = idsim(e. ffplot([speh. 3-69 . ir2 = idsim([1.[]). ts0 = poly2th([1 –1. sp2 = th2ff(ts2).na) which has an option that allows you to choose the algorithm from a group of several popular techniques for computing the least-squares AR model.1)].

Ry2. armax.5) The Sampling Interval The System Identification Toolbox assumes a normalized sampling interval of T = 1 . bj. per second. even if the model itself in parametrized in continuous time.th2. In the case of th2ff.2) element.. It is generally the last argument.T) Note that the value of T is just changed. for which this model was estimated. to transfer functions and to state-space matrices) will be in terms of the continuous-time model. in that case. An explicitly given sampling interval (as an argument to pem.3). It can be read by T = gett(th) and it is changed by thnew = sett(thold.. the default value of T is the one given by th. and oe is given by a matrix th in the theta format. to poles and zeros. per sampling interval” rather than “. This means that the frequency unit becomes “radians per sampling interval.and discrete-time models give numerical parameter values corresponding to the unit “.” and that all the transformations between continuous. unless you specify otherwise. for example) overrides the default value in th. no transformation of parameters is carried out by sett. All models in the theta format contain the sampling interval T as the (1.[Ryh. The absolute value of T denotes. 3-70 .” To obtain correct physical units in these cases. This is also the sampling interval used when the model is used for simulation or prediction.Ry0]) % The prediction ability of the model: compare(y.. You can specify the sampling interval as an optional argument in all the functions that create theta structures. A negative value of T indicates that the corresponding model is given in continuous time.3 Tutorial plot([–24:24]∗ones(1. If the initial structure in pem. abs(T) is used for the default choice of frequency range. Note that in ms2th and mf2th. the sampling interval of the data. it is the sampling interval of the data that you need to specify. the sampling interval must be specified accordingly.. All other transformations (to the frequency function.

The default value of MAXSIZE is set in the M-file idmsize. If you have memory problems. MAXSIZE is 8188 on the smaller machines. 3-71 . When you are using the iterative procedures armax.th). and pem. All the relevant System Identification Toolbox functions have an optional variable MAXSIZE that controls the memory/speed trade-off and is set automatically. Instead they go into for-loops to handle the situation. it is logspace(log10(pi/abs(T)/100). based upon the best values for the machine you are using. but since many matrices may form. For discrete-time systems. Discrete-time default frequency ranges can be changed by sett.:). bj.log10(10*pi/abs(T)). for example th = armax(z(1:500. and th2ff to determine default frequency ranges. Theoretically. this default is [1:128]/ 128*pi/T and for continuous-time systems. so that the memory delimiter gives you a slower response. or edit idmsize. you can use the argument MAXSIZE.[na nb nc]. use a portion of the data to calculate a good initial condition for the minimization. Out of Memory If you run out of memory on computers with memory limitations.th).10. The routines do not allow any matrix of size larger than MAXSIZE to form. pack th = armax(z.0. oe.0).nn.T). clear unnecessary variables and use the pack function. g = sett(g.128).1). it best to set the default value for these machines to MAXSIZE = 4096. with values lower than the default. it is a good idea to use pack to clean up after the start-up estimation procedure using. for example th = armax(z.The sampling interval T is also used by etfe. like in g = spa(z). If you have a large amount of input-output data. th = armax(z. spa.

2. on the dimensions of the corresponding matrix. and e is the N × 1 vector of residuals.3 Tutorial On a small machine. Regularization The Gauss-Newton direction is usually defined as ′ –1 gn = ( Ψ*Ψ ) * Ψ′*e where Ψ is the N × n gradient matrix of the predictions with respect to the parameters. The typical situation is when an overdetermined set of linear equations is solved for the least-squares solution. Memory-Speed Trade-Offs On machines with no formal memory limitations. it is still of interest to monitor the sizes of the matrices that are formed. if you have collected more than 8188 data points so that you cannot form z=[y u]. For-loops give linear increase in time when the data record is increased. The solution time depends. You then have to build separate models for separate parts of the data and reconcile the models. no memory help is offered. you can add a small fraction of the identity matrix to it. while the number of columns corresponds to the number of estimated parameters. plus some overhead (and somewhat worse numerical properties). If you regularly work with large data sets and/or high order models. Note that this value is allowed to depend on the number of rows and columns of the matrices formed. The routines in the System Identification Toolbox compute the Gauss-Newton direction with g=psi\e 3-72 . it is advisable to tailor the memory and speed trade-off to your machine by choosing the default value of MAXSIZE in the M-file idmsize carefully. of course. When the inverted matrix is ill-conditioned. See Ljung (1987). Larger data sets and/or higher order models are handled by for-loops. The number of rows corresponds to the number of observed data. Section 10. The argument MAXSIZE used with all the relevant M-files. This is called regularization. guarantees that no matrix with more than MAXSIZE elements is formed.

and bj lead to theta values corresponding to a local minimum of the criterion function (3. Local Minima The iterative search procedures in pem. An advanced version of regularization is thus automatically included. to see if a smaller value of the loss function can be found.th2). and pem use a start-up procedure to produce initial values. oe. however.39). 3-73 .b] th2 = th3 = iv4(z. The start-up procedure goes through two to four least squares and instrumental variables steps. However. Because of the high precision of M ATLAB. Sometimes it may. you can use an iv4 estimate computed earlier as an initial condition for estimating an output-error model of the same structure: th1 = [a.b. Initial Parameter Values When only orders and delays are specified.which uses the MATLAB mechanism for dealing with underdetermined. regularization is not invoked easily.000001 and run the identification again. = th2poly(th1).1. poly2th(1. For example.1. overdetermined systems of equations. try starting the minimization at several different initial conditions. For example. oe(z. bj. A large value for the gn–vector suggests that you decrease the model orders. It is reasonably efficient in that it usually saves several iterations in the minimization phase. reasonably efficient in giving initial estimates that lead to the global minimum. however. you can decrease the value of the machine epsilon. if you are interested in how the regularization works. pay to use other initial conditions. oe. If there is an indication that a minimum is not as good as you expected.[na nb nk]). The start-up procedure for black-box models in these routines is. the functions armax. Nothing guarantees that this local minimum is also a global minimum. armax. You may see some very large norm of gn–vector values before you see the MATLAB message that the matrix is rank deficient. set eps = 0.a).

c). [a.[3 3 2 2]).c). b(3) = 0.b. Linear Regression Models A linear regression model is of the type y( t) = θ ϕ( t) + e(t ) T (11. for example. [a.c] = th2poly(th1). For example. The basic approach is to use physical insight to choose initial values of the parameters with physical significance. You can therefore handle arbitrary linear regression models with arx. Such models are very useful in most applications.2) where y ( t ) and ϕ ( t ) are measured variables and e ( t ) represents noise. Note that when constructing home-made initial conditions. th2 = poly2th(a.3 Tutorial Another example is when you want to try a model with one more delay (for example. and try some different (randomized) initial values for the others.[3 3 2 3]).c] = th2poly(th1). th2 = poly2th(a. three instead of two) because the leading b-coefficient is quite small: th1 = armax(z.th2).b. remember that poly2th strips away leading zeros. If you decrease the number of delays. th3 = armax(z. and that they should not contain any exact pole-zero cancellations.b. the inclusion of nonlinear effects in a simple way.th2). the conditions must correspond to a stable predictor (C and F being Hurwitz polynomials). For models parametrized in canonical state-space form.00001. They allow. if you want to build a model of the type 3-74 . use canstart to get started. Suppose you go from three to two delays in the above example: th1 = armax(z. b(3) = 0. you must provide the initial parameter values either when defining the structure in ms2th or mf2th.b. or with the special initialization function thinit. th3 = armax(z. For state-space and multi-output models. The System Identification Toolbox function arx allows an arbitrary number of inputs.

but all the model testing in terms of compare. This normalization means that the unit of Φ y ( ω ) is “power per radians/time unit” and that the frequency scale is “radians/time unit.[0 1 1 1 1 0 0 0 0]) 2 3 (11.2). Then pem also converges in one step.^3]. The search for a minimum of the criterion function is carried out by iterative search.3) This is formally a model with one output and four inputs.y ( t ) = b0 + b 1 u ( t ) + b2 u ( t ) + b 3 u ( t ) call z = [y ones(u) u u. The normalization in etfe is consistent with (11. If you insist on a quadratic criterion.5) 3-75 .^2 u.” You then have 2 1 Ey ( t ) = ----2π π⁄T –π ⁄ T ∫ Φ y ( w ) dw (11. Normally. use this robustified criterion. Note that when pem is applied to linear regression structures.4) ∑ y ( lT – kT )y ( lT ) l=1 N (See also (3.3)). and resid operate in the natural way for the model (11. th = arx(z. once the data matrix z is defined as above. idsim. by default a robustified quadratic criterion is used. then set the argument lim in pem to zero. Spectrum Normalization and the Sampling Interval In the function spa the spectrum estimate is normalized with the sampling interval T as Φy( ω) = T where ˆ 1 R y ( kT ) = --N ∑ k = –M M ˆ – iωT R y ( kT )e WM( k) (11.4).

PHIY] = getff(sp). The normalization with T in (11. % 4th order MA–process y = idsim(randn(2000. S2 = sum(y.[1 1 1 1]).6) which is consistent with (11. The spectrum normalization differs from the one used by spectrum in the Signal Processing Toolbox. Try the following sequence of commands: th0 = poly2th(1.^2)/length(y).T). g1 = spa(y).g2 = sett(g2. ffplot([g1 g3]) % No folding For a parametric noise (time series) model y ( t ) = H ( q )e ( t ) Ee ( t ) = λ 2 the spectrum is computed as Φy ( w ) = λ ⋅ T ⋅ H ( e iwt 2 ) (11. the spectral estimates coincide. the functions 3-76 .th0).5).1). When a parametric noise model is transformed between continuous time and discrete time and/or resampled at another sampling rate.4). you have S1 ≈ S2 where sp = spa(y). otherwise you see folding effects. The sum S1 is.4) also gives consistent results when time series are decimated.[]. Note that PHIY contains Φ y ( ω ) between ω = 0 and ω = π ⁄ T with a frequency step of π / T / (length(PHIY)).4). and the above example shows the nature of the difference. the rectangular approximation of the integral in (11.5).3 Tutorial In MATLAB language. % Prefilter applied g3 = sett(g3. ffplot([g1 g2]) % Folding effects g3 = spa(idresamp(y. Think of λT as the spectral density of the white noise source e ( t ) . sp = sett(sp. g2 = spa(y(1:4:2000)). S1 = sum(PHIY)/length(PHIY)/T.4) and (11. [om. therefore.4)). If the energy above the Nyquist frequency is removed before decimation (as is done in idresamp). therefore.

32)). and appropriate low-pass filtering is applied before sampling the measurements. computed (using pe) from the model with the data for which the model was estimated. instantaneous variance). remains constant. Warnings about this are issued by poly2th and these functions. This latter effect is well in line with the standard description that the underlying continuous-time model is subject to continuous-time white noise disturbances (which have infinite. For multi-output systems. i. Otherwise the underlying state-space model.. Continuous-time noise models must have a white noise component. Make the degree of the monic C-polynomial in continuous time equal to the sum of the degrees of the monic A. scale the noise source appropriately before applying idsim.and D-polynomials. If this effect is unwanted in a particular application. During these transformations the variance λ of the innovations e ( t ) is changed so that the spectral density T λ . 3-77 . which is formed and used in thc2thd and thd2thc. this is equal to the determinant of the estimated covariance matrix of the innovations. so that the noise spectrum is essentially invariant (up to the Nyquist frequency) with respect to resampling. Modify the C-polynomial accordingly. is ill-defined.thc2thd and thd2thc in the System Identification Toolbox use formulas that are formally correct only for piecewise constant inputs. Interpretation of the Loss Function The value of the quadratic loss function is given as element 1. and also displayed by present. • Simulations with noise using idsim has a higher noise level when performed at faster sampling. (See (3. For most models the estimated covariance matrix of the innovations is obtained by forming the corresponding sample mean of the prediction errors. in continuous time length(C)–1 = (length(A)–1)+(length(D)–1).e. Note the following cautions relating to these transformations of noise models. This approximation is good when T is small compared to the bandwidth of the noise. This has two effects: • The spectrum scalings are consistent.1 in the theta format.

… b 1 . f nfnu ] Here superscript refers to the input number. The loss function therefore differs from what would be obtained if you computed the prediction errors using the model directly from the data. in ms2th. b nb1. …f nf1. • For a state-space structure. say.2). the parameters in pars are obtained in the following order. Note that for ARX models computed using iv4. d n c. …b n b2. …. and so on for the C. armax. …. c nc. you have the following alphabetical ordering pars = [ a 1. …. (See ms2th in the Command Reference chapter. …. 1 1 nu nu nu nu 1 1 2 2 3-78 . The A matrix is first scanned row by row for free parameters. …. It is still the best available estimate of the innovations covariance. and also when online information from the minimization routines are given. Furthermore. since these are the values of the robustified loss function (see under lim in Section 5). bj. D. In these cases it is important to know in what order the parameter are listed. defined by ms2th. b 1. c 1. f 1. you are asked to give a list of nominal/initial parameter values. and X0 matrices. Be careful when comparing loss function values between different structures that use very different noise models. Then the B matrix is scanned row by row. Enumeration of Estimated Parameters In some cases the parameters of a model are given just as an ordered list.) • For a state-space matrix that is defined by mf2th. ….23) or its multi-input variant (5. b 1. The basic three cases are as follows: • For the input-output model (3. …. it is difficult to compare the loss function in an ARX model estimated using arx and one estimated using iv4.3 Tutorial Note the discrepancy between this value and the values shown during the minimization procedure (in pem. b n bnu. or oe. K. an ARX model. even though it displays a higher value of the loss function than. the covariance matrix of the innovations is estimated using the provisional noise model that is used to form the optimal instruments. This is the case for th2par. An Output-Error model may have a better input-output fit. the ordering of the parameters is the same as in the user-written M-file. f 1 . In particular. d 1. a na.

like th2ff. also work for complex-valued models. bj. arx. pem. The ordering of the parameters may. phase. We only point out two cautions: It is tempting in identification applications to call the residuals “eps. The transformation routines. th2zp. oe. which certainly will give you strange results. Note also that the parameter variance-covariance information then refers to the complex valued parameters.” Don’t do that. etc. and spa. The parameter ordering follows the one described above. etc. Use idsim and plot real and imaginary parts separately. This changes the machine ε . Note though that these variables take precedence over M-files with the same name so be sure you don’t use variable names that also are names of M-files. however. It is also natural to use names like step. not be transparent so it is better to use th2arx and arx2th instead of th2par and ms2th.. armax. covf. so no separate information about the accuracy of the real and imaginary parts will be given. Complex-Valued Data Some applications of system identification work with complex valued data. Some display functions like compare and idplot do not work for the complex case. for certain variables. Strange Results Strange results can of course be obtained in any number of ways. This is true for the estimation routines ar. 3-79 . but (currently) not for canstart and n4sid. but no pole-zero confidence regions are given.Multivariate ARX models are internally represented in state-space form. iv4. and thus create complex-valued models. Most of the routines in the SITB support complex data and models. ivar.

3 Tutorial 3-80 .

4 Command Reference .

Default values are also obtained by entering the arguments as the empty matrix [ ]. It begins with a list of functions grouped by subject area and continues with the entries in alphabetical order. The Graphical User Interface ident midprefs Open the interface. missing arguments are. The functions can be used with any number of arguments between these extremes. predict 4-2 . The Synopsis first lists the function with the necessary input arguments and then with all the possible input arguments. MATLAB does not require that you specify all of the output arguments. Create a model structure for input-output models defined as numerator and denominator polynomials. those not specified are not returned. Compute prediction errors. Compute predictions according to model. in order to save time. most functions have several default arguments. as defined in the manual. Information is also available through the online Help facility. not computed. The rule is that missing. Simulation and Prediction idinput idsim pe poly2th Generate input signals.4 Command Reference This chapter contains detailed descriptions of all of the functions in the System Identification Toolbox. Set directory where to store start-up information. trailing arguments are given default values. as a rule. For ease of use. Simulate a general linear system. By typing a function name without arguments. you also get immediate syntax help about its arguments. For functions with several output arguments in the System Identification Toolbox.

ivar ivx iv4 4-3 . Estimate ARMAX model.Data Manipulation dtrend idfilt idresamp Remove trends from data. Estimate impulse response and covariance functions using correlation analysis. Estimate Box-Jenkins model. Estimate ARX model using general instruments. Nonparametric Estimation covf cra Estimate covariance function. Estimate spectra and transfer functions using direct Fourier techniques. Estimate multivariate models in canonical state-space form. etfe spa Parameter Estimation ar armax arx bj canstart Estimate AR model. Estimate ARX model using four-stage instrumental variable method. Estimate ARX model using least squares. Estimate AR model using instrumental variable methods. Filter data. Resample data. Estimate spectra and transfer functions using spectral analysis.

Set the sampling interval. Model Structure Creation arx2th canform mf2th Define (multivariate) ARX structures. Create a model structure for input-output models defined as numerator and denominator polynomials. Transform a state-space model to a parametrized canonical form. thinit unfixpar 4-4 . Define state-space models with known and unknown parameters. Estimate state-space model using subspace method. Generate canonical forms. Allow certain earlier fixed parameters be estimated.4 Command Reference Parameter Estimation oe n4sid pem Estimate Output-Error model. Select or randomize initial parameter values. Create arbitrary linear model structure via an M-file that you write. modstruc ms2th poly2th Manipulating Model Structures fixpar sett ss2th Fix parameters in structures to given values. Estimate general linear model. Create model structure for linear state-space models with known and unknown parameters.

Theta to frequency functions and spectra. Display input-output data. poles. Plot zeros and poles. and static gains. Plot frequency functions and spectra.Model Conversions idmodred thc2thd thd2thc th2arx th2ff th2par th2poly th2ss th2tf th2zp Reduce a model to lower order. Theta to state-space matrices. Model Presentation bodeplot ffplot idplot nyqplot present zpplot Plot Bode diagrams. Theta to ARX parameters. 4-5 . Theta to transfer functions. Theta to zeros. Theta to transfer function polynomials. Transform from continuous to discrete time. Display model on screen. Transform from discrete to continuous time. Theta to estimated parameters and variances. Plot Nyquist diagrams.

th2zp 4-6 . poles. Compute zeros. and their standard deviations. Extract estimated parameters and variances from the theta format. Extract the M-file name that defines the model structure. Predict future outputs. Compute frequency function and its standard deviation. Extract the zeros and poles from the zepo format.4 Command Reference Information Extraction getff Extract the frequency functions from the freqfunc format. gett getmfth getncap getzp th2par Model Validation compare idsim pe predict resid Compare model’s simulated or predicted output with actual output. Assessing Model Uncertainty idsimsd th2ff Simulate responses from several possible models. Extract from the theta format the number of data upon which model is based. static gains. Compute prediction errors. Simulate a model. Compute and test model residuals. Extract the sampling interval from the theta format.

rpem rplr segment 4-7 .Model Structure Selection arxstruc Compute loss functions for sets of ARX model structure. Segment data and estimate models for each segment. ivstruc selstruc struc Recursive Parameter Estimation rarmax rarx rbj roe Estimate ARMAX or ARMA models recursively. Estimate Box-Jenkins models recursively. Estimate Output-Error models (IIR-filters) recursively. Estimate general input-output models using a recursive prediction error method. Generate sets of structures. Compute loss functions for sets of output error model structures. Estimate ARX or AR models recursively. Select structure. Estimate general input-output models using a recursive pseudo-linear regression method.

4 Command Reference 4-8 .

n.T) The parameters of the AR model structure A ( q )y ( t ) = e ( t ) are estimated using variants of the least-squares method. The sum of a least-squares criterion for a forward model and the analogous criterion for a time-reversed model is minimized. The lattice filter equations are solved. ar th = ar(y. Variable approach allows you to choose an algorithm from a group of several popular techniques for computing the least-squares AR model. Note that the routine is for scalar time series only. so that the (2. The standard sum of squared forward prediction errors is minimized. variable refl is returned containing the reflection coefficients in the first row. and the corresponding loss function values in the second. 'burg' and 'gl' (see below).n) [th. approach = 'ls': The least-squares approach.maxsize. formed from sample covariances. The first column is the zero-th order model. Available methods are as follows: approach = 'fb': The forward-backward approach.ar Purpose Syntax Description Estimate the parameters of an AR model for scalar time series.refl] = ar(y. For the two lattice-based approaches.1) element of refl is the norm of the time series itself.win. using the harmonic mean of forward and backward squared prediction errors. This is the default approach. For multivariate data use arx. The estimate is returned in th and stored in theta format.approach. approach = 'burg': Burg’s lattice-based method. Scalar n specifies the order of the model to be estimated (the number of A parameters in the AR model). The Yule-Walker equations. Column vector y contains the time series data. are solved. 4-9 . approach = 'yw': The Yule-Walker approach.

ar only handles scalar time series. There are a number of variants available: window = 'now': No windowing. Missing past data are replaced by zeros. (N being the number of observations. use arx. so that the summation can be extended to time N + n. . As in Burg’s method. for example. This is used in the Yule-Walker approach. The Yule-Walker approach. least-squares plus pre. except when approach = 'yw'. is a technique for dealing with the fact that information about past and future data is lacking. is also known as the correlation method.and post-windowing. For multivariate series. Windowing. within the context of AR modeling.and post-windowing. is often called the modified covariance method. See auxvar for an explanation of the input arguments maxsize and T. The computation of the covariance matrix can be suppressed in any of the above methods by ending the approach argument with 0 (zero). 'burg0'.ar approach = 'gl': A geometric lattice approach. Only actually measured data are used to form the regression vectors. This is the same method that is used in the arx routine. The summation in the criteria starts only at time n. The least-squares approach with no windowing is also known as the covariance method. window = 'prw': Pre-windowing. This is the default value. Missing end data are replaced by zeros. window = 'pow': Post-windowing. The M ATLAB default method. 4-10 . so that the summation in the criteria can be started at time zero. The combinations of approaches and windowing have a variety of names. but the geometric mean is used instead of the harmonic one. forward-backward with no windowing.) window = 'ppw': Pre.

spa. Prentice Hall. S. thfb = ar(y. theta Marple. etfe. Chapter 8. ivar. sfb = th2ff(thfb)..ar Examples Compare the spectral estimates of Burg’s method with those found from the forward-backward nonwindowed method. arx. Englewood Cliffs. bodeplot([sgb sfb]) See Also References auxvar. Digital Spectral Analysis with Applications.'burg').4). Jr. L.4. 4-11 . 1987.1).5*randn(300. sgb = th2ff(thb). given a sinusoid in noise signal: y = sin([1:300]') + 0. thb = ar(y.

lim. If z = y and nn = [na nc]. information about the progress of the iterative search for the model will be furnished to the MATLAB command window. iter_info] = armax(z. The optional auxiliary variables iter_info. 4-12 . Use state-space model for this case (see canstart.nn. See Section 3 in the Tutorial for an exact definition of the orders. together with estimated covariances. stored in theta format. maxiter.maxsize. and pem) If a last argument ‘trace’ is supplied. and T are explained under auxvar.maxiter.nn) th = armax(z. armax does not support multi-output models. tol. such that the k-th entry corresponds to the order and delay associated with the k-th input.’trace’) Description The parameters of the ARMAX model structure A ( q )y ( t ) = B ( q )u ( t – nk ) + C ( q )e ( t ) are estimated using a prediction error method. For multi-input systems. and nc are the orders of the ARMAX model. given in theta format.nn.lim. maxsize.’trace’) [th. nb and nk are row vectors.tol. and nk is the delay. armax calculates an ARMA model for y: A ( q )y ( t ) = C ( q )e ( t ) th is returned with the resulting parameter estimates.T. n4sid. In the latter case thi is an initial value.armax Purpose Syntax Estimate the parameters of an ARMAX or ARMA model. nb. nn can be given either as nn = [na nb nc nk] or as nn = thi In the former case na. armax th = armax(z. Matrix z contains the output-input data z = [y u] where y and u are column vectors (u is a matrix in the multi-input case).

its predictor stability is taken for granted (not tested). if not specified in nn. listing parameters in alphabetical order) as well as the values of the criterion function are given. oe.75) 4-13 .armax Algorithm A robustified quadratic prediction error criterion is minimized using an iterative Gauss-Newton algorithm. Current and previous parameter estimates (in column vector form. and the procedure is repeated. The Gauss-Newton vector is bisected up to 10 times until a lower value of the criterion is found. (10. The value returned in element th(1. Generally. theta Ljung (1987). The cut-off value for the robustification is based on the parameter lim as well as on the estimated standard deviation of the residuals from the initial parameter estimate. The number in the upper left corner is the number of times the search vector has been bisected. Note that if an initial parameter estimate is given in nn.46).41). (10. are constructed in a special four-stage LS-IV algorithm. pem. when the Gauss-Newton vector has a norm less than tol.. a gradient search direction is used instead. bj. The Gauss-Newton vector and its norm are also displayed. or when a lower value of the criterion cannot be found. The iterations are terminated when maxiter is reached. both C ( q ) and F i ( q ) (if applicable) must have all their zeros inside the unit circle. If no such value is found. It is not recalculated during the minimization. A stability test of the predictor is performed. auxvar. The initial conditions for the iterative search. quadratic criterion. equations (10. so as to assure that only models corresponding to stable predictors are tested. See Also References arx.42).1) is the nonrobustified. (10. Information about the minimization is furnished to the screen in case the argument ‘trace’ is specified.

maxsize. unu] and by allowing nb and nk to be row vectors defining the orders and delays associated with each input.T) The parameters of the ARX model structure A ( q )y ( t ) = B ( q )u ( t – nk ) + e ( t ) are estimated using the least-squares method. an AR model of order na for y is computed: A ( q )y ( t ) = e ( t ) Models with several inputs A ( q )y ( t ) = B 1 ( q )u 1 ( t – nk 1 ) + …B nu u nu ( t – nk n u ) + e ( t ) are handled by allowing u to contain each input as a column vector. See Section 6 in the Tutorial for exact definitions of the orders and delays. With z = y and nn = na. 4-14 ..arx Purpose Syntax Description Estimate the parameters of an ARX or AR model. The optional auxiliary parameters maxsize and T are explained under auxvar. Models with several inputs and several outputs are handled by allowing nn to contain one row for each output number.nn. Matrix z contains the output-input data z = [y u] where y and u are column vectors. arx th = arx(z. See “Defining Model Structures” on page 3-29 for exact definitions. nn is given as nn = [na nb nk] defining the orders and delay of the ARX model..nn) th = arx(z. u = [u1 . th is returned as the least-squares estimates of the parameters. stored in theta format.

It is then better to use armax. iv.1)].[2 2 1]). iv4. bj. iv4. the normal equations are formed in a for-loop and subsequently solved.th0). z = [y.randn(300. B = [0 1 0.7].arx When the true noise term e ( t ) in the ARX model structure is not white noise and na is nonzero.5 0. y = idsim([u. The regression matrix is formed so that only measured quantities are used (no fill-out with zeros). ar. th = arx(z. the estimate does not give a correct model. th0 = poly2th(A.u]. Algorithm The least-squares estimation problem is an overdetermined set of linear equations that is solved using the MATLAB \ operator. See Also auxvar.5]. Examples Here is an example that generates and estimates an ARX model: A = [1 –1.'rbs'). or oe. theta 4-15 . u = idinput(300. When the regression matrix is larger than maxsize.B).

however. so that the orders and delays are given just below the corresponding loss functions.nn).NN) v = arxstruc(ze.zv.zv. cross-validation. The last column of v contains the number of data points in ze. v is returned with the loss functions in its first row. The data sets. while for time series.NN. Each of ze and zv are matrices containing output-input data [y u]. u has the corresponding number of columns.:). The selection of a suitable model structure based on the information in v is best done using selstruc.:). For multi-input systems. Models for each of the model structures defined by NN are estimated using the data set ze. no u is present.z(201:400. nn = selstruc(V. They could.1). in which case the computation is faster. The remaining rows of v contain the transpose of NN. selstruc. be the same sets. ivstruc. th = arx(z. ze and zv.1:5. See Also arx. and the like. See auxvar for an explanation of maxsize.maxsize) NN is a matrix that defines a number of different structures of the ARX type. arxstruc v = arxstruc(ze. Each row of NN is of the form nn = [na nb nk] with the same interpretation as described for arx. and then select the order that gives the best fit to the validation data set: NN = struc(1:5.NN). Examples Compare first to fifth order models with one delay using cross-validation on the second half of the data set. See struc for easy generation of typical NN matrices for single-input systems. See Section 8 in the Tutorial for advice on model structure selection.0). The loss functions (normalized sum of squared prediction errors) are then computed for these models when applied to the validation data set zv. Note that arxstruc is intended for single-output systems only. struc 4-16 . V = arxstruc(z(1:200.arxstruc Purpose Syntax Description Compute loss functions for a set of different model structures of single-output ARX type. need not be of equal size.

).B..e. and trailing zeros in A and B are regarded as a definition of lower order polynomials. etc.. th2zp.. The arguments ny and nu denote the number of outputs and inputs. These 4-17 .nu. You can also use it to define initial value models that are further adjusted to data (using pem). respectively (ny is the number of outputs. The default value is the identity matrix.ny. multi-output model structure of ARX type: y ( t ) + A 1 y ( t – 1 ) + A 2 y ( t – 2 ) + … + A na y ( t – na ) = B 0 u ( t ) + B 1 u ( t – 1 ) + … + B nb u ( t – nb ) + e ( t ) Here A k and B k are matrices of dimensions ny by ny and ny by nu. See theta. “Defining Model Structures” on page 3-29. The arguments A and B are matrices that contain the A matrices and the B matrices of the model: A = [I A1 A2 .B. The optional argument lam sets the covariance matrix of the driving noise source e ( t ) in the model above. respectively. and that delays in the model are defined by setting the corresponding leading entries in B to zero.ny. Ana] B = [B0 B1 ... i. The use of arx2th is twofold. The free parameters in the structure are consistent with the structure of A and B. th is returned as a model structure in the theta format.T) arx2th creates a matrix containing parameters that describe the general multi-input. For a multivariate time series take B = []. Bnb] Note that A always starts with the identity matrix. i. arx2th th = arx2th(A.lam.nu) th = arx2th(A. The optional argument T defines the sampling interval (Default 1). the dimension of the vector y ( t ) and nu is the number of inputs). leading zeros in the rows of B are regarded as fixed delays.arx2th Purpose Syntax Description Construct theta format matrix from ARX polynomials. You can use it to create models that are simulated (using idsim) or analyzed (using th2ff..e.

1 0.2.1]]). arx2th is compatible with poly2th.B1 B2]. th = arx([y u].–1]. u = idinput(300).[1. while all other parameters are free.1).5 0. The free parameters can be changed by thinit and the structure can be manipulated by fixpar and unfixpar. B1 = [1. The internal representation is however different. and then estimate a model using the simulated data : A1 = [–1. A2 = [0. th0 = arx2th([eye(2) A1 A2].2 2].3. fixpar.7 –0.7]. The nominal values of these free parameters are set equal to the values in A and B. poly2th.0].1.1.2 1.[[0. y = idsim([u e].[2.[[2 2.0. See Also arx. unfixpar 4-18 . th2arx. B2 = [0.5. and only a model structure that has been defined by arx2th can be manipulated by fixpar and unfixpar. e = randn(300.th0).2). For a model with one output.–0.5].2].arx2th zeros are fixed. Examples Simulate a second order ARX model with one input and two outputs.2].

and lim. Instead. bj. and T. maxiter. it is maxsize=4096. lim: This variable determines how the criterion is modified from quadratic to one that gives linear weight to large errors. T: Specifying the sampling interval T gives correct frequency scales on frequency function plots. The main use of maxsize is to limit variable sizes when the algorithms run out of memory. The iterations also terminate when the algorithm fails to find a lower value of the criterion and when the maximum number of iterations are reached. The default value is tol=0. lim=0 disables the robustification and leads to a purely quadratic criterion. The default value of maxsize is set in the M-file idmsize. The default value is T=1. 4-19 .01.6. See “Parametric Model Estimation” on page 3-22 for a more precise definition. maxsize. Default values of these parameters are obtained either by omitting trailing arguments or by entering them as the empty matrix [ ].auxvar Purpose Syntax Description Describe auxiliary variables iter_info. tol. The default value of lim is 1. oe. maxsize: No matrix formed by the function is allowed to contain more than maxsize elements. maxiter: This variable determines the maximum number of iterations performed during a search for a minimum. and pem are controlled by the three parameters lim. On small machines. See “Some Special Topics” on page 3-68 for more information. Several of the functions allow the sampling interval T to be specified. and correct time scales when transforming to continuous time using thd2thc. lim. tol: The iterations are continued until the norm of the Gauss-Newton update vector is less than TOL. maxiter. which are slower. the algorithms split the calculations into for-loops. The default value is maxiter=10. maxiter=0 returns the results of the special startup procedure. auxvar help auxvar Most of the functions have an optional argument maxsize that allows a trade-off between memory usage and speed. The iterative search procedures in armax.

norm_of_last_search_vector] containing the indicated information. and the number of the last iteration is less than maxiter. and pem. pem 4-20 .auxvar iter_info: This output argument from the iterative numerical search algorithms armax. bj. If the norm of the last search vector is larger than tol. then the iterations were stopped since no smaller value of the criterion could be found along the search direction. bj. See Also armax. oe. oe. supplies information about the iterations. last_fit_improvement. It is a row vector iter_info = [last_iteration#.

and pem) 4-21 . nn can be given either as nn = [nb nc nd nf nk] or as nn = thi In the former case. In the multi-input case. and nk are row vectors with as many entries as there are input channels. nb. nd. stored in theta format.’trace’) [th. maxiter.nn. bj th = bj(z. tol. thi is an initial value.maxiter. Use state-space model for this case (see canstart. The optional variables iter_info.T. and nf are the orders of the Box-Jenkins model and nk is the delay.maxsize. Matrix z contains the output-input data z = [y u] where y and u are column vectors. nf. and T are explained under auxvar. maxsize. nc. For multi-input systems. bj does not support multi-output models.nn. nb. In the latter case.tol.e ( t ) F( q) D( q ) are estimated using a prediction error method. iter_info]= bj(z.lim. Entry number i then described the orders and delays associated with the i-th input.’trace’) Description The parameters of the Box-Jenkins model structure B( q) C(q ) y ( t ) = -----------u ( t – nk ) + ----------.bj Purpose Syntax Estimate the parameters of a Box-Jenkins model. lim. u is a matrix containing the different inputs as columns. th is returned with the resulting parameter estimates and estimated covariances. See“The System Identification Problem” on page 3-8 for exact definitions of the model orders. n4sid. given in theta format.nn) th = bj(z.

D = [1 1. armax. C = [1 –1 0. Examples Here is an example that generates data and stores the results of the startup procedure separately: B = [0 1 0.5 0.1).5]. information about the progress of the iterative search for the model will be furnished to the MATLAB command window.0).7]. z = [y u]. auxvar.2].B. thi = bj(z. u = idinput(200).7]. present(th) Algorithm See Also bj uses essentially the same algorithm as armax with modifications to the computation of prediction errors and gradients.[2 2 2 2 1].5 0. th = bj(z.C. th0 = poly2th(1.thi).1). y = idsim([u e]. e = randn(200. pem.D. theta 4-22 .F. oe. F = [1 –1.bj If a last argument ‘trace’ is supplied.0.th0).

the logarithm of the absolute value. getff. freqfunc. Description If the frequency functions are generated by th2ff or spa. The latter value can sometimes be negative. By default. To show amplitude plots only. which results in an error message from the plotting routine. these plots are always given separately. To obtain all plots on the same diagram use mode = 'same'. bodeplot bodeplot(g) bodeplot([g1 g2 .mode) g contains the frequency data to be graphed. On amplitude plots. plus and minus the standard deviation you indicate.bodeplot Purpose Syntax Plot frequency functions in Bode diagram form. The resulting plot is still meaningful.sd. use C = 'A'. phase plots are omitted. and sd is specified as a number larger than zero. is graphed. use C = 'P'. however. Pressing the Return key advances the plot from one input to the next. ffplot. See freqfunc for the format. amplitude and phase plots are shown simultaneously for each input (noise spectrum) present in g.. confidence intervals for the functions are added to the graph as dash-dotted curves (of the same color as the estimate curve). gn]) bodeplot(g. They indicate the confidence regions corresponding to sd standard deviations.C. Note that if g contains information about several outputs. but have to have the same number of values. nyqplot. th2ff 4-23 . The default is C = 'B' for both plots. See Also etfe. The frequency functions do not have to be specified at the same frequencies. For phase plots only. For spectra.. spa.

and the initial state x(0) of the state-space model given above.dkx) canform is. a function that defines model parameterizations in state-space form. Briefly. the A matrix contains p ∗ n parameters. dkx: The argument dkx determines some additional structure of the matrices of the state-space model to be estimated. It is a row vector with three entries: dkx = [d. like modstruc. 4-24 . x] The entries refer to the matrices K. which one is determined only when the structure is formed with ms2th. while the B matrix is filled with parameters. k. nu: The number of inputs. where p is the number of outputs and n is the number of states.and discrete-time cases.nu) ms = canform(orders. The C matrix contains only zeros and ones. The sum of the order indices is the order of the system (the dimension of x): n = sum(orders) The exact structure is defined in Appendix 4. canform ms = canform(orders. The only use of the resulting matrix ms is as an input to ms2th. D. The model considered is in state-space form: · x ( t ) = A ( θ )x ( t ) + B ( θ )u ( t ) + K ( θ )e ( t ) y ( t ) = C ( θ )x ( t ) + D ( θ )u ( t ) + e ( t ) The function applies both to the continuous. orders is a row vector with as many entries as there are outputs. orders: The (pseudo-observability) indices orders define which matrix elements are fixed (to zero or one) and which are left free as parameters.canform Purpose Syntax Description Define multivariable state-space canonical form model structures. Element k of orders describes how many delayed values of the output are required to appropriately predict the k-th component of the output.A of Ljung (1987).nu. which are used in ms2th to create model structures in the theta format.

A. Examples Write out the state-space matrices for a sixth order system with three outputs and two inputs with NaN denoting free parameters: ps = [2 1 3]. 0] An alternative to canform is the function canstart. This also implies that there will be a delay of (at least) one sample between the input and the output. x = 1 indicates that the initial state x(0) will be parameterized. ms2th.K] = th2ss(th) See Also References canstart. th = ms2th(ms.ones(1.18+12+18)∗NaN). while k = 0 means that this matrix will be fixed to zero. Default is dkx = [0. ms = canform(ps. 1. fixpar. modstruc. This will give a so-called output error model. unfixpar Ljung (1987).D.canform k = 1 indicates that the K-matrix in the model (the Kalman Gain) will be fully parameterized. It also provides good initial estimates for the free parameters. Appendix 4.C. d = 1 indicates that D-matrix in the model (the direct term from input to output) will be fully parametrized.'c'.2). while d = 0 means that this matrix will be fixed to zero. while x = 0 means that the initial state will be fixed to zero. [A. 4-25 .B.

pem 4-26 . Then a default choice of parameterization is made.canstart Purpose Syntax Description Define and initialize state-space canonical form model structures. In the present case orders can also be taken as a scalar. Algorithm Examples The state-space model is first estimated using n4sid. resid(z.3. The model th could be further refined by using pem.dkx: These arguments define the state-space model parameterization exactly as for the function canform. The values of the parameters in th are estimated from the data matrix z = [y u] where y is the matrix of output signals. th = pem(z.nu. again one column for each input. It defines a state-space model parameterization according to the arguments orders.2). nu and dkx. and then transformed to the chosen canonical form using ss2th.nu) th = canstart(z.th). and u is the matrix of input signals.nu. one column for each output.dkx) orders. See Also canform. The output th is a matrix in the theta format. canstart th = canstart(z.th).orders. Choosing the order indices for many systems is not critical in the sense that most n-th order systems can be described by any set of order (pseudo-observability) indices whose sum is n. See “Model Structure Selection and Validation” on page 3-49 for more information. giving the model order (dimension of state vector). A system with two inputs and two outputs is estimated with a third order model: th = canstart(z.orders.

leveladj) z is the output-input data in the usual format z = [y u] where y is a matrix whose r-th column is the r-th output signal and correspondingly for the input u. predict 4-27 . If the optional argument leveladj is set to 'yes'.k. which obtains a pure simulation from the input only. Pressing the Return key advances the plots.th). The argument k computes the k-step ahead prediction of y according to the model th instead of the simulated output.[2 3 1 0]).:).) This allows for discounting of drift phenomena in the data. The whole data record is used for the simulation/prediction.th. Use the first one for estimating a model and the second one to check the model’s ability to predict six steps ahead: ze = z(1:250.compare Purpose Syntax Description Compare measured outputs with model outputs. For multi-output systems this is done separately for each output. th = armax(ze. Examples Split the data record into two parts. compare(zv. (This applies also to the calculation of the fit. The result is plotted (yellow/ solid) together with the corresponding measured output y (magenta/dashed). the simulated/predicted output and the measured output are level adjusted so that they both start at level zero. See Also idsim. the model can use outputs up to time t – k : y ( s ). The argument sampnr indicates that only the sample numbers in this row vector are plotted and used for the calculation of the fit. s = t – k .fit] = compare(z. though. The default value of k is inf. t – k – 1 . compare computes the output yh that results when the model th is simulated with the input u. The mean square fit fit = norm(yh – y)/sqrt(length(y)) is also computed and displayed.th. [yh.sampnr.:). compare compare(z. In the calculation of yh ( t ). zv = z(251:500.6). … (and inputs up to the current time t).

straightforward summing is used.∑ z i ( t )z j ( t + k ) N t=1 where z j is the j-th column of z and missing values in the sum are replaced by zero. Algorithm See Also When nz is at most two. k +1) = R ij ( k ) = --. which also explains how complex data are handled.nz.maxsize) z is an N by nz matrix and M is the maximum delay -1 for which the covariance function is estimated. and when permitted by maxsize. The expectation symbol E corresponds to the sample means.nz) = E z(t)∗z'(t+k) Here ' is complex conjugate transpose. spa 4-28 .M. The optional argument maxsize controls the memory size as explained under auxvar. Otherwise.k+1). The easiest way to describe and unpack the result is to use reshape(R(:.covf Purpose Syntax Description Estimate time series covariance functions. a fast Fourier transform technique is applied. covf R = covf(z. R is returned as an nz2 x M matrix with entries 1 ˆ R(i + ( j − 1)nz.M) R = covf(z.

) The output argument R contains the covariance/correlation information as follows: The first column of R contains the lag indices.. The second column contains the covariance function of the (possibly filtered) output. significant correlation for negative lags is an indication of feedback from y to u in the data. apply cra to two signals at a time. Description The output-input data are given as z = [y u] with y as the output column vector and u as the input column vector.plot). cra cra(z). i. Positive values of the lag variable then corresponds to an influence from u to later values of y. The plots can be redisplayed by cra(R). filters u through a filter chosen so that the result is as uncorrelated (white) as possible. The output y is subjected to the same filter. In other words. The impulse response is computed from 0 to M. These are from – M to M.R. and then the covariance functions of the filtered y and u are computed and graphed.na. The third column contains the covariance function of the (possibly prewhitened) input.) cra prewhitens the input sequence.e.cl] = cra(z. The cross correlation function between (prewhitened) input and output is also computed and graphed.cra Purpose Syntax Perform correlation analysis and estimate impulse response. The optional argument M defines the number of lags for which the covariance/ correlation functions are computed. so that the length of R is 2M+1.M. and the fourth column contains the correlation function. A properly scaled version of this correlation function is also an estimate of the system’s impulse response ir. This is also graphed along with 99% confidence levels. so that its first entry corresponds to lag zero. The output argument ir is this impulse response estimate. (Negative lags are excluded in ir. [ir. 4-29 . cra(R). The routine only handles single-input-single-output data pairs. The output argument cl is the 99% confidence level for the impulse response estimate. (For the multivariate case. The default value of M is 20.

plot: plot = 0 gives no plots. subplot(211) plot([ir irth]) title('impulse responses') subplot(212) plot([cumsum(ir). With na = 0 the covariance and correlation functions of the original data sequences are obtained. plot = 2 gives a plot of all the covariance functions. spa 4-30 .cumsum(irth)]) title('step responses') See Also covf.[2 2 1]). the input is fitted to an AR model of order na. plot = 1 (default) gives a plot of the estimated impulse response together with a 99% confidence region.th). Examples Compare a second order ARX model’s impulse response with the one obtained by correlation analysis: ir = cra(z). The third argument of cra can change this order from its default value na = 10. irth = idsim(imp.1)].cra For the prewhitening. th = arx(z.zeros(19. imp = [1.

1).o.e.1. dtrend zd = dtrend(z) zd = dtrend(z.dtrend Purpose Syntax Description Remove trends from output-input data. With o = 1. With brkp not specified.119). The default (o = 0) removes the zero-th order trends. Note that dtrend differs somewhat from detrend in the Signal Processing Toolbox. zd(:. linear trends are removed. one single line is subtracted from the entire data record. and remove the sample mean from the input: zd(:. 4-31 .2) = dtrend(z(:.2)).brkp) z is a matrix.1) = dtrend(z(:. i.. the sample means are subtracted. A continuous piecewise linear trend is subtracted if brkp contains breakpoints at sample numbers given in a row vector. dtrend removes the trend from each column and returns the result in zd. Examples Remove a V-shaped trend from the output with its peak at sample number 119. after a least-squares fit. with data organized in column vectors.

This can be a useful alternative to spa for narrowband spectra and systems. The routine works only for single-input.M. Then g is returned as the periodogram of y. etfe g = etfe(z) g = etfe(z. gs = spa(z).etfe Purpose Syntax Description Estimate empirical transfer functions and periodograms. with the estimate of iω G ( e ) at the frequencies w = [1:N]/N∗pi/T The default values of N and T are 128 and 1. single-output systems. which otherwise require large values of M. N must be a power of two. the corresponding spectral estimate is normalized in the way that is defined in “Some Special Topics” on page 3-68. Examples Compare an empirical transfer function estimate to a smoothed spectral estimate: ge = etfe(z). Note that this normalization may differ from the one used by spectrum in the Signal Processing Toolbox. using fft. where y and u are column vectors. g is given in frequency function format (see freqfunc). The effect of M is then similar to the effect of M in spa. respectively. bodeplot([ge gs]) Algorithm The empirical transfer function estimate is computed as the ratio of the output Fourier transform to the input Fourier transform. When M is specified other than the default value M = [ ]. a smoothing operation is performed on the raw spectral estimates. The periodogram 4-32 .T) etfe estimates the transfer function g of the general linear model y ( t ) = G ( q )u ( t ) + v ( t ) The matrix z contains the output-input data z = [y u]. When etfe is applied to time series. z = y. For a time series.N.

respectively. See Also freqfunc. spa 4-33 . The length of this Hamming window is equal to the number of data points in z divided by M.etfe is computed as the normalized absolute square of the Fourier transform of the time series. and subsequently forming the ratio of the results. and to the absolute square of the input FFT. The smoothed versions (M less than the length of z) are obtained by applying a Hamming window to the output FFT times the conjugate of the input FFT. plus one.

getff 4-34 . bodeplot.. freqfunc.C.mode) Description See Also This function has exactly the same syntax as bodeplot.ffplot Purpose Syntax Plot frequency functions and spectra. The only difference is that it gives graphs with linear frequency scales and Hz as the frequency unit. ffplot ffplot(g) ffplot([g1 g2 . gn]) ffplot(g..sd.

For example. 'B1'. The default is that the elements are fixed to their nominal (initial or currently estimated) value.fixpar Purpose Syntax Description Fix parameters in structures defined by ms2th and arx2th.5]). arx2th. 'C'.. The matrix tho must be originally defined by arx.. 'A2'.. to fix the 1. fixpar thn = fixpar(tho. and all the indicated elements will be fixed to that number. In this case parval can be given a scalar number. The argument elements is a matrix with two columns. where each row gives 4-35 .parval) The fixpar function produces a new model structure thn in the theta format from an old one tho.. The argument elements is then a matrix with two columns.[1. The r-th entry of this vector contains the value corresponding to the element defined by the r-th row of elements. thinit. or ms2th but may have been modified later on by fixpar. 'D'.. iv4. . in which each row specifies the indices of the element in the chosen system matrix that need to be fixed.'K'. If the argument elements is omitted (or entered as the empty matrix) all elements of the indicated matrix will be fixed. or unfixpar. canstart.elements. To modify an ARX model y ( t ) + A 1 y ( t – 1 ) + A 2 y ( t – 2 ) + … + A na y ( t – na ) = B 0 u ( t ) + B 1 u ( t – 1 ) + … + B nb u ( t – nb ) + e ( t ) the argument matrix is set equal to one of 'A1'. To modify a state-space structure · x ( t ) = A ( θ )x ( t ) + B ( θ )u ( t ) + K ( θ )e ( t ) y ( t ) = C ( θ )x ( t ) + D ( θ )u ( t ) + e ( t ) the argument matrix is set equal to one of 'A'. pem. To fix them to something else use the fourth input argument parval.matrix) thn = fixpar(tho..2. 'B0'. or 'x0'.2-element and the 3.'A'. .matrix. by fixing certain parameters to certain values.3.5-element of the A matrix use thn = fixpar(tho. 'B'.

'B2'.th).fixpar the indices of the element in the chosen ARX matrix that need to be fixed. Fixing certain parameters can. The routine does not apply to special model structures that you have originally defined using mf2th.'K'. unfixpar 4-36 . thinit. or to black-box input-output models other than ARX models. The role of parval is the same as for the state-space case above.[]. th = pem(z. be achieved by using the third argument in pem during the estimation phase. and then estimating the remaining parameters: th = arx(z.[1. thn = fixpar(thn.1).1]. th = fixpar(th.[2 3 0]). Examples Converting a state-space structure with all elements in the Kalman gain matrix K free to an output error structure in which K is fixed to zero. in those cases.0) Fixing the b 2 parameter to 1 in a scalar ARX model. See Also theta.

and phases. The basic way to display the information is to use the plot commands. describe the significance of the column in question. n = k + 100: The column contains the frequency values for input number k. where k is value between 1 and 19: The column contains amplitude values for the transfer function associated with input number k. This entry gives details of the internal representation. that. as well as their standard deviations. n = 100: The column contains frequencies for the spectrum. n = k + 70: The column contains phase standard deviations for input number k.freqfunc Purpose Syntax Description Describe the frequency-function format. freqfunc help freqfunc Frequency functions are created by etfe. n = k. and nyqplot. The interpretation of these integers is as follows: For transfer functions and spectra associated with output number 1: n = 0 : The column is a spectrum. n = 50: The column contains standard deviations of a spectrum. in coded form. You can also retrieve the information from the format by the function getff. These are all given as columns. amplitudes. and used by bodeplot. n = k + 20: The column contains phase values (in degrees) for input number k. n = k + 50: The column contains amplitude standard deviations for input number k. The internal format of the freqfunc format is intended to be transparent. add ( ky – 1 ) ∗1000 to the numbers above. 4-37 . The first row of a freqfunc matrix contains integers. For the same quantities associated with output number ky . and th2ff. ffplot. The freqfunc format contains information about frequency values. spa. but this information is not necessary for normal use of the System Identification Toolbox.

w) g = th2ff(th. Examples You can compute and graph the frequency functions at arbitrary frequency w (a row vector with an arbitrary number of elements) with g = spa(z. etfe. nyqplot. See Also bodeplot. up to a decade over the underlying Nyquist frequency (see th2ff). sett. the frequencies are 128 values.w) The MATLAB function logspace is useful for creating such frequency vectors. logarithmically spread over three decades.ku.M. spa. which is by default. For a continuous-time model.freqfunc The specified frequencies are for a discrete-time model. ffplot. Here T is the sampling interval (default = 1). th2ff 4-38 . equally spaced from 0 (excluded) to π ⁄ T over 128 values. getff.

w is a vector containing the frequency values (in radians/second). The noise source is counted as input number 0. Results in the freqfunc format are obtained by etfe. plot(w. In that case getff extracts information about the spectrum corresponding to output number ky. The output arguments sdamp and sdphas contain the corresponding standard deviations.ku.amp. Examples Make your own plot of the periodogram with linear scales: per = etfe(y).amp] = getff(per).phas] = getff(g) [w.amp) title('Periodogram of seismic data') 4-39 . sdamp. ffplot. The default values of ku and ky are both 1. If several entries in g correspond to the same input-output pair. ku is the chosen input number (only one) and ky is the chosen output number. All this information is for input number ku and output number ky.amp. [w. and nyqplot.sdamp. then w. getff [w. so that ku = 0 will extract spectral information. and th2ff.ky) This function extracts information from the freqfunc format for plotting as an alternative to bodeplot. spa. and sdphas have the corresponding number of columns. unless g contains only spectra.sdphas] = getff(g. The argument g is the frequency function or spectrum given in the freqfunc format.phas. amp contains the values of the magnitude (amplitude) of the frequency function and phas contains the phase values (in degrees).getff Purpose Syntax Description Retrieve frequency functions and spectra from the freqfunc format. phas. amp.

Note that for the noise dynamics. To extract this information enter [ze.ku. zepo normally just contains information about the zeros and poles from noise source k to output number k.ky) The basic use of getzp is to extract the poles and zeros of the coded format that th2zp results in. (no cross terms). getzp [ze.po] = getzp(zepo) [ze.getzp Purpose Syntax Description Extract zeros and poles from the zepo format.0. zpplot 4-40 .po] = getzp(zepo. The noise source number k is here counted as input number –k. The default values of ku and ky are both 1. ze contains the zeros and po the poles of the dynamics associated with input number ku and output number ky. ku contains the input number (just one) and ky the output number. zpform. zepo contains this information and is typically the output of th2zp.k) See Also th2zp.po] = getzp(zepo.

gett mymfile = getmfth(th) N = getncap(th) T = gett(th) Description These functions retrieve some information that is coded into the theta format. gett Purpose Syntax Extract information from the theta format. getncap. If the model is not estimated N is returned as []. See Also mf2th. from which a certain model th is estimated. mymfile is the name of the M-file that you write to define a model structure created by mf2th. getncap. the model is a continuous-time one that has been estimated from data with the sampling interval abs(T). If T is negative. N is the number of data. getmfth. T is the sampling interval of the model th.getmfth. sett 4-41 .

If the session file is on the MATLABPATH.ident Purpose Syntax Description Open the graphical user interface ident ident ident(session. Examples ident(‘iddata1. see Chapter 2 of this manual. directory can be omitted. or brings it forward if it is already open.directory) on the MATLAB command line.directory) ident by itself opens the main interface window. Typing ident(session. For more information about the graphical user interface.’\matlab\data\cdplayer\’) 4-42 . session is the name of a previous session with the graphical interface. the interface will open with this session active.sid’.sid.sid’) ident(‘mydata. will load and open the session in question. When the session is specified. when the interface is active. and typically has extension . directory is the complete path for the location of this file.

Also. Chapter 13. a causal filter (of order abs(ord)) is used instead.ord. If ord is a negative integer. If hs =' high' a high pass filter with this cutoff frequency is obtained instead. The output argument thf is the filter given in the theta format.hs) idfilt computes a Butterworth filter of order ord and filters all columns of the data matrix z = [y u] through this filter. Often this corresponds to bandpass filtering with a pass band over the interesting breakpoints in a Bode diagram. a non-causal.ord. Ljung (1987). If hs = 'stop' a bandstop filter with stop band between these two frequencies is obtained instead. idfilt zf = idfilt(z. a filter (of order 2*ord) with passband between Wnl and Wnh is obtained is hs is not specified. It is common practice in identification to select a frequency band where the fit between model and data is concentrated. If ord is a positive integer. Algorithm References The used filter is the same as butter in the Signal Processing Toolbox would give.Wn.thf] = idfilt(z. If Wn = [Wnl Wnh] is a vector with two elements. zero-phase filter is used for the filtering. a low pass filter with cutoff frequency Wn (measured as a fraction of the Nyquist frequency) is obtained. If hs is not specified and Wn contains just one element.idfilt Purpose Syntax Description Filter data using Butterworth filters. the zero-phase filter is equivalent to filtfilt in that toolbox. 4-43 .Wn) [zf.

. The frequencies wlow and whigh are expressed in fractions of the Nyquist frequency. corresponding to twologp = 18. whigh] that determine the lower and upper bound of the pass-band.band. • type = 'rbs': This gives a random. the length of u.e. The frequency contents of the signal is determined by the argument band.levels. which also is the default value. binary signal. binary signal. type defines the type of input signal to be generated. Also in this case the default is band = [0 1].auxvar) idinput generates input signals of different kinds. this argument is a row-vector with two entries band = [wlow.idinput Purpose Syntax Generate signals. • type = 'sine': This gives a signal which is a sum of sinusoids. This argument takes one Description of the following values: • type = 'rs' : This gives a random.levels) u = idinput(N. typically to be used as inputs for identification. • type = 'prbs': This gives a pseudo-random. and M is such that the signal is constant over intervals of length 1/M. that are typically used for identification purposes. i.'sine'. For the choice type = 'prbs' we have band = [twologp. Gaussian signal.band. and 'sine'. 4-44 . N is the number of data points generated. M] where the periodicity of the generated PRBS is 2^twologp –1. For the choices type = 'rs'. Default is type = 'rbs'. twologp = 0 gives the maximum length PRBS. 'rbs'. Only scalar inputs are generated. idinput u = idinput(N) u = idinput(N.type. A white noise character input is thus obtained for band = [0 1].

The frequency contents is achieved for 'rs' by an eighth order Butterworth. while maxu is the mean value plus one standard deviation. before making the signal binary. A number of trials are made.idinput The argument levels defines the input level. Default is auxvar = [10. The variable no_of_trials determines how many trials to be made to minimize the signal amplitude by assigning random phases to the different sinusoids. and the phases that give the smallest signal amplitude are selected. no_of_trials] determining the number of sinusoids to be used in the input signal. This is quite reliable. and each sinusoid is given a random phase. For the 'sine' case. 1].. Chapter C5. the frequencies are selected to be equally spread over the chosen pass band.) See Also Reference The Frequency Domain System Identification Toolbox contains several commands for input design that utilize more sophisticated algorithms. Algorithm Very simple algorithms are used. non-causal filter. For PRBS. the signal level is such that minu is the mean value of the signal.3. Gaussian white noise with zero mean and variance one is thus obtained for levels = [–1. This means that the frequency contents is not guaranteed to be precise in this case. For type = 'rs'. It is a row vector levels = [minu. (The amplitude is then scaled so as to satisfy the specifications of levels. e. there is a fourth argument auxvar = [no_of_sinusoids. which is also the default value. 'prbs' and 'sine'. Söderström and Stoica (1989). For the option type = 'sine'. The same filter is used for the 'rbs' case. 4-45 . see. using idfilt. maxu] such that the signal u will always be between the values minu and maxu for the choices type = 'rbs'. minus one standard deviation. 10].g.

OE: If the argument OE has the value ’oe’. then an output error model THRED is produced. You will then be prompted to select an order based on this plot. The idea is that such a small element will have a negligible influence on the input-output behavior of the model. in case ORDER = []. It is thus suggested that an order is chosen. also the noise model is reduced.3). which is the default. that is.ones(3. Otherwise (default). reduce its order to 3 and compare the frequency responses of the original and reduced models: TH = arx([y u]. This reduced model is always represented internally in state-space form with no free parameters. one with the Kalman gain equal to zero (see (3.or discrete-time model and perform the reduction accordingly. The resulting reduced order model THRED is also in the theta format.[4∗ones(3. bodeplot([trf(TH). ORDER: The desired order (dimension of the state-space representation).4∗ones(3. regardless of the nature of the model TH. idmodred THRED = idmodred(TH) THRED = idmodred(TH.OE) This function reduces the order of any model TH given in the theta format.27) and (3.ORDER.3). a plot will show how the diagonal elements of the observability and controllability Gramians decay with the order of the representation.2).trf(THRED)]) Examples 4-46 . "Tutorial"). THRED = idmodred(TH. The plot.2)]).idmodred Purpose Syntax Description Reduce the order of a model in theta format. Build a high order multivariable ARX model. The function requires several routines in the Control Systems Toolbox. such that only large elements in these matrices are retained. The resulting model THRED will be of the same kind in this respect as TH. The function will recognize whether TH is a continuous.31) in Chapter 3. Algorithm The functions (d)balreal and (d)modred from the Control Systems Toolbox are used. shows the vector g as returned from (d)balreal. If ORDER = [].

idmodred Use the reduced order model as initial condition for a third order state-space model: THI = ss2th(THRED). THSS = pem([y u]. See Also ss2th 4-47 .THI).

int. one by one if several. If you prefer linear interpolation between input data points. idplot idplot(z) idplot(z. The data points specified in the row vector int are graphed.pc) z is the output-input data z = [y u] to be graphed. The default value is pc = 'pc'. The argument ny is the number of outputs in the data matrix.100:200) 4-48 . You can use the sampling interval T (default T = 1) to give correct time axes. and it is graphed accordingly.idplot Purpose Syntax Description Plot input-output data.T. Examples Plot only a portion of the data points: idplot(z. at the bottom. Default is ny = 1. use pc = 'li'.ny. The default value of int is all the data. The input is piecewise constant between sampling points. A split plot is obtained with the output on top and the inputs. Pressing the Return key advances the plot.

not mishandled.1. but it will be replaced by a rational approximation (R_act).” due to the prefiltering effects.den] = rat(R.R) [zr. the resampled waveform may look “very different. R_act : The actually achieved resampling factor.u. Any positive real number for R is allowed. The interpolation and decimation are preceded by prefiltering. The new data record will correspond to a new sampling interval of R times the original one. Default is 8. plot(t. R : The resampling factor.5 and compare the signals. filter_order: The order of the presampling filters used before interpolation and decimation.R. however.1. The columns of zr correspond to those of z. The data are then interpolated by a factor den and then decimated by a factor num.ur) Caution Example 4-49 .filter_order. Resample by a factor 1. Default is 0. For signals that have much energy around the Nyquist frequency (like piece-wise constant inputs). idresamp zr = idresamp(z. Algorithm The resampling factor is first approximated by a rational number by [num. R_act] = idresamp(z. R > 1 thus corresponds to decimation and R < 1 corresponds to interpolation.tol).idresamp Purpose Syntax Description Resample data by interpolation and decimation. The frequency and information contents for identification is. zr : The resampled data.tol) z : The data to be resampled.ra∗t. and follow the same algorithms as in the routines interp and decimate in the Signal Processing Toolbox.ra] = idresamp(u. Each column of z contains a signal.5).u) [ur. plot(t. tol : The tolerance in the rational approximation of R.

idsim returns y containing the simulated output. Validate a model by comparing a measured output y with one simulated using an estimated model th: yh = idsim(u. The noise-sequence e is scaled by λ . a noise-free simulation is obtained. corresponding to the input sequence u (one column for each input) and the noise e. If e is omitted. The noise is again scaled using the noise covariance matrix in th. where λ is the noise variance (loss function) as specified by th. y = idsim([u e].th) th describes an arbitrary model in the theta format. For multi-output systems simulated with noise. If th is a continuous-time model.th). idsim y = idsim([u e].1). To achieve the correct noise effect. plot([y yh]) Algorithm See Also In case the model is of input-output type.th) [y. idsimsd. For state-space models.th0). See “Some Special Topics” on page 3-68 Examples Simulate a given system th0 (for example created by poly2th): e = randn(500. it uses ltitr. u = idinput(500. The second output argument is the standard deviation of the simulated output. e should have as many columns as the numbers of outputs. ysd] = idsim(u. poly2th 4-50 .’prbs’).idsim Purpose Syntax Description Simulate systems specified in theta format. give e zero mean and unit variance. it is first converted to discrete time with sampling interval abs(T). This option is however not available for state-space models. idsim uses the MATLAB filter function.

The responses of each of these models to the input u are computed and graphed in the same diagram.1)]. noise is added to the simulation.noise) u is a column vector (matrix) containing the input(s). according to the covariance information given in th. and its own uncertainty.idsimsd Purpose Syntax Description Simulate theta format system with uncertainty.1). th2ff. in accordance with the noise model of th. The default values are N = 10 noise = 'nonoise' Examples Plot the step response of the model th and evaluate how it varies in view of the model’s uncertainty: step1 = [zeros(5. idsimsd(step1. If noise = 'noise'. th2zp 4-51 .th) idsimsd(u.th) See Also idsim.N. N random models are created. idsimsd idsimsd(u.th. th is a model given in the theta format (see theta). ones(20.

possibly time varying.na. Optimal Instrumental variable estimates of the AR-parameters of an ARMA process. 4-52 .. entered as a column vector. P. na is the order of the A polynomial (the number of A parameters)..maxsize. v ( t ) is an arbitrary process. Autom.4). etfe. in theta format.nc. bodeplot([giv gls]) See Also References ar. pp. et al.5). In the above model. 1066-1074. y is the signal to be modeled. delayed nc steps.2) + sin([1:500]'∗1. gls = th2ff(thls). 1985. giv = th2ff(thiv).na) th = ivar(y.ivar Purpose Syntax Description Estimate the parameters of an AR model using an approximately optimal choice of instrumental variable procedure. thls = ar(y.) Instruments are chosen as appropriately filtered outputs. ivar th = ivar(y. The optional arguments maxsize and T are explained under auxvar. Control. + 0. The resulting estimate is returned as th.T) The parameters of an AR model structure A ( q )y ( t ) = v ( t ) are estimated using the instrumental variable method.4). The routine is for scalar signals only. spa Stoica. IEEE Trans. Vol AC-30. estimated by the IV method and estimated by the forward-backward least-squares method: y = sin([1:500]'∗1. assumed to be a moving average process of order nc. Examples Compare spectra for sinusoids in noise.2∗randn(500.1).. (Default is nc = na. thiv = ivar(y.

see auxvar. The rows below the first row in v are the transpose of NN. The estimated models are simulated using the inputs from data set zv. If p is equal to zero. and the last row contains the logarithms of the condition numbers of the IV matrix ∑ ς ( t )ϕ T (t ) A large condition number indicates that the structure is of unnecessarily high order (see page 415 in Ljung (1987)). The normalized quadratic fit between the simulated output and the measured output in zv is formed and returned in v.zv. The information in v is best analyzed using selstruc.NN. See struc for easy generation of typical NN matrices for single-input systems. Each row of NN is of the form nn = [na nb nk] with the same interpretation as described for arx. u has the corresponding number of columns. ivstruc v = ivstruc(ze.NN) v = ivstruc(ze. 4-53 .ivstruc Purpose Syntax Description Compute fit between simulated and measured output for a group of model structures. For multi-input systems.zv. Each of ze and zv are matrices containing output-input data [y u]. The output-error fit calculated in v may then be misleading. the computation of condition numbers is suppressed.p. For the use of maxsize. IMPORTANT: The IV method used does not guarantee that the obtained models are stable.maxsize) NN is a matrix that defines a number of different structures of the ARX type. The routine is for single-output systems only. Models for each model structure defined in NN are estimated using the instrumental variable (IV) method on data set ze.

1:2.ivstruc Examples Compare the effect of different orders and delays. The models are subsequently obtained by operating on submatrices in the corresponding large IV matrix.nn).z. selstruc. arxstruc. nn = selstruc(v) th = iv4(z. iv4.2:4)). struc See Also 4-54 . using the same data set for both the estimation and validation: v = ivstruc(z. Algorithm A maximum order ARX model is computed using the least-squares method. Instruments are generated by filtering the input(s) through this model.struc(1:3.

The main interest in ivx lies in its use for nonstandard situations. the first column(s) of z. Note that there is also an IV version that automatically generates instruments from certain filters you define (type help iv).ivx Purpose Syntax Description Estimate the parameters of an ARX model using the instrumental variable (IV) method with arbitrary instruments. except that y is replaced by x. for example when there is feedback present in the data. The instruments used are then analogous to the regression vector itself. or when other instruments need to be tried out. ivar Ljung (1987). See Also References iv4.nn. ivx th = ivx(z. Note that ivx does not return any estimated covariance matrix for th.. Use iv4 as the basic IV routine for ARX model structures. Make this the same size as the output. except that you can use arbitrary instruments. These are contained in the matrix x.maxsize.x) th = ivx(z. i. page 198.x. 4-55 .nn.T) ivx is a routine analogous to the iv4 routine. since that requires additional information.e.

equations (15. For the multi-output case. The resulting model generates the instruments for a second-stage IV estimate.nn. nk = [0 2]. Examples Here is an example of a two-input one-output system with different delays on the inputs u 1 and u 2 : z = [y u1 u2].iv4 Purpose Syntax Description Estimate the parameters of an ARX model using an approximately optimal four-stage instrumental variable (IV) procedure.[2 nb nk]). 4-56 . th = iv4(z.maxsize.26).T) This routine is an alternative to arx and the use of the arguments are entirely analogous to the arx function. the input-output data are filtered through this AR model and then subjected to the IV function with the same instrument-filters as in the second stage. At the fourth stage. Algorithm The first stage uses the arx function.nn) th = iv4(z. The main difference is that the procedure is not sensitive to the color of the noise term e ( t ) in the model equation. nb = [2 2]. iv4 th = iv4(z. The residuals obtained from this model are modeled as a high-order AR model. oe Ljung (1987).21)-(15. optimal instruments are obtained only if the noise sources at the different outputs have the same color. consult “Some Special Topics” on page 3-68. The estimates obtained with the routine are reasonably accurate though even in other cases. See Also References arx. For an interpretation of the loss function (innovations covariance matrix).

and x0 are the matrices in the discrete-time model description that correspond to this value of the parameters. The model structure corresponds to the general linear state-space structure x ( t + T ) = A ( θ )x ( t ) + B ( θ )u ( t ) + K ( θ )e ( t ) x (0 ) = x0 ( θ ) y ( t ) = C ( θ )x ( t ) + D ( θ )u ( t ) + e ( t ) The matrices in this time-discrete model can be parameterized in an arbitrary way by the vector θ . This is a row vector of the same length as the number of free parameters in the model structure.aux) Here the row vector pars contains the parameters θ . 4-57 . or the value 'd'. The argument parval contains the nominal values of the parameters. model is the name of an M-file that defines how the state-space matrices depend on the parameters to be estimated.x0] = mymfile(pars. The argument aux is a matrix of auxiliary variables that the M-file can use for various purposes.T) th is returned as a model structure in the theta format. Write the format for the M-file as follows: [A.lambda. D. indicating that the model parameterization is inherently a discrete-time one.T.K. C. and the output arguments A.parval. B.cd. The argument cd must be assigned either the value 'c' which designates that the underlying parameterization refers to a continuous-time model.D. K. The format of this M-file is given below.parval) th = mf2th(model. Give T a positive value even if the underlying model is defined to be continuous time.B. for which the model is going to be estimated (and the sampling interval that is used when the model is used for simulation and prediction).aux. mf2th th = mf2th(model. T denotes the sampling interval of the data.C.mf2th Purpose Syntax Description Package model structures you define into the theta model format.cd.

it is desirable that if the M-file myfile is called with a negative value of T.[0. If the underlying parameterization is a continuous-time one.3. Examples Use the M-file 'mynoise' given in Section 6 to obtain a physical parametrization of the Kalman gain: thn = mf2th('mynoise'.mf2th T is the sampling interval. use cd = 'c'.–2. it outputs the matrices of the corresponding continuous-time state-space model. even if they are not utilized within the M-file.'d'.0.1) th = pem(z.2]. If such a feature is included in the M-file. corresponding to the sampling interval T that should be delivered by the M-file.thn) 4-58 .1. and aux is any matrix of auxiliary variables with which you want to work. it is still the discrete-time model matrices. (In that way you can change certain constants and other aspects in the model structure without having to edit the M-file.) Note that the two arguments T and aux must be included in the function head of the M-file. However.1. “Defining Model Structures” on page 3-29 contains several examples of typical M-files that define model structures. This allows for easy transformations between continuous and discrete time using the normal functions thc2thd and thd2thc.

and names and directories of the four most recent sessions with ident. do not just move it using the file system.m file. Always use midprefs to change the directory for idprefs. which should be placed on the user’s MATLABPATH. midprefs midprefs midprefs(path) The graphical user interface ident allows a large number of variables for customized choices. midprefs is used to select or change the directory where you store idprefs. Therefore. which also needs to be updated. the default choices of plot options. 4-59 .mat.mat. automatic location for this file is in the same directory as the user’s startup.midprefs Purpose Syntax Description Select a directory for idprefs. and follow the instructions.mat contains a variable with the directory name. Include all directory delimiters as in the PC case midprefs('c:\matlab\toolbox\local\') or in the UNIX case midprefs('/home/ljung/matlab/') Warning The file idprefs. The default. or give the directory name as the argument. This information is stored in the file idprefs. These include the window layout.mat. a file that stores the graphical user interface’s start-up information. Either type midprefs.mat.

D. Examples Define a continuous-time model structure in diagonal form with the two (real) poles and the numerator unknown: A = [NaN.C.C. thinit. a function that defines model parameterizations in state-space form. while the symbol NaN marks an element that is not known and you need to estimate. modstruc ms = modstruc(A.B.1]. K. D = 0. ms = modstruc(A. B = [NaN.D.B. C. Numerical values in these matrices indicate fixed (known) entries.B. The model considered is in state-space form: · x ( t ) = A ( θ )x ( t ) + B ( θ )u ( t ) + K ( θ )e ( t ) x (0 ) = x0 ( θ ) y ( t ) = C ( θ )x ( t ) + D ( θ )u ( t ) + e ( t ) The function applies both to the continuous and discrete-time cases. The input arguments A. but it may also contain parameters you need to estimate.NaN].K. The only use of the resulting matrix ms is as an input to ms2th.0].D.0. See Also canform. and x0 are the matrices of the above state-space model. The default value of the initial state vector x0 is the zero vector. unfixpar 4-60 . ms2th.NaN]. which are used in ms2th to create model structures in the theta format.'c'). C = [1. fixpar. K = [0.K) ms = modstruc(A.C. D. B.modstruc Purpose Syntax Description Define state-space structure with unknown elements.x0) modstruc is. like canform. which one is determined only when the structure is formed with ms2th.K) th = ms2th(ms.0.

again row by row. The argument ms defines which parameters are fixed and which ones you need to estimate. D. They are also used whenever the model th is simulated or analyzed. The order in which the free parameters are found by this scanning defines the ordering in parval. Use cd = 'cfoh' if the input has been a continuous function during the data acquisition. 4-61 . These nominal values are used as initial estimates when the parameters in th are identified with pem. The default value of parval is all zeros. the input is supposed to be piecewise linear between the samples. cd = 'd' is the default. Use cd = ‘czoh’ (which is the default for continuous-time models) if the system has been controlled using a piece-wise constant input. The matrix A is first scanned. zero order hold) the input is assumed to be piecewise constant over the sampling interval. K. then the matrix B is scanned.parval. for free parameters. and X0 each of them row by row. For a continuous-time model there are two options for how to sample it. and then C. The argument cd indicates whether the state-space matrices in ms refer to a continuous-time model (cd = 'c') or a discrete-time model (cd = 'd'). and analyzing models. as it is fitted to observed sample data (in pem): By selecting cd = ‘czoh’ (continuous. first order hold). The numbering of the parameters in parval (as well as in all other contexts in which the model parameters are listed) is as follows.cd. row by row.lambda.ms2th Purpose Syntax Description Package standard state-space parameterizations into the theta model format. This means that the continuous-time input u(t) is obtained by linear interpolation between the sampled values. It is typically formed by modstruc or canform. By selecting cd = ‘cfoh’ (continuous. ms2th th = ms2th(ms) th = ms2th(ms.T) The function returns th as a model structure in the theta format for further use in estimating. The row vector parval contains the nominal values of the free parameters (those that correspond to NaN in ms). simulating.

NaN].NaN].0]).1].2 – 0. thinit. th = pem(z.4]).[–0. T denotes the sampling interval of the data. th = ms2th(ms. unfixpar 4-62 . The default value of lambda is the unit matrix. pem. Examples Define a continuous-time model structure corresponding to θ θ1 0 · x = x+ 3 u 0 θ2 θ4 y = 1 1 x+e with initial values θ = – 0.2. See Also canform.0. Give T a positive value even if the underlying model is defined to be continuous time.C.th). The argument lambda gives the covariance matrix of the innovation e ( t ) for the sampling interval indicated in T. modstruc.'c'. for which the model is going to be estimated (and the sampling interval that is used when the model is used for simulation and prediction). fixpar. C = [1.3 2 4 and estimate the free parameters: A = [NaN.–0.0.ms2th Note that setting all initial estimates equal to zero is not a good starting point for the iterative search for parameter estimates in pem. since this case often corresponds to a nonobservable/noncontrollable model.B.[0.2.3. B = [NaN.0. ms = modstruc(A. It is better to give more realistic values of parval or to randomize them using thinit.

the command thd2thc uses numerical differentiation when translating the covariance information for any model structure. Finally. The output argument nds is a row vector whose k-th entry gives the increment to be used when differentiating with respect the k-th element of the parameter vector pars. The step size used in these numerical derivatives is determined by the M-file nuderst. 4-63 . nuderst nds = nuderst(pars) The function pem uses numerical differentiation with respect to the model parameters when applied to state-space structures. The default version of nuderst uses a very simple method. for example 0. Note that the nominal value. The step size is the maximum of 10 – 7 and 10 – 4 times the absolute value of the current parameter.nuderst Purpose Syntax Description Select the step size for numerical differentiation. You can adjust this to the actual value of the corresponding parameter by editing nuderst. The same is true for the functions th2ff and th2zp when the parameter covariance information is translated to frequency function and zero-pole accuracy (again only for state-space structures). of a parameter may not reflect its normal size.

Several plots are obtained in the same diagram by simply listing the different frequency functions after each other.) Examples See Also g = th2ff(thmod) nyplot(g. gn]) nyqplot(g. or etfe.. given in the freqfunc format. th2ff 4-64 . Pressing the Return key advances from one pair to the next. It is computed by plotting the two curves g ± sd ∆g . ffplot. spa. nyqplot nyqplot(g) nyqplot([g1 g2 . spa. With mode = 'same' all plots corresponding to the same input are given in the same diagram.. The Nyquist diagram of a frequency function is a graph of its imaginary part against its real part. typically as the output of th2ff. (The information in g does not contain the correlation between the magnitude and phase estimates.sd.mode) nyqplot is an alternative to bodeplot and ffplot to graph frequency functions Description in the freqfunq format.nyqplot Purpose Syntax Plot Nyquist curve of frequency function. If the frequency function(s) contains information about several different input-output pairs. etfe.3) bodeplot. The argument g is the frequency function in question. a confidence region around the nominal Nyquist plot is marked with dash-dotted lines. where ∆g is the standard deviation (magnitude and phase) of g. freqfunc. the default is that the Nyquist plot for each pair is graphed separately. These need not be specified at the same frequencies (although they have to be of the same length). The confidence region is therefore only approximate. If sd is given a value larger than 0. This region corresponds to sd standard deviations.

among the orders 1:10.AO] = n4sid(z. If order is entered as a row vector (like order = [1:10].maxsize. The choice of auxord could have a substantial influence on the model quality.ny. You will be prompted to select the order. z: A matrix that contains the output-input data: z = [y u]. including the time series case (no input). a model of “best” (default choice) order is computed. It handles an arbitrary number of input and outputs. In the multi-variable case. If the last given 4-65 .auxord. In the time series case z = y. models for all these values will be computed.dkx. AO: See under auxord below. This can be seen as a prediction horizon. The idea is to choose an order such that the singular values for higher orders are comparatively small. The default value is auxord = 1. This value is returned as the output argument AO. n4sid TH = n4sid(z) [TH. The prediction error for each of the models are computed using the data z. based on this plot. If order = 'best'. Default is ny = 1.n4sid Purpose Syntax Description Estimate state-space models using a subspace method. and returns them in the theta format.'trace') The function n4sid estimates models in state-space form. and it should be larger than the order.2∗order+3. auxord: An “auxiliary order” used by the algorithm.order. the singular values of the Hankel matrices of the impulse response for different orders are graphed. u and y contain one column for each output and input. No covariance information about the uncertainty of the model is contained in TH. order: The desired order of the state-space model. A plot will then be given that shows the relative importance of the dimension of the state vector. ny: The number of outputs in the data set z. which is the default choice). where y and u are column vectors. and that value of auxord that minimizes the fit will be selected. More precisely. The state-space model is in the innovations form: x(t+1) = A x(t) + B u(t) + K e(t) y(t) = C x(t) + D u(t) + e(t) TH: The resulting model in theta format. preliminary calculations for all the indicated orders are carried out. If you enter auxord as a row vector (like auxord = [5:15]).T. and there are no simple rules for how to choose it.

gives information to the command line about the choice of auxiliary order. and may not be relevant when the model is evaluated on a new set of data. only if order is a given value (no vector). while k = 0 means that this matrix will be fixed to zero. 1. The algorithm is complemented with a separate linear least-squares step to re-estimate the matrices B. It is a row vector with three entries: dkx = [d. 30. pp. Default is dkx = [0. dkx: The argument dkx determines some additional structure of the matrices of the state-space model to be estimated. Vol. while x = 0 means that the initial state will be taken as zero. No 1. x = 1 indicates that the initial state x(0) will be estimated and stored in the model TH. 75-93. D. Automatica. De Moor: N4SID:Subspace algorithms for the identication of combined deteministic-stochastic systems. x] The entries refer to the matrices K. Note that auxord can be chosen as a vector. 0] The optional variables maxsize and T are explained under AUXVAR. which enter linearly. This also implies that there will be a delay of (at least) one sample between the input and the output. d = 1 indicates that D-matrix in the model (the direct term from input to output) will be estimated. and X(0). This will give a so called output error model. while d = 0 means that this matrix is fixed to zero. k. Note that the initial state is something that relates to the particular data set for which the model was estimated. in case this is given as a vector. information about the different choices of auxord will be given to the screen. 1994. 4-66 . trace: Letting the last input argument be 'trace'. Algorithm The function implements the methods described in P. Van Overschee and B. D. and the initial state X(0) of the state-space model given above.n4sid argument to n4sid is 'trace'. k = 1 indicates that the K-matrix in the model (the Kalman Gain) will be estimated.

thp = pem(z.n4sid Examples Build a fifth order model from data with three inputs and two outputs. bodeplot(trf(th)) Use the resulting model as initial values for estimating a state-space model of the same order using the prediction error method: thi = ss2th(th). theta 4-67 . canstart.2.’trace’). Try several choices of auxiliary orders. (Note that there will be no confidence intervals!) z = [y1 y2 u1 u2 u3].7:15. pem. See Also auxvar. Look at the frequency response of the model.thi).5. th = n4sid(z.

’trace’) [th. and T are explained under auxvar.nn. and nf are the orders of the Output-Error model and nk is the delay. and pem) If a last argument 'trace' is supplied. nb. th is returned with the resulting parameter estimates and estimated covariances. nn can be given either as nn = [nb nf nk] or as nn = thi In the former case.tol. maxiter. Matrix z contains the output-input data z = [y u] where y and u are column vectors. lim.lim. The optional variables iter_info. this is an initial value for the estimate. See “The System Identification Problem” on page 3-8 for an exact definition of the orders and delay.oe Purpose Syntax Estimate the parameters of an Output-Error model.'trace') Description The parameters of the Output-Error model structure B( q) y ( t ) = ----------. In the latter case. n4sid. For multi-input models. oe th = oe(z. 4-68 . tol.nn. nb. given in theta format. such that entry number i gives the orders and delays associated with the i-th input. information about the progress of the iterative search for the model will be furnished to the MATLAB command window. oe does not support multi-output models.maxsize. nf.u ( t – nk ) + e ( t ) F( q) are estimated using a prediction error method. maxsize. stored in theta format. iter_info] = oe(z. Use state-space model for this case (see canstart.T.nn) th = oe(z. and nk are row vectors.maxiter.

pem. auxvar. bj. armax. theta 4-69 .oe Algorithm See Also oe uses essentially the same algorithm as armax with modifications to the computation of prediction errors and gradients.

theta 4-70 . pe e = pe(z. z = [y u]. e ( t ) = H ( q ) [ y ( t ) – G ( q )u ( t ) ] –1 See Also resid.pe Purpose Syntax Description Compute the prediction errors associated with a model and a data set.th) Matrix z is the output-input data set. e is returned containing the prediction errors that result when model th is applied to the data. and th is a model specified in theta format.

. For multi-input systems.T.u nu ( t – nk nu ) + ----------. nn is given either as nn = [na nb nc nd nf nk] or as nn = thi In the former case. and nf are the orders of the model and nk is the delay(s). Multivariable ARX structures defined by arx2th are also covered. mf2th.maxiter. ms2th. The matrix z contains the output-input data z = [y u]. and nk are row vectors giving the orders and delays of each input.index.'trace') [th. The others remain fixed to their nominal values.'trace') Description The function pem handles all model structures.pem Purpose Syntax Estimate the parameters of general linear models. nc. nb. nf. thi defines a model structure and an initial value for the estimate. iter_info] = pem(z. thinit.. including the general multi-input-single-output structure B nu ( q ) B1( q ) C(q ) A ( q )y ( t ) = ------------.lim. where y and u are column vectors (in the multi-variable case u and y contain one column for each input and output). na. nd. The default 4-71 . and unfixpar. given in theta format. pem th = pem(z. The optional argument index is a row vector that contains the indices of the parameters that are to be estimated..nn) th = pem(z. In the latter case. (See Section 3 of the Tutorial for exact definitions of the orders).nn.tol.nn. maxsize. th is returned with the resulting parameter estimates and estimated covariances. nb. The ordering of the parameters is defined under th2par. stored in theta format.u 1 ( t – nk 1 ) + … + ---------------.e ( t ) D( q ) F1( q ) F nu ( q ) and general structures defined by fixpar.

The optional variables iter_info. thc = canstart(z. and Box-Jenkins type.3) th = pem(z. bj. oe. auxvar. information about the progress of the iterative search for the model will be furnished to the MATLAB command window. ARMAX. theta 4-72 . If a last argument ‘trace’ is supplied. Examples Here is an example of a system with three inputs and two outputs. z = [y1 y2 u1 u2 u3]. and T are explained under auxvar.thc). Algorithm See Also pem uses essentially the same algorithm as armax with modifications to the computation of prediction errors and gradients. armax. For the special cases of single-input models of Output-Error. A canonical form state-space model of order 5 is sought. it is more efficient to use oe. armax.5.pem value of index is that all free parameters are estimated. and bj. tol. maxiter. lim. maxsize.

B and F are entered as empty matrices: B = []. C. See “Defining Model Structures” on page 3-29. C. B and F are matrices with one row for each input. B. lam is the variance of the white noise sequence e ( t ) . The continuous-time model must have a white noise component in its noise description.e ( t ) D( q ) F1( q ) F nu ( q ) A.. while B contains leading zeros to indicate the delays. See “Some Special Topics” on page 3-68.poly2th Purpose Syntax Description Construct theta format matrix for input-output models. For multi-input systems. and so on. D. A negative value of T indicates that the model is a continuous-time one. (A sampled version of the model has the innovations variance lam/T. 3 2 4-73 . ana] A. where T is the sampling interval. For time series.u nu ( t – nk nu ) + ----------. D.F.C. For continuous-time systems lam indicates the level of the spectral density of the innovations. Then the interpretation of the arguments is that A = [1 2 3 4] corresponds to the polynomial s + 2s + 3s + 4 in the Laplace variable s.B. and F all start with 1.T) poly2th creates a matrix containing parameters that describe the general multi-input-single-output model structure: B1( q ) B nu ( q ) C(q ) A ( q )y ( t ) = ------------.lam. and F specify the polynomial coefficients.. For single-input systems.B) th = poly2th(A.u 1 ( t – nk 1 ) + ---------------.D. these are all row vectors in the standard M ATLAB format: A = [1 a1 a2 . F = []. poly2th th = poly2th(A. while T is the sampling interval.

1) y=idsim([u1 u2].F.1 2 4] th=poly2th(1. It also strips leading zeros from the B polynomial to determine the delays. (If B=[].thd). F=[1 1 0. then F is taken as [].0.1 3].7].1 and then simulate it without noise: B=[0 1.5 0. [0 1 0. See Also idsim. lam.) For discrete-time models (T>0).B. Create the continuous-time model y(t ) = s+ 3 1 u1 (t) + 2 u (t) + e(t ) s + 2s + 4 2 s(s + 1) Sample it with T=0.5]. = poly2th(A.1. Keep this in mind when you use poly2th and th2poly to modify earlier estimates to serve as initial conditions for estimating new structures. F. [1 –1 0.–1) thd=thc2thd(th. See “Some Special Topics” on page 3-68. D.B.poly2th Trailing arguments C.1. theta 4-74 . note the following: poly2th strips any trailing zeros from the polynomials when determining the orders. and T can be omitted. Examples To create a system of ARMAX type (the “Åström system”): A = B = C = th0 [1 –1. in which case they are taken as 1.2].1. This gives a system with one delay (nk = 1).C).

th) [yp.predict Purpose Syntax Description Predict the output k-step ahead. The default value of k is 1. since the low frequency behavior is emphasized. ny being the number of outputs and nu the number of inputs to th. s = t – k . since. (The predictor is a system with ny + nu inputs and ny outputs. and its i.j element contains the predicted value of the corresponding element in y. there is no difference between the k-step ahead predictions and the simulated output. The output argument thpred contains the k-step ahead predictor in the theta format. Note that for output-error models.k) z is the output-input data in the usual format z = [y u] where y is a matrix whose r-th column is the r-th output signal and correspondingly for the input u. predict p = predict(z. output-error models only use past inputs to predict future outputs. … and inputs up to the current time t.thpred] = predict(z. The trivial predictor ˆ y ( t ) = y ( t – 1 ) can give good predictions in case the sampling of the data is fast. by definition. t – k – 1. The natural way of studying a time series model’s ability to reproduce observations is to compare its k-step ahead predictions with actual data. Simulation with idsim (which conceptually corresponds to k = inf) can lead to levels that drift apart. 4-75 . One step ahead prediction is not a powerful test of the model’s properties.) An important use of predict is to evaluate a model’s properties in the mid-frequency range. Another important use of predict is to evaluate models of time series. in the case that th corresponds to an input-output model.th. since the high frequency behavior is stressed. The output yp is a matrix of the same size as y. The argument k indicates that the k-step ahead prediction of y according to the model th (in the theta format) is computed. In the calculation of yp(t) the model can use outputs up to time t – k : y ( s ).

th = armax(y(1:200). idsim. See Also compare.201:400). estimate a model based on the first half of the data. the formula (3. pe 4-76 .1).4).yp(201:400)]) Examples Note that the last two commands also are achieved by compare(y. y = idsim(randn(400.th. For state-space models. plot([y(201:400). the state ˆ equations are simulated k-steps ahead with initial value x ( t – k ) = x ( t – k ) .th0).[1 –1 0.4.th. Simulate a time series. and evaluate the four step ahead predictions on the second half: th0 = poly2th([1 –0.[1 2]).99].31) in Ljung (1987) is applied to compute the predictor. yp = predict(y.2]).predict Algorithm For a model th that is an input-output model. ˆ where x ( t – k ) is the Kalman filter state estimate.[].

imaginary parts of the parameter estimates. the standard deviations are given as fake. For input-output models. and Akaike’s Final Prediction Error Criterion (FPE) (which essentially equals the AIC). loss function.) For state-space models and multivariable ARX models.present Purpose Syntax Description Display the information in a theta matrix. the delay is nk if B starts with nk exact zeros. the estimated standard deviations are given just below the estimated parameters. therefore. (Note that leading zeros and ones are exact and have zero standard deviation. together with their standard deviations. Leading zeros in B correspond to delays. It also displays information about how th was created. present present(th) This function displays the polynomials of the model th. See Also theta 4-77 .

nn is given as nn = [na nb nc nk] where na.. The estimated parameters are returned in the matrix thm.yhat.. See equations (3. and nc are the orders of the ARMAX model.16). rarmax thm = rarmax(z.adm.adg) [thm.18) in Chapter 3.P.(3.P0.. Matrix z contains the output-input data z = [y u] where y and u are column vectors..ana.a2... 4-78 . according to the current model.psi] = . nb. row k of yhat contains the predicted value of z(k. The k-th row of thm contains the parameters associated with time k. yhat is the predicted value of the output.b1.cnc] See equations (3. If z = y and nn = [na nc]. single-output models are handled by rarmax. "Tutorial" for more information.. Use rpem for the multi-input case.1) based on all past data.18) in Chapter 3.phi0..nn..c1. rarmax(z.e.adm.. i..bnb.nn..th0. rarmax estimates the parameters of an ARMA model for y: A ( q )y ( t ) = C ( q )e ( t ) Only single-input.. they are based on the data in the rows up to and including row k in z..:) = [a1. Each row of thm contains the estimated parameters in the following order: thm(k.rarmax Purpose Syntax Estimate recursively the parameters of an ARMAX or ARMA model.e.phi. "Tutorial" for an exact definition of the orders.. i..16)-(3.psi0) Description The parameters of the ARMAX model structure A ( q )y ( t ) = B ( q )u ( t – nk ) + C ( q )e ( t ) are estimated using a recursive prediction error method.adg. and nk is the delay.

rarmax The actual algorithm is selected with the two arguments adm and adg. Compute and plot. Algorithm The general recursive prediction error algorithm (11. (11. plot(thm) Examples 4-79 . consistent with the rows of thm. See “Recursive Parameter Estimation” on page 3-61 for more information.) The default values of phi0 and psi0 are all zeros.0. of the scaled covariance matrix of the parameters. The default value of th0 is all zeros. shift the input sequence appropriately and use nk=1. respectively. See rarx. The default value of P0 is 104 times the unit matrix. and psi contain initial and final values of the data vector and the gradient vector. The arguments P0 and P are the initial and final values. Note that the function requires that the delay nk be larger than 0. a row vector. the four parameters in a second order ARMA model of a time series given in the vector y. The normal choice of phi0 and psi0 is to use the outputs from a previous call to rarmax with the same model orders. The input argument th0 contains the initial value of the parameters. These are described under rarx. respectively. phi. (This call could of course be a dummy call with default input arguments. The sizes of these depend in a rather complicated way on the chosen model orders.47)-(11. thm = rarmax(y.98).98 is applied. psi0. as functions of time. If you want nk=0.49) of Ljung (1987) is implemented.'ff'.44).[2 2]. The forgetting factor algorithm with a forgetting factor of 0. The arguments phi0.

yhat. The estimated parameters are returned in the matrix thm.nn. nn is given as nn = [na nb nk] where na and nb are the orders of the ARX model.. If z = y and nn = na. rarx thm = rarx(z.adg. Only single-output models are handled by rarx.th0.P.phi] = rarx(z.e. See equation (3.adm. rarx estimates the parameters of an AR model for y: A ( q )y ( t ) = e ( t ) Models with several inputs A ( q )y ( t ) = B 1 ( q )u 1 ( t – nk 1 ) + …B nu u nu ( t – nk nu ) + e ( t ) are handled by allowing u to contain each input as a column vector..nn. and nk is the delay.adg) [thm.phi0) The parameters of the ARX model structure A ( q )y ( t ) = B ( q )u ( t – nk ) + e ( t ) are estimated using different variants of the recursive least-squares method. unu] and by allowing nb and nk to be row vectors defining the orders and delays associated with each input.. Matrix z contains the output-input data z = [y u] where y and u are column vectors.rarx Purpose Syntax Description Estimate recursively the parameters of an ARX or AR model. i.16) in the Tutorial for an exact definition of the orders. u = [u1 .P0. they are based on the data 4-80 . The k-th row of thm contains the parameters associated with time k.adm.

The actual algorithm is selected with the two arguments adg and adm. Similarly adm ='ng' and adg = gam gives the normalized gradient or Normalized Least Mean Squares.. This is what is often referred to as Recursive Least Squares.e... all the b parameters associated with input number 1 are given first.. RLS..6abc)+(10. With adm ='kf' and adg = R1 the Kalman Filter Based algorithm (10.) The default value of th0 is all zeros. 4-81 . LMS.. If the variance of the innovations e(t) is not unity but R 2 . In the case of a multi-input model. This algorithm is commonly known as unnormalized Least Mean Squares.9) is obtained with gain gamma= gam..rarx in the rows up to and including row k in z. a row vector.bnb] See equation (3.4). yhat is the predicted value of the output. and so on.1) based on all past data.a2. then R 2 ∗ P is the covariance matrix of the parameter estimates. respectively.:) = [a1. (See above.16) in Chapter 3. row k of yhat contains the predicted value of z(k.6abc) + (10. according to the current model. consistent with the rows of thm. The input argument th0 contains the initial value of the parameters. Each row of thm contains the estimated parameters in the following order: thm(k.6) is obtained with R2= 1 and R1 = R1. With adm ='ug' and adg = gam the unnormalized gradient algorithm (10. The options are as follows: With adm ='ff' and adg = lam the forgetting factor algorithm (10. and then all the b parameters associated with input number 2.b1. NLMS algorithm (10..3)).10). In these cases P is not defined or applicable.ana. while R 1 =R1 / R 2 is the covariance matrix of the parameter changes in (10. The arguments P0 and P are the initial and final values. of the scaled covariance matrix of the parameters. The default value of P0 is 104 times the identity matrix. i. In this case the matrix P (see below) has the following interpretation: R 2 /2 ∗ P is approximately equal to the covariance matrix of the estimated parameters.. "Tutorial". These are described in “Recursive Parameter Estimation” on page 3-61.6abd)+(10.8) is obtained with forgetting factor λ = lam. Here R 2 is the variance of the innovations (the true prediction errors e(t) in (10.

of the data vector: ϕ ( t ) = [ y ( t – 1 ). If you want nk=0.[0 6 1]. shift the input sequence appropriately and use nk=1. …. Examples Adaptive noise canceling: The signal y contains a component that has its origin in a known signal r. if z = [y(1).rarx The arguments phi0 and phi contain initial and final values. Note that the function requires that the delay nk be larger than 0. …u ( t – nb – nk + 1 ) ] Then. and P. %noise is the adaptive estimate of the noise %component of y plot(y–noise) 4-82 . y ( t – na ). respectively. . The default value of phi0 is all zeros.u(N)] you have phi0 = ϕ ( 1 ) and phi = ϕ ( N ) . Remove this component by estimating.'ng'. thm (last row).y(N). th0. the system that relates r to y using a sixth order FIR model together with the NLMS algorithm: z = [y r]. recursively. u ( t – 1 ). [thm. and P0 as the previous outputs phi. For online use of rarx.. .0. use phi0.noise] = rarx(z.1)..u(1).

th.0.P.P.rarx If the above application is a true online one. proceed as follows: phi = zeros(6.0. plot(time.phi).'ff'. hold %The loop: while ~abort [y.1). plot(0.98. axis([0 100 –2 2]).ns.'∗'). so that you want to plot the best estimate of the signal y – noise at the same time as the data y and u become available. [th.6).y–ns. th = zeros(1.'∗') time = time +Dt end This example uses a forgetting factor algorithm with a forgetting factor of 0. P=1000∗eye(6). readAD represents an M-file that reads the value of an A/D converter at the indicated time instance.98.phi] = rarx([y r]. 4-83 .r.abort] = readAD(time).

.nn. Matrix z contains the output-input data z = [y u] where y and u are column vectors.29) in the Tutorial for an exact definition of the orders.e ( t ) F( q) D( q ) are estimated using a recursive prediction error method..adm.) yhat is the predicted value of the output. rbj(z.22) and (3. i..18).adm.u ( t – nk ) + ----------.adg) [thm. i.nn.21) and (3. The estimated parameters are returned in the matrix thm.phi0. Each row of thm contains the estimated parameters in the following order: thm(k. single-output models are handled by rbj. nc...c1.... The actual algorithm is selected with the two arguments adm and adg.fnf] (See equations (3.e.18).d1.psi] = . (3..:) = [b1.. they are based on the data in the rows up to and including row k in z. Only single-input.14). See equations (3.. nd. Use rpem for the multi-input case. and nf are the orders of the Box-Jenkins model..rbj Purpose Syntax Estimate recursively the parameters of a Box-Jenkins model.(3.adg.(3. The k-th row of thm contains the parameters associated with time k. rbj thm = rbj(z.e.dnd..P0. nn is given as nn = [nb nc nd nf nk] where nb. row k of yhat contains the predicted value of z(k. 4-84 ...phi. according to the current model..P.f1.(3.cnc.bnb.th0..1) based on all past data.. These are described under rarx..20) in the Tutorial..psi0) Description The parameters of the ARMAX model structure B( q) C(q ) y ( t ) = ----------. and nk is the delay.yhat.14).22) and (3.

and psi contain initial and final values of the data vector and the gradient vector. of course. See rarx. respectively. The arguments phi0. phi. If you want nk=0. The sizes of these depend in a rather complicated way on the chosen model orders.) The default values of phi0 and psi0 are all zeros. See also “Recursive Parameter Estimation” on page 3-61. The arguments P0 and P are the initial and final values. be a dummy call with default input arguments. 4-85 . The normal choice of phi0 and psi0 is to use the outputs from a previous call to rbj with the same model orders. The default value of P0 is 104 times the unit matrix. Note that the function requires that the delay nk is larger than 0. consistent with the rows of thm. Algorithm The general recursive prediction error algorithm (11.44) of Ljung (1987) is implemented. (This call could. respectively of the scaled covariance matrix of the parameters. a row vector. shift the input sequence appropriately and use nk=1. psi0.) The default value of th0 is all zeros.rbj The input argument th0 contains the initial value of the parameters. (See above.

plot(e) compare(z.r] = resid(z. The computation of these values is done assuming e to be white and independent of u. In the multivariable case. The correlation information is returned with r.resid Purpose Syntax Compute and test the residuals (prediction errors) of a model. 4-86 . resid [e.5. Section 16.r] = resid(z. pem. compare.M. Examples Here are some typical model validation commands: e = resid(z. The autocorrelation function of e and the cross correlation between e and the input(s) u are computed and displayed.maxsize) resid(r). with columns corresponding to the different inputs and outputs. See “Model Structure Selection and Validation” on page 3-49 for more information. e is returned with the residuals (prediction errors) associated with the model and the data. The functions are displayed up to lag M.th). th is the model to be evaluated on the given data set. The 99% confidence intervals for these values are also computed and displayed as dotted (red) curves.th. The plots can then be reviewed by resid(r). theta Ljung (1987). which is 25 by default.th) [e. Description Matrix z contains the output-input data z = [y u]. See Also References auxvar. y and u are matrices.th). The argument maxsize is explained under auxvar. defined in theta format. where y and u are column vectors.

roe thm = roe(z..nn.roe Purpose Syntax Description Estimate recursively the parameters of an Output-Error model.14). row k of yhat contains the predicted value of z(k.nn. Use rpem for the multi-input case. These are described under rarx.P0.:) = [b1.) The default value of th0 is all zeros. 4-87 .. Matrix z contains the output-input data z = [y u] where y and u are column vectors.f1... See equations (3.adg) [thm.. a row vector..20) in the Tutorial.19)-(3.yhat. Each row of thm contains the estimated parameters in the following order: thm(k. The actual algorithm is selected with the two arguments adg and adm. Only single-input. The estimated parameters are returned in the matrix thm. nn is given as nn = [nb nf nk] where nb and nf are the orders of the Output-Error model.14) and (3.adm..1) based on all past data.P. i.psi] = roe(z. single-output models are handled by roe.psi0) The parameters of the Output-Error model structure B(q) y ( t ) = -----------u ( t – nk ) F(q) are estimated using a recursive prediction error method..th0. The input argument th0 contains the initial value of the parameters.phi.20) in the Tutorial for an exact definition of the orders. i.e..e. they are based on the data in the rows up to and including row k in z.adg. consistent with the rows of thm. The k-th row of thm contains the parameters associated with time k. according to the current model. yhat is the predicted value of the output.fnf] See equations (3.. and nk is the delay.bnb.phi0.adm. (See above. (3.

oe. rplr. See rarx.) The default values of phi0 and psi0 are all zeros. If you want nk=0. phi.roe The arguments P0 and P are the initial and final values. Note that the function requires that the delay nk is larger than 0. respectively. 4-88 .44) of Ljung (1987) is implemented. The normal choice of phi0 and psi0 is to use the outputs from a previous call to roe with the same model orders. respectively. psi0. The sizes of these depend in a rather complicated way on the chosen model orders. of the scaled covariance matrix of the parameters. rbj. shift the input sequence appropriately and use nk=1. Algorithm See Also The general recursive prediction error algorithm (11. See also “Recursive Parameter Estimation” on page 3-61. The arguments phi0. (This call could be a dummy call with default input arguments. and psi contain initial and final values of the data vector and the gradient vector. The default value of P0 is 104 times the unit matrix. rarx.

. See equations (3. For multi-input systems nb. i.d1. nd.b1. and nk are row vectors giving the orders and delays of each input. they are based on the data in the rows up to and including row k in z.bnb.phi0.. yhat is the predicted value of the output..1) based on all past data. 4-89 .cnc.e.adm.phi. row k of yhat contains the predicted value of z(k.rpem Purpose Syntax Description Estimate recursively the parameters of a general multi-input single-output linear model. and also the F part is repeated for each input. rpem thm = rpem(z.:) = [a1.. nc. nf.P0.a2. This is the same ordering as in th2par. The k-th row of thm contains the parameters associated with time k..u nu ( t – nk nu ) + ----------.P...e ( t ) D(q) F1( q ) Fn u( q) are estimated using a recursive prediction error method. nb..dnd..psi] = rpem(z.13)-(3. nn is given as nn = [na nb nc nd nf nk] where na.. and nf are the orders of the model..... Matrix z contains the output-input data z = [y u] where y and u are column vectors (in the multi-input case u contains one column for each input). The estimated parameters are returned in the matrix thm... Each row of thm contains the estimated parameters in the following order: thm(k.th0.adg.f1.23) in the Tutorial for an exact definition of the orders.nn. i..fnf] See equations (3... For multi-input systems the B part in the above expression is repeated for each input before the C part begins.nn. and nk is the delay.adg) [thm.ana.yhat.adm.13)-(3...psi0) The parameters of the general linear model structure Bn u( q) B1( q ) C( q) A ( q )y ( t ) = ------------.e... c1.u 1 ( t – nk 1 ) + … + ---------------.23) in the Tutorial.. according to the current model..

a row vector. rarmax. roe. respectively. rbj. psi0. phi. (This call could be a dummy call with default input arguments.rpem The actual algorithm is selected with the two arguments adg and adm. and Output-Error models. Box-Jenkins. See rarx. shift the input sequence appropriately and use nk=1. See Also pem. respectively. rarx. of the scaled covariance matrix of the parameters. and psi contain initial and final values of the data vector and the gradient vector. The sizes of these depend in a rather complicated way on the chosen model orders. See also “Recursive Parameter Estimation” on page 3-61. The normal choice of phi0 and psi0 is to use the outputs from a previous call to rpem with the same model orders. rplr 4-90 . These are described under rarx The input argument th0 contains the initial value of the parameters. and of single-input ARMAX/ARMA. Algorithm The general recursive prediction error algorithm (11.44) of Ljung (1987) is implemented.. it is more efficient to use rarx. consistent with the rows of thm.) The default values of phi0 and psi0 are all zeros.) The default value of th0 is all zeros. rarmax. (See above. For the special cases of ARX/AR models. rbj. The arguments P0 and P are the initial and final values. If you want nk=0 . The default value of P0 is 104 times the unit matrix. Note that the function requires that the delay nk is larger than 0. The arguments phi0. and roe.

P0. ELS method. (nn = [na nb nc 0 0 nk]). rpem 4-91 . rarx.adm.phi0) This is a direct alternative to rpem and has essentially the same syntax. When applied to ARMAX models. roe.adg) [thm. See Section 11.nn.rplr Purpose Syntax Description Estimate recursively the parameters of a general multi-input single-output linear model. See Also pem.nn. rplr differs from rpem in that it uses another gradient approximation.adg.P. Several of the special cases are well known algorithms. rplr thm = rplr(z. rbj.5 in Ljung (1987). See rpem for an explanation of the input and output arguments. rarmax.phi] = rplr(z. rplr can also be applied to the time series case in which an ARMA model is estimated with z = y nn = [na nc] You can thus use rplr as an alternative to rarmax for this case.adm.yhat. rplr gives the Extended Least Squares. When applied to the output error structure (nn = [0 nb 0 0 nf nk]) the method is known as HARF in the adm = 'ff' case and SHARF in the adm = 'ng' case.th0.

ll. u has the corresponding number of columns.mu) segment builds models of AR. The function models signals and systems that may undergo abrupt changes. Moreover nk is the delay. For the ARMAX model nn = [na nb nc nk] where na. or ARMAX/ARMA.th0. For an ARX model (nc = 0) enter nn = [na nb nk] For an ARMA model of a time series z = y nn = [na nc] and for an AR model nn = na 4-92 . A ( q )y ( t ) = B ( q )u ( t – nk ) + C ( q )e ( t ) assuming that the model parameters are piece-wise constant over time.P0. See (3. segment segm = segment(z. It results in a model that has split the data record into segments over which the model remains constant.nn) [segm. The argument z is the output-input data z = [y u] where y is a column vector containing the outputs and u is a column vector containing the inputs.thm. The argument nn defines the model order. nb and nk are row vectors.nn. and nc are the orders of the corresponding polynomials.segment Purpose Syntax Description Segment data and estimate models for each segment.V. "Tutorial". nb. If the system has several inputs.q.R2e] = segment(z.R1.13)-(3. ARX.R2.18) in Chapter 3.M. giving the orders and delays for each input. If the model has several inputs.

The default value is the identity matrix with dimension equal to the number of estimated parameters. R1 is the assumed covariance matrix of the parameter jumps when they occur.01. The default is 10 times the identity matrix. The default value of R2 is that it is estimated. Its default is zero. The default is ll = 1. The input argument R2 is the assumed variance of the innovations e(t) in the model. P0 is the initial covariance matrix of the parameters. 4-93 . The default is 0. That is. M is the number of parallel models used in the algorithm (see below). The argument q is the probability that the model undergoes at an abrupt change at any given time. and has a better capability to deal with time variations that may be abrupt. (See the example below. In fact. and therefore correspond to the outputs of the functions rarmax and rarx. This is analogous to the output argument thm in rarx and rarmax. any created candidate model is not abolished until after at least ll time steps. Its default value is 5. Then the output argument R2e is a vector whose k-th element contains the estimate of R2 at time k. Mu is a forgetting parameter that is used in the scheme that estimates R2. you need to try different values of R2 and evaluate the results. The output argument thm of segment contains the corresponding model parameters that have not yet been segmented. It is a measure of how successful the segmentation has been. The default value is 0. th0 is the initial value of the parameters.) sqrt(R2) corresponds to a change in the value y(t) that is normal. whose k-row contains the parameters corresponding to time k. The most critical parameter for you to choose is R2. That is. segment is an alternative to these two algorithms. It is usually more robust to have a reasonable guess of R2 than to estimate it. ll is the guaranteed life of each of the models. The output argument V contains the sum of the squared prediction errors of the segmented model.segment The output argument segm is a matrix. Typically. they are not piecewise constant.97. giving no indication that the system or the input might have changed.

with probability q. this would have been the maximum likelihood estimates of the jump instances. At each time step the model (among those that have lived at least ll samples) that has the lowest posterior probability is abolished. The time varying estimate thm is formed by weighting together the M different models with weights equal to their posterior probability.ones(y)]. This defines the different segments of the data. In other words. A new model is started. assuming that the system parameters have jumped. Then use a very simple model y(t) = b1 * 1. Each is updated independently. (If no models had been abolished in the algorithm. a random jump from the most likely among the models. assuming that the jump instances are correct.) The segmented model segm is then formed by smoothing the parameter estimate. each recursively estimated by an algorithm of Kalman filter type. After all the data are examined. Examples Check how the algorithm segments a sinusoid into segments of constant levels.0. y = sin([1:50]/3)'. plot([thm. thm = segment([y.1). 4-94 . where 1 is a faked input and b 1 describes the piecewise constant level of the signal y(t) (which is simulated as a sinusoid).[0 1 1]. more levels are created as R2 decreases. and its posterior probability is computed. the surviving model with the highest posterior probability is tracked back and the time instances where it jumped are marked.1 in the above example).segment Algorithm The algorithm is based on M parallel models. The covariance matrix of the parameter change is set to R1. the last estimate over a segment is chosen to represent the whole segment.y]) By trying various values of R2 (0.

V mod = V∗ ( 1 + 2∗ ( d ⁄ N ) ) where V is the loss function. V mod = V∗ ( 1 + log ( N )∗ d ⁄ N ) When c equals a numerical value. If c = 'log'. If v was generated by ivstruc. the logarithms of the loss functions are graphed instead. the structure that minimizes V mod = V∗ ( 1 + c∗ d ⁄ n ) is selected. you can choose a suitable number of parameters. The output argument vmod has the same format as v.selstruc Purpose Syntax Description Select model order (structure). Based on inspection of these plots. and N is the number of data points used for the estimation. d is the total number of parameters in the structure in question. and nn returns the best structure with this number of parameters.vmod] = selstruc(v) [nn. c = 'aic' gives no plots. then these are also graphed against the number of parameters. The default value of c is 'plot'. 4-95 .vmod] = selstruc(v. but it contains the logarithms of the accordingly modified criteria. c = 'mdl' returns in nn the structure that minimizes Rissanen’s Minimum Description Length (MDL) criterion. selstruc [nn. This graphs the values of the loss functions in v against the total number of parameters in the corresponding model structure. so that it also contains the condition numbers of the IV matrices.c) selstruc is a function to help choose a model structure (order) from the information contained in the matrix v obtained as the output from arxstruc or ivstruc. but returns in nn the structure that minimizes Akaike’s Information Theoretic Criterion (AIC).

v = arxstruc(z(1:200. See Chapter 3. the logical choice is c = 0.NN).:).nk).0).:). NN = struc(1:4. vi = ivstruc(z(1:200. nni = selstruc(vi).:). it is important to assess carefully whether the benefit of a better fit is worth the additional complexity of a higher order model.z(201:400.1:4.NN).NN). When selecting model structures.:).selstruc The formal grounds for applying AIC or MDL require that v be generated by arxstruc with ze = zv. When cross-validation is used (ze different from zv). "Tutorial" for more information. ivstruc.:). nk = nn(3). va = arxstruc(z(1:200.:). nn = selstruc(v.1:8). See Also arxstruc.2. struc 4-96 .z(201:400. Examples Here is a typical sequence of commands for finding a suitable model structure: NN = struc(2.z(201:400. nna = selstruc(va).

sett Purpose Syntax Description Set the sampling interval directly. th = armax(z.nn). See Also freqfunc.T).T).[]. theta 4-97 . For convenience sett offers an alternative to set it directly. sett modn = sett(mod.[].[].T) All functions that create model descriptions in the theta or freqfunc format set the sampling interval T in their last argument.[]. th = sett(th. is equivalent to g = spa(z.T) Similarly. Use thc2thd or thd2thc instead. with a default choice of frequencies.[]. g = spa(z).T) Note that you cannot use sett to recalculate models to a new sampling interval.[]. is equivalent to th = armax(z. g = sett(g.nn.[]. It can be applied both to the case where mod is a model in the theta format and to the case where mod is a frequency function or spectrum in the freqfunc format.

The default value is M = min(30. g is returned in the frequency function format (see freqfunc) with the estimate of G ( e iω ) at the frequencies ω specified by row vector w.M. The data may be complex-valued.length(z)/10) Changing the value of M exchanges bias for variance in the spectral estimate. spa [g. but are more corrupted by noise. The default value of w is w = [1:128]/128∗pi/T phiv is returned with the autospectrum estimate of Φ v ( ω ) at the same frequencies.w.spa Purpose Syntax Description Estimate frequency response and spectrum by spectral analysis.phiv] = spa(z) [g.phiv. Both outputs are returned with estimated standard deviations (see freqfunc). where y and u are column vectors. If there are several inputs.maxsize. T is the sampling interval and maxsize controls the memory-speed trade-off (see auxvar). the higher M it needs. 4-98 . M is the length of the lag window used in the calculations.T) spa estimates the transfer function g and the noise spectrum phiv = Φ v of the general linear model y ( t ) = G ( q )u ( t ) + v ( t ) where Φ v ( ω ) is the spectrum of ν(t). As M is increased. The sharper peaks a true frequency function has. Matrix z contains the output-input data z = [y u]. the estimated functions show more detail.z_spe] = spa(z. u is a matrix with one column for each input. See etfe as an alternative for narrowband signals and systems.

. g is returned with the estimated output spectrum and its estimated standard deviation. Examples With default frequencies g = spa(z). bodeplot(g) With logarithmically spaced frequencies w = logspace(–2. For default window size use in the multi-output case M = [–1.nz) = The spectrum S at frequency W(k) where nz is the number of channels in the data matrix z and S = ∑ m = –M M Ez ( t + m )z ( t )′ exp ( – iW ( k )mT ) win ( m ) Here win(m) is weight at lag m of an M-size Hamming window and W(k) is the frequency value i rad/s. The normalization of the spectrum differs from the one used by spectrum in the Signal Processing Toolbox .pi.spa For time series z = y. –1.w).128). See “Some Special Topics” on page 3-68 for a more precise definition. 4-99 .. Note that ' denotes complex-conjugate transpose. .[]. This is the way the distinction between inputs and outputs in z is clarified. % (empty matrix gives default) bodeplot([g phiv].phiv] = spa(z. –1] The optional third output argument z_spe gives directly the spectrum matrix of z as follows: reshape(z_spe(:.. IMPORTANT: For multi-output data the argument M must be entered as a row vector of the same length as the number of outputs.nz.k). [g.3) plots the estimated spectrum together with confidence intervals of three standard deviations.

which is more efficient than for user-defined frequencies.4. th2ff Ljung (1987).spa Algorithm The covariance function estimates are computed using covf. For the default frequencies. See Also References auxvar.1 of Ljung (1987). Section 6. These are multiplied by a Hamming window of lag size M and then Fourier transformed. The standard deviations are computed as on pages 155-156 and 264 of Ljung (1987). The relevant ratios and differences are then formed. a straightforward for-loop is used. Note that M = ϒ is in Table 6. 4-100 . freqfunc. etfe. For multi-variable systems. this is done using FFT. ffplot. bodeplot.

which can be any model in theta format. Their sum must be equal to the order of the model TH. See canform for more details. a default choice of indices is made. orders: The pseudo-observability indices. also in theta format. See Also canform. A canonical parametrization in observer form.27) in the Tutorial with D=0) then THS will also have such a structure. thp = pem(z. A row vector. with as many elements as there are outputs in the model TH.K). Let the model obtained from n4sid be used as the initial value for prediction error estimation: thn = n4sid(z.ss2th Purpose Syntax Description Create a model structure parametrized in canonical form. Examples Make a parametrized state-space model from given matrices A.C. and you want to use it as an initial model for prediction error estimation using pem. C. then so is THS. THS: The resulting model. and K and use it as initial condition for pem estimation: th1 = ms2th(modstruc(A.D. based on the pseudo-observability indices orders. B. th = pem(z. TH: The given model. n4sid 4-101 . If the model TH is an output error model (its Kalman gain equal to zero). If orders is omitted. It is useful when a model has been obtained in some way.3).B. ss2th THS = ss2th(TH) THS = ss2th(TH. ms2th. canstart.’d’). thi = ss2th(th1). D.orders) This function converts any model in theta format to a canonically parameterized state-space model.ss2th(thn)).thi). Also if there is a delay from input to output in TH (corresponding to a state-space representation (3. also in theta format.

struc NN = struc(NA. The format of NN is consistent with the input format used by arxstruc and ivstruc. The command is intended for single-input systems only.1:2.NB. NB.4:5). Examples The statement NN = struc(1:2.NK) struc returns in NN the set of model structures comprised of all combinations of the orders and delays given in row vectors NA. and NK.struc Purpose Syntax Description Generate model structure matrices. produces NN = 1 1 1 1 1 2 1 2 2 1 2 1 2 2 4 5 4 5 4 5 5 4-102 .

If thc is of input-output type. zpplot(th2zp(thd)) See Also thd2thc 4-103 .T) thc is a continuous-time model in the theta format. thd is what is obtained when it is sampled with sampling interval T.1.1.1.1. Examples Define a continuous-time system and study the poles and zeros of the sampled counterpart: thc = poly2th(1.5).0. The innovations variance in thd will thus be given as λ /T. thd = thc2thd(thc.[1 1 0]. thc2thd thd = thc2thd(thc.–1). Note that the innovations variance λ of the continuous-time model is interpreted as the intensity of the spectral density of the noise spectrum.thc2thd Purpose Syntax Description Convert a model from continuous time to discrete time. the covariance matrix of the parameters is not translated.

The step sizes in the numerical derivatives are determined by the function nuderst. is converted to a continuous-time counterpart thc. thc2thd See “Some Special Topics” on page 3-68. This is done automatically by th2ff. and its sampling interval is T. enter delay = 'del'.delay. consistent with the discrete-time model. i. poles on the negative real axis. thd2thc selects the continuous-time counterpart with the slowest time constants. thc = thd2thc(th). gc = th2ff(thc). To have the time delay approximated by a finite-dimensional continuous system. Interpret the results with care. given in the theta format.NoP) The discrete-time model thd.thd2thc Purpose Syntax Description Convert a model from discrete to continuous time. The lack of uniqueness also means that the transformation may be ill-conditioned or even singular. IMPORTANT: The transformation from discrete to continuous time is not unique. in the origin. These delays should then be appended as pure time-delay (deadtime) to the continuous-time model. 4-104 .e. then the continuous-time model has an indicated level of innovations spectral density equal to T ∗ λ . nk > 1 . Examples Transform an identified model to continuous time and compare the frequency responses of the two models: gd = th2ff(th). bodeplot([gd.3) See Also References nuderst. or in the point 1. gc]. thd2thc thc = thd2thc(thd) thc = thd2thc(thd. If the discrete-time model contains pure time delays. enter NoP = 1. The default is delay = 'nodel'. To inhibit the translation of the covariance matrix and save time.. If the innovations variance is λ in thd. are likely to cause problems. then these are first removed before the transformation is made. The covariance matrix of the parameters in the model is also translated using Gauss’ approximation formula and numerical derivatives of the transformation. In particular.

B. nb. It also contains other relevant information about the identification result. This model format is the basic format with the System Identification Toolbox.theta Purpose Syntax Description Describe the theta format. respectively. theta help theta help thss theta is a packed matrix containing information about both a model structure and its nominal or estimated parameters.u 1 ( t – nk 1 ) + … + ---------------. For the general multi-input single-output linear model structure Bn u( q) B1( q) C(q ) A ( q )y ( t ) = ------------. 6 + 3 nu ) 4-105 . I. If the system has nu inputs. and F are polynomials in the delay operator of orders na.e ( t ) D( q ) F1( q) Fn u( q) A. The formats differ whether the underlying model is in state-space form or of the input-output black box character. D.u n u ( t – nk nu ) + ----------. It is used by all parametric identification methods and it can be transformed to many other model representations. B and F are not defined. Let n be the sum of all the orders (the number of estimated parameters) and let r = max(n. Some specific information is retrieved from the format by the functions getmfth. and th2par. getncap. The internal format of the theta format is intended to be transparent to the user. nc. gett. but this information is not necessary for most users of the System Identification Toolbox. 7. C. In the case of a time series (no u). The basic way to display the information is to use the present command. nd. nf and nk are row vectors of dimension nu containing information about the orders and delays associated with each of the inputs. nb. See the tables in the beginning of this chapter for more details. This entry gives the details of the internal representation. and nf.

(excluding leading 1s and 0s). The matrix entry (2. 7 + r) by 3+ n + nr + ny) organized as follows: • Row 1 has entries: determinant of innovations covariance. D.7) thus contains the coded number of which command generated the model. minute and command by which the model was generated. This M-file is called by [A.C. sampling interval. ny. sampling interval T. month. This is used when computing frequency functions in th2ff. the name of this M-file is ssmodx9 or ssmodx8 and the argument aux is the actual model structure ms created by modstruc. • Row 3 is the vector of estimated parameters. • Row 2 has entries: FPE (Akaike’s Final Prediction Error). Suppose that the number of estimated parameters is n and that the length of the name of your M-file mfname is r. number of estimated parameters. • Rows 4 to 3+n contain the estimated covariance matrix. na. nf. a possible element (4+n.theta Then theta is a (3+n) r matrix organized as follows: • Row 1 has entries: estimated variance of e. Notice in particular that multi-output ARX models are internally represented as state-space models with the aid of ssmodx9.D.1) contains a dead-time for the system. number of inputs. number of columns of aux. II.B. This number is less than 20 for the black-box models of the type above. For models that are defined as state-space structures there is an underlying M-file that defines the structure. 4-106 .aux) (See mf2th. A.) For model structures that are defined by ms2th. nd. year. and nk.C.K.X0] = mfname(par. nc. nc. hour. number of outputs. number of rows of aux. B . date.T. nu. • For continuous-time models. and name of M-file that defines the structure. and F. Then theta is a matrix of dimension max(n. nb. Suppose also that the model has ny outputs and that the size of the argument aux above is nr times nc.

4-107 . date. year. using ssmodx9. • Entry (2. to be sampled by first-order-hold. ‘3” means that the model is a multivariate ARX model. “ll” means that the underlying parameterization is in continuous time. month. “4” means that the underlying parameterization is in discrete time and user defined. • Rows 4 + n to 3 + n + nr contain the matrix aux. “5” means that the model is a user-defined continuous-time parameterization.theta • Row 2 contains the entries: FPE (Akaike’s Final Prediction Error). • Rows 4 +n + nr to 3+n + nr + ny contain the covariance matrix of the innovations of the model. This last one is a number larger than 20 for state-space structures. • Rows 4 to 3 + n contain the estimated covariance matrix of the parameters. using ssmodx8.8) is interpreted as follows: “1” means that the underlying parameterization is in continuous time. and command by which the model was generated. “2” means that it is in discrete time. minute. again using ssmodx9. • Row 3 contains the estimated (nominal) values of the parameters. hour. equipped with sampling inhibition when called with a negative value of T.

sp) This function randomizes initial parameter estimates for model structures th0 in the theta format that correspond to state-space models.R. Sp = 'p' is the default. where e is a normal random variable with zero mean and a variance of 1. and the default value of pars is the nominal parameter vector in th0. th is the same model structure as th0.thinit Purpose Syntax Description Set initial values for the parameters to be estimated. A maximum of 100 trials are made by thinit. If sp = 'b'. See Also canstart. sp = 's' requires stability only of the model. mf2th. This vector is used as the initial estimate by pem. An alternative is then to compute the Kalman filter predictor for a randomized model. Only models that give stable predictors are accepted. thinit th = thinit(th0) th = thinit(th0. and sp = 'p' requires stability only of the predictor. pem 4-108 .pars. ms2th. only models that are both stable and have stable predictors are accepted. The parameters are randomized around pars with variances given by the row vector R. The default value of R is all ones. It may be difficult to find a stable predictor for high order systems just by trial and error. Parameter number k is randomized as pars(k) + e*sqrt(R(k)). but with a different nominal parameter vector.

B. Ana] B = [B0 B1 .B] = th2arx(th) [A. See Also arx2th 4-109 ..th2arx Purpose Syntax Description Extract the ARX parameters from a theta format model. Bnb] where y ( t ) + A 1 y ( t – 1 ) + … + A na y ( t – na ) = B 0 u ( t ) + B 1 u ( t – 1 ) + … + B nb u ( t – nb ) Delays in the system are indicated by leading zeros in the B matrices.. th2arx [A.dB] = th2arx(th) th is the model in the theta format.dA... See Section 6 in the Tutorial. dA and dB are the standard deviations of A and B. A and B are returned as the matrices that define the ARX structure: A = [I A1 A2 .

where th is a matrix in theta format containing a general model.ku. The standard deviations of the frequency function(s) and the spectra are also computed. Note that no cross-spectra between different outputs are computed.4). The format of g is detailed under freqfunc.phiv] = th2ff(th. trf [g. The default values of ku and ky are all input and output pairs contained in th. 4-110 . The normalization of the spectrum differs from the one used by spectrum in the Signal Processing Toolbox.w. For models with complicated parameter dependencies. for a precise definition. respectively. g is returned with the transfer function estimate (see (3.phiv] = th2ff(th) [g. See “Some Special Topics” on page 3-68. For a time continuous model the frequency function G ( iω ) is obtained instead.25) in the Tutorial) G(e ) computed at the frequencies ω given in row vector w. Phiv ( Φ v ) is returned with the estimated noise spectrum for each of the outputs iω Φ v ( ω ) = λ ∗ T∗ H ( e iwt 2 ) where λ is the estimated variance of e(t) (the loss function) specified by th. th2ff. trf Purpose Syntax Description Compute the frequency response and standard deviations of a theta format model. using the Gauss approximation formula. If th has several inputs and outputs. and (3. phiv is computed at the same frequencies as g. The step sizes for the numerical derivatives are determined by nuderst. g is computed for the input and output numbers specified in row vectors ku and ky. numerical differentiation is applied. (3.th2ff.ky) th2ff computes the frequency functions of th.23).

log10(10*pi/ abs(T)). and can be considerably faster. and nyqplot. spa 4-111 .[2 2 2 1]). ffplot. sett.th2ff.128) where abs(T)is the “underlying” sampling interval for the continuous-time model. IMPORTANT: The command trf has the same syntax as th2ff but does not calculate the standard deviations. but don’t store. nyqplot. trf The default values of the frequencies are in the discrete-time case are w = [1:128]/128∗pi/T where T is the sampling interval specified by th (default = 1) and for the continuous-time case w = logspace(log10(pi/abs(T)/100). etfe. gs = spa(z). the frequency function g associated with th: bodeplot(th2ff(th)) See Also bodeplot. The frequency functions can be graphed with bodeplot. Examples Compare the results from spectral analysis and an ARMAX model (input-output dynamics only). bodeplot([gs gp]) Plot. ffplot. th = armax(z. gp = th2ff(th).

P. …. c nc. D. …. defined by ms2th. …. c 1. defined in the theta format. b nb2. …. you have pars = [ a 1. K.) For a state-space matrix that is defined by mf2th. nu nu 1 1 nu nu 1 1 2 2 4-112 . …. d nc. the ordering of the parameters is the same as in your M-file. Multivariate ARX models are internally represented in state-space form. it is better to use th2arx. the parameters in pars are obtained in the following order: The A matrix is first scanned row by row for free parameters. …. (See ms2th. For the general input-output model (7. and lam is the variance (covariance matrix) of the innovations. …. par is returned as the nominal or estimated values of the free parameters in th. b 1. a na. f 1. For a state-space structure. th2par [par. …. superscript refers to the input number. b n b1. d 1. …. b nb nu. …. b 1. f nf1. Then the B matrix is scanned row by row. f 1 . f nfnu ] Here. The covariance matrix of the parameters is obtained as P.th2par Purpose Syntax Description Extract the parameters from the theta format. and so on for the C.2). and X0 matrices. … b 1 . The ordering of the parameters may not be transparent in this case.lam] = th2par(th) th is a model. …. The ordering for the parameters is as follows.

LAM is the noise variance and T is the sampling interval.D. See “Examining Models” on page 3-40. See Also poly2th. theta 4-113 . It returns the polynomials of the general model B nu ( q ) B1( q ) C(q ) A ( q )y ( t ) = ------------. th2tf.u nu ( t – nk nu ) + ----------.e ( t ) D( q ) F1( q ) F nu ( q ) as contained by the matrix th in theta format.th2poly Purpose Syntax Description Convert theta matrix into its component polynomials. th2poly [A.F.B.u 1 ( t – nk 1 ) + … + ---------------.T] = th2poly(th) This is essentially the inverse of the poly2th function.LAM.C.

Gauss approximation formula is used together with numerical derivatives.dD. dK. dB.dA.X0] = th2ss(th) [A. The step sizes for this differentiation are determined by nuderst.D.dC. Algorithm The computation of the standard deviations in the input-output case assumes that an A polynomial is not used together with a F or D polynomial in (7.D. nuderst See Also 4-114 . A. C. dA.K. dC.dK.C.dX0] = th2ss(th) th is the model given in the theta format.dB.2).X0. the matrices correspond to the same basis. dD.K. For the computation of standard deviations in the case that the state-space parameters are complicated functions of the parameters.B.C. and dX0 are the standard deviations of the state-space matrices. ms2th. B. If the underlying model itself is a state-space model.th2ss Purpose Syntax Description Transform a model to state-space form. D. If the underlying model is an input-output model. th2ss [A. an observer canonical form representation is obtained.B. and X0 are the matrices in the state-space description ˜ x ( t ) = Ax ( t ) + Bu ( t ) + Ke ( t ) x ( 0 ) = x0 y ( t ) = Cx ( t ) + Dx ( t ) + e ( t ) · ˜ where x ( t ) is x or x ( t + 1 ) depending on whether th is a continuous or discrete-time model.K. mf2th.

enter iu = –k. To obtain the transfer function from noise source number k. Examples For a continuous-time model num = [1 2] den = [1 3 0] corresponds to the transfer function s+2 G ( s ) = ---------------2 s + 3s For a discrete-time model num = [2 4 0] den = [1 2 3 5] corresponds to the transfer function 2z + 4z H ( z ) = ---------------------------------------3 2 z + 2z + 3z + 5 which is the same as 2q + 4q H ( q ) = -------------------------------------------------------–1 –2 –3 1 + 2q + 3q + 5q See Also th2poly –1 –2 2 4-115 . num is a matrix whose row number k gives the numerator polynomial associated with the transfer function from input number iu to output number k. both for continuous-time and discrete-time models.iu) th is a model given in the theta format.den] = th2tf(th) [num. The formats of num and den are the same as those used by the Signal Processing Toolbox and the Control Systems Toolbox. The default value of iu is 1.th2tf Purpose Syntax Description Transform a model to transfer function form.den] = th2tf(th. See “Examining Models” on page 3-40. den is a row vector giving the (common) denominator polynomial for these transfer functions. th2tf [num.

In this context. finite values. poles. while the static gains are returned in k. zp [zepo. The second row of k contains the corresponding gains. the poles and zeros and static gains. where jy is the output number and ju is the input number for the gain in question. The best way to display the information in zepo is to plot it using zpplot.ku. the coefficient of the highest power in the numerator. The value 0 in the vector ku is the default for “all noise sources. due to the numerical procedure. The poles and zeros are stored in coded form in the matrix zepo. Zeros at infinity may. which use the transfer function gain. The first row of k contains the integer (jy-1)∗1000+ju. The information can also be retrieved with getzp.” The default values of ku and ky are all inputs and all outputs (no noise inputs).thresh) For any model described in theta format by th. the steady state gain from a step in input number ju to output number jy. and the third row the standard deviation of the gain in question. the noise e(t) is counted as inputs with negative numbers. any zero whose absolute value is larger than thresh is regarded to be at infinity. NOTE: The gain here is the static gain.th2zp. Row vectors ku and ky contain the indices of the inputs and outputs. The default value of thresh is 100000. along with their standard deviations are computed. noise source number ju (the ju-th component of e(t) is counted as input number ju. 4-116 . This is different from the routines ss2zp and zp2ss in the Signal Processing Toolbox. and static gains of a theta format model. To avoid this.e. The procedure handles both models in continuous and discrete time.k] = th2zp(th) [zepo. end up as large.ky. That is. respectively.k] = th2zp(th.. The optional argument thresh is a threshold for the computation of the zeros.. zp Purpose Syntax Description Compute zeros. i. th2zp. for which the zeros. i. It is thus the same for a discrete-time and a continuous-time representation of the same model. poles and gains are to be computed.e.

zp uses ss2zp from the Signal Processing Toolbox.u n u ( t – nk nu ) + ----------. This can be a useful alternative. Moreover. (This is a somewhat confusing issue anyway. ku. when the standard deviations are not of interest. The alternative routine zp has the same syntax as th2zp but does not compute standard deviations.u 1 ( t – nk 1 ) + … + ---------------. zp For the general discrete-time multi-input. Algorithm The standard deviations are computed using Gauss’s approximation formula.) zepo is returned in a format that allows easy plotting with zpplot. present in the indices ky. and computation time for th2zp is long. The static gain is k =B(1)/(A(1)F(1)).th2zp.) The routine zpform is useful n b + nk when comparing different models.e ( t ) D (q ) F1 (q ) F nu ( q ) B ( z ) (with z replacing the forward shift the zeros are the roots of z n a + nf operator q). Note that you cannot rely on information about zeros and poles at the origin and at infinity. These zeros may thus differ from the transmission zeros associated with the multivariable system. (Then zeros and poles at the origin and at infinity are ignored. Note: Although zp computes zeros and poles for all combinations of noise sources and outputs. and the poles are the roots of z A ( z )F ( z ) . single-output model B nu ( q ) B1 (q ) C(q ) A ( q )y ( t ) = ------------. which may give better numerical accuracy in difficult cases. the poles are the eigenvalues of the system matrix. For models that are internally represented in state-space form. To find the trans-mission zeros. The zeros are the zeros of the corresponding transfer function. first use th2ss and then apply tzero from the Control System Toolbox. numerical 4-117 . When the transfer function depends on the parameters in a complicated way. using the parameter covariance matrix contained in th. the command th2zp only gives information about poles and zeros from noise source number ju to output number ju (if ku contains the number -ju).

th2zp, zp

differentiation is applied. The step sizes for the differentiation are determined in the M-file nuderst. Note that Gauss’s approximation formula gives infinite variance to poles and zeros that are exactly repeated.

Examples

The statement
zpplot(th2zp(th))

plots, but does not store, the poles and zeros. To compare the zeros and poles of second and third order ARX models (input-output dynamics only), use
th2 = arx(z,[2 2 1]); th3 = arx(z,[3 3 1]); zp2 = th2zp(th2); zp3 = th2zp(th3); zpplot(zpform(zp2,zp3))

See Also

getzp, theta, zepo, zpform, zpplot

4-118

unfixpar

Purpose Syntax Description

Free parameters in structures defined by ms2th and arx2th.
unfixpar

thn = unfixpar(tho,matrix) thn = unfixpar(tho,matrix,elements)

This function is the inverse of fixpar. The interpretation of the arguments is the same. unfixpar makes the indicated parameters free parameters to be estimated. The nominal/initial values of these parameters are taken to be equal to their actual values in the structure tho.
fixpar, ms2th, theta, thinit

See Also

4-119

zepo

Purpose Syntax Description

Describe the zeros and pole format.
zepo

help zepo

The zepo format is created by th2zp and zp and used by zpplot. It contains information about zeros and poles and their standard deviations. The internal format is intended to be transparent to the user. The basic way to display the information is to use the zpplot command. Some specific infor-mation is retrieved from the format by the function getzp. This entry gives the details of the internal representation, but this information is not necessary for most users of the System Identification Toolbox. The first row of the matrix consists of integers that give information about what the column below contains. The integers are coded in the following way: • The zeros associated with input number ku and output number ky correspond to the number (ky - 1)*1000 + ku. • The standard deviations of these zeros correspond to the number (ky-1)*1000 + ku +60. • The poles associated with input number ku and output number ky correspond to the number (ky - 1)*1000 + ku + 20. • The standard deviation of these poles correspond to the number (ky - 1)*1000 + ku + 80. • The zeros associated with noise input number ky and output number ky (only these are normally represented) correspond to the number 500 + ky. • The standard deviation of these, the corresponding poles, and their standard deviations are obtained by adding 60, 20, and 80, respectively to this number. • Positions corresponding to nonexisting zeros and poles (as well as zeros and poles at infinity) are represented by inf. • If any of the above numbers is negative, it indicates that the pole or zero representation corresponds to a continuous-time model. Then the absolute value of the number has the interpretation above.

4-120

zepo

• For complex conjugated pairs, the first row in the corresponding entry for the standard deviation contains a complex number whose real and imaginary parts are the standard deviations of the real and imaginary parts, respectively, of the pole or zero in question. The next row entry (corres-ponding to the conjugate pole or zero) contains a real number that is the correlation between the real and imaginary parts.

See Also

getzp, th2zp, zpform, zpplot

4-121

zpform

Purpose Syntax Description

Merge zero-pole information from different models.
zpform

zepo = zpform(zepo1,zepo2,...,ku)

The zeros and poles in zepo1, zepo2, ... from different models are merged into one matrix to be used by zpplot. zepo1, zepo2, ... have the format as produced by th2zp. ku is an optional row vector containing the input numbers to be picked out when forming zepo. The default value is ku is equal to all inputs present in zepo1, zepo2, ... A maximum of five input arguments to zpform is possible. The statement
zpplot(zpform(zpbj2,zpbj4,zpax2,zpax4,0))

Examples

compares the noise characteristics from four different models.

See Also

th2zp, zpplot

4-122

confidence regions around the poles and zeros are also graphed. zpplot zpplot(zepo) zpplot(zpform(zepo1. zeros and poles at the origin are also ignored. mode = 'sep' erases the previous plot before the next input is treated. The default value is sd = 0. axis = [x1 x2 y1 y2] fixes the axis scaling accordingly. axis = m is the same as axis = [–m m –m m] 4-123 . corresponding to the same model all have the same color. Note that the confidence regions may sometimes stretch outside the plot. are always graphed in the same diagram.sd. zepon)) zpplot(zepo. but they are always symmetric around the indicated zero or pole...zepo2. with o denoting zeros and x denoting poles. Poles and zeros associated with the same input. If sd has a value larger than zero.mode. On color screens poles. mode = 'same' gives all plots in the same diagram. When zepo contains information about several different inputs. Poles and zeros at infinity are ignored.zpplot Purpose Syntax Plot zeros and poles. For discrete-time models. If the poles and zeros are associated with a discrete-time model. zeros and their confidence regions.axis) Description The zeros and poles specified by zepo (see zepo for the format) are graphed. there are some options: mode = 'sub' splits the screen into several plots. The default value is mode = 'sub'. Pressing the Return key advances the plots. a unit circle is also drawn. The regions corresponding to sd standard deviations are marked. and pressing the Return key advances the plot from one model to the next.. . but different models.

3) show all zeros and poles of three models along with the confidence regions corresponding to three standard deviations. zpoe = th2zp(thoe3). See Also th2zp.zpbj).zpplot Examples zpbj = th2zp(thbj2). zpform 4-124 .zpax. zpplot(zpform(zpoe. zpax = th2zp(tharmax4).

introduction 1-5 E B basic tools 3-3 Bode diagram 2-29 Bode plot 1-9 Box-Jenkins (BJ) structure 3-11 Box-Jenkins model 2-22 Burg’s method 3-23 estimation data 1-4 estimation method instumental variables 3-17 prediction error approach 2-18. 2-14. 3-25 exporting to the MATLAB workspace 2-32 extended least squares (ELS) 3-66 C canonical forms 3-35 communication window ident 2-2 comparisons using compare 3-48 complex-valued data 3-79 correlation analysis 1-4. 3-31 detrending the data 2-10 disturbance 1-5 drift matrix 3-63 dynamic models. 3-20 covariance function 3-9 covariance method 3-23 creating models from data 2-2 cross correlation function 3-52 cross spectrum 3-16 F fault detection 3-67 feedback 1-13 freqfunc format 3-20 frequencies 3-28 frequency function 2-15 functions 3-8. 3-6. 3-22. 3-17 estimation methods direct 2-14 parametric 2-14 subspace method 3-18. 2-20. 3-20 plots 3-8 range 3-8 response 2-15 scales 3-8 frequency domain description 3-10 frequency response 1-9 D Data Board 2-3 data handling checklist 2-12 data representation 2-7. 3-17.Index A adaptive noise cancelling 4-82 Akaike’s Final Prediction Error (FPE) 3-50 AR model 3-23 ARARMAX structure 3-12 ARMAX model 2-22 ARMAX structure 3-11 ARX model 1-6. 3-29 delays 3-10. 3-19 data views 1-4 I-125 . 3-10. 3-15.

basic steps 1-10 importing data into the GUI 2-9 impulse response 1-9. 2-29. 3-8. 3-19 nonparametric identification 1-4 Normalized Gradient (NG) Approach 3-64 numerical differentiation 3-37 K Kalman-gain matrix 3-33 L lag widow 3-16 layout 2-35 O offsets 3-58 I-126 . 3-15 Information Theoretic Criterion (AIC) 3-50 initial condition 3-24 initial parameter values 3-37 innovations form 3-13. 3-9. 3-33 input signals 1-5 instrumental variable 3-17 (IV) method 3-22 technique 3-23 iterations 3-27 iterative search 3-24 N noise 1-5 noise model 1-7 noise source 1-7.Index G Gauss-Newton minimization 3-24 geometric lattice method 3-23 graphical user interface (GUI) 2-2 GUI 2-2 topics 2-34 M main ident window 2-34 maximum likelihood criterion 3-26 method 3-17 memory horizon 3-63 model output-error 1-7 properties 1-9 set 1-4 state-space 1-7 structure 2-17. 3-3 structure selection 3-3 structures 3-29 uncertainty 3-53 validation 1-4 view functions 2-27 views 1-4. 1-7. 2-31 noise-free simulation 1-8 noise-free simulations 3-53 nonparametric 3-10. 3-23 H Hamming window 3-21 I ident window 2-34 identification process. 2-4 Model Board 2-3 multivariable ARX model 3-30 multivariable systems 1-16.

2-29 R recursive identification 3-4.Index outliers signals 1-4 output signals 1-5 Output-Error (OE) structure 3-11 Output-Error model 1-7. 3-16 spectral analysis 1-4. 3-29 time domain description 3-9 time-continuous systems 3-30 transfer function 1-6 transient response 1-9. 3-20 startup identification procedure 1-12 state vector 3-13 state-space form 3-13 model 1-7. 2-22 P parametric identification 1-4 periodogram 3-21 poles 1-9 prediction error identification 2-18 error method 3-17 prefiltering 2-11 prefiltering signals 2-11 simulating data 2-12 spectra 3-8. 2-24 modeling 3-4 models 3-33 step response 1-9. 2-29 structure 1-4 subspace method 3-18. 3-61 least squares 3-64 parameter estimation 3-61 references list 1-19 resampling 2-11 robust estimation techniques 3-27 U Unnormalized Gradient (UG) Approach 3-64 V validation data 1-4 S sampling interval 3-30 selecting data ranges 2-11 Sessions 2-5 shift operator 3-8 W white noise 3-9 window sizes 3-21 Working Data set 2-3 workspace variables 2-6 I-127 . 3-25 T Q Quickstart menu item 2-12 theta format 3-22. 3-16. 3-20 spectrum 3-9.

Index Y Yule-Walker approach 3-23 Z zeros 1-9 I-128 .

Sign up to vote on this title
UsefulNot useful