MayaFlux 0.1.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 319 of file Yantra.cpp.

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

References MayaFlux::Yantra::ZERO_CROSSING.