Module 4/5 · Weeks 10–12 · 27 h

Log-based tuning

UAT 305 Autopilot and Control Technology

About 90 minDraft, awaiting reviewLast updated 28 September 2026

Lesson

By the end of this module you will be able to

  1. Compute a notch filter's attenuation and phase at different frequencies
  2. Set ArduPilot's harmonic notch to track motor frequency
  3. Compute the phase that a low-pass filter adds to the control loop
  4. Use log analysis tools to check results before and after changes

Prerequisites: UAT 305 Modules 1–3 · UAT 303 Module 3 (FFT of vibration)

Why this matters

UAT 303 used an FFT to find where vibration sits in frequency. This module uses the same data to set filters so that the control loop does not respond to motor vibration. Without filtering, the rate loop’s D term amplifies noise until the motors run hot; with too much filtering, the loop gains delay and oscillates (Module 1). The drone knowledge base’s unit on analysing filters from flight logs teaches reading spectra and filter effects offline, and its PX4 Flight Review and PlotJuggler units show log tools.

Notch and harmonic notch

A notch filter reduces a narrow band around frequency and passes the rest. The prototype from the W3C Audio EQ Cookbook is with bandwidth . ArduPilot uses a harmonic notch, placing filters at the fundamental and its harmonics, set with INS_HNTCH_ENABLE, INS_HNTCH_FREQ (default 80 Hz), INS_HNTCH_BW (40 Hz, typically half the base frequency), INS_HNTCH_ATT (40 dB depth) and INS_HNTCH_MODE, which selects the frequency source, for example 1 = throttle, 3 = ESC telemetry (which the documentation calls generally the best) and 4 = in-flight FFT. Motor frequency changes with throttle, so a fixed notch can miss when flying differently from when it was set.

Example 1 How much does an 80 Hz notch remove?

A prototype notch with = 80 Hz and = 40 Hz (unlimited depth; the real one is limited by INS_HNTCH_ATT).

import cmath
import math

F0, BW = 80.0, 40.0
Q = F0 / BW

def notch(f):
    s = 1j * f / F0
    return (s * s + 1) / (s * s + s / Q + 1)

for f in (8, 60, 80, 83, 100, 160):
    h = notch(f)
    db = 20 * math.log10(max(abs(h), 1e-5))
    print(f"{f:>3} Hz: {db:7.1f} dB, phase {math.degrees(cmath.phase(h)):6.1f} deg")
  8 Hz:    -0.0 dB, phase   -2.9 deg
 60 Hz:    -2.4 dB, phase  -40.6 deg
 80 Hz:  -100.0 dB, phase    0.0 deg
 83 Hz:   -16.7 dB, phase   81.6 deg
100 Hz:    -3.5 dB, phase   48.0 deg
160 Hz:    -0.5 dB, phase   18.4 deg

At exactly 80 Hz the filter cuts deeply, but if the motors turn at 83 Hz the depth falls below 20 dB, which is why the notch should track real motor frequency. At 8 Hz, near the loop’s crossover, the notch adds only a few degrees of phase lag, so it barely affects stability, unlike lowering a low-pass cutoff.

Notch magnitude in decibels against frequency from 0 to 200 hertz: a blue line near zero except for a deep dip at 80 hertz, with a pink point at 83 hertz at about minus 17 decibels
Figure 1 Notch attenuation around 80 Hz

Low-pass filters and phase

Copter’s INS_GYRO_FILTER defaults to 20 Hz and is a second-order low-pass filter in the source code. Texas Instruments’ note states that a second-order low-pass has 90° of phase lag at the cutoff and approaches 180° well above it. Even below the cutoff, the filter adds phase lag to the loop.

Example 2 Cutoff frequency and phase at an 8 Hz crossover

Computed with a second-order Butterworth low-pass ( = 0.707) for comparison.

import math

F_CROSS = 8.0
for fc in (40, 20, 10):
    r = F_CROSS / fc
    phase = -math.degrees(math.atan2(math.sqrt(2) * r, 1 - r * r))
    print(f"gyro filter {fc:>2} Hz: phase at {F_CROSS:.0f} Hz = {phase:6.1f} deg")
