示例#1
0
    def test_single_imf(self):
        """
        Input is IMF. Expecint single shifting.
        """

        max_diff = lambda a,b: np.max(np.abs(a-b))

        emd = EMD()
        emd.FIXE_H = 2

        t = np.arange(0, 1, 0.001)
        c1 = np.cos(4*2*np.pi*t) # 2 Hz
        S = c1.copy()

        # Input - linear function f(t) = sin(2Hz t)
        # import pdb; pdb.set_trace()
        imfs = emd.emd(S, t)
        self.assertEqual(imfs.shape[0], 1, "Expecting sin + trend")

        diff = np.allclose(imfs[0], c1)
        self.assertTrue(diff, "Expecting 1st IMF to be sin\nMaxDiff = " + str(max_diff(imfs[0],c1)))

        # Input - linear function f(t) = siin(2Hz t) + 2*t
        c2 = 5*(t+2)
        S += c2.copy()
        imfs = emd.emd(S, t)

        self.assertEqual(imfs.shape[0], 2, "Expecting sin + trend")
        diff1 = np.allclose(imfs[0], c1, atol=0.2)
        self.assertTrue(diff1, "Expecting 1st IMF to be sin\nMaxDiff = " + str(max_diff(imfs[0],c1)))
        diff2 = np.allclose(imfs[1], c2, atol=0.2)
        self.assertTrue(diff2, "Expecting 2nd IMF to be trend\nMaxDiff = " + str(max_diff(imfs[1],c2)))
示例#2
0
    def test_emd_FIXEH(self):
        T = np.linspace(0, 2, 200)
        c1 = 1 * np.sin(11 * 2 * np.pi * T + 0.1)
        c2 = 11 * np.sin(1 * 2 * np.pi * T + 0.1)
        offset = 9
        S = c1 + c2 + offset

        emd = EMD()

        # Default state: converge
        self.assertTrue(emd.FIXE == 0)
        self.assertTrue(emd.FIXE_H == 0)

        # Set 5 iterations per each protoIMF
        FIXE_H = 6
        emd.FIXE_H = FIXE_H

        # Check flags correctness
        self.assertTrue(emd.FIXE == 0)
        self.assertTrue(emd.FIXE_H == FIXE_H)

        # Extract IMFs
        IMFs = emd.emd(S)

        # Check that IMFs are correct
        self.assertTrue(IMFs.shape[0] == 3)

        closeIMF1 = np.allclose(c1[1:-1], IMFs[0, 1:-1], atol=0.5)
        self.assertTrue(closeIMF1)
        self.assertTrue(np.allclose(c1, IMFs[0], atol=1.))

        closeIMF2 = np.allclose(c2[1:-1], IMFs[1, 1:-1], atol=0.5)
        self.assertTrue(closeIMF2)
        self.assertTrue(np.allclose(c2, IMFs[1], atol=1.))

        closeOffset = np.allclose(offset, IMFs[2, 1:-1], atol=0.5)
        self.assertTrue(closeOffset)
        self.assertTrue(np.allclose(IMFs[1, 1:-1], c2[1:-1], atol=0.5))

        closeOffset = np.allclose(offset, IMFs[2, 1:-1], atol=0.5)
        self.assertTrue(closeOffset)
示例#3
0
    def test_emd_FIXEH(self):
        T = np.linspace(0, 2, 200)
        c1 = 1*np.sin(11*2*np.pi*T+0.1)
        c2 = 11*np.sin(1*2*np.pi*T+0.1)
        offset = 9
        S = c1 + c2 + offset

        emd = EMD()

        # Default state: converge
        self.assertTrue(emd.FIXE==0)
        self.assertTrue(emd.FIXE_H==0)

        # Set 5 iterations per each protoIMF
        FIXE_H = 6
        emd.FIXE_H = FIXE_H

        # Check flags correctness
        self.assertTrue(emd.FIXE==0)
        self.assertTrue(emd.FIXE_H==FIXE_H)

        # Extract IMFs
        imfs = emd.emd(S)

        # Check that IMFs are correct
        self.assertTrue(imfs.shape[0]==3)

        close_imf1 = np.allclose(c1[2:-2], imfs[0,2:-2], atol=0.2)
        self.assertTrue(close_imf1)
        self.assertTrue(np.allclose(c1, imfs[0], atol=1.))

        close_imf2 = np.allclose(c2[2:-2], imfs[1,2:-2], atol=0.21)
        self.assertTrue(close_imf2)
        self.assertTrue(np.allclose(c2, imfs[1], atol=1.))

        close_offset = np.allclose(offset, imfs[2,2:-2], atol=0.1)
        self.assertTrue(close_offset)

        close_offset = np.allclose(offset, imfs[2,1:-1], atol=0.5)
        self.assertTrue(close_offset)