Build an analog filter in logic

Originally posted by Peter Nachtwey:

Why not use Kalman filter?

As the problem is presented, we don't have enough information to construct the system model to provide state updates for the predicted portion of the filter. Nor do we have the system input value. We have no way of knowing what the system state is supposed to be so we have nothing to compare the feedback value to. Also, most plcs don't have the tools or horsepower to reasonably implement a Kalman filter. It can be done but only for relatively "slow" systems and you would be doing everything at the lowest level.


Originally posted by NetNathan:

How sensitive is K1?

Not very. Steve's filter is basically a first order IIR filter. It has a tweek that causes it to operate on the filtered value from two scans back but outside of that it is a pretty standard form. Interestingly, it is effectively the same filter as that posted by Mickey, just in a different form. It doesn't sound like you have a specific target to shoot for; you just want the signal "cleaner". Since this is the case you can just start playing with values of K1 until you are happy with the result. If you get to 0.1 and you still need more filtering, just enter 0.05 and keep going down from there. Add digits to the right as you need to in order to get the level of filtering you need. But you will not see a visual difference between 0.1 and 0.09 so don't get too worried about absolute precision.

This is a first order filter. It will produce an output to a step response that looks like a capacitor charging. You can calculate a value of K1 for this filter if you know what you want your time constant to be with the equation:

1-e(-t/T)
where t is the equation update rate and T is the time constant you are shooting for.

Keith
 
I am a Rockwell user these are two that use. Filter or Average.
Included screen shots and AOI L5K files for add-ons I've created.

AVG.PNG Filter.PNG
 

Attachments

  • L5K.zip
    3 KB · Views: 19
You can do some interesting stuff with Mickey's filter, because, the constant doesn't actually have to be constant.

For instance, if you use a high level of averaging then at power up you have a lazy curve as the averaging works through. You can combat it with a timer and different 'starting' and 'running' averaging levels.

Or you can calculate the constant from the difference between the new value and the averaged value. You can have heavy averaging when they are close but still let it move quickly if the values are far apart.

Hours of fun and entertainment.
 
As the problem is presented, we don't have enough information to construct the system model to provide state updates for the predicted portion of the filter. Nor do we have the system input value. We have no way of knowing what the system state is supposed to be so we have nothing to compare the feedback value to. Also, most plcs don't have the tools or horsepower to reasonably implement a Kalman filter. It can be done but only for relatively "slow" systems and you would be doing everything at the lowest level.




Not very. Steve's filter is basically a first order IIR filter. It has a tweek that causes it to operate on the filtered value from two scans back but outside of that it is a pretty standard form. Interestingly, it is effectively the same filter as that posted by Mickey, just in a different form. It doesn't sound like you have a specific target to shoot for; you just want the signal "cleaner". Since this is the case you can just start playing with values of K1 until you are happy with the result. If you get to 0.1 and you still need more filtering, just enter 0.05 and keep going down from there. Add digits to the right as you need to in order to get the level of filtering you need. But you will not see a visual difference between 0.1 and 0.09 so don't get too worried about absolute precision.

This is a first order filter. It will produce an output to a step response that looks like a capacitor charging. You can calculate a value of K1 for this filter if you know what you want your time constant to be with the equation:

1-e(-t/T)
where t is the equation update rate and T is the time constant you are shooting for.

Keith

Thanks for the explanation.
I am testing now.
Funny thing is there seems to be more movement on the filtered value than the unfiltered...
I will keep testing different K1 (filtering) values.
 
Originally posted by NetNathan:

Funny thing is there seems to be more movement on the filtered value than the unfiltered...

That does seem odd. Are you using Steve's implementation or Mickey's? Have you tried both?

Keith
 
Here is my logic.

It appears to be the same as Steve's.
I added the first rung that shows:
1. Move of the noisy signal to the Unfiltered register.
2. Move of value to K1
3. Subtract of Filtered from Unfiltered and result is Error register. (This was only put in so I could monitor Unfiltered and Filtered values in one place)

Presently K1 is 0.9. I have tried 0.2, 0.5, and 0.75. All K1 values show a lot more movement below the decimal place on the Filtered value than the Unfiltered value?? (0.9 is not as bad, but it is almost 1). Sometimes I even see a higher value in the Filtered value than was shown in the Unfiltered value???

The range of my signal is 0.0 to 1000.0. Most of the time the noise is seen 0.0 to 10.0, this is where the equipment is using heating power (400KVA power supply), which causes the noise. During heating the signal may spike from 0.3 to 2.5, or even 5.0, and come right back.

If this is too small of a range to filter..... I could try filtering the raw count value from the sensor (0-32000). Would this help or hinder?
 
