我正在尝试找到函数的两个内插x值,该值在超过阈值的地方找到。
我已经尝试按照先前答案中的建议将x和y值切换为类似问题;但是,由于反转时这些值具有相同的x坐标,因此它仅返回我要查找的两个x值之一。
每个图形上的红色点显示了我已经通过以下代码找到的点:
interp = interp1d(data[1], data.times)
val = interp(great.middle.iloc[1])
其中数据是一个包含所有事件的熊猫数据框(因此这里我们看事件1)和一个时间列,而great是另一个熊猫数据框,其中中间值是事件列中的最大值乘以2。这里val等于42.28045192307682,它是达到中间值(第二次)的插值时间。
我曾尝试缩小插值函数的值,但是y值的插值总是导致Nan的x值。
我正在使用的数据很大,但这是电压和时间的输出: https://drive.google.com/open?id=16xPB5HU_ZJ4qmIdD8icKrDKAAXAO2lH7 https://drive.google.com/open?id=1Yc-_ole-dFAnpTNJhEjKNYU6hQfCSiar
答案 0 :(得分:0)
这是我解决此问题的方法:
#save the event data column as pulse (y-values)
pulse = data[1]
#save the time data as time (x-values)
times = data.times
#resample the zero points of the data (the data - the threshold)
spulse = signal.resample(pulse - np.max(pulse)/2., 10*len(pulse))
#find the place where the data changes signs
crossings = np.where(np.diff(np.sign(spulse)))[0]
#because the data has noise, average the first and second crossings
first = np.mean(crossings[crossings < np.argmax(spulse)])/1000
second = np.mean(crossings[crossings > np.argmax(spulse)])/1000
#print the times that the threshold was crossed
print "First crossing at: " + str(first) + ", Second at: " + str(second)