Skip to content

Commit

Permalink
Filter: use a define for nyquist cutoff
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Mar 15, 2024
1 parent 90c8359 commit 148c176
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libraries/Filter/HarmonicNotchFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#include <stdio.h>
#endif

/*
cutoff proportion of sample rate above which we do not use the notch
*/
#define HARMONIC_NYQUIST_CUTOFF 0.48f

/*
point at which the harmonic notch goes to zero attenuation
*/
Expand Down Expand Up @@ -166,7 +171,7 @@ void HarmonicNotchFilter<T>::init(float sample_freq_hz, HarmonicNotchFilterParam
const float attenuation_dB = params->attenuation_dB();
float center_freq_hz = params->center_freq_hz();

const float nyquist_limit = sample_freq_hz * 0.48f;
const float nyquist_limit = sample_freq_hz * HARMONIC_NYQUIST_CUTOFF;
const float bandwidth_limit = bandwidth_hz * 0.52f;

// remember the lowest frequency we will have a notch enabled at
Expand Down Expand Up @@ -248,7 +253,7 @@ void HarmonicNotchFilter<T>::expand_filter_count(uint16_t total_notches)
template <class T>
void HarmonicNotchFilter<T>::set_center_frequency(uint16_t idx, float notch_center, float spread_mul, uint8_t harmonic_mul)
{
const float nyquist_limit = _sample_freq_hz * 0.48f;
const float nyquist_limit = _sample_freq_hz * HARMONIC_NYQUIST_CUTOFF;
auto &notch = _filters[idx];

// scale the notch with the harmonic multiplier
Expand Down Expand Up @@ -339,7 +344,7 @@ void HarmonicNotchFilter<T>::update(uint8_t num_centers, const float center_freq
}

// adjust the frequencies to be in the allowable range
const float nyquist_limit = _sample_freq_hz * 0.48f;
const float nyquist_limit = _sample_freq_hz * HARMONIC_NYQUIST_CUTOFF;

const uint16_t total_notches = num_centers * _num_harmonics * _composite_notches;
if (total_notches > _num_filters) {
Expand Down

0 comments on commit 148c176

Please sign in to comment.