write a MATLAB function to calculate the EMD