cross2()

Expression: Give the x-values and y-values of specific y-values

Call: cross2(signal_y, signal_x, value, n_th=1, rising=True, falling=True)

Description

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.

IO

  • Input
    • signal_y: name of y-signal
    • signal_x: name of x-signal (usually ’time')
    • value: crossing value
    • return_all:
      • False: Return only first crossingpoint
      • True: Return all crossingpoints
  • Output
    • Dataframe with columns ‘x’ and ‘y’ with both containing the x- and y-value of the crossing.

See also

cross()

Example

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
)

Example Picture cross2

Code

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)