예제 #1
0
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))
예제 #2
0
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))
예제 #3
0
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'))
예제 #4
0
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'))
예제 #5
0
def test_convolve_ltv():
    """Test whether :func:`acoustics.signal.convolve` behaves properly when
    performing a convolution with a time-variant system.
    """
    """Input signal"""
    u = np.array([1, 1, 1])
    """Impulse responses where each column represents an impulse response."""
    C = np.array([[1, 0, 0], [2, 1, 1]])
    """The result calculated manually."""
    y_manual = np.array([1, 2, 1, 1])

    y_ltv = convolveLTV(u, C)
    np.testing.assert_array_equal(y_ltv, y_manual)
예제 #6
0
def test_convolve_ltv():
    """Test whether :func:`acoustics.signal.convolve` behaves properly when
    performing a convolution with a time-variant system.
    """
    """Input signal"""
    u = np.array([1, 1, 1])
    """Impulse responses where each column represents an impulse response."""
    C = np.array([[1, 0, 0], [2, 1, 1]])
    """The result calculated manually."""
    y_manual = np.array([1, 2, 1, 1])

    y_ltv = convolveLTV(u, C)
    np.testing.assert_array_equal(y_ltv, y_manual)