Extracted envelope via Hilbert Transform is tracking the signal
Computing the envelope of a signal via the Hilbert transform only works well for bandpass signals.

But apart from that, you're not taking into account the delay of the Hilbert transformer when creating the analytic signal. It would be easier to choose an odd filter length $N$, because then you get an integer delay:

$$d=\frac{N-1}{2}$$

Also note that there's the command hilbert for directly computing the analytic signal. Furthermore, there's a function envelope that lets you choose different methods for computing the envelope of a signal.