cross()

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

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

Description

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.

IO

  • Input
    • signal_y: name of y-signal
    • signal_x: name of x-signal (usually ’time')
    • value: crossing value
    • n_th [optional]: the n_th crossing point (default: 1 –> returns the first crossing)
    • rising [optional]: crossing the value on the rising etch (default: True)
    • falling [optional]: crossing the value on the rising etch (default: True
  • Output
    • Dataframe with columns ‘x’ and ‘y’ with both containing the x-value of the crossing.

See also

cross2()

Example

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
)

Example Picture value

Code

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)