Unsure how to tune notch filter

Hello, I am currently tuning a moderately large 1300mm motor to motor hexa equipped with T-Motor 6007-X 320KV and 22x11 props. I do not have RPM feedback.

The flight controller is a Pixhawk Cube Orange, mounted a bit forward of centre on the double sided foam that comes with it.

I am following the instructions for In-Flight FFT Based Harmonic Notch Setup and have performed an initial flight as mentioned here.

The dataflash log for this flight is here.

My problem is that plotting FTN1.PkAvg in MP shows no clear dominant frequency:

Also, getting Mission Planner to perform an FFT according to the batch sampler documentation gives a fairly spread out picture:

The peaks in the accels and gyros are 37, 74, 111, 150 Hz.

However, except for the fairly obvious 111Hz peak, the second biggest is debatable, accels say it’s 37 Hz, gyros say it’s 76 Hz.

Having said all that, the vehicle flies like a dream with default params, to the point where I wonder if I should bother with vibration filtering (or even tuning) at all. I wonder if the reason I am not getting very strong results is that vibrations are too low anyway.

So, does anyone have any tips? Should I bother with vibration filtering at all? If I do, should I go for throttle based or In-Flight FFT?


Yes, set your filtering. When setting the filter only look to the gyro FFT graph, not the accel. Normally you take the lowest peak, but 37 sounds low to me. There are some experts here with more practice tuning larger machines that may be able to clarify.

Yes, you should do the tuning. It’s flying well enough, but there’s lots of room for improvement. Once you have the filtering set it would be worth it to run autotune. Vibrations look low so you’re off to a good start.

Looks like you don’t have FFT_MINHZ and FFT_MAXHZ set up to cover all the frequencies. Also for these larger aircraft you generally want a large window size - on a cube orange you could try 256

I have not touched the FFT_MINHZ (80) and FFT_MAXHZ (200). What values should I put there? @andyp1per , do you mean that FFT_MAXHZ - FFT_MINHZ should be 256 (or greater)?

Also, since my FFT_MINHZ is 80, the 37Hz peak looks suspicious.

You should try FFT_MINHZ=25, FFT_MAXHZ=300, but do not enable the notch - get the FFT working well before enabling the notch

There’s an important step missing!
Connect to MissionPlanner, Mandatory…, Initial Parameters !
Put in you prop size and battery cell details.
Accept all that it offers, including the recommended battery failsafe actions.

Visually flying like a dream and actual results in logs can be two different things. The attitude control can be improved somewhat. All improvements you can make will be better for battery life and also gives a good baseline so you can more easily notice issues.

Let us know if you need more help with the FFT and HNOTCH settings. It will be quite easy to set this up.

I was trying to investigate why sometimes plotting an FFT from a log is unable to see data, it seems to be for the following reasons.

or if ESC telemetry is not supported.
or LOG_BITMASK’s IMU_RAW bit has been checked

If INS_BAT_MASK is set to anything but 0 batch data for FFT analysis will be logged. It doesn’t matter whether the notch filter is enabled or not nor does it matter if you have ESC telemetry.
If INS_LOG_BAT_OPT is set to 0 it’s pre-filter, 2 is post filter.

That’s about it.

Thank you all for your replies. Today I managed to do another couple of test flights with FFT_MINHZ=25, FFT_MAXHZ=300 as suggested by @andyp1per .

Also, @xfacta, I have followed the instructions on setting up for tuning, including using Mission Planner Helper to get the correct prams for my setup.

Now, I did two test flights, the second one longer than the first. FFT graphs are here for accels:


and here for gyros:


The first four peaks are pretty much the same for all (only relative magnitudes change): 37 Hz, 74 Hz, 109 Hz, 148 Hz.

I might also have a candidate for the lowest peak, when the motors spin up, the arms vibrate quite a bit, but then stop at rpm close to liftoff. It’s possible this the 37 Hz peak.

