我正在尝试在收集信号的全局峰值和谷值的地方实现峰值检测,但是,当我将其实现为一个简单的信号时,该功能可以完美运行,没有错误。但是,当我将代码运行到大量数据集(大约 9000 个样本)中时,它一直给我这个错误:
TypeError: only integer scalar arrays can be converted to a scalar index
我的峰值检测功能可以在下面找到:
def custom_peakdetection_envelope(y_axis, peak_height, x_axis=None):
"""
keyword arguments:
y_axis -- A list containing the signal over which to find peaks
x_axis -- (optional) A x-axis whose values correspond to the 'y_axis' list and is used in the return to specify the position of the peaks. If omitted the index of the y_axis is used. (default: None)
peak_height -- This specifies a minimum height of the peak
return -- two lists [maxtab, mintab] containing the positive and negative peaks respectively. Each cell of the lists contains a tuple of:
(position, peak_value) to get the average peak value do 'np.mean(maxtab, 0)[1]' on the results
"""
global amplitude_envelope_y
global amplitude_envelope_x
maxtab = []
mintab = []
maxthresh = []
minthresh = []
ax = []
amplitude_envelope_mx = []
amplitude_envelope_mn = []
if x_axis is None:
x = arange(len(y_axis))
else:
x = asarray(x_axis)
y = asarray(y_axis)
ax.append((x,y))
if len(y) != len(x):
sys.exit('Input vectors y and x must have same length')
if not isscalar(peak_height):
sys.exit('Input argument peak_height must be a scalar')
# if peak_height <= 0:
# sys.exit('Input argument peak_height must be positive')
# maxima and minima candidates are temporarily stored in mx and mn respectively:
mn, mx = np.Inf, -np.Inf
mnpos, mxpos = NaN, NaN
冉冉说
相关分类