jaidevd / pyhht Goto Github PK
View Code? Open in Web Editor NEWPython toolbox for the Hilbert-Huang transform
License: Other
Python toolbox for the Hilbert-Huang transform
License: Other
Hi,
First of all thank you very much for providing such a package.
I'm currently working on EEG signals and wanted to try the EMD method to classify them.
So my data is an array of time series. I want to have the imfs of each time serie so I use the tutorial.emd function but it sometimes (I mean on some time series) returns me an error of type "TypeError: m > k must hold" which I don't understand. Maybe you know what this problem is related to.
Ask for any further precision,
Thank you in advance for your answer
Hi,
if I understood correctly at the moment there is only the possibility to get the insta. freq. and not the whole Hilbert spectrum, right?
are there progress/motivations in that direction?
Testing monotonicity is a bad way of testing the residual output. Much better to just use the classic definition of the residue from the original paper.
Just curious if there're any plan to rewrite some module in Cython?
The default maximum iterations in sifting is set to 2000, but this should be inferred from the input data itself.
Dear Jaidevd,
I'm interested on using your work and I really appreciate the effort that you took on making the library. I'm forking it to start using it, I did some minor changes on my branch to make it work on python3, still not everything tested, but it seems that adding parenthesis to the print statements is enough. Also, imports from the library needed to be pyhht.LIB2IMPORT, VG in emd.py the line 15 reads: from utils import ....., needs to be from pyhht.utils import ....
Will comment on my results on the docstrings, that also seem to have a problem with python3, at least in spyder I don't see them on the object inspector.
Mucha Suerte!
Hi,
is printing this info really needed ?
Line 80 in 61af178
i + 2
? isn't i+1
-- anyway, better to remove I guessfrom pyhht.emd import EMD
decomposer = EMD(data[0])
imf = decomposer.decompose()
matlab code is :
emd(data(1,:))
I think it may be useful to have a choice of the interpolation method for obtaining envelopes and include ie. quadratic, linear etc. in addition to the cubic spline, because in some situations it could be interesting to see how the results of the decomposition depend on the chosen interpolation method.
Hello,
whenever I'm trying to set fixed number of sifting ('fixe' parameter) OR when checking the stopping criteria for the current mode I get:
TypeError: mean_and_amplitude() takes exactly 2 arguments (1 given)
although I don't understands what am I doing wrong:
decomp_data = pyhht.emd.EMD(np.asarray(data))
decomp_data.stop_sifting(np.asarray(data))
OR
decomp_data = pyhht.emd.EMD(np.asarray(data), fixe=9)
decomp_data.decompose()
Could you please advice? Thank you!
The simpler examples should have doctests.
no marginal spectrum energy spectrum examples tutorial
Hello, when I applied the code to complex list for bivariate EMD, the result is not cosistent with matlab's.
Hi,
I was thinking that in roder to provide a more meaningful orthogonality measure it might be useful for instance, to normalise the ortogonality (io()
) by the N of IMFs combinations of which is computed (you can use for instance scipy comb)
what do you think? -- maybe we should ask to a broader audience ...
from pyhht.emd import EMD
from pyhht.visualization import plot_imfs
import numpy as np
x = [2275.4, 2274.6, 2274.6, 2274.4, 2274.0, 2273.6, 2272.8, 2273.6, 2274.0, 2273.4, 2273.0, 2272.8, 2272.4, 2272.4, 2272.6, 2271.8, 2269.4, 2269.8, 2270.0, 2269.6, 2269.0, 2267.4, 2267.6, 2268.0, 2268.4, 2268.0, 2268.2, 2268.0, 2267.6, 2267.8, 2267.6, 2265.2, 2265.0, 2264.0, 2263.2, 2262.4, 2263.8, 2263.2, 2263.0, 2261.4, 2263.0, 2263.0, 2262.8, 2262.4, 2262.4, 2263.6, 2262.8, 2262.6, 2261.2, 2258.2, 2258.8, 2258.4, 2259.4, 2258.4, 2258.0, 2257.0, 2257.0, 2257.0, 2256.8, 2255.4, 2256.2, 2256.2, 2256.8, 2255.4, 2256.6, 2256.2, 2255.0, 2256.0, 2256.4, 2257.0, 2255.8, 2256.6, 2257.0, 2255.6, 2254.0, 2253.6, 2255.0, 2255.2, 2254.2, 2255.2, 2255.0, 2256.4, 2256.2, 2256.8, 2256.2, 2256.4, 2257.0, 2256.6, 2256.2, 2256.6, 2256.4, 2256.0, 2255.2, 2254.6, 2254.2, 2254.4, 2253.4, 2251.6, 2250.4, 2251.6, 2252.6, 2252.6, 2252.8, 2251.4, 2252.4, 2253.2, 2252.6, 2252.8, 2253.0, 2253.2, 2253.8, 2253.2, 2253.4, 2253.4, 2253.4, 2254.8, 2253.8, 2253.4, 2253.8, 2254.0, 2253.4, 2253.0, 2253.8, 2253.4, 2253.2, 2253.4, 2253.8, 2253.0, 2252.4, 2252.2, 2252.0, 2251.2, 2252.4, 2253.8, 2254.0, 2253.6, 2253.2, 2251.8, 2251.0, 2251.6, 2251.6, 2250.4, 2252.0, 2250.6, 2251.0, 2251.4, 2251.2, 2251.6, 2252.2, 2252.0, 2252.0, 2252.4, 2252.6, 2252.4, 2251.4, 2251.8, 2251.0, 2251.4, 2252.2, 2252.0, 2253.0, 2252.6, 2253.4]
x = np.array(x)
t = np.array([i for i in range(len(x))])
decomposer = EMD(x)
imfs = decomposer.decompose()
plot_imfs(x, imfs, t)
In signals like the one in #29 , PyHHT should automatically detect whether the mirrored symmetry of extrema is breaking the interpolation, and raise a warning.
Hi,
First I am really thankful for your code, it has solved a lot of problems, given that no package exists for EMD in python.
The issue I am having currently is that my time series data when pre-processed yields a time series which is of the form of pulse train, where in consecutive elements are same for a few number of elements and then it shifts to another value.
Ex: [1 1 1 1 0 0 0 2 2 2 2 -1 -1 -1 ...]
For such a time series, the function is throwing an error.
If you could kindly look into this.
Thank you
Thank you for your work on pyhht.
I have been working with the code and do not understand some results I am seeing.
When working through the boundary_conditions() example I got:
>>> from pyhht.utils import boundary_conditions
>>> import numpy as np
>>> signal = np.array([-1, 1, -1, 1, -1])
>>> tmin, tmax, vmin, vmax = boundary_conditions(signal, np.arange(5))
>>> tmin
array([-2, 2, 6])
>>> tmax
array([-3, -1, 1, 3, 5, 7])
>>> vmin
array([-1, -1, -1])
>>> vmax
array([1, 1, 1, 1, 1, 1])
Which agrees with your example.
I would have thought that tmin should be [-2, 0, 2, 4, 6] and vmin should be [-1, -1, -1, -1, -1] - am I misunderstanding?
I try some seismic signal use this EMD cannot yield same imfs solution as emd in MATLAB
and I do not know why ?
Why this emd tool usually only produce 2 imfs component but emd in MATLAB can produce 8~9 imfs?
Hi! I'm also writing a HHT implementation in Julia, as part of an article. Have you found any decent and clear implementations of the Hilbert transform?
Hi, Jaidevd. I am Dongwei Chen. It's nice to leave a message here. It's great to put EEMD and CEEMD into pyhht module successfully, which will contribute to python community. Thanks for your work!
Hi,
thanks for the package -- I just started to use it.
I was thinking that would be useful for a quick start to see the reference to pip-installation in the readme https://pypi.org/project/pyhht/, even if it's a trivial thing for python users (maybe not for others :))
When the size of data is even number, emd function can run correctly. If the size is odd number, the emd function cannot run. I run the default configure.
Here are the error information
signals[0:base / 2, 0] = data[::-1][base / 2:]
ValueError: could not broadcast input array from shape (2039) into shape (2038)
By the way, I test the matlab emd, which can handle any size of data.
I calculated the IMFs using pyhht then I extracted the instantaneous frequencies using the method in this package. The values that I always got were 100 and 200 Hz regardless of which IMF I used. After that, I switched to Matlab and I plotted the Hilbert space using the IMFs I got from this package, but it gave me different (more reasonable) results as shown below. Why is that happening?
sx = np.abs(envmoy) / amp
stop = not(((np.mean(sx > self.threshold_1) > self.alpha) or
np.any(sx > self.threshold_2)) and np.all(nem > 2))
Which paper did this stop rule come from?
thanks!
Thanks for your effort in making such a package, it's the most popular package I found on GitHub implementing HHT. But I got some problems with tutorials, the file intro_pyhht.rst only has the title, but the content is missing. Maybe you can help fix it? Thanks a million!
The initialization and use of attributes of the EMD class that are used exclusively for bivariate EMD should be clearly separated from the other attributes.
I reviewed your codes and thought that local maximum and local minimum should be spline function's local maximum and local minimum , not array index nor array value of original data unless the samples of signal is dense enough for this.
your original code is faster but rough solution.
I'll add another option on the function if you agree.
Excuse me, does pyhht package include the EEMD algorithm?
Is there any way to preserve the decomposition memory?
For example I have data from Jan 2016 - Feb 2017
the first time I decompose until on Jan 2017
second time decompose until on feb 2017
But the value on imfs and residual is not the same in the two decomposition given the same number of imfs and the same date
Line 32 in b5e15b9
Hi,
sorry, trivial question -- I cannot find the theta1, theta2, alpha pars in the original paper (attached hereby)
Could you point to them? ( In particular I was expecting them in section 5...)
Thanks again
HHT_original.pdf
Hi,
I'd really like to try your package, but there seems to be a problem handling complex valued inputs. I created several (simple) complex signals, and for each I receive:
Force stopping EMD: amplitude too small.
example code:
n = 1000
fc = 0.25
t = np.linspace(0, 1, n)
x = np.exp(2.0j * np.pi * fc * t)
X = np.fft.fftshift(np.fft.fft(x))
X /= np.max(X)
plt.plot(np.linspace(-0.5, 0.5, len(X)), np.abs(X) ** 2)
plt.show()
decomposer = EMD(x, is_mode_complex=True)
imfs = decomposer.decompose()
plot_imfs(x, imfs, t)
Any insight you may have would be very helpful. Thanks.
Hi, I am testing pyhht to do rolling emd decomposition to de-trend time series. however, I find there are two issues, 1) with rolling test progress on, sometimes the residual emd's shape completely changed, and sometime later it could revert back to earlier one, this makes the de-trended data not stable and thus not usable. 2) with test rolling on, sometimes the number of imfs increase, sometimes decrease. I am using the default configuration, except set n_imfs = 5.
Is there a way control the two issues above?
Thanks and really appreciate sharing pyhht to community!
I'm trying to build the docs and it throws this error. I think it must be a version thing, i.e., the add_javascript
method probably went away with Sphinx v4.x
pyhht/docs $ make singlehtml
sphinx-build -b singlehtml -d build/doctrees source build/singlehtml
Running Sphinx v4.0.2
making output directory... done
Exception occurred:
File "/Users/jdm/Dropbox/Tools/Software/Python/pyhht/docs/source/conf.py", line 282, in setup
app.add_javascript("https://docs.python.org/2/_static/copybutton.js")
AttributeError: 'Sphinx' object has no attribute 'add_javascript'
The full traceback has been saved in /var/folders/cs/lqjsdh5s69dd7csnhrxwmbgm0000gn/T/sphinx-err-gnmyqxeg.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [singlehtml] Error 2
And the log file shows this:
pyhht/docs $ more /var/folders/cs/lqjsdh5s69dd7csnhrxwmbgm0000gn/T/sphinx-err-gnmyqxeg.log
# Sphinx version: 4.0.2
# Python version: 3.8.8 (CPython)
# Docutils version: 0.17.1 release
# Jinja2 version: 2.11.3
# Last messages:
# Loaded extensions:
Traceback (most recent call last):
File "/Applications/anaconda3/lib/python3.8/site-packages/sphinx/cmd/build.py", line 276, in build_main
app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
File "/Applications/anaconda3/lib/python3.8/site-packages/sphinx/application.py", line 257, in __init__
self.config.setup(self)
File "/Users/jdm/Dropbox/Tools/Software/Python/pyhht/docs/source/conf.py", line 282, in setup
app.add_javascript("https://docs.python.org/2/_static/copybutton.js")
AttributeError: 'Sphinx' object has no attribute 'add_javascript'
in stop_sifting() the line: "sx = np.abs(envmoy) / amp" sometimes causes a divide by zero error.
also, I notice that right above this line (currently 376) there are some try/except checks for the return values of self.mean_and_amplitude(), but ONLY for two very specific errors. seems there should be an unconditional "except" too.
what's the right fix here?
-- jdm
I am coming across a specific error, "ValueError: setting an array element with a sequence." It shows up after the 2000th iteration, which I know is the set default. I tried changing the default number of iterations in the emd.py file for a quick fix, but it continues to just do 2000 iterations as a max.
My main issue is not the number of iterations, but rather why I am getting the error, "ValueError: setting an array element with a sequence." The main difference between the GitHub example and my analysis was that I was reading my signal data from a csv file.
I made sure the data sets were put into arrays, similar to the example involving modes=sin(2_pi_5_t)+sin(2_pi_10_t). Could it be that there are too many points in the csv file for "pyhht" to handle? The length of the array created by the CSV file is about 38200.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.