# Real-Time Computing and Control

Topics: Mathematics, Estimation, Least squares Pages: 2 (832 words) Published: May 17, 2013
Using the recursive least squares method, obtain parameter estimates for different model structures. The program is below: clear all close all N=1500; % set lenghth of data y=zeros(1,N); u=zeros(1,N); yhat=zeros(1,N); e=zeros(1,N); noise=rand(1,N); % generate noise %ny=2; true value %nu=3; true value %ny=2; good// model with different order :test 1 %nu=4; %ny=3; bad %nu=5; %ny=4; bad %nu=5; %ny=3; good %nu=3; %ny=2; with more numerator terms:test 2 %nu=4; ny=2; %test 3 nu=3; m=ny+nu; P=eye(m,m)*1000; % set initial value of matrix P k=zeros(1,m); Phi=zeros(N,m); phi=zeros(1,m); theta=zeros(m,1); % set initial guess of parameters for i=1:5 % 5 loops results in 1500 iterations % each iteration contains 300 steps to ensure convergence of estimation for j=2*(i-1)*150+1:((2*i)-1)*150 u(j)=1; % u is defined as a step signal,repeated every 300 steps. end; end; for i=(nu+1):N %y(i)=0.5*y(i-1)-0.4*y(i-2)+0.2*u(i-2)+0.3*u(i-3)+0.4*u(i-4) %+0.0003*(noise(i)-0.5*noise(i-1)+0.4*noise(i-2)); %for text 2 %y(i)=0.5*y(i-2)-0.4*y(i-3)+0.2*u(i-3)+0.3*u(i-4) % +0.0003*(noise(i)-0.5*noise(i-1)+0.4*noise(i-2)); %for test 3 %y(i)=0.5*y(i-3)-0.4*y(i-4)+0.2*u(i-3)+0.3*u(i-4) %+0.0003*(noise(i)-0.5*noise(i-1)+0.4*noise(i-2)); %for test 3 % % test for different model structure above our noise suppression test

y(i)=0.5*y(i-1)-0.4*y(i-2)+0.2*u(i-2)+0.3*u(i-3)+0.3*(noise(i)-0.5*noise(i1)+0.4*noise(i-2)); % generate real output data end; for i=(max(nu,ny)+1):N for j=1:ny Phi(i,j)=y(i-j); end; % update Phi matrix for j=(ny+1):m Phi(i,j)=u(i-(j-ny)); % For this line, max of (j-ny) is nu, to have (i-(jny)) positive, i should be i>nu. % Therefore, i should be defined as i=(max(nu,ny)+1):N. end; % Each row of Phi is made of 2 steps of past value of y and 2 steps of past value of u. % It is assumed here that the guesses on % numbers of entries in the numerator and % denominator are both successful.

phi=Phi(i,:); % phi is the last row in Phi.% P=P-P*phi'*inv(1+phi*P*phi')*phi*P; % P is derived...