In [7]:
import numpy
import peakutils
from peakutils.plot import plot as pplot
from matplotlib import pyplot
%matplotlib inline
In [2]:
centers = (30.5, 72.3)
x = numpy.linspace(0, 120, 121)
y = peakutils.gaussian(x, 5, centers[0], 3) + peakutils.gaussian(x, 7, centers[1], 10) + numpy.random.rand(x.size)
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y)
pyplot.title("Data with noise")
Out[2]:
In [8]:
indexes = peakutils.indexes(y, thres=0.5, min_dist=30)
print(indexes)
print(x[indexes], y[indexes])
pyplot.figure(figsize=(10,6))
pplot(x, y, indexes)
pyplot.title('First estimate')
Out[8]:
In [9]:
peaks_x = peakutils.interpolate(x, y, ind=indexes)
print(peaks_x)
In [10]:
y2 = y + numpy.polyval([0.002,-0.08,5], x)
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y2)
pyplot.title("Data with baseline")
Out[10]:
In [11]:
base = peakutils.baseline(y2, 2)
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y2-base)
pyplot.title("Data with baseline removed")
Out[11]:
In [ ]: