Filters are a hot topic in the Betaflight community. They can have an astounding effect on the flight performance of your quadcopter at the cost of nothing but a few hours spent tweaking some software. They are also a cause of latency between control inputs and response. For that reason, it is not sufficient to just “turn them all on” and “dial them up to 11”.

For these two reasons, the developer team behind Betaflight has made numerous changes to the filter system built into Betaflight. These changes include tweaking of existing filters that most of us are familiar with like the Low Pass (LPF) and Notch filters as well as adding in new (and presumably improved) filters like the Dynamic Notch, PT2, FIR+Biquad and Kalman filters. The goal of this article is to steer your knowledge of software filters in a direction such that you can be more capable of trying them out for yourself and deciding what you like. At the end of the article, I will also make some personal suggestions for how you should set-up your software filters on Betaflight 3.3 for the best overall flight experience.

Please note that this guide is for advanced pilots looking to pick up that extra edge for competition or smoother acro. You can spend your entire quad career without touching the default filter settings in Betaflight, and your quad will fly fantastic. Most pilots will experience 90% of the advantages of filter tuning by simply turning on the dynamic filter and disabling the notch filters, as we specify in the Betaflight configuration guide. Further tweaks requires you to have some knowledge of your quadcopter’s flight behavior — so get out and fly first, then come back here and do some tweaking.

Understanding Software Filters

To become proficient at tuning the software filters on your quadcopter, you need to first understand what they are doing. This doesn’t mean you need to become proficient in Fourier transforms or any of the details behind how these filters actually work — you just need to understand what will happen when you turn on <x> filter. In the next few sections, we’re going to give a primer course on just that.

A Brief Refresher on Control Logic

Our quadcopters are flying PID controllers. The Proportional-Integral-Derivative controller is an algorithm which takes a reading from a gyroscope and tries to manipulate the motor state to match that reading to a desired state. For example, lets say you are in a perfect hover. Your quadcopter’s gyroscope is reading 0 roll, 0 pitch and 0 yaw. Lets say you push the roll stick full left, commanding a 540 degrees/second roll to the left. The PID controller must now find the optimal configuration of motor commands which will change the gyroscope reading from 0 degrees of roll per second to 540 degrees.

The PID controller does this by breaking up the problem into three components:

The Proportional component of the PID controller works to directly roll the quadcopter left by applying extra throttle to motors 1 and 2 and reducing throttle to motors 3 and 4.

The Integral component of the PID controller works by watching how quickly the quadcopter is rolling over time. If the quadcopter only reaches a roll rate of 400 degrees/second with the given P settings, the Integral component will slowly adjust the throttle values to reach the command 540 degrees/second.

The Derivative component of the PID controller resists rapid changes to the roll rate. It attempts to smooth out the ramp up and ramp down of the roll rate due to the P and I settings. With a well-tuned D component, the roll rate will quickly ramp from 0 degrees/second to 540 degrees/second and center precisely at 540 degrees/second with no overshoot.

pid

You don’t need to be understand this diagram to understand a PID controller, but it may help for folks trained in math. Image courtesy of opticontrols.

The Problem of Noise

The principle problem that quadcopter software developers face is that the data from the gyroscope never just contains the roll, pitch and yaw data from the quadcopter. The gyroscopes we use on these machines are incredibly precise sensors that pick up minute fluctuations in the vehicles and register them as roll/pitch/yaw changes. For the rest of this article, we will refer to the continuous feed of data from the gyroscope as the “signal”. When plotted on a graph, this raw signal will be full of sine waves from the aforementioned interference. Here is a general description of the primary sources of these waves:

  1. High frequency signals is often caused by the vibration of unbalanced motors and propellers on a quadcopter and generally sits between 100Hz-500Hz. Unless the problem is really bad, you generally will not know you have high frequency noise without looking at Blackbox logs.
  2. Mid-frequency signals are generally caused by the PID controller and felt by the pilot as “propwash” or similar in flight vibrations. You will see these vibrations in video feeds and will hear them as audible “stutters” as the quadcopter violently shakes, often after hard maneuvers. These signals often sit between 5-100Hz.
  3. Low frequency signals are generally caused by the flight dynamics of the quadcopter itself. For example, if you are flying a track with a lot of twists and turns, you might be banking the quadcopter back and forth once a second. This would manifest as a signal of frequency of 1Hz.

