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

◆ goertzel()

MAYAFLUX_API double MayaFlux::Kinesis::Discrete::goertzel ( std::span< const double >  window,
std::span< const double >  coefs 
)
noexcept

Weighted energy of the window at chosen frequencies.

coefs: pairs (frequency in cycles per sample, weight). Each frequency is measured with the Goertzel recurrence over the whole window and gives the squared amplitude of the sinusoid there (a sine of amplitude A on the frequency gives A^2 when it fits the window in whole cycles); the result is the weighted sum.

Definition at line 451 of file Kernels.cpp.

452{
453 const size_t n = window.size();
454 if (n == 0)
455 return 0.0;
456
457 const double scale = 4.0 / (static_cast<double>(n) * static_cast<double>(n));
458 double total = 0.0;
459
460 for (size_t j = 0; j + 1 < coefs.size(); j += 2) {
461 const double coeff = 2.0 * std::cos(two_pi * coefs[j]);
462 double s1 = 0.0;
463 double s2 = 0.0;
464 for (const double x : window) {
465 const double s = x + coeff * s1 - s2;
466 s2 = s1;
467 s1 = s;
468 }
469 total += coefs[j + 1] * scale * (s1 * s1 + s2 * s2 - coeff * s1 * s2);
470 }
471 return total;
472}
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
uint32_t total
Tendency< D, float > scale(const Tendency< D, float > &t, float factor)
Uniform scaling of a scalar-output tendency.
Definition Tendency.hpp:98

References MayaFlux::Kinesis::scale(), total, and window.

+ Here is the call graph for this function: