コード例 #1
0
    def runAlgorithm(self):
        self.alg = EMD(self.refInVector,
                       tWindowSize=self.tWindowSize,
                       samplingFrequency=self.samplingFreq,
                       imfsNo=self.imfsNo)
        self.resultVector = self.alg.process()
        self.env = self.alg.hilbertAlgorithm.envelope
        self.imfs = self.alg.imfs
        # self.spline_upper = self.alg.spline_upper

        for val in self.resultVector or []:
            self.resultFile.write('%d\n' % val)

        # for val in self.imf:
        #     self.imfOutFileFile.write('%f\n' % val)
        np.savetxt(self.imfOutFileDir, self.imfs, delimiter=',')

        for val in self.env:
            self.envOutFileFile.write('%f\n' % val)
コード例 #2
0
def compare_kmeans(C1, C2, unif):
	"""
	C1 and C2 are obtained from the attribute kmeans.labels_
	"""
	N = len(C1)
	K, J = max(C1)+1, max(C2)+1

	zeta = np.zeros((N,K))
	gamma = np.zeros((N, J))
	for i in range(N):
		zeta[i, C1[i]] = 1
		gamma[i, C2[i]] = 1
	zeta = zeta.T
	gamma = gamma.T
	if unif:
		alpha = [1./K for _ in range(K)]
		beta = [1./J for _ in range(J)]
	else:
		alpha = [len(np.where(C1 == j)[0]) for j in range(K)]
		beta = [len(np.where(C2 == j)[0]) for j in range(J)]

	# compute EMD

	d = lambda x,y: np.linalg.norm(x-y, ord=1)
	emd = EMD(zip(zeta, alpha), zip(gamma, beta), d)
	emd.write_lp_problem('emd_pb.lp')
	emd.solve_lp()
	return emd.distance
コード例 #3
0
        inst_phase = self._calc_inst_phase(sig)
        return np.diff(inst_phase) / (t[1] - t[0])

    def show(self):
        plt.show()


if __name__ == "__main__":
    import numpy as np
    from EMD import EMD

    # Simple signal example
    t = np.arange(0, 3, 0.01)
    S = np.sin(13 * t + 0.2 * t**1.4) - np.cos(3 * t)

    emd = EMD()
    emd.emd(S)
    imfs, res = emd.get_imfs_and_residue()

    # Initiate visualisation with emd instance
    vis = Visualisation(emd)

    # Create a plot with all IMFs and residue
    vis.plot_imfs(imfs=imfs, residue=res, t=t, include_residue=True)

    # Create a plot with instantaneous frequency of all IMFs
    vis.plot_instant_freq(t, imfs=imfs)

    # Show both plots
    vis.show()
コード例 #4
0
ファイル: HHSA.py プロジェクト: ars599/HHSA
plt.figure()
plt.psd(smn, nfft, 1 / dt, label='Signal * Noise', c='#FF8E40')
plt.psd(signal, nfft, 1 / dt, label='Signal', ls=':', c='#9282FF')
plt.xscale('log')
plt.ylim(-64, 9)

plt.legend()

# In[ First IMF ]
# Data plot
fig, ax = plt.subplots(1, 2)
ax[0].plot(signal, 'w-', label='data')
ax[0].grid(linestyle='--', color=([0.2, 0.2, 0.2]))

imfs = EMD(signal, 3)

# IMF plot
for i in range(len(imfs)):
    ax[1].plot(imfs[i], label=str(i))
ax[1].grid(linestyle='--', color=([0.2, 0.2, 0.2]))

plt.legend()

# In[ Second IMF ]
max_envs = []
for imf in imfs:
    max_env, _ = max_min_env(imf)
    max_envs += [max_env]

new_imfs = []
コード例 #5
0
ファイル: encoder.py プロジェクト: williamscommajason/EMD_LPC
def run_EMD_encoder(x, samples):

    emd = EMD(samples)
    emd.emd(x, None)
    return emd
