Sign in to follow this  
Followers 0
BenJones

Rolling Average / exponential smoothing

29 posts in this topic

Hello, Does anyone know if there is a way to perform a rolling average function using a special function block in IEC Developer ? I know that there are function blocks using Allen Bradley which can perform this function but can't find one with Mitsubishi. If I were to manually program this I'd need to make an array and then use a pointer and this would be hard for myself to program. I would use this function to monitor machine performance over time and it would give me an average over time. Any fluctuation to this average and I would see a change in machine behaviour which could possible mean that something is failing. Another function which could possibly work is an 'exponentialsmoothing ' fuction. I'm also not sure if there is a function block which can do this. Another way Thanks for any help, Ben Edited by BenJones

Share this post


Link to post
Share on other sites
I'm not sure if I fully understand your needs. Could you please try to explain exactly what you want to do and what result you expect?

Share this post


Link to post
Share on other sites
Hi, The special function block for rolling average, which you need, is absent in IEC Developer. For FX3U exists MEAN command that calculates the average value of data written in array (the appropriate function is in IEC Developer). Simultaneously, for FX3U exist WSFL and WSFR commands that write new words string (or new single word) into array with deleting of old data. Therefore, you can solve your task with combination of these commands . Maximum lenght of array of the averaging data should not exceed of 512 word. May be, later I'll prepare and publish ready function block for this purpose.

Share this post


Link to post
Share on other sites
Thankyou, that looks like the sort of thing I need. I've had a look at the WSFL_M function block and there is also a WSFLP_M (Pulse) but I can't get the word to shift to the left over time. If I wanted to shift the data register data to the left ever one second do I need to apply a second (time) pulse like using M8013 so that the registers save data and it shifts every second ? Kaare, basically what I'm trying to do is to store data in registers (say one piece of data every second) add these up and average them every second, so that my output is a rolling average which changes every second. Using the WSFL function block I could maybe save 512 seconds of data (512 words), shift the registers to the left every second and each second I would get a changing output (rolling average output)

Share this post


Link to post
Share on other sites
If you'll use WSFLP_M with M8013 strobe you get refresh of data in the array every second. Also if after WSFLP_M will be MEANP_M every second you get an averaged data . An example, Edited by Inntele

Share this post


