% example ch13ex12.m % Illustrates construction of the Kalman filter clc echo on A=[-1 0 0 -2]; B=[0 0];B=B'; G=[1 1]; C=[0 1]; D=[0]; Q=[1];R=[1]; [L,P,E]=lqe(A,G,C,Q,R) [ae,be,ce,de]=estim(A,B,C,D,L) % This computes the estimator % Now convert to transfer function form [num,den]=ss2tf(ae,be,ce,de) % note that there are three rows corresponding to the three states: x1,x2 and z % y corresponds to x2. Hence the second row gives the transfer function for the estimator