---
title: The discrete Hilbert transform
heading: The ideal 90° phase shifter, its impulse response and FIR approximations, analytic signals, envelopes and instantaneous frequency, and single-sideband modulation
eyebrow: S7 · Lesson 40 · The discrete Hilbert transform
xp: 50
---

::: hook
A real signal's spectrum always has a mirror image at negative frequencies, which carries no new information but gets in the way: it's why multiplying by a carrier gives two sidebands, and why a signal's envelope can't simply be read off its samples. The Hilbert transform shifts every positive frequency by −90° and every negative one by +90°. Combine a signal with its Hilbert transform as real and imaginary parts and the negative frequencies cancel, leaving the analytic signal, whose magnitude is the envelope and whose phase gives the instantaneous frequency. Radios use it for single-sideband transmission, and every envelope detector in software uses it.
:::

::: play
- An amplitude-modulated carrier $x = (1 + m\cos\Omega n)\cos\omega_cn$ (solid) and the magnitude of its analytic signal $|x + j\hat{x}|$ (dashed), which traces the envelope $1 + m\cos\Omega n$ exactly while the modulation is slow compared with the carrier.
- The envelope follows the peaks smoothly, with no ripple at the carrier frequency, which is what a rectifier and lowpass filter can only approximate.
- Push the modulation index past 1 and the "envelope" becomes |1 + m cos Ωn|: the analytic signal reports magnitude, so overmodulation shows as folding.
:::
:::

```sim plot
view: graph
x: n = 0..200
y: x = -2.2..2.2
slider: m = 0..1.5 = 0.6
slider: c = 0.3..1.5 = 0.8
plot: (1 + m*cos(0.05*n))*cos(c*n) | samples: 1200 | label: AM signal
plot: abs(1 + m*cos(0.05*n)) | samples: 600 | dashed | color: ch3 | label: |analytic signal|
```

::: predict
## A tone cos(ω₀n) passes through an ideal Hilbert transformer. What comes out?

- [ ] cos(ω₀n), unchanged
- [x] sin(ω₀n)
- [ ] −cos(ω₀n)
- [ ] Nothing: the Hilbert transform removes real signals

::: reveal
sin(ω₀n). The transformer multiplies positive frequencies by −j and negative ones by +j: $\frac{1}{2}e^{j\omega_0n}(-j) + \frac{1}{2}e^{-j\omega_0n}(j) = \sin\omega_0n$, a 90° delay of every component with no change in amplitude. Then cos + j sin = $e^{j\omega_0n}$: the analytic signal of a cosine is a single complex exponential at positive frequency.
:::
:::

::: nameit
## The ideal Hilbert transformer

$$H(e^{j\omega}) = \begin{cases}-j, & 0 < \omega < \pi\\ j, & -\pi < \omega < 0\end{cases}, \qquad h[n] = \begin{cases}\frac{2}{\pi n}, & n \text{ odd}\\ 0, & n \text{ even}\end{cases}$$

Noncausal and infinitely long, so it's approximated by a delayed, windowed FIR filter: antisymmetric, so Type III (odd length, zeros at 0 and π) or Type IV (even length, zero at 0). No FIR Hilbert transformer works all the way down to DC; a Type III one can't work at π either. Truncation causes Gibbs ripple: keeping only the taps at ±1 and ±3 gives the amplitude $\frac{4}{\pi}(\sin\omega + \frac{1}{3}\sin 3\omega)$, which is 0.849 at π/2 against the ideal 1.

## The analytic signal

$x_a[n] = x[n] + j\hat{x}[n]$ has $X_a(e^{j\omega}) = 2X(e^{j\omega})$ for 0 < ω < π and zero for negative frequencies. Then

- **envelope**: $|x_a[n]|$;
- **instantaneous phase**: $\arg x_a[n]$, and **instantaneous frequency**: its rate of change.

For two tones of amplitudes A and B, the envelope at a moment when they differ in phase by φ is $\sqrt{A^2 + B^2 + 2AB\cos\phi}$.

## Single sideband

With a message x and its Hilbert transform, $x\cos\omega_cn - \hat{x}\sin\omega_cn = \text{Re}\{x_ae^{j\omega_cn}\}$ contains only the upper sideband (the + sign gives the lower), using half the bandwidth of double-sideband AM.

## Causal sequences

