2#include "PatternModHelpers.h"
6static const int max_moving_window_size = 6;
9static const int ccacc_timing_check_size = 3;
22 for (
auto i = 1; i < max_moving_window_size; ++i) {
23 _itv_vals.at(i - 1) = _itv_vals.at(i);
27 _itv_vals.at(max_moving_window_size - 1) = new_val;
33 assert(pos >= 0 && pos < max_moving_window_size);
34 return _itv_vals.at(pos);
38 [[nodiscard]]
auto get_now() const -> T {
return _itv_vals.back(); }
42 return _itv_vals.at(max_moving_window_size - 2);
48 T o =
static_cast<T
>(0);
49 auto i = max_moving_window_size;
50 while (i > max_moving_window_size - window) {
61 T o =
static_cast<T
>(0);
62 auto i = max_moving_window_size;
63 while (i > max_moving_window_size - window) {
65 o = _itv_vals.at(i) > o ? _itv_vals.at(i) : o;
75 auto i = max_moving_window_size;
76 while (i > max_moving_window_size - window) {
78 o = _itv_vals.at(i) < o ? _itv_vals.at(i) : o;
87 T o =
static_cast<T
>(0);
89 auto i = max_moving_window_size;
90 while (i > max_moving_window_size - window) {
95 return static_cast<float>(o) /
static_cast<float>(window);
103 auto i = max_moving_window_size;
104 while (i > max_moving_window_size - window) {
106 o += _itv_vals.at(i);
122 auto i = max_moving_window_size;
123 while (i > max_moving_window_size - window) {
125 sd += (
static_cast<float>(_itv_vals.at(i)) - avg) *
126 (
static_cast<float>(_itv_vals.at(i)) - avg);
129 return fastsqrt(sd /
static_cast<float>(window)) / avg;
156 const float& threshold) ->
bool
160 _itv_vals[4] /= factor;
166 _itv_vals[4] *= factor;
168 return o < threshold;
177 const float& threshold) ->
bool
180 _itv_vals[4] *= factor;
182 _itv_vals[4] /= factor;
183 return o < threshold;
188 const float& threshold) ->
bool
198 if (any_ms_is_greater(_itv_vals[4], _itv_vals[5])) {
210 void zero() { _itv_vals.fill(
static_cast<T
>(0)); }
211 void fill(
const T& val) { _itv_vals.fill(val); }
214 std::array<T, max_moving_window_size> _itv_vals = { 0, 0, 0, 0, 0, 0 };
Definition CalcWindow.h:15
void zero()
set everything to zero
Definition CalcWindow.h:210
auto get_max_for_window(const int &window) const -> T
get the max for the moving window up to a given size
Definition CalcWindow.h:59
auto get_total_for_windowf(const int &window) const -> float
Definition CalcWindow.h:100
auto operator[](const int &pos) const -> T
index moving window like an array
Definition CalcWindow.h:31
void operator()(const T &new_val)
Definition CalcWindow.h:19
auto get_min_for_window(const int &window) const -> T
get the min for the moving window up to a given size
Definition CalcWindow.h:72
auto get_total_for_window(const int &window) const -> T
get the sum for the moving window up to a given size
Definition CalcWindow.h:46
auto get_mean_of_window(const int &window) const -> float
get the mean for the moving window up to a given size
Definition CalcWindow.h:85
auto roll_timing_check(const float &factor, const float &threshold) -> bool
perform cv check internally
Definition CalcWindow.h:187
auto get_cv_of_window(const int &window) const -> float
get the coefficient of variance of the moving window up to a given size
Definition CalcWindow.h:113
auto ccacc_timing_check(const float &factor, const float &threshold) -> bool
perform cv check internally
Definition CalcWindow.h:155
auto get_now() const -> T
get most recent value in moving window
Definition CalcWindow.h:38
auto acca_timing_check(const float &factor, const float &threshold) -> bool
perform cv check internally
Definition CalcWindow.h:176
auto get_last() const -> T
get oldest value in moving window
Definition CalcWindow.h:40