Decomposing Signal Using Empirical Mode Decomposition — Algorithm Explanation for Dummy | by Muhammad Ryan | Towards Data Science

What kind of ‘beast’ is Empirical Mode Decomposition (EMD) is? It’s an algorithm to decompose signals. And when I say signal, what I mean is a time-series data. We inputting a signal to the EMD and we will get some decomposed signal a.k.a ‘basic ingredient’ of our signal input. It’s similar to the Fast Fourier Transform (FFT). FFT assumes our signal is periodic and it’s ‘basic ingredient’ is various simple sine waves. In FFT, our signal is changed from the time spectrum to the frequency spectrum.
The different with EMD is the output remains in the time spectrum and EMD does not assume our signal is periodic and it’s not based on simple sine wave instead, it’s Intrinsic Mode Function (IMF). EMD is really based on the dataset, doesn’t have an assumption about the data (That why it’s called Empirical). IMF is a wave that obeying 2 properties:
The difference number of maxima and minima at most by 1. Maxima is a peak of wave and minima is a valley.
The difference number of maxima and minima at most by 1. Maxima is a peak of wave and minima is a valley.
Assume our dataset has been standardized using
Then maxima not always above zero and minima not always below zero. Maxima is the value of the signal where when the trend in the signal continues to go up then suddenly go down, the value right before the value goes down is maxima. On the other hand, Minima is when the trend in the signal continues to go down then suddenly go up, the value right before goes up is minima.
2. The Mean of the wave of IMF is zero.
A simple sine wave is an IMF (The difference between minima and maxima is at most by 1 ✓, The mean of the dataset is zero ✓).
>>> import numpy as np>>> frequency = 1>>> total_time = 1>>> res = 0.01>>> time = np.arange(0, total_time, res)>>> amplitude = np.sin(2 * np.pi * frequency * total_time * (time/time[-1]))>>> np.mean(amplitude)-2.6319088627735572e-17 #this value literally equal 0
But an IMF can have more than 1 frequency and more complex.
To make it more easy for us to understand the algorithm, here I present a toy test signal.
This signal (1 Hz sine wave)
and this (4 Hz sine wave)
are combined become this
Voila, we will try to decompose this signal trough this step by step algorithm explanation.
Here the algorithm of EMD.
Step 1, Find the Minima and Maxima.
Step 2, create an envelope of minima and maxima from the array of minima and maxima. Interpolate the value of minima and maxima to create an envelope of minima and maxima using a cubic spline.
Step 4, from the envelope of minima and maxima, get the middle value.
Step 5, decrease the value of the real toy test signal by the middle value of the envelope.
If you look closely, this is our 4 Hz sine wave successfully extracted. But looks like there is some error like a sudden leap on both sides of the wave. This has come from the error of the interpolation of the cubic spline. The interpolation of the cubic spline becomes so bad at the beginning and the end of the signal. The solution is we must define a boundary condition. What I mean about boundary condition is we must define the envelope of minima and maxima at the beginning and the end of the signal before doing the cubic spline. In this article, the envelope of minima and maxima of the beginning and the end of the signal is the same as with the nearest maxima and minima from them. Let’s restart it from step 1 to step 5 but this time, we define the boundary condition.
Ouch, this time the error is affected the entire extracted signal. But the sudden leap has vanished.
Step 6, Check if this extracted signal is an IMF.
#here is the ouput of python scriptmean: -0.002681745482482584 Total minima 20 Total maxima 21
The mean is nearly zero, I think we can ignore it and round it to zero. The number of Minima and Maxima also fulfill the requirement, we get an IMF. If you are not satisfied with the mean of the extracted signal, you can process it 1 more time following step 2 — step 6. But this time, instead of inputting a real toy test signal, we use that extracted signal. This the route of the algorithm when in the first or second or so on triest, the extracted signal not satisfied IMF condition. To make it more simple, let’s just admit the signal is an IMF.
Step 7, decrease the original toy test signal with this IMF.
Woah, we get our 1 Hz signal (but as we thought, the beginning and the end is wrong). It looks like we success to decompose our fused signal. But, the condition to stop in the algorithm of EMD is when our residuum signal is just a constant, monotonic, or just have 1 extremum (just have 1 minima or maxima). Our signal which we have reduced by the IMF before is called residuum. Let’s continue the process.
mean: -0.002681745482482584 Total minima 6 Total maxima 6
It looks like the requirement of the residuum not yet fulfilled. Let’s processed it again.
mean: -0.002681745482482584 Total minima 2 Total maxima 2
And at last, we find the residuum (monotonic). The last extracted looks like just noise because of the accumulative error of boundary. This is can be prevented by raising the threshold of the mean of the signal. When the mean of the signal is not fulfilling the threshold (the extracted signal is not an IMF), it will try again following step 2–6 until the extracted signal fulfill the threshold. The more convergence the threshold to zero, the more likely this noise vanishes. So that this article is not too long, in the EMD algorithm demonstration earlier, the threshold we used was not too strict. Because in the end what we want to achieve here is that readers understand step by step the EMD algorithm easily.
For the first time, I am trying using google colab, so all the code and explanation to build all graph above can be accessed through this link (ps: some code must be run in the order to make it work properly).
See you.
references:
https://medium.com/@rrfd/standardize-or-normalize-examples-in-python-e3f174b65dfc, accessed on 2 October 2019
Zeiler, A., Faltermeier, R., Keck, I. R., Tomé, A. M., Puntonet, C. G., & Lang, E. W. (2010, July). Empirical mode decomposition-an introduction. In The 2010 International Joint Conference on Neural Networks (IJCNN) (pp. 1–8). IEEE.