def main(): """Input signal""" u = np.array([1, 2, 3, 4, 3, 2, 1], dtype='float') """Impulse responses where each column represents an impulse response.""" C = np.array([[1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4, 4]], dtype='float') """The array C represents here a linear time-invariant system.""" y_ltv = convolveLTV(u, C) y_lti = convolveLTI(u, C[:, 0]) """Check whether the output is indeed the same.""" print(np.all(y_ltv == y_lti)) print('LTV:' + str(y_ltv)) print('LTI:' + str(y_lti)) """Let's now use a time-variant system.""" C = np.array([[1, 2, 3, 4, 3, 2, 1], [2, 3, 4, 5, 4, 3, 2], [3, 4, 5, 6, 5, 4, 3], [4, 5, 6, 7, 6, 5, 4]], dtype='float') y_ltv = convolveLTV(u, C) y_lti = convolveLTI( u, C[:, 0]) # We use now only the first impulser response for the LTI. """Is the result still equal?""" print(np.all(y_ltv == y_lti)) print('LTV:' + str(y_ltv)) print('LTI:' + str(y_lti))
def main(): """Input signal""" u = np.array([1, 2, 3, 4, 3, 2, 1], dtype='float') """Impulse responses where each column represents an impulse response.""" C = np.array([ [1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4, 4] ], dtype='float') """The array C represents here a linear time-invariant system.""" y_ltv = convolveLTV(u, C) y_lti = convolveLTI(u, C[:,0]) """Check whether the output is indeed the same.""" print( np.all(y_ltv == y_lti) ) print('LTV:' + str(y_ltv)) print('LTI:' + str(y_lti)) """Let's now use a time-variant system.""" C = np.array([ [1, 2, 3, 4, 3, 2, 1], [2, 3, 4, 5, 4, 3, 2], [3, 4, 5, 6, 5, 4, 3], [4, 5, 6, 7, 6, 5, 4] ], dtype='float') y_ltv = convolveLTV(u, C) y_lti = convolveLTI(u, C[:,0]) # We use now only the first impulser response for the LTI. """Is the result still equal?""" print( np.all( y_ltv == y_lti ) ) print('LTV:' + str(y_ltv)) print('LTI:' + str(y_lti))
def test_convolve_lti(u, h): """Test whether :func:`acoustics.signal.convolve` behaves properly when performing a convolution with a time-invariant system. """ H = np.tile(h, (len(u), 1)).T np.testing.assert_array_almost_equal(convolveLTV(u, H), convolveLTI(u, h)) np.testing.assert_array_almost_equal(convolveLTV(u, H, mode='full'), convolveLTI(u, h, mode='full')) np.testing.assert_array_almost_equal(convolveLTV(u, H, mode='valid'), convolveLTI(u, h, mode='valid'))
def test_convolve_lti(u, h): """Test whether :func:`acoustics.signal.convolve` behaves properly when performing a convolution with a time-invariant system. """ H = np.tile(h, (len(u), 1)).T np.testing.assert_array_almost_equal(convolveLTV(u,H), convolveLTI(u,h)) np.testing.assert_array_almost_equal(convolveLTV(u,H,mode='full'), convolveLTI(u,h,mode='full')) np.testing.assert_array_almost_equal(convolveLTV(u,H,mode='valid'), convolveLTI(u,h,mode='valid')) np.testing.assert_array_almost_equal(convolveLTV(u,H,mode='same'), convolveLTI(u,h,mode='same'))