import arrlib as arr
def peaks(v,b,c,d,t):
#---------------------------------------------------------------------------------
# v - a list or tuple with values;
# b - smoothbase
# c - smoothcount;
# d - order of differentiation
# t - threshold for peak detection
# returns a list of tuples - [(pos,val)...]
#--------------------------------------------------------------------------------
L=len(v)
w=arr.floatVec(L);
for i in range(L): w[i]=v[i]
p=arr.xyfVec(L)
p.setLength(0)
w,h,s=arr.smooDiff(w,b,c,d)
arr.findPeaks(w,t,p)
return [(x[0]+h,x[1]/s) for x in p if x[1]>0]
Example 1: Locate peaks in a list
from math import *
v=[sin(i/4.0) for i in range(50)]
base=2
count=1
diff=0
thresh=0.5
print peaks(v,base,count,diff,thresh)
|