For a causal sequence, the real and imaginary parts of the DTFT are a Hilbert pair; for a minimum-phase system, so are the log magnitude and the phase (lesson 13). A magnitude response therefore determines the minimum-phase response completely.
:::

::: example
## What are the first taps of the ideal Hilbert transformer, and how far does a 4-tap approximation fall short at π/2?

::: solution
1. **The ideal taps.**
   $$\begin{aligned} h[\pm1] &= \pm 2/\pi \\ &= \pm 0.637 \\ h[\pm3] &= \pm 0.212 \end{aligned}$$
   and every even tap is zero.
2. **Four taps at π/2.** Keeping ±1 and ±3 gives
   $$\begin{aligned} A(\pi/2) &= \frac{4}{\pi}\left(1 - \frac{1}{3}\right) \\ &= 0.849 \end{aligned}$$
   instead of 1.
3. **At π/4.** It overshoots to 1.200.
4. **Longer filters.** Longer, windowed filters approach 1 across most of the band.

**Answer:** the first taps are ±0.637 at n = ±1 and ±0.212 at n = ±3, with the even taps zero; the 4-tap version reaches only 0.849 at π/2 instead of 1.
:::
:::

::: example
## Two tones of amplitude 1 and 0.5 beat together. Between what values does the envelope swing?

::: solution
1. **Envelope.**
   $$E = \sqrt{1 + 0.25 + \cos\phi}$$
2. **Its range.** It ranges from 1.5 (in phase) to 0.5 (in antiphase), swinging at the difference frequency.
3. **Single sideband.** A 1 kHz message on a 100 kHz carrier, sent upper sideband, occupies only 101 kHz; double sideband would use 99 to 101 kHz.

**Answer:** the envelope swings between 0.5 and 1.5.
:::
:::

::: example
## An analytic signal's phase is 0.30 rad at one sample and 0.55 rad at the next, at 8 kHz. What is the instantaneous frequency?

::: solution
1. **Phase step.** The phase advanced 0.55 − 0.30 = 0.25 rad in one sample.
2. **Frequency.**
   $$\begin{aligned} f &= \frac{0.25}{2\pi} \times 8000\ \text{Hz} \\ &= 318\ \text{Hz} \end{aligned}$$
3. **Uses.** Tracking this sample by sample demodulates FM and measures chirps; it needs the analytic signal because the real signal alone doesn't define a phase.

**Answer:** 318 Hz.
:::
:::

::: check
given: n = 1 | 3 | 5 | 7
answer: 2/(pi*n)
tolerance: 0.5%

## What's tap h[{n}] of the ideal Hilbert transformer?

::: right
Right. For odd n, $2/(\pi n)$ = {answer}.
:::

::: misses
- [1/(pi*n)] The odd taps are $2/(\pi n)$.
- [any] Not yet. $h[n] = 2\sin^2(\pi n/2)/(\pi n)$.
:::
:::

::: check
given: w = 0.3 | 0.785 | 1.571 | 2.5
answer: 4/pi*(sin(w) + sin(3*w)/3)
tolerance: 0.5%

## A Hilbert transformer keeps only the taps at ±1 and ±3. What's its amplitude at ω = {w}?

::: right
Right. $\frac{4}{\pi}(\sin\omega + \frac{1}{3}\sin3\omega)$ = {answer}, against the ideal 1.
:::

::: misses
- [4/pi*sin(w)] Include the taps at ±3.
- [any] Not yet. Each antisymmetric pair ±n contributes $\frac{4}{\pi n}\sin n\omega$.
:::
:::

::: check
given: A = 1 | 2; B = 0.3 | 0.8; p = 50 | 90 | 120 | 180
answer: sqrt(A^2 + B^2 + 2*A*B*cos(p*pi/180))
tolerance: 0.5%

## Two tones of amplitudes {A} and {B} are {p}° apart in phase at some instant. What's the envelope there?

::: right
Right. $\sqrt{A^2 + B^2 + 2AB\cos\phi}$ = {answer}.
:::

::: misses
- [A + B] That's only when they're in phase.
- [any] Not yet. Add them as phasors and take the magnitude.
:::
:::

::: check
given: w = 0.4 | 1.1 | 2; n = 3 | 7
answer: sin(w*n)
tolerance: 0.5%

## cos({w}n) passes through an ideal Hilbert transformer. What's the output at n = {n}?

::: right
Right. The output is sin(ω₀n): {answer}.
:::

