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

◆ interval_median()

MAYAFLUX_API std::vector< double > MayaFlux::Kinesis::Discrete::interval_median ( std::span< const double > values,
std::span< const size_t > positions,
const std::vector< std::pair< size_t, size_t > > & intervals )
nodiscard

Median of the values inside each interval.

Parameters
valuesOne value per position
positionsSample position of each value, ascending
intervals[start, end) pairs; a value belongs to an interval holding its position
Returns
One median per interval, the mean of the two middle values for an even count, 0 for an interval holding no values

Definition at line 110 of file Extract.cpp.

114{
115 std::vector<double> out;
116 out.reserve(intervals.size());
117 for (const auto& interval : intervals) {
118 const auto inside = values_inside(values, positions, interval);
119 if (inside.empty()) {
120 out.push_back(0.0);
121 continue;
122 }
123 std::vector<double> sorted(inside.begin(), inside.end());
124 std::ranges::sort(sorted);
125 const size_t mid = sorted.size() / 2;
126 out.push_back(sorted.size() % 2 == 1 ? sorted[mid] : 0.5 * (sorted[mid - 1] + sorted[mid]));
127 }
128 return out;
129}

Referenced by MayaFlux::Yantra::measure_voicing().

Here is the caller graph for this function: