示例#1
0
def upfirdn_naive(x, h, up=1, down=1):
    """Naive upfirdn processing in Python

    Note: arg order (x, h) differs to facilitate apply_along_axis use.
    """
    h = np.asarray(h)
    out = np.zeros(len(x) * up, x.dtype)
    out[::up] = x
    out = np.convolve(h, out)[::down][:_output_len(len(h), len(x), up, down)]
    return out
示例#2
0
def upfirdn_naive(x, h, up=1, down=1):
    """Naive upfirdn processing in Python

    Note: arg order (x, h) differs to facilitate apply_along_axis use.
    """
    h = np.asarray(h)
    out = np.zeros(len(x) * up, x.dtype)
    out[::up] = x
    out = np.convolve(h, out)[::down][:_output_len(len(h), len(x), up, down)]
    return out
示例#3
0
 def scrub(self, x, axis=-1):
     yr = np.apply_along_axis(upfirdn_naive, axis, x, self.h, self.up,
                              self.down)
     want_len = _output_len(len(self.h), x.shape[axis], self.up, self.down)
     assert yr.shape[axis] == want_len
     y = upfirdn(self.h, x, self.up, self.down, axis=axis)
     assert y.shape[axis] == want_len
     assert y.shape == yr.shape
     dtypes = (self.h.dtype, x.dtype)
     if all(d == np.complex64 for d in dtypes):
         assert_equal(y.dtype, np.complex64)
     elif np.complex64 in dtypes and np.float32 in dtypes:
         assert_equal(y.dtype, np.complex64)
     elif all(d == np.float32 for d in dtypes):
         assert_equal(y.dtype, np.float32)
     elif np.complex128 in dtypes or np.complex64 in dtypes:
         assert_equal(y.dtype, np.complex128)
     else:
         assert_equal(y.dtype, np.float64)
     assert_allclose(yr, y)