63[[nodiscard]]
inline double roughness(std::span<const double>
values,
double dt)
noexcept
65 const size_t n =
values.size();
66 if (n < 2 || dt <= 0.0)
70 for (
size_t i = 1; i < n; ++i)
73 return (acc /
static_cast<double>(n - 1)) / dt;
90 const auto [
lo,
hi] = std::ranges::minmax_element(
values);
109 for (
const double v :
values) {
113 return static_cast<double>(
count) * dt;
135 const size_t n =
values.size();
136 if (n < 2 || dt <= 0.0)
139 size_t crossings = 0;
140 for (
size_t i = 1; i < n; ++i) {
145 const double duration =
static_cast<double>(n - 1) * dt;
146 return static_cast<double>(crossings) / duration;
204 std::span<const double>
values,
207 double max_period)
noexcept
209 const size_t n =
values.size();
210 if (n < 4 || dt <= 0.0 || max_period <= min_period)
214 for (
const double v :
values)
216 mean /=
static_cast<double>(n);
222 const auto min_lag = std::max<size_t>(1,
static_cast<size_t>(min_period / dt));
223 const auto max_lag = std::min(n / 2,
static_cast<size_t>(max_period / dt));
224 if (min_lag > max_lag)
228 for (
size_t lag = min_lag; lag <= max_lag; ++lag) {
230 for (
size_t i = 0; i + lag < n; ++i)
236 best.
period =
static_cast<double>(lag) * dt;
std::vector< std::byte > values
static double variance(std::span< const double > samples) noexcept
Sample variance of a span.
double time_above(std::span< const double > values, double threshold, double dt) noexcept
Seconds within a window spent at or above a threshold.
double roughness(std::span< const double > values, double dt) noexcept
Mean absolute difference between consecutive samples, per second.
double excursion(std::span< const double > values) noexcept
Difference between the largest and smallest value in a window.
double threshold_crossing_rate(std::span< const double > values, double threshold, double dt) noexcept
Threshold crossings per second within a window.
double correlation(std::span< const double > a, std::span< const double > b) noexcept
Pearson correlation between two equal-length windows.
PeriodEstimate estimate_period(std::span< const double > values, double dt, double min_period, double max_period) noexcept
Estimate a repetition period by direct autocorrelation over a bounded lag range.
double mean(const std::vector< double > &data)
Calculate mean of single-channel data.
double period
Seconds between repetitions, zero when no lag qualified.
double strength
Normalized autocorrelation at that lag, in -1..1. Near zero means no repetition.
A candidate repetition period and how strongly the window actually supports it.