top of page
Search

Practical use case: Low-pass filter

  • Writer: Ivaylo Fiziev
    Ivaylo Fiziev
  • 1 day ago
  • 2 min read

A low-pass filter is used to smooth a signal by allowing slow (low frequency) changes through, while filtering out fast noise or spikes and keeping real trends. On output what you get is a stable value that can be used for control decisions.


Typical applications are:

  1. Temperature sensors

  2. Analog inputs

  3. Flow or pressure signals

  4. PID feedback stabilizations

  5. Any noisy measurement in industrial environments


In Process Simulate this kind of filter can be implemented with a simple SCL script.

And here it is:

FUNCTION_BLOCK "LOW_PASS_FILTER"
VERSION:1.0
VAR_INPUT
	IN:LREAL; 	// Input value
	T:LREAL;		// Time factor
END_VAR
VAR_OUTPUT
	OUT:LREAL; 	// Output value
END_VAR
VAR
	INIT:BOOL;
END_VAR
BEGIN
	IF NOT #INIT THEN
		#OUT := #IN;
		#INIT := TRUE;
	ELSE
		#OUT := #OUT + (LOGIC_UPDATE_RATE() / #T) * (#IN - #OUT);
	END_IF;
END_FUNCTION_BLOCK

When the input is noisy the output is stable:


	IN: 	--------/\/\/\/\/\---------
 	OUT:	--------\________/---------

Import the script and call it like any other FB.

FUNCTION_BLOCK "MAIN"
VERSION:1.0
VAR_OUTPUT
	out : LREAL;
END_VAR
VAR_INPUT
	in : LREAL;
END_VAR
VAR
	filter : "LOW_PASS_FILTER";	// filter instance
END_VAR
BEGIN
	#filter(IN:=#in, T:=1000, OUT=>#out);
END_FUNCTION_BLOCK

This is the time dependent version of the filter which can be used with variable time steps. In Process Simulate we work with a fixed time step so a possible optimization could be to use a filtering factor (alpha) instead of the time factor (T). Just replace '(LOGIC_UPDATE_RATE() / #T)' with an input variable '#A' of type LREAL. In both cases the smaller this value is, the stronger the filtering will be!


For example:

0.1 - Strong filtering, slow response

0.8 - Weak filtering, fast response



 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Subscribe Form

Thanks for submitting!

bottom of page