summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Brazier <tom_github@firstsolo.net>2023-06-02 15:25:04 +0100
committerTom Brazier <tom_github@firstsolo.net>2023-07-23 14:00:51 +0100
commit26db426f05657edcaf4bd5ea84d807e63c7ef181 (patch)
treef12c814af99c10aab703fbf95ca7a1f092f976bf
parent1e88d84e1df7d04e0a17d70e07ecdc2586d8b5e6 (diff)
corrected EWA logic for large values of dt * responsiveness
-rw-r--r--filter-nm/ftnoir_filter_nm.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/filter-nm/ftnoir_filter_nm.cpp b/filter-nm/ftnoir_filter_nm.cpp
index b616f722..cd395f1b 100644
--- a/filter-nm/ftnoir_filter_nm.cpp
+++ b/filter-nm/ftnoir_filter_nm.cpp
@@ -36,8 +36,10 @@ void filter_nm::filter(const double* input, double* output)
for (int i = 0; i < 6; i++)
{
double speed = (input[i] - last_input[i]) / dt;
- speeds[i] += dt * (double)s.responsiveness[i] * (speed - speeds[i]);
- filtered_output[i] += dt * (double)s.responsiveness[i] * min(1.0, abs(speeds[i]) / (double)s.drift_speeds[i]) * (input[i] - filtered_output[i]);
+ double timescale = 1. / *(s.responsiveness[i]);
+ double alpha = dt / (dt + timescale);
+ speeds[i] += alpha * (speed - speeds[i]); // EWA
+ filtered_output[i] += alpha * min(1.0, abs(speeds[i]) / *(s.drift_speeds[i])) * (input[i] - filtered_output[i]);
}
}