11import time
22import math
3- import ulab . numpy
3+ from ulab import numpy as np
44
55def mean (values ):
66 return sum (values ) / len (values )
@@ -16,15 +16,15 @@ def normalized_rms(values):
1616
1717def normalized_rms_ulab (values ):
1818 # this function works with ndarrays only
19- minbuf = ulab . numpy .mean (values )
19+ minbuf = np .mean (values )
2020 values = values - minbuf
21- samples_sum = ulab . numpy .sum (values * values )
21+ samples_sum = np .sum (values * values )
2222 return math .sqrt (samples_sum / len (values ))
2323
2424# Instead of using sensor data, we generate some data
2525# The amplitude is 5000 so the rms should be around 5000/1.414 = 3536
2626nums_list = [int (8000 + math .sin (i ) * 5000 ) for i in range (100 )]
27- nums_array = ulab . numpy .array (nums_list )
27+ nums_array = np .array (nums_list )
2828
2929def timeit (s , f , n = 100 ):
3030 t0 = time .monotonic_ns ()
@@ -37,5 +37,5 @@ def timeit(s, f, n=100):
3737print ("Computing the RMS value of 100 numbers" )
3838timeit ("traditional" , lambda : normalized_rms (nums_list ))
3939timeit ("ulab, with ndarray, some implementation in python" , lambda : normalized_rms_ulab (nums_array ))
40- timeit ("ulab only, with list" , lambda : ulab . numpy .std (nums_list ))
41- timeit ("ulab only, with ndarray" , lambda : ulab . numpy .std (nums_array ))
40+ timeit ("ulab only, with list" , lambda : np .std (nums_list ))
41+ timeit ("ulab only, with ndarray" , lambda : np .std (nums_array ))
0 commit comments