How do you find the mean of a FIFO array discarding extremes?

fishin_fl

Member
Join Date
Sep 2014
Location
Middleburg, Florida
Posts
17
I am using a distance laser to bring in an analog value. I have converted the value to inches and filling an array using FIFO using RSLogix 5000.

I know you can average an array with the AVE instruction, but I am wanting to discard the outliers(extremes).

Can someone assist me in completing this task?
 
Last edited:
I guess I would use a sort instruction. Say FIFOArray[0-9,0-9] Then copy FIFOArray[1-8,1-8] to ArrayAvg[0-7,0-7] then average that.
Because if you sort it then the highest (9) will be at one end and the lowest (0) at the other.
 
JaxGTO thank you for your response. After I wrote the question I did sort the array. I will try your suggestion.

I was hoping to find some way to replicate the excel function, TRIMMEAN(array,percent). The reason is that I may have multiple points or noise that may cause skewing the mean.
 
Cwal61 thank you for laying out the ladder. I will attempt today.

What about using the FSC instruction and or FAL instruction? Could I search thru the array by element, compare to percentage of the mean of first array, then if within tolerance, move each element that is true to another array, then average?

Now if I had more the 2 lows or highs they are gone.
 
Last edited:
You could use 2 FSC instructions on the Sorted array. One to find High and One to find Low. Finding High is straight forward first position found.

Finding the last low would require you to capture the position as each position is found unlatch the inhibit to continue searching. So, if found and not done then capture position and unlatch inhibit bit. Once FSC is done then the last capture position is your low position.

For the Average.
To get your Start position would be Low position + 1
To get your length. High position - Low position
 
cwal61,
Looking at the logic you presented wouldn't the logic only remove the last 2 elements of the fifo? So in essence it would average array elements 1 -28 instead of 1 -30? Thanks

Chris
 
yes, it would Average 1-28 if the size of the Array = 30

30 Elements In AB land, equals Element 0-29. The Size instruction will report out as 30. So 30-2=28 and starting the average at Element 1 thru 28 thereby removing element 0 and 29.

the OP wanted to remove the low and high values before average.
 
Ok I have the sorting and averaging good now. Thanks.

Question is how do I trigger a ONS to fill the array when the periodic task runs on CompactLogix rslogix5000?

I need a status bit within the 100ms task to trigger the load to array. I tried S:FS but it does not work. My understanding that is paired with the Maintask.
 
The S:FS is the first scan bit. It's only true for first scan after PLC power cycle.

short an OTL in the first rung of periodic task. Use OTL bit to trigger load. After load rung then next rung short an OTU to reset.

_________(OTL)
OTL
_||________(FFL)

__________(OTU)
 
Warning, nerd hour content ahead :geek:



While sorting and then excluding the first and last elements is conceptually easy to understand, it is not the optimal approach in terms of efficiency. In computer science Quicksort is generally considered a very efficient sorting algorithm for practical applications. Its' efficiency is typically of order(n log n), worst case order(n^2) where n is the number of elements in the array. What this means, is that as the array grows larger, the amount of time it takes to sort grows faster than the size of the array. Sorting is time consuming, PLC's don't like time consuming work as it conflicts with the fast and steady cycle times that we desire. Therefore sorting is something I try to avoid when it is not necessary. One pass over all elements of your fifo array allows you to find the lowest and highest value, add all values except the lowest and highest and divide by the number of elements minus 2. That is an operation that scales linearly with the number of elements, way more efficient than sorting. You did not mention the number of elements. If it is small then nothing to worry about. For a large number of elements, I would opt for the more efficient approach.



End of computer science 101 👨🏻‍🏫, apologies for the interruption, normal operation may now resume :)
 
Warning, nerd hour content ahead :geek:

...... Sorting is time consuming, PLC's don't like time consuming work as it conflicts with the fast and steady cycle times that we desire.


Who needs "fast and steady cycle times"



One pass over all elements of your fifo array allows you to find the lowest and highest value


One SRT instruction puts the elements into ascending order, just need to average the "middle" elements, another single instruction, AVE



One pass over all elements of your fifo array allows you to find the lowest and highest value


Surely you would need two passes ???


EDIT: No sorry, you can do it in one pass, but you would need to do it one element per scan at a time.....


Say you had a 1,000 element array, it would take 1000 scans of your code to do this, at 5mS per scan, on an array of 1000 elements, it would take 5 seconds to find highest and lowest. What if the data changes between scans ??
 
Last edited:

Similar Topics

Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
130
I have tested every screen and no single screen individually has this fault pop up, but when I compile and send to the PanelView it comes up. If I...
Replies
4
Views
187
Hi, One of my customers has an old fabric tensile testing machine. The IC # AD7501KN of its controller has malfunctioned. This IC is related to...
Replies
1
Views
86
Hello everyone, I am a student and would like to take the next step and learn FactoryTalk (Batch preferably) and how to create HMIs etc. Would...
Replies
4
Views
496
Hi, Have a look at this picture... How can I find out the memory address of this tag? It was created by adding it to DB "Data_block_1", but I...
Replies
6
Views
1,069
Back
Top Bottom