37 lines
877 B
Python
Executable File
37 lines
877 B
Python
Executable File
"""
|
|
Multi-peak search
|
|
"""
|
|
|
|
from mathutils import estimate_peak_indexes, fit_gaussians
|
|
|
|
start = 0
|
|
end = 5
|
|
step_size = 0.1
|
|
|
|
result= lscan(inp,sin,start,end,[step_size,],0.1)
|
|
|
|
readable = result.getReadable(0)
|
|
positions = result.getPositions(0)
|
|
|
|
threshold = (min(readable) + max(readable))/2
|
|
min_peak_distance = 0.5
|
|
|
|
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
|
|
print peaks
|
|
|
|
gaussians = fit_gaussians(readable, positions, peaks)
|
|
|
|
plots = plot([readable],["sin"],[positions] , title="Data")
|
|
for i in range(len(peaks)):
|
|
peak = peaks[i]
|
|
(norm, mean, sigma) = gaussians[i]
|
|
if abs(mean - positions[peak]) < min_peak_distance:
|
|
print "Peak -> " + str(mean)
|
|
plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None)
|
|
else:
|
|
print "Invalid gaussian fit: " + str(mean)
|
|
|
|
|
|
|
|
|