Skip to content

Commit

Permalink
Fixing #102 - check for zero residue and discard
Browse files Browse the repository at this point in the history
  • Loading branch information
laszukdawid committed Oct 29, 2021
1 parent 6d78eb4 commit da7d203
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
15 changes: 11 additions & 4 deletions PyEMD/EMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def emd(self, S: np.ndarray, T: Optional[np.ndarray] = None, max_imf: int = -1)

# Create arrays
imfNo = 0
extNo = -1
IMF = np.empty((imfNo, N)) # Numpy container for IMF
finished = False

Expand Down Expand Up @@ -911,11 +912,17 @@ def emd(self, S: np.ndarray, T: Optional[np.ndarray] = None, max_imf: int = -1)
finished = True
break

# Saving residuum
self.residue = residue = S - np.sum(IMF, axis=0)
# If the last sifting had 2 or less extrema then that's a trend (residue)
if extNo <= 2:
IMF = IMF[:-1]

# Saving imfs and residue for external references
self.imfs = IMF.copy()
if not np.allclose(residue, 0):
IMF = np.vstack((IMF, residue))
self.residue = S - np.sum(self.imfs, axis=0)

# If residue isn't 0 then add it to the output
if not np.allclose(self.residue, 0):
IMF = np.vstack((IMF, self.residue))

return IMF

Expand Down
2 changes: 1 addition & 1 deletion PyEMD/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

__version__ = "1.0.0"
__version__ = "1.1.0"
logger = logging.getLogger("pyemd")

from PyEMD.EMD import EMD
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
numpy>=1.12
numpydoc
scipy>=0.19
numpy>=1.12,<=1.20
scipy>=0.19,<=1.18
pathos>=0.2.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = "1.0.1"
VERSION = "1.1.0"

DESCRIPTION = "Implementation of the Empirical Mode Decomposition (EMD) and its variations"

Expand Down

0 comments on commit da7d203

Please sign in to comment.