Peak Detection

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kunal.2904
Posts: 1
Joined: Mon Mar 05, 2018 10:27 pm

Peak Detection

Post by kunal.2904 » Mon Mar 05, 2018 10:42 pm

Due to unavailability of numpy and scipy libraries, I have developed a peak detection algorithm for micropython. The original python
implementation can be found here: https://gist.github.com/endolith/250860. The code can be improved further, but this is a good start.

#Peak Detection
def peakdet(v, delta, x = None):
maxtab = []
mintab = []

if x is None:
x = range(len(v))

mn, mx = float(100), float(-100)
mnpos, mxpos = 0, 0

lookformax = True

for i in range(len(v)):
this = v[i]
#print (type(this))
if this > mx:
mx = this
mxpos = x[i]
if this < mn:
mn = this
mnpos = x[i]

if lookformax:
if this < mx-delta:
maxtab.append((mxpos, mx))
mn = this
mnpos = x[i]
lookformax = False
else:
if this > mn+delta:
mintab.append((mnpos, mn))
mx = this
mxpos = x[i]
lookformax = True

return maxtab, mintab

Post Reply