gyro filter 40 Hz: phase at 8 Hz =  -16.4 deg
gyro filter 20 Hz: phase at 8 Hz =  -34.0 deg
gyro filter 10 Hz: phase at 8 Hz =  -72.3 deg

Lowering the cutoff from 20 Hz to 10 Hz to reduce noise raises the phase lag at crossover from about 34° to 72°, more than the 60° phase margin of the example loop in Module 1, so the loop becomes unstable. A better approach is to use a notch to remove only the motor frequency and keep the low-pass cutoff high enough.

Bars of phase lag at 8 hertz for low-pass cutoffs of 40, 20 and 10 hertz, about 16, 34 and 72 degrees; the 10 hertz bar is pink
Figure 2 Phase lag at crossover by filter cutoff

The log-based tuning process

ArduPilot’s tuning instructions follow an order: fix mechanical vibration first, set filters from the spectrum, then tune the rate and angle loops. After every change, fly a new log and compare with the previous one. Tools such as ArduPilot WebTools (FilterReview), PX4 Flight Review and PlotJuggler show spectra before and after filtering and compare desired with actual values.

Module lab

Lab: setting the harmonic notch from a log

  1. Hover with detailed IMU logging enabled and view the spectrum in FilterReview
  2. Find the motors’ fundamental frequency in hover and compute the attenuation with Example 1
  3. Set INS_HNTCH_* for the mode the hardware supports, fly again and compare the filtered spectrum
  4. Try low-pass cutoffs in SITL, compute the phase with Example 2 and observe the loop
  5. Record every change in the configuration register

Common mistakes

Watch out

  • Lowering the low-pass cutoff instead of using a notch
  • Setting a fixed notch when motor frequency changes with throttle
  • Tuning PID before fixing vibration
  • Changing several values at once so nobody knows which one worked
  • Not keeping before-and-after logs, so results cannot be compared

Summary

  • A notch cuts a narrow band; if the motor frequency drifts from the centre, the depth falls quickly
  • ArduPilot’s harmonic notch can track motor frequency from throttle, ESC telemetry or FFT
  • Low-pass filters add phase lag even below their cutoff, so lowering the cutoff risks stability
  • Tune in order: fix vibration, set filters, then tune the loops, comparing logs each time

Check your understanding

  1. A notch with 100 Hz and 50 Hz bandwidth has what ?
  2. A motor at 5,400 rpm has what fundamental frequency?
  3. What is the phase lag of a second-order low-pass at its cutoff?
  4. Why does a notch affect stability less than lowering a low-pass cutoff?
  5. Which INS_HNTCH_MODE does the documentation call generally the best?
Answers
  1. Hz
  2. 90°
  3. The notch acts only on a narrow band around the motor frequency, far from crossover, so it adds little phase lag at crossover
  4. ESC telemetry (value 3)

Key formulas

Notch filter
Phase of a second-order low-pass (Butterworth)

Key references

  1. ArduPilot Dev Team. Managing gyro noise with the dynamic harmonic notch filters. ArduPilot Copter documentation. link
  2. Toy, R. (Ed.). (2021). Audio EQ cookbook (W3C Working Group Note). link
  3. Karki, J. (2023). Active low-pass filter design (SLOA049D). Texas Instruments. link
  4. ArduPilot Dev Team. ArduPilot source code, tag Copter-4.6.3 [Computer software]. GitHub. link
  5. PX4 Autopilot. Log analysis using Flight Review. PX4 guide (main). link
  6. ArduPilot Dev Team. Tuning process instructions. ArduPilot Copter documentation. link

Further reading

Study the assigned knowledge units in advance, review media and take the module quiz

In class / field

Lab or field practice from worksheets with a safety checklist

Learning evidence: Checked worksheets and quiz results

Module quiz

This is a formative self-check, not a graded exam

Knowledge domain: Control, autopilot and navigation · Installation, maintenance and testing