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

◆ zero_crossings_per_channel()

MAYAFLUX_API std::vector< std::vector< size_t > > MayaFlux::zero_crossings_per_channel ( const std::vector< Kakshya::DataVariant > &  channels,
double  threshold = 0.0 
)

Detect zero crossings per channel for multi-channel signal.

Parameters
channelsVector of channel data
thresholdMinimum amplitude difference for crossing detection (default: 0.0)
Returns
Vector of zero crossing indices for each channel

Definition at line 380 of file Yantra.cpp.

381{
382 static const auto s_op = [] {
383 auto a = std::make_shared<Yantra::StandardEnergyAnalyzer>();
384 a->set_energy_method(Yantra::EnergyMethod::ZERO_CROSSING);
385 return a;
386 }();
387 auto result = s_op->analyze_energy(channels);
388 std::vector<std::vector<size_t>> all_crossings;
389 all_crossings.reserve(result.channels.size());
390
391 for (size_t ch = 0; ch < result.channels.size(); ++ch) {
392 const auto& positions = result.channels[ch].event_positions;
393 if (threshold <= 0.0) {
394 all_crossings.push_back(positions);
395 continue;
396 }
397 auto double_data = std::get<std::vector<double>>(channels[ch]);
398 std::vector<size_t> filtered;
399 for (size_t pos : positions) {
400 if (pos < double_data.size() && std::abs(double_data[pos]) >= threshold)
401 filtered.push_back(pos);
402 }
403 all_crossings.push_back(filtered);
404 }
405 return all_crossings;
406}
size_t a

References a, and MayaFlux::Yantra::ZERO_CROSSING.