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:
Name | Type | Description | Default |
---|---|---|---|
sig
|
ndarray
|
Signal array of shape (n_samples, n_channels). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Centered signal with same shape as input. |
Source code in pyeyesweb/utils/math_utils.py
compute_jerk_rms(signal, rate_hz=50.0)
Compute RMS of jerk (third derivative) from a signal.
Jerk is the rate of change of acceleration. Lower RMS jerk values indicate smoother movement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal
|
ndarray
|
1D movement signal (position or velocity). |
required |
rate_hz
|
float
|
Sampling rate in Hz (default: 50.0). |
50.0
|
Returns:
Type | Description |
---|---|
float
|
Root mean square of jerk. Returns NaN if signal has less than 2 samples. |
Notes
This implementation uses first-order finite differences to approximate the derivative. For position signals, this computes jerk directly.
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:
Name | Type | Description | Default |
---|---|---|---|
phase1
|
ndarray
|
Phase values of first signal in radians. |
required |
phase2
|
ndarray
|
Phase values of second signal in radians. |
required |
Returns:
Type | Description |
---|---|
float
|
Phase Locking Value between 0 and 1. |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal
|
ndarray
|
1D movement signal. |
required |
rate_hz
|
float
|
Sampling rate in Hz (default: 50.0). |
50.0
|
Returns:
Type | Description |
---|---|
float
|
SPARC value (negative, more negative = smoother). Returns NaN if signal has less than 2 samples. |
References
Balasubramanian et al. (2015). On the analysis of movement smoothness from the Journal of NeuroEngineering and Rehabilitation.
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:
Name | Type | Description | Default |
---|---|---|---|
signal
|
ndarray
|
Input signal to normalize. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Normalized signal with same shape as input. Returns original signal if max absolute value is 0. |