jaidevd / pyhht

Python toolbox for the Hilbert-Huang transform
Other
254 stars 88 forks source link

Instantaneous frequencies are not consistent with the plot of HHT #43

Closed hbake001 closed 3 years ago

hbake001 commented 6 years ago

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?

image

WRAR891 commented 6 years ago

I, too, have questions about how to interpret the results of utils.inst_freq(). I tried

f, ts = utils.inst_freq(np.sin(2.0 np.pi 10.0 * t)) plt.xlabel('Ts') plt.ylabel('Freq') plt.plot(ts, f) plt.show()

and get an unexpected result. Clearly, the inst. freq should be a constant value for this. Is there some usage detail that is being overlooked?

figure_1

hbake001 commented 6 years ago

@WRAR891 I think it's a major bug in this package. Waiting the confirmation from the author

jaidevd commented 6 years ago

Thanks for pointing this out, @hbake001 and @WRAR891

This implementation of instantaneous frequency detection was adapted from the MATLAB toolbox for time frequency analysis - http://tftb.nongnu.org/

I don't think it is meant to work with IMFs at all, since the definition of the instantaneous frequency of an IMF is the derivative of the arctan of the Hilbert transform of the IMF. I'll dig deeper into this over the weekend.

jaidevd commented 6 years ago

Hi @hbake001 @WRAR891

I'm able to reproduce this and this is indeed a bug in the instantaneous frequency estimation. @WRAR891 in your example, the input is not an analytic signal, and those are required for instantaneous frequencies to be well defined. Converting your signal into an analytic one with the scipy.signal.hilbert function should produce a better, more meaningful results - but they would still not be perfect. Give me a couple of days and I'll get this fixed.

Thanks

jaidevd commented 6 years ago

@WRAR891 As I said earlier, the problem was the analyticity of the signal. Converting the input to an analytical signal seems to be giving reasonable, almost identical results in both MATLAB and pyhht. Here are the instantaneous frequency plots for your specific example,

MATLAB: matlab_inst_freq

pyhht figure_1

@hbake001 Can you provide an example so I can debug your problem? Also please mention which MATLAB package you are using to generate instantaneous frequencies.

Thanks,

WRAR891 commented 6 years ago

@jaidevd, @hbake001

I agree, that for analytical or complex-valued signals, inst_freq() appears to give a reasonable result. One could compare it to: 1.0 / (2.0 np.pi) np.diff(np.unwrap(np.angle(m)))

where m is a mode expressed as the hilbert xform of a real-valued signal. Note: if the mode itself is complex-valued, one does not need to hilbert-transform it.

atilileri commented 5 years ago

Hi everyone, I am also trying to get instant frequencies from my signal, I tried using hilbert() to convert my signal to analytic one but, I believe I am missing something, somewhere. My result looks like below: image And below is my codepiece: https://github.com/atilileri/Thesis01/blob/master/insFrqPyhht.py

Am I doing something wrong? Thanks in advance.

jaidevd commented 5 years ago

Hi @atilileri

I looked at your code, and it appears that you're reading an audio file and converting the waveforms into an analytic signal using scipy.signal.hilbert. However, please note that the analyticity of the signal alone does not guarantee well behaved instantaneous frequency. For that to happen, two conditions must be met:

  1. Signal must be an IMF
  2. Signal should be analytic.

In your script, it doesn't look like you have done anything to decompose the signal into purely amplitude/frequency modulated modes. Without that, there is no reason to expect the instantaneous frequency calculation to be meaningful.

Hope this helps.

atilileri commented 5 years ago

Hi again,

As you said; I extracted imfs from the original signal and then applied hilbert(), got better results. Adding a sample screenshot for reference. Hope it helps some more googlers like me :). Thanks for the help again @jaidevd image And below is my codepiece again: https://github.com/atilileri/Thesis01/blob/master/insFrqPyhht.py

DuanHaiyang525 commented 5 years ago

Hi, Why could not I find the method about instantaneous frequencies?