IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2010-11-12 15:48:20 (13 years 4 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 417ef7b8c16e713d53a912efa3053968a7d5881f |
Message: | usrp/p: cleanup and more command-line control - usrp/p.c (find_peak, main): moved data processing to separate function - usrp/p.c (find_peak, usage, main): new option -s skip to set the number of samples to skip (default: 0) - usrp/p.c (find_peak, usage, main): new option -d to dump the histogram instead of picking the peak - usrp/p.c (find_peak, usage, main): the percentile can now be set on the command line (default: 0.9) |
Files: |
usrp/p.c (4 diffs) |
Change Details
usrp/p.c | ||
---|---|---|
1 | 1 | #include <stdlib.h> |
2 | 2 | #include <stdio.h> |
3 | #include <unistd.h> | |
3 | 4 | #include <math.h> |
4 | 5 | #include <sys/types.h> |
5 | 6 | |
6 | 7 | |
7 | #define PERC 0.9 | |
8 | #define SKIP 1000000 | |
8 | #define PERC_DEFAULT 0.9 | |
9 | 9 | |
10 | 10 | |
11 | 11 | static int comp(const void *_a, const void *_b) |
... | ... | |
17 | 17 | } |
18 | 18 | |
19 | 19 | |
20 | int main(int argc, char **argv) | |
20 | static void find_peak(int skip, float percentile, int dump) | |
21 | 21 | { |
22 | 22 | float max = 0; |
23 | 23 | float c[2], a; |
24 | 24 | float *rec = NULL; |
25 | int e = 0, n = 0, skip = SKIP; | |
25 | int e = 0, n = 0; | |
26 | 26 | |
27 | 27 | while (1) { |
28 | 28 | size_t s; |
... | ... | |
33 | 33 | break; |
34 | 34 | if (s < 0) { |
35 | 35 | perror("read"); |
36 | return 1; | |
36 | exit(1); | |
37 | 37 | } |
38 | 38 | } |
39 | 39 | if (skip) { |
... | ... | |
54 | 54 | rec[n] = a; |
55 | 55 | n++; |
56 | 56 | } |
57 | ||
58 | if (skip >= n) { | |
59 | fprintf(stderr, "cannot skip %d of %d entries\n", skip, n); | |
60 | exit(1); | |
61 | } | |
62 | rec += skip; | |
63 | n -= skip; | |
64 | ||
57 | 65 | qsort(rec, n, sizeof(float), comp); |
58 | printf("%f %f\n", max, rec[(int) (PERC*n)]); | |
59 | #if 0 | |
60 | int i; | |
61 | 66 | |
62 | for (i = 0; i < n; i += 1000) | |
63 | printf("%f %f\n", (double) i/n, rec[i]); | |
64 | #endif | |
67 | if (!dump) | |
68 | printf("%f %f\n", max, rec[(int) (percentile*n)]); | |
69 | else { | |
70 | int i; | |
71 | ||
72 | for (i = 0; i < n; i += 1000) | |
73 | printf("%f %f\n", (double) i/n, rec[i]); | |
74 | } | |
75 | } | |
76 | ||
77 | ||
78 | static void usage(const char *name) | |
79 | { | |
80 | fprintf(stderr, | |
81 | "usage: %s [-s skip] [percentile]\n" | |
82 | " %s [-s skip] -d\n\n" | |
83 | " percentile select the specified percentile (default: %g)\n\n" | |
84 | " -d dump the histogram\n" | |
85 | " -s skip skip this number of samples from the beginning (default: 0)\n" | |
86 | , name, name, PERC_DEFAULT); | |
87 | exit(1); | |
88 | } | |
89 | ||
90 | ||
91 | int main(int argc, char **argv) | |
92 | { | |
93 | int dump = 0, skip = 0; | |
94 | float perc = PERC_DEFAULT; | |
95 | int c; | |
96 | ||
97 | while ((c = getopt(argc, argv, "ds:")) != EOF) | |
98 | switch (c) { | |
99 | case 'd': | |
100 | dump = 1; | |
101 | break; | |
102 | case 's': | |
103 | skip = atoi(optarg); | |
104 | break; | |
105 | default: | |
106 | usage(*argv); | |
107 | } | |
108 | ||
109 | switch (argc-optind) { | |
110 | case 0: | |
111 | break; | |
112 | case 1: | |
113 | if (dump) | |
114 | usage(*argv); | |
115 | perc = atof(argv[optind]); | |
116 | break; | |
117 | default: | |
118 | usage(*argv); | |
119 | } | |
120 | ||
121 | find_peak(skip, perc, dump); | |
122 | ||
65 | 123 | return 0; |
66 | 124 | } |