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