PredictCovariance.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. function P = PredictCovariance(deltaAngle, ...
  2. deltaVelocity, ...
  3. quat, ...
  4. states,...
  5. P, ... % Previous state covariance matrix
  6. dt) ... % IMU and prediction time step
  7. % Set filter state process noise other than IMU errors, which are already
  8. % built into the derived covariance predition equations.
  9. % This process noise determines the rate of estimation of IMU bias errors
  10. dAngBiasSigma = dt*dt*5E-4; % delta angle bias process noise (rad)
  11. processNoise = [0*ones(1,6), dAngBiasSigma*[1 1 1]];
  12. % Specify the estimated errors on the IMU delta angles and delta velocities
  13. % Allow for 0.5 deg/sec of gyro error
  14. daxNoise = (dt*0.5*pi/180)^2;
  15. dayNoise = (dt*0.5*pi/180)^2;
  16. dazNoise = (dt*0.5*pi/180)^2;
  17. % Allow for 0.5 m/s/s of accelerometer error
  18. dvxNoise = (dt*0.5)^2;
  19. dvyNoise = (dt*0.5)^2;
  20. dvzNoise = (dt*0.5)^2;
  21. dvx = deltaVelocity(1);
  22. dvy = deltaVelocity(2);
  23. dvz = deltaVelocity(3);
  24. dax = deltaAngle(1);
  25. day = deltaAngle(2);
  26. daz = deltaAngle(3);
  27. q0 = quat(1);
  28. q1 = quat(2);
  29. q2 = quat(3);
  30. q3 = quat(4);
  31. dax_b = states(7);
  32. day_b = states(8);
  33. daz_b = states(9);
  34. % Predicted covariance
  35. F = calcF(dax,dax_b,day,day_b,daz,daz_b,dvx,dvy,dvz,q0,q1,q2,q3);
  36. Q = calcQ(daxNoise,dayNoise,dazNoise,dvxNoise,dvyNoise,dvzNoise,q0,q1,q2,q3);
  37. P = F*P*transpose(F) + Q;
  38. % Add the general process noise
  39. for i = 1:9
  40. P(i,i) = P(i,i) + processNoise(i)^2;
  41. end
  42. % Force symmetry on the covariance matrix to prevent ill-conditioning
  43. % of the matrix which would cause the filter to blow-up
  44. P = 0.5*(P + transpose(P));
  45. % ensure diagonals are positive
  46. for i=1:9
  47. if P(i,i) < 0
  48. P(i,i) = 0;
  49. end
  50. end
  51. end