Date:2010-11-17 01:16:41 (9 years 4 days ago)
Author:Werner Almesberger
Commit:c4d906bd8b34fb24ebe0f7e6a6d61b2fdc742b5d
Message:usrp/range: obtain avg/min/max from a series of values and eliminate outliers

Files: usrp/range (1 diff)

Change Details

usrp/range
1#!/usr/bin/perl
2
3
4sub usage
5{
6    print STDERR "usage: $0 [[-v] tolerance]\n";
7    exit(1);
8}
9
10
11$tol = 999;
12
13if (@ARGV) {
14    $tol = shift @ARGV;
15    if ($tol eq "-v") {
16    $verbose = 1;
17    $tol = shift @ARGV;
18    }
19    &usage unless $tol =~ /^[0-9.]+$/;
20    &usage if @ARGV;
21}
22
23while (<>) {
24    chop;
25    push(@v, $_);
26    $s += $_;
27}
28$avg = $s/@v;
29
30$n = 0;
31for (@v) {
32    $n++;
33    if ($_ < $avg-$tol || $_ > $avg+$tol) {
34    print STDERR "sample $n is outlier: $_\n" if $verbose;
35    next;
36    }
37    $sum += $_;
38    $ns++;
39    $min = $_ if $_ < $min || !defined $min;
40    $max = $_ if $_ > $max || !defined $max;
41}
42
43if (!$ns) {
44    print STDERR "no samples\n";
45    exit(1);
46
47}
48
49print $sum/$ns, " $min $max\n";

Archive Download the corresponding diff file



interactive