Ejemplo n.º 1
0
def test_MorletWaveletAnalyzer():
    """Testing the MorletWaveletAnalyzer """
    time_series = ts.TimeSeries(data=np.random.rand(100), sampling_rate=100)

    W = nta.MorletWaveletAnalyzer(time_series, freqs=20)
    WL = nta.MorletWaveletAnalyzer(time_series, freqs=20, log_morlet=True)
    H = nta.HilbertAnalyzer(W.real)
    HL = nta.HilbertAnalyzer(WL.real)

    npt.assert_almost_equal(np.sin(H.phase.data[10:-10]),
                            np.sin(W.phase.data[10:-10]),
                            decimal=0)
    npt.assert_almost_equal(np.sin(HL.phase.data[10:-10]),
                            np.sin(WL.phase.data[10:-10]),
                            decimal=0)
Ejemplo n.º 2
0
def test_HilbertAnalyzer():
    """Testing the HilbertAnalyzer (analytic signal)"""
    pi = np.pi
    Fs = np.pi
    t = np.arange(0, 2 * pi, pi / 256)

    a0 = np.sin(t)
    a1 = np.cos(t)
    a2 = np.sin(2 * t)
    a3 = np.cos(2 * t)

    T = ts.TimeSeries(data=np.vstack([a0, a1, a2, a3]), sampling_rate=Fs)

    H = nta.HilbertAnalyzer(T)

    h_abs = H.amplitude.data
    h_angle = H.phase.data
    h_real = H.real.data
    #The real part should be equal to the original signals:
    npt.assert_almost_equal(h_real, T.data)
    #The absolute value should be one everywhere, for this input:
    npt.assert_almost_equal(h_abs, np.ones(T.data.shape))
    #For the 'slow' sine - the phase should go from -pi/2 to pi/2 in the first
    #256 bins:
    npt.assert_almost_equal(h_angle[0, :256],
                            np.arange(-pi / 2, pi / 2, pi / 256))
    #For the 'slow' cosine - the phase should go from 0 to pi in the same
    #interval:
    npt.assert_almost_equal(h_angle[1, :256], np.arange(0, pi, pi / 256))
    #The 'fast' sine should make this phase transition in half the time:
    npt.assert_almost_equal(h_angle[2, :128],
                            np.arange(-pi / 2, pi / 2, pi / 128))
    #Ditto for the 'fast' cosine:
    npt.assert_almost_equal(h_angle[3, :128], np.arange(0, pi, pi / 128))