savgol()

Expression: Rolling mean of a signal using the Savitzky-Golay filter.

Call: savgol(y, x,window, order=3)

Description

Returns the rolling average of windows values of a signal ‘y’ over ‘x’. It uses the function scipy.signal.savgol_filter().

IO

  • Input

    • y: name of y-signal
    • x: name of x-signal
    • window: count of averaging values.
    • order: The order of the polynomial used to fit the samples. Must be less than window (default = 3)
  • Output

    • Dataframe with columns ‘x’ and ‘y’ with both containing rolling_average

See also

rolling_average() rolling-average_df()

Example

Return the rolling average of 1000 values of the signal ‘v(inv_in)’ over ’time’. Use a 3rd order polygon

savgol(
	'v(inv_in)',
	'time',
	1000,
	3
)

Example Picture savgol

Code

def savgol(*args):
    # Erstellt einen neuen DataFrame df_out, der den Savitzky-Golay-gefilterten Werten der Spalte 'y' enthält
    if len(args) == 4:
        x = process_operator(args[1])
        y = process_operator(args[0])
        window = args[2]
        order = args[3]
    elif len(args) == 3:
        if isinstance(args[0], pd.DataFrame):
            x = args[0]['x']
            y = args[0]['y']
            window = args[1]
            order = args[2]
    if window % 2 == 0:
        window +=1
    df_out = pd.DataFrame()
    df_out['x'] = x
    df_out['y'] = savgol_filter(y, window, order)
    return df_out