MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ threshold_crossing_rate()

double MayaFlux::Kinesis::threshold_crossing_rate ( std::span< const double >  values,
double  threshold,
double  dt 
)
inlinenoexcept

Threshold crossings per second within a window.

Parameters
valuesChronological span, at least two entries
thresholdLevel whose crossings are counted
dtSeconds per sample
Returns
Crossings in either direction, divided by the window duration

A rate in seconds against an arbitrary level, where Discrete::zero_crossing_rate is normalized per sample and windowed into a vector. Both count the same events; this is the shape a per-update scalar measure needs.

Counts crossings in both directions, so a value oscillating about the threshold reports twice the rate of its underlying cycle. Halve the result when the intended quantity is cycles rather than transitions.

Definition at line 132 of file TemporalMeasures.hpp.

134{
135 const size_t n = values.size();
136 if (n < 2 || dt <= 0.0)
137 return 0.0;
138
139 size_t crossings = 0;
140 for (size_t i = 1; i < n; ++i) {
141 if ((values[i] >= threshold) != (values[i - 1] >= threshold))
142 ++crossings;
143 }
144
145 const double duration = static_cast<double>(n - 1) * dt;
146 return static_cast<double>(crossings) / duration;
147}
std::vector< std::byte > values
Definition VDBWriter.cpp:26
float threshold

References threshold, and values.