MATLAB Software For Recursive Identification and Scaling Using A Structured Nonlinear Black-Box Model
MATLAB Software For Recursive Identification and Scaling Using A Structured Nonlinear Black-Box Model
Abstract
This reports is intended as a users manual for a package of MATLABä scripts and functions,
developed for recursive prediction error identification of nonlinear state space systems and nonlinear
static systems. The core of the package is an implementation of an output error identification and
scaling algorithm. The algorithm is based on a continuous time, structured black box state space
model of a nonlinear system. An RPEM algorithm for recursive identification of nonlinear static
systems, that re-uses the parameterization of the nonlinear ODE model, is also included in the
software package. In this version of the software an initialization algorithm based on Kalman filter
theory has been added to the package. The purpose of the initialization algorithm is to find initial
parameters for the prediction error algorithm, and thus reduce the risk of convergence to local minima
for the nonlinear identification problem. The software can only be run off-line, i.e. no true real time
operation is possible. The algorithms are however implemented so that true on-line operation can be
obtained by extraction of the main algorithmic loop. The user must then provide the real time
environment. The software package contains scripts and functions that allow the user to either input
live measurements or to generate test data by simulation. The scripts and functions for the setup and
execution of the identification algorithms are somewhat more general than what is described in the
references. There is e.g. support for automatic re-initiation of the algorithms using the parameters
obtained at the end of a previous identification run. This allows for multiple runs through a set of
data, something that is useful for data sets that are too short to allow convergence in a single run. The
re-initiation step also allows the user to modify the degrees of the polynomial model structure and to
specify terms that are to be excluded from the model. This makes it possible to iteratively re-fine the
estimated model using multiple runs. The functionality for display of results include scripts for
plotting of data, parameters, prediction errors, eigenvalues and the condition number of the Hessian.
1
The estimated model obtained at the end of a run can be simulated and the model output plotted, alone
or together with the data used for identification. Model validation is supported by two methods apart
from the display functionality. First, a calculation of the RPEM loss function can be performed, using
parameters obtained at the end of an identification run. Secondly, the accuracy as a function of the
output signal amplitude can be assessed.
Keywords: Identification, Kalman filter, MATLABä, Nonlinear systems, Ordinary differential
equation, Prediction error method, Recursive algorithm, Sampling, Scaling, Software, State space
model.
Prerequisites
This report only describes the parts of [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], and [ 6 ] that are required for the
description of the software. Hence the user is assumed to have a working knowledge of the algorithm
of these publications and of MATLABä, see e.g. [ 7 ]. This, in turn, requires that the user has a
working knowledge of system identification and in particular of recursive identification methods as
described in e.g. [ 8 ]. The algorithm for identification of static systems is described in some detail in
the report.
Revisions
Revision 1: [ 10 ] describes revision 1.0 of the accompanying SW. The software of revision 1 has
been tested with MATLAB 5.3, MATLAB 6.5, and MATLAB 7.0 running on PCs and UNIX
workstations.
Revision 2: [ 11 ] includes functionality for recursive identification of static nonlinear systems. See
sections 9 and 10 of the report. Furthermore, an error has been corrected in the RPEM algorithm. The
timing error of one sample in the output equation of the RPEM affected identification results slightly
in case an explicit dependence of input signals was used in the output equation.
Revision 3: This revision adds a recursive algorithm for initialization of the dynamic prediction error
algorithm. The new algorithm is based on Kalman filter theory, for details see sections 11 and 12.
Installation
The file SW.zip is copied to the selected directory and unzipped. MATLAB is opened and a path is
set up to the selected directory using the path browser. The software is then ready for use.
Note: This report is written with respect to the software, as included in the SW.zip file. It may
therefore be advantageous to store the originally supplied software for reference purposes.
2
Error reports
1. Introduction
Identification of nonlinear systems is an active field of research today. There are several reasons for
this. First, many practical systems show strong nonlinear effects. This is e.g. true for high angle of
attack flight dynamics, many chemical reactions and electromechanical machinery of many kinds, see
e.g. [ 1 ], [ 2 ], [ 3 ], [ 4 ], [5], [6] and the references therein for further examples. Another important
reason is perhaps that linear methods for system identification are quite well understood today, hence
it is natural to move the focus to more challenging problems.
There are already a number of identification methods available for identification of nonlinear
systems. These include grey-box differential equation methods, where numerical integration is
combined with optimization in order to optimize the unknown physical parameters that appear in the
differential equations. An alternative approach is to start with a discrete time black box model, and to
apply existing methodology from the linear field to the solution of the nonlinear identification
problem. This is the approach taken in the NARMAX method and its related algorithms. There, a
least squares formulation can often be found, a fact that facilitates the solution. Other methods apply
neural networks for modeling of nonlinear dynamic systems. See [ 1 ], [ 2 ] and the references therein
for a more detailed survey.
This report focuses on software that implements new nonlinear recursive system identification
methods. Contrary to the above methods, this black box method estimates continuous time parameters
in a general state space model, with a known and possibly nonlinear measurement equation. The main
identification method belongs to the class of recursive prediction error methods (RPEMs) and the
method is of output error type. Advantages include the fact that the stability of the estimated model is
checked by a projection algorithm, at each iteration step. The least squares approaches above cannot
guarantee a resulting stable model - this needs to be checked after the identification has been
completed. A further advantage is that the connection to the physical parameters can be retained to a
greater extent than if a discrete time nonlinear model is used as the starting point. There are also
disadvantages. A major disadvantage with output error methods is that they sometimes converge to a
local sub-optimal minimum point of the criterion function, meaning that careful initialization is
needed. The effect of local minimum points is reduced for the method described in [ 1 ] – [ 4 ], by a
3
method that scales the states, the estimated parameters of the model and, most importantly, the
Hessian of the criterion function. The scaling is implemented by a scaling of the sampling period used
when running the identification algorithm, see [ 1 ] – [ 3 ] for details. One important aspect of this
scaling method is that corresponding un-scaled parameter values can be calculated in a post-
identification step.
The nonlinear identification algorithm is based on a continuous time black box state space model.
This model is structured in that only one right hand side component of the ordinary differential
equation (ODE) model is parameterized as an unknown function. As shown in [ 1 ] and [ 2 ] this
avoids overparameterization. The restriction imposed on the model structure may seem restrictive.
However, it is motivated in [ 1 ] and [ 2 ] that the selected structure can always (locally in the states)
model systems with more general right hand sides, a fact that extends the applicability of the method
significantly. The selected parameterization of the right hand side function of the ODE is a linear-in-
the-parameters multi-variate polynomial in the states and input signals. The approach taken allows for
MIMO nonlinear system identification. The covariance matrix of the measurement disturbances is
estimated on-line.
The second revision of the software package adds an RPEM algorithm for recursive identification
of nonlinear static systems. The algorithm re-uses the parameterization of the nonlinear function used
in the RPEM for identification of nonlinear dynamic systems described above. Most of the code of the
SW package has been re-used, however a number of scripts have been modified and appear in two
versions. This is marked by the inclusion of “Static” in one of the duplicated m-files. All other m-files
can be used as described for the RPEM for identification of nonlinear dynamics. Note that scaling is
not applicable in the static case. The static algorithm is described in sections 9 and 10.
The present revision adds a Kalman filter based algorithm to the software package. The new
algorithm is based on the same model structure as the RPEM for identification of nonlinear dynamic
systems, and is intended to provide initial parameters for the RPEM. Most parts of the scripts and
functions of the previous versions of the SW package can be used in combination with the new
algorithm.
Recursive system identification is a software dependent technology. Hence, when publishing new
methodology in this field, it is relevant to also provide useful software for application of the presented
algorithms. This facilitates a quick practical exploitation of new ideas. The development of the
present MATLABä software package is motivated by this fact.
The present software package is developed and tested using MATLAB 5.3, MATLAB 6.5 and
MATLAB 7.0. The software package does not rely on any MATLAB toolboxes. It consists of a
number of scripts and functions. Briefly, the software package consists of scripts for setup, scripts for
generation or measurement of data, scripts for execution of the RPEM and scripts for generation and
4
plotting of results. There is presently no GUI, the scripts must be run from the command window.
Furthermore, input parameters need to be configured in one or several of the setup scripts, as well as
when running the scripts. In case of data generation by simulation, the ODE that defines the data
generating system must be specified in standard MATLAB style. The software can only be run off-
line, i.e. there is no support for execution in a real time environment. The major parts of the
algorithmic loop can however easily be extracted for such purposes.
The report is organized according to the flow of tasks a user encounters when applying the scripts
of the package. A detailed description of the software is given for the nonlinear dynamic case, the
static case is described more briefly in the end of this report. Before the software is described some
basic facts about the ODE model and the scaling method are reviewed.
( )
T
u( t ) = u1 (t ) ... u1( n1 ) (t ) ... u k (t ) ... u k( nk ) (t )
(1)
( )
T
y m (t ) = y m,1 (t ) ... y m, p (t )
(k )
The superscript denotes differentiation k times. The starting point for the derivation of the model
is the following n :th order state space ODE
æ x (1) ö æ x2 ö
ç 1 ÷ ç ÷
ç M ÷ ç M ÷
ç (1) ÷ = ç x ÷
ç xn −1÷ ç æ
n
÷
ç (1) ÷ ç f ç x1 ,K, xn , u1 ,K, u1(n1 ) ,K, uk ,K, uk( nk ) ,θ ö÷ ÷
è xn ø è è øø
where x = x1 ( ... xn −1 xn ) is the state vector. The following polynomial parameterization of the
T
(
f x1 ,..., xn , u1 ,..., u1( n1 ) ,..., uk ,..., uk( nk ) ,θ )
I (n ) I (n )
I x1 I xn I u1 u 11
Iuk u k
k
( ) ... (u k ) ( )
i (n ) i (n )
... u1( n1 ) ... u k( nk ) = ϕ T (x, u)θ
iu k
u 1
1 u k
k
.
5
Here
æ
θ = çθ0...0 ... θ0... I ( θ0...010 ... θ0...01I ( ...
è n
uk k
) n
uk k
)
T
ö
θ0...0 I (nk − 1)
0 ... θ0...0 I
( n k − 1) I u ( n k )
... θI X ... I n ÷
1 ( k) ø
uk uk k uk
æ (n )
ö
I
uk k
æ
( )
ϕ = çè 1 ... æçè u k( nk ) ö÷
( ) (u ( ) )
I (n ) I ( n −1)
u k
k
ø uk( nk −1)
... ç u k( nk −1) u k( nk ) ÷ ... n k −1 u k
k ...
ç ÷ k
è ø
T
(4)
(
æç u
) (u ) ö÷ ... æçè ( x1 ) ... ( xn ) (u ) ( ) ö÷ ö÷
I ( n −1) I (n ) I (n )
( nk −1) ( nk )
... u ) (nk
I x1 I xn I u1 k
u k u k u
è
k k
ø øø
k
k k 1 k
.
Please see example 5 below for a low order example of the above parameterization. In order to obtain
a discrete time model that is suitable for scaling, the Euler integration method is applied to ( 2 ). The
main reason for using the Euler method is that the sampling appears explicitly and linearly in the right
hand side of the resulting difference equation model ( 5 ) . This is convenient when the scaling
algorithm is introduced. The result of the discretization is
æ x1 (t + TS ,θ ) ö æ x1 (t ,θ ) ö æ x2 ( t , θ ) ö
ç ÷ ç ÷ ç ÷
ç M ÷ ç M ÷ ç M ÷
ç x (t + T ,θ )÷ = ç x (t ,θ )÷ + TS ç xn ( t , θ ) ÷
çç n −1 ÷÷ ç n −1 ç T ÷ (5)
÷
( )
S
è xn (t + TS ,θ ) ø è xn (t ,θ ) ø
ç ϕ x (t ,θ ),K , x (t ,θ ), u (t ),K, u( n k ) (t ) θ ÷
è 1 n 1 k ø
During development of the RPEM described in [ 1 ] - [ 4 ] , it was noticed that problems with
convergence to false local minimum points of the criterion were often highly related to the selection
6
of the sampling period. The sampling period of course needs to be short enough during measurement,
in order to capture the essential dynamics of the identified system. Hence the measurement sampling
period cannot be arbitrarily selected. However, since the sampling period appears explicitly in the
model ( 5 ) and in the corresponding gradient difference equation, it is straightforward to apply
identification algorithms based on ( 5 ) with another, scaled value of the sampling period. This idea
affects the updating of the states, the gradient and any projection algorithm that is used to control the
stability of the model. A scale factor α appears before the multiplication with the sampling period TS
in those three quantities. To explain the details, the scale factor α and the scaled sampling period
æ x1s (t + TS ,θ s ) ö æ x1s (t ,θ s ) ö
ç ÷ ç ÷
ç M ÷ ç M ÷
ç x s (t + T ,θ s )÷ = ç x s (t ,θ s )÷ (8)
ç n −1 ÷
ç x s (t + T ,θ s ) ÷ çç x s (t ,θ s ) ÷÷
S n −1
è n S ø è n ø
æ x 2s ( t ,θ s ) ö
ç ÷
ç M ÷
+ TSScaled ç
xn ( t ,θ s )
s ÷
ç ÷
1 (
ç f x s ( t , θ s ) , K . x s ( t , θ s ) , u ( t ), K , u ( n k ) ( t ) , θ s
è n 1 k )
÷
ø
s
where the superscript denotes scaled quantities. Note that the original sampling period must be
retained in all time arguments, so as to refer to the correct measurement times. The gradient follows
by differentiation of ( 8 ) and ( 9 )
dx s (t + TS ,θ s ) dx s (t ,θ s )
=
dθ s dθ s
æ dx 2s (t ,θ s ) ö æ 0 ö
ç ÷ ç ÷
ç dθ s ÷ ç M ÷
ç M ÷ Scaled ç ÷
0
+ TSScaled ç dx n (t ,θ s )
s
÷ + TS
ç ÷
ç æ s
(
ç θ T ç dϕ x (t ,θ ), u t
s
() ) ö æ dx s ( t , θ s ) ö ÷
÷ç ÷÷
( 10 )
ç T s dθ s
s
÷ ç çè ÷ çè dθ s ÷ø ÷
( )
s
è ϕ x (t ,θ ), u( t ) è dx ø ø
ø
7
dy s ( t , θ s ) dx s ( t , θ s )
(ψ (t ,θ ))
s s
T
=
dθ s
=C
dθ s .
( 11 )
Note that the above change from θ to θ s is not to be treated as a change of variables in the
differentiation leading to ( 10 ) and ( 11 ). The originally derived gradient is applied, but with a scaled
sampling period. The last affected quantity of the algorithm is the projection algorithm that is [1]
æ 0 1 0 L 0 ö
ç ÷
ç 0 0 1 O M ÷
ç M M O O 0 ÷
S s (θ s ) = I n + TSScaled ç ÷
ç 0 0 L 0 1 ÷
ç
ç (θ s )
s
(
T dϕ x ( t ,θ )
s
) ÷
÷
( 12 )
è dx s ø
DM = θ s { (
| eig S s (θ s ) ) < 1 − δ} , δ > 0 ( 13 )
ïì θ (t ) θ s (t ) ∈ D M
s
[θ s (t ) ] DM
= í s
ïîθ (t − TS ) θ s ( t ) ∉ D M
( 14 )
In ( 12 ), S s (θ s ) denotes the linearized system matrix of the model, D M denotes the model set,
here defined as the asymptotically stable models with a margin δ to the stability limit. The last
equation stops the updating of the parameter vector in case the update would result in values outside
the model set. Other details of an RPEM where the scaling algorithm is used can be found in [ 1 ] – [
4].
When a scaled value of the sampling period is applied, the algorithm still attempts to minimize the
criterion, thereby obtaining other minimizing parameter values than when the true sampling period is
used. When testing the scaling algorithm experimentally, dramatic improvements were sometimes
observed in the algorithmic behavior. Convergence speeds could be improved and initial values that
lead to divergence and instability could be made to work well.
The application of the scaling algorithm results in other estimated parameter values than what
would be obtained without scaling. Fortunately, as shown in [ 2 ], the original parameters can be
calculated from the estimated ones. The transformation is given by a diagonal transformation matrix
that is a function of the applied scale factor. The analysis of the effect of the scaling is continued in [
3 ] , where the effect of the conditioning of the Hessian of the criterion function is analysed in detail.
8
This shows that the effect of the scaling is quite dramatic. Changes of the condition number by several
orders of magnitude were obtained there, for a simple simulated second order example.
9
2. In case the user is to perform live measurements, all the steps of the Live data measurement group
should be executed first. The user can then proceed directly to use the groups Recursive
Identification and Preparation and display of results.
3. In case the user intends to use simulated data, this data can be generated by execution of the
scripts and functions of the group Simulated data generation. The user can then proceed directly
to use the groups Recursive Identification and Preparation and display of results.
10
Live data measurements Simulated data generation
Live Simulated
measurements measurement generation
MeasurementMain.m GenerateData.m
Result evaluation Result preparation Result evaluation Result evaluation Result evaluation
PlotCondition.m SimulateModelOutput.m PlotParameters.m PlotPredictionErrors.m PlotEigenvalues.m
Figure 1: MATLAB scripts, functions and their relations in terms of execution order.
11
4.2 Restrictions
The main restrictions of the software are
• The software is command line driven - no GUI support is implemented.
• The software does not support true real time operation - there is no real time OS support
implemented.
• The software has been tested and run using MATLAB 5.3, MATLAB 6.5 and MATLAB 7.0.
12
.. .
x( t ) + x( t ) + ( 2 + u( t )) x = u( t )
y( t ) = x( t ) + e( t ). ( 15 )
This system is also used in [ 3 ], to asses effects of scaling. This system can be written in state space
form as
æ . ö æ
ç x1( t ) ÷ ç x2 ( t )( 2 + u( t )) − u( t )ö÷
ç . ÷ = çè − x ( t ) − x ( t ) ÷ø
è x2 ( t )ø 1 2
( 16 )
y( t ) = x2 ( t ) + e( t ) .
Note that the ordering of states is not exactly as defined in the model ( 2 ). This is intentional since
such situations are common in practical situations. It can be seen that the system is oscillatory with an
input amplitude depending resonance frequency and damping.
The relevant parts of the files f.m and h.m become
f.m
function [f]=f(t,x,u,w)
f(1,1)=x(2,1)*(2+u(1,1))-u(1,1);
f(2,1)=-x(1,1)-x(2,1);
end
h.m
function [h]=h(t,x,u,e);
h=x(2,1)+e(1,1);
end
amplitude, with a mean of 0, a range [ − 1,1] and a clock period 3.0s. The measurement disturbance is
to be white, zero mean with a standard deviation of 0.1.
The setup script that performs this task is SetupData.m
% dimensions...
13
% Input signal related...Type may be selected among:
%
% InputType=[
% 'PRBS ';
% 'Gaussian ';
% 'UniformPRBS';
% 'SineWave ';
% 'Custom '];
InputType=[
'UniformPRBS'];
uAmplitude=[
1.0];
uMean=[
0];
uFrequency=[
0.1];
ClockPeriod=[
30];% Clock period vector in terms of sampling time
DisturbanceTypeSystem=[
'WGN ';
'WGN '];
wSigma=[
0.0;
0.0]; % Gaussian system noise standard deviation (discrete time)
wMean=[
0;
0];
wSineAmplitude=[
0;
0];
14
wSineFrequency=[
0;
0];
DisturbanceTypeMeasurement=[
'WGN '];
eSigma=0.1; % Gaussian measurement noise standard deviation
eMean=[
0;
0];
eSineAmplitude=[
0];
eSineFrequency=[
0];
% ODE related...
The final step of the data generation is to execute the files SetupData.m and GenerateData.m.
This is done in the MATLAB command window as follows
» SetupData
» GenerateData
…
15
percentReady =
100
»
16
The measurement process is started by typing
» SetupData
» GenerateData
…
in the MATLAB command window. During the measurement session, the script continuously displays
the time, the inputs as well as the measured outputs, as commanded to DA-converters and read by
AD-converters. After termination all data that is needed for identification is available in the
MATLAB workspace.
1
y(1)
-1
-2
0 200 400 600 800 1000
time [s]
1
0.5
u(1)
-0.5
-1
0 200 400 600 800 1000
time [s]
17
6. Recursive Identification – RPEM ODE case
At this point everything is in place for a first identification run.
value of the R -recursion, the initial value of the measurement covariance matrix Λ ( t ) , the
stability limit applied by the projection algorithm, the scale factor, as well as the down-sampling
period used to avoid too large logs during long runs with high degree models. The reader is
referred to [ 1 ] - [ 4 ] for details on these parameters, as well as on their use.
3. Executes SetupRPEM.m. This loads the necessary parameters into the MATLAB workspace.
Example 4: The system is to be identified with a second order model. The projection algorithm is
to use a stability radius of 0.975 and the scale factor is selected equal to 2. The initial value of the
measurement covariance matrix is selected equal to 0.1. The initial value of the R - recursion ( its
inverse affecting the initial algorithmic gain) is selected equal to 100. The selection of the gain
dhdx_m.m
function [dhdx_m]=dhdx_m(x,u);
dhdx_m=[1 0];
end
18
The setup script SetupRPEM.m becomes
nx=2;
x_m_0=[0.5 -1]';
%
% Remaining initial values
%
%
% Parameters
%
19
6.2 RPEM command window control and estimated parameters
In order to perform an identification run the user is required to execute and provide input to the script
RPEM.m. The execution of this script makes use of four additional functions, implementing the
polynomial model applied for modeling of the RHS of the ODE. These functions are f_m.m,
dfdx_m.m, dfdtheta_m.m and GenerateIndices.m. The latter function generates the exponents of
all factors of all terms of the polynomial expansion. The generation of these indices involves nested
loops. They are therefore calculated in advance and used in repetitive calls in the form of a table.
To identify the system, the user is required to
1. Execute the script RPEM.m
2. Provide the degrees of the polynomial model (polynomialOrders) when prompted. The
polynomialOrders variable is a column vector with the first element corresponding to the maximal
degree of x1 , the second element corresponding to the maximal degree of x2 and so on. The last
element corresponds to the maximum degree of the derivative of highest degree of the last input
signal component. In the present example, polynomialOrders = [1 2 3]' would mean that the
2 3
highest degree term of the polynomial expansion is θ123 x1 x2 u .
3. Provide a list of indices that are not to be used (notUsedIndices) by the algorithm. The indices
exclude terms in the polynomial expansions. Providing an empty matrix ([]) indicates that no terms
shall be excluded. The list of not used indices are to be provided as rows in a matrix , where the
number of rows equals the number of terms that are to be excluded from the model. In the present
example notUsedIndices = [0 0 0; 1 1 1] would mean that the terms θ000 and θ111x1x2 u are to be
excluded from the model.
4. Provide the initial parameter vector (theta_0). Note that this parameter vector needs to correspond
to a linearized system with all poles within the stability radius indicated by the script
SetupRPEM.m. If the initial parameter vector does not meet this criterion the user is prompted for
theta_0 again. Observe that the scale factor of the sampling period needs to be accounted for - it is
a part of the linearized model, cf. [ 1 ].
Note: A good strategy is to initialize the algorithm with a model that has time constants and a static
gain that are similar to those of the system.
Example 5: The algorithm is in this example initialized with
ϕ ( x , u) = (1 u x2 x1x2 u) .
T
x2 u x1 x1u x1x2 ( 18 )
20
In this example comments and explanations have been added. To distinguish these from the actual
commands the comments are in italics. The command sequence applied in the MATLAB command
window is
» RPEM
ans =
Input polynomialOrders and notUsedIndices - The script asks for the max degrees of states and inputs
K» polynomialOrders=[1 1 1]'
polynomialOrders =
1
1
1
K» notUsedIndices=[] - The script asks for terms of the polynomial that are to be excluded
notUsedIndices =
[]
K» return
allIndices = - The script returns the degrees of all included terms, input degrees to the right
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
ans =
Input theta_0 - The script asks for an initial parameter vector
K» theta_0=[0 1 -1 0 -0.25 0 0 0]'
theta_0 =
0
1.0000
-1.0000
0
-0.2500
0
0
0
21
K» return
LinearizedPoleRadii = - The script returns the polr-radii of the linearized, initial model
0.9000
0.9000
…
percentReady = - The script displays the fraction of the processing that is completed.
100
ans = - The script displays the identified parameters – scaled parameters to the left
0.0003 0.0013
0.2508 1.0031
-0.4946 -0.9893
-0.0018 -0.0035
-0.4992 -1.9968
-0.2512 -1.0050
0.0163 0.0326
-0.0174 -0.0347
»
The estimated parameters of the left column correspond to the ones obtained directly from the RPEM,
i.e. these are scaled parameters. The right column contain parameters that are recomputed to
correspond to the original sampling period. Note that the exact result depends on the generated input
signal. This may differ between systems and execution occasions since the seed for the random
number generator may differ. Hence, slight variations of the estimated parameters are normal.
22
In order to perform a new RPEM run with modified degrees, then user is required to
1. Run the script reInitiate.m. That script prompts the user for polynomialOrders and
notUsedIndices. The parameter vector at the end of the run, together with the previous and new
degrees, are then used to re-initiate all relevant quantities of the RPEM.
2. Rerun RPEM.m. Note that the RPEM does not need to prompt the user for any further information
this time.
Example 6: In this example the degree of the input signal is increased to 2.
The MATLAB command window commands become
» reInitiate
ans =
Input polynomialOrders and notUsedIndices
K» polynomialOrders=[1 1 2]'
polynomialOrders =
1
1
2
K» return
» RPEM
…
The identification is now finalized and everything is set for display of the results.
7.1 Parameters
In order to plot the parameters the user is required to
1. Execute the script PlotParameters.m. The components of the parameter vector are then plotted as
a function of time. Note that the time scale is assumed to be seconds. In case another time scale is
required, the figure needs to be edited after plotting, or the script needs modification.
Example 7: The command in the MATLAB command window is
» PlotParameters
»
The following plot is then generated
23
1.5
0.5
parameters
-0.5
-1
-1.5
0 200 400 600 800 1000
time [s]
24
1.5
0.5
prediction error (1)
0
-0.5
-1
-1.5
-2
0 200 400 600 800 1000
time [s]
7.3 Eigenvalues
In order to plot the convergence of the eigenvalues over time, the user is required to
1. Execute the script PlotEigenvalues.m. The eigenvalues of the Hessian are then plotted as a
function of time. Note that the time scale is assumed to be seconds. In case another time scale is
required, the figure needs to be edited after plotting, or the script needs modification.
Example 9: The MATLAB command window command is
» PlotEigenvalues
»
The following plot is generated
25
3
10
2
10
0
10
-1
10
-2
10
0 200 400 600 800 1000
time [s]
26
4
10
2
10
1
10
0
10
0 200 400 600 800 1000
time [s]
27
1. Execute the script PlotModelOutput.m. The output signals of the model are then plotted as a
function of time. Note that the time scale is assumed to be seconds. In case another time scale is
required, the figure needs to be edited after plotting, or the script needs modification.
Example 12: The MATLAB command window command is
» PlotModelOutput
»
The following plot is generated
1
y m(1)
-1
-2
0 200 400 600 800 1000
time [s]
1
0.5
u(1)
-0.5
-1
0 200 400 600 800 1000
time [s]
28
2
-1
-2
0 200 400 600 800 1000
time [s]
1
0.5
u(1)
-0.5
-1
0 200 400 600 800 1000
time [s]
29
1.5
0.5
-0.5
-1
-1.5
-2
0 200 400 600 800 1000
time [s]
The user is referred to [ 1 ], [ 6 ] and the references therein for further details. In order to compute
the loss function, using parameters at the end of the identification run, the user is required to
1. Execute the script ComputRPEMLossFunction.m. The loss function is then computed.
Example 15: The MATLAB command window command is
» ComputeRPEMLossFunction
…
percentReady =
100
30
V=
-1.7094
»
Note: Another relevant measure to use is the sum of the squared prediction errors.
31
0.2
mean residual
0.1
-0.1
-0.2
-3 -2 -1 0 1 2 3
y(1)
1500
number of samples
1000
500
0
-3 -2 -1 0 1 2 3
y(1)
The RPEM for identification of MISO static nonlinear systems is based on the model
(
f u1 ,..., u1( n1 ) ,..., u k ,..., u k( nk ) , θ )
I (n ) I (n )
Iu1 u 1 I uk u k
(u )
1 k
( ) ... (u k ) ( )
i (n ) i (n )
... u1( n1 ) ... u k( nk )
iu k
u 11 u k
k = ϕ T ( u)θ
.
Here
æ
θ = çθ0...0 ... θ0... I ( θ0...010 ... θ0...01I ( ...
è n
uk k
) n
uk k
)
T
ö
θ0...0 I ( 0 ... θ0...0 I ( n −1) I ( n ... θI u1 ... I ( n ) ÷
uk k ø
n −1 ) )
uk k uk k uk k
æ (n )
ö
I
uk k
æ
( )
ϕ = ç 1 ... æçè u k( nk ) ö÷
( ) (u ( ) )
I (n ) I ( n −1)
u kk
ø uk ( nk −1)
... ç u k( nk −1) u k( nk ) ÷ ... n k −1 u k
k ...
è ç ÷ k
è ø
32
( )
T
(
æç u ( nk −1)
) (u ) ö÷ ... æçè (u1 ) 1 ... u k( nk ) ö÷ ö÷
I ( n −1) I (n ) I (n )
u k ( nk ) u k
Iu
u
k
øø
k k k
è k k ø
.
(21)
The recursive algorithm is then developed exactly as in [1] and [2]. The main difference is that the
state equation iteration and the corresponding state gradient iteration disappears. The end result is the
following algorithm where all variables are explained in detail in [1] and [2]
ε ( t ) = y m ( t ) − y( t )
µ( t )
Λ (t ) = Λ (t − TS ) +
t
(
ε (t )ε T (t ) − Λ (t − TS ) )
µ( t )
R (t ) = R (t − TS ) +
t
(
ψ (t )Λ−1(t )ψ T (t ) − R (t − TS ) )
µ ( t ) −1
[
θ(t ) = θ(t − TS ) + R (t )ψ ( t )Λ −1 (t )ε (t )]
t
æ æ
I
(n
uk k
)
ö
ϕ ( t ) = çç 1 ... æçè u k( nk ) (t ) ( ) ö÷
( )( )
I (n )
u kk
ø uk ( nk −1)
(t ) ... ç u k( nk −1) ( t ) u k( nk ) ( t ) ÷ ...
ç ÷
è è ø
(u ( ( t )) (
... æçè u k( nk −1) (t ) ) (u ( ( t )) ö÷
(
... æçè (u1 (t )) 1 ... uk( nk ) (t ) ) ö÷ ö÷
I ( n −1 ) I ( n −1 ) I (n ) I (n )
nk −1) u k u k nk ) u k
Iu
u k
... k
k k
k
k
ø
k
øø
y(t + TS ) = ϕ T ( t )θ
ψ (t + TS ) = ϕ (t + Ts ) . ( 22 )
It should be noted that this algorithm collapses to a least-squares case. Hence it will always converge.
All software for identification of nonlinear static systems fits into the framework of Figure 1. As
much as possible of the software has been kept usable for both the nonlinear dynamic case and the
nonlinear static case. However, static versions of the following 7 scripts replace or add to the dynamic
counterparts, in case a static model is identified: dhdthetaStatic_m.m (new m-file),
GenerateDataStatic.m, hStatic_m.m, RPEMStatic.m, SetupDataStatic.m, SetupRPEMStatic.m
and SimulateModelOutputstatic.m. These files are now briefly described.
SetupDataStatic.m: This m-file sets up the parameters needed for static data generation. The file has
been modified by selection of parameters needed for dynamic data generation consistent with the
33
static case. Most variables are however left as dummy variables, so that SetupDataStatic.m does not
prevent the successful execution of existing scripts later in the data processing chain.
GenerateDataStatic.m: This file has been created from GenerateData.m by deletion of the state
iteration. Note that this script makes use of h.m that must be based only on input signals in the static
case. The state argument in the call is an empty matrix.
SetupRPEMStatic.m: This file has been created from SetupRPEM.m by setting the state dimension
equal to zero, by setting state initial values equal to a 0x1 matrix, and by setting the sampling period
scale factor scalingTs equal to 1. The latter is important since no scaling shall be applied in the static
case.
RPEMStatic.m: This file has been created from RPEM.m by deletion of the parts of the algorithm
that are not relevant in the static case. This is true for the state variable iteration and the
corresponding state gradient iteration. The exact details follow by a comparison of the RPEM of [2]
with (22) above. A further modification is the use of calls to the functions hStatic_m.m and
dhdthetaStatic_m.m, in order to compute output predictions and gradients.
hStatic_m.m: This function computes (20) above. It was created by small modifications of f_m.m.
The order of the output prediction (1) is e.g. included in the function call.
DhdthetaStatic_m.m: This function generates ϕ of (21). It was cretaed by small modifications of
dfdtheta_m.m. The order of the output prediction (1) is e.g. included in the function call.
SimulateModelOutputStatic.m. This file has been created from SimulateModelOutput.m by
deletion of the state variable iteration and by a call to the function hStatic_m.m for computation of
the output prediction.
The Kalman filter based algorithm for initialization of the RPEM (dynamic case) is based on (3) just
like the RPEM. The recursive algorithm is then developed exactly as in [ 5 ] and [ 6 ]. The end result
is the following scheme where all variables are explained in detail in [ 5 ] and [ 6 ]
Initiate
Iterate
K (t ) = P (t | t − TS ) H T ( HP(t | t − TS ) H T + R2 ) −1
x (t | t ) = x (t | t − TS ) + K (t )( y m (t ) − Hx (t | t − TS ))
34
P(t | t ) = P (t | t − TS ) − K (t ) HP(t | t − TS )
x (t + TS | t ) = F (t , ξ (t ), u (t )) x (t )
P (t + TS | t ) = F (t , ξ (t ), u (t )) P (t | t ) F T (t , ξ (t ), u (t )) + R1
( 23 )
It should be noted that this algorithm is similar to a least squares problem, solved recursively. Hence
(23) will always converge. The key ides to obtain the algorithm is to replace the estimated states of
the RPEM by an approximation ξ ( t ) , obtained by repeated differentiation of the output signal.
To use the Kalman filter based initialization algorithm the following steps are required. Please note,
that since this algorithm is based on the same model structure as the dynamic RPEM in section 6 some
of the information is identical.
R2 , the scale factor, as well as the down-sampling period used to avoid too large logs during long
runs with high degree models. The reader is referred to [ 1 ] - [ 6 ] for details on these parameters,
as well as on their use.
3. Executes SetupInit.m. This loads the necessary parameters into the MATLAB workspace.
Example 17: The system (15) is to be identified with a second order model, which implies that the
true parameter and corresponding regressor vectors are
35
θ = (0 1 − 1 0 − 2 − 1 0 0 )
T
( 24 )
ϕ ( x , u) = (1 u x2 x1x2 u) .
T
x2 u x1 x1u x1x2 ( 25 )
The scale factor is selected equal to 2. The magnitude of the state and parameter disturbance
covariance are selected to 0.01 and 0.001 respectively, while the measurement covariance matrix is
selected equal to 1. The initial value of the P- recursion is selected equal to 0.1. The functions
h_m.m and dhdx_m.m become
h_m.m
function [h_m]=h_m(x_m,u);
h_m=x_m(1,1);
end
dhdx_m.m
function [dhdx_m]=dhdx_m(x,u);
dhdx_m=[1 0];
end
%
% Remaining initial values
%
y_m_0=[x_m_0(1)];
scaleFactorP=1e-1;
%
% Parameters
%
36
downSampling=10; % The downsampling factor used when data from the
run is saved
scalingTs=2; % The scaling factor with which the sampling period is
multiplied during identification
37
stability region as described in section 6. If this is not the case it will not be possible to use the
obtained parameter vector for initializing the RPEM Observe that the scale factor of the sampling
period needs to be accounted for - it is a part of the linearized model, cf. [ 1 ].
Example 18: In this example the same system as in Example 17 is studied. The algorithm is in
this example initialized with
θˆ(0 ) = (0 0 0 0 0 0 0 0 )T . (26 )
ϕ ( x , u) = (1 u x2 x1x2 u) .
T
x2 u x1 x1u x1x2 (27 )
In this example comments and explanations have been added. To distinguish these from the actual
commands the comments are in italics. The command sequence applied in the MATLAB command
window is
>> Init
ans =
Input polynomialOrders and notUsedIndices - The script asks for the max degrees of states and inputs
K>> polynomialOrders=[1 1 1]'
polynomialOrders =
1
1
1
K>> notUsedIndices=[]
notUsedIndices =
[]
K>> return
allIndices = - The script returns the degrees of all included terms, input degrees to the right
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
ans =
Input theta_0 - The script asks for an initial parameter vector
K>> theta_0=zeros(8,1)
38
theta_0 =
0
0
0
0
0
0
0
0
K>> return
…
percentReady = - The script displays the fraction of the processing that is completed.
100
LinearizedPoleRadii=
0.9956
0.9956
ans = - The script displays the identified parameters – scaled parameters to the left
-0.0000 -0.0000
0.2451 0.9805
-0.2452 -0.4904
-0.0002 -0.0004
-0.4902 -1.9607
-0.2450 -0.9800
0.0002 0.0004
-0.0005 -0.0010
»
The estimated parameters of the left column correspond to the ones obtained directly from the RPEM,
i.e. these are scaled parameters. The right column contain parameters that are recomputed to
correspond to the original sampling period. Note that the exact result depends on the generated input
signal. This may differ between systems and execution occasions since the seed for the random
number generator may differ. Hence, slight variations of the estimated parameters are normal.
39
1. Run the script reInitiate.m. That script prompts the user for polynomialOrders and
notUsedIndices. The parameter vector at the end of the run, together with the previous and new
degrees, are then used to re-initiate all relevant quantities of the RPEM.
2. Run the SetupRPEM.m file, as described in section 6.
3. Rerun RPEM.m. Note that the RPEM does not need to prompt the user for any further information
this time.
Here, reinitiate.m is used in exactly the same way as described in section 6.3. Note, however, that the
model structure is normally not changed when the initialization algorithm is used in combination with
the RPEM, as the initial parameters are given for a specific model structure. By changing the model
structure between the initialization and RPEM algorithms, the benefits of an initialization algorithm
may be lost or significantly reduced.
13. Summary
This report describes a software package for identification of nonlinear systems. Future work in this
field, that result in useful MATLAB routines, will be integrated with the presently available
functionality. Updated versions of this report will then be made available.
14. References
[ 2 ] T. Wigren, "Recursive prediction error identification and scaling of nonlinear state space models
using a restricted black box parameterization", accepted for publication in Automatica.
[ 4 ] T . Wigren "Recursive identification based on nonlinear state space models applied to drum-
boiler dynamics with nonlinear output equations", in Proceedings of IEEE ACC 2005, Portland,
Oregon, U.S.A., pp. 5066-5072, June 8-10, 2005.
[5] L.Brus and T. Wigren "Constrained ODE modeling and Kalman filtering for recursive
identification of nonlinear systems", in Proceedings of SYSID 2006, Newcastle, Australia, pp. 997-
1002, March 29-31, 2006.
40
[ 6 ] L. Brus, T. Wigren and B. Carlsson "Initialization of a nonlinear identification algorithm applied
to laboratory plant data", submitted to IEEE Trans. Contr. Sys. Tech., 2006.
[ 8 ] L. Ljung and T. Söderström. Theory and Practice of Recursive Identification. Cambridge, Ma:
MIT Press, 1983.
[ 9 ] T. Wigren, "User choices and model validation in system identification using nonlinear Wiener
models", Prep. 13:th IFAC Symposium on System Identification , Rotterdam, The Netherlands, pp.
863-868, August 27-29, 2003. Invited session paper.
[ 10 ] T. Wigren, “MATLAB software for recursive identification and scaling using a structured
nonlinear black—box model – revision 1”, Technical Reports from the department of Information
Technology 2005-002, Uppsala University, Uppsala, Sweden, January, 2005.
[ 11 ] T. Wigren, “MATLAB software for recursive identification and scaling using a structured
nonlinear black—box model – revision 2”, Technical Reports from the department of Information
Technology 2005-022, Uppsala University, Uppsala, Sweden, August, 2005.
41