1
1
/*
2
- * Copyright (C) 2017 Eistec AB
2
+ * Copyright (C) 2017-2018 Eistec AB
3
3
*
4
4
* This file is subject to the terms and conditions of the GNU Lesser
5
5
* General Public License v2.1. See the file LICENSE in the top level
@@ -61,13 +61,14 @@ void spectrum_scanner(unsigned long interval_us)
61
61
/* Using expf(x) (natural exponent) gives quicker computations on Cortex-M0+,
62
62
* compared to using powf(10, x). */
63
63
/*
64
- * This was optimized by testing different combinations of expf, powf, logf, log10f:
64
+ * This was optimized by testing different combinations of expf, powf, logf, log10f, ldexp, ilogbf :
65
65
*
66
- * functions used | measurement iterations per 0.5 s on reference system (frdm-kw41z)
67
- * ------------------------------------------------------------------
68
- * expf, logf | 64
69
- * powf, log10f | 46
70
- * expf, log10f | 61
66
+ * functions used | measurement iterations per 0.5 s on reference system (frdm-kw41z)
67
+ * --------------------------------------------------------------------
68
+ * expf, logf | 64
69
+ * powf, log10f | 46
70
+ * expf, log10f | 61
71
+ * ldexpf, ilogbf | 82
71
72
* no-op (baseline) | 83 (but the measurements are useless)
72
73
*/
73
74
@@ -105,11 +106,11 @@ void spectrum_scanner(unsigned long interval_us)
105
106
}
106
107
/* Convert dB to pseudo-energy before summing together the
107
108
* measurements. "Pseudo" because we use the natural
108
- * exponential function e ^x instead of computing 10^x which
109
+ * exponential function 2 ^x instead of computing 10^x which
109
110
* would be required if we needed the real measured energy.
110
111
* There is no need to know the real energy level because we
111
112
* will be converting back to dB again before printing. */
112
- ed_average [k ][ch ] += expf (( float ) level / 128.f );
113
+ ed_average [k ][ch ] += ldexpf ( 1.f , level );
113
114
}
114
115
}
115
116
++ count ;
@@ -125,10 +126,10 @@ void spectrum_scanner(unsigned long interval_us)
125
126
print ("] " , 2 );
126
127
for (unsigned int ch = IEEE802154_CHANNEL_MIN ; ch <= IEEE802154_CHANNEL_MAX ; ++ ch ) {
127
128
/* Compute the average pseudo-energy and convert back to dB */
128
- ed_average [ k ][ ch ] = logf (ed_average [k ][ch ] / count ) * 128.f ;
129
+ uint32_t ed = ilogbf (ed_average [k ][ch ] / count );
129
130
print_u32_dec (ch );
130
131
print (": " , 2 );
131
- print_float ( ed_average [ k ][ ch ], 4 );
132
+ print_s32_dec ( ed );
132
133
print (", " , 2 );
133
134
}
134
135
print ("\n" , 1 );
0 commit comments