gonumgonum.org/v1/gonum/dsp/transform Index | Examples | Files

package transform

import "gonum.org/v1/gonum/dsp/transform"

Package transform provides important transforms on signals used in digital signal processing.

Index

Examples

Types

type Hilbert

type Hilbert struct {
	// contains filtered or unexported fields
}

Hilbert implements an approximate Hilbert transform that allows calculation of an approximate analytical signal of a real signal, and determine the real envelope of a signal.

func NewHilbert

func NewHilbert(n int) *Hilbert

NewHilbert returns a new Hilbert transformer for signals of size n. The transform is most efficient when n is a product of small primes. n must not be less than one.

func (*Hilbert) AnalyticSignal

func (h *Hilbert) AnalyticSignal(dst []complex128, signal []float64) []complex128

AnalyticSignal computes the analytical signal of a real signal, and stores the result in the dst slice, returning it.

If the dst slice is nil, a new slice will be created and returned. The dst slice must be the same length as the input signal, otherwise the method will panic.

Example

Code:

{
	// Samples is a set of real amplitudes that make up a signal.
	samples := []float64{1, 0, 2, 0, 4, 0, 2, 0}

	// Initialize a Hilbert transform and 'demodulate' to get the
	// analytic signal.
	// The result is the complex I/Q (In-Phase / Quadrature) demodulation
	// of the input signal.
	h := NewHilbert(len(samples))
	iqSamples := h.AnalyticSignal(nil, samples)

	// We can compute the instantaneous amplitude of the signal
	// (or 'envelope') using absolute value. Analyzing the envelope
	// is an easy way to measure changes in amplitude over time in a
	// signal.
	envelope := make([]float64, len(samples))
	for ind, iq := range iqSamples {
		envelope[ind] = cmplx.Abs(iq)
	}

	// We can also compute the instantaneous phase of each part of the
	// signal using the 4-quadrant arc-tangent. With multiple samples,
	// the instantaneous phase can be used to estimate instantaneous
	// frequency of a signal.
	phase := make([]float64, len(samples))
	for ind, iq := range iqSamples {
		phase[ind] = cmplx.Phase(iq)
	}

	for i, iq := range iqSamples {
		fmt.Printf("ind=%d -> I=%.4f, Q=%.4f, envelope=%.4f, phase=%.4f\n",
			i, real(iq), imag(iq), envelope[i], phase[i])
	}

	// Output:
	//
	// ind=0 -> I=1.0000, Q=0.0000, envelope=1.0000, phase=0.0000
	// ind=1 -> I=-0.0000, Q=-0.8107, envelope=0.8107, phase=-1.5708
	// ind=2 -> I=2.0000, Q=0.0000, envelope=2.0000, phase=0.0000
	// ind=3 -> I=-0.0000, Q=-1.3107, envelope=1.3107, phase=-1.5708
	// ind=4 -> I=4.0000, Q=0.0000, envelope=4.0000, phase=0.0000
	// ind=5 -> I=0.0000, Q=1.3107, envelope=1.3107, phase=1.5708
	// ind=6 -> I=2.0000, Q=0.0000, envelope=2.0000, phase=0.0000
	// ind=7 -> I=0.0000, Q=0.8107, envelope=0.8107, phase=1.5708
}

Output:

ind=0 -> I=1.0000, Q=0.0000, envelope=1.0000, phase=0.0000
ind=1 -> I=-0.0000, Q=-0.8107, envelope=0.8107, phase=-1.5708
ind=2 -> I=2.0000, Q=0.0000, envelope=2.0000, phase=0.0000
ind=3 -> I=-0.0000, Q=-1.3107, envelope=1.3107, phase=-1.5708
ind=4 -> I=4.0000, Q=0.0000, envelope=4.0000, phase=0.0000
ind=5 -> I=0.0000, Q=1.3107, envelope=1.3107, phase=1.5708
ind=6 -> I=2.0000, Q=0.0000, envelope=2.0000, phase=0.0000
ind=7 -> I=0.0000, Q=0.8107, envelope=0.8107, phase=1.5708

func (*Hilbert) Len

func (h *Hilbert) Len() int

Len returns the length of signals that are valid input for this Hilbert transform.

Source Files

doc.go hilbert.go

Version
v0.16.0 (latest)
Published
Mar 21, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
2 days ago

Tools for package owners.