View full-text article in PMC Sensors (Basel). 2016 Jan 26;16(2):153. doi: 10.3390/s16020153 Search in PMC Search in PubMed View in NLM Catalog Add to search Copyright and License information © 2016 by the authors; licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons by Attribution (CC-BY) license (http://creativecommons.org/licenses/by/4.0/). PMC Copyright notice Algorithm A2 for each measured sample from the sensors do ωkb←gyroscope sample Prediction Predict the quaternion and the magnetic disturbance x^k−=[q^kbn−b^knm−]=[exp(Ω(ωk−1b)Ts)0303I3][q^k−1bn+b^k−1nm+] Process noise covariance matrix Qk−1=[(σgTs2)2Ξ(q^k−1bn+)I3Ξ(q^k−1bn+)T04×303×4σ2b⋅I3] Update: compute R^bn−=quaternionToMatrix(q^bn−) yk=[ykmagykacc],ykmag←magnetometer sampleykacc←accelerometer sample Sensor data validation Racc={I3⋅σ2a, if |yacc−R^bn−gn|<εacc∞, otherwise Rmag={I3⋅σ2m, if |ymag−R^bn−(hn−b^knm−)|<εmag∞, otherwise R=[RmagRacc] Jacobian calculation H=[Ψ(q^kbn−,hn+b^knm−)RbnΨ(q^kbn−,gn)03] x^+←KalmanUpdate (x^−, Qk−1, yk, H, R) end for