Help - Search - Members - Calendar
Full Version: Rolling Average / exponential smoothing
Forums.MrPLC.com > PLCs and Supporting Devices > Mitsubishi
BenJones
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
kaare_t
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?
Inntele
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.
BenJones
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)













QUOTE (Inntele @ Nov 16 2009, 06:20 PM) *
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.

Inntele
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,Click to view attachment
BenJones
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.



QUOTE (Inntele @ Nov 17 2009, 03:32 PM) *
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,Click to view attachment

waynes
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
Inntele
QUOTE (BenJones @ Nov 18 2009, 04:18 PM) *
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.


Hi Ben,

Sorry, I did mistake, but it can be solve very easy wink.gif Today I'll publish the universal FB with the filter up to 512 words. Wait for, please smile.gif
Inntele
QUOTE (Inntele @ Nov 18 2009, 06:47 PM) *
QUOTE (BenJones @ Nov 18 2009, 04:18 PM) *
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.


Hi Ben,

Sorry, I did mistake, but it can be solve very easy wink.gif Today I'll publish the universal FB with the filter up to 512 words. Wait for, please smile.gif


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. Click to view attachment graduated.gif
BenJones
Hi Waynes, yes thats a way to do it, thaks for your advise !



QUOTE (waynes @ Nov 18 2009, 07:28 AM) *
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

BenJones
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 smile.gif

Many thanks again,

Ben
Inntele
QUOTE (BenJones @ Nov 19 2009, 03:38 PM) *
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 smile.gif

Many thanks again,

Ben


Dear Ben,

In you first post you wrote:
QUOTE (BenJones)
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.


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. yes.gif

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. lookaround.gif

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. smile.gif
kaare_t
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! smile.gif
Inntele
QUOTE (kaare_t @ Nov 20 2009, 01:10 AM) *
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! smile.gif


Thank you for good words, 'kaare_t' smile.gif

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) angry.gif

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". smile.gif
BenJones
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 smile.gif

Ben




QUOTE (Inntele @ Nov 19 2009, 06:04 PM) *
QUOTE (kaare_t @ Nov 20 2009, 01:10 AM) *
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! smile.gif


Thank you for good words, 'kaare_t' smile.gif

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) angry.gif

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". smile.gif

Inntele
QUOTE (BenJones @ Nov 20 2009, 09:29 PM) *
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 smile.gif

Ben


Don't mention it, Ben smile.gif It wasn't difficult task for me and it's not busy so much time. Moreover, I like job and a job likes me too wink.gif

Already I've answered on your question several posts above when published the FB:

QUOTE (Inntele)
... 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


However, it's not a problem, I can do the similar FB with "open" array, which start address will be user-defined smile.gif
Inntele
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.

Click to view attachment


Below you can see screenshot of test.

Click to view attachment

Is important to remember, the range of System Variables should not cross with the array addreses.
Inntele
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 smile.gif

Click to view attachment
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.