@@ -16,12 +16,12 @@ def normalized_rms(values):
1616 return math .sqrt (samples_sum / len (values ))
1717
1818def normalized_rms_ulab (values ):
19+ # this function works with ndarrays only
1920 minbuf = ulab .numerical .mean (values )
2021 values = values - minbuf
2122 samples_sum = ulab .numerical .sum (values * values )
2223 return math .sqrt (samples_sum / len (values ))
2324
24-
2525# Instead of using sensor data, we generate some data
2626# The amplitude is 5000 so the rms should be around 5000/1.414 = 3536
2727nums_list = [int (8000 + math .sin (i ) * 5000 ) for i in range (100 )]
@@ -33,8 +33,10 @@ def timeit(s, f, n=100):
3333 x = f ()
3434 t1 = time .monotonic_ns ()
3535 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 ))
3737
3838print ("Computing the RMS value of 100 numbers" )
3939timeit ("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