From 7d1bf429ba84ad4f807362ca2306381fb5ac0809 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 2 Jan 2019 04:04:21 -0800 Subject: [PATCH] update 48 --- lib/bs.py | 2 +- lib/fft.py | 4 +--- lib/util.py | 14 ++++++-------- lib/windowing.py | 4 ---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/bs.py b/lib/bs.py index 1f55f96..1a168ec 100644 --- a/lib/bs.py +++ b/lib/bs.py @@ -79,7 +79,7 @@ def BS_plot(ys, g10=None, g70=None, threshold=None, fig=None, ax=None): def normalize(s, srate): - """performs BS.1770-3 normalization and returns inverted gain.""" + """performs BS.1770-3 normalization and returns reciprocal gain.""" db = BS1770_3(s, srate) rms = 10**(db/20) return s/rms, rms diff --git a/lib/fft.py b/lib/fft.py index cb9af05..52d8cd8 100644 --- a/lib/fft.py +++ b/lib/fft.py @@ -1,5 +1,3 @@ -from . import rfft - import numpy as np import scipy.signal as sig @@ -30,7 +28,7 @@ def magnitudes(s, size=8192): count = 0 for i in range(0, L - 1, int(step)): windowed = s[i:i+win_size]*win - power = np.abs(rfft(windowed, size))**2 + power = np.abs(np.fft.rfft(windowed, 2 * size))**2 # this scraps the nyquist value to get exactly 'size' outputs yield power[0:size] count += 1 diff --git a/lib/util.py b/lib/util.py index 9262ead..6d5d49d 100644 --- a/lib/util.py +++ b/lib/util.py @@ -36,19 +36,17 @@ def warp(w): def ceil2(x): - return np.power(2, np.ceil(np.log2(x)).astype(int)) + x = int(x) + assert x > 0 + return 2**(x - 1).bit_length() def pad2(x): - return np.r_[x, np.zeros(ceil2(len(x)) - len(x))] - - -def rfft(src, size): - return np.fft.rfft(src, size*2) + return np.r_[x, np.zeros(ceil2(len(x)) - len(x), x.dtype)] def magnitude(src, size): - return 10*np.log10(np.abs(rfft(src, size))**2)[0:size] + return 10*np.log10(np.abs(np.fft.rfft(src, 2 * size))**2)[0:size] # x axis for plotting above magnitude @@ -70,7 +68,7 @@ def xsp(precision=4096): def blocks(a, step, size=None): - """break an iterable into chunks""" + """break an array into chunks""" if size is None: size = step for start in range(0, len(a), step): diff --git a/lib/windowing.py b/lib/windowing.py index 3847154..3dbda41 100644 --- a/lib/windowing.py +++ b/lib/windowing.py @@ -97,7 +97,3 @@ def welch(N): @_deco_win def sinc(N): return np.sinc((np.arange(N) - (N - 1)/2)/2) - - -def winmod(f): - return lambda N: f(N + 2)[1:-1]