Link to post
Share on other sites
Thank you for your reply, I programmed that yesterday and went into 'Debug' / Device Edit so that I could see what was happening in the registers and how the program was working. Works a dream ! I can see all the data shifting registers and it averages it nicely. The only thing which is a shame is that 0 < 'n*' < 64 for the MEANP block (it can't be 512) so I can only get an average of 64 pieces of data. Ben Using th WSFRP_M block seems to copy and paste the register contents of D1 into 512 registers to the right.

Share this post


Link to post
Share on other sites
Maybe you can use the average'd date and average it over a greater time, intead of per second? Ie. every minute take the average, push it out to another MEAN block, and average that again? Not the best solution, but it should work. The only other way to do this is increment an index register (like Z0) and keep moving data into a contigious block of registers, let's say 512 long. Use the FOR/ NEXT loop to loop through those and code your own average block. When you get to 512 you can either move all 511 devices one up, or restart from zero (which is not ideal). Good luck

Share this post


Link to post
Share on other sites
Hi Ben, Sorry, I did mistake, but it can be solve very easy Today I'll publish the universal FB with the filter up to 512 words. Wait for, please

Share this post


Link to post
Share on other sites
Hi, This is the IEC user library includes FB for the rolling average with the array of 512 words (plus two elements additionally), which automatically being appointed during compilation from the system variables area, defined in menu Extras - Options - Project Options - System Variables of GX IEC Developer software. FB_Rolling_Average.zip Edited by Inntele

Share this post


Link to post
Share on other sites
Hi Waynes, yes thats a way to do it, thaks for your advise !

Share this post


Link to post
Share on other sites
Hi Inntele, thank you very much for the time and effort you've spent making that function block ! It would be perfect to use this function block with 512 words as I'll get much mre accuracy than just 64 words. I tried to load the .SUL file in, and it looks like it has been created with instruction List (IL). Would it be possible for you to upload it again in Ladder (LD) format rather than instruction list (IL) because I'm totally lost with using Instruction List ! I'm just a novice Many thanks again, Ben Edited by BenJones

Share this post


Link to post
Share on other sites
Now you have the library with the ready FB, which you could install and then use this function in your project. And it's available for other programmers usage in their projects. The FB's programm is written in Ladder Diagram, but you couldn't look on it, because the library is closed by password. You can see the download code in MELSEC IL by menu "Tools - Show MELSEC code of network" only. This is classical practice. All FBs are closed usually, including of manufacturer, standard or user library of the Beijer company, because it is know-how. Is not necessary to look on the program code, you can insert it in your program and forget about it, because it already was tested and works fine.

Share this post


Link to post
Share on other sites
I've used several FBs from Beijer and they are always open (you can open their function blocks without a password). It is of course your choice if you want to put a password on your code, but in my experience Beijer usually publish all the source code freely available. Thanks for the upload, nice work!

Share this post


Link to post
Share on other sites
Thank you for good words, 'kaare_t' In fact, very many of the functional blocks of Beijer are closed by password. Moreover, in their libraries is an icon "copyright". And if someone would decide to place their functional blocks on his web page, or to extradite them for its intellectual property, hardly Beijer will look at it through the fingers and an intruder waits for the inevitable punishment! Here I upload my FBs onto alien resourse, which is open, and I can not to control its dissemination. I can not be sure that some sort of crafty man or malicious person does not use the results of my intellectual labor to enrich themselves, issued these results as own. This is especially true of people without talent and with great vanity... Another problem is "innovators". They edit any ready work and then loud say "it does not work". For these reasons, I don't want to open those programs... Àlas abovementioned persons are also presents on this web-site (somebody whom I know) The program of this function block is very simple. And I'm absolutely sure that the closing program not a hindrance for you and you exactly know how to write it from "zero".

Share this post


Link to post
Share on other sites
Brilliant Intelle ! Very good work. I have it working and it works perfectly. I am now able to get a much more accurate averaged answer so thank you for the time you've spent developing this function block. I have one question. Which registers are used to hold the data which is to be averaged ? I thought it would be the 512 adjacent registers to the 'Input_Value' register but this doesn't seem too be the case. Works perfectly anyway so thank you very much Ben

Share this post


Link to post
Share on other sites
However, it's not a problem, I can do the similar FB with "open" array, which start address will be user-defined

Share this post


Link to post
Share on other sites
Hi Ben, I have updated the library for rolling average by new function block in which the array head address is user-defined and the array lenght is variable from a number of 128, 192, 256, 320, 384, 448, 512. FB_Rolling_Average.zip Below you can see screenshot of test. Is important to remember, the range of System Variables should not cross with the array addreses. Edited by Inntele

Share this post


Link to post
Share on other sites
As promised, the library was expanded with universal FB for rolling average, for which the length of the array can be assigned arbitrarily in the range from 1 to 512 FB_Rolling_Average.zip

Share this post


Link to post
Share on other sites

Hello. Nine years later. Was there a finished code to share? I am trying to set up the same function in gxworks2.

Cheers

Share this post


Link to post
Share on other sites

This is library for FX, which you can adapt for Q.

FB_Rolling_Average.SUL

1 person likes this

Share this post


Link to post
Share on other sites
1 hour ago, Inntele said:
1 hour ago, Inntele said:

This is library for FX, which you can adapt for Q.

FB_Rolling_Average.SUL

This is library for FX, which you can adapt for Q.

FB_Rolling_Average.SUL

Great. I have imported it. But how do you suggest it could be adapted for GX? WSFL is missing for GX, and MEANP_M is called something else.

RI

Share this post


Link to post
Share on other sites

Yes, it could be adapted. Just need to search the instructions with similar fuctioning in Q/L Programming Manual.

Share this post


Link to post
Share on other sites
On 2018-09-03 at 5:14 PM, Inntele said:

Yes, it could be adapted. Just need to search the instructions with similar fuctioning in Q/L Programming Manual.

Sure. But the blocks were locked.

Downloaded mitsubishis blocks instead.

System Q - GX Works2 - Analog - q68ad_GW2_simple_v100a_e
https://se3a.mitsubishielectric.com/fa/sv/mymitsubishi/download_manager?id=8602&tab=3

 

Share this post


Link to post
Share on other sites
5 minutes ago, Rolf_Inge said:

Sure. But the blocks were locked.

It's locked with password?

Share this post


Link to post
Share on other sites

Now the lib is open)

 

FB_Rolling_Average.SUL

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0