# The Observer/Kalman System Identification Procedure Explained

Previously, we have had a look at the Eigensystem Realisation Algorithm (ERA) by Joung and Pappa . This algorithm allows us to find the parameters for a linear, time-invariant (LTI) system in discrete-time from measurements of the impulse response.

What, however, do we do when we don’t have measurements of the impulse response? We might not want to hit our system too hard, or have measurements with non-trivial inputs. Maybe we cannot wait for our system to return to a zero state before applying the impulse.

Again, Professor Steve Brunton came to the rescue with two videos on the Observer/Kalman System Identification procedure (or OKID for short) in his series on data-driven control:

Unfortunately, Prof. Brunton skips over the details and only gives a very short overview. Yet, I always try to understand the details of the methods I apply — if not for being able to assess when they may be used, then to learn about the principles being applied.

So I had a look into the papers by a group around Jer-Nan Juang, Minh Phan, Lucas G. Horta and Richard W. Longman, in which the OKID was introduced . And again, there are some clever ideas in there that I found quite enlightening regarding handling the descriptions of dynamic systems:

• The basic approach of the OKID uses the fact that the response of an LTI to any input is related to the output by convolution of the impulse response.
• By reshaping the measurement data, a linear equation between said impulse response and the measurement data is established.
• This linear equation is solved using an ordinary least-squares approach.

The basic approach only works for asymptotically stable systems which approach zero state fast enough. However, there is a extension for non-stable or too slow systems: Instead of identifying the system itself, the OKID uses a modified system which is made asymptotically stable by a Luenberger observer , and then reconstructs the impulse response of the original system from the modified system.

Finally, this observer extension also leads to the “Kalman” part in the name for this procedure: The observer that is identified “on the go” this way turns out to be an optimal Kalman filter  given the amount of noise seen on the measurements.

So, all in all, the whole approach is quite ingenious. However, it’s not as complicated as Professor Brunton makes it sound, and we’ll briefly go over it and its basic ideas in this article.

## Review: Impulse Response

As for the ERA, we are dealing with discrete-time LTI systems. But different from previously, we’ll directly consider a Multiple Input, Multiple Output (MIMO) system.

The dynamics of this system shall be defined by the following recurrence equation:

(1) Note that this time we also consider the case where the output is directly influenced by the output via the matrix . Now, let’s assume that we have an input sequence and observe the system starting at time step . We can determine the state (with ) to be

(2) This can be verified by complete induction. For the case we get .

For we get

(3) By extension, we can give the following expression for the output :

(4) Here, we define the column vector by stacking the inputs at time steps above each other:

(5) The matrix gives us the so-called Markov-Parameters of length , and when reversed, gives the impulse response of the system. If we had these Markov-Parameters, we could extract the system matrices with the help of the Eigensystem Realisation Algorithm (ERA).

## Handling Asymptotically Stable Systems

For an asymptotically stable system, the term approaches zero for increasing values of . Thus, for some sufficiently large we may assume that .

This helps us in simplifying Equation 4

(6) Now, we can aggregate this into a larger equation:

(7) With measurements (ideally, we have ) we can thus find by solving the equation above. Usually, this will be done using an ordinary least-squarey approach.

## Handling Insufficient Stability

In the previous section, we assumed that the system we measure is asymptotically stable and is sufficiently damped so that we can have our measurement count sufficiently large relative to the length of our impulse response . So how do we handle systems where this is not the case?

### Stabilisation Using a Luenberger Observer

The idea presented by Juang, Phan, Horta and Longman is quite simple: To arbitrarily choose the eigenvalues of the observed system, they construct a Luenberger observer. In general application, such an observer aims to reconstruct the internal state of a system from knowledge about the internal dynamics, about the inputs to the system and the measurements obtained from the system. It has the following structure:

(8) In this case, and represent the state of the observer, which according to the construction of the observer shall follow the state of the original system. The observer state is adjusted using the correction term .

Usually, when constructing a Luenberger observer, we choose given our knowledge about the original system in such a way that the observation error is asymptotically stable, i.e. approaches zero. The dynamics of this error are described as follows:

(9) Given a completely observable system, we can select in such a way that the eigenvalues of these error dynamics can be set arbitrarily. However, these eigenvalues also become the eigenvalues of the observer system, allowing us to arbitrarily stabilise it.

