Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. xp=position_data(:,1);
  2. yp=position_data(:,1)(:,2);
  3.  
  4. N=length(xp);
  5.  
  6. Q=eye(4);
  7. motion=zeros(4,1);
  8.  
  9. H=[1 0 0 0
  10. 0 1 0 0];
  11. F=[1 0 1 0
  12. 0 1 0 1
  13. 0 0 1 0
  14. 0 0 0 1];
  15.  
  16. x=zeros(4,1);
  17. P = eye(4)*1000; %initial uncertainty
  18.  
  19. observed_x=xp+0.05*rand(N,1).*xp;
  20. observed_y=yp+0.05*rand(N,1).*yp;
  21.  
  22. R=0.01^2;
  23.  
  24. pos=[observed_x,observed_y];
  25.  
  26. start=0;
  27. jj=zeros(N,2); %%jj will be the final result
  28.  
  29.  
  30. for k=start+1:length(observed_x)
  31. measurement=pos(k,:);
  32. y = measurement' - H * x;
  33. S = H * P * H' + R; % residual convariance
  34. K = P * H' * inv(S); % Kalman gain
  35. x = x + K*y;
  36. I = eye(4); % identity matrix
  37. P = (I - K*H)*P;
  38.  
  39. % predict x and P
  40. x = F*x + motion;
  41. P = F*P*F' + Q;
  42. jj(k,:)=x(1:2);
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement