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

◆ low_frequency_energy()

std::vector< double > MayaFlux::Kinesis::Discrete::low_frequency_energy ( std::span< const double >  data,
size_t  n_windows,
uint32_t  hop_size,
uint32_t  window_size,
double  low_bin_fraction = 0.125 
)

Low-frequency spectral energy per window.

Computes energy in the lowest (low_bin_fraction * N/2) bins of the magnitude spectrum. Defaults to the bottom eighth of the spectrum.

Note
Eigen::FFT dependency — not portable to compute shader contexts.
Parameters
dataInput span
n_windowsPre-computed window count from num_windows()
hop_sizeSamples between window starts
window_sizeSamples per window
low_bin_fractionFraction of positive-frequency bins to include (default: 0.125)
Returns
Per-window low-frequency energy values

Definition at line 164 of file Analysis.cpp.

165{
166 std::vector<double> out(n_windows);
167 std::vector<size_t> idx(n_windows);
168 std::iota(idx.begin(), idx.end(), 0);
169
170 const Eigen::VectorXd hw = hann_window(window_size);
171 const int low_bins = std::max(1, static_cast<int>(static_cast<double>((double)window_size / 2) * low_bin_fraction));
172
173 Parallel::for_each(Parallel::par_unseq, idx.begin(), idx.end(),
174 [&](size_t i) {
175 const size_t start = i * hop_size;
176 auto w = data.subspan(start, std::min<size_t>(window_size, data.size() - start));
177
178 Eigen::VectorXd buf = Eigen::VectorXd::Zero(window_size);
179 for (size_t j = 0; j < w.size(); ++j)
180 buf(static_cast<Eigen::Index>(j)) = w[j] * hw(static_cast<Eigen::Index>(j));
181
182 Eigen::FFT<double> fft;
183 Eigen::VectorXcd spec;
184 fft.fwd(spec, buf);
185
186 double e = 0.0;
187 for (int j = 1; j < low_bins; ++j)
188 e += std::norm(spec(j));
189
190 out[i] = e / static_cast<double>(low_bins);
191 });
192
193 return out;
194}

References low_frequency_energy().

Referenced by low_frequency_energy().

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