5/22/2006 10:41 PM  
Posts: 2 Rating: (2) 
Hi experts! How can I smooth an analog input? The flow is very fluctating, so I want to make the changes more soft. Anybody with a hint? Thanks, Anderson 
5/23/2006 7:22 AM  
Posts: 31 Rating: (2) 
Hi Anderson! 
5/26/2006 8:58 AM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
Have look at this: 
Regards, 

This contribution was helpful to1 thankful Users 
5/26/2006 7:39 PM  
Joined: 1/7/2006 Last visit: 5/27/2020 Posts: 2705 Rating: (301) 
Hi Anderson, The smoothing is like Jacek says the best. [:)] I have made a block that is working with that formula. [;)] The block have to be called every 100mS and is using no variabele so that it would not inteferer on your variabele. Filtout := Filtout * e^Rate + RawValue * (1  e^Rate) where e^Rate := (0.1 / F_tau) [8)] AttachmentFilter.zip (2528 Downloads) 
I hope that the answer will help, if you have still questions, don't hesitate to ask me. 

This contribution was helpful to3 thankful Users 
5/29/2006 3:52 PM  
Posts: 31 Rating: (2) 
I agree that "smoothing", as far as it isan established expression is the best way to accomplish a filtered signal. consider implementing the floating average functionality that I suggested in my first post, n = nbr of input values then F_OUT := (AI+(n1)*F_OUT)/n substitute n = 1/K and use some algebra... => F_OUT := AI*K+(1K)*F_OUT) which is the same as what jacek d suggested but the other way around. If n i.e. nbr of elements in the numerator is equal to 1 => K=1 and F_OUT = AI. So I guess I join in that "smoothing" is the best way to implement this. Late I don't have the Simatic Manager here but I will have a look at your code later. Regards Mårten 
6/1/2006 12:03 PM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
Dear MartAnd, when you write "floating average" do you mean "moving average" ? 
Regards, 

This contribution was helpful to1 thankful Users 
6/8/2006 12:43 PM  
Posts: 2 Rating: (2) 
I used this one. Anderson Attachmentsmooth.zip (2370 Downloads) 
6/8/2006 2:19 PM  
Joined: 9/23/2005 Last visit: 7/1/2020 Posts: 3821 Rating: (1103) 
I know, that it is a polemic theme, but I want do some considerations: If you use a filter of the type: out = last out + k * in, you have a new calculated value in each program cycle. However, a past value has a “weight” for a long time. So, it reacts quickly but has also inertia. If you use a mean (average) formulation, statisticly, you can clear any random noise. However you need some samplings, i.e. your filtered value is always “old”. So it is applicable if you can sample your signal quickly as you need. Better as mean is a regression analysis to a f(y)= a * t +b, so, you can obtain a more precise value at the last sample moment. 
Denilson Pegaia 

6/9/2006 3:20 PM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
Dear Pegaia, BTW, I like this: "So, it reacts quickly but has also inertia."  so it's fast and slow at same time. Neat. 
Regards, 

6/11/2006 4:23 PM  
Joined: 1/7/2006 Last visit: 5/27/2020 Posts: 2705 Rating: (301) 
Dear Pegaia, Jacek and Anderson, I believe whe have found the same solutions with the blocks whe presented.... My block have also FiltOut := FiltOut * e^Rate + RawValue * (1  e^Rate),where Rate := (0.1 / F_tau) a regression in it. The blocks are working fine, also the one of Pagia. [;)] So the blocks from Pagia and me are very good 'Filters' for bad analog values, normally you wouldn't need this for a anlog value, only when it is 'dancing'! [:blush:] 
Last edited by: Late at: 6/11/2006 4:24 PMname misspelled I hope that the answer will help, if you have still questions, don't hesitate to ask me. 

6/12/2006 8:39 AM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
[quote user="Late"] The blocks are working fine, also the one of Pagia. Late, Did you refer to this: "out = last out + k * in" (by Pegaia) ? Iwasnot so sure this could work. 
Regards, 

6/12/2006 4:13 PM  
Posts: 31 Rating: (2) 
Yes Jacek, I do mean moving average and nothing else. BTW I think linear regression is a pretty tough one to implement, can we use the least square method[:D]? World Cup is on so I better go home than annoying anyone..... Regards MartAnd 
6/12/2006 11:10 PM  
Joined: 1/7/2006 Last visit: 5/27/2020 Posts: 2705 Rating: (301) 
Hi Jacek, I mean Anderson's program... [:blush:] 
I hope that the answer will help, if you have still questions, don't hesitate to ask me. 

6/19/2006 9:16 AM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
[quote user="MartAnd"] I do mean moving average and nothing else. So I'm amazed how you managed to transform the moving average (which is special case of a FIR) into some realization of an IIR. 
Regards, 

6/20/2006 8:40 PM  
Joined: 9/23/2005 Last visit: 7/1/2020 Posts: 3821 Rating: (1103) 
Hi, Second, when I suggested a linear regression, I don’t would create so big repercution. Follow I send a document with a general explanation about linear regression. The graphic shows the difference between average method and linear regression method. I attach also a sample program. AttachmentSA_en.zip (969 Downloads) 
Denilson Pegaia 

This contribution was helpful to1 thankful Users 
6/22/2006 4:24 PM  
Joined: 9/23/2005 Last visit: 7/2/2020 Posts: 2686 Rating: (415) 
Let's say that I have idea what a linear regression is. That's why I wrote that it's overkill. Like constructing a laser gun to kill a fly. 
Regards, 

6/27/2006 8:34 PM  
Joined: 9/23/2005 Last visit: 7/1/2020 Posts: 3821 Rating: (1103) 
I really agree with your opinion. He applies only in very specific cases. 
Denilson Pegaia 

12/25/2008 6:24 PM  
Joined: 1/7/2006 Last visit: 5/27/2020 Posts: 2705 Rating: (301)

Dear Rawat, The error is coming when the "F_Tau" signal is zero, when that happens the calculations go wrong. This is especially done for a changing variable on "F_Tau", This block could be used as a Multiple Instance if you mean, could it be ysed in a FB.... 
I hope that the answer will help, if you have still questions, don't hesitate to ask me. 

6/5/2011 11:12 PM  
Joined: 9/3/2007 Last visit: 6/12/2020 Posts: 241 Rating: (6) 
Dear Pegaia, Could you please share your formula litle more detail. What I understand is f(y)= filtered valu a=contant value t=input unfiltered value b=another constant value that means we need again the fine tuning for parameter a & b? 
Last edited by: PowerTags at: 6/5/2011 11:13 PMsome english Regards, 

6/6/2011 10:50 AM  
Joined: 5/24/2007 Last visit: 3/10/2017 Posts: 284 Rating: (27) 
Hi Appreciate the work you have done in developing your own function blocks. But have you guys tried the Open Source Library which is available also for Siemens S7at this link www.oscat.de. You need to download the S7 library.You will find a lot of filter functions to achieve these same functions.Advantages is that many people are using and so well tested. Disadantage : Bad English documentation. But I guess the program is clear and structured. Krish 