summaryrefslogtreecommitdiffhomepage
path: root/filter-ewma2
diff options
context:
space:
mode:
authorGO63-samara <go1@list.ru>2020-04-28 22:13:55 +0400
committerGO63-samara <go1@list.ru>2020-04-28 22:13:55 +0400
commit48e1c8a5a41449e4b9291954964188fad9dfd248 (patch)
treed5b0e339cdc03fb6d6b28adce84ea3b37a34be0b /filter-ewma2
parent7252c00161959b3b7ce9d78506ec6cf026f24d5e (diff)
fix sintax
replacing define with static constexpr double and replacing a tab with a space
Diffstat (limited to 'filter-ewma2')
-rw-r--r--filter-ewma2/ftnoir_filter_ewma2.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/filter-ewma2/ftnoir_filter_ewma2.cpp b/filter-ewma2/ftnoir_filter_ewma2.cpp
index 09e6f5d7..25902280 100644
--- a/filter-ewma2/ftnoir_filter_ewma2.cpp
+++ b/filter-ewma2/ftnoir_filter_ewma2.cpp
@@ -26,8 +26,8 @@ ewma::ewma() = default;
void ewma::filter(const double *input, double *output)
{
-#define FULL_TURN 360.0
-#define HALF_TURN 180.0
+ static constexpr double full_turn = 360;
+ static constexpr double half_turn = 180;
// Start the timer and initialise filter state if it's not running.
if (first_run)
{
@@ -59,13 +59,13 @@ void ewma::filter(const double *input, double *output)
using std::pow;
// Calculate the current and smoothed delta.
- double input_value = input[i];
- double delta = input_value - last_output[i];
- if (fabs(delta) > HALF_TURN)
- {
- delta -= copysign(FULL_TURN, delta);
- input_value -= copysign(FULL_TURN, input_value);
- }
+ double input_value = input[i];
+ double delta = input_value - last_output[i];
+ if (fabs(delta) > half_turn)
+ {
+ delta -= copysign(full_turn, delta);
+ input_value -= copysign(full_turn, input_value);
+ }
last_delta[i] = delta_alpha*delta + (1.0-delta_alpha)*last_delta[i];
// Calculate the current and smoothed noise variance.
double noise = last_delta[i]*last_delta[i];
@@ -78,9 +78,9 @@ void ewma::filter(const double *input, double *output)
// Calculate the dynamic alpha.
double alpha = dt/(dt + RC);
// Calculate the new output position.
- output[i] = alpha*input_value + (1.0-alpha)*last_output[i];
- if (fabs(output[i]) > HALF_TURN) output[i] -= copysign(FULL_TURN, output[i]);
- last_output[i] = output[i];
+ output[i] = alpha*input_value + (1.0-alpha)*last_output[i];
+ if (fabs(output[i]) > half_turn) output[i] -= copysign(full_turn, output[i]);
+ last_output[i] = output[i];
}
}