-
Notifications
You must be signed in to change notification settings - Fork 154
Description
The current implementation of the auc feature applies the absolute value after summing consecutive samples:
np.sum(0.5 * np.diff(t) * np.abs(np.array(signal[:-1]) + np.array(signal[1:])))
This effectively computes (abs(y_i + y_{i+1}) / 2) * Δt, which is not equivalent to the correct trapezoidal rule for the unsigned area ( (abs(y_i) + abs(y_{i+1})) / 2 ) * Δt.
When the signal crosses zero, the current implementation underestimates the area. For example, for a 1 Hz signal = [3, -3], the current implementation gives 0.0 instead of the correct 3.0.
The unsigned AUC should integrate the absolute value of each sample, not the absolute value of their sum. We should replace the current implementation by the SciPy trapezoidal rule implementation, which is also faster.