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

◆ fourier_series()

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

Fourier series of a phase.

The phase in radians is window[0]. coefs: [a0, a1, b1, a2, b2, ...] and the result is a0 + sum a_k cos(k t) + b_k sin(k t). A final a_k without its b_k is read with b_k = 0. One sine and one cosine are evaluated, the harmonics follow by rotation.

Definition at line 291 of file Kernels.cpp.

292{
293 if (coefs.empty())
294 return 0.0;
295
296 const double phase = window.empty() ? 0.0 : window.front();
297 const double c1 = std::cos(phase);
298 const double s1 = std::sin(phase);
299
300 double ck = c1;
301 double sk = s1;
302 double sum = coefs.front();
303
304 for (size_t i = 1; i < coefs.size(); i += 2) {
305 sum += coefs[i] * ck;
306 if (i + 1 < coefs.size())
307 sum += coefs[i + 1] * sk;
308
309 const double next_c = ck * c1 - sk * s1;
310 sk = sk * c1 + ck * s1;
311 ck = next_c;
312 }
313 return sum;
314}
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
std::vector< double > sum(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sum per window.
Definition Analysis.cpp:469

References sum(), and window.

+ Here is the call graph for this function: