0

I am trying to find two interpolated x-values of a function found where a threshold is crossed.

here

I have tried switching the x and y values as proposed in previous answers to similar questions; however, this only returns one of the two x-values I am looking for due to the values having the same x-coordinate when inverted.

Inverted Graph.

The red point on each graph shows the point I've already located with the following code:

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

Where data is a pandas data frame that contains all the events (so here we are looking at event 1) and a single time column and great is another pandas data frame where the middle value is the greatest value in the event column divided by 2. Here val is equal to 42.28045192307682 which is the interpolated time at which the middle value is reached (for the second time).

I have tried narrowing the the values for the interpolation function, but the interpolation of a y- value always results in Nan x-values.

The data that I am using is kind of large but here is an output for a voltage and time: https://drive.google.com/open?id=16xPB5HU_ZJ4qmIdD8icKrDKAAXAO2lH7 https://drive.google.com/open?id=1Yc-_ole-dFAnpTNJhEjKNYU6hQfCSiar

Erica
  • 1
  • 2
  • You really need to post the code and maybe some sample data you are using. – Stephen Rauch May 29 '19 at 02:02
  • @StephenRauch I updated the question so hopefully it is a little more helpful! I really don't have any other code to post when it comes to the interpolation. – Erica May 29 '19 at 02:18
  • Use this to find the zero crossings: https://stackoverflow.com/questions/23289976/how-to-find-zero-crossings-with-hysteresis Then narrow the interp to those ranges of crossings. – Stephen Rauch May 29 '19 at 02:20

1 Answers1

0

Here's how I solved this:

#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))
Oren
  • 4,711
  • 4
  • 37
  • 63
Erica
  • 1
  • 2