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.

New Here? Please read this important info!!!
November 9th, 2017, 04:51 AM  #1 
Member
Join Date: Dec 2005
Location: Deinze
Posts: 62

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 = (Y1 * Kf) + (X * (1  Kf)) where: Y0 is the filtered output Y1 is the filtered output from the previous scan X is the input to be filtered Kf is the first order filter constant Kf = et/T where" t is the time between scans T is the first order time constant Can I use the above formula : Y0 = (Y1 * Kf) + (X * (1  Kf)) where I can set T (Kf = et/T) to 50? Or is this the wrong approach? 
November 9th, 2017, 08:23 AM  #2 
Member
Join Date: Jun 2013
Location: MI
Posts: 1,577


November 9th, 2017, 10:01 AM  #3 
Member
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 177

The equation you show is an easy way to approximate a 1storder lowpass 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 + (1w)yout where y is the filter output (i sample on left, i1 sample on right). yin is the raw signal (i sample), and w is the weighting factor, which approximates a 1storder filter w/ time constant tau: w = 1  (T/tau) where T = sampling period (sec). For the common RC lowpass 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 10:15 AM. 
November 9th, 2017, 01:56 PM  #4 
Member

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(n1)+(1Kf)*x(n)
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon 
November 9th, 2017, 03:39 PM  #5 
Member
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 177

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 AB 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 + (1w)*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 email 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 runningaverage 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 = (1T/tau)yout + (T/tau) yin 
November 9th, 2017, 03:46 PM  #6 
Member
Join Date: May 2010
Location: London
Posts: 396

What are they talking about?

November 9th, 2017, 06:25 PM  #7 
Member
Join Date: Oct 2009
Location: Sacramento, CA
Posts: 177

Ronnie,
aand74 needs to smooth a signal by numerical averaging. A running average is a simple method. It approximates an analog lowpass filter. 
November 9th, 2017, 08:40 PM  #8 
Lifetime Supporting Member + Moderator

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 addin a kalman library function quite easily, it's all prebuilt, 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 ab train ltd. abtrain@tiscali.co.uk www.abtrain.co.uk tel: 07506 73 9999 nil illegitimi carborundem 
November 9th, 2017, 10:11 PM  #9  
Lifetime Supporting Member

Quote:
FV=FV+C(NVFV) 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 ValueFiltered Value) New Value = Unfiltered Value Constant= 0.00.99 The smaller the number the more damping.
__________________
Mickey If you want happiness for an hourtake a nap. If you want happiness for a daygo fishing. If you want happiness for a monthgetmarried. If you want happiness for a yearinherit a fortune. If you want happiness for a lifetimehelp someone else.  Chinese Proverb 

November 10th, 2017, 01:53 AM  #10 
Member

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 
November 10th, 2017, 08:42 AM  #11  
Lifetime Supporting Member + Moderator

Quote:
It is suitable for applications where the noise is more constant, such as noise induced by mainsborne 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 "shiftedout" 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.
__________________
___________________________ ControlLogix & SLC Training ab 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 09:01 AM. 

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


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 07:14 PM 
LPF Low pass filter  turbohamad  LIVE PLC Questions And Answers  1  June 26th, 2009 01:45 AM 