system identification code

clc;

clear all;

load(‘u:\pdata4.mat’);

Ts = 1/10000;  % enter sampling time

fpos=idfilt(pos, 5, 0.005, ‘non causal’);

fvel=idfilt(vel, 5, 0.005, ‘non causal’);

fvol=idfilt(vol, 5, 0.005, ‘non causal’);

ftime=idfilt(time, 5, 0.005, ‘non causal’);

vpos=idfilt(pos, 5, 0.005, ‘non causal’);

vvel=idfilt(vel, 5, 0.005, ‘non causal’);

vvol=idfilt(vol, 5, 0.005, ‘non causal’);

vtime=idfilt(time, 5, 0.005, ‘non causal’);

subplot(2,2,1);

plot(ftime,fpos);

subplot(2,2,2);

plot(ftime,fvel);

subplot(2,2,3);

plot(ftime,fvol);

out=[fpos,fvel];

out2=[vpos,vvel];

inp=fvol;

inp2=vvol;

fdata=iddata(out,inp,Ts);

vdata=iddata(out2,inp2);

a=[ 0  1 ;

    0 -1];

b=[0 ;

   20

    ];

c=[ 1 0 ;

    0 1 ];

d=[0;0];

x0=[fpos(1);fvel(1)];

k=[0 0; 0 0];

m1=idss(a,b,c,d,k,x0,’Ts’,0);

As=[ 0 1 ;

    0 NaN ;

    ];

Bs=[0;NaN];

Cs=[1 0 ;

    0 1

    ];

Ds=[0;0];

ks = [0 0; 0 0];

x0s=[NaN;NaN];

setstruc(m1, As, Bs, Cs, Ds, ks, x0s);

set(m1,’Ts’,0);

 m2= pem(fdata, m1);

A = m2.A

B = m2.B

C = m2.C

D = m2.D