MataveID
System identification toolbox for GNU Octave and MATLAB
Install / Use
/learn @DanielMartensson/MataveIDREADME
MataveID V17.1.0
MataveID is a basic system identification toolbox for both GNU Octave and MATLAB®. MataveID is based on the power of linear algebra and the library is easy to use. MataveID using the classical realization and polynomal theories to identify state space models from data. There are lots of subspace methods in the "old" folder and the reason why I'm not using these files is because they can't handle noise quite well.
I'm building this library because I feel that the commercial libraries are just for theoretical experiments. I'm focusing on real practice and solving real world problems.
Papers:
MataveID contains realization identification, polynomal algorithms and subspace algorithms. They can be quite hard to understand, so I highly recommend to read papers in the "reports" folder about the algorithms if you want to understand how they work, or read the literature.
Literature:
I have been using these books for creating the .m files. All these books have different audience. Some techniques are meant for researchers and some are meant for practical engineering.
Applied System Identification
This book include techniques for linear mechanical systems such as vibrating beams, damping, structural mechanics etc. These techniques comes from NASA and the techniques are created by Jer-Nan Juang. This is a very practical book. The book uses the so called realization theory methods for identify dynamical models from data.
Advantages:
- Easy to read and very practical
- Include mechanical model buildning
- Include impulse, frequency, stochastic, closed loop and recursive identification
- These techniques are applied onto Hubble Telescope, Space Shuttle Discovery and Galileo spacecraft
Disadvantages:
- Do not include nonlinear system identification and subspace methods
- Do not include filtering
- MATLAB files from this book is export controlled from NASA = Difficult to download
- This book is not produced anymore. I have the PDF.

System Modeling & Identification
This book covering techniques for all types of systems, linear and nonlinear, but it's more a general book for system identfication. Professor Rolf Johansson book contains lots of practice, but also theory as well. More theory and less practice compared to Applied System Identification from Jer-Nan Juang. This book uses both the realization theory methods and subspace methods for identify dynamical systems from data. Also this book includes filters as well such as Uncented Kalman Filter. Can be purchased from https://kfsab.se/sortiment/system-modeling-and-identification/
Advantages:
- Easy to read and somtimes practical
- Include filtering, statistics and other types of modeling techniques
- Include impulse, frequency, stochastic, closed loop, nonlinear and recursive identification
- Include both realization theory, subspace and nonlinear system identification methods
Disadvantages:
- Do not include closed loop identification
- Some methods are difficult to understand how to apply with MATLAB-code. Typical univerity literature for students

Subspace Methods For System Identification
This book include techniques for all types of linear systems. It's a general book of linear system identification. The advantages of this book is that it include modern system identification techniques. The disadvantages about this book is that it contains only theory and no practice, but Professor Tohru Katayama, have made a great work for collecting all these subspace methods. Use this book if you want to have knowledge about the best subspace identification methods.
Advantages:
- Include MATLAB code examples and lots of step by step examples
- Include stochastic and closed identification
- Include the latest methods for linear system identification
- Include both realization theory and subspace system identification methods
Disadvantages:
- Difficult to read and understand
- Does not include impulse, frequency and nonlinear identification
- Does not include filtering, statistics and other types of modeling techniques

Adaptive Control
This book is only for adaptive control. But there is one algorithm that are very useful - Recursive Least Squares. This is a very pratical book for applied adaptive control. It's uses the legacy SISO adaptive techniques such as pole placement, Self Tuning Regulator(STR) and Model Reference Adaptive Systems(MRAS) combined with Recursive Least Squares(RLS). If you wonder why only SISO and not MIMO, it's because adaptive control is very difficult to apply in practice and create a reliable controller for all types of systems. The more difficult problem is to solve, the more simplier technique need to be used.
Advantages:
- The authors of the book explains which chapters are for pratcial engineering and theoretical researchers
- Easy to read
- Include both advanced and simple methods depending on which type of problem to solve
Disadvantages:
- Only one system identification algorithm is taught
- Only SISO model are applied
- This book is made for adaptive control and have only one chapter that contains system identification

