I have read some papers about mahony filter design..the filter corrects the error in gyroscope measurement using PI compensator....the error in gyro reading is calculated using the gravity vector..the gravity vector has two components V and W..can any one define the V and W vectors..or give me their names? The following link enter link description hereshows in heading (sample filter 2complementary filter with cosine matrices after mahony) the two vectors vt and wt...i want to know what they are?... also the vt and wt are also shown in the following figureenter image description here

  • \$\begingroup\$ Can you add links to the references you have read ? Different references may be using different symbols. \$\endgroup\$
    – AJN
    Commented Oct 5, 2020 at 13:05
  • \$\begingroup\$ hal.archives-ouvertes.fr/hal-00488376/document \$\endgroup\$
    – user255471
    Commented Oct 5, 2020 at 13:07
  • \$\begingroup\$ The reference you linked to shows acceleration has three components: \$v_a=R^T \cdot e_3\$ (page 3). There seems to be no reference to two components V and W in the linked reference. Also, the question says: "The gravity vector has two components V,W. can any one define the V and W vectors ". Are V and W individual components or separate vectors ? Please edit more details into your question instead of adding to comments. (Comments may get removed later, making the question incomplete). \$\endgroup\$
    – AJN
    Commented Oct 5, 2020 at 13:51
  • \$\begingroup\$ motionsensorcomputing.com/index.php/… \$\endgroup\$
    – user255471
    Commented Oct 5, 2020 at 15:00
  • \$\begingroup\$ The above link shows in heading (sample filter 2complementary filter with cosine matrices after mahony) the two vectors vt and wt...i want to know what they are? \$\endgroup\$
    – user255471
    Commented Oct 5, 2020 at 15:03

1 Answer 1


Imagine a reference frame (inertial frame, spatial frame etc.). The orientation of the IMU is specified with respect to this reference frame. Let's explain part of the the algorithm with an example.

Let the reference frame be define so. Z axis points towards centre of earth; i.e. in the direction of gravitational force. Let the X axis point towards north. Y axis be defined in such a way as to get a right handed reference frame.

So the (normalised) gravity vector in the above reference frame is clearly1

$$\begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix}$$

IMU however measures the acceleration (due to gravity if it is kept stationary) in it's own frame; usually called the body frame. In that frame, the (normalised) gravity vector coming from the accelerometer (as measured by the sensors rigidly fixed on the IMU) is

$$ \begin{bmatrix} {}^s a_x\\ {}^s a_y\\ {}^s a_z \end{bmatrix} $$

Both the above vectors represent the same physical quantity; the gravitational force vector. However, we cannot compare them directly since both vectors have been resolved in different frames.

Let \$R_{true}\$ be the rotation matrix4 that allows you to convert a vector in the inertial reference frame to the IMU body frame. Then2,3

$$ \begin{bmatrix} {}^s a_x\\ {}^s a_y\\ {}^s a_z \end{bmatrix} = R_{true} \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix} $$

\$R_{true}\$ is unknown to us. What we have is only an estimate of \$R_{true}\$; Let's call it \$R_{est}\$. We want to bring \$R_{est}\$ closer to \$R_{true}\$ with each successive measurement.

To bring \$R_{est}\$ towards \$R_{true}\$, the correction-rotation that needs to be applied to \$R_{est}\$ is about the axis

$$ \left( R_{est} \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix} \right) \times \begin{bmatrix} {}^s a_x\\ {}^s a_y\\ {}^s a_z \end{bmatrix} = \hat{v}_t \times \begin{bmatrix} {}^s a_x\\ {}^s a_y\\ {}^s a_z \end{bmatrix} $$

Note that, when \$R_{est}=R_{true}\$, the correction-rotation-axis will become zero. The above shows what the vector \$v_t\$ is.


In short, \$\hat{v}_t\$ is the acceleration vector transformed into the estimated IMU frame so that it can be compared with the measured acceleration vector which is in the IMU frame.


1 It could be [0;0;-1] also depending on whether we are talking about force, reaction force, acceleration, or sensed acceleration. Let's not worry about that for this answer.

2 \$v_a = R^T e_3\$ is the notation in the first link you commented.

3 ideal sensor, perfect knowledge etc. etc.

4 The explanation is in terms of rotation matrices for notational convinience, but it can be easily adapted to quaternions.

5 The acceleration vector turned out to be very easy to represent in the inertial reference frame since one of the axes of the inertial frame was chosen to point towards the centre of the earth. This is not the case for magnetic vector. The magnetic vector \$\hat{w}_t\$ in general will have all three components non-zero however you choose the reference frame. But no worry, the expression for magnetic model in inertial frames can be calculated (approximately) from IGRF or WMM or any other model. We can also skip these models if we are willing to measure the magnetic field of the area where the experiments is conducted before the experiments starts.

edit: In our example, we defined inertial frame X axis as pointing towards (geographic) north. So the magnetic field will take a simple form and can be found from declination and inclination information.

6 Be very careful when following multiple reference documents / papers / websites / codes. Here in this example, we converted the inertial vector to estimated IMU frame and compared with the measured data in the IMU frame. But some follow the opposite convention. They convert measured data to estimated inertial frame and compare to the value in the inertial frame. Stick to one document / code / website which is correct and easy to understand and follow that. Do not mix and match formulae from different sources without checking their conventions.

  • \$\begingroup\$ Really,i am very thankful very much...you are a great person...thank you \$\endgroup\$
    – user255471
    Commented Oct 5, 2020 at 17:01
  • \$\begingroup\$ So.i want to confirm something with you...vt is estimated accelaration from the previous reading in body frame...also wt is the estimated magnetic field reading in body frame...is this right? \$\endgroup\$
    – user255471
    Commented Oct 5, 2020 at 17:03
  • \$\begingroup\$ Yes. The estimated quaternion from previous step is used to transform the expected vector in inertial frame to estimated IMU frame. So in the acceleration example, \$[0;0;1]\$ will always be the same. But the \$R_{est}\$ used along with it (or corresponding quaternion) will be taken from previous step. So, \$v_t\$ depends on previous estimate. I have gone through the sample code in one of the links, and this is how i have understood it to be. But \$v_t\$ does not directly depend on previous step accelerometer reading; only indirectly through the \$R_{est}\$ . \$\endgroup\$
    – AJN
    Commented Oct 5, 2020 at 17:12
  • \$\begingroup\$ Yes. \$w_t\$ is the similar to \$v_t\$, but for the magnetic field. \$\endgroup\$
    – AJN
    Commented Oct 5, 2020 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.