detect_peaks#

pyCGM2.Signal.detector.detect_peaks(x, mph=None, mpd=1, threshold=0, edge='rising', kpsh=False, valley=False, show=False, ax=None, title=True)#

Detects peaks in data based on their amplitude and other features.

Parameters:
  • x (np.ndarray) – Data to analyze.

  • mph (float, optional) – Detect peaks that are greater than minimum peak height or valleys smaller than maximum peak height if valley is True. Default is None.

  • mpd (int, optional) – Minimum number of data points separating peaks. Default is 1.

  • threshold (float, optional) – Detect peaks that are greater than the threshold in relation to their neighbors. Default is 0.

  • edge (str, optional) – For a flat peak, keep only the specified edges. Options are ‘rising’, ‘falling’, ‘both’, or None. Default is ‘rising’.

  • kpsh (bool, optional) – Keep peaks with the same height even if they are closer than mpd. Default is False.

  • valley (bool, optional) – If True, detect valleys instead of peaks. Default is False.

  • show (bool, optional) – If True, plot data using matplotlib. Default is False.

  • ax (plt.Axes, optional) – Matplotlib Axes instance for plotting. Default is None.

  • title (bool or str, optional) – Show standard title, custom title, or no title in the plot. Default is True.

Returns:

np.ndarray – Indices of the detected peaks in x.

Notes

  • The detection of valleys is done by negating the data: ind_valleys = detect_peaks(-x).

  • The function can handle NaN values.

  • See the IPython Notebook for more information.

References

Examples

>>> x = np.random.randn(100)
>>> # various examples using the function with different parameters
Version history:
  • ‘1.0.7’: Part of the detecta module - [Detecta PyPI](https://pypi.org/project/detecta/)

  • ‘1.0.6’: Fixes and new features regarding ax object and title parameter.

  • ‘1.0.5’: Inversion of mph sign based on valley parameter.