Guest User

Untitled

a guest
Dec 9th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. % integrate angular velocity to get angle
  2. dt = seconds(angular_velocities(2) - angular_velocities(1));
  3. for idx = 1 : length(angular_velocities)
  4. gyro_angle = gyro_angle + ( dt * angular_velocities(idx) );
  5. gyro_angles(idx) = gyro_angle;
  6. end
  7.  
  8. % set the first value in the x hat as the accelerometer value
  9. x_hat(1) = accelerometer_angles(1);
  10.  
  11. % run the ext kalman filter
  12. for idx = 2 : length(angular_velocities)
  13. accele_angle = accelerometer_angles(idx);
  14. gyro_angle = gyro_angles(idx);
  15.  
  16. % predict
  17. x_hat(idx) = x_hat(idx - 1);
  18. P = P + Q;
  19.  
  20. % update
  21. a = P + R_1;
  22. d = P + R_2;
  23. e = P / (a*d - P*P);
  24. k1 = e*d - e*P;
  25. k2 = e*a - e*P;
  26. P = (1 - (k1+k2)) * P;
  27.  
  28. x_hat(idx) = x_hat(idx) + (k1*(gyro_angle - x_hat(idx))) + (k2*(accele_angle-x_hat(idx)));
  29. end
Add Comment
Please, Sign In to add comment