Skip to content

Commit

Permalink
HACK: log the actual frequencies of our notch filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Nov 5, 2023
1 parent c1831ba commit df2abf5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libraries/Filter/HarmonicNotchFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#include "HarmonicNotchFilter.h"
#include <GCS_MAVLink/GCS.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>

#define HNF_MAX_FILTERS HAL_HNF_MAX_FILTERS // must be even for double-notch filters

Expand Down Expand Up @@ -301,6 +305,8 @@ void HarmonicNotchFilter<T>::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
*/
Expand All @@ -311,10 +317,22 @@ T HarmonicNotchFilter<T>::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;
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/Filter/NotchFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
#include <AP_Param/AP_Param.h>


template <class T>
class HarmonicNotchFilter;

template <class T>
class NotchFilter {
public:
friend class HarmonicNotchFilter<T>;
// 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);
Expand Down

0 comments on commit df2abf5

Please sign in to comment.