Replace delete implementation with ulab delete
This commit is contained in:
parent
8e8aa263e9
commit
d5ab0cf716
2 changed files with 7 additions and 13 deletions
|
|
@ -12,9 +12,3 @@ def append(arr, values, axis=None):
|
||||||
values = values.flatten()
|
values = values.flatten()
|
||||||
axis = len(arr.shape)-1
|
axis = len(arr.shape)-1
|
||||||
return np.concatenate((arr, values), axis=axis)
|
return np.concatenate((arr, values), axis=axis)
|
||||||
|
|
||||||
|
|
||||||
def delete(arr, obj, axis=None):
|
|
||||||
mask = np.ones(len(arr), dtype=np.bool)
|
|
||||||
mask[obj] = 0
|
|
||||||
return arr[mask]
|
|
||||||
|
|
@ -4,7 +4,7 @@ from ulab import numpy
|
||||||
from ulab import numpy as np
|
from ulab import numpy as np
|
||||||
from ulab import scipy as spy
|
from ulab import scipy as spy
|
||||||
|
|
||||||
from ...numpy import (atleast_1d, poly, asarray, prod, size, append, nonzero, zeros_like, delete, isreal)
|
from ...numpy import (atleast_1d, poly, asarray, prod, size, append, nonzero, zeros_like, isreal)
|
||||||
|
|
||||||
def butter(N, Wn, btype='low', analog=False, output='ba', fs=None):
|
def butter(N, Wn, btype='low', analog=False, output='ba', fs=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -735,13 +735,13 @@ def zpk2sos(z, p, k, pairing='nearest'):
|
||||||
# Select the next "worst" pole
|
# Select the next "worst" pole
|
||||||
p1_idx = np.argmin(abs(1 - abs(p)))
|
p1_idx = np.argmin(abs(1 - abs(p)))
|
||||||
p1 = p[p1_idx]
|
p1 = p[p1_idx]
|
||||||
p = delete(p, p1_idx)
|
p = np.delete(p, p1_idx)
|
||||||
# Pair that pole with a zero
|
# Pair that pole with a zero
|
||||||
if isreal(p1) and np.sum([isreal(p)]) == 0:
|
if isreal(p1) and np.sum([isreal(p)]) == 0:
|
||||||
# Special case to set a first-order section
|
# Special case to set a first-order section
|
||||||
z1_idx = _nearest_real_complex_idx(z, p1, 'real')
|
z1_idx = _nearest_real_complex_idx(z, p1, 'real')
|
||||||
z1 = z[z1_idx]
|
z1 = z[z1_idx]
|
||||||
z = delete(z, z1_idx)
|
z = np.delete(z, z1_idx)
|
||||||
p2 = z2 = 0
|
p2 = z2 = 0
|
||||||
else:
|
else:
|
||||||
if not isreal(p1) and np.sum(isreal(z)) == 1:
|
if not isreal(p1) and np.sum(isreal(z)) == 1:
|
||||||
|
|
@ -753,7 +753,7 @@ def zpk2sos(z, p, k, pairing='nearest'):
|
||||||
# Pair the pole with the closest zero (real or complex)
|
# Pair the pole with the closest zero (real or complex)
|
||||||
z1_idx = np.argmin(abs(p1 - z))
|
z1_idx = np.argmin(abs(p1 - z))
|
||||||
z1 = z[z1_idx]
|
z1 = z[z1_idx]
|
||||||
z = delete(z, z1_idx)
|
z = np.delete(z, z1_idx)
|
||||||
# Now that we have p1 and z1, figure out what p2 and z2 need to be
|
# Now that we have p1 and z1, figure out what p2 and z2 need to be
|
||||||
if not isreal(p1):
|
if not isreal(p1):
|
||||||
if not isreal(z1): # complex pole, complex zero
|
if not isreal(z1): # complex pole, complex zero
|
||||||
|
|
@ -764,7 +764,7 @@ def zpk2sos(z, p, k, pairing='nearest'):
|
||||||
z2_idx = _nearest_real_complex_idx(z, p1, 'real')
|
z2_idx = _nearest_real_complex_idx(z, p1, 'real')
|
||||||
z2 = z[z2_idx]
|
z2 = z[z2_idx]
|
||||||
assert isreal(z2)
|
assert isreal(z2)
|
||||||
z = delete(z, z2_idx)
|
z = np.delete(z, z2_idx)
|
||||||
else:
|
else:
|
||||||
if not isreal(z1): # real pole, complex zero
|
if not isreal(z1): # real pole, complex zero
|
||||||
z2 = np.conjugate(z1)
|
z2 = np.conjugate(z1)
|
||||||
|
|
@ -785,9 +785,9 @@ def zpk2sos(z, p, k, pairing='nearest'):
|
||||||
z2_idx = _nearest_real_complex_idx(z, p2, 'real')
|
z2_idx = _nearest_real_complex_idx(z, p2, 'real')
|
||||||
z2 = z[z2_idx]
|
z2 = z[z2_idx]
|
||||||
assert isreal(z2)
|
assert isreal(z2)
|
||||||
z = delete(z, z2_idx)
|
z = np.delete(z, z2_idx)
|
||||||
|
|
||||||
p = delete(p, p2_idx)
|
p = np.delete(p, p2_idx)
|
||||||
|
|
||||||
p_sos = np.array(p_sos, dtype=np.complex)
|
p_sos = np.array(p_sos, dtype=np.complex)
|
||||||
p_sos[si] = np.array([p1, p2], dtype=np.complex)
|
p_sos[si] = np.array([p1, p2], dtype=np.complex)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue