19 Find peaks in a list of data points by looking for the peak within a window
21 This algorithm will ignore subpeaks that are close to the main peak
22 (assuming e.g. that they are noise)
24 def __init__(self, window_size, threshold_over_mean, window_step):
26 Initialise the peak finder
27 - window_size integer size of the window over which we look for peaks.
28 - threshold_over_mean float, require the peak to be greater than a
29 multiple of the data mean within the window to be registered
30 - window_step float, move the window by window_step on each iteration
38 Find peaks in the data
40 - data list of floats that contains data within which we seek to find
43 Makes a window and looks for the highest value within that window. If
44 the highest value is at the boundary of the window, it is ignored; else
45 the peak is saved. The index corresponding to window start is then
46 incremented by one and the routine is repeated.
48 uses window_size that is the smallest of self.window_size and len(data)
50 Returns a list of indices, each index corresponding to the location of a
56 window_size = len(data)
57 win_sz_float = float(window_size)
58 for i
in range(0, len(data)-window_size+1, self.
window_step):
61 test = data[i:i+window_size]
63 max_index = test.index(max_value)
64 if (i != 0
and max_index == 0)
or \
65 (i != len(data)-window_size
and \
66 max_index == window_size-1):
70 if max_index
not in peaks:
72 peaks.append(max_index)
74 mean = sum(test)/win_sz_float
75 sigma = (sum([x**2
for x
in test])-mean**2)**0.5\
78 peaks.append(max_index)
def find_peaks
Find peaks in the data.
def __init__
Initialise the peak finder.
Find peaks in a list of data points by looking for the peak within a window.