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

◆ estimate_frequency()

MAYAFLUX_API double MayaFlux::Kinesis::Discrete::estimate_frequency ( std::span< const double >  data,
double  sample_rate,
double  fallback = 0.0,
double  threshold = 0.0 
)

Estimate the dominant cycle frequency of a sampled signal.

Detects zero-crossing positions in data and derives frequency from the mean inter-crossing interval. Each consecutive pair of crossings represents one half-period; the mean of all half-periods gives a robust estimate robust to occasional spurious crossings.

Returns fallback when fewer than two crossings are found (signal is silent, DC, or the buffer is shorter than one half-cycle).

Parameters
dataInput span (any sampled sequence)
sample_rateSamples per second
fallbackValue returned when estimation is not possible
thresholdZero-crossing detection threshold (default: 0.0)
Returns
Estimated frequency in Hz, or fallback

Definition at line 646 of file Analysis.cpp.

651{
652 if (data.size() < 2)
653 return fallback;
654
655 const auto crossings = zero_crossing_positions(data, threshold);
656
657 if (crossings.size() < 2)
658 return fallback;
659
660 const double mean_half_period = static_cast<double>(crossings.back() - crossings.front())
661 / static_cast<double>(crossings.size() - 1);
662
663 if (mean_half_period < 1.0)
664 return fallback;
665
666 return sample_rate / (2.0 * mean_half_period);
667}
std::vector< size_t > zero_crossing_positions(std::span< const double > data, double threshold)
Sample indices of zero crossings in the full span.
Definition Analysis.cpp:634

References estimate_frequency(), MayaFlux::Kinesis::threshold(), and zero_crossing_positions().

Referenced by estimate_frequency().

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