Skip to content

[BUG] Incorrect computation of unsigned AUC (absolute area under the curve) #180

@dmfolgado

Description

@dmfolgado

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions