laszukdawid / PyEMD

Python implementation of Empirical Mode Decompoisition (EMD) method
https://pyemd.readthedocs.io/
Apache License 2.0
857 stars 222 forks source link

Rectify the rescaling step for "a posteriori" test #114

Open oshin94 opened 2 years ago

oshin94 commented 2 years ago

Describe the bug The re-scaling step in the "a posterior" test is not accurate at the moment. In the current method, the IMFs are rescaled using a "subtraction/addition" operation. This does not always give the correct output. The proper way to do this would be re-scaling the IMFs using a "division/multiplication" operation. Currently, this is what we are using. https://github.com/laszukdawid/PyEMD/blob/5859f5ea7e435ffc6e5130e5a1df9cd71784a75d/PyEMD/checks.py#L118-L125

To Reproduce Proposed changes,

up_limit = -scaling_imf_mean_period + (k * math.sqrt(2 / N) * math.exp(scaling_imf_mean_period) / 2)

scaling_factor = math.exp(up_limit)

for idx, imf in enumerate(IMFs):
    log_T = math.log(mean_period(imf))
    if idx != rescaling_imf - 1:
        scaled_energy_density = math.log((energy(imf) / N) / scaling_factor) 
    else:
        scaled_energy_density = math.log(scaling_factor)

@laszukdawid Please advise if I shall raise a pull request. Also, I am hoping to add visualizations for the tests so that users can visually check if the outputs are as expected. Do let me know if that will be required.

laszukdawid commented 2 years ago

Hi @oshin94 , super sorry that it took my that long to reply! Simple distraction combined with forgetfulness.

As it is right now, I haven't heard of anyone using this module so it should be relatively safe to update it. It's a bit on me that I didn't do thorough check. Feel free to create a PR and we can work on it together :-)