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_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_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_sparc(signal, rate_hz=50.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
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: |
|
|---|