Call: cross(signal_y, signal_x, value, n_th=1, rising=True, falling=True)
Gives all crossing x-values of a signal crossing a value. It generates a new dataframe with signal_y - value. Then it solves the functions to find the roots of this new dataframe.
cross2()
Return the x-value of the signal ‘v(inv_in)’ over ’time’ when it crosses 1V the second time.
cross(
'v(inv_in)',
'time',
1,
2
)

def cross(y, x, value, n_th=1, rising=True, falling=True):
if n_th == 0:
n_th =1
y_minus_value = y - value
# Erstelle eine Interpolationsfunktion
f = lambda x_new : np.interp(x_new, x, y_minus_value)
initial_guess = []
for i in range(len(x)-1):
if sig_ch(y_minus_value[i], y_minus_value[i+1], rising, falling):
initial_guess.append(x[i])
# Finde die Nullstellen der Funktion
initial_guess = initial_guess [0:n_th+5]
roots = fsolve(f,initial_guess)
# To Dataframe
if len(roots)<n_th:
root = roots[-1]
else:
root = roots[n_th-1]
d = {'x':[root], 'y':[root]}
# Wenn return_all False ist, gib nur den ersten Kreuzungspunkt zurück
# Ansonsten gib alle Kreuzungspunkte zurück
return pd.DataFrame(data=d)