Carries out empirical mode decomposition of the provided function. Written following Huang et al. (1998; RSPA 454:903).
Please acknowledge R. O. Parke Loyd if you use this code in your research.
(also in test_script.py)
importnumpyasnpimportemdimportmatplotlib.pyplotasplt# GENERATE A POLYNOMIAL + SINE TEST FUNCTIONN=200t=np.arange(200, dtype=float) -N/2amp=10.0# polynomial to starty=t**2fac=amp/np.max(y) #but let's make the numbers easier to ready*=fac# but let's give it an offset just to make sure that doesn't screw with thingsy+=amp/5.0# and now add in a sineperiod=N/10.0phase=np.random.uniform(0.0, 2*np.pi)
y+= (amp/10.0) *np.sin(2*np.pi*t/period+phase)
# ADD NOISE, IF DESIREDy+=np.random.normal(0.0, amp/50.0, N)
# DECOMPOSEc, r=emd.emd(t, y)
# PLOTpf, =plt.plot(t, y)
pr, =plt.plot(t, r)
pcs=plt.plot(t, c, 'k-')
plt.legend((pf, pcs[0], pr), ('original function', 'modes', 'residual'))