MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AnalysisHelper.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Yantra {
4
5/**
6 * @brief Compute dynamic range energy using zero-copy processing
7 *
8 * This function computes the dynamic range energy for a given data span.
9 * It calculates the maximum and minimum absolute values in each window,
10 * then computes the dynamic range in decibels.
11 *
12 * @param data Input data span
13 * @param num_windows Number of windows to process
14 * @param hop_size Hop size for windowing
15 * @param window_size Size of each window
16 * @return Vector of dynamic range energy values
17 */
18std::vector<double> compute_dynamic_range_energy(
19 std::span<const double> data,
20 const size_t num_windows,
21 const uint32_t hop_size,
22 const uint32_t window_size);
23
24/**
25 * @brief Compute zero-crossing energy using zero-copy processing
26 *
27 * This function computes the zero-crossing rate for a given data span.
28 * It counts the number of zero crossings in each window and normalizes it.
29 *
30 * @param data Input data span
31 * @param num_windows Number of windows to process
32 * @param hop_size Hop size for windowing
33 * @param window_size Size of each window
34 * @return Vector of zero-crossing energy values
35 */
36std::vector<double> compute_zero_crossing_energy(
37 std::span<const double> data,
38 const size_t num_windows,
39 const uint32_t hop_size,
40 const uint32_t window_size);
41
42/**
43 * @brief Find actual zero-crossing positions in the signal
44 *
45 * Unlike compute_zero_crossing_energy which returns ZCR per window,
46 * this returns the actual sample indices where zero crossings occur.
47 *
48 * @param data Input data span
49 * @param threshold Threshold value for crossing detection (default: 0.0)
50 * @return Vector of sample positions where crossings occur
51 */
52std::vector<size_t> find_zero_crossing_positions(
53 std::span<const double> data,
54 double threshold = 0.0);
55
56/**
57 * @brief Find actual peak positions in the signal
58 *
59 * Returns sample indices where local maxima occur above a threshold.
60 *
61 * @param data Input data span
62 * @param threshold Minimum absolute value to be considered a peak
63 * @param min_distance Minimum samples between peaks (prevents clustering)
64 * @return Vector of sample positions where peaks occur
65 */
66std::vector<size_t> find_peak_positions(
67 std::span<const double> data,
68 double threshold = 0.0,
69 size_t min_distance = 1);
70
71/**
72 * @brief Find onset positions using spectral flux
73 *
74 * Detects rapid increases in spectral energy (transients/attacks).
75 *
76 * @param data Input data span
77 * @param window_size FFT window size
78 * @param hop_size Hop between analysis frames
79 * @param threshold Flux threshold for onset detection
80 * @return Vector of sample positions where onsets occur
81 */
82std::vector<size_t> find_onset_positions(
83 std::span<const double> data,
84 uint32_t window_size,
85 uint32_t hop_size,
86 double threshold = 0.1);
87
88/**
89 * @brief Compute power energy using zero-copy processing
90 *
91 * This function computes the power energy for a given data span.
92 * It calculates the sum of squares of samples in each window.
93 *
94 * @param data Input data span
95 * @param num_windows Number of windows to process
96 * @param m_hop_size Hop size for windowing
97 * @param m_window_size Size of each window
98 * @return Vector of power energy values
99 */
100std::vector<double> compute_power_energy(
101 std::span<const double> data,
102 const size_t num_windows,
103 const uint32_t m_hop_size,
104 const uint32_t m_window_size);
105
106/**
107 * @brief Compute peak energy using zero-copy processing
108 *
109 * This function computes the peak amplitude for a given data span.
110 * It finds the maximum absolute value in each window.
111 *
112 * @param data Input data span
113 * @param num_windows Number of windows to process
114 * @param hop_size Hop size for windowing
115 * @param window_size Size of each window
116 * @return Vector of peak energy values
117 */
118std::vector<double> compute_peak_energy(
119 std::span<const double> data,
120 const uint32_t num_windows,
121 const uint32_t hop_size,
122 const uint32_t window_size);
123
124/**
125 * @brief Compute RMS energy using zero-copy processing
126 *
127 * This function computes the root mean square (RMS) energy for a given data span.
128 * It calculates the square root of the average of squares in each window.
129 *
130 * @param data Input data span
131 * @param num_windows Number of windows to process
132 * @param hop_size Hop size for windowing
133 * @param window_size Size of each window
134 * @return Vector of RMS energy values
135 */
136std::vector<double> compute_rms_energy(
137 std::span<const double> data,
138 const uint32_t num_windows,
139 const uint32_t hop_size,
140 const uint32_t window_size);
141
142/**
143 * @brief Compute spectral energy using FFT-based analysis
144 *
145 * This function computes the spectral energy for a given data span using FFT.
146 * It calculates the magnitude spectrum and sums the energy across frequency bins.
147 *
148 * @param data Input data span
149 * @param num_windows Number of windows to process
150 * @param hop_size Hop size for windowing
151 * @param window_size Size of each window
152 * @return Vector of spectral energy values
153 */
154std::vector<double> compute_spectral_energy(
155 std::span<const double> data,
156 const size_t num_windows,
157 const uint32_t hop_size,
158 const uint32_t window_size);
159
160/**
161 * @brief Compute harmonic energy using low-frequency FFT analysis
162 *
163 * This function computes the harmonic energy for a given data span.
164 * It focuses on the lower portion of the frequency spectrum (harmonics).
165 *
166 * @param data Input data span
167 * @param num_windows Number of windows to process
168 * @param hop_size Hop size for windowing
169 * @param window_size Size of each window
170 * @return Vector of harmonic energy values
171 */
172std::vector<double> compute_harmonic_energy(
173 std::span<const double> data,
174 const size_t num_windows,
175 const uint32_t hop_size,
176 const uint32_t window_size);
177
178/**
179 * @brief Compute mean statistic using zero-copy processing
180 *
181 * This function computes the arithmetic mean for a given data span.
182 * It calculates the average value in each window.
183 *
184 * @param data Input data span
185 * @param num_windows Number of windows to process
186 * @param hop_size Hop size for windowing
187 * @param window_size Size of each window
188 * @return Vector of mean values
189 */
190std::vector<double> compute_mean_statistic(
191 std::span<const double> data,
192 const size_t num_windows,
193 const uint32_t hop_size,
194 const uint32_t window_size);
195
196/**
197 * @brief Compute variance statistic using zero-copy processing
198 *
199 * This function computes the variance for a given data span.
200 * It calculates the sample or population variance in each window.
201 *
202 * @param data Input data span
203 * @param num_windows Number of windows to process
204 * @param hop_size Hop size for windowing
205 * @param window_size Size of each window
206 * @param sample_variance If true, use sample variance (N-1), else population (N)
207 * @return Vector of variance values
208 */
209std::vector<double> compute_variance_statistic(
210 std::span<const double> data,
211 const size_t num_windows,
212 const uint32_t hop_size,
213 const uint32_t window_size,
214 bool sample_variance = true);
215
216/**
217 * @brief Compute standard deviation statistic using zero-copy processing
218 *
219 * This function computes the standard deviation for a given data span.
220 * It calculates the square root of variance in each window.
221 *
222 * @param data Input data span
223 * @param num_windows Number of windows to process
224 * @param hop_size Hop size for windowing
225 * @param window_size Size of each window
226 * @param sample_variance If true, use sample variance (N-1), else population (N)
227 * @return Vector of standard deviation values
228 */
229std::vector<double> compute_std_dev_statistic(
230 std::span<const double> data,
231 const size_t num_windows,
232 const uint32_t hop_size,
233 const uint32_t window_size,
234 bool sample_variance = true);
235
236/**
237 * @brief Compute skewness statistic using zero-copy processing
238 *
239 * This function computes the skewness (third moment) for a given data span.
240 * It measures the asymmetry of the distribution in each window.
241 *
242 * @param data Input data span
243 * @param num_windows Number of windows to process
244 * @param hop_size Hop size for windowing
245 * @param window_size Size of each window
246 * @return Vector of skewness values
247 */
248std::vector<double> compute_skewness_statistic(
249 std::span<const double> data,
250 const size_t num_windows,
251 const uint32_t hop_size,
252 const uint32_t window_size);
253
254/**
255 * @brief Compute kurtosis statistic using zero-copy processing
256 *
257 * This function computes the kurtosis (fourth moment) for a given data span.
258 * It measures the tail heaviness of the distribution in each window.
259 *
260 * @param data Input data span
261 * @param num_windows Number of windows to process
262 * @param hop_size Hop size for windowing
263 * @param window_size Size of each window
264 * @return Vector of kurtosis values (excess kurtosis, normal = 0)
265 */
266std::vector<double> compute_kurtosis_statistic(
267 std::span<const double> data,
268 const size_t num_windows,
269 const uint32_t hop_size,
270 const uint32_t window_size);
271
272/**
273 * @brief Compute median statistic using zero-copy processing
274 *
275 * This function computes the median (50th percentile) for a given data span.
276 * It finds the middle value in each window.
277 *
278 * @param data Input data span
279 * @param num_windows Number of windows to process
280 * @param hop_size Hop size for windowing
281 * @param window_size Size of each window
282 * @return Vector of median values
283 */
284std::vector<double> compute_median_statistic(
285 std::span<const double> data,
286 const size_t num_windows,
287 const uint32_t hop_size,
288 const uint32_t window_size);
289
290/**
291 * @brief Compute percentile statistic using zero-copy processing
292 *
293 * This function computes an arbitrary percentile for a given data span.
294 * It finds the specified percentile value in each window.
295 *
296 * @param data Input data span
297 * @param num_windows Number of windows to process
298 * @param hop_size Hop size for windowing
299 * @param window_size Size of each window
300 * @param percentile Percentile value (0-100)
301 * @return Vector of percentile values
302 */
303std::vector<double> compute_percentile_statistic(
304 std::span<const double> data,
305 const size_t num_windows,
306 const uint32_t hop_size,
307 const uint32_t window_size,
308 double percentile);
309
310/**
311 * @brief Compute entropy statistic using zero-copy processing
312 *
313 * This function computes the Shannon entropy for a given data span.
314 * It calculates information content based on value distribution in each window.
315 *
316 * @param data Input data span
317 * @param num_windows Number of windows to process
318 * @param hop_size Hop size for windowing
319 * @param window_size Size of each window
320 * @param num_bins Number of histogram bins (0 = auto-detect)
321 * @return Vector of entropy values
322 */
323std::vector<double> compute_entropy_statistic(
324 std::span<const double> data,
325 const size_t num_windows,
326 const uint32_t hop_size,
327 const uint32_t window_size,
328 size_t num_bins = 0);
329
330/**
331 * @brief Compute min statistic using zero-copy processing
332 */
333std::vector<double> compute_min_statistic(
334 std::span<const double> data,
335 const size_t num_windows,
336 const uint32_t hop_size,
337 const uint32_t window_size);
338
339/**
340 * @brief Compute max statistic using zero-copy processing
341 */
342std::vector<double> compute_max_statistic(
343 std::span<const double> data,
344 const size_t num_windows,
345 const uint32_t hop_size,
346 const uint32_t window_size);
347
348/**
349 * @brief Compute range statistic using zero-copy processing
350 */
351std::vector<double> compute_range_statistic(
352 std::span<const double> data,
353 const size_t num_windows,
354 const uint32_t hop_size,
355 const uint32_t window_size);
356
357/**
358 * @brief Compute sum statistic using zero-copy processing
359 */
360std::vector<double> compute_sum_statistic(
361 std::span<const double> data,
362 const size_t num_windows,
363 const uint32_t hop_size,
364 const uint32_t window_size);
365
366/**
367 * @brief Compute count statistic using zero-copy processing
368 */
369std::vector<double> compute_count_statistic(
370 std::span<const double> data,
371 const size_t num_windows,
372 const uint32_t hop_size,
373 const uint32_t window_size);
374
375/**
376 * @brief Compute MAD (Median Absolute Deviation) statistic using zero-copy processing
377 */
378std::vector<double> compute_mad_statistic(
379 std::span<const double> data,
380 const size_t num_windows,
381 const uint32_t hop_size,
382 const uint32_t window_size);
383
384/**
385 * @brief Compute CV (Coefficient of Variation) statistic using zero-copy processing
386 */
387std::vector<double> compute_cv_statistic(
388 std::span<const double> data,
389 const size_t num_windows,
390 const uint32_t hop_size,
391 const uint32_t window_size,
392 bool sample_variance = true);
393
394/**
395 * @brief Compute mode statistic using zero-copy processing
396 */
397std::vector<double> compute_mode_statistic(
398 std::span<const double> data,
399 const size_t num_windows,
400 const uint32_t hop_size,
401 const uint32_t window_size);
402
403/**
404 * @brief Compute z-score statistic using zero-copy processing
405 */
406std::vector<double> compute_zscore_statistic(
407 std::span<const double> data,
408 const size_t num_windows,
409 const uint32_t hop_size,
410 const uint32_t window_size,
411 bool sample_variance = true);
412}
std::vector< double > compute_zscore_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, bool sample_variance)
Compute z-score statistic using zero-copy processing.
std::vector< double > compute_entropy_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, size_t num_bins)
Compute entropy statistic using zero-copy processing.
std::vector< double > compute_skewness_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute skewness statistic using zero-copy processing.
std::vector< double > compute_dynamic_range_energy(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute dynamic range energy using zero-copy processing.
std::vector< double > compute_variance_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, bool sample_variance)
Compute variance statistic using zero-copy processing.
std::vector< double > compute_mad_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute MAD (Median Absolute Deviation) statistic using zero-copy processing.
std::vector< size_t > find_onset_positions(std::span< const double > data, uint32_t window_size, uint32_t hop_size, double threshold)
Find onset positions using spectral flux.
std::vector< double > compute_harmonic_energy(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute harmonic energy using low-frequency FFT analysis.
std::vector< double > compute_peak_energy(std::span< const double > data, const uint32_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute peak energy using zero-copy processing.
std::vector< double > compute_power_energy(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute power energy using zero-copy processing.
std::vector< double > compute_std_dev_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, bool sample_variance)
Compute standard deviation statistic using zero-copy processing.
std::vector< double > compute_sum_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute sum statistic using zero-copy processing.
std::vector< double > compute_percentile_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, double percentile)
Compute percentile statistic using zero-copy processing.
std::vector< size_t > find_peak_positions(std::span< const double > data, double threshold, size_t min_distance)
Find actual peak positions in the signal.
std::vector< double > compute_mode_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute mode statistic using zero-copy processing.
std::vector< double > compute_rms_energy(std::span< const double > data, const uint32_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute RMS energy using zero-copy processing.
std::vector< double > compute_min_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute min statistic using zero-copy processing.
std::vector< double > compute_mean_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute mean statistic using zero-copy processing.
std::vector< double > compute_range_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute range statistic using zero-copy processing.
std::vector< double > compute_zero_crossing_energy(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute zero-crossing energy using zero-copy processing.
std::vector< double > compute_cv_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size, bool sample_variance)
Compute CV (Coefficient of Variation) statistic using zero-copy processing.
std::vector< size_t > find_zero_crossing_positions(std::span< const double > data, double threshold)
Find actual zero-crossing positions in the signal.
std::vector< double > compute_median_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute median statistic using zero-copy processing.
std::vector< double > compute_spectral_energy(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute spectral energy using FFT-based analysis.
std::vector< double > compute_kurtosis_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute kurtosis statistic using zero-copy processing.
std::vector< double > compute_max_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute max statistic using zero-copy processing.
std::vector< double > compute_count_statistic(std::span< const double > data, const size_t num_windows, const uint32_t hop_size, const uint32_t window_size)
Compute count statistic using zero-copy processing.