torch_ecg.utils.find_extrema

torch_ecg.utils.find_extrema(signal: ndarray | Sequence, mode: str = 'both') ndarray[source]

Locate local extrema points in a 1D signal.

This function is based on Fermat’s Theorem.

Parameters:
  • signal (array_like) – 1D input signal.

  • mode ({"max", "min", "both"}, optional) – Whether to find maxima (“max”), minima (“min”), or both (“both”), by default “both”, case insensitive.

Returns:

extrema – Indices of the extrama points.

Return type:

numpy.ndarray

Examples

>>> x = np.linspace(0, 2 * np.pi, 100)
>>> y = np.sin(x)
>>> find_extrema(y, mode="max")
array([25])
>>> find_extrema(y, mode="min")
array([74])
>>> find_extrema(y, mode="both")
array([25, 74])