function kf1D
clf;
%plot1DGaussian([0,1],'k');
hold on;
xt=0;
Pt=0.5;
W=2.82; % Process Noise
N=0.0009; % Sensor Noise
% What really happened
xt1=xt+randn(1,1)*W; % Propagate of Real Position
zt1=xt1+randn(1,1)*N; % Real Measurment
% KF 
Ext1=xt;   % Estimate after Propagation
Pt1=Pt+W;  % Covariance after Propagation
plot1DGaussian([Ext1, Pt1],'r');
plot(Ext1,0,'r*');
hold on;
plot(xt1,0,'m*');
Ezt1=Ext1;  % Estimated Measurment
plot1DGaussian([zt1, N],'b');
plot(zt1,0,'b*');
rt1=zt1-Ezt1; % Residual
St1=Pt1+N;    % Covariance of the Measurment
K=Pt1/St1;    % Kalman Gain
Ext1=Ext1+K*rt1; % Updated Estimate
Pt1=Pt1-(Pt1/St1)*Pt1; % Updated Covariance
plot1DGaussian([Ext1, Pt1],'g');
plot(Ext1,0,'g*');
legend('Propagation PDF','Propagation Est.','Real Position','Measurment PDF','Z','Update PDF','Final Est.');
