The world’s leading publication for data science, AI, and ML professionals.

Instantaneous phase and magnitude with the Hilbert transform

Applying the Hilbert transform to better understand periodic data

Better understand periodic data with the Hilbert transform

Photo by Maxim Tolchinskiy on Unsplash
Photo by Maxim Tolchinskiy on Unsplash

Motivation

In other articles, we’ve explored the application of the Fourier transform to decompose the frequency components of a signal.

The Fourier transform, though, doesn’t tell us much about the temporal or spatial dynamics of our original signal. We know what frequencies composed our original signal, but not when/where the frequencies were or how they evolved over time. Let’s start addressing this deficiency by building out our digital signal processing toolkit! Here, we will examine a simple application of the Hilbert transform to a real-valued signal to understand its practical importance.

Why does it matter for the data scientist? Easy! When we are working with periodic data, we are often most interested in the dynamics of phase and magnitude rather than raw values. From chronobiology to climate science, the Hilbert transform is crucial to making sense of data.

Sample signal

To demonstrate the application of the Hilbert transform, let’s consider a simple continuous wave (CW) pulse.

In this code snippet, the first cosine defines a constant frequency for our carrier wave. The sine function scales this carrier, amplitude modulating the pulse.

Real and imaginary components of the Hilbert transform

In Figure 1a, the simulated CW pulse is shown. As expected, the signal is real-valued and includes a single, constant frequency amplitude modulated by a lower frequency.

Figure 1: (a) Simple CW pulse and (b) the Hilbert transform of this real-valued signal. Image by author.
Figure 1: (a) Simple CW pulse and (b) the Hilbert transform of this real-valued signal. Image by author.

The real and imaginary components of the values returned by the Hilbert transform are shown in Figure 1b. Calling the Hilbert transform on our real-valued signal is… complex! The real component is identical to our input pulse. The imaginary component, though, is a phase shifted duplicate.

Phase and magnitude estimation

OK, so the Hilbert transform adds an imaginary component to our signal… Why? Also, couldn’t we have just phase shifted the pulse ourselves?

We’ll get to "why?" in just a moment, but before we continue it is worth addressing the second question. We certainly could have! Remember, though, that we contrived this simple signal to demonstrate the mechanics. Correctly phase shifting a signal with arbitrary frequency components can be tricky! We leave it as an exercise to the reader 😉

Figure 2: (a) Phase and (b) magnitude of the Hilbert transform. Image by author.
Figure 2: (a) Phase and (b) magnitude of the Hilbert transform. Image by author.

Now to the magic! Let’s examine the phase and magnitude of the complex-valued results of the Hilbert transform.

Introducing this phase shifted duplicate signal as an imaginary component allows us to continuously measure the phase and magnitude! If you need a refresher on what the phase and magnitude reflect in this context…

While the phase angle values are meaningless for the signal’s stationary leading and trailing zero-valued tails, it shows the expected wrapped phase progression for the pulse duration (Figure 2a).

Using the magnitude information we have recovered using the Hilbert transform, we can plot the signal’s "envelope": a smooth curve bounding the signal (Figure 2b).

Conclusion

The Hilbert transform extends our DSP toolkit and allows us to estimate the phase and magnitude of an input signal. When working with amplitude modulated signals, this is critical! If you take a peek at the source supporting my NOAA signal decoding article, you’ll see the Hilbert transform playing a central role.


Up next, I’ll walk through how wavelets can be used to recover frequency information while preserving temporal/spatial information! Thanks for reading!


Related Articles