% example ch19ex5.m % % load previously stored data load ch19ex5_reg_data; scal=ch19ex5_reg_data; % extract vectors load ch19ex5_test_data; test=ch19ex5_test_data; time=scal(:,1); x=scal(:,2);y=scal(:,3); tt=test(:,1);xt=test(:,2);yt=test(:,3); z=[y x]; idplot(z,[],1);% this program is from identification toolbox % now fit the data to a first order arx model % try various time delays for i=1:10 th1=arx(z,[1 1 i]); % arx is an id_toolbox function that implements % the least squares fit for the parameters the results are % stored in a structure variable called th1 % the parameters are na,nb and nk. present(th1); % this prsents the model pause; y1sim=idsim(xt,th1); pe=yt-y1sim;penorm(i)=sqrt(sum(pe .*pe)) % compare step responses of all models end; plot(penorm);