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

◆ compute_zero_crossing_energy()

std::vector< double > MayaFlux::Yantra::compute_zero_crossing_energy ( std::span< const double >  data,
const size_t  num_windows,
const uint32_t  hop_size,
const uint32_t  window_size 
)

Compute zero-crossing energy using zero-copy processing.

This function computes the zero-crossing rate for a given data span. It counts the number of zero crossings in each window and normalizes it.

Parameters
dataInput data span
num_windowsNumber of windows to process
hop_sizeHop size for windowing
window_sizeSize of each window
Returns
Vector of zero-crossing energy values

Definition at line 41 of file AnalysisHelper.cpp.

42{
43 std::vector<double> zcr_values(num_windows);
44
45 std::vector<size_t> indices(num_windows);
46 std::iota(indices.begin(), indices.end(), 0);
47
48 std::for_each(std::execution::par_unseq, indices.begin(), indices.end(),
49 [&](size_t i) {
50 const size_t start_idx = i * hop_size;
51 const size_t end_idx = std::min(start_idx + window_size, data.size());
52 auto window = data.subspan(start_idx, end_idx - start_idx);
53
54 int zero_crossings = 0;
55 for (size_t j = 1; j < window.size(); ++j) {
56 if ((window[j] >= 0.0) != (window[j - 1] >= 0.0)) {
57 zero_crossings++;
58 }
59 }
60 zcr_values[i] = static_cast<double>(zero_crossings) / static_cast<double>(window.size() - 1);
61 });
62
63 return zcr_values;
64}

References compute_zero_crossing_energy(), and MayaFlux::zero_crossings().

Referenced by MayaFlux::Yantra::EnergyAnalyzer< InputType, OutputType >::compute_energy_values(), and compute_zero_crossing_energy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: