(* @NESTEDCOMMENTS := 'Yes' *) (* @PATH := '' *) (* @OBJECTFLAGS := '0, 8' *) (* @SYMFILEFLAGS := '2048' *) FUNCTION_BLOCK FB_EWMA VAR_INPUT IN_rN : REAL := 15; (* Filter constant alpha := rN/(rN+1) *) IN_rXk : REAL; (* Input value to smooth *) END_VAR VAR_OUTPUT OUT_rXk_avg : REAL; (* smoothed output *) END_VAR VAR rAlpha : REAL; rXk_avg_old : REAL; END_VAR (* Exponentially Weighted Moving Average Filter Author: mo Date: 2019-02 Filter constant: alpha := n / (n+1) EWMA Filter: Xk_avg := alpha*Xk_prev + (1-alpha)*Xk *) (* @END_DECLARATION := '0' *) rAlpha := IN_rN/(IN_rN+1); OUT_rXk_avg := rAlpha * rXk_avg_old + ( (1 - rAlpha) * IN_rXk); rXk_avg_old := OUT_rXk_avg; END_FUNCTION_BLOCK