High- and Mid-frequency signals are bad news for PID controllers. The reason is that these signals are not caused by the flight dynamics of the quadcopter itself, but the PID controller will try to correct for them by changing throttle values and MAKE them part of the flight.

The “D” component of the controller is particularly susceptible to noise. Since it reacts only to the degree of change in the gyro data, the large slopes caused by sine waves moving up and down play havoc with it. In the past, we simply reduced the D gain so low that it hardly played a role in flight at all. The problem is that “D” component’s primary responsibility is to resist propwash oscillations which are caused by the “P” component rapidly “hunting” for a particular rate. So if you reduce your D-gains to the floor, your get a lot of propwash oscillations and a sub-par flight experience. Clearly a better solution is needed..

Software Filters to the Rescue

A software filter is an algorithm which analyzes the gyro feed (signal) over time, finds patterns of noise (sine waves), and attempts to remove them from the feed mathematically.

The only reason we have software filters on our quadcopters is to remove high- and mid- frequency signals from the gyro data before it is sent to the PID controller. In an optimal world, the PID controller would see gyro data which only contains information about the roll/pitch/yaw rate of the quadcopter itself, and nothing else.

Here’s the catch: software filters must analyze some time-span of gyro signal data before they can react to perceived noise. This requirement means that the filters must delay delivery of the gyro data to the PID controller until they can get enough data to do their processing. Delay is latency, and it means that your PID is reacting to something your quadcopter was doing some time ago, not right now. Latency is bad.

The goal, then, is somewhat confusing: quadcopters must have software filters applied to the gyro data to fly correctly, but we want as few and as low-latency filters as we can possibly get.

Reducing Noise with Hardware Mods

Motor soft mounts are a great way to reduce noise without a software filter.

The best way to reduce the number of software filters you need is to build your quadcopter with hardware noise dampers. Simple rubber washers placed around the mounting points of the flight controller and motors can make an amazing difference to the noise environment that the flight controller lives in. These dampeners act like physical low-pass-filters (described below) with no added latency by resisting high-frequency vibrations but letting the big low-frequency stuff through.

Most flight controllers are shipped with soft-mounting washers these days. We recommend you use them.

To learn more about soft mounting your motors, read our guide on soft mounting.

Betaflight Filters Described

Now that you have a general understanding of what filters do, lets take a closer look at the specific filters in Betaflight. There are only really two main types of filters: low pass filters, sometimes called “LPF” and notch filters. Complexity is added because the Betaflight developers have decided to add two layers of LPF and notch filters: one set of “main” filters, and a secondary set which does further filtering for data fed to the “D” component of the PID controller.

The developers have also added considerable configuration options into both of these filter types. This includes the ability to set the software algorithm that drives the LPF filters as well as some neat features like the “dynamic” notch filter. One thing to keep in mind with all of this is the goal: we want to maximize the suppression of motor noise while minimizing the latency introduced by the filters. Let’s jump in.

The Filter Stack

Filter stack.

This is the filtering stack for Betaflight 3.3

In order to minimize noise and support the maximum number of quadcopter builds, Betaflight has a configurable filter stack. This includes up to 6 filters which are applied to the gyro data in sequence before it reaches the PID controller. In order to visualize how the gyro data reaching the PID controller is affected by these filters, we’ve drawn out the a diagram of the filtering stack to the right.

With that stack in mind, let’s dig a little deeper into the individual filters.

Low Pass Filters

The purpose of low pass filters is to reduce (or attenuate) high-frequency signals while leaving low frequency signals alone. When configuring a LPF, you generally set a frequency “gate”. All frequencies lower than this gate are ignored. All frequencies higher than the gate are attenuated, with higher frequencies being attenuated exponentially more. The higher the signal frequency, the more it is attenuated.

Let’s take a look at a few of the different algorithms used to implements LPFs:

Gyro LPF and D-Term LPF

