        ## 《The Balance Filter》互补滤波器

2020-05-28

Pros:

· Can help fix noise, drift, and horizontal acceleration dependency.
· Fast estimates of angle, much less lag than low-pass filter alone.
· Not very processor-intensive.

· 可以解决噪声、漂移和水平加速度问题。
· 快速估算角度，滞后比单低通滤波器少很多。
· 不太占用线程时间。

Cons:

· A bit more theory to understand than the simple filters, but nothing like the Kalman filter.

· 需要比简单滤波器懂多点理论，但不像卡尔曼滤波那种骚东西。

More on Digital Filters

There is a lot of theory behind digital filters, most of which I don’t understand,but the basic concepts are fairly easy to grasp without the theoretical notation (z-domain transfer functions,if you care to go into it). Here are some definitions:

Integration: This is easy. Think of a car traveling with a known speed and your program is a clock that ticks once every few milliseconds. To get the new position at each tick, you take the old position and add the change in position. The change in position is just the speed of the car multiplied by the time since the last tick, which you can get from the timers on the microcontroller or some other known timer. In code:

position+= speed*dt;, or for a balancing platform, angle += gyro*dt;.

Low-Pass Filter: The goal of the low-pass filter is to only let through long-term changes, filtering out short-term fluctuations. One way to do this is to force the changes to build up little by little in subsequent times through the program loop. In code:

angle= (0.98)*angle + (0.02)*x_acc;

If,for example, the angle starts at zero and the accelerometer reading suddenly jumps to 10º, the angle estimate changes like this in subsequent iterations:

 Iter. 1 2 3 4 5 6 7 8 9 10 θ 0.20º 0.40º 0.59º 0.78º 0.96º 1.14º 1.32º 1.49º 1.66º 1.83º

If the sensor stays at 10º, the angle estimate will rise until it levels out at that value. The time it takes to reach the full value depends on both the filter constants (0.98 and 0.02 in the example) and the sample rate of the loop(dt).

position+= speed*dt;, 若是一个平衡平台 angle += gyro*dt;.

angle= (0.98)*angle + (0.02)*x_acc;

 迭代 1 2 3 4 5 6 7 8 9 10 角度 0.20º 0.40º 0.59º 0.78º 0.96º 1.14º 1.32º 1.49º 1.66º 1.83º

High-Pass Filter: The theory on this is a bit harder to explain than the low-pass filter, but conceptually it does the exact opposite: It allows short-duration signals topass through while filtering out signals that are steady over time. This can beused to cancel out drift.

Sample Period: The amount of time that passes between each program loop. If  the sample rate is 100Hz, the sample period is 0.01 sec.

Time Constant: The time constant of a filter is the relative duration of signal it will act on.For a low-pass filter, signals much longer than the time constant pass through unaltered while signals shorter than the time constant are filtered out. The opposite is true for a high-pass filter. The time constant, τ, of a digital low-pass filter,

y= (a)*(y) + (1-a)*(x);,

running in a loop with sample period, dt, can be found like this*: So if you know the desired time constant and the sample rate, you can pick the filter coefficient a.

Complementary: This just means the two parts of the filter always add to one, so that the output is an accurate, linear estimate in units that make sense. After reading a bit more, I think the filter presented here is not exactly complementary, but is a very good approximation when the time constant is much longer than the sample rate (a necessary condition of digital control anyway)

.高通滤波器：此者理论比低通滤波器要难解释一些，但是概念上它俩是完全相反的：它允许高频信号通过，滤去一直保持不变的信号，这能用于消除漂移。

y= (a)*(y) + (1-a)*(x);, A Closer Look at the Angle Complementary Filter If this filter were running in a loop that executes 100 times per second, the time constant for both the low-pass and the high-pass filter would be: This defines where the boundary between trusting the gyroscope and trusting the accelerometer is. For time periods shorter than half a second, the gyroscope integration takes precedence and the noisy horizontal accelerations are filtered out. For time periods longer than half a second, the accelerometer average is given more weighting than the gyroscope, which may have drifted by this point.

For the most part, designing the filter usually goes the other way. First, you picka time constant and then use that to calculate filter coefficients. Picking the time constant is the place where you can tweak the response. If your gyroscope drifts on average 2º per second (probably a worst-case estimate), you probably want a time constant less than one second so that you can be guaranteed never to have drifted more than a couple degrees in either direction. But the lower the time constant, the more horizontal acceleration noise will be allowed to pass through. Like many other control situations, there is a trade off and the only way to really tweak it is to experiment.

Remember that the sample rate is very important to choosing the right coefficients. If you change your program, adding a lot more floating point calculations, and your sample rate goes down by a factor of two, your time constant will go up by a factor of two unless you recalculate your filterterms.

As an example, consider using the 26.2 msec radio update as your control loop(generally a slow idea, but it does work). If you want a time constant of 0.75sec, the filter term would be: So,angle= (0.966)*(angle + gyro*0.0262) + (0.034)*(x_acc);.

The second filter coefficient, 0.034, is just (1 - 0.966).

It’s also worthwhile to think about what happens to the gyroscope bias in this filter. It definitely doesn’t cause the drifting problem, but it can still effect the angle calculation. Say, for example, we mistakenly chose the wrong offset and our gyroscope reports a rate of 5 º/sec rotation when it is stationary. It can be proven mathematically (I won’t here) that the effect of this on the angle estimate is just the offset rate multiplied by the time constant. So if we have a 0.75 sec time constant, this will give a constant angle offset of 3.75º.

Besides the fact that this is probably a worst-case scenario (the gyro should never be that far offset), a constant angle offset is much easier to deal with than a drifting angle offset. You could, for example, just rotate the accelerometer 3.75º in the opposite direction to accommodate for it.

《The Balance Filter》互补滤波器--MIT著名牛文翻译（上）http://blog.csdn.net/qq_32666555/article/details/54692956

0条评论

×

¥.00

• 电子书免费读
• 全站无广告
• 全屏阅读
• 高品质朗读
• 批量上传文档
• 购书5折
• 5千个文件夹
• 专属客服