function demo_KF(plotswitch,varR,varQ); I=eye(2); if nargin == 3 R=varR*randCovariance(2); Q=varQ*randCovariance(2); end if nargin < 3 R = I; Q = I; end if nargin < 1 plotswitch=0; end vt=eye(2,1); y=zeros(2,1); P=0.1*I; loop=1; switchflag=0; figure(1); clf; plotGauss(y(1),y(2),P(1,1),P(2,2),P(1,2),'c'); grid on;hold on; while loop>0 loop=loop+1; [Mx,My,but]=ginput2(1); if but == 1 M = [Mx;My]; K = P*inv(R + P); y = y + K * (M - y); P = (I - K)*P*(I-K)' + K*R*K'; plot(Mx,My,'y+','Markersize',4,'Linewidth',4); plotGauss(y(1),y(2),P(1,1),P(2,2),P(1,2),'r'); drawnow; grid on; if switchflag == 1 & plotswitch ~= 0 hold off; switchflag = 0; else hold on; end elseif but == 3 y = y + vt; P = P + Q; plotGauss(y(1),y(2),P(1,1),P(2,2),P(1,2),'g'); grid on; drawnow; if switchflag == 1 & plotswitch ~= 0 hold off; switchflag=0; else hold on; end else break; end if plotswitch ~=0 if rem(loop,plotswitch)==0 switchflag = 1; end end end