PredictCovarianceOptimised.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. function nextP = PredictCovarianceOptimised(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. t1365 = dax*0.5;
  35. t1366 = dax_b*0.5;
  36. t1367 = t1365-t1366;
  37. t1368 = day*0.5;
  38. t1369 = day_b*0.5;
  39. t1370 = t1368-t1369;
  40. t1371 = daz*0.5;
  41. t1372 = daz_b*0.5;
  42. t1373 = t1371-t1372;
  43. t1374 = q2*t1367*0.5;
  44. t1375 = q1*t1370*0.5;
  45. t1376 = q0*t1373*0.5;
  46. t1377 = q2*0.5;
  47. t1378 = q3*t1367*0.5;
  48. t1379 = q1*t1373*0.5;
  49. t1380 = q1*0.5;
  50. t1381 = q0*t1367*0.5;
  51. t1382 = q3*t1370*0.5;
  52. t1383 = q0*0.5;
  53. t1384 = q2*t1370*0.5;
  54. t1385 = q3*t1373*0.5;
  55. t1386 = q0*t1370*0.5;
  56. t1387 = q3*0.5;
  57. t1388 = q1*t1367*0.5;
  58. t1389 = q2*t1373*0.5;
  59. t1390 = t1374+t1375+t1376-t1387;
  60. t1391 = t1377+t1378+t1379-t1386;
  61. t1392 = q2*t1391*2.0;
  62. t1393 = t1380+t1381+t1382-t1389;
  63. t1394 = q1*t1393*2.0;
  64. t1395 = t1383+t1384+t1385-t1388;
  65. t1396 = q0*t1395*2.0;
  66. t1403 = q3*t1390*2.0;
  67. t1397 = t1392+t1394+t1396-t1403;
  68. t1398 = q0^2;
  69. t1399 = q1^2;
  70. t1400 = q2^2;
  71. t1401 = q3^2;
  72. t1402 = t1398+t1399+t1400+t1401;
  73. t1404 = t1374+t1375-t1376+t1387;
  74. t1405 = t1377-t1378+t1379+t1386;
  75. t1406 = q1*t1405*2.0;
  76. t1407 = -t1380+t1381+t1382+t1389;
  77. t1408 = q2*t1407*2.0;
  78. t1409 = t1383-t1384+t1385+t1388;
  79. t1410 = q3*t1409*2.0;
  80. t1420 = q0*t1404*2.0;
  81. t1411 = t1406+t1408+t1410-t1420;
  82. t1412 = -t1377+t1378+t1379+t1386;
  83. t1413 = q0*t1412*2.0;
  84. t1414 = t1374-t1375+t1376+t1387;
  85. t1415 = t1383+t1384-t1385+t1388;
  86. t1416 = q2*t1415*2.0;
  87. t1417 = t1380-t1381+t1382+t1389;
  88. t1418 = q3*t1417*2.0;
  89. t1421 = q1*t1414*2.0;
  90. t1419 = t1413+t1416+t1418-t1421;
  91. t1422 = P(1,1)*t1397;
  92. t1423 = P(2,1)*t1411;
  93. t1429 = P(7,1)*t1402;
  94. t1430 = P(3,1)*t1419;
  95. t1424 = t1422+t1423-t1429-t1430;
  96. t1425 = P(1,2)*t1397;
  97. t1426 = P(2,2)*t1411;
  98. t1427 = P(1,3)*t1397;
  99. t1428 = P(2,3)*t1411;
  100. t1434 = P(7,2)*t1402;
  101. t1435 = P(3,2)*t1419;
  102. t1431 = t1425+t1426-t1434-t1435;
  103. t1442 = P(7,3)*t1402;
  104. t1443 = P(3,3)*t1419;
  105. t1432 = t1427+t1428-t1442-t1443;
  106. t1433 = t1398+t1399-t1400-t1401;
  107. t1436 = q0*q2*2.0;
  108. t1437 = q1*q3*2.0;
  109. t1438 = t1436+t1437;
  110. t1439 = q0*q3*2.0;
  111. t1441 = q1*q2*2.0;
  112. t1440 = t1439-t1441;
  113. t1444 = t1398-t1399+t1400-t1401;
  114. t1445 = q0*q1*2.0;
  115. t1449 = q2*q3*2.0;
  116. t1446 = t1445-t1449;
  117. t1447 = t1439+t1441;
  118. t1448 = t1398-t1399-t1400+t1401;
  119. t1450 = t1445+t1449;
  120. t1451 = t1436-t1437;
  121. t1452 = P(1,7)*t1397;
  122. t1453 = P(2,7)*t1411;
  123. t1628 = P(7,7)*t1402;
  124. t1454 = t1452+t1453-t1628-P(3,7)*t1419;
  125. t1455 = P(1,8)*t1397;
  126. t1456 = P(2,8)*t1411;
  127. t1629 = P(7,8)*t1402;
  128. t1457 = t1455+t1456-t1629-P(3,8)*t1419;
  129. t1458 = P(1,9)*t1397;
  130. t1459 = P(2,9)*t1411;
  131. t1630 = P(7,9)*t1402;
  132. t1460 = t1458+t1459-t1630-P(3,9)*t1419;
  133. t1461 = q0*t1390*2.0;
  134. t1462 = q1*t1391*2.0;
  135. t1463 = q3*t1395*2.0;
  136. t1473 = q2*t1393*2.0;
  137. t1464 = t1461+t1462+t1463-t1473;
  138. t1465 = q0*t1409*2.0;
  139. t1466 = q2*t1405*2.0;
  140. t1467 = q3*t1404*2.0;
  141. t1474 = q1*t1407*2.0;
  142. t1468 = t1465+t1466+t1467-t1474;
  143. t1469 = q1*t1415*2.0;
  144. t1470 = q2*t1414*2.0;
  145. t1471 = q3*t1412*2.0;
  146. t1475 = q0*t1417*2.0;
  147. t1472 = t1469+t1470+t1471-t1475;
  148. t1476 = P(8,1)*t1402;
  149. t1477 = P(1,1)*t1464;
  150. t1486 = P(2,1)*t1468;
  151. t1487 = P(3,1)*t1472;
  152. t1478 = t1476+t1477-t1486-t1487;
  153. t1479 = P(8,2)*t1402;
  154. t1480 = P(1,2)*t1464;
  155. t1492 = P(2,2)*t1468;
  156. t1493 = P(3,2)*t1472;
  157. t1481 = t1479+t1480-t1492-t1493;
  158. t1482 = P(8,3)*t1402;
  159. t1483 = P(1,3)*t1464;
  160. t1498 = P(2,3)*t1468;
  161. t1499 = P(3,3)*t1472;
  162. t1484 = t1482+t1483-t1498-t1499;
  163. t1485 = t1402^2;
  164. t1488 = q1*t1390*2.0;
  165. t1489 = q2*t1395*2.0;
  166. t1490 = q3*t1393*2.0;
  167. t1533 = q0*t1391*2.0;
  168. t1491 = t1488+t1489+t1490-t1533;
  169. t1494 = q0*t1407*2.0;
  170. t1495 = q1*t1409*2.0;
  171. t1496 = q2*t1404*2.0;
  172. t1534 = q3*t1405*2.0;
  173. t1497 = t1494+t1495+t1496-t1534;
  174. t1500 = q0*t1415*2.0;
  175. t1501 = q1*t1417*2.0;
  176. t1502 = q3*t1414*2.0;
  177. t1535 = q2*t1412*2.0;
  178. t1503 = t1500+t1501+t1502-t1535;
  179. t1504 = dvy*t1433;
  180. t1505 = dvx*t1440;
  181. t1506 = t1504+t1505;
  182. t1507 = dvx*t1438;
  183. t1508 = dvy*t1438;
  184. t1509 = dvz*t1440;
  185. t1510 = t1508+t1509;
  186. t1511 = dvx*t1444;
  187. t1551 = dvy*t1447;
  188. t1512 = t1511-t1551;
  189. t1513 = dvz*t1444;
  190. t1514 = dvy*t1446;
  191. t1515 = t1513+t1514;
  192. t1516 = dvx*t1446;
  193. t1517 = dvz*t1447;
  194. t1518 = t1516+t1517;
  195. t1519 = dvx*t1448;
  196. t1520 = dvz*t1451;
  197. t1521 = t1519+t1520;
  198. t1522 = dvy*t1448;
  199. t1552 = dvz*t1450;
  200. t1523 = t1522-t1552;
  201. t1524 = dvx*t1450;
  202. t1525 = dvy*t1451;
  203. t1526 = t1524+t1525;
  204. t1527 = P(8,7)*t1402;
  205. t1528 = P(1,7)*t1464;
  206. t1529 = P(8,8)*t1402;
  207. t1530 = P(1,8)*t1464;
  208. t1531 = P(8,9)*t1402;
  209. t1532 = P(1,9)*t1464;
  210. t1536 = P(9,1)*t1402;
  211. t1537 = P(2,1)*t1497;
  212. t1545 = P(1,1)*t1491;
  213. t1546 = P(3,1)*t1503;
  214. t1538 = t1536+t1537-t1545-t1546;
  215. t1539 = P(9,2)*t1402;
  216. t1540 = P(2,2)*t1497;
  217. t1547 = P(1,2)*t1491;
  218. t1548 = P(3,2)*t1503;
  219. t1541 = t1539+t1540-t1547-t1548;
  220. t1542 = P(9,3)*t1402;
  221. t1543 = P(2,3)*t1497;
  222. t1549 = P(1,3)*t1491;
  223. t1550 = P(3,3)*t1503;
  224. t1544 = t1542+t1543-t1549-t1550;
  225. t1553 = P(9,7)*t1402;
  226. t1554 = P(2,7)*t1497;
  227. t1555 = P(9,8)*t1402;
  228. t1556 = P(2,8)*t1497;
  229. t1557 = P(9,9)*t1402;
  230. t1558 = P(2,9)*t1497;
  231. t1560 = dvz*t1433;
  232. t1559 = t1507-t1560;
  233. t1561 = P(1,1)*t1510;
  234. t1567 = P(3,1)*t1506;
  235. t1568 = P(2,1)*t1559;
  236. t1562 = P(4,1)+t1561-t1567-t1568;
  237. t1563 = P(1,2)*t1510;
  238. t1569 = P(3,2)*t1506;
  239. t1570 = P(2,2)*t1559;
  240. t1564 = P(4,2)+t1563-t1569-t1570;
  241. t1565 = P(1,3)*t1510;
  242. t1571 = P(3,3)*t1506;
  243. t1572 = P(2,3)*t1559;
  244. t1566 = P(4,3)+t1565-t1571-t1572;
  245. t1573 = -t1507+t1560;
  246. t1574 = P(2,1)*t1573;
  247. t1575 = P(4,1)+t1561-t1567+t1574;
  248. t1576 = P(2,2)*t1573;
  249. t1577 = P(4,2)+t1563-t1569+t1576;
  250. t1578 = P(2,3)*t1573;
  251. t1579 = P(4,3)+t1565-t1571+t1578;
  252. t1580 = P(1,7)*t1510;
  253. t1581 = P(1,8)*t1510;
  254. t1582 = P(1,9)*t1510;
  255. t1583 = P(2,1)*t1518;
  256. t1584 = P(3,1)*t1512;
  257. t1592 = P(1,1)*t1515;
  258. t1585 = P(5,1)+t1583+t1584-t1592;
  259. t1586 = P(2,2)*t1518;
  260. t1587 = P(3,2)*t1512;
  261. t1593 = P(1,2)*t1515;
  262. t1588 = P(5,2)+t1586+t1587-t1593;
  263. t1589 = P(2,3)*t1518;
  264. t1590 = P(3,3)*t1512;
  265. t1594 = P(1,3)*t1515;
  266. t1591 = P(5,3)+t1589+t1590-t1594;
  267. t1595 = dvxNoise*t1433*t1447;
  268. t1596 = P(2,7)*t1518;
  269. t1597 = P(3,7)*t1512;
  270. t1598 = P(5,7)+t1596+t1597-P(1,7)*t1515;
  271. t1599 = P(2,8)*t1518;
  272. t1600 = P(3,8)*t1512;
  273. t1601 = P(5,8)+t1599+t1600-P(1,8)*t1515;
  274. t1602 = P(2,9)*t1518;
  275. t1603 = P(3,9)*t1512;
  276. t1604 = P(5,9)+t1602+t1603-P(1,9)*t1515;
  277. t1605 = P(3,1)*t1526;
  278. t1606 = P(1,1)*t1523;
  279. t1614 = P(2,1)*t1521;
  280. t1607 = P(6,1)+t1605+t1606-t1614;
  281. t1608 = P(3,2)*t1526;
  282. t1609 = P(1,2)*t1523;
  283. t1615 = P(2,2)*t1521;
  284. t1610 = P(6,2)+t1608+t1609-t1615;
  285. t1611 = P(3,3)*t1526;
  286. t1612 = P(1,3)*t1523;
  287. t1616 = P(2,3)*t1521;
  288. t1613 = P(6,3)+t1611+t1612-t1616;
  289. t1617 = dvzNoise*t1438*t1448;
  290. t1618 = dvyNoise*t1444*t1450;
  291. t1619 = P(3,7)*t1526;
  292. t1620 = P(1,7)*t1523;
  293. t1621 = P(6,7)+t1619+t1620-P(2,7)*t1521;
  294. t1622 = P(3,8)*t1526;
  295. t1623 = P(1,8)*t1523;
  296. t1624 = P(6,8)+t1622+t1623-P(2,8)*t1521;
  297. t1625 = P(3,9)*t1526;
  298. t1626 = P(1,9)*t1523;
  299. t1627 = P(6,9)+t1625+t1626-P(2,9)*t1521;
  300. nextP(1,1) = daxNoise*t1485+t1397*t1424+t1411*t1431-t1419*t1432-t1402*t1454;
  301. nextP(2,1) = -t1397*t1478-t1411*t1481+t1419*t1484+t1402*(t1527+t1528-P(2,7)*t1468-P(3,7)*t1472);
  302. nextP(3,1) = -t1397*t1538-t1411*t1541+t1419*t1544+t1402*(t1553+t1554-P(1,7)*t1491-P(3,7)*t1503);
  303. nextP(4,1) = -t1402*(P(4,7)+t1580-P(3,7)*t1506-P(2,7)*t1559)+t1397*t1562+t1411*t1564-t1419*t1566;
  304. nextP(5,1) = t1397*t1585+t1411*t1588-t1402*t1598-t1419*t1591;
  305. nextP(6,1) = t1397*t1607+t1411*t1610-t1402*t1621-t1419*t1613;
  306. nextP(7,1) = -t1628+P(7,1)*t1397+P(7,2)*t1411-P(7,3)*t1419;
  307. nextP(8,1) = -t1527+P(8,1)*t1397+P(8,2)*t1411-P(8,3)*t1419;
  308. nextP(9,1) = -t1553+P(9,1)*t1397+P(9,2)*t1411-P(9,3)*t1419;
  309. nextP(1,2) = -t1402*t1457-t1424*t1464+t1431*t1468+t1432*t1472;
  310. nextP(2,2) = dayNoise*t1485+t1464*t1478-t1468*t1481-t1472*t1484+t1402*(t1529+t1530-P(2,8)*t1468-P(3,8)*t1472);
  311. nextP(3,2) = t1464*t1538-t1468*t1541-t1472*t1544+t1402*(t1555+t1556-P(1,8)*t1491-P(3,8)*t1503);
  312. nextP(4,2) = -t1402*(P(4,8)+t1581-P(3,8)*t1506-P(2,8)*t1559)-t1464*t1562+t1468*t1564+t1472*t1566;
  313. nextP(5,2) = -t1402*t1601-t1464*t1585+t1468*t1588+t1472*t1591;
  314. nextP(6,2) = -t1402*t1624-t1464*t1607+t1468*t1610+t1472*t1613;
  315. nextP(7,2) = -t1629-P(7,1)*t1464+P(7,2)*t1468+P(7,3)*t1472;
  316. nextP(8,2) = -t1529-P(8,1)*t1464+P(8,2)*t1468+P(8,3)*t1472;
  317. nextP(9,2) = -t1555-P(9,1)*t1464+P(9,2)*t1468+P(9,3)*t1472;
  318. nextP(1,3) = -t1402*t1460-t1431*t1497+t1432*t1503+t1491*(t1422+t1423-t1429-t1430);
  319. nextP(2,3) = -t1478*t1491+t1481*t1497-t1484*t1503+t1402*(t1531+t1532-P(2,9)*t1468-P(3,9)*t1472);
  320. nextP(3,3) = dazNoise*t1485-t1491*t1538+t1497*t1541-t1503*t1544+t1402*(t1557+t1558-P(1,9)*t1491-P(3,9)*t1503);
  321. nextP(4,3) = -t1402*(P(4,9)+t1582-P(3,9)*t1506-P(2,9)*t1559)+t1491*t1562-t1497*t1564+t1503*t1566;
  322. nextP(5,3) = -t1402*t1604+t1491*t1585-t1497*t1588+t1503*t1591;
  323. nextP(6,3) = -t1402*t1627+t1491*t1607-t1497*t1610+t1503*t1613;
  324. nextP(7,3) = -t1630+P(7,1)*t1491-P(7,2)*t1497+P(7,3)*t1503;
  325. nextP(8,3) = -t1531+P(8,1)*t1491-P(8,2)*t1497+P(8,3)*t1503;
  326. nextP(9,3) = -t1557+P(9,1)*t1491-P(9,2)*t1497+P(9,3)*t1503;
  327. nextP(1,4) = P(1,4)*t1397+P(2,4)*t1411-P(3,4)*t1419-P(7,4)*t1402-t1432*t1506+t1510*(t1422+t1423-t1429-t1430)-t1559*(t1425+t1426-t1434-t1435);
  328. nextP(2,4) = -P(1,4)*t1464-P(8,4)*t1402+P(2,4)*t1468+P(3,4)*t1472-t1478*t1510+t1484*t1506+t1481*t1559;
  329. nextP(3,4) = -P(9,4)*t1402+P(1,4)*t1491-P(2,4)*t1497+P(3,4)*t1503-t1510*t1538+t1506*t1544+t1541*t1559;
  330. nextP(4,4) = P(4,4)+P(1,4)*t1510-P(3,4)*t1506+P(2,4)*t1573-t1506*t1566+t1510*t1575+t1573*t1577+dvxNoise*t1433^2+dvyNoise*t1440^2+dvzNoise*t1438^2;
  331. nextP(5,4) = P(5,4)+t1595-P(1,4)*t1515+P(2,4)*t1518+P(3,4)*t1512+t1510*t1585-t1506*t1591+t1573*t1588-dvyNoise*t1440*t1444-dvzNoise*t1438*t1446;
  332. nextP(6,4) = P(6,4)+t1617+P(1,4)*t1523-P(2,4)*t1521+P(3,4)*t1526+t1510*t1607-t1506*t1613+t1573*t1610-dvxNoise*t1433*t1451-dvyNoise*t1440*t1450;
  333. nextP(7,4) = P(7,4)-P(7,3)*t1506+P(7,1)*t1510+P(7,2)*t1573;
  334. nextP(8,4) = P(8,4)-P(8,3)*t1506+P(8,1)*t1510+P(8,2)*t1573;
  335. nextP(9,4) = P(9,4)-P(9,3)*t1506+P(9,1)*t1510+P(9,2)*t1573;
  336. nextP(1,5) = P(1,5)*t1397+P(2,5)*t1411-P(3,5)*t1419-P(7,5)*t1402-t1424*t1515+t1432*t1512+t1518*(t1425+t1426-t1434-t1435);
  337. nextP(2,5) = -P(1,5)*t1464-P(8,5)*t1402+P(2,5)*t1468+P(3,5)*t1472+t1478*t1515-t1484*t1512-t1481*t1518;
  338. nextP(3,5) = -P(9,5)*t1402+P(1,5)*t1491-P(2,5)*t1497+P(3,5)*t1503+t1515*t1538-t1512*t1544-t1518*t1541;
  339. nextP(4,5) = P(4,5)+t1595+P(1,5)*t1510-P(3,5)*t1506+P(2,5)*t1573-t1515*t1575+t1512*t1579+t1518*t1577-dvyNoise*t1440*t1444-dvzNoise*t1438*t1446;
  340. nextP(5,5) = P(5,5)-P(1,5)*t1515+P(2,5)*t1518+P(3,5)*t1512-t1515*t1585+t1512*t1591+t1518*t1588+dvxNoise*t1447^2+dvyNoise*t1444^2+dvzNoise*t1446^2;
  341. nextP(6,5) = P(6,5)+t1618+P(1,5)*t1523-P(2,5)*t1521+P(3,5)*t1526-t1515*t1607+t1512*t1613+t1518*t1610-dvxNoise*t1447*t1451-dvzNoise*t1446*t1448;
  342. nextP(7,5) = P(7,5)+P(7,3)*t1512-P(7,1)*t1515+P(7,2)*t1518;
  343. nextP(8,5) = P(8,5)+P(8,3)*t1512-P(8,1)*t1515+P(8,2)*t1518;
  344. nextP(9,5) = P(9,5)+P(9,3)*t1512-P(9,1)*t1515+P(9,2)*t1518;
  345. nextP(1,6) = P(1,6)*t1397+P(2,6)*t1411-P(3,6)*t1419-P(7,6)*t1402+t1424*t1523-t1431*t1521+t1526*(t1427+t1428-t1442-t1443);
  346. nextP(2,6) = -P(1,6)*t1464-P(8,6)*t1402+P(2,6)*t1468+P(3,6)*t1472-t1478*t1523+t1481*t1521-t1484*t1526;
  347. nextP(3,6) = -P(9,6)*t1402+P(1,6)*t1491-P(2,6)*t1497+P(3,6)*t1503-t1523*t1538+t1521*t1541-t1526*t1544;
  348. nextP(4,6) = P(4,6)+t1617+P(1,6)*t1510-P(3,6)*t1506+P(2,6)*t1573-t1521*t1577+t1523*t1575+t1526*t1579-dvxNoise*t1433*t1451-dvyNoise*t1440*t1450;
  349. nextP(5,6) = P(5,6)+t1618-P(1,6)*t1515+P(2,6)*t1518+P(3,6)*t1512+t1523*t1585-t1521*t1588+t1526*t1591-dvxNoise*t1447*t1451-dvzNoise*t1446*t1448;
  350. nextP(6,6) = P(6,6)+P(1,6)*t1523-P(2,6)*t1521+P(3,6)*t1526+t1523*t1607-t1521*t1610+t1526*t1613+dvxNoise*t1451^2+dvyNoise*t1450^2+dvzNoise*t1448^2;
  351. nextP(7,6) = P(7,6)-P(7,2)*t1521+P(7,1)*t1523+P(7,3)*t1526;
  352. nextP(8,6) = P(8,6)-P(8,2)*t1521+P(8,1)*t1523+P(8,3)*t1526;
  353. nextP(9,6) = P(9,6)-P(9,2)*t1521+P(9,1)*t1523+P(9,3)*t1526;
  354. nextP(1,7) = t1454;
  355. nextP(2,7) = -t1527-t1528+P(2,7)*t1468+P(3,7)*t1472;
  356. nextP(3,7) = -t1553-t1554+P(1,7)*t1491+P(3,7)*t1503;
  357. nextP(4,7) = P(4,7)+t1580-P(3,7)*t1506+P(2,7)*t1573;
  358. nextP(5,7) = t1598;
  359. nextP(6,7) = t1621;
  360. nextP(7,7) = P(7,7);
  361. nextP(8,7) = P(8,7);
  362. nextP(9,7) = P(9,7);
  363. nextP(1,8) = t1457;
  364. nextP(2,8) = -t1529-t1530+P(2,8)*t1468+P(3,8)*t1472;
  365. nextP(3,8) = -t1555-t1556+P(1,8)*t1491+P(3,8)*t1503;
  366. nextP(4,8) = P(4,8)+t1581-P(3,8)*t1506+P(2,8)*t1573;
  367. nextP(5,8) = t1601;
  368. nextP(6,8) = t1624;
  369. nextP(7,8) = P(7,8);
  370. nextP(8,8) = P(8,8);
  371. nextP(9,8) = P(9,8);
  372. nextP(1,9) = t1460;
  373. nextP(2,9) = -t1531-t1532+P(2,9)*t1468+P(3,9)*t1472;
  374. nextP(3,9) = -t1557-t1558+P(1,9)*t1491+P(3,9)*t1503;
  375. nextP(4,9) = P(4,9)+t1582-P(3,9)*t1506+P(2,9)*t1573;
  376. nextP(5,9) = t1604;
  377. nextP(6,9) = t1627;
  378. nextP(7,9) = P(7,9);
  379. nextP(8,9) = P(8,9);
  380. nextP(9,9) = P(9,9);
  381. % Add the general process noise
  382. for i = 1:9
  383. nextP(i,i) = nextP(i,i) + processNoise(i)^2;
  384. end
  385. % Force symmetry on the covariance matrix to prevent ill-conditioning
  386. % of the matrix which would cause the filter to blow-up
  387. P = 0.5*(P + transpose(P));
  388. % ensure diagonals are positive
  389. for i=1:9
  390. if P(i,i) < 0
  391. P(i,i) = 0;
  392. end
  393. end
  394. end