**This brings more questions:**

In `NavEKF3_core::CovarianceInit()`

(here), a covariance matrix is initialized, and the parameters of interest are used. The PosD covariance used is the parameter for barometer noise (ALT_M_NSE):

```
// velocities
P[4][4] = sq(frontend->_gpsHorizVelNoise);
P[5][5] = P[4][4];
P[6][6] = sq(frontend->_gpsVertVelNoise);
// positions
P[7][7] = sq(frontend->_gpsHorizPosNoise);
P[8][8] = P[7][7];
P[9][9] = sq(frontend->_baroAltNoise);
```

I found that `P[4][4]`

and `P[5][5]`

are reset in `NavEKF3_core::ResetVelocity()`

(here) to

```
P[5][5] = P[4][4] = sq(MAX(frontend->_gpsHorizVelNoise,gpsSpdAccuracy));
```

`P[7][7]`

and `P[8][8]`

are reset in `NavEKF3_core::ResetPosition()`

(here) to

```
P[7][7] = P[8][8] = sq(MAX(gpsPosAccuracy,frontend->_gpsHorizPosNoise));
```

`P[9][9]`

is set in `NavEKF3_core::ResetHeight()`

(here) to

```
P[9][9] = posDownObsNoise;
```

But for the vertical velocity variance, `P[6][6]`

, it only shows up in `NavEKF3_core::ConstrainVariances()`

(here) as

```
P[6][6] = sq(frontend->_gpsVertVelNoise);
```

and in `NavEKF3_core::ResetHeight()`

(here) as

```
P[6][6] = sq(frontend->_gpsVertVelNoise);
```

Are these functions (`ResetVelocity()`

, `ResetPosition()`

, `ResetHeight()`

and `ConstrainVariances()`

) continuously being called in flight? If so, does that means that the speed accuracy and NE position accuracy reported by the GPS are being used in this covariance matrix, but not the GPS’s vertical position accuracy? **Why**?

I also found out that this `P`

matrix is logged in XKV. I had a look at my logs, and I am now even more perplexed.

My parameters were:

VELNE_M_NSE = 0.3 m/s

VELD_M_NSE = 0.5 m/s

POSNE_M_NSE = 0.5 m

So I shouldn’t expect values lower than their square (0.09 and 0.25) in the XKV log, right? Yet, here are the average values in the XKV log:

`P[4][4]`

= 0.009 m/s

`P[5][5]`

= 0.009 m/s

`P[6][6]`

= 0.006 m/s

`P[7][7]`

= 0.027 m

`P[8][8]`

= 0.027 m

`P[9][9]`

= 0.047 m

I was wondering how is this possible, if these should be no less than 0.09 and 0.25, as they are constrained by the x_NSE parameters.

And if the variances are so good, how am I often reaching terrible vertical innovations (differences between predicted states and observations) on my primary EKF lane? Some times all EKF lanes nicely match the vertical position and vertical velocity reported by the GPS, sometimes there are differences of up to 1.2 m and 0.8 m/s.

This is the issue I’m trying to solve. I’m using a RTK GPS because I need my drone to have an accurate estimate of it’s position. Here is an example of a problematic flight. The following figure shows the reported GPS altitude (minus EKF origin altitude) and vertical velocity, compared to the 3 EKF estimations, and the position and velocity used by the position controller (PSCD), basically telling me which EKF lane is being used. Horizontally, the drone is traveling at 20 km/h and slowly reaches hover at the dotted vertical line, and then gradually accelerates to reach 60 km/h at the end of the highlighted red zone.

The vertical innovations are large, mostly in lane 0 and lane 1:

Yet the variances are tiny:

Vibrations are low (under 5 m/s2 in all axes on all IMU’s) and accelerations are low.

**I know I’m missing crucial information into understanding what is going on**, and how the x_NSE parameters can affect the state estimation. What is the difference between observation variances `R_OBS`

I found in my last reply and the variances used in the covariance matrix `P`

?

I am at heart a mechanical engineer, and would need some help understanding this.

Again, sorry for the tag. I am only trying to reach the best minds that can help me out.

Also, please let me know if this is a discussion best had over on Discord.