How to get the coefficients from a nlarx model constructed using System Identification Toolbox?

Hey all,
I am using System Identification Toolbox for constructing a non linear regression model. This is what I've done:
[num] = xlsread( '1.xlsx' ,1);
u1 = num(:,10); % Input Channel 1
u2 = num(:,3); % Input Channel 2
u = [u1 u2]; %Concatenate both input channels
y = num(:,11); % Output Channel
ts = 0.04; % Sampling Interval
data = iddata(y,u,0.04); % Construct data object with the specified input arguments
get(data) % Get the properities of the data object
advice(data)
datae = misdata(data,idarx); % This command linearly interpolates missing % values to estimate the first model. Then, it uses this model to estimate % the missing data as parameters by minimizing the output prediction errors % obtained from the reconstructed data.
advice(datae)
% Define the order by trial and error m1 = nlarx(datae,[4 4*ones(1,2) zeros(1,2)],'tree')
compare(datae,m1)
m2 = nlarx(datae,[2 2*ones(1,2) zeros(1,2)],'tree')
compare(datae,m2)
My second model was better with 94% fit. But now I don't know how to get the coefficients of the regressors and how to convert the model into a Transfer Function and to a SS model??
For example if I want to see the estimated parameters for M = ARX(DATA,ORDERS) I will type m.a

 Accepted Answer

The coefficients of the nonlinear arx model are stored in the property called "Nonlinearity". In particular, look at m2.Nonlinearity.Parameters. The coefficients stored correspond to a certain equation whose nature depends upon the type of the nonlinearity chosen (tree partition in your case). Type "idprops treepartition", "idprops wavenet" etc for more information on the underlying equations. A couple of comments:
1. The model obtained by 1-step ahead prediction error minimization can be quite different from the one obtained by simulation error minimization. See the "focus" property which lets you toggle between prediction and simulation.
2. NLARX is a nonlinear model. You cannot just convert it into a (linear) transfer function or a state space model. If you want a linear approximation, use the idnlarx/linearize and idnlarx/linapp commands. If you are looking for a way of importing the nonlinear model into Simulink, use the dedicated "Nonlinear ARX" block which is part of System Identification Toolbox blockset.
Some useful links: For insights into the structure of nonlinear models, see:
For setting up the mask parameters for Nonlinear ARX model block in Simulink, see:
The reference page for idnlarx has lots of information too:

4 Comments

Thanks a lot. Really appreciate it. I still have some questions.
1] This is what I'm getting when I type >> m2.Nonlinearity.Parameters
ans =
RegressorMean: [0.2927 0.2927 0.2955 0.2964 1.0261 1.0263]
RegressorMinMax: [6x2 double]
OutputOffset: 0.2917
LinearCoef: [6x1 double]
SampleLength: 305
NoiseVariance: 2.1692e-006
Tree: [1x1 struct]
>> m2.Nonlinearity.Parameters.LinearCoef
ans =
-0.0038
-0.0113
1.0042
-0.0052
-0.1369
-0.0054
Is the LinearCoef my coefficients and what about the nonlinear ones from where I can get them??
2] I added the following lines into my code in order to compare between nlarx model using linear estimator and arx model.
Mlin = nlarx(datae, [2 2*ones(1,2) zeros(1,2)], 'linear'); figure(5) compare(datae,Mlin)
model = arx(datae, [2 2*ones(1,2) zeros(1,2)]); figure(6) compare(datae,model)
I thought That I will get the same coefficients since both have the same structure but they turned out different!! Can you explain to me why??
3] When I used advice(datae) it recommended using nlarx with [4 4*ones(1,2) 4*ones(1,2)], but when I tried smaller values the fit of the model was better. It also suggested using nonlinear model, but when I tried both nlarx and arx, the latter fitted my data with a higher percentage! So, which one shall I use now? Please advise.
Everything you see under "Parameters" are, well, parameters. They all contribute to the dynamic equation relating the input to the output. For tree partition, the structure of the tree is dictated by Parameters.Tree coefficients; the relationship is nontrivial.
The nonlinear ARX model (idnlarx) even with linear choice is more flexible than a linear ARX model. The idnlarx model also estimates output offset. This form (i.e., idnlarx with Nonlinearity = linear) also allows you to specify custom regressors, something you cannot do with (linear) ARX.
ADVICE is basically saying that it found a model with smaller 1-step ahead prediction error using a [4 4 1] nonlinear arx model than a [4 4 1] order linear ARX model. It is not recommending [4 4 1] as the best order. Indeed you may be able to get results with other orders. The other thing to note is that both ARX and NLARX, by default, estimate a model by minimizing the 1-step ahead prediction error norm. This does not necessarily imply minimization of the simulation error, which is what you seem to be interested in obtaining (since you use COMPARE with default options which shows the simulation result comparison to data). To unambiguously minimize the simulation error during estimation, set the focus to 'simulation', as in:
Mlin = nlarx(datae, [2 2*ones(1,2) zeros(1,2)], 'linear', 'focus', 'sim');
model = arx(datae, [2 2*ones(1,2) zeros(1,2)], 'focus', 'simulation');
(in releases R2012a or later, use:
opt = arxOptions('Focus', 'simulation');
model = arx(datae, [2 2*ones(1,2) zeros(1,2)], opt);
T have the same problem, when I try m.Nonlinearity.Parameters to get the paramets, this command does not focus and Matlab gives an error " Error using InputOutputModel/subsref (line 43) Dot-reference can be used for a scalar nonlinearity estimator only." Please help me !!!!!!!!!!
I'm having the same problem that @Chahira Mahjoub reported.
"Error using idnlfunVector/subsref (line 42) Dot-reference can be used for a scalar nonlinearity estimator only." (R2017a)
Does anyone know how to solve this?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!