Basics and Guidelines of Complementary Filters
Basics and Guidelines of Complementary Filters
Magnitude (dB)
x + x̂ −50
G1
xm2 G2
H2 (s) G2 (s) −100 −2
10 10
−1
10
0 1
10
2
10
Frequency (rad/s)
200
Fig. 2. Frequency Domain Complementary Filter
Phase (deg)
100
10
Orientation (deg)
0
−5
−10
Orientation (deg)
in Eq. (5) [8]. The gyro is modeled as the derivative of the
80
actual orientation plus a bias. Noise is also added to the gyro
before the signal is integrated to get orientation. The output 60
of the sensors are then passed through the filters from Eqs. 40
(3) and (4) and combined to get the orientation estimate.
20
1.88 0
H1 (s) = . (5)
s + 1.88 −20
0 50 100 150
Time (s)
8
as the frequency is reduced, the inclinometer is more capable
of tracking the sine wave. The output of the gyro is also
6
expected; it tracks the input well but drifts away from the
actual orientation at 1 degree per second.
4
The filter is tuned by finding the optimal value of ω0 X: 0.22
Y: 2.231
that minimizes the error e. This is done by running multiple 2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
simulations with varying values of ω0 (0.01 rad/s to 0.5 C utoff F requency (rad/s ec)
rad/s). At the end of each simulation, the squared error and
the variance are calculated for each value of ω0 . Figure 7 Fig. 7. Variance of the error vs. cutoff frequency (ω0 ).
shows the result of these simulations. The lowest variance
is σ 2 = 2.23 with an ω0 of 0.22 rad/s. Figures 8 and 9
show plots of the filter output (estimated orientation) and
the squared error with this optimal frequency. Figures 10 and 11 show the filter output and error plots
when ω0 is too high and the output is dominated by the
While exploring the concept of a complementary filter, inclinometer. Notice how similar the output plot matches
it is also worthwhile to look at the filter output at non- the output of the inclinometer in Fig. 5. Figures 12 and 13
optimal frequencies. As Fig. 7 explains, if ω0 is too high, show the filter output and error plots when ω0 is too low and
the inclinometer will dominate the output of the filter. If ω0 the output is dominated by the gyro. These gyro dominated
is too low, the gyro will dominate the output of the filter. plots also show similarities to the gyro output in Fig. 6.
502
2
Estimated Output vs. Actual Orientation: =0.22 Estimation Error: =3, =26.7165
0 0
15 120
Actual Orientation
Estimated Output
10 100
5 80
Orientation (deg)
Error Squared
0 60
−5 40
−10 20
−15 0
0 50 100 150 0 50 100 150
Time (s) Time (s)
Fig. 8. Estimated orientation vs. actual orientation at ω0 = 0.22 rad/s Fig. 11. Squared error for ω0 = 3 rad/s (Inclinometer Dominant).
(Optimal Frequency).
40
Orientation (deg)
15
Error Squared
30
20
10
10
5
0
0 −10
0 50 100 150 0 50 100 150
Time (s) Time (s)
Fig. 9. Squared error for ω0 = 0.22 rad/s (Optimal Frequency). Fig. 12. Estimated orientation vs. actual orientation at ω0 = 0.01 rad/s
(Gyro Dominant).
Estimated Output vs. Actual Orientation: 0
=3
15
Actual Orientation
2
Estimated Output Estimation Error: =0.01, =909.2397
0
1800
10
1600
5
1400
Orientation (deg)
1200
0
Error Squared
1000
−5
800
600
−10
400
−15
0 50 100 150 200
Time (s)
0
0 50 100 150
Time (s)
Fig. 10. Estimated orientation vs. actual orientation at ω0 = 3 rad/s
(Inclinometer Dominant).
Fig. 13. Squared error for ω0 = 0.01 rad/s (Gyro Dominant).
20
+ φ̂
φg 1 15
Variance
s Gi (s)
10
0
φi + 1
φ̂ 0 0.5 1 1.5 2 2.5 3
+
−
C(s) +
s Gain
Fig. 16. Variance of the error vs. controller gain (P ) for SSCF.
Fig. 15. Closed-loop Complementary Filter System. Estimated Output vs. Actual Orientation: P=0.84
15
Actual Orientation
Estimated Output
10
III. S TATE S PACE C OMPLEMENTARY F ILTERS
The complementary filter can be interpreted in state 5
space form in order to easily realize the complementary filter
Orientation (deg)
with digital systems, implement multiple-input multiple- 0
output systems, and use classical control theory for filter
design [6], [23]. Figure 14 illustrates this conversion with −5
an example of the frequency domain complimentary filter
where φi and φg are the outputs from the inclinometer and −10
the gyro, Gi (s) and Gg (s) are the filters for the inclinometer
and gyro, and φ̂ is the estimate of φ. −15
0 50 100 150
Time (s)
To be a complementary filter, Gi (s) + Gg (s) must equal
1 (as shown in Eq. (2)). Therefore Gi (s) and Gg (s) could
be set as the following: Fig. 17. Estimated orientation vs. actual orientation with P = 0.84
(Optimal Gain).
C(s)
Gi (s) = , (6)
C(s) + s
ẋ = (φi − x)P + φg . (9)
s
Gg (s) = . (7)
C(s) + s A. SSCF Example - Using a Gain Controller
According to the diagram in Fig. 14 and the definitions To test the SSCF from Eq. (9), the simulator from Sec-
of Gi (s) and Gg (s), φ̂ is defined as tion II-A was used. After running this simulation multiple
times for different values of P , they are plotted with their
respective error variance to find the gain P with the lowest
C(s) φg s error. Figure 16 shows this plot and a minimum variance of
φ̂ = φi + , σ 2 = 4.15 with a gain of 0.84. Figures 17 and 18 show the
C(s) + s s C(s) + s
1 filter output and squared error plots using the optimal gain.
φ̂ = φi C(s)s + φg − C(s)φ̂ ,
s Even though it was subjected to the same input, the
sφ̂ = (φi − φ̂)C(s) + φg . (8) performance of this filter was not as good as the frequency
domain filter designed in Section II. This could be because
Equation (8) represents the frequency domain comple- of constant bias in the gyro. Introducing an integrator in the
mentary filter in the closed-loop form as displayed in Fig. controller could improve the performance by removing this
15. With this design, classical closed-loop control theory can bias.
be used to design the complementary filter.
B. SSCF Example - Using a PI Controller
After choosing a controller, Eq. (8) can be converted to
state space. Using a gain controller, P , Eq. (9) shows the After adding an integrator to the controller C(s), Eq. (8)
state space representation of a complementary filter with φ̂ can be written as shown below where P is constant gain and
set as the state space variable x. I is integrator gain.
504
2
Estimation Error: P=0.84, =4.1502 Variance vs. Gains
35 0.4
0.35 2.9
30
0.3
25 2.8
0.25
2.7
Error Squared
20
IGain
0.2
2.6
15
0.15
2.5
10
0.1
X: 0.44
Y: 0.05
Z: 2.27 2.4
5 0.05
2.3
0 0
0 50 100 150 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6
Time (s) PGain
Fig. 18. Squared error for P = 0.84 (Optimal Gain). Fig. 20. Variance of the error vs. controller gains (P and I) for SSCF.
10
Orientation (deg) 0
(10)
−15
0 50 100 150
The term (φi − φ̂)I/s is compensation for the bias and Time (s)
16
Notice the similarities between Eq. (11) and Eq. (9).
Equation (11) can now be rearranged into its matrix repre- 14
6
−P 1 x1
x˙1 P 1 φi
= + , 4
x˙2 −I 0 x2 I 0 φg
" # 2
φ̂ 1 0 x1 0
= . (12) 0 50 100 150
b̂ 0 −1 x2 Time (s)
Figure 19 shows the realization of Eq. (12) in Simulink. Fig. 22. Squared error for P = 0.44 and I = 0.048 (Optimal PI Gains).
This model was used with the same input signal and sensor
models from the simulation in Section II-A. Multiple values
of P and I were simulated, the variance of the error was Figures 21 and 22 show the output of the filter with
found, and the contour plot in Fig. 20 was generated to find optimal gains. With a variance of σ 2 = 2.31, the perfor-
the optimal values for P and I that minimize the variance mance of this filter is very similar to the performance of
of the error. As shown in Fig. 20, the optimal values for P the frequency domain filter designed in Section II. This
and I in this example are 0.44 and 0.048, respectively, with similarity is expected. If the complementary filter from
a variance of σ 2 = 2.31. Eq. (12) were converted back into its frequency domain
505
1.6
Estimated Bias vs. Actual Bias: P=0.44, I=0.048 Although Gaussian statistical models are traditional and
Actual Bias
Estimated Bias
have a wide range of applications, non-Gaussian, power-law
1.4
statics are ubiquitous in practice [27]. Although augmented
1.2 Kalman-style filters (such as the Kalman-Levy filter) that
1
allow non-Gaussian PDFs have been considered in research,
they are not well studied and have even higher mathematical
Bias (deg)
506
[5] H. Rehbinder and X. Hu, “Drift-free Attitude Estimation for Measurements: A Theoretical Study,” in Proc. of the IEEE Confer-
Accelerated Rigid Bodies,” Automatica, vol. 40, no. 4, pp. 653–659, ence on Decision and Control held jointly with the Chinese Control
Apr. 2004. Conference., 2009, pp. 6407–6412.
[6] R. Mahony, T. Hamel, and J.-M. Pflimlin, “Complementary Filter [25] G. Baldwin, R. Mahony, J. Trumpf, T. Hamel, and T. Cheviron,
Design on the Special Orthogonal Group SO(3),” in Proc. of the “Complementary Filter Design on the Special Euclidean Group
IEEE Conference on Decision and Control and European Control SE(3),” in Proc. of the European Control Conference, vol. 1, no. 3,
Conference, 2005, pp. 1477–1484. 2007, pp. 3763–3770.
[7] W. Higgins, “A Comparison of Complementary and Kalman [26] J. M. Roberts, P. I. Corke, and G. Buskey, “Low-cost flight control
Filtering,” IEEE Transactions on Aerospace and Electronic Systems, system for a small autonomous helicopter,” in Proc. of the Aus-
vol. AES-11, no. 3, pp. 321–325, May 1975. tralasian Conference on Robotics and Automation, vol. 1, 2002, pp.
[8] A.-J. Baerveldt and R. Klang, “A Low-cost and Low-weight Attitude 71–76.
Estimation System for an Autonomous Helicopter,” in Proc. of the [27] M. Newman, “Power laws, pareto distributions and zipfs law,”
IEEE International Conference on Intelligent Engineering Systems, Contemporary Physics, vol. 46, no. 5, pp. 323–351, 2005.
1997, pp. 391–395. [28] N. Gordon, J. Percival, and M. Robinson, “The kalman-levy filter
[9] J. M. Roberts, P. I. Corke, and G. Buskey, “Low-cost Flight Control and heavy-tailed models for tracking maneuvering targets,” in Proc.
System for a Small Autonomous Helicopter,” in Proc. of the IEEE of the International Conference on Information Fusion, 2003, pp.
International Conference on Robotics and Automation, vol. 1, 2003, 1024–1031.
pp. 546–551. [29] N. I. Krobka, “Differential methods of identifying gyro noise struc-
[10] T. Hamel and R. Mahony, “Attitude Estimation on SO[3] Based on ture,” Gyroscopy and Navigation, vol. 2, no. 3, pp. 126–137, 2011.
Direct Inertial Measurements,” in Proc. of the IEEE International
Conference on Robotics and Automation, 2006, pp. 2170–2175.
[11] R. G. Brown and P. Y. C. Hwang, Introduction to Random Signals
and Applied Kalman Filtering, 2nd ed., ser. Wiley, TK5102.5.B696.
John Wiley & Sons, 1997, no. 4.
[12] W. H. Wirkler, “Aircraft Course Stabilizing Means,” pp. 23, Patent
2,548,278, 1951.
[13] W. Anderson and E. Fritze, “Instrument Approach System Steering
Computer,” Proc. of the Institute of Radio Engineers, vol. 41, no. 2,
pp. 219–228, Feb. 1953.
[14] F. R. Shaw and K. Srinivasan, “Bandwidth Enhancement of Position
Measurements Using Measured Acceleration,” Mechanical Systems
and Signal Processing, vol. 4, no. 1, pp. 23–38, 1990.
[15] M. Zimmermann and W. Sulzer, “High Bandwidth Orientation Mea-
surement and Control Based on Complementary Filtering,” in Proc.
of the SYROCO IFAC Symposium on Robot Control, Vienna, Austria,
Sep. 1991.
[16] E. R. Bachmann, I. Duman, U. Y. Usta, R. B. McGhee, X. P. Yun,
and M. J. Zyda, “Orientation Tracking for Humans and Robots Using
Inertial Sensors,” in Proc. of the IEEE International Symposium on
Computational Intelligence in Robotics and Automation, 1999, pp.
187–194.
[17] E. R. Bachmann, R. B. McGhee, X. Yun, and M. J. Zyda,
“Inertial and Magnetic Posture Tracking for Inserting Humans into
Networked Virtual Environments,” in Proc. of the ACM Symposium
on Virtual Reality Software and Technology (VRST). ACM Press,
2001, p. 9.
[18] E. R. Bachmann, D. McKinney, R. B. McGhee, and M. J.
Zyda, “Design and Implementation of MARG Sensors for 3-DOF
Orientation Measurement of Rigid Bodies,” in Proc. of the IEEE
International Conference on Robotics and Automation, 2003, pp.
1171–1178.
[19] S. Salcudean, “A Globally Convergent Angular Velocity Observer
for Rigid Body Motion,” IEEE Transactions on Automatic Control,
vol. 36, no. 12, pp. 1493–1497, 1991.
[20] J. M. Pflimlin, T. Hamel, and P. Souères, “Nonlinear Attitude
and Gyroscope’s Bias Estimation for a VTOL UAV,” International
Journal of Systems Science, vol. 38, no. 3, pp. 197–210, Jan. 2007.
[21] R. Mahony, T. Hamel, and J.-M. Pflimlin, “Nonlinear Complemen-
tary Filters on the Special Orthogonal Group,” IEEE Transactions
on Automatic Control, vol. 53, no. 5, pp. 1203–1218, 2008.
[22] A. R. Plummer, “Optimal Complementary Filters and Their
Application in Motion Measurement,” Institution of Mechanical
Engineers, Part I: Journal of Systems and Control Engineering, vol.
220, no. 6, pp. 489–507, 2010.
[23] P. Oliveira, I. Kaminer, and A. Pascoal, “Navigation System Design
Using Time-varying Complementary Filters,” IEEE Transactions on
Aerospace and Electronic Systems, vol. 36, no. 4, pp. 1099–1114,
2000.
[24] R. Mahony, T. Hamel, J. Trumpf, and C. Lageman, “Nonlinear
Attitude Observers on SO(3) for Complementary and Compatible
507