I am trying to extract the envelope of the signal shown in blue, which is the low-pass filtered output of a second-order system. Low-pass filtering was done in order to reduce measurement noise. To be able to determine the decay of the system I want to extract the envelope of the signal. My MATLAB code looks as follows:

d = fdesign.hilbert(500,0.05);
hd = design(d,'equiripple','SystemObject',true);
coeff = hd.Numerator;
h = coeff / sum(abs(coeff));

y_hilb =  1i * filter(h, 1, y_filt);
y_an = y_filt + y_hilb;
env = abs(y_an);

Unfortunately, the envelope that I am extracting is actually tracking the signal rather than showing the actual envelope. What am I doing wrong here?

Sampling Period: 0.01s enter image description here

EDIT1: I changed the code as follows. Unfortunately, the result looks similar.

d = fdesign.hilbert(501,0.05);
delay = (N - 1) / 2;

y_an = y_filt(1 : end - delay) + 1j * y_hilb(delay + 1 : end);

EDIT2: As suggested, I removed the scaling of the coefficients. Result: enter image description here


2 Answers 2


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:


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.

  • $\begingroup$ Hi Matt, I now took into account the delay as you mentioned, please have a look at my first edit of the question. Unfortunately, the result looks similar. I tried the command hilbert, an the result looks better, although the envelope is still oscillating quite heavily. $\endgroup$ Jan 15, 2018 at 13:44
  • $\begingroup$ @Daiz: Don't scale the filter coefficients (with sum(abs(coeff))). $\endgroup$
    – Matt L.
    Jan 15, 2018 at 14:24
  • $\begingroup$ @Daiz: And note that if your signal is not a bandpass signal, the envelope computation via the Hilbert transform will not work well. $\endgroup$
    – Matt L.
    Jan 15, 2018 at 14:30
  • $\begingroup$ I removed the coefficient scaling. Now the amplitude is too big, but interestingly it already looks more like an actual envelope. Should I just scale it down until it fits, or is there a better way? Thanks already so far! $\endgroup$ Jan 15, 2018 at 14:36
  • $\begingroup$ @Daiz: You should always check the result of your filter design first. Plot the frequency response of the Hilbert transformer to see if it's OK. Then you should create a bandpass signal (by modulation of some lowpass signal) and apply the same processing. In that case you should get an almost perfect envelope (after the transients have decayed). Then you've checked your method. Finally, you might find out that even though the method works, it doesn't work for your signal because it's no bandpass signal. $\endgroup$
    – Matt L.
    Jan 15, 2018 at 16:45

As already mentioned you can use MATLAB inbuilt function hilbert to find the envelope. But hilbert function will give you analytical signal which is a complex number, to find envelope you need to take magnitude of analytical signal.

The hilbert function uses frequency domain approach (FFT) to realize the hilbert filter, alternatively you can realize hilbert filter in time domain by using FIR linear phase filter.

MATLAB code for type 3 linear phase FIR filter is:

L = 33; % length of filter
f = [0 0.004 0.05 0.55 0.7 1]; % these number you have to change based on your stop band and passband frequencies
m = [0 0.001 1 1 0.001 0]; % these are the gains/attenuations at passband/stopband
we = [1 1 100];
h = firpm(L-1, f, m,we, 'hilbert');

y = conv(x,y,'same'); % this is filter output, it takes into account the delay caused by filter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.