Betaflight uses two LPFs in it’s filtering stack. The first LPF is applied to all gyro data and is referred to as the “Gyro LPF”. As discussed earlier, the “D” component of the PID controller is far more sensitive to noise than the other components, so the Betaflight devs have given us the option of adding an additional LPF on the data that is fed to the D controller. This second filter can be more aggressive but the latency added by this aggression will only be added to the D-component of the PID controller, and is far less noticeable.

Low Pass Filter Gate Frequency

The LPF Gate frequency is the gate variable I described above. Signals below this gate value is ignored by the LPF. Signals above it are attenuated. These gates are configurable in the “Filter Settings” section of the “PID Tuning” tab of Betaflight Configurator:

 Gate frequency for the Gyro LPF
 Gate frequency for the D-Term LPF

We recommend that the average user doesn’t mess with the default gate frequencies. They are well tuned by the Betaflight team and the gains in performance are minimal.

PT1 / BIQUAD / FIR Filters

There are several ways to program a low-pass filter in code. Betaflight currently supports 3 “standard” LPF algorithms: PT1, BIQUAD and FIR. Each algorithm has it’s own unique behavior in terms of noise suppression and the latency it adds. In general, most pilots will either pick the BIQUAD or PT1 filters. PT1 has the lowest latency, so it performs the best, while BIQUAD has better noise suppression and should be used on noisy quadcopters.

Betaflight Configurator does not even have an option for configuring which filtering algorithm is used by the Gyro LPF. This is because it is set to the high-performing PT1 by default and the developers have decided that most pilots probably do not need the additional filtering provided by the other algorithms. The filter algorithm used by the gyro LPF can still be set, however, by configuring the “gyro_lowpass_type” setting in the CLI.

The D-Term LPF is, however, configurable. It is found in the “Filter Settings” section of the “PID Tuning” tab:
Disable filter
By default it is set to the more aggressive BIQUAD LPF algorithm. Many pilots report significant gains in performance by switching this setting to the PT1 algorithm.

Disabling the Low Pass Filter

LPF filters do not have “on/off” switches in Betaflight. Instead, you can disable the filter by setting the gate frequency of the respective LPF filter to 0.

BQRCF2 Low Pass Filter

The Betaflight developers added a “secret” low-pass filter into Betaflight 3.3 called the “BQRCF2” filter. This is similar to PT1 / BIQUAD / FIR in that it is yet another algorithm which can achieve LPF-like results. The primary benefit to it is that it further reduces latency from the PT1 algorithm. You can enable the BQRCF2 filter by setting the “gyro_stage2_lowpass_hz” CLI option. We recommend you set it to 90, the default Gyro LPF gate frequency. If you do this, make sure you turn off the Gyro LPF to realize the performance gains available.

Notch Filters

LPFs are great at reducing a broad swath of noise in the high-frequency band. However, they lack the potency needed to take the bite out of quadcopter motor vibrations. Particularly on quads with hardmounted flight controllers or motors (or both), these vibrations are so intense that they easily make it past most LPFs. That is where notch filters come in.

The purpose of notch filters is to apply a large reduction (attenuation) to a specific band of signal frequencies. The term “notch” describes the shape of the attenuatation curve applied to the signal: a large amount of attenuation at the center frequency with reduced attenuation moving outwards.

Image result for notch filter diagram

Notch filters were added to Betaflight for one reason: to apply a large, targeted reduction to motor noise. Since motor noise generally resides in a limited band of frequencies that has no relevance to the actual (low) frequencies of actual flight, a notch filter is the perfect way to get rid of it.

Betaflight ships with four different notch filters:

  1. There are two gyro notch filters. These allow you to independently reduce noise in two signal frequencies. Many quadcopters only need to enable one of these. The Betaflight defaults come with both notch filters enabled at 200Hz and 400Hz, which allows attenuation to cover almost the entire band where motor noise exists on 99% of quadcopters. This is a pretty inefficient set-up that can be improved by properly tuning one notch filter and disabling the other. Check out the “Dynamic Filter” section below before you go do this, though!
  2. There is one additional notch filter specific to the data provided to the “D” component, much like the D-term LPF.
  3. There is a “dynamic” notch filter, described below.
