You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 9th, 2017, 03:51 AM   #1
aand74
Member
Belgium

aand74 is offline
 
Join Date: Dec 2005
Location: Deinze
Posts: 79
Program low pass first order

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?
  Reply With Quote
Old November 9th, 2017, 07:23 AM   #2
mk42
Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 1,783
Quote:
Originally Posted by aand74 View Post
��(��)=(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.
  Reply With Quote
Old November 9th, 2017, 09:01 AM   #3
RocketTester
Member
United States

RocketTester is offline
 
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 185
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 by RocketTester; November 9th, 2017 at 09:15 AM.
  Reply With Quote
Old November 9th, 2017, 12:56 PM   #4
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,667
T has units of what? Minutes? Seconds?
You need to set T on initialization as well as calculate Kf.
However, you could set T= 50 each scan and calculate Kf each scan it just wouldn't be as efficient.

BTW, don't get sloppy with your equations
y(n) = Kf*y(n-1)+(1-Kf)*x(n)
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old November 9th, 2017, 02:39 PM   #5
RocketTester
Member
United States

RocketTester is offline
 
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 185
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
  Reply With Quote
Old November 9th, 2017, 02:46 PM   #6
Ronnie Sullivan
Member
United Kingdom

Ronnie Sullivan is offline
 
Join Date: May 2010
Location: London
Posts: 441
What are they talking about?
  Reply With Quote
Old November 9th, 2017, 05:25 PM   #7
RocketTester
Member
United States

RocketTester is offline
 
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 185
Ronnie,
aand74 needs to smooth a signal by numerical averaging. A running average is a simple method. It approximates an analog low-pass filter.
  Reply With Quote
Old November 9th, 2017, 07:40 PM   #8
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,341
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.
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old November 9th, 2017, 09:11 PM   #9
Mickey
Lifetime Supporting Member
United States

Mickey is offline
 
Mickey's Avatar
 
Join Date: May 2003
Location: Palmdale,Ca
Posts: 10,067
Quote:
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.
Attached Files
File Type: txt Filtering.txt (292 Bytes, 9 views)
__________________
Mickey

If you want happiness for an hour-take a nap. If you want happiness for a day-go fishing. If you want happiness for a month-getmarried. If you want happiness for a year-inherit a fortune. If you want happiness for a lifetime-help someone else.
----- Chinese Proverb
  Reply With Quote
Old November 10th, 2017, 12:53 AM   #10
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,667
Two Pole Butterworth filter and comparison with single pole low pass filter.
http://deltamotion.com/peter/Mathcad...worth%20NG.pdf
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old November 10th, 2017, 07:42 AM   #11
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,341
Quote:
Originally Posted by Mickey View Post
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.
Attached Files
File Type: zip Kalman.zip (1,018 Bytes, 6 views)
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem



Last edited by daba; November 10th, 2017 at 08:01 AM.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Navigating Connections/Parameters in modern Allen Bradley Program edw1983 LIVE PLC Questions And Answers 0 March 18th, 2016 08:45 AM
RS5000 Program order RoTaTech LIVE PLC Questions And Answers 4 October 2nd, 2015 10:33 AM
EWMA vs Low Pass Analog Smoothing iraiam LIVE PLC Questions And Answers 2 May 18th, 2014 10:36 PM
Program Structure Jieve LIVE PLC Questions And Answers 3 February 6th, 2012 06:14 PM
LPF Low pass filter turbohamad LIVE PLC Questions And Answers 1 June 26th, 2009 01:45 AM


All times are GMT -5. The time now is 12:50 PM.


.