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

◆ extract_high_spectral_data()

std::vector< std::vector< double > > MayaFlux::Yantra::extract_high_spectral_data ( const std::vector< std::span< const double > > &  data,
double  spectral_threshold = 0.1,
uint32_t  window_size = 512,
uint32_t  hop_size = 256 
)

Extract data from regions with high spectral energy.

Parameters
dataInput data span
spectral_thresholdMinimum spectral energy threshold
window_sizeAnalysis window size
hop_sizeHop size between windows
Returns
Vector containing actual data from high spectral energy regions

Definition at line 251 of file ExtractionHelper.cpp.

256{
257 std::vector<std::vector<double>> result;
258 result.reserve(data.size());
259
260 for (const auto& channel : data) {
261 if (channel.empty()) {
262 result.emplace_back();
263 continue;
264 }
265
266 uint32_t effective_window_size = std::min(window_size, static_cast<uint32_t>(channel.size()));
267 uint32_t effective_hop_size = std::min(hop_size, effective_window_size / 2);
268 if (effective_hop_size == 0)
269 effective_hop_size = 1;
270
271 if (!validate_extraction_parameters(effective_window_size, effective_hop_size, channel.size())) {
272 result.emplace_back();
273 continue;
274 }
275
276 try {
277 auto energy_analyzer = std::make_shared<EnergyAnalyzer<std::vector<Kakshya::DataVariant>, Eigen::VectorXd>>(
278 effective_window_size, effective_hop_size);
279 energy_analyzer->set_parameter("method", "spectral");
280
281 std::vector<Kakshya::DataVariant> data_variant { Kakshya::DataVariant { std::vector<double>(channel.begin(), channel.end()) } };
282 EnergyAnalysis energy_result = energy_analyzer->analyze_energy(data_variant);
283
284 if (energy_result.channels.empty() || energy_result.channels[0].energy_values.empty() || energy_result.channels[0].window_positions.empty()) {
285 result.emplace_back();
286 continue;
287 }
288
289 std::vector<std::pair<size_t, size_t>> qualifying_windows;
290 const auto& ch_energy = energy_result.channels[0].energy_values;
291 const auto& ch_windows = energy_result.channels[0].window_positions;
292 for (size_t i = 0; i < ch_energy.size(); ++i) {
293 if (ch_energy[i] > spectral_threshold) {
294 auto [start_idx, end_idx] = ch_windows[i];
295 if (start_idx < channel.size() && end_idx <= channel.size() && start_idx < end_idx) {
296 qualifying_windows.emplace_back(start_idx, end_idx);
297 }
298 }
299 }
300
301 auto merged_windows = merge_overlapping_windows(qualifying_windows);
302
303 std::vector<double> extracted_data;
304 for (const auto& [start_idx, end_idx] : merged_windows) {
305 std::ranges::copy(channel.subspan(start_idx, end_idx - start_idx),
306 std::back_inserter(extracted_data));
307 }
308
309 result.push_back(std::move(extracted_data));
310 } catch (const std::exception&) {
311 result.emplace_back();
312 }
313 }
314
315 return result;
316}

References MayaFlux::Yantra::EnergyAnalysis::channels, and validate_extraction_parameters().

Referenced by MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::extract_implementation().

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