Last edited:
It has been my experience that filtering every scan is unnecessary, and requires a great many samples to be effective. I usually use a timed subroutine for the filtering, ad only take a sample and filter three to ten times per second, with three to ten samples. This scheme provides more control, and has worked well for typical analog signal fluctuations.

Attached is a spreadsheet that shows the formula that is the basis for most of the above, showing the effect of different number of samples. You should remember that the greater the degree of filtering the slower the response will be to changes in the measured variable.
 
Using Machine Edition open a data monitor with your unfiltered and filtered values. Drop a screen capture of the data monitor into a Word document and post it.

I usually use K1 values of less than 0.1, sometimes as low as 0.005. In the application I initially used it on, there was always plenty of settling time after a step change in the unfiltered value (a new load of product dropped into the hopper) before a weigh-out cycle. That gave the filtered value plenty of time to "catch up" with the unfiltered before I needed to use the filtered value for control decisions, so I could get away with such a low K1 value. Also, since the filter updates every PLC scan, a faster scan time means you can use a smaller K1 value.
 
Using Machine Edition open a data monitor with your unfiltered and filtered values. Drop a screen capture of the data monitor into a Word document and post it.

I usually use K1 values of less than 0.1, sometimes as low as 0.005. In the application I initially used it on, there was always plenty of settling time after a step change in the unfiltered value (a new load of product dropped into the hopper) before a weigh-out cycle. That gave the filtered value plenty of time to "catch up" with the unfiltered before I needed to use the filtered value for control decisions, so I could get away with such a low K1 value. Also, since the filter updates every PLC scan, a faster scan time means you can use a smaller K1 value.

Thanks Steve...
Will do... but have to wait till Monday...
 
Using Machine Edition open a data monitor with your unfiltered and filtered values. Drop a screen capture of the data monitor into a Word document and post it.

I usually use K1 values of less than 0.1, sometimes as low as 0.005. In the application I initially used it on, there was always plenty of settling time after a step change in the unfiltered value (a new load of product dropped into the hopper) before a weigh-out cycle. That gave the filtered value plenty of time to "catch up" with the unfiltered before I needed to use the filtered value for control decisions, so I could get away with such a low K1 value. Also, since the filter updates every PLC scan, a faster scan time means you can use a smaller K1 value.

"Data Watch" (can't find "Data Monitor") shows just the unfiltered and filtered data as it changes. But it is not really collecting.
If I take a screen shot it is only going to show data at that moment. I assume you need something like a log file?
 
Under the "Utilities" tab of the project navigator (the tab with the picture of a screwdriver). There is a selection called "Data Monitor". It gives you a trend chart that you can populate with any variable from you project's variable list. Once you've opened the Data Monitor. go to the variables list, select the variable you want to display and drag it to the chart. Or you can right click on the chart and type in the name of the variable you want to display or select it from the drop-down list.

The chart will store up to 600 minutes of data as long as you keep the project open. You can not store the data to a file, so the only way to preserve data is to take a screenshot and save that. Unfortunately you also can't save the chart configuration so every time you need to use the tool you have to enter the variables again. In short, its a handy tool, but it could be so much better.....
 
Got it...
I can see it working now. It appears ok.
The filtered value IS moving a little more but at the hundreths and below + (.01 +) range.
This is okay because I am only displaying/controlling tenths (.1)
 
So far what I see are all averaging. When doing this, it is important to have samples scattered across the signal period.

One other approach is, instead of averaging, you pick up the median value as the filtered value. This can be very effective when the signal points suffer with bad outliers.
 
Here is Mickey's Filter that I have been using for years with great results. Zip file is a Function Block for GE, Just import it.

filter logic.JPG
 

Attachments

  • Filter_FB.zip
    1.3 KB · Views: 14

Similar Topics

Hi, I would like to assemble a simulator/practice booster pump system that uses PID to maintain steady water pressure under various outlet demands...
Replies
0
Views
82
We are considering dropping our UL membership because most of our customers do not care if we are a 508A shop. However, there may be times when a...
Replies
8
Views
396
I'm looking for some clarification if anyone here is familiar with UL698a panels. Panel is out of zone/class'd area. with thermocouples extending...
Replies
0
Views
119
Hey guys, last week I posted part 1 of a series of OPC UA articles in Node-RED. That article covered some important concepts of OPC UA and how...
Replies
8
Views
3,927
Hey everyone I have an 1756-CNBR/E CONTROLNET goes faulty sometimes and now it's still faulty until I restart the main racks It shows this message...
Replies
0
Views
874
Back
Top Bottom