可以使用计算信封要么scipy.signal.hilbert
:
import numpy as np
from scipy import signal
# Add some padding to limit the periodic extension effect
padlen = int(np.floor(0.1*len(x)))
y = np.pad(x, (0,padlen), mode='edge');
# Compute the envelope
envelope = np.abs(signal.hilbert(y));
# Truncate to the original signal length
envelope = envelope[:-padlen]
或使用简单的diode detector实现:
def diode_detector(x,alpha):
xmax = abs(x[0])
y = np.array(x)
for i in np.arange(len(x)):
if (xmax < abs(x[i])):
xmax = abs(x[i])
else:
xmax = alpha*xmax
y[i] = xmax
return y
# you may need to tweak the alpha parameter depending on your signal bandwidth
envelope = diode_detector(x,0.9997)
然后,它只是计算的触发位置的问题:
T = t[1]-t[0]
print T*np.min(np.where(envelope < limit))
你的意思是你需要检测当一个本地峰值d没有超过阈值。您可以在反向时间进行分析,或者可以区分并仅在梯度为零的点处与阈值进行比较。 – barny