10
0
10
1
10
2
10
?2
10
?1
10
0
10
1
10
2
Mag
Freq
OKID model using OK model=8 SS model=10
ETFE
OKID
N4SID
10
0
10
1
10
2
?500
?400
?300
?200
?100
0
Phase (deg)
Freq
OKID model using OK model=8 SS model=10
ETFE
OKID
N4SID
1.5
y
e
u
1
0.5
0
?0.5
?1
?1.5
0 10 20 30 40 50 60
10
?2
10
?1
10
0
Mag
SS G model using model of size 4
Actual
OKID
N4SID
?1 0 1
10 10 10
Freq
10
?1
10
0
10
1
10
0
10
1
Mag
Freq
SS H model using model of size 4
Actual
N4SID
1.2
Correlation function of residuals. Output # 1
0
0.2
0.4
0.6
0.8
1
?0.2
0 5 10 15 20 25
lag
Cross corr. function between input 1 and residuals from output 1
0.15
0.1
0.05
0
?0.05
?0.1
?0.15
?0.2
?25 ?20 ?15 ?10 ?5 0 5 10 15 20 25
lag
\begin{verbatim}
%
% E211 System ID
% Jonathan How
% Fall 1999
% Use the N4SID algorithm for the robot data
%
clear all;close all;
randn('state',44);
Ny=40;
load hw3_robot_arm
y=z(:,1);
u=z(:,2);
y=dtrend(y);u=dtrend(u);
z=[y u];
fig=0;fig=fig+1;figure(fig);clf
plot([z]);setlines;legend('y','u')
Nest=6;
[Aok,Bok,Cok,Dok,Gok]=okid(size(y,2),size(u,2),Ts,u,y,'batch',(Nest)+2);
%
% [TH,AO]=N4SID(Z,ORDER,NY,AUXORD,DKX,MAXSIZE,TSAMP)
%
[th_ss,AO]=n4sid(z,4:10,1,[],[1 1 1],[],Ts,'trace');
[A_ss,B_ss,C_ss,D_ss,K_ss,X0_ss]=th2ss(th_ss);
Npts=512;
ghat=etfe([y u],[128*4],Npts,Ts);
[wa,ghm,ghp]=getff(ghat,1,1);
%
% models of G
%
[mag1,ph1]=dbode(Aok,Bok,Cok,Dok,Ts,1,wa);
[mag2,ph2]=dbode(A_ss,B_ss,C_ss,D_ss,Ts,1,wa);
fig=fig+1;figure(fig);clf
subplot(211)
hh=loglog(wa,ghm,'b.',wa,mag1,'r--',wa,mag2,'md');
set(hh(1),'MarkerSize',12)
legend('ETFE','OKID','N4SID');
axis([1 150 .005 100])
ylabel('Mag');xlabel('Freq')
title(['OKID model using OK model=',num2str(size(Aok,1)),' SS
model=',num2str(size(A_ss,1))])
subplot(212)
hh=semilogx(wa,ghp,'b.',wa,ph1-360,'r--',wa,ph2-360,'md');
set(hh(1),'MarkerSize',12)
legend('ETFE','OKID','N4SID');
axis([1 150 -540 90])
ylabel('Phase (deg)');xlabel('Freq')
title(['OKID model using OK model=',num2str(size(Aok,1)),' SS
model=',num2str(size(A_ss,1))])
%return
figure(2);print -dpsc robot.ps