This guide explains the different software filters in Betaflight, which are used to attenuate noise in the system. I will also show you a simple way to configure the filters for better performance.
Why Do You Need Software Filters?
Gyro sensor data can be noisy and might require software filters to clean up for better performance. Because noise can exist at any frequency, you need to enable the right filters, and tweak them in order to reduce noise more effectively.
You quad might fly just fine without filters, so you might not need to worry about it. Filters are useful for those really noisy builds, as well as for perfectionist pilots to squeeze every bit of performance in their quads.
Before playing with filters, make sure you are already soft mounting FC or even motors to minimize the amount of physical noise reaching the Gyro sensor. Adding capacitors can also help reduce the amount of electrical noise reaching the gyro.
A Simple Introduction to the Filters in Betaflight
The two main types of filters used in Betaflight are “Lowpass filter” (LPF) and “Notch filter”. There are also other terminology I want to cover related to Betaflight filters.
Lowpass filters allow low frequency signal to pass through, and attenuate high frequency which is mostly just noise and not needed for our flight controllers.
You set a cut-off frequency, and the flight controller will simply reduce signals higher than this frequency. The attenuation curve is a slope, meaning the higher the signal frequency, the more it is attenuated.
Notch filters are great for rejecting noise at a very specific frequency band. Notch filters are usually more effective for reducing motor noise than LPF, but more manual tuning might be required to determine the bandwidth and center frequency.
Dynamic Filter is a feature you can enable in Betaflight.
These filters usually do a good job keep noise out if you tune and set the filter parameters properly. But there are times when oscillations and noise occur at an unexpected frequency, for example, bent props, or deteriorating motors. This is where Dynamic Filter comes in.
In a nutshell, the dynamic filter is an algorithm that can detect the frequency of the noise, and it can use notch filter to reduce it automatically.
The main downside of Dynamic filter is the increase of CPU load. On F3 flight controllers, you would have to lower your looptime from 8KHz to 4KHz or lower in order to run Dynamic Filter.
Filter Stages in Betaflight
In Betaflight, Gyro data has to go through a series (or stages) of filters before they reach the PID controller. You can choose to turn on or off any particular filter, and to tweak them individually to your requirement.
|Raw Gyro Data|
|Gyro LPF 2 (Stage 2)|
|Dynamic Notch Filter|
|Gyro Notch 1|
|Gyro Notch 2|
|D Term LPF|
|D Term Notch|
I will go into a bit more detail how you should set each of them.
You are given the option of PT1, BIQUAD and FIR.
These are the different low pass filter algorithms. In a nutshell, , BIQUAD is better at noise suppression than PT1, but PT1 has less latency than BIQUAD. Don’t worry about FIR because PT1 and BIQUAD are more popular.
You probably want to run PT1 whenever possible, but if you have hot motors, switch back to BIQUAD. Less latency can translate to more responsive quad, and less prop wash oscillations.
The Biquad filter uses two-sample averaging. It takes the PT1 lowpass filter we already have, and cascade with another filter on top of it. Having two filters you get more filtering, and you get a much sharper cutoff curve, but takes longer to complete.
The same applies to both Gyro and D Term LPF.
You can turn the LPF off by setting the frequency to 0, but it’s not recommended unless you know what you are doing.
Stage 2 LPF
The Stage 2 Lowpass filter is called BIQUAD RC + FIR2, which replaced Kalman filter in recent BF version. It’s known to have even lower latency than PT1. If you turn this on you can try turning off Gyro LPF (Stage 1) for maximum performance gain.
There are two notch filters for the Gyro to target two separate frequencies, you can turn one off, or both off if you want.
Default values are set at 200Hz and 400Hz, these work pretty well on most builds where the motor noises are. But ideally you should really play with blackbox and find out the exact motor noise frequency in your quad.
There is also the Dynamic Filter feature in Betaflight, which can continuously analyze your gyro data to locate signal noise frequency in the 200-400Hz spectrum and get rid of it. The best part is there is no tuning needed.
If you use Dynamic filter, you can turn the other two gyro notch filters off, which we strongly recommend as it’s effective and easy to do.
Before messing with filters…
By setting filters incorrectly can cause your quad to oscillate and your motors to overheat, so leave them at default if you don’t feel like you are ready.
If you do want to continue, make sure you only change one filter setting at a time. Test it by flying it for at least 20-30 seconds after every change, pay attention to noise and oscillations and check motor temperatures right after landing. If your motors are getting noticeably hotter, you need to stop and back up.
You can burn your motors or ESC if not careful.
Simple but Effective Filter Settings
This is a simple filter setup that can get you started playing with them. You might want to tweak them to work better for your particular build.
- Enable “Dyanmic Filter” feature, and disable Gyro Notch filter 1 by setting frequency to 0
- Disable Gyro Notch filter 2 (by setting frequency to 0)
- Change D term lowpass filter (d_lowpass_type) to PT1, I think this should be fine on most of the quads out there. Anyway, to make sure, fly your quad around for 30 seconds, see if motors are hot
- Set Stage 2 LPF to 90 and disable Gyro LPF
- If your quad is super clean and well tuned, you might even be able to disable “D term notch filter” too, but it’s very risky so I don’t personally recommend it
I can’t stress it enough, make sure to fly around and check motor temperature after each change. Stop and go back one step if motors are too hot :)