rolling_mean()

Expression: Rolling mean of a signal

Call:
	rolling_mean(y, x, nvalues)
or
	rolling_mean(df, nvalues)

Description

Returns the rolling average of nvalues values of a signal y over x. x and y can also be replaced by a DataFrame (output of another expression).

IO

  • Input
    • y: name of y-signal
    • x: name of x-signal (usually ’time')
    • df: Dataframe with columns ‘x’ and ‘y’ that contains a signal
    • nvalues: count of averaging values
  • Output
    • Dataframe with columns ‘x’ and ‘y’ with both containing rolling_average

See also

savgol()

Example

Return the rolling average of 300 values of the signal ‘v(inv_in)’ over ’time’.

rolling_average(
	'v(inv_in)',
	'time',
	1000
)

Example Picture rolling_mean

Code

def rolling_mean(*args):#y, x, nvalues):
    # Erstellt einen neuen DataFrame df_out, der den rollenden Mittelwert der Spalte 'y' enthält
    if len (args) == 3:
        x = process_operator(args[1])
        y = process_operator(args[0])
        nvalues=args[2]
    elif len(args) == 2:
        if isinstance(args[0], pd.DataFrame):
            x = args[0]['x']
            y = args[0]['y']
            nvalues=args[1]
    else:
        return pd.DataFrame()
    df_out = pd.DataFrame()
    df_out['x'] = x
    df_out['y'] = y.rolling(window=nvalues).mean()
    return df_out