pivots
# Routine to find pivots of degree k
def pivots(s, k):
'''Routine to find pivots of degree k in 1D numpy array'''
peaks = []
troughs = []
for i in range(k,len(s) - k):
#print (s[i], [s[j] for j in range(i-k,i+k+1)])
if max([s[j] for j in range(i-k,i+k+1)]) == s[i]:
peaks.append(i)
#print ('P', i)
elif min([s[j] for j in range(i-k,i+k+1)]) == s[i]:
troughs.append(i)
#print ('T', i)
return peaks, troughs
Definition 1: (Pivot of degree K) The time index t in a timeseries is an upper pivot or a peak of degree K,if for all j =1, 2,...,K, $x_t > x_t−j$ and $x_t > x_i+j$ . Similarly, t is a lower pivot or a trough of degree K,if for j =1, 2,...,K, $x_t < x_t−j$ and $x_t < x_t+j$ .