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, 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
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: |
|
|---|