# EKF2 replay matlab vs px4

**URL:** <https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970>\
**Category:** PX4 Autopilot\
**Created:** [April 27, 2024, 3:42pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970 "2024-04-27T15:42:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_O](https://discuss.px4.io/user_avatar/discuss.px4.io/m_o/32/15904_2.png) [@M\_O](https://discuss.px4.io/u/M_O)\
**Post date:** [April 27, 2024, 3:42pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/1 "2024-04-27T15:42:50Z")

</div>

I attempted to validate the EKF2 replay using MATLAB from the GitHub repository provided ([PX4-ECL/EKF/matlab/EKF\_replay at master · PX4/PX4-ECL · GitHub](https://github.com/PX4/PX4-ECL/tree/master/EKF/matlab/EKF_replay)). Upon executing the ulg file obtained from a SITL in MATLAB and supplying messages such as sensor\_combined, vehicle\_air\_data, vehicle\_magnetometer, and vehicle\_gps\_position, and configuring the parameters as instructed in MATLAB, mirroring those of the original mission, I executed the RunFilter.m function. Then, I plotted the x-NED coordinates derived from the output of the RunFilter function against the x-NED coordinate message vehicle\_local\_position. However, I observed that the outcomes were markedly dissimilar.

 ![image](https://discuss.px4.io/uploads/default/original/3X/f/0/f0e09721e43a4812bca0cebe9c9d198eab2b78fa.png)

So, why does MATLAB fail to accurately compute the replay, and what distinguishes it from the calculation performed in the PX4 ekf2 replay?

The sensor data and local position data vs MATLAB replay data can be found in [EKF2\_Replay - Google Drive](https://drive.google.com/drive/folders/12UKS4Vh2nyae80niMPMBYw-S0u-gnMI2?usp=sharing)

the full log file can be found in: [https://review.px4.io/plot\_app?log=0c3ad6f8-6791-4bbb-96d1-bf040e6eab4b](https://review.px4.io/plot_app?log=0c3ad6f8-6791-4bbb-96d1-bf040e6eab4b)

---

<div class="post-metadata">

**Author:** ![Douglas\_wong](https://discuss.px4.io/user_avatar/discuss.px4.io/douglas_wong/32/16249_2.png) [@Douglas\_wong](https://discuss.px4.io/u/Douglas_wong)\
**Post date:** [April 27, 2024, 5:03pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/2 "2024-04-27T17:03:28Z")

</div>

I think it’s just because the Matlab replay is not well maintained as the px4 replay that’s why they gave different results, even the timestamps to publish the topics are different so the logic behind the two seems different, maybe @Paul_Riseborough can help since he’s the one in charge of EKF and estimation system

---

<div class="post-metadata">

**Author:** ![M\_O](https://discuss.px4.io/user_avatar/discuss.px4.io/m_o/32/15904_2.png) [@M\_O](https://discuss.px4.io/u/M_O)\
**Post date:** [April 29, 2024, 9:41am UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/3 "2024-04-29T09:41:36Z")

</div>

@JulianOes Do you think it’s because the matlab EKF doesn’t give the same results because it not as maintained as the PX4-Autopilot repository or there is a possible another reason?

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [May 1, 2024, 9:13am UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/4 "2024-05-01T09:13:04Z")

</div>

That old Matlab EKF is now quite different from what’s implemented in PX4’s EKF2. If you want to replay ulog files, please use [System-wide Replay | PX4 Guide (main)](https://docs.px4.io/main/en/debug/system_wide_replay.html#ekf2-replay)

---

<div class="post-metadata">

**Author:** ![M\_O](https://discuss.px4.io/user_avatar/discuss.px4.io/m_o/32/15904_2.png) [@M\_O](https://discuss.px4.io/u/M_O)\
**Post date:** [May 1, 2024, 12:34pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/6 "2024-05-01T12:34:17Z")

</div>

Thank you. To understand the EKF2 replay in MATLAB is there a documentations or someway to understand the order of scripts to go through or the sole possibility is going on an arbitrary journey?

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [May 1, 2024, 2:03pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/7 "2024-05-01T14:03:26Z")

</div>

I’ve never seen a documentation. Again, you’ll be on you own here, the last update of these files was about 5 years ago and the ECL repo is now archived as we stopped using it 3 years ago. Since then, the development happens in [PX4-Autopilot/src/modules/ekf2 at main · PX4/PX4-Autopilot · GitHub](https://github.com/PX4/PX4-Autopilot/tree/main/src/modules/ekf2)

---

<div class="post-metadata">

**Author:** ![M\_O](https://discuss.px4.io/user_avatar/discuss.px4.io/m_o/32/15904_2.png) [@M\_O](https://discuss.px4.io/u/M_O)\
**Post date:** [May 1, 2024, 5:58pm UTC](https://discuss.px4.io/t/ekf2-replay-matlab-vs-px4/37970/8 "2024-05-01T17:58:37Z")

</div>

Apologies for any confusion. I’m wondering if there’s a clear sequence of scripts to follow in order to grasp the estimation system, particularly EKF and EKF2 replay in PX4. For instance, in the provided link, there are scripts like ekf.cpp and EKF2.cpp.

Additionally, I’ve noticed that in PX4 documentation, it references both EKF and estimator interchangeably. Moreover, in the published uORB topics, some are attributed to EKF2 while others to estimator. Could “estimator” possibly refer to the output predictor?
