Beispiel #1
0
    def test_different_length_input(self):
        T = np.arange(20)
        S = np.random.random(len(T) + 7)

        emd = EMD()
        with self.assertRaises(ValueError):
            emd.emd(S, T)
Beispiel #2
0
    def test_unsupporter_spline(self):
        emd = EMD()
        emd.splineKind = "waterfall"

        S = np.random.random(20)

        with self.assertRaises(ValueError):
            emd.emd(S)
Beispiel #3
0
    def test_trend(self):
        """
        Input is trend. Expeting no shifting process.
        """
        emd = EMD()

        t = np.arange(0, 1, 0.01)
        S = 2 * t

        # Input - linear function f(t) = 2*t
        IMF = emd.emd(S, t)
        self.assertEqual(IMF.shape[0], 1, "Expecting single IMF")
Beispiel #4
0
    def test_single_imf(self):
        """
        Input is IMF. Expecint single shifting.
        """

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

        emd = EMD()
        emd.FIXE_H = 5

        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)
        IMF = emd.emd(S, t)
        self.assertEqual(IMF.shape[0], 1, "Expecting sin + trend")

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

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

        self.assertEqual(IMF.shape[0], 2, "Expecting sin + trend")
        diff1 = np.allclose(IMF[0], c1, atol=0.2)
        self.assertTrue(
            diff1, "Expecting 1st IMF to be sin\nMaxDiff = " +
            str(maxDiff(IMF[0], c1)))
        diff2 = np.allclose(IMF[1], c2, atol=0.2)
        self.assertTrue(
            diff2, "Expecting 2nd IMF to be trend\nMaxDiff = " +
            str(maxDiff(IMF[1], c2)))
Beispiel #5
0
class EEMD:

    logger = logging.getLogger(__name__)

    def __init__(self):

        # Import libraries
        from PyEMD.EMD import EMD

        # Ensemble constants
        self.noise_width = 0.3
        self.trials = 100

        self.EMD = EMD()
        self.EMD.FIXE_H = 5

    def eemd(self, S, T=None, max_imf=None):

        if T is None: T = np.arange(len(S), dtype=S.dtype)
        if max_imf is None: max_imf = -1

        N = len(S)
        E_IMF = np.zeros((1,N))

        for trial in range(self.trials):
            self.logger.debug("trial: "+str(trial))

            noise = np.random.normal(loc=0, scale=self.noise_width, size=N)

            IMFs = self.emd(S+noise, T, max_imf)
            imfNo = IMFs.shape[0]

            while(E_IMF.shape[0] < imfNo):
                E_IMF = np.vstack((E_IMF, np.zeros(N)))

            E_IMF[:imfNo] += IMFs

        E_IMF /= self.trials

        return E_IMF

    def emd(self, S, T, max_imf=-1):
        return self.EMD.emd(S, T, max_imf)
                                          cutoff_l, fs, order)
y_filtrada_dislex = butter_highpass_filter(y_filtrada_dislex, cutoff_h, fs,
                                           order)

senial_indep_2500_muestras = y_filtrada
senial_indep_2500_muestras_dislexia = y_filtrada_dislex

# from PyEMD import EMD,visualisation
from PyEMD.EMD import EMD
from PyEMD.visualisation import Visualisation

# Perform decomposition
print("Performing decomposition... ")

emd = EMD()
emd.emd(senial_indep_2500_muestras, max_imf=5)

emd_dis = EMD()
emd_dis.emd(senial_indep_2500_muestras_dislexia, max_imf=5)

imfs, res = emd.get_imfs_and_residue()
imfs_dis, res_dis = emd_dis.get_imfs_and_residue()

vis = Visualisation()

print("Sujeto Normal")
vis.plot_imfs(imfs=imfs, residue=res, t=time, include_residue=False)
vis.plot_instant_freq(time, imfs=imfs)
vis.show()

print("Sujeto Dislexia")