コード例 #6
0
class EMDTest(unittest.TestCase):

    def setUp(self):
        refDir = os.path.dirname(os.getcwd())
        refNumStr = '103'
        refInFileDir = os.path.join(refDir, refNumStr, 'Input.csv')
        refOutFileDir = os.path.join(refDir, refNumStr, 'EMDOutput.csv')
        resOutFileDir = os.path.join(refDir, refNumStr, 'EMDResultsPython.csv')
        self.imfOutFileDir = os.path.join(refDir, refNumStr, 'Imf.csv')
        envOutFileDir = os.path.join(refDir, refNumStr, 'Envelope.csv')

        self.samplingFreq = 360.0
        self.imfsNo = 3
        self.tWindowSize = 120.0

        self.refInFile = open(refInFileDir, 'r')
        self.refOutFile = open(refOutFileDir, 'r')
        self.resultFile = open(resOutFileDir, 'w')
        # self.imfOutFileFile = open(imfOutFileDir, 'w')
        self.envOutFileFile = open(envOutFileDir, 'w')
        self.refInVector = []
        self.refOutVector = []
        self.resultVector = []
        self.refIntSignalVector = []
        self.refMarksVector = []

    def tearDown(self):
        self.refInFile.close()
        self.refOutFile.close()
        self.resultFile.close()
        # self.imfOutFileFile.close()
        self.envOutFileFile.close()

    def loadReferenceData(self):
        refInVectorStr = self.refInFile.readline().split(',')
        del refInVectorStr[-1]
        for item in refInVectorStr:
            val = float(item)
            self.refInVector.append(val)

        refOutVectorStr = self.refOutFile.readline().split(',')
        del refOutVectorStr[-1]
        for item in refOutVectorStr:
            val = int(float(item))
            self.refOutVector.append(val)

    def runAlgorithm(self):
        self.alg = EMD(self.refInVector,
                       tWindowSize=self.tWindowSize,
                       samplingFrequency=self.samplingFreq,
                       imfsNo=self.imfsNo)
        self.resultVector = self.alg.process()
        self.env = self.alg.hilbertAlgorithm.envelope
        self.imfs = self.alg.imfs
        # self.spline_upper = self.alg.spline_upper

        for val in self.resultVector or []:
            self.resultFile.write('%d\n' % val)

        # for val in self.imf:
        #     self.imfOutFileFile.write('%f\n' % val)
        np.savetxt(self.imfOutFileDir, self.imfs, delimiter=',')

        for val in self.env:
            self.envOutFileFile.write('%f\n' % val)

    def isResultIdentical(self):
        result = True

        # self.assertTrue(len(self.resultVector) > 0)

        print 'Output size: {}'.format(len(self.resultVector))

        for ref, res in zip(self.refOutVector, self.resultVector):
            # print '{} {}'.format(ref, res)
            if ref != res:
                print 'reference ({}) and result ({}) are not equal'.format(ref, res)
                result = False

        return result

    def testAlgorithm(self):
        self.loadReferenceData()
        self.runAlgorithm()

        self.assertTrue(self.isResultIdentical(), 'Reference vector and result vector are not identical')
コード例 #7
0
import os
from EMD import EMD

refDir = os.path.dirname(os.getcwd())
refNumStr = '101'
refInFileDir = os.path.join(refDir, refNumStr, 'Input.csv')
resOutFileDir = os.path.join(refDir, refNumStr, 'EMDResultsPython.csv')

refInFile = open(refInFileDir, 'r')
resultFile = open(resOutFileDir, 'w')

refInVector = []

refInVectorStr = refInFile.readline().split(',')
del refInVectorStr[-1]
for item in refInVectorStr:
    val = float(item)
    refInVector.append(val)

alg = EMD(refInVector, tWindowSize=120.0, samplingFrequency=360, imfsNo=3)
resultVector = alg.process()

for val in resultVector or []:
    resultFile.write('%d\n' % val)

refInFile.close()
resultFile.close()
コード例 #8
0
ファイル: EMDRun.py プロジェクト: piotrekbrozyna/esdmit
import os
from EMD import EMD

refDir = os.path.dirname(os.getcwd())
refNumStr = '101'
refInFileDir = os.path.join(refDir, refNumStr, 'Input.csv')
resOutFileDir = os.path.join(refDir, refNumStr, 'EMDResultsPython.csv')