In our case, we want the observer state to be equal to the actual state, so we set , and arrive at the new state equations:

(10) These equations describe the exact same system as in Equations 1 and ??, but with the current output of the system fed back into the system in such a way that the observed state always equals the actual system state. With this little trick, we have created a stable system to identify.

To find the Markov-Parameters of the new system, we simply apply the algorithm we used for sufficiently stable systems. This time, we use as input, which combines both the actual input and our measurement.

However, there’s one thing we need to be careful about: is not completely unconstrained in this problem. Indeed, its second part must be . If we were to allow non-zero values there, the best fit would be , with all other system matrices being zero. This system would just forward the input into its output. This would of course be a perfect fit — but it would not properly represent our system.

So instead, we have to find the best fit for

(11) Note how all rows consist of pairs of input and output, but the last row consists only of the input? This way, the identified system cannot feed through the measured output to its output, and instead the equation identifies the dynamics of the system we want to identify.

The result, however, does not yet represent the Markov-Parameters of our observer. Instead, it has the form

(12) For recovery of the Markov-Parameters of the original system, this is quite inconsequential (we just have to be careful in the implementation). If we wanted to actually have the Markov-Parameters of the observer — which we might, as we will see when we look at the specific properties of that observer — then we would have to restructure the response as follows by appending an appropriately sized zero-matrix at the end:

(13) ### Recovery of Original Markov-Parameters

But how do we get the Markov-Parameters of the original system? Again, Juang et al provide us with a little trick. Let’s first look at the structure of our stabilized Markov-Parameters:

(14) with

(15) Now, it is quite straightforward to extract from . For the others, we find that

(16) For , we can immediately recover :

(17) For we first expand the last element of the power:

(18) Looking further, we can identify a pattern:

(19) The reader is encouraged to prove this identity by complete induction over . Hint: First prove for the following, more general identity:

(20) With a few more steps Equation 19 follows for .

Thus, the Markov-Parameters can be easily retrieved from Equation 19.

## Why Kalman?

Now we know how the term “observer” got into the name. But how did “Kalman” end up there?

When we described the observer that we would use as model, we actually described a very specific observer, namely one that would immediately provide the same output as the actual system. The authors of the OKID paper  use the term “deadbeat observer” for this. This is the fastest possible observer for a discrete time system. Any faster, and the observer would predict the output of the system, violating causality.

Indeed, later in the paper, the authors show that this deadbeat observer is identical with the Kalman filter one would find given the variance of noise seen in the measurement. A more detailed explanation of their proof might follow in a later article.

Thus, extracting not only the original Markov Parameters, but also the parameter for the observer may be very beneficial if one wanted to design a Kalman filter for the system.

How do we get the system parameters for this Kalman filter? Well, we already have its Markov parameters, given by , and can use the ERA on them. That gives us dynamics matrices for a Kalman filter.

## Example

Let’s apply this method to our spring pendulum example from the ERA article. Remember: We had a horizontal spring pendulum with the following setup:

Different from the case with ERA, we now use an arbitrary input signal (which is the force applied to the mass), and determine the output signal. Again, we simulate the system and add noise to the output. The result is shown in the following figure.

The input is a pseudorandom binary sequence (PRBS). Such sequences can be generated, e.g., using the max_len_seq function from the SciPy signal processing library.

As we know from the ERA experiments, our pendulum is quite stable, so we can use the method for asymptotically stable systems. The result is shown in the following figure:

It seems that the estimate fits the actual impulse response (this time without noise) quite well. However, we’re in a dilemma:

• If we increase the length of our estimated impulse response, we reduce the amount of data we have available to counter all the noise, and thereby also the quality of our estimate.
• If we decrease the length of our estimated impulse response, we get a better estimate, but we have less data for our ERA procedure.

So we need to find a good compromise there by playing with the length of our estimated impulse response.

## Conclusion

We have seen that the idea of the OKID procedure is not as involved as one might believe. The basis are three very simple ideas:

