# How to handle sensor data for a sensor-fusion algorithm

I am implementing the explicit complementary filter(see below) with a 9DOF MEMS sensors (accelerometer, magnetometer and gyroscope) for attitude estimation.

Currently, the gyro and accel update rates are at ~1kHz and I am running my filter at 100Hz. The magnetometer refresh rate is running at ~20hz.

The constraints are that I can't modify the sensors reading rate and the algorithm can't be run at more than 400Hz.

As it is implemented right now, I read the gyro and accel if available, optionally the magnetic field if new data is available and run the maths, trying to keep my update rate at 100Hz.

But in addition to the poor performance I observe, it seems the current implementation is not a good way to handle the sensors reading.

From what I read, it seems there are more efficient way to handle the data:

1. Running my filter at 400Hz where I run a buffer which accumulates gyro and accel samples, averages them and use it every 100Hz to update my filter (with the risk to increase bias and noise) ?

2. Running a low pass filter @400Hz on the raw data and update my ECF every 10ms ?

3. A combination of the two previous solutions ?

ECF Algorithm:

$$\dot{\hat{q}} = \frac{1}{2} \hat{q}\otimes p(\Omega_{y}-\hat{b} + k_{P}\omega_{meas} ).$$

$$\dot{\hat{b}} = -k_{I}\omega_{meas}.$$

where $$\otimes$$ is the quaternion cross operator, $$w_{meas}$$ the sum of cross product between accel and mag reading with respectively their estimates. $$\Omega_{y}$$ is the gyro measurements. $$k_I$$ and $$k_P$$ are the filter gains.

[EDIT]

The chosen strategy was to accumulate and compute the mean from sensors data as the quaternion propagation step is considering these values being constants. After the update step, the buffer is emptied.