amep.utils.envelope#

amep.utils.envelope(f: ndarray, x: ndarray | None = None) tuple[ndarray, ndarray]#

Calculates the envelope of the data f by determining all local peaks of the data.

Parameters:
  • f (np.ndarray) – Data values.

  • x (np.ndarray, optional) – x values (same shape as f). If not specified, x is just a list of of indices from 0 to len(f)-1. The default is None.

Returns:

  • np.ndarray – Envelope of f.

  • x (np.ndarray) – Corresponding x values (same shape as envelope.

Examples

>>> import amep
>>> import numpy as np
>>> x = np.linspace(0,10*np.pi,1000)
>>> y = np.sin(10*x) + np.sin(0.25*x)
>>> yenv, xenv = amep.utils.envelope(y, x=x)
>>> fig, axs = amep.plot.new()
>>> axs.plot(x, y, label='data')
>>> axs.plot(
...     xenv, yenv, label='envelope',
...     marker='', c='orange', lw=2
... )
>>> axs.legend()
>>> axs.set_xlabel(r'$x$')
>>> axs.set_ylabel(r'$y$')
>>> fig.savefig('./figures/utils/utils-envelope.png')
>>>
../_images/utils-envelope.png