Beispiel #1
0
def test_linear():
    # Should detect *one* rising zero crossing
    # Specify `AC_coupled` = False to prevent computation of DC offset,
    # which is only a well-defined operation when there are two or more
    # zero crossings of the same type.
    zc = ZeroCrossing(np.array([-1, 0, 1]), 1, auto=False)
    tools.assert_equal(zc._getRisingZeroCrossingIndices(), np.array([0]))
    tools.assert_equal(zc._getRisingZeroCrossingTimesLerp(), np.array([1]))
Beispiel #2
0
def test_constant():
    # Should detect *no* zero crossings with a constant array
    # Specify `AC_coupled` = False to prevent computation of DC offset,
    # which is only a well-defined operation when there are two or more
    # zero crossings of the same type.
    zc = ZeroCrossing(np.array([1, 1]), 1, auto=False)
    tools.assert_equal(len(zc._getRisingZeroCrossingIndices()), 0)
    tools.assert_equal(len(zc._getRisingZeroCrossingTimesLerp()), 0)
Beispiel #3
0
def test__getRisingZeroCrossingTimesLerp():
    # Create signal with well-known zero crossings
    f = 0.125
    t = 0.5 + np.linspace(0, 100, 101)
    y = np.cos(2 * np.pi * f * t)
    Fs = 1. / np.mean(np.diff(t))

    # Construct zero crossing object
    zc = ZeroCrossing(y, Fs, t0=t[0])

    # Test identification of *rising* zero crossings
    # via linear interpolation
    xtimes_rising_exact = np.arange(6, t[-1], int(1. / f))
    xtimes_rising_calc = zc._getRisingZeroCrossingTimesLerp()
    np.testing.assert_allclose(xtimes_rising_exact, xtimes_rising_calc)

    # Test identification of *falling* zero crossings
    # via linear interpolation
    xtimes_falling_exact = np.arange(2, t[-1], int(1. / f))
    xtimes_falling_calc = zc._getRisingZeroCrossingTimesLerp(invert=True)
    np.testing.assert_allclose(xtimes_falling_exact, xtimes_falling_calc)