4 * Throws out the highest and lowest values then averages what's left
6 template <typename T
, size_t N
>
11 * Adds a value to the accumulator, returns 0
12 * if the accumulator has filled a complete cycle
15 unsigned int add(T item
)
17 _data
[_counter
] = item
;
18 _counter
= (_counter
+ 1) % N
;
23 * Resets the accumulator and position
28 memset(_data
, 0, sizoe(_data
));
32 * Calculate the MedianAvg
36 return calc_scaled() / scale();
40 * Calculate the MedianAvg but without dividing by count
41 * Useful for preserving precision when applying external scaling
45 T minVal
, maxVal
, retVal
;
46 maxVal
= minVal
= retVal
= _data
[0];
47 // Find the minumum and maximum elements in the list
48 // while summing all the values
49 for (unsigned int i
= 1; i
< N
; ++i
)
58 // Subtract out the min and max values to discard them
59 return (retVal
- (minVal
+ maxVal
));
63 * Scale of the value returned by calc_scaled()
64 * Divide by this to convert from unscaled to original units
66 size_t scale() const { return N
- 2; }
69 * Operator to just assign as type
71 operator T() const { return calc(); }
75 unsigned int _counter
;