Table of Contents

Pt1Filter

Namespace
ZCore
FUNCTION_BLOCK Pt1Filter

This function block provides a PT1 filter function. The filter is bason the on system step response, which inturn is the answer of a system to a step function (heaviside function). The mathematical model describes a setp response that follows an e-function characteristics. The output value increases to 63 percent of the input value within the time period t1 (time constant). The gain k is used to scale the output signal. For k=0.5 the filter will only reach half of the input signal. As the time constant t1 is increased, the filter gets "stronger and stronger", which means that the output reacts slower to changes of the input value. Please note, that the output of a PT1 filter is phase shifted to the input, which is not necessarily the case for a Lowpass filter.

The following code shows an example where a signal (constant value 5) is noisy (50Hz noise). Three distinct PT1 filters are applied to the signal.

// --- Declaration ----------------------------------------
pt1Filter1 : ZCore.Pt1Filter(cycletime:=0.001, k:=1, t1:=0.1);
pt1Filter2 : ZCore.Pt1Filter(cycletime:=0.001, k:=1, t1:=1.0);  
pt1Filter3 : ZCore.Pt1Filter(cycletime:=0.001, k:=1, t1:=2.0);  
signal, t : LREAL;
filtered1, filtered2, filtered3 : LREAL;

//--- Implementation --------------------------------------
signal := 5.0 + 0.1 * SIN(50.0 * 2.0 * PI * t);
t := t + 0.001;
pt1Filter1.Update(signal);
pt1Filter2.Update(signal);
pt1Filter3.Update(signal);
filtered1 := pt1Filter1.Output();
filtered2 := pt1Filter2.Output();
filtered3 := pt1Filter3.Output();

Constructor

FB_init

METHOD FB_init (
 [input] bInitRetains : BOOL,
 [input] bInCopyCode : BOOL,
 [input] cycletime : LREAL,
 [input] k : LREAL,
 [input] t1 : LREAL) : BOOL

The constructor of MovingAverageFilter is used to initialize the amount of values which this function block should Average over. For details see the description of MovingAverageFilter.

Inputs

bInitRetains BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

cycletime LREAL

cycletime in seconds, this should be set to the cycle time of the PLC and the cycle that Update is called with, respectively. If cycletime=0, the internal coefficients are set to 0

k LREAL

gain of the filter

t1 LREAL

time constant of the filter

Returns

BOOL

Methods

Output

METHOD Output () : LREAL

Returns the filtered value

Returns

LREAL

Reset

METHOD Reset (
 [input] value : LREAL)

Clears the internal value storage of the filter, resetting the filter to value

Inputs

value LREAL

Update

METHOD Update (
 [input] value : LREAL)

This method has to be called cyclically with the cycletime that has been set up during construction of the object.

Inputs

value LREAL