Dynamic Notch Filter (or DYNAMIC filter)

They dynamic notch filter was a huge improvement to Betaflight that was introduced in version 3.2. The dynamic filter is a software algorithm that continuously analyzes your gyro traces and finds the peak signal noise in the 200-400Hz spectrum. It then centers a normal notch filter at that peak noise. Put simply, it finds out exactly where your motor noise is located at and gets rid of it. While you are flying. No tuning needed.

The dynamic filter completely removes any need for the two gyro notch filters. This is because it does their job — only better. This is why we recommend all pilots enable the dynamic filter and disable the gyro notch filters in our Betaflight configuration guide.

The dynamic filter is found in an odd place in Betaflight Configurator: it is listed as a “feature” in the “Configuration” tab:
Dynamic filter.
Enabling this box turns the feature on.

Tuning the Notch Filters

Honestly — we recommend you avoid tuning the notch filters. Manual tuning will never be as effective as simply enabling the dynamic filter. If your quad is particularly noisy, though, you can use our notch filter guide to learn how to tune these filters.

Kalman Filter

The Kalman filter is an advanced algorithm that use prediction instead of analysis to attenuate noise. For example, a Kalman filter will infer that since your quadcopter has been experiencing motor noise at 123.59Hz for the last couple of seconds, it will continue to do so for the next millisecond. It will not need to analyze the gyro data to perform corrections for that motor noise and therefore will introduce very little latency.

The Kalman filter algorithm is very data hungry and only produces noticeable improvements to flight performance when you have your gyro feeding data to your flight controller at 32kHz. It is also a very complex algorithm which consumes a lot of CPU power, meaning you’ll need to overclock most F4 boards.

A Kalman filter found its way into a pre-release version of Betaflight 3.3 for awhile but was ultimately removed by the development team who decided the BQRCF2 filter was a better idea. The author of that filter forked Betaflight to make the Butterflight flight control software, which still contains the Kalman filter. Setting this up will require you to put Butterflight on your quadcopter. If you’re interested in checking this out, there is a guide here.

Recommendations for Software Filters in Betaflight 3.3

When tuning your quadcopter’s filters, the primary goal is to disable as many as possible without adversely affecting your Blackbox PID traces or overheating your motors. Starting from the Betaflight defaults, there is a recommended order to settings changes that I like to follow. I’ll outline this below as a set of configuration changes.

First, though, you must understand the consequences of under-filtering your quadcopter’s gyro data. Your motors will literally melt if you take things too far. The high frequency loads imposed by unfiltered gyro data being fed to the PID controller will cause all of the motors to run at very high power, even in a hover. This will cause the motors to heat up and eventually fail. The most important thing to do when disabling filters is to do it one at a time, only flying a hover for 5-10 seconds after a filter is disabled or reduced, and then checking your motor temperatures afterwards. If your motors are too hot to comfortably touch, you need to stop removing filters and should probably back up one step. OK, let’s go.

Starting from the Betaflight defaults, we recommend you:

  1. Enable the dynamic notch filter.
    Disable filter
  2. Disable both gyro notch filters:

    Disable filter

  3. Disable the D-term notch filter:

    Disable filter

  4. Set the D-Term LPF to “PT1”:

    Disable filter

  5. Enable the BQRCF2 Gyro LPF:

    Disable filter

  6. Disable the Gyro LPF:

    Disable filter

If you can do all of these steps and your quadcopter still flies without hot motors or a borked Blackbox feed, you are golden. As of Betaflight 3.3 this is about the best you can do.

That being said – even if you just enable the dynamic filter and disable the notch filters, you will still be enjoying some pretty amazing performance.

References

If you are more interested in the technical details behind software filters, I highly recommend you check out the videos that UAV Tech has done. Here is one that I particularly liked for Betaflight 3.3:

The Betaflight wiki is also a great, if outdated, resource:

https://github.com/betaflight/betaflight/wiki/Gyro-&-Dterm-filtering-recommendations

Show Buttons
Hide Buttons