@@ -16,12 +16,12 @@ def normalized_rms(values):
16
16
return math .sqrt (samples_sum / len (values ))
17
17
18
18
def normalized_rms_ulab (values ):
19
+ # this function works with ndarrays only
19
20
minbuf = ulab .numerical .mean (values )
20
21
values = values - minbuf
21
22
samples_sum = ulab .numerical .sum (values * values )
22
23
return math .sqrt (samples_sum / len (values ))
23
24
24
-
25
25
# Instead of using sensor data, we generate some data
26
26
# The amplitude is 5000 so the rms should be around 5000/1.414 = 3536
27
27
nums_list = [int (8000 + math .sin (i ) * 5000 ) for i in range (100 )]
@@ -33,8 +33,10 @@ def timeit(s, f, n=100):
33
33
x = f ()
34
34
t1 = time .monotonic_ns ()
35
35
r = (t1 - t0 ) * 1e-6 / n
36
- print ("%-20s : %8.3fms [result=%f]" % (s , r , x ))
36
+ print ("%-30s : %8.3fms [result=%f]" % (s , r , x ))
37
37
38
38
print ("Computing the RMS value of 100 numbers" )
39
39
timeit ("traditional" , lambda : normalized_rms (nums_list ))
40
- timeit ("ulab" , lambda : normalized_rms_ulab (nums_array ))
40
+ timeit ("ulab, with ndarray, some implementation in python" , lambda : normalized_rms_ulab (nums_array ))
41
+ timeit ("ulab only, with list" , lambda : ulab .numerical .std (nums_list ))
42
+ timeit ("ulab only, with ndarray" , lambda : ulab .numerical .std (nums_array ))
0 commit comments