-
Notifications
You must be signed in to change notification settings - Fork 2
Description
With grain of salt 🧂 , may be FALSE -- A.I. Interrogation result
UNOFFICIAL / TESTING : IMUF_257.bin.zip
[BUG] Kalman Filter Performance Degraded Due to Incorrect Covariance Update Signal
Problem Summary
The filtered gyro output from the IMU-F firmware is significantly noisier than the output from a standard EmuFlight flight controller using a similar tune.
This is evident in comparative Blackbox spectrum analysis, where a standard FC shows a nearly "floored" noise spectrum post-filtering, while the IMU-F-equipped FC does not, indicating a substantial performance gap in noise reduction.
Root Cause Analysis
A deep analysis of both the EmuFlight and imu-f source code revealed that while both systems use a Kalman filter, their implementations differ in one critical detail.
The issue lies in the data used to adapt the Kalman filter's noise estimation over time. The function update_kalman_covariance is responsible for calculating the measurement noise (r), which is crucial for the filter's effectiveness.
-
Standard EmuFlight Implementation: The
update_kalman_covariancefunction is fed the final, fully-filtered gyro signal after all LPF and notch filters have been applied. This creates a powerful feedback loop: as the signal gets cleaner, the filter's calculated noise (r) decreases, causing its gain (k) to decrease, which in turn makes the filter even stronger and more aggressive at rejecting noise. -
Current IMU-F Implementation: The
update_kalman_covariancefunction is fed the original, raw, unfiltered gyro signal. Because it always sees a noisy signal, the calculated noise (r) remains high, keeping the filter's gain (k) high. This prevents the filter from becoming sufficiently aggressive and allows more noise to pass through.
This single difference in signal flow is the direct cause of the observed performance gap.
Proposed Solution
The fix is to align the IMU-F's filter behavior with the more effective implementation in EmuFlight. This requires modifying src/filter/filter.c in the imu-f.
The update_kalman_covariance call should be moved to after the PTN filter is applied and fed the filtered data.
Code Modification
--- a/src/filter/filter.c
+++ b/src/filter/filter.c
@@ -98,7 +98,7 @@
filteredData->rateData.y = ptnFilterApply(filteredData->rateData.y, &(lpfFilterStateRate.y));
filteredData->rateData.z = ptnFilterApply(filteredData->rateData.z, &(lpfFilterStateRate.z));
- update_kalman_covariance(gyroRateData);
+ update_kalman_covariance(&(filteredData->rateData));
if (setPointNew)
This change will enable the same self-reinforcing feedback loop found in the main EmuFlight code, allowing the IMU-F's Kalman filter to perform with the same high efficiency and resolving the noise issue.