This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.  
Your Personal PLC Tutor Site - Interactive Q & A

"FIRST ORDER FILTER IN PLC-5"

New Here? Please read this important info!!!
Email this topic to a friend
Printer-friendly version of this topic
 
Previous Topic | Next Topic 
Home Conferences *** LIVE PLC Q&A *** (Public)
Original message

DOR_LZ Click to EMail DOR_LZ - (2 posts) Click to check IP address of the poster Apr-11-02, 01:26 PM (EST)
"FIRST ORDER FILTER IN PLC-5"

HELLO !
I WANT TO CONFIG FIRST ORDER FILTER FOR ANALOG POINT IN PLC-5/40 (SOFTWARE IS RSLOGIX5)
CAN ANY BADY HELP ME ?

THANKS

DOR LZ

  Alert Edit | Reply | Reply With Quote | Top

 Table of contents

RE: FIRST ORDER FILTER IN PLC-5, Allen Nelson, Apr-11-02, (1)
RE: FIRST ORDER FILTER IN PLC-5, Peter Nachtwey, Apr-11-02, (2)
RE: FIRST ORDER FILTER IN PLC-5, Peter Nachtwey, Apr-11-02, (3)
RE: FIRST ORDER FILTER IN PLC-5, Allen Nelson, Apr-11-02, (4)
RE: FIRST ORDER FILTER IN PLC-5, Gerry, Apr-11-02, (5)
RE: FIRST ORDER FILTER IN PLC-5, Peter Nachtwey, Apr-11-02, (6)
RE: FIRST ORDER FILTER IN PLC-5, rsdoran, Apr-11-02, (7)
RE: FIRST ORDER FILTER IN PLC-5, Peter Nachtwey, Apr-11-02, (8)
RE: FIRST ORDER FILTER IN PLC-5, rsdoran, Apr-11-02, (9)
RE: FIRST ORDER FILTER IN PLC-5, Peter Nachtwey, Apr-11-02, (10)
RE: FIRST ORDER FILTER IN PLC-5, Allen Nelson, Apr-12-02, (11)
RE: FIRST ORDER FILTER IN PLC-5, Tom Jenkins, Apr-12-02, (12)

Lobby | Topics | Previous Topic | Next Topic
Messages in this topic

Allen Nelson Click to EMail Allen NelsonClick to view user profile - (249 posts) Click to check IP address of the poster Apr-11-02, 02:12 PM (EST)
1. "RE: FIRST ORDER FILTER IN PLC-5"

Most, if not all, of the 1771-IFE modules have built-in filtering, that you can enable with RSLogix. See RSLogix help or the Analog input module manual for details.

If you are looking for a programming method, then try


