Complementary filters enable sensor fusion, are easy to implement and eliminate integrating errors from gyro’s or accelerometers. Normally complementary filters are discussed in the frequency domain. Using simple Python code a 1st order linear complementary filter for determining the quadcopter ground speed was analyzed in the time domain. The results are depicted in the figure shown above. voff represents the filter output of the accelerometer offset, acc(n) the filter output of the accelerometer, vgps(n) the output of the GPS velocity, vgps, and v(n) the sensor fusion output of the filter.
It follows from the figure above that the integrating drift of the accelerometer is converted into a constant steady state error. Moreover this error can be eliminated by deriving the filter output at the start of the quadcopter with GPS input zero, and subtracting this value from the complementary filter output during flight mode. It also follows that the output v(n) (steady state error corrected) corresponds nicely with the GPS velocity (noise added at simulation) and equals the algebraic sum of the more slowly varying acc(n) and vgps(n) contribution. Output noise is suppressed due to the low pass filtering of vgps.
Although these results confirm the already known features of complementary filtering, it helped me a lot in a better understanding of the basic mechanisms of complementary filtering, especially how a delayed, filtered signal vgps(n) nevertheless results in a correct complementary filter response.
The simulated results are confirmed by actual recorded data from my quadcopter, see figure below. For more details consult my google site.