----- Original Message ----- From: "Jim Tellier" To: Sent: Thursday, September 11, 2003 3:28 PM Subject: Re: [PIC:] Mean averaging routine? > John Pearson wrote: > > > Is there a simple routine for finding a mean average? > and, > > But is there a simple way to eliminate the numbers that are not as common > as the majority. > If you want the arithmetic mean it's given by > (eqn 1) > > (V(min) + V(max) ) / 2 > So to do that in PIC assembly, you would need 2 variables (assuming 8-bit > arithmetic; if you want more resolution, you'll need some n-bit functions, > which are readily available). I'd name them > Vmin and Vmax. Then for some number of iterations, or samples, take each > new data value (Vnew) and compare it against Vmin: if it's smaller, replace > Vmin with Vnew, else check against Vmax: if it's larger, replace Vmax with > Vnew. Whenever you want to obtain the mean, just do eqn. 1 above. > If on the other hand you want the *median* value, that's the value of the > item in a set of values that has an equal number of other values above and > below it. I don't know of a method offhand that doesn't require storing all > of the incoming data values to compute the median. > I'm not sure what you mean by "eliminate the numbers that are not as common > as the majority": if you're computing the mean, it's *those* very values > that cause a running calculation of the mean to shift... so you wouldn't > want to discard them. Can you be more specific? > Jim I thought the mean is when you take a group of numbers and discard the ones that are very high and very low, and then average the remaining. That is median? Anyway, that is what I want to do, is to discard the very high and very low numbers and average the numbers that fall in the middle. Thanks John > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.