So, the question now is, what notch? Throttle based or In-Flight FFT or something else?

The notch filter is not active on the accelerometers so don’t bother looking at those graphs. If you have already set the FFT parameters then the next step is to set INS_LOG_BAT_OPT to 2 and make another Hover flight to see the effectiveness of the filter.

It depends if you are OK with the CPU overhead of running the live FFT all the time. If you plan on using scripting or some other advanced features it might be better to do throttle based HNOTCH.
We could tell more by seeing your .bin log.

INS_HNTCH_ENABLE,1 ← set this then refresh params to see the rest

INS_HNTCH_ENABLE,1 ← set this then refresh params to see the rest
INS_HNTCH_REF, hover_thrust ← use MOT_THST_HOVER x 0.6

I am still learning, I just want to ensure my understanding. Is it that INS_HNTCH_FREQ should be set to 109?

Use the first peak (37), not the highest peak (109).

OK, so I went out and tested everything as follows based on the instructions of @xfacta. Specifically, I tried out three throttle based filters and one FFT one.

First of all, I set:

Then, for the throttle based filters I set:

Questions (mainly for @xfacta) the documentation does not mention a factor of 0.6 for INS_HNTCH_REF but says to set it to hover_thrust. My MOT_THST_HOVER is 0.125 so I set INS_HNTCH_REF to 0.075 as you suggested but where does the 0.6 come from?

You mentioned setting INS_HNTCH_ATT to 40. It was already there so no change needed but this is not mentioned in the documentation.

Finally, the documentation mentions setting INS_HNTCH_FM_RAT but you did not. I did not touch it but should I have?

Now, with these settings, I did three flights, varying INS_HNTCH_FREQ and INS_HNTCH_BW. Each flight was more or less the same, take off in Alt Hold, hard up, moderate down, hard up, moderate down, land. The idea was to stress the throttle somewhat.

Logs as follows:

Flight 1, INS_HNTCH_FREQ 37, INS_HNTCH_BW 37, log here.

Flight 2, INS_HNTCH_FREQ 74, INS_HNTCH_BW 37, log here.

Flight 3, INS_HNTCH_FREQ 108, INS_HNTCH_BW 54, log here.

Flight , INS_HNTCH_FREQ , INS_HNTCH_BW , log here.

Finally, I did a flight with FFT filtering. For that, I set:


Same flight pattern but I also did a bit of throwing it around in roll and pitch to record some responses, log here.

In terms of performance, there was not much I could tell by flying, all flights felt more or less the same (great really). What should I be looking at in the logs to make up my mind about which filter to select? Regarding throttle vs FFT, I am not planning on doing anything on the autopilot (Lua scripts or whatever) other than using it for flying. How can I compare the difference in CPU load across the logs?

Without setting INS_LOG_BAT_OPT to 2 you can’t determine the effectiveness of the filter. I opened 2 logs and they are set to 0.

The correct formula for setting INS_HNTCH_REF for throttle based use is:
INS_HNTCH_REF = hover_thrust * (min_freq / hover_freq)^2
which in rough terms works out to be about
INS_HNTCH_REF = hover_thrust * 0.6

INS_HNTCH_FM_RAT is a new parameter, I think it could be about 0.7, I havent tested it for myself.

INS_LOG_BAT_OPT,2 will tell us more

I am terribly sorry, I totally forgot to set the INS_LOG_BAT_OPT. I have now carried out new tests. However, new stuff has happened (don’t you just love it :slightly_smiling_face:).

I started off with a flight exactly as I left it in my previous post. FFT filtering and no INS_LOG_BAT_OPT. Just a completely identical setup. The vehicle immediately started very violent oscillations, I tried two take offs with this behaviour, the log is here.

The strange thing is that the params were identical to the last flight of my previous attempt, here. That flight was a delight. This one was insane, I was super glad I had taken the precaution of binding motor emergency stop to a button on the Tx.

