Ladder logic 402: Data manipulation and filtering

Once values from an analog card have been captured, there are methods to filter the data and methods to simulate a filter using Microsoft Excel before it is coded into a PLC.

03/29/2016


The prior post on ladder logic discussed using a programmable logic controller (PLC) to capture values from an analog card. Once those values have been captured, there are methods to filter the data and methods to simulate a filter using Microsoft Excel before it is coded into a PLC. There are several filtering algorithms that can be found on the Internet currently being used on a PLC (see links below). For the formulas, the same variable names were used even though they differed extensively in the various posts:

N = New value calculated and substituted for the input value. In other words, the calculated filtered value.

L = The previous captured input value.

F = The previous calculated filtered value.

k = The manipulated factor for all calculations (sometimes known as Alpha).

i = The current analog input value.

Avg = A running average over x number of previous samples, (3 for x was used in this example.)

The formula for a first order filter is New Filtered = Last Filtered + Factor * (Input - Last Filtered).

This equates to N=F+k(i-F) according to the variables listed above. The actual formula uses Alpha instead of k. Results from this formula are listed as Formula 6 below in the simulation.

To simulate a signal analog values were listed in one column on an Excel spreadsheet. These values are typical for a 13-bit signed analog signal from a PLC card; notice that they increment or decrement by a factor of eight. This would mean that on a 0 to 10v or 0 to 20mA signal with a range of 0-32,767, there would be 4096 possible values for the signal. The other half of the range, -32768 to -1, is not obtainable from the field device.

Simulation of a signal with listed some analog values in one column on a Microsoft Excel spreadsheet. These values are typical for a 13 bit signed analog signal from a PLC card; notice that they increment or decrement by a factor of eight. Courtesy: Frank

The first column shown above are the input values. The value of 20168 simulates a big noise spike that the user might want to filter for. The following columns show results after using the various filtering formulas found. The reason the input column has earlier values in it is to ptovide a running average of up to five values in the formulas. Formula 6 (shown below) also needs to use the previous filtered value, so that's why it has an extra value in it also.

This is a key with the variables listed and the formulas. The k values are linked to cells used in the table, so they can be changed as needed. Courtesy: Frank Lamb, Automation Primer

This is a key with the variables listed and the formulas. The k values are linked to cells used in the table.

Formulas 1 to 3 in graph form after they have been computed. Courtesy: Frank Lamb, Automation Primer

Formulas 4 to 6 in graph form after they have been computed. Courtesy: Frank Lamb, Automation Primer

Formula 1 actually looks like it makes the signal worse. Formula 2 and Formula 4 did nearly the same things; in the instructions Formula 2 was "k=1.0, no filtering, k=0, output freezes." Formula 4′s instructions said "k=1.0, no filtering, 2.0, 4.0 and 8.0 give increasing amounts of filtering with more dampening, but more delay."

Formula 3 is a straight running average, and seems to actually work pretty well. The current and previous values were used for an average of three; when using more there was more lag. Formula 5 also uses a running average. Three samples were used in the average also even though the intent was to use four or five. When four or five were used, the delayed reaction (lag) got worse.

The formal definition of a first order filter is represented by Formula 6. Sometimes this is known as a first derivative filter; if the points are equated to position, this would represent a velocity based filter. A second order filter would then represent Accel/Decel and a third order filter would represent "jerk."

The filters would work off of the delta between the current and previous values. Simulating formulas can be done very easily in Microsoft Excel, but the user may want to check things out before coding it into the PLC as illustrated by Formula 1.

Putting a formula into PLC form will vary a lot between platforms. In ladder logic, a "calculate" type command lets the user type the formula in directly, though you may still need to use first in, first out (FIFOs) instructions, especially when averaging.

Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Chris Vavra, production editor, Control Engineering, CFE Media, cvavra@cfemedia.com.

ONLINE extra

For more articles on PLCs and programming, see related articles below.



The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Women in engineering; Engineering Leaders Under 40; PID benefits and drawbacks; Ladder logic; Cloud computing
Robotic integration and cloud connections; SCADA and cybersecurity; Motor efficiency standards; Open- and closed-loop control; Augmented reality
Controller programming; Safety networks; Enclosure design; Power quality; Safety integrity levels; Increasing process efficiency
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

Cloud, mobility, and remote operations; SCADA and contextual mobility; Custom UPS empowering a secure pipeline
Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Women in engineering; Engineering Leaders Under 40; PID benefits and drawbacks; Ladder logic; Cloud computing
Robotic integration and cloud connections; SCADA and cybersecurity; Motor efficiency standards; Open- and closed-loop control; Augmented reality
Controller programming; Safety networks; Enclosure design; Power quality; Safety integrity levels; Increasing process efficiency
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

Cloud, mobility, and remote operations; SCADA and contextual mobility; Custom UPS empowering a secure pipeline
Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Women in engineering; Engineering Leaders Under 40; PID benefits and drawbacks; Ladder logic; Cloud computing
Robotic integration and cloud connections; SCADA and cybersecurity; Motor efficiency standards; Open- and closed-loop control; Augmented reality
Controller programming; Safety networks; Enclosure design; Power quality; Safety integrity levels; Increasing process efficiency
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

Cloud, mobility, and remote operations; SCADA and contextual mobility; Custom UPS empowering a secure pipeline
Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
click me