The Hilbert transform and the analytic signal
| Problem | Form the complex signal whose real part is a given real signal and whose spectrum has no negative frequencies; read off the instantaneous amplitude, phase and frequency |
| Devised by | David Hilbert (1905), the integral transform; Dennis Gabor (1946), the analytic signal; Lawrence Marple (1999), the discrete-time construction by the DFT |
| Accuracy | Agrees with SciPy’s hilbert to |
| Cost | Two FFTs of the signal length |
| Read first | The fast Fourier transform |
| API | analytic_signal, hilbert_transform, instantaneous_attributes (InstantaneousAttributes) |
Overview
A real signal’s spectrum is symmetric: every positive frequency has a negative twin carrying the same information. Discarding the negative half and doubling the positive half gives the analytic signal , whose imaginary part is the Hilbert transform of , the signal with every component shifted by 90°: , . For a narrow-band signal , the analytic signal is , so its magnitude is the envelope and the derivative of its phase is the instantaneous frequency. Demodulation, envelope detection, single-sideband modulation and the analysis of chirps and vibrations all rest on it.
Where it is used
The analytic signal gives amplitude and phase at every instant.
- Communications. Single-sideband modulation and quadrature (I/Q) processing use the Hilbert transform to remove the negative-frequency half of a spectrum.
- Envelope detection. Amplitude envelope of vibration signals for bearing fault diagnosis, and of audio.
- Instantaneous frequency. Estimating how the frequency of a chirp, a seismic wave or an EEG rhythm changes with time.
- Radar and sonar. Complex baseband signals.
History
David Hilbert studied the integral transform in 1905 in connection with boundary-value problems for analytic functions, whose real and imaginary parts on the boundary are Hilbert transforms of each other. Dennis Gabor (1946) introduced the analytic signal in his “Theory of communication”, defining the instantaneous amplitude and frequency of a real signal. Lawrence Marple (1999) gave the discrete-time analytic signal computed with the DFT, the construction used by MATLAB and SciPy.
The idea
Removing negative frequencies
The motivating example. A real oscillation hides its amplitude and its phase behind each other: from the value at one instant there is no telling whether the signal is small because is small or because the cosine is near zero. The complex signal has no such ambiguity. Its magnitude is and its angle is , at every instant. The analytic signal is the systematic way to pass from the first to the second.
The link is Euler’s formula, . A real cosine is the sum of a positive-frequency exponential and a negative-frequency one, each of half the amplitude. Deleting the negative-frequency half and doubling the positive one leaves exactly . Doing this to every frequency component of a real signal gives its analytic signal .
The Hilbert transform. The imaginary part of is called the Hilbert transform of , so that . It turns every cosine into a sine: each frequency component is shifted in phase by a quarter cycle, which in the frequency domain is multiplication by . The analytic signal therefore has spectrum : twice for , at , and zero for , as described. In discrete time, with an -point DFT, the recipe is:
The DC and Nyquist bins are their own negatives and are kept once. The real part of is exactly .
Envelope and instantaneous frequency
Figure 15.6. Envelope of an AM signal.
The magnitude of the analytic signal is the envelope of , the slowly varying amplitude within which it oscillates. For an amplitude-modulated carrier, recovers the modulation, here exactly, because the modulation (3 Hz) is far below the carrier (60 Hz) and the record holds whole periods of both. The angle is the instantaneous phase, and its rate of change is the instantaneous frequency, , computed from phase differences between samples:
Figure 15.7. Instantaneous frequency of a chirp.
The estimate follows the chirp’s linear sweep except at the ends. There the DFT’s implicit periodic extension joins the high-frequency end to the low-frequency start, and the Gibbs ripple of that discontinuity disturbs the phase. Taper or pad the signal if the ends matter.
When it makes sense
The envelope and instantaneous frequency are meaningful only for narrow-band signals. For a sum of two tones, the analytic signal’s phase advances at a rate that beats between them, and the instantaneous frequency can even be negative. The decomposition of a signal into amplitude and phase is not unique, and the analytic signal is one particular, well-behaved choice; Bedrosian’s theorem says when it separates them correctly.
Algorithm
Analytic signal of a real signal of samples.
- Take the FFT of the signal.
- Modify the bins: leave bin 0 (DC) unchanged; double bins (the positive frequencies); leave the Nyquist bin unchanged if is even; set the remaining bins (the negative frequencies) to zero.
- Take the inverse FFT. The result is complex: its real part is the original signal and its imaginary part is the Hilbert transform.
Attributes computed from :
- the envelope is ;
- the instantaneous phase is , unwrapped: whenever the phase jumps by more than between consecutive samples, a multiple of is added to remove the jump, so that the phase is continuous;
- the instantaneous frequency is the difference of the unwrapped phase between consecutive samples, times . It has one value fewer than the signal.
The cost is two FFTs.
Implementation
let input: Vec<Complex<f64>> = x.iter().map(|&v| Complex::new(v, 0.0)).collect();
let mut spectrum = Fft::with_plan(n, FftScaleFactor::None, FftDirection::Forward, FftOrdering::Standard)?.execute(&input)?;
let half = n.div_ceil(2);
for (k, s) in spectrum.iter_mut().enumerate() {
if k == 0 || (n.is_multiple_of(2) && k == n / 2) {
continue;
}
*s *= if k < half { 2.0 } else { 0.0 };
}
Fft::with_plan(n, FftScaleFactor::N, FftDirection::Inverse, FftOrdering::Standard)?.execute(&spectrum)
- The transform is circular: it assumes the record is one period of a periodic signal.
instantaneous_attributesreturns frequencies one sample shorter than the signal, at the midpoints between samples.- An FIR Hilbert transformer for streaming use can be designed with
remezandRemezFilterType::Hilbert.
In practice
//! The analytic signal: envelope and instantaneous frequency.
use lib_jsl_dsp::discrete::spectral::hilbert::{analytic_signal, instantaneous_attributes};
use std::f64::consts::PI;
fn main() {
let fs = 1000.0;
let x: Vec<f64> = (0..1000).map(|n| (2.0 * PI * 50.0 * n as f64 / fs).cos()).collect();
let z = analytic_signal(&x).unwrap();
println!("cos → analytic signal at n = 0, 5: {:.3}, {:.3}", z[0], z[5]);
let am: Vec<f64> = (0..1000).map(|n| {
let t = n as f64 / fs;
(1.0 + 0.5 * (2.0 * PI * 2.0 * t).sin()) * (2.0 * PI * 100.0 * t).cos()
}).collect();
let attr = instantaneous_attributes(&am, fs).unwrap();
let mid = 500;
println!("envelope at t = 0.5 s: {:.4} (true {:.4})", attr.amplitude[mid], 1.0 + 0.5 * (2.0 * PI * 2.0 * 0.5f64).sin());
let f = &attr.frequency[200..800];
println!("instantaneous frequency: mean {:.3} Hz", f.iter().sum::<f64>() / f.len() as f64);
}
cos → analytic signal at n = 0, 5: 1.000+0.000i, 0.000+1.000i
envelope at t = 0.5 s: 1.0000 (true 1.0000)
instantaneous frequency: mean 100.000 Hz
Strengths
- Exact, fast, and parameter-free envelope and phase extraction for narrow-band signals.
Weaknesses
- Circular edge effects; meaningless “instantaneous” quantities for broadband or multi-component signals.
Exercises
- Show that the Hilbert transform of is for , and that for signals without a DC component.
- Show that the analytic signal of is when the spectrum of lies below (Bedrosian’s theorem).
- Compute the instantaneous frequency of and find where it is negative.
- Explain why the analytic signal’s DC and Nyquist bins must not be doubled.
Hints and answers
- The spectrum of is two impulses at ; the transform multiplies positive frequencies by and negative by , giving . Applying it twice multiplies each non-zero frequency by (for positive) and (for negative), so .
- when the spectrum of does not overlap that of the carrier; then the analytic signal .
- The analytic signal is and the instantaneous frequency is . It is negative where , i.e. near (within about rad): negative instantaneous frequency arises because the signal is not a single narrow-band component.
- The DC and Nyquist bins are their own conjugates (they have no mirror image to cancel), so doubling them would change the real part; they are left unscaled, and only the positive-frequency bins are doubled.
Further reading
- D. Gabor, “Theory of communication”, Journal of the IEE, Part III 93 (1946) 429–457.
- S. L. Marple, “Computing the discrete-time analytic signal via FFT”, IEEE Transactions on Signal Processing 47 (1999) 2600–2603.
- B. Boashash, “Estimating and interpreting the instantaneous frequency of a signal”, Proceedings of the IEEE 80 (1992) 520–568.