ardupilot/libraries/AP_GyroFFT/tests/test_harmonic_fit.cpp
Andy Piper 4199ccc292 AP_GyroFFT: correct notch calculation for FFT tune.
use freq_min_ratio for scaling
add harmonic calculation test
set harmonics in notch setup
2023-01-24 10:56:33 +11:00

24 lines
596 B
C++

#include <AP_gtest.h>
#include <AP_HAL/HAL.h>
#include <AP_HAL/Util.h>
#include <AP_GyroFFT/AP_GyroFFT.h>
#include <stdio.h>
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
TEST(harmonic_fit_Test, Basic)
{
#if HAL_GYROFFT_ENABLED
float freqs[] { 176.9, 57.2, 228.7 };
uint8_t harmonics;
float harmonic = AP_GyroFFT::calculate_notch_frequency(freqs, 3, 10, harmonics);
printf("FFT: Found peaks at %.1f/%.1f/%.1fHz\n", freqs[0], freqs[1], freqs[2]);
printf("FFT: Selected %.1fHz %d\n", harmonic, harmonics);
EXPECT_TRUE(is_equal(harmonic, 57.2f));
#endif
}
AP_GTEST_MAIN()