<ipython-input-2-5aa2c85ecb9b>:12: RuntimeWarning: divide by zero encountered in log10
return 10*np.log10(x)
<ipython-input-2-5aa2c85ecb9b>:12: RuntimeWarning: divide by zero encountered in log10
return 10*np.log10(x)
<ipython-input-2-5aa2c85ecb9b>:12: RuntimeWarning: divide by zero encountered in log10
return 10*np.log10(x)
Modified db() to find out why:
def db(x):
""" Convert linear value to dB value """
with np.errstate(divide='raise'):
try:
result = 10.0 * np.log10(x)
except FloatingPointError as err:
print("*** db: Oops, RunTimeWarning err:{}\nx={}".format(err, x))
sys.exit(86)
return result
The real issue is the code that is generating x here [15]:
chan0_val = []
chan1_val = []
chan2_val = []
first_time = True
for p in period:
t = np.arange(0, M*P*W)
x = np.sin(t * p)
X_psd = pfb_spectrometer(x, n_taps=M, n_chan=P, n_int=256, window_fn="hamming")
if first_time:
first_time = False
print("DEBUG ")
chan0_val.append(X_psd[0, 0])
chan1_val.append(X_psd[0, 1])
chan2_val.append(X_psd[0, 2])
The first pass through the loop, Xpsd is all zeros. That's why the first element of chan{0,1,2}_val = 0 causing db() to throw an exception. So, why was x = 0? x = np.sin(t * p) and the first value of t = 0.
My simple-minded fix:
x = np.sin(t * p) + 0.001 # the old "fudge factor" as it were
At the end of running the notebook, I saw this:
Modified db() to find out why:
As you can see, the first element is 0 and it comes from here:
So, all 3 db() calculations fail with arguments chan0_val, chan1_val, and chan2_val. All 3 channel arrays have a 0 in the first element.
The real issue is the code that is generating x here [15]:
The first pass through the loop, Xpsd is all zeros. That's why the first element of chan{0,1,2}_val = 0 causing db() to throw an exception. So, why was x = 0? x = np.sin(t * p) and the first value of t = 0.
My simple-minded fix: x = np.sin(t * p) + 0.001 # the old "fudge factor" as it were
Now, it sails through just fine.