After that, I set INS_LOG_BAT_OPT to 4 (it’s a bitmask so sets bit 2) for pre and post filter and tried again with the same settings. I tried one take off in STAB and one in ALT HOLD. In both cases I got the violent oscillations, log here.

To test if the problem was FFT related, I switched to throttle based filtering by setting the following:

INS_HNTCH_REF 0.075 (0.6 of hover thrust, which is 0.125)

and then tried one flight with:


First I did a take off in STAB. I noticed a very obvious tendency for yaw right, has to be controlled by stick. I got no oscillations at very low alt (<1m), which is as high as I dared go. After that, I switched to Alt Hold and tried another take off. That one went OK too. Log is here.

I then tried:


OK flight. A bit of yaw at take off but not sure it wasn’t accidental user input. Threw it around at low alt a bit to see responses, which we OK. Log is here.

For the last flight, I set:


Same as the others, no oscillations, low altitude, threw it around a bit to see responses, all OK. Log is here.

So, the most obvious question is what happened in the first flights? Why did it stop when I switched from FFT to throttle based filtering? Why was the exact same setup flying perfectly one day and violently uncontrollable the next day?

The less dramatic question is, how should I evaluate the performance of the different filters?

You are 0 for 2 with this parameter. Set it to 2 (sample post filtering only)

Just noticed these:

I should be 2X P and P=MOT_THST_HOVER. But I don’t know the history of how you arrived at these values and I realize you didn’t change them from yesterday to today.

I have now set INS_LOG_BAT_OPT to 2 (post-filtering). Weather is terrible, will get fresh logs as soon as possible.

Meanwhile, please help me understand, why is the problem with setting INS_LOG_BAT_OPT to 4? Surely, if we are sampling both pre and post, we have the info we need (and more), no?

Regarding PSC_ACCZ_P and PSC_ACCZ_I. Pop up window in MP Helper says to set:

My MOT_THST_HOVER is 0.125 but min value for PSC_ACCZ_P is 0.2 so this is what I set for P.
My PSC_ACCZ_I is set to 2 x MOT_THST_HOVER (2 x 0.125)

Finally, given the logs in my last post, does anyone have any idea about why I got the violent oscillations? They were not in Z but in pitch and roll and went away when I disabled the in-flight FFT filtering. If it is problem with the in-flight FFT, perhaps we should raise this somewhere other than this thread before someone breaks something.

PSC_ACCZ_I should definitely be 2 x PSC_ACCZ_P. The range listed in MissionPlanner is not a definite.
Set yours to
and that will be close enough for now. It can be re-evaluated when MOT_THST_HOVER changes after more tuning.

You should add some dummy payload so MOT_THST_HOVER,0.125 is greater than MOT_SPIN_MIN,0.15. Try to get the average hover PWM up around 1500 instead of 1340.
Ensure the pauload is very secure and will not contribute to vibrations.

Definitely also set INS_ACCEL_FILTER,10

Based on those logs I would set 2 notch filters
A throttle based dynamic notch
INS_HNTCH_REF,0.08 ← this is unrealistic, add dummy payload and get a new hover thrust

A static notch

and keep logging the pre-filter data so we can see how it changes with the dummy payload.

By the way, my rough calculations based on prop size and what we know about motor RPM and frequency gives a hover frequency of 30HZ for your props - so that backs up what we see in the FFT graphs showing 37Hz.

I do not think the FFT or HNOTCH settings were causing the instability you saw. In all these logs you are on the verge of instability and there are “weak” PIDs which are probably the cause. Any disturbances would have been an issue.

Carry out the recommended changes and do a new test flight just with AltHold, hovering for a while to get a new learned MOT_THST_HOVER value and make INS_HNTCH_REF = 0.6 x MOT_THST_HOVER
and repeat the test flight. No need to try to stress anything or perform aerobatics.
Let’s see that log file.

After that if you want to try new PIDs to possibly help with the stability, cautiously try these:
If there’s obvious oscillations lower the ATC_ANG ones by 10%