where A is the corrected answer, M is the arithmetic mean of the results (average), P is the number of samples greater than M, N is the number of samples less than M, TD is the total deviation from mean (absolute value and one direction only), and n is the number of samples.

For example, consider a simple system taking 10 samples and yielding results of 10, 10, 10, 10, 10, 20, 10, 10, 10, and 10. Ignoring the fact that a human will discard the obvious erroneous answer, process the following. The mean is 11. The total number of samples positive is 1, and the total number of samples negative is 9 (so P − N = −8). Total deviation in either direction from mean is 9 (1 times 9 samples low, or 9 times 1 sample high). The deviation factor is −72, which divided by n squared (100) provides a correction of −0.72, for a derived answer of 10.28.

The algorithm works well for random scattering, and reasonably well for spurious interference, such as in the previous example. Note that sinusoidal error will result in P − N of zero, or no deviation from average. An interesting homework assignment for the mathematician in the crowd is to calculate the rejection ratio for various types of interference at different values of n.

Go to *www.elecdesign.com* for an M68000 assembly-language subroutine sample implementation. It assumes a 12-bit ADC and 32-bit registers.