|
1 | 1 | # MEMD-Python-
|
2 | 2 | Python version of the Multivariate Empirical Mode Decomposition algorith
|
| 3 | + |
| 4 | + |
| 5 | +Created on Wed Mar 14 16:50:30 2018 |
| 6 | + |
| 7 | +@author: Mario de Souza e Silva |
| 8 | + |
| 9 | + |
| 10 | +This is a translation of the MEMD (Multivariate Empirical Mode Decomposition) |
| 11 | +code from Matlab to Python. |
| 12 | + |
| 13 | +The Matlab code was developed by [1] and is freely available at: |
| 14 | + . http://www.commsp.ee.ic.ac.uk/~mandic/research/emd.htm |
| 15 | + |
| 16 | +The only difference in this Python script is that the input data can have any |
| 17 | +number of channels, instead of the 36 estabilished in the original Matlab code. |
| 18 | + |
| 19 | +All of the defined functions have been joined together in one single script |
| 20 | +called MEMD_all. Bellow follows the Syntax described in [1], but adapted to |
| 21 | +this Python script. |
| 22 | + |
| 23 | +------------------------------------------------------------------------------- |
| 24 | +Syntax: |
| 25 | +from MEMD_all import memd |
| 26 | + |
| 27 | +imf = memd(X) |
| 28 | + returns a 3D matrix 'imf(M,N,L)' containing M multivariate IMFs, one IMF per column, computed by applying |
| 29 | + the multivariate EMD algorithm on the N-variate signal (time-series) X of length L. |
| 30 | + - For instance, imf_k = IMF[:,k,:] returns the k-th component (1 <= k <= N) for all of the N-variate IMFs. |
| 31 | + |
| 32 | + For example, for hexavariate inputs (N=6), we obtain a 3D matrix IMF(M, 6, L) |
| 33 | + where M is the number of IMFs extracted, and L is the data length. |
| 34 | + |
| 35 | +imf = memd(X,num_directions) |
| 36 | + where integer variable num_directions (>= 1) specifies the total number of projections of the signal |
| 37 | + - As a rule of thumb, the minimum value of num_directions should be twice the number of data channels, |
| 38 | + - for instance, num_directions = 6 for a 3-variate signal and num_directions= 16 for an 8-variate signal |
| 39 | + The default number of directions is chosen to be 64 - to extract meaningful IMFs, the number of directions |
| 40 | + should be considerably greater than the dimensionality of the signals |
| 41 | + |
| 42 | +imf = memd(X,num_directions,'stopping criteria') |
| 43 | + uses the optional parameter 'stopping criteria' to control the sifting process. |
| 44 | + The available options are |
| 45 | + - 'stop' which uses the standard stopping criterion specified in [2] |
| 46 | + - 'fix_h' which uses the modified version of the stopping criteria specified in [3] |
| 47 | + The default value for the 'stopping criteria' is 'stop'. |
| 48 | + |
| 49 | + The settings num_directions=64 and 'stopping criteria' = 'stop' are defaults. |
| 50 | + Thus imf = memd(X) = memd(X,64) = memd(X,64,'stop') = memd(X,None,'stop'), |
| 51 | + |
| 52 | +imf = memd(X, num_directions, 'stop', stop_vec) |
| 53 | + computes the IMFs based on the standard stopping criterion whose parameters are given in the 'stop_vec' |
| 54 | + - stop_vec has three elements specifying the threshold and tolerance values used, see [2]. |
| 55 | + - the default value for the stopping vector is step_vec = (0.075,0.75,0.075). |
| 56 | + - the option 'stop_vec' is only valid if the parameter 'stopping criteria' is set to 'stop'. |
| 57 | + |
| 58 | +imf = memd(X, num_directions, 'fix_h', n_iter) |
| 59 | + computes the IMFs with n_iter (integer variable) specifying the number of consecutive iterations when |
| 60 | + the number of extrema and the number of zero crossings differ at most by one [3]. |
| 61 | + - the default value for the parameter n_iter is set to n_iter = 2. |
| 62 | + - the option n_iter is only valid if the parameter 'stopping criteria' = 'fix_h' |
| 63 | + |
| 64 | + |
| 65 | +This code allows to process multivaraite signals having any number of channels, using the multivariate EMD algorithm [1]. |
| 66 | + - to process 1- and 2-dimensional (univariate and bivariate) data using EMD in Python, it is recommended the toolbox from |
| 67 | + https://bitbucket.org/luukko/libeemd |
| 68 | + |
| 69 | +Acknowledgment: All of this code is based on the multivariate EMD code, publicly available from |
| 70 | + http://www.commsp.ee.ic.ac.uk/~mandic/research/emd.htm. |
| 71 | + |
| 72 | + |
| 73 | +[1] Rehman and D. P. Mandic, "Multivariate Empirical Mode Decomposition", Proceedings of the Royal Society A, 2010 |
| 74 | +[2] G. Rilling, P. Flandrin and P. Goncalves, "On Empirical Mode Decomposition and its Algorithms", Proc of the IEEE-EURASIP |
| 75 | + Workshop on Nonlinear Signal and Image Processing, NSIP-03, Grado (I), June 2003 |
| 76 | +[3] N. E. Huang et al., "A confidence limit for the Empirical Mode Decomposition and Hilbert spectral analysis", |
| 77 | + Proceedings of the Royal Society A, Vol. 459, pp. 2317-2345, 2003 |
| 78 | + |
| 79 | + |
| 80 | +Usage |
| 81 | + |
| 82 | + |
| 83 | +Case 1: |
| 84 | +import numpy as np |
| 85 | + |
| 86 | +np.random.rand(100,3) |
| 87 | +imf = memd(inp) |
| 88 | +imf_x = imf[:,0,:] #imfs corresponding to 1st component |
| 89 | +imf_y = imf[:,1,:] #imfs corresponding to 2nd component |
| 90 | +imf_z = imf[:,2,:] #imfs corresponding to 3rd component |
| 91 | + |
| 92 | + |
| 93 | +Case 2: |
| 94 | +import numpy as np |
| 95 | + |
| 96 | +inp = np.loadtxt('T045.txt') |
| 97 | +imf = memd(inp,256,'stop',(0.05,0.5,0.05)) |
0 commit comments