hilbert_exact: Hilbert transforms

View source: R/fft.R

hilbert_exactR Documentation

Hilbert transforms

Description

hilbert_exact treats the input as one period of an infinite periodic signal (circular convolution), while hilbert_approx pads the input on both sides to a good length for FFT, which is faster at the cost of possible slight artifacts at the edges (~linear convolution). If the input is <3 samples long, the envelope is calculated simply as Mod(x). Note: only hilbert_approx is fast enough to be used for extracting the envelopes of typical audio.

Usage

hilbert_exact(x)

hilbert_approx(x)

Arguments

x

numeric vector

Value

A list with two components:

hilbert

Hilbert transform

envelope

Instantaneous amplitude of the analytic signal (envelope)

Examples

# signal: amplitude-modulated sine wave
t = seq(0, 1, length.out = 477)
carrier = cos(2 * pi * 50 * t)
modulator = 1 + 0.5 * cos(2 * pi * 5 * t)
s = modulator * carrier  # amplitude modulated signal
hil_exact = hilbert_exact(s)
hil_approx = hilbert_approx(s)
plot(s, type = 'l')
points(hil_exact$envelope, type = 'l', col = 'blue')
points(hil_approx$envelope, type = 'l', col = 'red')

soundgen documentation built on Sept. 20, 2026, 5:07 p.m.