The number of local maximums and minimums of the signal is not equal so I can't sum them. I mean ' h1 =(emax+emin)/2'.
And the other problem arises when I try to subtract the signal 'h1' from the original signal 'X'. because the dimension of two signals are not equal.
what should I do to make the dimensions equal?