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

◆ zero_crossings() [2/2]

MAYAFLUX_API std::vector< size_t > MayaFlux::zero_crossings ( const std::vector< double > &  data,
double  threshold = 0.0 
)

Detect zero crossings in single-channel signal.

Parameters
dataInput signal data
thresholdMinimum amplitude difference for crossing detection (default: 0.0)
Returns
Vector of zero crossing indices

Definition at line 268 of file Yantra.cpp.

269{
270 auto analyzer = std::make_shared<Yantra::StandardEnergyAnalyzer>();
271 analyzer->set_energy_method(Yantra::EnergyMethod::ZERO_CROSSING);
272
273 auto result = analyzer->analyze_energy({ { data } });
274
275 if (result.channels.empty()) {
276 return {};
277 }
278
279 const auto& positions = result.channels[0].event_positions;
280
281 if (threshold <= 0.0) {
282 return positions;
283 }
284
285 std::vector<size_t> filtered;
286 for (size_t pos : positions) {
287 if (pos < data.size() && std::abs(data[pos]) >= threshold) {
288 filtered.push_back(pos);
289 }
290 }
291 return filtered;
292}

References MayaFlux::Yantra::ZERO_CROSSING.