Program low pass first order

aand74

Member
Join Date
Dec 2005
Location
Deinze
Posts
131
We have to program a low pass first order filter in Siemens S7.
From an engineering company we got following transfer function :
��(��)=(1/��)/(��+1/��)
��=50

I found following on this forum as implementation :
Y0 = (Y-1 * Kf) + (X * (1 - Kf))
where:
Y0 is the filtered output
Y-1 is the filtered output from the previous scan
X is the input to be filtered
Kf is the first order filter constant
Kf = e-t/T
where"
t is the time between scans
T is the first order time constant


Can I use the above formula : Y0 = (Y-1 * Kf) + (X * (1 - Kf))
where I can set T (Kf = e-t/T) to 50?

Or is this the wrong approach?
 
��(��)=(1/��)/(��+1/��)
��=50

I'm not sure what it looked like on your end, but what I see in the equation is mostly question marks with a few math symbols like parentheses, division, etc.
 
The equation you show is an easy way to approximate a 1st-order low-pass filter. It is variously termed "running average" or "exponential filter". The later is from Management Science and Industrial Engineering. It is simple to implement because you need store only one past value. In the classification of digital filters, it falls into "infinite impulse response" (IIR) because any spike or such will affect the output forever (slowly decaying). The contrast is FIR filters which average a block of input readings (must store all of them), a useful one being a "window average" such as averaging over exactly 1 period (or n) of 60 Hz (or 50 Hz) to eliminate AC noise.

I usually write the running average as:
yout = w*yin + (1-w)yout

where y is the filter output (i sample on left, i-1 sample on right). yin is the raw signal (i sample), and w is the weighting factor, which approximates a 1st-order filter w/ time constant tau:
w = 1 - (T/tau)
where T = sampling period (sec). For the common RC low-pass circuit in textbooks, tau = R*C. In terms of cutoff frequency (3 dB attenuation point), fco = 1/(2*pi*tau). Of course, a faster sampling rate better approximates an analog filter.
 
Last edited:
Peter,

I clearly said T has units of sec. But, not necessary since the equations work in any consistent set of units. If T <> sec, then fco <> Hz.

Yes, one must assign values to the constants before using them. In PLC world that doesn't have to be done in PLC code. In Beckhoff's TwinCAT, one can download a value for w from a Visual Basic HMI program (I recall similar for A-B ControlLogix). T is best set from a function call which polls the PLC OS for the current value of cycle time.

In Structured Text, the equation should be:
yout := w*yin + (1-w)*yout;

One doesn't need to distinguish which yout goes with which calculation cycle, since implicit in the way the code flows. As in most computer languages, variables on the left side are assigned, thus "new value", while variables on the right side are inputs, thus "last value". That is why many languages use ":=" instead of math's "=".

I just noticed a mistake. Should be w = T/tau.
I grabbed this from an e-mail I sent to a young engineer here years ago, and made the mistake then. I related the weighting to an equivalent time constant long ago when at Westinghouse. I recall seeing the same in a textbook after that, but forgot where (if someone finds, please post). For those who care, look at the simple mathematical derivation below and compare to the running-average equation to equate w to equivalent tau.

Exact Integration
The time derivative is a function of the input (yin) and current output value (yout):
dyout/dt = (yin – yout)/tau
As a numerical approximation, one recalculates the slope at intervals T, projecting to a new yout, each time:
yout = yout + (dyout/dt)T = yout + (T/tau)(yin – yout)
or
yout = (1-T/tau)yout + (T/tau) yin
 
I'm leaning towards Kalman filtering for analog signals that may have unwanted noise, but I've yet to find a simple explanation as to how it works.

I've used it in Arduino projects with great success, you can add-in a kalman library function quite easily, it's all pre-built, but have no knowledge of the nuts and bolts of it.

Perhaps I haven't looked long and hard enough, but I've yet to see a Kalman filtering method applied in the PLC world.
 
for analog signals that may have unwanted noise

For that use this...

FV=FV+C(NV-FV)
Where:
FV= Filtered value
C= constant (range 0-.99) The smaller the number the more dampening.
NV= New Value

Filtered Value= Filtered Value+Constant*(New Value-Filtered Value)

New Value = Unfiltered Value

Constant= 0.00-.99 The smaller the number the more damping.
 
For that use this...

FV=FV+C(NV-FV)
Where:
FV= Filtered value
C= constant (range 0-.99) The smaller the number the more dampening.
NV= New Value

Filtered Value= Filtered Value+Constant*(New Value-Filtered Value)

New Value = Unfiltered Value

Constant= 0.00-.99 The smaller the number the more damping.

That's a very simple filtering algorithm, and not really suited to my application.

It is suitable for applications where the noise is more constant, such as noise induced by mains-borne interference, or where the "noise" is relatively constant and largely predictable. Large transients will still propagate through the maths, and produce noticeable shifts in the output until it is "shifted-out" of the equations.

So, I've been reading up on Kalman filtering, and the description of how it operates seems to suit my needs better.

My application is a tracking receiving antenna system for FPV flying R/C aircraft, helis etc., and my findings are such that you can get large, short term, deviations in Received Signal Strength as the model moves around, mainly due to multiple signal paths being created and disappearing.

The Kalman filter assigns a "weighting" to each successive reading, based on the probability of its "correctness". The larger the deviation, the smaller the probability. The subsequent averaging includes the weighting factor, so large transients have much less effect on the final filtered value.

My initial tests when I first adopted Kalman were extremely encouraging.

If anyone is interested in the math involved, I have attached the Arduino "Kalman.h" library file FYI. I'm relatively new to Arduino programming, and don't yet undersyand some of the syntax, but it may be useful if anyone wants to try translating into PLC code.
 
Last edited:

Similar Topics

I am trying to figure out how ladder programs in the compactlogix/controllogix platforms handle JSRs and general flow, etc. :banghead: If I have...
Replies
20
Views
5,054
in the scl code written in screenshot Line 1 condition is false but still the program checking the line 2 condition and says it is true i had...
Replies
3
Views
1,736
In program, L36ER is communicating with L33ER through Ethernet. L33ER module shows unknown. i installed L33ER EDS file of very version but no...
Replies
4
Views
1,784
I keep getting a major fault occur on a CompactLogix L43 CPU which I can't get to the bottom of. Fault details: Major fault Type 04 - Program...
Replies
3
Views
4,394
In RS Logix500 (with ML1100) I am developing a program with a lot of program files used as sub-routines that are called as needed. Is there a way...
Replies
1
Views
2,569
Back
Top Bottom