diff --git a/libraries/Filter/HarmonicNotchFilter.cpp b/libraries/Filter/HarmonicNotchFilter.cpp index 82ae789ba5d97..3bcbb1c0688b3 100644 --- a/libraries/Filter/HarmonicNotchFilter.cpp +++ b/libraries/Filter/HarmonicNotchFilter.cpp @@ -20,6 +20,10 @@ #include "HarmonicNotchFilter.h" #include +#include +#include +#include +#include #define HNF_MAX_FILTERS HAL_HNF_MAX_FILTERS // must be even for double-notch filters @@ -301,6 +305,8 @@ void HarmonicNotchFilter::update(uint8_t num_centers, const float center_freq } } +static int dfd = -1; + /* apply a sample to each of the underlying filters in turn and return the output */ @@ -311,10 +317,22 @@ T HarmonicNotchFilter::apply(const T &sample) return sample; } + if (dfd == -1) { + dfd = ::open("notch.txt", O_WRONLY|O_CREAT|O_TRUNC, 0644); + } + T output = sample; for (uint8_t i = 0; i < _num_enabled_filters; i++) { + if (!_filters[i].initialised) { + ::dprintf(dfd, "------- "); + } else { + ::dprintf(dfd, "%.4f ", _filters[i]._center_freq_hz); + } output = _filters[i].apply(output); } + if (_num_enabled_filters > 0) { + ::dprintf(dfd, "\n"); + } return output; } diff --git a/libraries/Filter/NotchFilter.h b/libraries/Filter/NotchFilter.h index dd6f319f784ff..3011f09867c7a 100644 --- a/libraries/Filter/NotchFilter.h +++ b/libraries/Filter/NotchFilter.h @@ -26,9 +26,13 @@ #include +template +class HarmonicNotchFilter; + template class NotchFilter { public: + friend class HarmonicNotchFilter; // set parameters void init(float sample_freq_hz, float center_freq_hz, float bandwidth_hz, float attenuation_dB); void init_with_A_and_Q(float sample_freq_hz, float center_freq_hz, float A, float Q);