The best algorithm
If you are looking for the best algorithm to use for system identification. An algorithm that always work no matter what type of data you're using. Then it is the SYNDy algorithm. The SINDy algorithm is a combination of grey box system identification and black box system identification. The disadvantages with SINDy is that it requries that the user have at last a minor knowledge about how the model might look like e.g first order, second order etc.
Examples
Multivariable Output-Error State Space
MOESP is an algorithm that identify a linear state space model. It was invented in 1992. It can both identify SISO and MISO models. Try MOESP or N4SID. They give the same result, but sometimes MOESP can be better than N4SID. It all depends on the data.
[sysd] = mi.moesp(u, y, k, sampleTime, delay, systemorder); % k = Integer tuning parameter such as 10, 20, 25, 32, 47 etc.
Example MOESP
https://github.com/DanielMartensson/MataveID/blob/39c9b1b9d4361b880f1773b82764bd549c943f5d/examples/moespExample.m#L1-L22

RLS - Recursive Least Squares
RLS is an algorithm that creates a SISO model from data. Here you can select if you want to estimate an ARX, OE model or an ARMAX model, depending on the number of zeros in the polynomal "nze". Select number of error-zeros-polynomal "nze" to 1, and you will get a ARX model or select "nze" equal to model poles "np", you will get an ARMAX model that also includes a kalman gain matrix K. I recommending that. This algorithm can handle data with noise. This algorithm was invented 1821 by Carl Friedrich Gauss, but it was until 1950 when it got its attention in adaptive control.
Use this algorithm if you have data from a open/close loop system and you want to apply that algorithm into embedded system that have low RAM and low flash memory. RLS is very suitable for system that have a lack of memory.
There is a equivalent C-code for RLS algorithm here. Works on ALL embedded systems. https://github.com/DanielMartensson/CControl
[sysd, K] = mi.rls(u, y, np, nz, nze, sampleTime, delay, forgetting);
Notice that there are sevral functions that simplify the use of rls.m
[sysd, K] = mi.oe(u, y, np, nz, sampleTime, delay, forgetting);
[sysd, K] = mi.arx(u, y, np, nz, sampleTime, ktune, delay, forgetting);
[sysd, K] = mi.armax(u, y, np, nz, nze, sampleTime, ktune, delay, forgetting);
Example RLS
This is a hanging load of a hydraulic system. This system is a linear system due to the hydraulic cylinder that lift the load. Here I create two linear first order models. One for up lifting up and one for lowering down the weight. I'm also but a small orifice between the outlet and inlet of the hydraulic cylinder. That's create a more smooth behavior. Notice that this RLS algorithm also computes a Kalman gain matrix.

https://github.com/DanielMartensson/MataveID/blob/2014b74a0863729b43e0ee02ecdcd4fcbc06b26b/examples/rlsExample.m#L1-L60
Here we can se that the first model follows the measured position perfect. The "down-curve" should be measured a little bit longer to get a perfect linear model.

SINDy - Sparse Identification of Nonlinear Dynamics
This is a new identification technique made by Eurika Kaiser from University of Washington. It extends the identification methods of grey-box modeling to a much simplier way. This is a very easy to use method, but still powerful because it use least squares with sequentially thresholded least squares procedure. I have made it much simpler because now it also creates the formula for the system. In more practical words, this method identify a nonlinear ordinary differential equations from time domain data.
This is very usefull if you have heavy nonlinear systems such as a hydraulic orifice or a hanging load.
[dx] = mi.sindy(inputs, outputs, degree, lambda, sampleTime);
SINDy Example
This example is a real world example with noise and nonlinearities. Here I set up a hydraulic motor in a test bench and measure it's output and the current to the valve that gives the motor oil. The motor have two nonlinearities - Hysteresis and the input signal is not propotional to the output signal. By using two nonlinear models, we can avoid the hysteresis.

https://github.com/DanielMartensson/MataveID/blob/2014b74a0863729b4
