Compute and test model residuals (prediction errors)
e = resid(m,data)
resid(m,data) plots the residuals associated with an identified model. data contains the output-input data as an iddata object. Both time-domain and frequency-domain data are supported. data can also be an idfrd object. m is any linear or nonlinear identified model.
resid(m,data,Type) specifies the type of plot. The plot can be one of three kinds depending on the argument Type:
Type = 'Corr' (only available for time-domain data) — The autocorrelation function of e and the cross-correlation between e and the input(s) u are computed and displayed. The 99% confidence intervals for these values are also computed and shown as a yellow region. The computation of the confidence region is done assuming e to be white and independent of u. The functions are displayed up to lag M, which is 25 by default.
Type = 'ir' — The impulse response (up to lag M, which is 25 by default) from the input to the residuals is plotted with a 99% confidence region around zero marked as a yellow area. Negative lags up to M/4 are also included to investigate feedback effects. The result is the same as impulse(e,'sd',2.58,M).
Type = 'fr' — The frequency response from the input to the residuals (based on a high-order FIR model) is shown as a Bode plot. A 99% confidence region around zero is also marked as a yellow area.
The default for time-domain data is Type = 'Corr'. For frequency-domain data, the default is Type = 'fr'.
resid(m,data,Type,M) specifies the number of positive lags. The correlation functions for Type = 'Corr' are given up to lag 25, which can be changed to M. If M is specified, this will also be the number of positive lags used for the impulse response in the 'ir' case. Specification of lags is not meaningful when Type = 'fr'.
e = resid(m,data) returns the residuals (prediction errors) associated with the model and the data. e is an iddata object with the residuals as outputs and the input in data as inputs. That means that e can be directly used to build model error models, that is, models that describe the dynamics from the input to the residuals (which should be negligible if m is a good description of the system). This is done as in the command pe with a default choice of init.
Here are some typical model validation commands.
e = resid(m,data); plot(e) compare(data,m);
To compute a model error model, that is, a model from the input to the residuals to see if any essential unmodeled dynamics are left, do the following:
e = resid(m,data); me = arx(e,[10 10 0]); bode(me,'sd',3,'fill')