6
$\begingroup$

I know that the Complementary Filter has the functions of both LPF and HPF. But I think my understanding on the principal behind it is still unclear.

I am quite new on digital signal processing, and maybe some very fundamental explanations will help a lot.

Say I have a Complementary Filter as follows:

$$y =a\cdot y+(1-a)\cdot x$$

Then my parameter $a$ may be calculated by $$a=\frac{\text{time constant}}{\text{time constant}+\text{sample period}}$$ where the $\text{sample period}$ is simply the reciprocal of the $\text{sampling frequency}$.

The $\text{time constant}$ seems to be at my own choice.

My Questions:

  1. What is the theory behind this calculation?
  2. How do we choose the $\text{time constant}$ properly?

Note: I also posted this question on Stack Overflow, as the answers there are likely to be slightly different in emphasis.

$\endgroup$
  • $\begingroup$ The difference equation you give for the complimentary filter isn't -- it's the difference equation for a low-pass filter. $\endgroup$ – TimWescott Aug 7 '13 at 21:00
  • $\begingroup$ Multi-posted to Stack Overflow. $\endgroup$ – Mark Booth Aug 7 '13 at 23:14
  • 2
    $\begingroup$ Please don't post the same answer to multiple stack exchange sites @perfectionm1ng. If a question is on the wrong site it will be moved to a more suitable one. $\endgroup$ – Mark Booth Aug 7 '13 at 23:17
  • $\begingroup$ @TimWescott sorry could you please elaborate? $\endgroup$ – Sibbs Gambling Aug 8 '13 at 2:04
  • $\begingroup$ @MarkBooth I am sorry for not knowing this rule. $\endgroup$ – Sibbs Gambling Aug 8 '13 at 2:05
4
$\begingroup$

The complementary filter you mentioned comprises of both a low-pass filter (which filters out, or attenuates, short term accelerometer fluctuations), as well as a high pass filter (which tries to negate the effect of drift on the gyroscope).

Image copied from [http://www.chrismarion.net/index.php?option=com_content&view=article&id=122:the-segway-theory&catid=44:robotics](Chris Marion  - The Segway: Theory (Jan 2011))

A time constant $\tau$ with respect to first order filters describes at what point (the cut-off frequency $f_{c}$) information should start being rejected (LPF) or stop being rejected (HPF). With respect to a complementary filter the time-constant used is the same for both the LPF as well as the HPF. The time constant can be thought of as boundary between trusting the gyroscope, and trusting the accelerometer.

The value of $a$, or the time constant, should be a function of your gyroscope's drift and accelerometer noise. You can optimize to filter out gyroscopic drift (HPF with slow cut-off), but then your accelerometer will allow too much accelerometer noise (LPF with slow cut-off).

As with all filter design, calculate the filter coefficients, test it to confirm it doesn't work, and randomly tweak it till it does.

Refer to the following links for more in depth discussion:

| improve this answer | |
$\endgroup$
  • $\begingroup$ The block diagram, as given, suffers from pole-zero cancellation in the gyro signal path. The consequence of that, as drawn, will be undetected integrator windup and eventual numerical overflow. In practice you'd remember that in mathemagic land an integrator cascaded with a high-pass is just a low-pass, and here in the real world a low-pass filter is way more tractable than the cascade shown. $\endgroup$ – TimWescott Aug 7 '13 at 21:02
  • $\begingroup$ Yeah I realise the graph might not be perfect, I was just trying to illustrate the two different signal paths (I copied the graph from the segway link). $\endgroup$ – EDDY74 Aug 7 '13 at 21:18
  • $\begingroup$ actually mine is to combine gyroscope and the magnetometer. but anw, should share the same rationale. e.g. my sampling frequency for gyroscope and magnetometer is same, 50Hz. Could you please show a sample calculation of a? $\endgroup$ – Sibbs Gambling Aug 8 '13 at 2:09
  • $\begingroup$ Please refer to page 13 of the second link I posted (A simple solution for integrating...), but I think ultimately it would be best to test the filter practically. $\endgroup$ – EDDY74 Aug 8 '13 at 7:51
  • $\begingroup$ Oh and an example: given sampling rate of 50 hz (0.02 period), and a time constant of say 0.5 seconds, a = (0.5)/(0.5 + 0.02) = 0.96 $\endgroup$ – EDDY74 Aug 8 '13 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.