Averaging

Deanney

Member
Join Date
Dec 2007
Location
Cincinnati
Posts
1
I have an analog input (air transducer) that isn't real steady. How would I average the input to smooth the display? My analog in is 0 -32000 (real 0 -145PSI). When the air pressure is present (say 60PSI) I have a display of 60 then it will jump to 64 or 69 then 61 or so and on occasion 59. I do not need super accuracy but something a little more steady. Thanks in advance.
Deanney
 
If I have lots of PLC resources available, such that I can use floating point math without concern, I like the following low pass filter:

FV = FV + FF(NR-FV)

where:
FV is the filtered value
FF is an arbitrary 'filter factor', between 0 and 1
NR is the newest reading taken

If FF is 1, no filtering takes place.
As FF approaches 0, the input is filtered more and more at the expense of response time.

This is real easy in an A/B PLC that has a CPT instruction.

Edit: It also works on non-floating point values, but takes a little more effort. (Turn the multiplication into a division by a whole number). Watch out for overflow.

Credit to whom credit is due:
(Good explanation, too.)
http://www.piclist.com/techref/postbot.asp?by=time&id=piclist/2002/08/25/084701a.txt
 
Last edited:
Create a FIFO of 5 or more words long that is triggered say once a second by a timer, this will collect the last 5 seconds of air pressure.
Then use a compute instruction to add those 5 values together, then divide the result by 5. This gives a smoother average of the last 5 seconds
 
I would go a bit further with the FIFO - take 10 readings, discard the highest and lowest (or 2 highest and 2 lowest) and average the rest with a simple SUM and DIVIDE instructions. Bit of data fiddling but will work.
 
Air transducers

Most air transducers require a snubber to absorb the sometimes violent transistions of air systems. You should'nt see the variations you mention unless the demand changes and the air system design can't compensate. Most won't in a demanding industrial enviorment. A transducer without a snubber will see valves opening and closing anywhere in the system. If you have snubbed the air simply copy the values to a table or array and average the table. Use a sample large enough, say 100 values every second. Copy each value at a timer set for .01 sec. In Allen Bradley I'd use the FAL. As the timer Done bit goes high, I store the air presure in the FAL. At the 100th value Id average the Fal table of values using the AVG function block. I'll warn you here, this will not match any air presure gauge in the system. You are averaging a sample of air presure values. The gauge, even snubbed will be different. Many operators love to point this out. If you keep the Sample duration small and use enough values, you can be +/- 1 PSI.
 
I use exactly the same filter as Agarb. This is simple to implement and very effective provided that you can live with the phase shift. If you are using the filtered value as the PV in a PID loop then you should get the filter sorted before you try to tune the loop.

Andybr
 

Similar Topics

Hi, I have a bit of PLC experience in Siemens and have unfortunately been blessed with working on Automation Studio and B&R which has been a big...
Replies
5
Views
1,363
The PLC code calculates oil flow rate and outputs it on D420. It is represented on the HMI as a vertical bar. Problem is that the operator says...
Replies
33
Views
4,923
Hello, I am working with a laser encoder that is providing the speed of a fiber strand to our AB 1756-L61 PLC. In order to calculate the amount...
Replies
3
Views
3,145
Hi ;Configure A1s64AD card in slot 3 is as attached. This is averaging count. my signals are coming in at channel 3 and 4. There are spiking so i...
Replies
1
Views
1,632
Hi, folks. Thanks for taking the time to read this. I need to average 5 numbers, they being an accumulated value (mSec) from a timer. My director...
Replies
19
Views
5,641
Back
Top Bottom