• The Markov Parameters determine the impulse response, and thereby define the input-output relationship — together with the initial state.
• For asymptotically stable systems, the influence of the initial state diminishes over time, eventually becoming so small that we can ignore it.
• Not sufficiently asymptotically stable systems can be made stable by considering a Luenberger observer in their place. The problem is then reduced to identifying the Markov Parameters for this observer, and retrieving the Markov Parameters for the original system from this intermediate result.
• The observer such identified actually is a Kalman filter for the system, given the noise seen in the measurement.

It seems useful to always use the observer-enhanced procedure by default. Even for sufficiently asymptotically stable systems the use of the observer would reduce and thus the amount of measurements required.

Now, finally, this opens up a lot of new possibilities for system identification: We can use the response to any set of inputs to determine the system model. This also allows us to identify a system that already is subject to control and where it would be impractical or impossible to remove that control. One simple example are flight-tests with an already controlled multicopter to improve the controller, but another would be to identify the progression of a disease without having to stop treatment (which of course would be unethical).

To take the design of a multicopter as an example, we could simply record in-flight data from sensors as well as the control inputs sent to our engines, and use that to improve our already existing model. We do not even have to provide specific inputs, but just a general recording of flight data will help, as long as it was rich enough. J. Juang and R. S. Pappa, “An Eigensystem Realization Algorithm for Modal Parameter Identification and Model Reduction,” Journal of guidance control and dynamics, vol. 8, iss. 5, 1985.
[Bibtex]
@Article{Juang.Pappa1985,
author = {Juang, Jer-Nan and Pappa, Richard S.},
title = {{A}n {E}igensystem {R}ealization {A}lgorithm for {M}odal {P}arameter {I}dentification and {M}odel {R}eduction},
journal = {Journal of Guidance Control and Dynamics},
year = {1985},
volume = {8},
number = {5},
month = nov,
abstract = {A method called the eigensystem realization algorithm is developed for modal parameter identification and model reduction of dynamic systems from test data. A new approach is introduced in conjunction with the singular-value decomposition technique to derive the basic formulation of minimum order realization which is an extended version of the Ho-Kalman algorithm. The basic formulation is then transformed into modal space for modal parameter identification. Two accuracy indicators are developed to quantitatively identify the system and noise modes. For illustration of the algorithm, an example is shown using experimental data from the Galileo spacecraft.},
doi = {10.2514/3.20031},
file = {:Juang.Pappa1985 - An Eigensystem Realization Algorithm for Modal Parameter Identification and Model Reduction.pdf:PDF},
} J. Juang, M. Phan, L. G. Horta, and R. W. Longman, “Identification of Observer/Kalman Filter Markov Parameters: Theory and Experiments,” , Hampton, Virginia 23665, techreport 104069, 1991.
[Bibtex]
@TechReport{Juang.Phan.ea1991,
author = {Jer-Nan Juang and Minh Phan and Lucas G. Horta and Richard W. Longman},
title = {{Identification of Observer/Kalman Filter Markov Parameters: Theory and Experiments}},
year = {1991},
type = {techreport},
number = {104069},
month = jun,
abstract = {An algorithm to compute Markov parameters of an observer or Kalman filter from experimental input and output data is discussed. The Markov parameters can then be used for identification of a state space representation, with associated Kalman gain or observer gain, for the purpose of controller design. The algorithm is a non-recursive matrix version of two recursive algorithms developed in previous works for different purposes. The relationship between these other algorithms is developed. The new matrix formulation here gives insight into the existence and uniqueness of solutions of certain equations and gives bounds on the proper choice of observer order. It is shown that if one uses data containing noise, and seeks the fastest possible deterministic observer, the deadbeat observer, one instead obtains the Kalman filter, which is the fastest possible observer in the stochastic environment. Results are demonstrated in numerical studies and in experiments on an ten-bay truss structure.},
doi = {10.2514/6.1991-2735},
file = {:Juang.Phan.ea1991 - Identification of Observer_Kalman Filter Markov Parameters_ Theory and Experiments.pdf:PDF},
keywords = {ALGORITHMS; CONTROL THEORY; CONTROLLERS; KALMAN FILTERS; STOCHASTIC PROCESSES; SYSTEM IDENTIFICATION; TRUSSES; MATRICES (MATHEMATICS); SELECTION; UNIQUENESS},
owner = {ralfg},
school = {NASA Langley Research Center},
timestamp = {2019-09-11},
url = {https://ntrs.nasa.gov/search.jsp?R=19910016123},
} M. Phan, J. N. Juang, and R. W. Longman, “Identification of Linear Multivariable Systems by Identification of Observers with Assigned Real Eigenvalues,” Journal of the astronautical sciences, vol. 40, iss. 2, p. 261–279, 1992.
[Bibtex]
@Article{Phan.Juang.ea1992,
author = {M. Phan and J.N. Juang and R.W. Longman},
title = {{Identification of Linear Multivariable Systems by Identification of Observers with Assigned Real Eigenvalues}},
journal = {Journal of the Astronautical Sciences},
year = {1992},
volume = {40},
number = {2},
pages = {261--279},
month = jun,
doi = {https://doi.org/10.2514/6.1991-949},
file = {:Phan.Juang.ea1992 - Identification of Linear Multivariable Systems by Identification of Observers with Assigned Real Eigenvalues.pdf:PDF},
} M. Phan, L. G. Horta, J. N. Juang, and R. W. Longman, “Linear system identification via an asymptotically stable observer,” Journal of optimization theory and applications, vol. 79, iss. 1, p. 59–86, 1993.
[Bibtex]
@Article{Phan.Horta.ea1993,
author = {M. Phan and L.G. Horta and J.N. Juang and R.W. Longman},
title = {{Linear system identification via an asymptotically stable observer}},
journal = {Journal of Optimization Theory and Applications},
year = {1993},
volume = {79},
number = {1},
pages = {59--86},
month = oct,
issn = {0022-3239},
abstract = {This paper presents a formulation for identification of linear multivariable systems from single or multiple sets of input-output data. The system input-output relationship is expressed in terms of an observer, which is made asymptotically stable by an embedded eigenvalue assignment procedure. The prescribed eigenvalues for the observer may be real, complex, mixed real and complex, or zero corresponding to a deadbeat observer. In this formulation, the Markov parameters of the observer are first identified from input-output data. The Markov parameters of the actual system are then recovered from those of the observer and used to realize a state space model of the system. The basic mathematical formulation is derived, and numerical examples are presented to illustrate the proposed method.},
doi = {10.1007/BF00941887},
file = {:Phan.Horta.ea1993 - Linear System Identification Via an Asymptotically Stable Observer.pdf:PDF},
owner = {ralfg},
timestamp = {2019-09-11},
} D. Luenberger, “Observing the State of a Linear System,” Ieee transactions on military electronics, vol. MIL8, p. 74–80, 1964.
[Bibtex]
@Article{Luenberger1964,
author = {Luenberger, David},
title = {{Observing the State of a Linear System}},
journal = {IEEE Transactions on Military Electronics},
year = {1964},
volume = {MIL8},
pages = {74--80},
month = may,
abstract = {In much of modern control theory designs are based on the assumption that the state vector of the system to be controlled is available for measurement. In many practical situations only a few output quantities are available. Application of theories which assume that the state vector is known is severely limited in these cases. In this paper it is shown that the state vector of a linear system can be reconstructed from observations of the system inputs and outputs. It is shown that the observer, which reconstructs the state vector, is itself a linear system whose complexity decreases as the number of output quantities available increases. The observer may be incorporated in the control of a system which does not have its state vector available for measurement. The observer supplies the state vector, but at the expense of adding poles to the over-all system.},
doi = {10.1109/TME.1964.4323124},
file = {:Luenberger1964 - Observing the State of a Linear System.pdf:PDF},
} R. E. Kalman, “A New Approach to Linear Filtering and Prediction Problems,” Transactions of the asme – journal of basic engineering, vol. 82, p. 35–45, 1960.
[Bibtex]
@Article{Kalman1960,
author = {Kalman, R. E.},
title = {{A New Approach to Linear Filtering and Prediction Problems}},
journal = {Transactions of the ASME - Journal of Basic Engineering},
year = {1960},
volume = {82},
pages = {35--45},
doi = {10.1115/1.3662552},
file = {:Kalman1960 - A New Approach to Linear Filtering and Prediction Problems.pdf:PDF},
owner = {ralfg},
timestamp = {2015.08.09},
}