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

◆ relation_at_lag()

double MayaFlux::Kinesis::relation_at_lag ( std::span< const double >  a,
std::span< const double >  b,
long  lag 
)
inlinenoexcept

Correlation between two spans at a single fixed lag.

Parameters
aFirst span
bSecond span
lagSamples to offset b relative to a; positive tests whether b's later samples resemble a's earlier ones
Returns
Correlation over the overlapping region at that lag, or zero if the overlap is too short to be meaningful

The bounded, single-lag counterpart to Discrete::cross_correlate; see this file's header comment for the relationship. Exists as its own function, distinct from relation_lag below, because a caller who already knows the lag they care about (a fixed device latency, a known frame offset between two sensors) should not pay for a search over a range to confirm what they already know.

Definition at line 111 of file Relation.hpp.

113{
114 const auto na = static_cast<long>(a.size());
115 const auto nb = static_cast<long>(b.size());
116
117 const long start_a = std::max(0L, -lag);
118 const long start_b = std::max(0L, lag);
119 const long overlap = std::min(na - start_a, nb - start_b);
120
121 if (overlap < 2)
122 return 0.0;
123
124 return correlation(
125 a.subspan(static_cast<size_t>(start_a), static_cast<size_t>(overlap)),
126 b.subspan(static_cast<size_t>(start_b), static_cast<size_t>(overlap)));
127}
size_t a
size_t b
double correlation(std::span< const double > a, std::span< const double > b) noexcept
Pearson correlation between two equal-length windows.
Definition Relation.hpp:45

References a, b, and correlation().

Referenced by relation_lag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: