Call: cross2(signal_y, signal_x, value, n_th=1, rising=True, falling=True)
Gives all crossing x-values and y-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. In difference to cross(), the return is a dataframe with x- and y-values of the crosspoints.
cross()
Return the x-value of the signal ‘v(inv_in)’ over ’time’ when it crosses 1V the second time.
cross2(
'v(inv_in)',
'time',
1
)

def cross2 (y,x, value, return_all='all'):
if isinstance(y, pd.DataFrame):
if len(y.columns)==2 and 'x' in y and 'y' in y:
x = y['x']
y = y['y']
y_minus_value = y - value
f = lambda x_new : np.interp(x_new, x, y_minus_value)
g = lambda x_new: np.interp(x_new, x, y)
initial_guess = x[sig_ch2(y_minus_value)]
# Finde die Nullstellen der Funktion
roots = fsolve(f, initial_guess)
roots = list(set(roots))
roots = sorted(roots, key=float)
values = [g(x) for x in roots]
# To Dataframe
d = {'x': roots, 'y': values}
# Wenn return_all False ist, gib nur den ersten Kreuzungspunkt zurück
# Ansonsten gib alle Kreuzungspunkte zurück
return pd.DataFrame(data=d)