# Use Matrix-Based Data for Time-Domain System Identification

The simplest way to represent data in System Identification Toolbox™ is to use numeric matrices, one matrix for input data, and one matrix for output data. The observations are along the rows and the channels are along the columns. This data format is often sufficient for identifying discrete-time models. Note that this format does not provide any information about the time vector. **Hence this format is not recommended for identifying continuous-time models.**

### Estimate Discrete-Time Model

As a simple example, estimate a discrete-time model from matrix data. Specify the matrices as a comma-separated pair $\mathit{u},\mathit{y}$.

load sdata1 umat1 ymat1 sysd = n4sid(umat1, ymat1, 4)

sysd = Discrete-time identified state-space model: x(t+Ts) = A x(t) + B u(t) + K e(t) y(t) = C x(t) + D u(t) + e(t) A = x1 x2 x3 x4 x1 0.8392 -0.3129 0.02105 0.03743 x2 0.4768 0.6671 0.1428 0.003757 x3 -0.01951 0.08374 -0.09761 1.046 x4 -0.003885 -0.02914 -0.8796 -0.03171 B = u1 x1 0.02635 x2 -0.03301 x3 7.256e-05 x4 0.0005861 C = x1 x2 x3 x4 y1 69.08 26.64 -2.237 -0.5601 D = u1 y1 0 K = y1 x1 0.003282 x2 0.009339 x3 -0.003232 x4 0.003809 Sample time: 1 seconds Parameterization: FREE form (all coefficients in A, B, C free). Feedthrough: none Disturbance component: estimate Number of free coefficients: 28 Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using N4SID on time domain data "umat1". Fit to estimation data: 76.33% (prediction focus) FPE: 1.21, MSE: 1.087

View the sample time.

sysd.Ts

ans = 1

Since the data does not provide the sample time, the software assumes that the data sample time is 1 second. Consequently, the model sample time, `sysd.Ts`

, is also 1 second (Note that n4sid estimates a discrete-time model by default.)

Since the data does not provide the sample time information, you can specify different sample time for the model by using the `'Ts'/<value>`

name-value argument. Specify a model sample time of 0.1 seconds.

`sysd = n4sid(umat1, ymat1, 4, 'Ts', 0.1);`

The software assumes that the data sample time is also 0.1 seconds.

### Estimate Continuous-Time Model

Simply specifying the sample time does not work if the goal is to specify a continuous-time model by setting `Ts`

to `0`

.

`sysc = n4sid(umat1, ymat1, 4, 'Ts', 0);`

Warning: Data sample time is assumed to be 1 seconds. To specify a different value for the data sample time consider providing data using a timetable or an iddata object.

In this case, there is no direct way of specifying the data sample time. The software assumes that the data sample time is 1 second and issues a warning.

To estimate a continuous-time model with this data, you must convert it into a timetable or an `iddata`

object so that you can specify the data sample time information.

Suppose that the true sample time of the data above is 0.1 hours. Convert the data to a timetable using the data sample time information.

N = size(umat1,1); % (assume a start time of 1 hr) t = hours(0.1*(1:N)'); dataTT = timetable(umat1,ymat1,'RowTimes',t);

You can now estimate the continuous model

```
sysc = n4sid(dataTT, 4, 'Ts', 0);
sysc.Ts
```

ans = 0

sysc.TimeUnit

ans = 'hours'

Alternatively, instead of converting the data to a timetable, you can convert it to an `iddata`

object. Note that the conversion command for `iddata`

specifies output first, while the timetable command specifies input first.

dataIDDATA = iddata(ymat1, umat1, 0.1, 'TimeUnit', 'hours'); sysc = n4sid(dataIDDATA, 4, 'Ts', 0); sysc.Ts

ans = 0

sysc.TimeUnit

ans = 'hours'

### Estimate Time Series Model

For time series data, that is, data containing only output data and no input data, specify `[]`

,$\mathit{y}$.

systs = n4sid([],ymat1,4)

systs = Discrete-time identified state-space model: x(t+Ts) = A x(t) + K e(t) y(t) = C x(t) + e(t) A = x1 x2 x3 x4 x1 0.8293 -0.4941 -0.0201 0.2288 x2 0.2122 0.6994 -0.03311 0.5703 x3 -0.01299 0.03653 -0.8259 0.7642 x4 0.007749 -0.04922 -0.3883 -0.1022 C = x1 x2 x3 x4 y1 -74.48 14.6 0.6196 -0.1086 K = y1 x1 -0.01566 x2 0.006688 x3 -0.0009932 x4 0.0005739 Sample time: 1 seconds Parameterization: FREE form (all coefficients in A, B, C free). Disturbance component: estimate Number of free coefficients: 24 Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using N4SID on time domain data. Fit to estimation data: 59.64% (prediction focus) FPE: 3.425, MSE: 3.161

`systs`

is a time series model that contains no $\mathit{B}$ or $\mathit{D}$ component.