从不可逆函数中查找多个插值 x 值

Finding multiple interpolated x-values from a function that is not invertible

我正在尝试找到超过阈值的函数的两个插值 x 值。

我试过按照之前对类似问题的回答中的建议切换 x 和 y 值;但是,这只是 returns 我正在寻找的两个 x 值之一,因为这些值在反转时具有相同的 x 坐标。

.

每张图上的红点表示我已经使用以下代码定位的点:

interp = interp1d(data[1], data.times)
val = interp(great.middle.iloc[1])

其中数据是一个 pandas 数据框,其中包含所有事件(因此我们在这里查看事件 1)和一个时间列,很棒的是另一个 pandas 数据框,其中中间value 是事件列中的最大值除以 2。这里的 val 等于 42.28045192307682,这是达到中间值(第二次)的插值时间。

我尝试缩小插值函数的值,但 y 值的插值总是导致 Nan x 值。

我使用的数据有点大,但这里是电压和时间的输出: https://drive.google.com/open?id=16xPB5HU_ZJ4qmIdD8icKrDKAAXAO2lH7 https://drive.google.com/open?id=1Yc-_ole-dFAnpTNJhEjKNYU6hQfCSiar

这是我解决这个问题的方法:

#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)