Noise Filters

Honeytree

Member
Join Date
Jan 2006
Location
Ohio
Posts
11
Does anyone have a good filter code I can use to allow the data value on the HMI screen to be more readable when the data is noisey (bouncing around a number)?
 
It's really going to depend on what platform you are programming with. A solution for an A-B won't be quite the same as the one for a Siemens, etc. It's also going to depend on how often the data changes, what the range is on the bouncy signal, and how often you need to register the data.

A quick answer off the top of my head would be to set up a register of data(maybe the last 10 values of the data) and then use the average value of the data at the hmi instead of the raw data.

Another answer(the quick and dirty one) might be to copy the data to another data point, but only every 2 seconds, that way you have a steady value to look at on your hmi, but won't need to do any compicated coding.
Neither one of these are true "filtering" answers, but they will do the job as you described it.

More details please :)

And welcome to the forum!
 
I want to be able to change the response in milliseconds. Lets say its the good old SLC/503 is the platform. I would like to enter a value into a register N7:0 that will be the response of the filter in milliseconds. Want better than the add them all then divide by the number approach.
 
Does the SLC/503 have FIFO buffers? If so, each read could be stuffed into the buffer. The buffer length could be varied if required. Then just add the buffer words together and divide by the number of words in the buffer, or perhaps there is an "average" type instruction that could be used.

Does the analogue input card have a built in adjustable buffer? I have used the built in buffer in Omron PLCs for this for many years now. The buffer length can be caried from 4 to 16 reads if I remember correctly.

I guess the correct answer is fix the noise in the input. Use good quality screened cable and ground it at one end only - suggest in the control panel. Make sure it is well away from any power cables or high frequency stuff for a start.

Is the input a voltage or current input? current inputs tend to be less noise prone from my experience. I use current inputs wherever possible.
 
A simple filter I often use is a first order digital low-pass filter. The form I usually use is:



Y0 = (Y-1 * k) + (X0 * (1-k))

where:

Y0 is the output
Y-1 is the previous output
X0 is the latest input
k is the filter constant

k is equal to e-(t/T)

where:
e is the base of the natural log
t is the filter scan rate
T is the filter time constant




This will give a simple first order response (like a capaciter charging). You can string several first order filters together to get higher order filters with sharper cutoffs, but that has it's own issues. As the filter order increases so does the delay for a given filter scan time.
One thing that worries me is you want to filter a signal with a filter that has millisecond time constants. You may have trouble doing that in a SLC just due to scan time. You also need a consistent scan time, which would suggest using an STI. Then there is your analog input conversion rate, which is probably something like 50 milliseconds. You may be having aliasing issues, which will be hard to get rid of.

You may want to consider an external filter. I have used a company called Alligator Technologies for high pole count analog anti-aliasing filters with pretty good luck.

There are a few guys on the forum that will probably have some better ideas. You may want to hold out for them. They will have filter design techniques that may do a better job of cutting out only what you want cut out.

Keith
 
Last edited:
RSS Filtering

I use something similar to Keith, but not quite as elegant. The filtering is attached. I usually put this in a subroutine and use a timer to call it at pre-set intervals rather than have it calculate every scan, but you can do it either way.
 
Tom's implementation is very similar to mine. They are both first order filters. My value of K needs to be between 0 and 1 to produce a filter without gain. Tom's needs to be 1 or greater. With Tom's equation a value of 1 effectively disables the filter. With mine a value of 0 disables the filter.

Outside of those minor differences they are the same filter.

Keith

P.S.:
Tom, the description in your ladder and the equation in the compute don't match. The description appears correct.
The description is:

Y0 = Y-1 + (1/k * (X0 - Y-1))



The compute is:

Y0 = Y-1 + (1/k * (Y-1 - X0))



As I said, I think the description is correct.
 
Last edited:
Originally posted by Peter Nachtwey:

Did you know you can cascase filters?

Yes, I did know you can cascade filters.

Originally posted by Peter Nachtwey:

How do you compute K as a function of time constants and PLC update times?

From post 5:

k is equal to e-(t/T)

where:

k is the filter coefficient

e is the base of the natural log

t is the filter scan rate

T is the filter time constant




Originally posted by Peter Nachtwey:

What effect does cascading filters have on the result?

I acts effectively like a single higher order filter. Cascading two first order filters will produce the effect of a single second order filter. This filter will have a steeper roll-off as frequency increases than the first order filter does.

Where I still need to do some looking is in converting time constants to frequencies. A first order filter has a time constant that defines the amount of time required for the output to reach a specific level based on a step input. Higher order filters are expressed in terms of frequency and damping ratio. How do I move between the two representations?

Keith
 
Last edited:
Filtered Value = ((Current input - Filtered Value)x Filter Factor) + Filtered Value.

The Filter Factor is between 0 - 1. The larger the filter factor, the less filtering. A 0.1 gives you 10% of the actual change applied and a value of 1.0 gives you 100% of the change applied (no filtering). If this input is used in a control loop, be careful that it is not filtered too much as to conflict with the process reaction time.
 
If this input is used in a control loop, be careful that it is not filtered too much as to conflict with the process reaction time.

THe good Dr brings up an excellent point. Since it is for display only, and if otherwise the control is working well, then go ahead and use Keith's or Tom's first order lag filters, but write the result to a different register than the one you are using for control. Tag the display to this second register. Let the loop or limit control or whatever it is continue to respond to the unfiltered value.
 

Similar Topics

I have been using Islatrol line filters on the machines that i have been building but curious as what brands others may be using.
Replies
4
Views
1,430
I need some help with this situation: I am writing an A.B. SLC 5/02 program for handling scrap metal. I have an ultrasonic level detector...
Replies
20
Views
14,178
Hello, I am running a AMCI SD4840 Stepper Motor drive system with Allen Bradley CompactLogix. Every now and then when a 480VAC motor kicks in on...
Replies
1
Views
585
Hello Everyone, I hope we are all well. I have an L36ERM with a 1769-OF8C/a driving a 5HP Power Flex 523 speed reference 4-20 mA. With the...
Replies
6
Views
1,831
Good Morning , We have a new Fortress Stealth Metal Detector. About 30' away we have a machine with motors and solenoids on it , Whenever...
Replies
8
Views
2,182
Back
Top Bottom