Digital Filter

This function digitally filters the input. The function block provides the following input pins x, Tau and ZeroInit. The output pin is y.

Ynew = Yold + (X -Yold)*(1-exp(-t/Tau))

Where, t = 1 second and Tau is in the range 0 to 65535 seconds.

The output can be initialized to zero (zeroInit=TRUE) or the first valid input value (zeroInit=FALSE).

From iteration to iteration, the Function Block keeps track of the tau multiplier (1-exp(-t/Tau). On power up/reset, this is recalculated.

Inputs

  Range    
Input Name Low High Input Value Description
x >=- infinity <+ infinity Unconnected Output is invalid.
      Invalid Output is set to invalid and filter reinitializes when the input returns to valid.

Output

Output Name Range Description
Y out Any floating point value Ynew = Yold +(X -Yold)*(1-exp(-t/Tau)).

Setpoints

Name Range/Value Description
tau 0 - 65535 seconds Configuration parameter.
zeroInit
  • 0
  • 1
  • Initializes filter value to first valid value
  • Initializes filter value to 0.0

Note: You can connect both Analog and Digital inputs as inputs to this function block.

Example 1: Set In1 (X) = 4, tau = 2.0, Set ZeroInit = 1 (initializes filter to 0.0)

Ynew = Yold +(X -Yold)*(1-exp(-t/Tau))

In the first iteration,

Yold = 0

Ynew = Yold + ( X - Yold) * (1 - exp (-t/tau))

Ynew = 0 + (4 - 0) * (1 - 2.718(-1/2))

Ynew = 0 + 4 * (0.393)

Ynew = 1.572

In the second iteration,

Yold = 1.572

X = 4

Ynew = 1.57 + (4 - 1.57) * (0.393)

Ynew = 2.52

In the third iteration,

Ynew = 2.52 + (4 - 2.52) * (0.393)

Ynew = 3.107

The iterations continue until the input is reached.

Example 2: Set In1 (X) = 4, tau = 2.0, Set ZeroInit = 0 (initializes filter to first valid value)

Ynew = Yold + (X -Yold) * (1-exp(-t/Tau))

In the first iteration,

Ynew = X

Ynew = 4

In the second iteration, if X = 6

Ynew = Yold + ( X - Yold) * (1 - exp (-t/tau))

Ynew = 4 + (6 - 4) * (0.393)

Ynew = 4 + 0.786

Ynew = 4.786

In the third iteration, if X = 6

Ynew = Yold + ( X - Yold) * (1 - exp (-t/tau))

Ynew = 4.786 + (6 - 4.786) * (0.393)

Ynew = 5.263

The iterations continue until the input is reached.