update 48
This commit is contained in:
parent
6c1f0a4f3a
commit
7d1bf429ba
4 changed files with 8 additions and 16 deletions
|
@ -79,7 +79,7 @@ def BS_plot(ys, g10=None, g70=None, threshold=None, fig=None, ax=None):
|
||||||
|
|
||||||
|
|
||||||
def normalize(s, srate):
|
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)
|
db = BS1770_3(s, srate)
|
||||||
rms = 10**(db/20)
|
rms = 10**(db/20)
|
||||||
return s/rms, rms
|
return s/rms, rms
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from . import rfft
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.signal as sig
|
import scipy.signal as sig
|
||||||
|
|
||||||
|
@ -30,7 +28,7 @@ def magnitudes(s, size=8192):
|
||||||
count = 0
|
count = 0
|
||||||
for i in range(0, L - 1, int(step)):
|
for i in range(0, L - 1, int(step)):
|
||||||
windowed = s[i:i+win_size]*win
|
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
|
# this scraps the nyquist value to get exactly 'size' outputs
|
||||||
yield power[0:size]
|
yield power[0:size]
|
||||||
count += 1
|
count += 1
|
||||||
|
|
14
lib/util.py
14
lib/util.py
|
@ -36,19 +36,17 @@ def warp(w):
|
||||||
|
|
||||||
|
|
||||||
def ceil2(x):
|
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):
|
def pad2(x):
|
||||||
return np.r_[x, np.zeros(ceil2(len(x)) - len(x))]
|
return np.r_[x, np.zeros(ceil2(len(x)) - len(x), x.dtype)]
|
||||||
|
|
||||||
|
|
||||||
def rfft(src, size):
|
|
||||||
return np.fft.rfft(src, size*2)
|
|
||||||
|
|
||||||
|
|
||||||
def magnitude(src, size):
|
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
|
# x axis for plotting above magnitude
|
||||||
|
@ -70,7 +68,7 @@ def xsp(precision=4096):
|
||||||
|
|
||||||
|
|
||||||
def blocks(a, step, size=None):
|
def blocks(a, step, size=None):
|
||||||
"""break an iterable into chunks"""
|
"""break an array into chunks"""
|
||||||
if size is None:
|
if size is None:
|
||||||
size = step
|
size = step
|
||||||
for start in range(0, len(a), step):
|
for start in range(0, len(a), step):
|
||||||
|
|
|
@ -97,7 +97,3 @@ def welch(N):
|
||||||
@_deco_win
|
@_deco_win
|
||||||
def sinc(N):
|
def sinc(N):
|
||||||
return np.sinc((np.arange(N) - (N - 1)/2)/2)
|
return np.sinc((np.arange(N) - (N - 1)/2)/2)
|
||||||
|
|
||||||
|
|
||||||
def winmod(f):
|
|
||||||
return lambda N: f(N + 2)[1:-1]
|
|
||||||
|
|
Loading…
Reference in a new issue