MayaFlux 0.3.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 321 of file Yantra.cpp.

322{
323 auto analyzer = std::make_shared<Yantra::StandardEnergyAnalyzer>();
324 analyzer->set_energy_method(Yantra::EnergyMethod::ZERO_CROSSING);
325 auto result = analyzer->analyze_energy(channels);
326
327 std::vector<std::vector<size_t>> all_crossings;
328 all_crossings.reserve(result.channels.size());
329
330 for (size_t ch = 0; ch < result.channels.size(); ++ch) {
331 const auto& positions = result.channels[ch].event_positions;
332
333 if (threshold <= 0.0) {
334 all_crossings.push_back(positions);
335 continue;
336 }
337
338 auto double_data = std::get<std::vector<double>>(channels[ch]);
339 std::vector<size_t> filtered;
340 for (size_t pos : positions) {
341 if (pos < double_data.size() && std::abs(double_data[pos]) >= threshold) {
342 filtered.push_back(pos);
343 }
344 }
345 all_crossings.push_back(filtered);
346 }
347
348 return all_crossings;
349}

References MayaFlux::Yantra::ZERO_CROSSING.