Is there a similar function in Python that can do this?
As far as I know, there is no such function in Numpy / Scipy / Python. However, creating it is not so difficult. The general idea is this:
For the vector of values ββ(s):
- Find the location of the peaks (s). Let us call them (u)
- Find the location of the s depressions. Let us call them (l).
- Set the model to value pairs (u). Let me call him (u_p)
- Set the model to value pairs (1). Let me call him (l_p)
- Rate (u_p) over domain (s) to get interpolated upper shell values. (Let me call them (q_u))
- Rate (l_p) in domain (s) to get the interpolated values ββof the lower envelope. (Let me call them (q_l)).
As you can see, this is a sequence of three steps (find location, fit the model, evaluate the model), but it is applied twice, once for the upper part of the envelope and the other for the lower.
To collect the βpeaksβ (s), you need to find the points where the slope changes from positive to negative, and to collect the βpeaksβ (s) you need to find the points where the slope (s) changes from negative to positive.
Peak example: s = [4,5,4] 5-4 positive 4-5 negative
Gutter example: s = [5,4,5] 4-5 negative 5-4 positive
Here is an example script to get you started with a lot of inline comments:
from numpy import array, sign, zeros from scipy.interpolate import interp1d from matplotlib.pyplot import plot,show,hold,grid s = array([1,4,3,5,3,2,4,3,4,5,4,3,2,5,6,7,8,7,8])
This produces this conclusion:

Points for further improvement:
The code above does not filter peaks or troughs that may occur closer than some threshold βdistanceβ (Tl) (for example, time). This is similar to the second envelope parameter. It is easy to add if you analyze the differences between successive values u_x,u_y .
However, a quick improvement over the aforementioned point is a low-pass filter for your data with a moving average filter BEFORE interpolating the upper and lower envelope functions. You can do this easily by folding yours with a suitable moving average filter. Without going into details (you can do it if necessary) to create a moving average filter that works on N consecutive patterns, you would do something like this: s_filtered = numpy.convolve(s, numpy.ones((1,N))/float(N) . The higher (N) the more smooth the information will be displayed. Note that this will shift your (N / 2) values ββto the right (in s_filtered ) due to what is called group delay of the smoothing filter. For more information on the moving average, see this link .
Hope this helps.
(If you want more information about the original application, you can compensate for the answer. Perhaps the data can be pre-processed in a more appropriate way (?))