📄 ch4_1g.m
字号:
% Select a demo number: 8
% We start by looking at the dataset iddemo8.mat.
load iddemo8
% The name of the data object is dat, and let us look at it.
figure,plot(dat)
% We see that there are some problems with the output around
% sample 250-280 and around samples 600 to 650. Might have been
% sensor failures.
%
% Therefore split the data into three separate experiments and
% put then into a multi-experiment data object:
d1 = dat(1:250);
d2 = dat(281:600);
d3 = dat(651:1000);
d = merge(d1,d2,d3);
% To look at the new data set, just type its name:
% The different experiments can be given other names, e.g.,
d.exp = {'Period 1';'Day 2';'Phase 3'}
figure,plot(d) % Strike a key to advance the plots for one experiment to another.
% All model estimation routines accept multi-experiment data and
% take into account that they are recorded at different periods.
% Let us use the two first experiments for estimation and the third one
% for validation:
de = getexp(d,[1,2]); % subselection is done using the command GETEXP using numbers
dv = getexp(d,'Phase 3'); % or names.
m1 = arx(de,[2 2 1]);
m2 = n4sid(de,2);
m3 = armax(de,[2 2 2 1]);
figure,compare(dv,m1,m2,m3)
% compare also accepts multiple experiments:
figure,compare(d,m1,m2,m3)
% Also spa, etfe, resid, predict, sim operate in the obvious way for
% multi-experiment data.
% There is another way to deal with separate data sets: A model can be
% computed for each set, and then the models can be merged:
m4 = armax(getexp(de,1),[2 2 2 1]);
m5 = armax(getexp(de,2),[2 2 2 1]);
m6 = merge(m4,m5);
% This is conceptually the same as computing m from the merged set DE, but
% it is not numerically the same. Working on DE assumes that the
% signal-to-noise ratios are (about) the same in the different experiments,
% while merging separate models makes independet estimates of the noise levels.
% If the conditions are about the same for the different experiments, it is
% more efficient to estimate directly on the multi-experiment data.
% We can check the models m3 and m6 that are both ARMAX models obtained on the
% same data inthe two different ways:
figure,compare(dv,m3,m6)
% We now turn to another situation.
% Let us consider two data sets generated by the system m0.
% The system is given by
% The data sets that have been collected are z1 and z2, obtained from m0
% with different inputs, noise and initial conditions.
% Strike a key to advance between the plots.
figure,plot(z1)
figure,plot(z2)
% If we just concatenate the data we obtain
zzl = [z1;z2]
figure,plot(zzl)
% A model is obtained by
ml = pem(zzl,3,'nk',[0 1]); % No delay from input # 1 and one from input # 2
figure,bode(m0,ml)
% Strike a key to advance between plots
% This is not a very good model.
% Now, instead treat the two data sets as different experiments:
zzm = merge(z1,z2)
% The model becomes
mm = pem(zzm,3,'nk',[0 1],'trace','on');
% Let us compare the Bode plots of the true system (blue)
% the model from concatenated data (green) and the model from the
% merged data set (red):
figure,bode(m0,'b',ml,'g',mm,'r')
% The merged data give a much better model.
% End of demo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -