I've heard that the Hilbert transform can be used to calculate the envelope of a signal. How does this work? And how is this "Hilbert envelope" different from the envelope one gets by simply rectifying a signal?

I'm interested specifically in finding a way to calculate an envelope for use in dynamic range compression (i.e., "turning down the volume" of the loud parts of an audio signal automatically).

  • 1
    $\begingroup$ do you have some working code now ? either with Hilbert transsform or another method ? $\endgroup$
    – Basj
    Commented Nov 12, 2013 at 14:35

4 Answers 4


The Hilbert transform is used to calculate the "analytic" signal. See for example http://en.wikipedia.org/wiki/Analytic_signal. If your signal is a sine wave or an modulated sine wave, the magnitude of the analytic signal will indeed look like the envelope. However, the computation of the Hilbert transform is not trivial. Technically it requires a non-causal FIR filter of considerable length so it will require a fair amount of MIPS, memory and latency.

For a broad band signal, it really depends on how you define "envelope" for your specific application. For your application of dynamic range compression you want a metric that is well correlated with the the perception of loudness over time. The Hilbert Transform is not the right tool for that.

A better option would be to apply an A-weighted filter (http://en.wikipedia.org/wiki/A-weighting) and then do a lossy peak or lossy RMS detector. This will correlate fairly well with perceived loudness over time and is relatively cheap to do.

  • 1
    $\begingroup$ Both are non-causal, but is FFT method (throw away half of spectrum and IFFT) usually faster than FIR filter? $\endgroup$
    – endolith
    Commented Oct 17, 2011 at 16:31
  • 1
    $\begingroup$ Also, how does the FFT method for computing the Hilbert transform require non-causality? One probably just needs a fairly big window to get useful envelope shapes. $\endgroup$
    – mavavilj
    Commented Aug 1, 2017 at 17:52
  • $\begingroup$ Hilbert transform works ideally for any recorded signal with a carrier, or a stable band center within the filter window. i.e. it gives almost universally a perfect envelope of any amplitude modulated signal, which is very useful in experimental physics. . $\endgroup$
    – Asdf
    Commented Nov 20, 2023 at 10:41
  • $\begingroup$ On the contrary, FFT requires knowing the carrier exactly, and because of the window asymmetry relatively to the carrier, it will always result in expanding divergence with the actual amplitude from the window center, where it converges to the edges. Therefore strong window shaping and overlapping is mandatory, which increases computation, and still does not produce nice results. $\endgroup$
    – Asdf
    Commented Nov 20, 2023 at 10:41
  • $\begingroup$ Peak detector is just skipping the data and inheriting the aliasing error, which will produce unneeded noise. Absolutely not-recommended method useful only in very low performance computing, like in low-power PIC microcontrollers. $\endgroup$
    – Asdf
    Commented Nov 20, 2023 at 10:45

You can use the Hilbert transform to compute an envelope in the following way. (I will write it as MATLAB code):

envelope = abs(hilbert(yourTimeDomainSignal));

I do not have time to write the math out right now, (I will try later on), but very simply, say your signal is a sine wave. The Hilbert transform of a sine is a -cosine. (In other words, the hilbert transform will always give you your signal shifted by -90 degrees phase - its quadrature in other words).

If you add your signal (the sine wave) to j times your hilberted signal, (-cosine wave), you get:

sin(wt) - j.*cos(wt)

Which also happens to be e^(j*(wt - pi/2)).

Thus, when you take the absolute value of this, you get 1, which is your envelope. (For this case).

  • $\begingroup$ Oops! Forgot the negative sign - thanks Dilip, fixed now. $\endgroup$
    – Spacey
    Commented Oct 15, 2011 at 3:57
  • 4
    $\begingroup$ More than 8 years later and you still haven't found the "time to write the math out"? ;-) $\endgroup$
    – Hagbard
    Commented Dec 11, 2019 at 13:11

I am aware of at least two separate ways to retrieve the amplitude envelope from a signal.

The key equation is:

E(t)^2 = S(t)^2 + Q(S(t))^2

Where Q represents a π/2 phase shift (also known as quadrature signal).

Simplest way I am aware of is to get Q would be to decompose S(t) into a bunch of sinusoidal components using FFT, rotate each component a quarter turn anticlockwise ( remember each component is going to be a complex number so a particular component x + iy -> -y + ix ) and then recombine.

This approach works pretty well, although requires a bit of tuning (I don't yet understand the maths well enough to explain this in any better way)

There are a couple of key terms here, namely ' Hilbert transform ' and ' analytic signal '

I'm avoiding using these terms because I'm pretty sure I have witnessed considerable ambiguity in their use.

One document describes the (complex) analytic signal of an original real signal f(t) as:

Analytic(f(t)) = f(t) + i.H(f(t))

where H(f(t)) represents the 'π/2 phase shift' of f(t)

in which case the amplitude envelope is simply |Analytic(f(t))|, which brings us back to the original Pythagorean equation

NB: I have recently come across a more advanced technique involving frequency shifting and a lowpass digital filter. The theory is that we can construct the analytic signal by different means; we decompose f(t) into positive and negative sinusoidal frequency components and then simply remove the negative components and double the positive components. and it is possible to do this ' negative frequency component removal ' by a combination of frequency shifting and lowpass filtering. this can be done extremely fast using digital filters. I haven't yet explored this approach, so this is as much as I can say at the moment.

  • 3
    $\begingroup$ These are all just different ways of calculating the same thing (magnitude of the analytic signal through a Hilbert transform). The "advanced" technique is to simply do an FFT, zero out the negative frequencies and then do an inverse FFT. The real part is the original signal and the imaginary part the Hilbert transform of it. The devil is in the details like framing, windowing, overlapping and linear vs. circular processing. $\endgroup$
    – Hilmar
    Commented Apr 17, 2012 at 12:53
  • 2
    $\begingroup$ It is disheartening to see that some individual has seen fit to reward the time and energy I have given to this community (via the above post) with a downvote. A post which contains good solid information that will be of benefit to someone. $\endgroup$
    – P i
    Commented Apr 17, 2012 at 19:24
  • 2
    $\begingroup$ @Hilmar, There is a better way of 'removing the negative frequencies' in order to achieve the Hilbert Transform. As I said, a way that doesn't involve FFT. In light of the above, I don't feel particularly enthused to detail it right now. $\endgroup$
    – P i
    Commented Apr 17, 2012 at 19:31
  • 1
    $\begingroup$ Appreciate your detailed answer on the Hilbert transform; wanted to assure that this is well-received, hence not to be disheartened. Please ignore the downvote by whoever. $\endgroup$
    – user4285
    Commented Apr 5, 2013 at 10:47

so you basically are looking for an Automatic Gain Control (AGC). Not sure if you must do it by processing digitally, but there are very very good integrated circuits out there that can perform that task very well, usually the AGC is integrated with a lot of other features, but some circutis can be created with JFET transistors and some diodes.

But a very easily understandable way of doing this with digital processing would be to design an adaptive variance estimator, like taking a time window of enough samples to represent 5 or 10 msec, and apply a forgetting factor alpha^n (alpha <1) so each new sample that comes gets taken into account more than the past samples. then based on this variance estimation you design aaccording to your desire, a function that maps the variance to a gain that you apply to each audio sample. this could be a hard-decision boundary,whereas if the variance goes above some threshold you decrease the gain by some factor.

Or could be a more soft-decision boundary, where you create a non linear transformation from variance to gain, and apply the transformation to every sample based on the last variance estimation.

This are more heuristic methods but at least it saves you from all the heavy math.


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