refInFile = open(refInFileDir, 'r')
resultFile = open(resOutFileDir, 'w')

refInVector = []

refInVectorStr = refInFile.readline().split(',')
del refInVectorStr[-1]
for item in refInVectorStr:
    val = float(item)
    refInVector.append(val)

alg = EMD(refInVector,
          tWindowSize=120.0,
          samplingFrequency=360,
          imfsNo=3)
resultVector = alg.process()

for val in resultVector or []:
    resultFile.write('%d\n' % val)

refInFile.close()
resultFile.close()
コード例 #9
0
ファイル: sequence.py プロジェクト: gprerit96/Mouse_biometric
 def get_emd(self):
     self.imf = EMD().emd(self.sig, self.t)
コード例 #10
0
ファイル: visualisation.py プロジェクト: laszukdawid/PyEMD
        inst_phase = self._calc_inst_phase(sig)
        return np.diff(inst_phase)/(t[1]-t[0])

    def show(self):
        plt.show()


if __name__ == "__main__":
    import numpy as np
    from EMD import EMD

    # Simple signal example
    t = np.arange(0, 3, 0.01)
    S = np.sin(13*t + 0.2*t**1.4) - np.cos(3*t)

    emd = EMD()
    emd.emd(S)
    imfs, res = emd.get_imfs_and_residue()

    # Initiate visualisation with emd instance
    vis = Visualisation(emd)

    # Create a plot with all IMFs and residue
    vis.plot_imfs(imfs=imfs, residue=res, t=t, include_residue=True)

    # Create a plot with instantaneous frequency of all IMFs
    vis.plot_instant_freq(t, imfs=imfs)

    # Show both plots
    vis.show()
コード例 #11
0
ファイル: sample.py プロジェクト: gprerit96/Mouse_biometric
plt.plot(x, y, 'b', label="Actual Trajectory")
plt.plot([x[0], x[-1]], [y[0], y[-1]], 'go')
plt.plot([x[0], x[-1]], [y[0], y[-1]], 'r--', label="Shortest Path")
plt.text(x[0], y[0], "(%i,%i) Start" % (int(x[0]), int(y[0])))
plt.text(x[-1], y[-1], "(%i,%i) End" % (int(x[-1]), int(y[-1])))
plt.xlabel("X-axis on screen")
plt.ylabel("Y-axis on screen")
#plt.title("Mouse_movement sequence")
#plt.title("User 2 : mouse signal trajectory")
plt.legend(loc='upper right')
plt.show()

# Execute EMD on signal
S = s
print type(S)
eIMFs = EMD().emd(S, t)
nIMFs = eIMFs.shape[0]
print eIMFs.shape
print s
"""
##### Retrieval #############
p1 = s1.get_start()
p2 = s1.get_end()
slope = (p2.y - p1.y)/(p2.x - p1.x)
cosx = -(p2.x - p1.x)/dist(p2,p1)
sinx = (p2.y - p1.y)/dist(p2,p1)
ret = eIMFs[1:].sum(axis=0)
print "Retrieved"
print ret
[val,t1] = s1.get_p()
コード例 #12
0
from EMD import EMD
import numpy as np
import pylab as plt

# Define signal
t = np.linspace(0, 1, 200)

sin = lambda x, p: np.sin(2 * np.pi * x * t + p)
S = 3 * sin(18, 0.2) * (t - 0.2)**2
S += 5 * sin(11, 2.7)
S += 3 * sin(14, 1.6)
S += 1 * np.sin(4 * 2 * np.pi * (t - 0.8)**2)
S += t**2.1 - t
s = S
# Execute EMD on signal
IMF = EMD().emd(s, t)
N = IMF.shape[0] + 1
print IMF.shape
imf = sum(IMF)
print imf.shape
plt.figure(figsize=(12, 9))
plt.subplot(N, 1, 1)
plt.plot(t, imf, 'r')
plt.show()

# Plot results
"""
plt.figure(figsize=(12,9))
plt.subplot(N, 1, 1)
plt.plot(t, s, 'r')