update 31
This commit is contained in:
parent
80ce638013
commit
28d51b685c
5 changed files with 11 additions and 18 deletions
|
@ -14,7 +14,6 @@ from .windowing import *
|
||||||
from .piir import *
|
from .piir import *
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from matplotlib.pylab import show
|
|
||||||
|
|
||||||
def analog(b, a):
|
def analog(b, a):
|
||||||
import sympy as sym
|
import sympy as sym
|
||||||
|
|
|
@ -26,20 +26,17 @@ def cleanplot():
|
||||||
return fig, ax
|
return fig, ax
|
||||||
|
|
||||||
def new_response(*args, **kwargs):
|
def new_response(*args, **kwargs):
|
||||||
fig = plt.figure()
|
fig, ax = plt.subplots()
|
||||||
ax = fig.gca()
|
|
||||||
response_setup(ax, *args, **kwargs)
|
response_setup(ax, *args, **kwargs)
|
||||||
return fig, ax
|
return fig, ax
|
||||||
|
|
||||||
def new_phase_response(*args, **kwargs):
|
def new_phase_response(*args, **kwargs):
|
||||||
fig = plt.figure()
|
fig, ax = plt.subplots()
|
||||||
ax = fig.gca()
|
|
||||||
phase_response_setup(ax, *args, **kwargs)
|
phase_response_setup(ax, *args, **kwargs)
|
||||||
return fig, ax
|
return fig, ax
|
||||||
|
|
||||||
def new_bode(magnitude_offset=0):
|
def new_bode(magnitude_offset=0):
|
||||||
fig = plt.figure()
|
fig, ax1 = plt.subplots()
|
||||||
ax1 = fig.gca()
|
|
||||||
ax2 = ax1.twinx()
|
ax2 = ax1.twinx()
|
||||||
ymin = -24 + magnitude_offset
|
ymin = -24 + magnitude_offset
|
||||||
ymax = 24 + magnitude_offset
|
ymax = 24 + magnitude_offset
|
||||||
|
|
|
@ -25,9 +25,7 @@ magnitude_x = lambda srate, size: np.arange(0, srate/2, srate/2/size)
|
||||||
degrees_clamped = lambda x: ((x*180/np.pi + 180) % 360) - 180
|
degrees_clamped = lambda x: ((x*180/np.pi + 180) % 360) - 180
|
||||||
|
|
||||||
def xsp(precision=4096):
|
def xsp(precision=4096):
|
||||||
"""create #precision log-spaced points from 20 to 20480 Hz"""
|
"""create #precision log-spaced points from 20 Hz (inclusive) to 20480 Hz (exclusive)"""
|
||||||
# i opt not to use steps or linspace here,
|
|
||||||
# as the current method is less error-prone for me.
|
|
||||||
xs = np.arange(0,precision)/precision
|
xs = np.arange(0,precision)/precision
|
||||||
return 20*1024**xs
|
return 20*1024**xs
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ def convolve_each(s, fir, mode='same', axis=0):
|
||||||
return np.apply_along_axis(lambda s: sig.fftconvolve(s, fir, mode), axis, s)
|
return np.apply_along_axis(lambda s: sig.fftconvolve(s, fir, mode), axis, s)
|
||||||
|
|
||||||
def count_channels(s):
|
def count_channels(s):
|
||||||
if len(s.shape) < 2:
|
if s.ndim < 2:
|
||||||
return 1
|
return 1
|
||||||
return s.shape[1]
|
return s.shape[1]
|
||||||
|
|
||||||
|
@ -55,8 +53,7 @@ def monoize(s):
|
||||||
existing mono signals are passed through unmodified."""
|
existing mono signals are passed through unmodified."""
|
||||||
channels = count_channels(s)
|
channels = count_channels(s)
|
||||||
if channels != 1:
|
if channels != 1:
|
||||||
s = np.sum(s, 1)
|
s = np.average(s, axis=1)
|
||||||
s /= channels
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def div0(a, b):
|
def div0(a, b):
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .util import lament, count_channels
|
from .util import lament, count_channels
|
||||||
|
|
||||||
# TODO: don't use wavfile, it breaks on perfectly good files
|
|
||||||
import scipy.io.wavfile as wav
|
|
||||||
import ewave
|
|
||||||
|
|
||||||
def wav_smart_read(fn):
|
def wav_smart_read(fn):
|
||||||
lament('wav_smart_read(): DEPRECATED; use wav_read instead.')
|
lament('wav_smart_read(): DEPRECATED; use wav_read instead.')
|
||||||
|
import scipy.io.wavfile as wav # don't use this, it fails to load good files
|
||||||
srate, s = wav.read(fn)
|
srate, s = wav.read(fn)
|
||||||
if s.dtype != np.float64:
|
if s.dtype != np.float64:
|
||||||
bits = s.dtype.itemsize*8
|
bits = s.dtype.itemsize*8
|
||||||
|
@ -15,12 +12,14 @@ def wav_smart_read(fn):
|
||||||
|
|
||||||
def wav_smart_write(fn, srate, s):
|
def wav_smart_write(fn, srate, s):
|
||||||
lament('wav_smart_write(): DEPRECATED; use wav_write instead.')
|
lament('wav_smart_write(): DEPRECATED; use wav_write instead.')
|
||||||
|
import scipy.io.wavfile as wav
|
||||||
si = np.zeros_like(s, dtype='int16')
|
si = np.zeros_like(s, dtype='int16')
|
||||||
bits = si.dtype.itemsize*8
|
bits = si.dtype.itemsize*8
|
||||||
si += np.clip(s*2**(bits - 1), -32768, 32767)
|
si += np.clip(s*2**(bits - 1), -32768, 32767)
|
||||||
wav.write(fn, srate, si)
|
wav.write(fn, srate, si)
|
||||||
|
|
||||||
def wav_read(fn):
|
def wav_read(fn):
|
||||||
|
import ewave
|
||||||
with ewave.open(fn) as f:
|
with ewave.open(fn) as f:
|
||||||
s = f.read()
|
s = f.read()
|
||||||
srate = f.sampling_rate
|
srate = f.sampling_rate
|
||||||
|
@ -32,6 +31,7 @@ def wav_read(fn):
|
||||||
return s, srate
|
return s, srate
|
||||||
|
|
||||||
def wav_write(fn, s, srate, dtype='h'):
|
def wav_write(fn, s, srate, dtype='h'):
|
||||||
|
import ewave
|
||||||
if dtype in ('b', 'h', 'i', 'l') and np.max(np.abs(s)) > 1:
|
if dtype in ('b', 'h', 'i', 'l') and np.max(np.abs(s)) > 1:
|
||||||
lament('wav_write(): WARNING; clipping')
|
lament('wav_write(): WARNING; clipping')
|
||||||
with ewave.open(fn, 'w', srate, dtype, count_channels(s)) as f:
|
with ewave.open(fn, 'w', srate, dtype, count_channels(s)) as f:
|
||||||
|
|
|
@ -43,7 +43,7 @@ blackman_nuttall = _h(0.3635819, 0.4891775, 0.1365995, 0.0106411)
|
||||||
blackman_harris = _h(0.35875, 0.48829, 0.14128, 0.01168)
|
blackman_harris = _h(0.35875, 0.48829, 0.14128, 0.01168)
|
||||||
nuttall = _h(0.355768, 0.487396, 0.144232, 0.012604)
|
nuttall = _h(0.355768, 0.487396, 0.144232, 0.012604)
|
||||||
flattop = _h(*_normalize(1, 1.93, 1.29, 0.388, 0.028)) # FTSRS
|
flattop = _h(*_normalize(1, 1.93, 1.29, 0.388, 0.028)) # FTSRS
|
||||||
#flattop_weird = _h(_normalize(1, 1.93, 1.29, 0.388, 0.032)) # ??? wtf
|
#flattop_weird = _h(*_normalize(1, 1.93, 1.29, 0.388, 0.032)) # ??? wtf
|
||||||
flattop_weird = _h(0.2156, 0.4160, 0.2781, 0.0836, 0.0069) # ??? scipy crap
|
flattop_weird = _h(0.2156, 0.4160, 0.2781, 0.0836, 0.0069) # ??? scipy crap
|
||||||
hann = _h(0.5, 0.5)
|
hann = _h(0.5, 0.5)
|
||||||
hamming_inexact = _h(0.54, 0.46)
|
hamming_inexact = _h(0.54, 0.46)
|
||||||
|
|
Loading…
Reference in a new issue