::: misses
- [-sin(w*n)] Positive frequencies are multiplied by −j, giving +sin.
- [cos(w*n)] The transformer shifts every component by 90°.
- [any] Not yet. −j on positive frequencies turns a cosine into a sine.
:::
:::

::: check
given: c = 100 | 455 | 10700; f = 1 | 3
answer: c + f
unit: kHz
tolerance: 0.001%

## A {f} kHz tone modulates a {c} kHz carrier by $x\cos\omega_cn - \hat{x}\sin\omega_cn$. At what frequency is the output?

::: right
Right. Upper sideband only: {answer} kHz.
:::

::: misses
- [c - f] That's the lower sideband, produced with a + sign.
- [any] Not yet. $\text{Re}\{x_ae^{j\omega_cn}\}$ shifts the analytic signal up.
:::
:::

::: check
given: m = 1.3 | 1.6 | 2; c = -1 | -0.95
answer: abs(1 + m*c)
tolerance: 0.5%

## An overmodulated AM signal $(1 + \given{m}\cos\Omega n)\cos\omega_cn$ is at a moment where cos Ωn = {c}. What envelope does the analytic signal report?

::: right
Right. $|1 + m\cos\Omega n|$ = {answer}.
:::

::: misses
- [1 + m*c] The analytic signal's magnitude can't be negative: overmodulation folds.
- [any] Not yet. The envelope is the magnitude of the analytic signal.
:::
:::

::: check
kind: parts
given: A = 1 | 2; B = 0.3 | 0.8; f = 1 | 1.05; g = 1.1 | 1.2

## Two tones of amplitudes {A} and {B} at {f} kHz and {g} kHz add.

::: part
answer: A + B
tolerance: 0.5%

### What is the envelope's maximum?

::: misses
- [any] The tones in phase.
:::
:::

::: part
answer: abs(A - B)
tolerance: 0.5%

### What is its minimum?

::: misses
- [any] The tones out of phase: |A − B|.
:::
:::

::: part
answer: (g - f)*1000
unit: Hz
tolerance: 0.5%

### How often does it repeat?

::: misses
- [(g - f)*500] The envelope repeats at the full difference frequency.
- [any] The difference frequency.
:::
:::
:::

::: check
kind: derivation
vars: A = 0.1..10, B = 0.1..10, p = 0..6.28

## Two tones of amplitudes A and B differ in phase by p at some instant.

::: step
answer: sqrt(A^2 + B^2 + 2*A*B*cos(p))

### What is the envelope?
:::

::: step
answer: A + B

### What is its largest possible value?
:::

::: step
answer: abs(A - B)

### And its smallest?
:::

::: right
Right. The analytic signal's magnitude is this envelope exactly, at every sample.
:::
:::

::: explain
## Why does combining a signal with its Hilbert transform remove the negative frequencies?

::: model
A real signal's spectrum has matching components at +ω and −ω, which is what keeps the signal real. The Hilbert transformer multiplies the positive-frequency components by −j and the negative ones by +j. Forming $x + j\hat{x}$ multiplies the Hilbert output by another j, so the positive-frequency parts become $X + j(-j)X = 2X$ while the negative-frequency parts become $X + j(j)X = 0$. The negative half of the spectrum cancels exactly, leaving a complex signal whose spectrum is one-sided. Its magnitude no longer contains the carrier's oscillation, because a single rotating phasor has a constant length, which is why it measures the envelope directly.
:::
:::

::: practice

::: check
given: n = 1 | 3 | 5 | 9 | 11 | 15
answer: 2/(pi*n)
tolerance: 0.5%

## Hilbert tap h[{n}]?

::: misses
- [any] $2/(\pi n)$.
:::
:::

::: check
given: A = 1 | 3; B = 0.5 | 1.5; p = 45 | 150
answer: sqrt(A^2 + B^2 + 2*A*B*cos(p*pi/180))
tolerance: 0.5%

## Envelope: amplitudes {A}, {B}, {p}° apart?

::: misses
- [any] $\sqrt{A^2 + B^2 + 2AB\cos\phi}$.
:::
:::

::: check
given: w = 0.3 | 0.5 | 0.8 | 1.2 | 1.6 | 2.2
answer: 4/pi*(sin(w) + sin(3*w)/3)
tolerance: 0.5%

## 4-tap Hilbert amplitude at ω = {w}?

::: misses
- [any] $\frac{4}{\pi}(\sin\omega + \frac{1}{3}\sin3\omega)$.
:::
:::
:::
