Filtering out higest x% of the values in an array

A bit of background first...

I'm using an Arduino Uno to measure a square wave output from a speed sensor. My current plan (it's not running yet) is to measure a number of instantaneous (lets say 50-odd) values and then process the results to return a single "speed". I'll fine-tune the duration and filtering once I have seen how stable the sensor output is but for now I've set up a filter that removes all values that are not within 20% of the arithmetic mean. I would rather use a filter that first disregards the top 10% and bottom 10% (by value) of the data and then averages the remaining 80% however and I'm not sure of the most efficient way to do that. I think I could setup a nested loop to reorder all of the values numerically but I was hoping there was a more direct way to do that. Is there a way I can find the rank of a value within an array for instance?

Wingers

if you want to disregards the top 10% or so you must have an average. As the speed may vary (assumption) that is almost an impossibility…

Have you considered using interrupts and measure the time stamps of the changes. Might be easier…

Is that over a specific time? One second, one hour. or what. Sounds like you want a formula similar to the Social Security uses. ( take all the readings, discard the lowest, discard the largest), and average the rest. But, over 50 years?

What is the real question?

Are you really wanting an average of the last 5(or whatever) readings? Try average=(average*4+sensorValue)/5;