mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-05 07:28:29 -04:00
Filter: fixed reset of filters to first value
the delay elements were set incorrectly
This commit is contained in:
parent
d1e6b0befb
commit
6144136b61
@ -18,7 +18,7 @@ T DigitalBiquadFilter<T>::apply(const T &sample, const struct biquad_params &par
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!initialised) {
|
if (!initialised) {
|
||||||
reset(sample);
|
reset(sample, params);
|
||||||
initialised = true;
|
initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +38,8 @@ void DigitalBiquadFilter<T>::reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void DigitalBiquadFilter<T>::reset(const T &value) {
|
void DigitalBiquadFilter<T>::reset(const T &value, const struct biquad_params ¶ms) {
|
||||||
_delay_element_1 = _delay_element_2 = value;
|
_delay_element_1 = _delay_element_2 = value * (1.0 / (1 + params.a1 + params.a2));
|
||||||
initialised = true;
|
initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ void LowPassFilter2p<T>::reset(void) {
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void LowPassFilter2p<T>::reset(const T &value) {
|
void LowPassFilter2p<T>::reset(const T &value) {
|
||||||
return _filter.reset(value);
|
return _filter.reset(value, _params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
|
|
||||||
T apply(const T &sample, const struct biquad_params ¶ms);
|
T apply(const T &sample, const struct biquad_params ¶ms);
|
||||||
void reset();
|
void reset();
|
||||||
void reset(const T &value);
|
void reset(const T &value, const struct biquad_params ¶ms);
|
||||||
static void compute_params(float sample_freq, float cutoff_freq, biquad_params &ret);
|
static void compute_params(float sample_freq, float cutoff_freq, biquad_params &ret);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -26,16 +26,12 @@ void loop()
|
|||||||
for(int16_t i = 0; i < 300; i++ ) {
|
for(int16_t i = 0; i < 300; i++ ) {
|
||||||
|
|
||||||
// new data value
|
// new data value
|
||||||
const float new_value = sinf((float)i * 2 * M_PI * 5 / 50.0f); // 5hz
|
const float new_value = 17 + sinf((float)i * 2 * M_PI * 5 / 50.0f); // 5hz
|
||||||
|
|
||||||
// output to user
|
|
||||||
hal.console->printf("applying: %6.4f", (double)new_value);
|
|
||||||
|
|
||||||
// apply new value and retrieved filtered result
|
// apply new value and retrieved filtered result
|
||||||
const float filtered_value = low_pass_filter.apply(new_value);
|
const float filtered_value = low_pass_filter.apply(new_value);
|
||||||
|
|
||||||
// display results
|
// output to user
|
||||||
hal.console->printf("\toutput: %6.4f\n", (double)filtered_value);
|
hal.console->printf("applying: %6.4f -> %6.4f\n", (double)new_value, filtered_value);
|
||||||
|
|
||||||
hal.scheduler->delay(10);
|
hal.scheduler->delay(10);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user