Math Utils
Mathematical utility functions for signal analysis.
This module provides mathematical functions used throughout the PyEyesWeb library for signal processing, phase analysis, and movement metrics.
center_signals(sig)
Remove the mean from each signal to center the data.
Centers signals by subtracting the mean, removing DC bias.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in pyeyesweb/utils/math_utils.py
compute_eyesweb_smoothness_and_fluidity(positions, dt, epsilon=1e-06)
Calcola la Smoothness e la Fluidity del movimento secondo il modello descritto
nel paper "Adaptive Body Gesture Representation for Automatic Emotion Recognition"
Parameters:
positions : np.ndarray Matrice delle posizioni nel tempo con forma (N, 3) o (N, 2), dove N è il numero di campioni temporali. dt : float Intervallo di campionamento temporale tra due frame successivi (in secondi). epsilon : float Valore di tolleranza per evitare divisioni per zero.
Returns:
dict Dizionario contenente: - 'smoothness': Coefficente di correlazione r tra log(curvatura) e log(velocità). - 'fluidity': Grado di aderenza al modello minimum jerk (0 = non fluido, 1 = ideale). - 'curvature': Serie temporale della curvatura. - 'speed': Serie temporale della velocità tangenziale.
Source code in pyeyesweb/utils/math_utils.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
compute_harmonicity_index(signal, rate_hz=100.0)
Calcola l'Harmonicity Index (H) dal profilo di velocità/accelerazione.
Un valore H vicina a 1 indica un moto armonico pulito (es. sottomovimento singolo), valori vicini a 0 indicano molteplici sub-inversioni/sub-picchi.
Source code in pyeyesweb/utils/math_utils.py
compute_jerk_rms(signal, rate_hz=50.0, signal_type='velocity')
Compute RMS of jerk (rate of change of acceleration) from a signal.
Jerk is the third derivative of position or the first derivative of acceleration. Lower RMS jerk values indicate smoother movement.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Uses numpy.gradient for smooth derivative approximation with central differences where possible, providing better accuracy than forward differences.
Source code in pyeyesweb/utils/math_utils.py
compute_ldlj(signal, rate_hz, signal_type='velocity')
Calculates the Log Dimensionless Jerk (LDLJ) based on Balasubramanian (2012) and Melendez-Calderon (2021).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in pyeyesweb/utils/math_utils.py
compute_phase_locking_value(phase1, phase2)
Compute the Phase Locking Value (PLV) from two phase arrays.
PLV measures the inter-trial variability of the phase difference between two signals. A value of 1 indicates perfect phase locking, while 0 indicates no phase relationship.
| Parameters: |
|
|---|
| Returns: |
|
|---|
References
Lachaux et al. (1999). Measuring phase synchrony in brain signals.
Source code in pyeyesweb/utils/math_utils.py
compute_sample_entropy(signal, m=2, r_factor=0.2)
Calcola la Sample Entropy (SampEn) di una serie temporale 1D.
| Parameters: |
|
|---|
Source code in pyeyesweb/utils/math_utils.py
compute_sparc(signal, rate_hz=50.0, amplitude_threshold=0.05, min_fc=2.0, max_fc=20.0)
Compute SPARC (Spectral Arc Length) from a signal.
SPARC is a dimensionless smoothness metric that quantifies movement smoothness independent of movement amplitude and duration. More negative values indicate smoother movement.
This implementation is based on the original algorithm by Balasubramanian et al. (2015). SPARC values are typically negative, with values closer to 0 indicating less smooth (more complex) movements. For healthy reaching movements, values around -1.4 to -1.6 are common. Pathological or very unsmooth movements may have values ranging from -3 to -10 or lower, depending on the degree of movement fragmentation.
| Parameters: |
|
|---|
| Returns: |
|
|---|
References
Balasubramanian, S., Melendez-Calderon, A., Roby-Brami, A., & Burdet, E. (2015). On the analysis of movement smoothness. Journal of NeuroEngineering and Rehabilitation, 12(1), 1-11.
Source code in pyeyesweb/utils/math_utils.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
compute_submovement_count(signal, rate_hz=100.0, prominence_factor=0.1)
Stima il numero di sottomovimenti contando i picchi di velocità significativi.
| Parameters: |
|
|---|
Source code in pyeyesweb/utils/math_utils.py
extract_velocity_from_position(position, rate_hz=50.0)
Extract velocity from position data.
Computes velocity magnitude from position data of any dimensionality. For 1D position, returns absolute velocity. For multi-dimensional position, returns the Euclidean norm of the velocity vector.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Examples:
>>> # 1D position data
>>> position_1d = np.array([0, 1, 2, 3, 4])
>>> velocity = extract_velocity_from_position(position_1d, rate_hz=100)
>>> # 2D position data (x, y coordinates)
>>> position_2d = np.array([[0, 0], [1, 0], [1, 1], [2, 1]])
>>> velocity = extract_velocity_from_position(position_2d, rate_hz=100)
Source code in pyeyesweb/utils/math_utils.py
normalize_signal(signal)
Normalize signal by its maximum absolute value.
Scales the signal to the range [-1, 1] by dividing by the maximum absolute value.
| Parameters: |
|
|---|
| Returns: |
|
|---|