FILTERED_SIGNAL = ( (FILTERED_SIGNAL * X) + (SIGNAL * (100 - X) )
---------------------------------------------
100

where X is a number between 0 and 99. '0' gives you no filtering, '99' gives maximum filtering.

©¿©¬

  Remove | Alert Edit | Reply | Reply With Quote | Top

Peter Nachtwey Click to EMail Peter Nachtwey - (31 posts) Click to check IP address of the poster Apr-11-02, 03:40 PM (EST)
2. "RE: FIRST ORDER FILTER IN PLC-5"
So what value of X gives a time constant of 1 second?
Allen's formula does not take into account the PLC scan time.

I asked this same question 6 months ago but know one knew what I was talking about. Since this problem is also related to the PID scan time issue I am asking ( quiz ) again. Yes, Ron, I know the answer.

What if I want the filter to be a 2 HZ low pass filter. What would be the value of X.

BTW. This is more efficient.

FILTERED_SIGNAL = K * ( SIGNAL - FILTERED_SIGNAL )

BUT is doen't account for scan time variance.

Where K = X/100 using Allen's example. I prefer that K is just a float .0 to 1.0 with much more resolution. With intergers one uses a trick called fractional multiplies but that is another topic. But this still doesn't answer what the relationship between between X and time constants or filter pole frequencies.

Does any body know or care?

  Remove | Alert Edit | Reply | Reply With Quote | Top

Peter Nachtwey Click to EMail Peter Nachtwey - (31 posts) Click to check IP address of the poster Apr-11-02, 03:47 PM (EST)
3. "RE: FIRST ORDER FILTER IN PLC-5"
Good grief, Peter, we are only cutting pickles!
  Remove | Alert Edit | Reply | Reply With Quote | Top

Allen Nelson Click to EMail Allen NelsonClick to view user profile - (249 posts) Click to check IP address of the poster Apr-11-02, 04:26 PM (EST)
4. "RE: FIRST ORDER FILTER IN PLC-5"
I don't take into account scan time, because this is a PLC-5, and analog inputs are handled by BTR, which is asynchonous to scan.

So even knowing the scan time isn't going to get you a precise 2 Hz filter.

Besides, how do you know up front that you want 2 Hz and not 5 Hz? You don't - you look at the input, and decide that you want more or less filtering. That's going to depend on how rapidly the signal changes "for real" vs how much it changes due to noise.

Therefore, X is empirical, and scan time, while it certainly affects the value you'll use, is irrelavent.

BTW, you have a error in your equation:

FILTERED_SIGNAL = K * ( SIGNAL - FILTERED_SIGNAL ) + FILTERED_SIGNAL

which is mathematically the same as mine (for K=X/100). I'm not sure how much difference using a float makes, since SIGNAL is an integer between 0-4095 anyway.

©¿©¬

  Remove | Alert Edit | Reply | Reply With Quote | Top

Gerry Click to EMail Gerry - (16 posts) Click to check IP address of the poster Apr-11-02, 05:20 PM (EST)
5. "RE: FIRST ORDER FILTER IN PLC-5"
If using a 1771-IFE analogue input, then you can configure the module for real-time sampling, and you will then know the interval between readings (adjustable between approx. 25-3000 msec) - if this is vital.
  Remove | Alert Edit | Reply | Reply With Quote | Top

Peter Nachtwey Click to EMail Peter Nachtwey - (31 posts) Click to check IP address of the poster Apr-11-02, 06:01 PM (EST)
6. "RE: FIRST ORDER FILTER IN PLC-5"
You are right.
I usually right it like this


FILTERED_SIGNAL += K * ( SIGNAL - FILTERED_SIGNAL )

The += is the C equivelent of your correction.

FILTERED_SIGNAL = K * ( SIGNAL - FILTERED_SIGNAL ) + FILTERED_SIGNAL

>So even knowing the scan time isn't going to get you a precise >2 Hz filter.

Yes, but not everyone uses a PLC5 and BTR.

  Remove | Alert Edit | Reply | Reply With Quote | Top

rsdoran Click to EMail rsdoran - (541 posts) Click to check IP address of the poster Apr-11-02, 06:46 PM (EST)
7. "RE: FIRST ORDER FILTER IN PLC-5"
Just an observation, wasnt the original question pertaining to AB PLC5?

Shouldnt the answers correspond to the device used when appropriate?

I wrote a long diatribe but deleted it, what I am asking is "If an answer is device/brand specific (as can happen with any brand) then why the debate/discussion?" Isnt the theory used a basis/foundation to work from? Wont circumstances, situations, devices be a factor in HOW a specific equation is done?

I print out and save all these kind of answers to use as a reference when needed, but sometimes y'all get into some deep stuff that I dont fully understand.

  Remove | Alert Edit | Reply | Reply With Quote | Top

Peter Nachtwey Click to EMail Peter Nachtwey - (31 posts) Click to check IP address of the poster Apr-11-02, 07:16 PM (EST)
8. "RE: FIRST ORDER FILTER IN PLC-5"
Allen has already given a suitable answer for a PLC5. Allen has also reminded me of the PLC5's limitations when it comes to getting acquiring timely analog data. Perhaps the PLC5 is not capable of doing a decent filter because of these limitations but there are other PLCs that aren't. My questions about relating Allens's X to a time constant or roll off frequency are still valid. The answers just aren't as useful on a PLC5.

  Remove | Alert Edit | Reply | Reply With Quote | Top

rsdoran Click to EMail rsdoran - (541 posts) Click to check IP address of the poster Apr-11-02, 08:27 PM (EST)
9. "RE: FIRST ORDER FILTER IN PLC-5"
Is it truly a limitation? Please explain why and if possible tone down the explanation fer this ol guy.
  Remove | Alert Edit | Reply | Reply With Quote | Top

Peter Nachtwey Click to EMail Peter Nachtwey - (31 posts) Click to check IP address of the poster Apr-11-02, 10:11 PM (EST)
10. "RE: FIRST ORDER FILTER IN PLC-5"
The problem with Allen's filter is that it doesn't take into account the scan time. This will cause Allen's filter to respond differently ( at different rates ) depending on how often Allen's filter is updated. This means the filter constants must be updated as more code is added to the PLC and the PLC scan time becomes longer. These crude filters may be OK for many applications but wouldn't it be nice to be able to calculate how a low pass filter will respond? OH YEAH, we all assume we were asked about how to do a low pass filter.

Low pass filters are usually described as having a time constant or cut off frequency.

Time constants describe how quickly a filter will respond to a step input. Let's assume the the signal we are filtering is at 0 volts and then it takes a step jump to 10 volts. It takes five time constants for the signal to rise from 0 to within 1% of 10 volts. Therefore if the time constant is 1 second, it will take the filtered signal 5 seconds to get within 1% of the signal.

Y = 10 ( 1 - exp ( -t / TC ))

BTW if this were a RC electrical circuit then TC = RC or
Y = 10 ( 1 - exp ( -t / RC ))

The cut off frequency, roll off frequency or pole frequeny of a filter is the frequency where the amplitude of the AC or noise components are reduced by 3db or .707 of the 0 HZ signal. Beyond the pole frequency the noise drops off at 6db per octave or 20db per decade.

For most applications I like to think in terms of time constants. I want to filter the data as much as possible but not too much. If I need the input to be accurate within 1% in 1 second then the time constant needs to be 200 milliseconds ( remember it takes 5 time constants to get within 1%).

Now that I know the time constant I need to calculate the filter coefficient that will yield a time constant of 200 milliseconds.

The formula is:

K is the filter coefficient
TC is the time constant
ST is the scan time or period
Y is the Output or filtered value
X is the Input or signal or error

K = ST / ( TC + ST )

Now the filter formula becomes

Y = Y + K * ( X - Y )

This formula is accurates as long as the scan time ST is small compared to the time constant TC. If ST is <= TC /10 then an analog system can be approximated. So if the PLC scan time is 10 milliseconds, the TC can be as low as 100 and the results will be pretty good.

Normally K is computed only once when the PLC starts but it may need to be updated before it is used eached scan if the scan time can vary a lot.

In this case the filter is

Y = Y + ST * ( X - Y) / ( ST + TC )

Many PLCs perform A to D conversions synchrously to the scan and the period between scans or scan time is known to a millisecond.

Compensating for the scan time and knowing how safe ratio between the ST and TC keep the wierd stuff from happening that Terry mentioned in the PID thread.

The relationship between the TC and pole frequency is simple:

F is the pole frequency where the noise is reduced to .707

F = 1/(2*PI*TC)

In the example where TC = .2 seconds the pole frequency is 1.256 HZ which is pretty low. At 12.56HZ or one decade above 1.256 hz the noise reduced to a tenth.

Now you might have an application where you have 5 HZ signal that you want to measure but want to start to filter noise above 10 HZ. From the equation

TC = 1/(2*PI*f) = .0159 seconds or 16 milliseconds. This filter would be hard to do accurately because the scan time is not 10 times less than the time constant. The PLC scan time would have to be less than two milliseconds. There are other ways of calculating the filter coefficient K that would return adequate results with much lower scan times.

Now one can predict how a filter will respond to noise.

Get a spread sheet a try it.

  Remove | Alert Edit | Reply | Reply With Quote | Top

Allen Nelson Click to EMail Allen NelsonClick to view user profile - (249 posts) Click to check IP address of the poster Apr-12-02, 00:16 AM (EST)
11. "RE: FIRST ORDER FILTER IN PLC-5"

OK, Peter, all well and good. But I repeat - how do you know, before monitoring the input, how much damping you want?

All your explanation shows that you don't know, because first you have to know the frequency of the noise, to get a feel for how much to dampen it by. This you determine empirically.

Next, you decide how much you want to dampen the signal by. If its just for display, you may want to dampen it a lot ("Don't confuse the operators with the facts"). If it's for PID control, then you want to balance dampening with the need to detect real-but-small changes. So you pick a number (say 10% dampening), and see how that looks/tunes. If you don't like it, you tweak it, up or down, depending.

The equation I gave works the same way. Sure, it doesn't take scan time into account, but then, the PID doesn't either, because it's only evaluated once per scan.

Oh, what's that? The PID is in an interrupt routine? Then so is the dampening logic (The PID has to know what the "correct" PV is in order to be "accurate, after all). And therefore the filter has a metronome-steady scan time, and is predictable (if still arbritary).

I'm not really disagreeing with you in principle - I just think you're making it harder than it needs to be, trying for an exact solution to an inexact problem. ("Pickle slicer")

BTW - the asynchonous-to-scan BTR "problem" is probably why the analog I/O modules are capable of their own filtering (which was the first thing I mentioned in my reply to this topic).

Thanks for the refresher and making me think about this again. Maybe my RAM difficulty is just increased resistance due to dust on the chips.

©¿©¬

  Remove | Alert Edit | Reply | Reply With Quote | Top

Tom Jenkins Click to EMail Tom Jenkins - (939 posts) Click to check IP address of the poster Apr-12-02, 08:36 AM (EST)
12. "RE: FIRST ORDER FILTER IN PLC-5"
Well, I has done printed this thread out cuz they is a lot o' good stuff in it. And this is good theoretical background too! But if I can make a observation, to this ole country boy, if you is jist slicin' pickles you might be gildin' the lily a bit.

If you need a true low pass predictable deterministic filter I reckon ya ought to be doin' it with hardware like Allen suggests. Even a "fat cap" (high value capacitor) on the signal lines is gonna git the job done, at least to the standards o' most of my applicashuns. I normally don't try to use mathematical filtering ta' get rid o' electrical noise and sich.

I use digital filerin' on almost every application, but I does it ta git rid o' normal fluctuations in my input due to process fluctuations. I ain't tryin to git rid of noise. And in that case I jist use a timer, and go to the filterin' calculashun every so offen (usually at 0.2 to 0.3 second inervals) and average out over 5 ta 10 values usin' a formula like Allen's.

As has been offen stated hyar, it comes down to knowin' the applicashun and the true requirements thereof.

  Remove | Alert Edit | Reply | Reply With Quote | Top


Lock | Archive | Remove

Lobby | Topics | Previous Topic | Next Topic
Rate this topic (1=skip it, 10=must read)? [ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 ]
Your Personal PLC Tutor Site Learn Now!!.