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

◆ spectral_energy()

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

Spectral energy per window using Hann-windowed FFT.

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 (determines FFT size)
Returns
Per-window summed spectral energy, normalised by window_size

Definition at line 133 of file Analysis.cpp.

134{
135 std::vector<double> out(n_windows);
136 std::vector<size_t> idx(n_windows);
137 std::iota(idx.begin(), idx.end(), 0);
138
139 const Eigen::VectorXd hw = hann_window(window_size);
140
141 Parallel::for_each(Parallel::par_unseq, idx.begin(), idx.end(),
142 [&](size_t i) {
143 const size_t start = i * hop_size;
144 auto w = data.subspan(start, std::min<size_t>(window_size, data.size() - start));
145
146 Eigen::VectorXd buf = Eigen::VectorXd::Zero(window_size);
147 for (size_t j = 0; j < w.size(); ++j)
148 buf(static_cast<Eigen::Index>(j)) = w[j] * hw(static_cast<Eigen::Index>(j));
149
150 Eigen::FFT<double> fft;
151 Eigen::VectorXcd spec;
152 fft.fwd(spec, buf);
153
154 double e = 0.0;
155 for (Eigen::Index j = 0; j < spec.size(); ++j)
156 e += std::norm(spec(j));
157
158 out[i] = e / static_cast<double>(window_size);
159 });
160
161 return out;
162}

References spectral_energy().

Referenced by MayaFlux::Yantra::extract_high_spectral(), and spectral_energy().

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