예제 #1
0
    def test_emd_FIXE(self):
        T = np.linspace(0, 1, 100)
        c = np.sin(9 * 2 * np.pi * T)
        offset = 4
        S = c + offset

        emd = EMD()

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

        # Set 1 iteration per each sift,
        # same as removing offset
        FIXE = 1
        emd.FIXE = FIXE

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

        # Extract IMFs
        IMFs = emd.emd(S)

        # Check that IMFs are correct
        self.assertTrue(np.allclose(IMFs[0], c))
        self.assertTrue(np.allclose(IMFs[1], offset))
예제 #2
0
    def test_emd_FIXE(self):
        T = np.linspace(0, 1, 100)
        c = np.sin(9*2*np.pi*T)
        offset = 4
        S = c + offset

        emd = EMD()

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

        # Set 1 iteration per each sift,
        # same as removing offset
        FIXE = 1
        emd.FIXE = FIXE

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

        # Extract IMFs
        IMFs = emd.emd(S)

        # Check that IMFs are correct
        self.assertTrue(np.allclose(IMFs[0], c))
        self.assertTrue(np.allclose(IMFs[1], offset))
예제 #3
0
def emd_csi(csi, imfn=10):
    # Execute EMD on signal
    emd = EMD()
    emd.FIXE = 10
    IMF = emd(csi)

    csi_emd = np.zeros((csi.shape[0], imfn))
    for n, imf in enumerate(IMF):
        if n < imfn:
            csi_emd[:, n - 1] = imf
    return csi_emd
예제 #4
0
파일: test_emd.py 프로젝트: zbkzzh520/PyEMD
    def test_max_iteration_flag(self):
        S = np.random.random(200)
        emd = EMD()
        emd.MAX_ITERATION = 10
        emd.FIXE = 20

        imfs = emd.emd(S)

        # There's not much to test, except that it doesn't fail.
        # With low MAX_ITERATION value for random signal it's
        # guaranteed to have at least 2 imfs.
        self.assertTrue(imfs.shape[0]>1)
예제 #5
0
    def _emd(self, data, label):
        f_0 = self._random_pick(label)
        d = load(f_0)

        if self.pretransform is not None:
            d = self.pretransform(d)

        data, d = match_length(data, d)

        emd = EMD()
        emd.FIXE = 5
        imf_0 = emd(data, max_imf=5)
        imf_1 = emd(d, max_imf=5)

        imf = [*imf_0[:3], *imf_1[3:]]
        data = np.sum(imf, 0)
        return data
예제 #6
0
    def test_EMD_max_execution_time(self):
        t_min, t_max = 0, 1
        N = 100
        T = np.linspace(t_min, t_max, N)
        all_test_signals = []

        # These are local values. I'd be veeerrry surprised if everyone had such performance.
        # In case your test is failing: ignore and carry on.
        expected_times = np.array(
            [0.015, 0.04, 0.04, 0.05, 0.04, 0.05, 0.05, 0.05, 0.03, 0.05])
        received_times = [0] * len(expected_times)

        # Detect whether run on Travis CI
        # Performance test should be run on same machine with
        # same setting. Travis cannot guarantee that.
        if "TRAVIS" in os.environ:
            expected_times *= 10  # Conservative.

        all_w = np.arange(10, 20)
        for w in all_w:
            signal = np.sin(w * 2 * np.pi * T)
            signal[:] = signal[:] + 2 * np.cos(5 * 2 * np.pi * T)
            all_test_signals.append(signal)

        emd = EMD()
        emd.FIXE = 10

        for idx, signal in enumerate(all_test_signals):
            avg_t = self._timeit(emd.emd, signal, T, N=15)

            self.logger.info("{}. t = {:.4} (exp. {})".format(
                idx, avg_t, expected_times[idx]))
            received_times[idx] = avg_t

    # allclose = np.allclose(received_times, expected_times, atol=1e-2)
    # self.assertTrue(allclose)

        less_than = received_times <= expected_times
        self.assertTrue(np.all(less_than))