本文整理汇总了Python中scipy.signal.deconvolve方法的典型用法代码示例。如果您正苦于以下问题:Python signal.deconvolve方法的具体用法?Python signal.deconvolve怎么用?Python signal.deconvolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.deconvolve方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: poly2lsf
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def poly2lsf(a):
a = a / a[0]
A = np.r_[a, 0.0]
B = A[::-1]
P = A - B
Q = A + B
P = deconvolve(P, np.array([1.0, -1.0]))[0]
Q = deconvolve(Q, np.array([1.0, 1.0]))[0]
roots_P = np.roots(P)
roots_Q = np.roots(Q)
angles_P = np.angle(roots_P[::2])
angles_Q = np.angle(roots_Q[::2])
angles_P[angles_P < 0.0] += np.pi
angles_Q[angles_Q < 0.0] += np.pi
lsf = np.sort(np.r_[angles_P, angles_Q])
return lsf
示例2: poly2lsf
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def poly2lsf(a):
a = a / a[0]
A = np.r_[a, 0.0]
B = A[::-1]
P = A - B
Q = A + B
P = deconvolve(P, np.array([1.0, -1.0]))[0]
Q = deconvolve(Q, np.array([1.0, 1.0]))[0]
roots_P = np.roots(P)
roots_Q = np.roots(Q)
angles_P = np.angle(roots_P[::2])
angles_Q = np.angle(roots_Q[::2])
angles_P[angles_P < 0.0] += np.pi
angles_Q[angles_Q < 0.0] += np.pi
lsf = np.sort(np.r_[angles_P, angles_Q])
return lsf
# mel filterbank function modified from librosa
示例3: haroldpolydiv
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def haroldpolydiv(dividend, divisor):
"""
Polynomial division wrapped around :func:`scipy.signal.deconvolve`
function. Takes two arguments and divides the first
by the second.
Parameters
----------
dividend : (n,) array_like
The polynomial to be divided
divisor : (m,) array_like
The polynomial that divides
Returns
-------
factor : ndarray
The resulting polynomial coeffients of the factor
remainder : ndarray
The resulting polynomial coefficients of the remainder
Examples
--------
>>> a = np.array([2, 3, 4 ,6])
>>> b = np.array([1, 3, 6])
>>> haroldpolydiv(a, b)
(array([ 2., -3.]), array([ 1., 24.]))
>>> c = np.array([1, 3, 3, 1])
>>> d = np.array([1, 2, 1])
>>> haroldpolydiv(c, d)
(array([1., 1.]), array([], dtype=float64))
"""
h_factor, h_remainder = (np.trim_zeros(x, 'f') for x
in sig.deconvolve(dividend, divisor))
return h_factor, h_remainder
示例4: lpc_to_lsf
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def lpc_to_lsf(all_lpc):
if len(all_lpc.shape) < 2:
all_lpc = all_lpc[None]
order = all_lpc.shape[1] - 1
all_lsf = np.zeros((len(all_lpc), order))
for i in range(len(all_lpc)):
lpc = all_lpc[i]
lpc1 = np.append(lpc, 0)
lpc2 = lpc1[::-1]
sum_filt = lpc1 + lpc2
diff_filt = lpc1 - lpc2
if order % 2 != 0:
deconv_diff, _ = sg.deconvolve(diff_filt, [1, 0, -1])
deconv_sum = sum_filt
else:
deconv_diff, _ = sg.deconvolve(diff_filt, [1, -1])
deconv_sum, _ = sg.deconvolve(sum_filt, [1, 1])
roots_diff = np.roots(deconv_diff)
roots_sum = np.roots(deconv_sum)
angle_diff = np.angle(roots_diff[::2])
angle_sum = np.angle(roots_sum[::2])
lsf = np.sort(np.hstack((angle_diff, angle_sum)))
if len(lsf) != 0:
all_lsf[i] = lsf
return np.squeeze(all_lsf)
示例5: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def test_basic(self):
# From docstring example
original = [0, 1, 0, 0, 1, 1, 0, 0]
impulse_response = [2, 1]
recorded = [0, 2, 1, 0, 2, 3, 1, 0, 0]
recovered, remainder = signal.deconvolve(recorded, impulse_response)
assert_allclose(recovered, original)
示例6: poly2lsf
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def poly2lsf(a):
"""Prediction polynomial to line spectral frequencies.
converts the prediction polynomial specified by A,
into the corresponding line spectral frequencies, LSF.
normalizes the prediction polynomial by A(1).
.. doctest::
>>> from spectrum import poly2lsf
>>> a = [1.0000, 0.6149, 0.9899, 0.0000 ,0.0031, -0.0082]
>>> lsf = poly2lsf(a)
>>> lsf = array([0.7842, 1.5605, 1.8776, 1.8984, 2.3593])
.. seealso:: lsf2poly, poly2rc, poly2qc, rc2is
"""
#Line spectral frequencies are not defined for complex polynomials.
# Normalize the polynomial
a = numpy.array(a)
if a[0] != 1:
a/=a[0]
if max(numpy.abs(numpy.roots(a))) >= 1.0:
error('The polynomial must have all roots inside of the unit circle.');
# Form the sum and differnce filters
p = len(a)-1 # The leading one in the polynomial is not used
a1 = numpy.concatenate((a, numpy.array([0])))
a2 = a1[-1::-1]
P1 = a1 - a2 # Difference filter
Q1 = a1 + a2 # Sum Filter
# If order is even, remove the known root at z = 1 for P1 and z = -1 for Q1
# If odd, remove both the roots from P1
if p%2: # Odd order
P, r = deconvolve(P1,[1, 0 ,-1])
Q = Q1
else: # Even order
P, r = deconvolve(P1, [1, -1])
Q, r = deconvolve(Q1, [1, 1])
rP = numpy.roots(P)
rQ = numpy.roots(Q)
aP = numpy.angle(rP[1::2])
aQ = numpy.angle(rQ[1::2])
lsf = sorted(numpy.concatenate((-aP,-aQ)))
return lsf
示例7: deconvolve
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import deconvolve [as 别名]
def deconvolve(num, den, n=None):
"""Deconvolves divisor out of signal, division of polynomials for n terms
calculates den^{-1} * num
Parameters
----------
num : array_like
signal or lag polynomial
denom : array_like
coefficients of lag polynomial (linear filter)
n : None or int
number of terms of quotient
Returns
-------
quot : array
quotient or filtered series
rem : array
remainder
Notes
-----
If num is a time series, then this applies the linear filter den^{-1}.
If both num and den are both lagpolynomials, then this calculates the
quotient polynomial for n terms and also returns the remainder.
This is copied from scipy.signal.signaltools and added n as optional
parameter.
"""
num = np.atleast_1d(num)
den = np.atleast_1d(den)
N = len(num)
D = len(den)
if D > N and n is None:
quot = []
rem = num
else:
if n is None:
n = N-D+1
input = np.zeros(n, float)
input[0] = 1
quot = signal.lfilter(num, den, input)
num_approx = signal.convolve(den, quot, mode='full')
if len(num) < len(num_approx): # 1d only ?
num = np.concatenate((num, np.zeros(len(num_approx)-len(num))))
rem = num - num_approx
return quot, rem