Research studies on designing an accurate AHRS with minimum error could be categorized in three main topics, namely complementary filters (CF), optimization approaches, and Kalman filter (KF)-based solutions. The authors of [
3,
4] have considered AHRS improvement using CF and MEMS sensors. A more completed AHS was designed and implemented by the authors of [
5] based on explicit CF, which showed great capability for implementation in embedded hardware [
5]. In these papers, although the systems showed acceptable real-time performance, the drift estimation in passive and direct CFs were not robust enough in highly dynamic experiments. Apart from that, the system demonstrated dependency to methods of initialization. Adaptive Kalman filter (AKF) [
6], extended Kalman filter (EKF) [
7], and dual Kalman filter (DKF) methods [
8] have been performed for orientation estimation with a basic model of the system. A precise stable Kalman-based AHRS was designed as an approach of the simultaneous localization and mapping (SLAM) applications by the authors of [
9]. Furthermore, an EKF using a depth measurement for underwater AHRS and unscented Kalman filter (UKF) methods was investigated by the authors of [
10,
11]. As the attitude estimators require the precise model and noise covariance determiner, a novel time-varying noise covariance EKF was designed and experimented. The designed filter considered changing the noise covariance matrix of the system’s model to identify the magnitude of the angle between the estimated gravitational and measured acceleration [
12]. In addition, determination of this angle and the orientation between the body and the navigational coordinates can be considered as an optimization problem. The quaternion-based optimization approach was studied by the authors of [
13] using the gradient descent algorithm, known as Madgwick, with magnetic angular rate and gravity (MARG) sensors [
14]. The mentioned works have had great improvements in attitude and heading estimation using kinds of Kalman-based systems. However, they did not analyze the behavior of error in noisy measurements, which is prevalent in low-cost AHRS designs. As a result, in highly dynamic maneuvers, fast angular rates, and noisy environments, the outputs can be diverged through time.
Low-cost MEMS-based sensors, especially the magnetometers, are required to be calibrated deterministically and stochastically. A KF-based AHRS method was studied by the authors of [
15] in environments with high magnetic distortion. Also, some efforts have been performed to use attitude determination methods in healthcare applications, such as the fall detection of elderly persons [
16], motion capture for sport activity analysis [
17], and shoulder injury prevention [
18]. The mentioned works have only considered special scenarios, which means they did not show the potential of their works to be expanded in all medical situations and sport activities. Wearable low-cost and lightweight IMUs were used in those applications. A comprehensive comparison between CF, UKF, EKF, Madgwick, and Mahony by the authors of [
19] showed that the minimum AHRS error between CF and Kalman-based algorithms is accounted for by the EKF, with better results in attitude and position estimations. The authors of [
20] compared Mahony and Madgwick and demonstrated that there is no significant difference between them. Apart from the mentioned filter-based AHRS algorithms, some researches have investigated the use of integration of AHRS with GPS signals to estimate more precise Euler angles. The method has shown significant results in airspace applications, but the method is significantly affected by pseudorange measurements of GPS and cannot respond to GPS-challengeable situations [
21,
22,
23].
2.1. EKF Model and Parameters
There are different orientation representations between the body and navigation frame. This paper considered the quaternion-based equations because of their nonsingularity and lower computation complexity compared to directed cosine matrix (DCM) with nine integration equations [
12,
24]. The system model of EKF, defined with state vector
, is formulated in Equation (1).
where
,
,
, and
are the elements of quaternion vector of
, and model matrix of
is defined as Equations (2) and (3).
is the rotation angle for a time step, and matrix
is the skew symmetric of quaternion form of angular velocity vector [
12,
25].
For the measurement model, the magnetometer and acceleration data are considered as the EKF measurement, as defined in Equation (4).
is the measurement matrix, and
consists of two elements, namely the normalized specific force and normalized horizontal component of the geomagnetic field. The first one is achieved from acclerometer and the second one from magnetometer output [
12,
25].
where
and
are considered as
and
[
12]. The
and
subscripts show the body and navigation coordinates. The
is calculated from cross-product of vectors
and
. This calculation is necessary because the geomagnetic field is not parallel to the earth. Fortunately, the obtained
is parallel to the magnetic north [
12]. Parameters a and b are defined in Equations (5) and (6) [
12].
As mentioned before, the measurement model predicts the gravitational acceleration and geomagnetism in the body frame. The predicted measurement is included two elements of
and
which are obtained from Equation (7). The horizontal element of
is considered as the magnetometer measurement [
12].
The conversion matrix
between navigation to body frame is obtained from predicted quaternion states with following the Equation (8). The simplified form of measurement matrix is considered in Equation (9) [
12,
25].
Determination of the EKF parameters is required before the designing process. The important parameters of EKF are the measurements of noise covariance
, process noise covariance
, and the initialization parameters comprised of initial states vector
and initial error covariance
. Initialization considers the initial orientation of the system, which can be characterized as wahba’s problem. The most effective approach to the problem is the triad algorithm [
26,
27,
28,
29,
30]. The algorithm deliniates the angle between two nonparallel vectors. To initialize the attitude determination system, the gravitional acceleration of the two vectors and the magnetic field of the earth are defined as, and
, respectively. The vectors are obtained from transforming the magnetometer and accelerometer’s output from the body frame to the navigation frame with multiplying each one with
[
26,
27,
28,
29].
Two orthogonal matrices, from the body frame and from the navigation frame, are determined to calculate the transformation matrix of
for attitude initialization. The orthogonal matrices are defined as
and
, which are calculated as Equations (10) and (11) [
12].
According to the fact that
and
, the
is calculated as the matrix in Equation (12).
Eventually, the parameters of quaternion vactor for the attitude initialization,
, are obtained in Equations (13) and (14), as explained completely by the authors of [
31].
After the initialization of the states vector
and the error covariance matrix
, EKF needs to update the estimated states and estimated covariances. The measurement noise covariance was selected to vary with time with regard to
α, which is the magnitude of the angle between the estimated gravitional acceleration,
, and the measured specific force,
[
12]. The measurement noise covariance matrix,
, in Equation (15), consists of the measured noise covariances of the acceleration and magnetometer sensors [
12].
where
changes as a results of the variation in
α. The weight value,
, and the constant shifter,
, satisfy the performance accuracy of the attitude estimation algorithm [
12].
The matrix
is defined in Equation (17), assuming that the gyroscope uses the white gaussian noise model [
25]. The proposed EKF with the time-varying noise covariance was considered for the attitude estimation in the AHRS. In the following section, the main innovation of this study regarding to prediction and compensation filter is described in detail.