DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::Hilbert< T > Class Template Reference

90-degree phase-differencing network (analytic-signal generator). More...

#include <Hilbert.h>

Classes

struct  Result
 

Public Member Functions

void prepare (double sampleRate) noexcept
 Prepares the transformer. The FIR kernel is sample-rate independent; sampleRate is accepted for API symmetry.
 
Result process (T input) noexcept
 Processes one sample, returning the analytic signal {real, imag}.
 
void processBlock (std::span< const T > input, std::span< T > outReal, std::span< T > outImag) noexcept
 Processes a block of samples. Optimized for CPU cache.
 
void reset () noexcept
 Resets the delay line. Mandatory when seeking or starting playback.
 

Static Public Member Functions

static constexpr int getLatencySamples () noexcept
 FIR group-delay latency applied to both outputs, in samples.
 

Detailed Description

template<FloatType T>
class dspark::Hilbert< T >

90-degree phase-differencing network (analytic-signal generator).

Implemented as a windowed-sinc FIR Hilbert transformer: the quadrature (imaginary) output is the input convolved with the ideal Hilbert kernel, windowed with a Blackman window; the in-phase (real) output is the input delayed by the FIR group delay (kCenter samples) so the two outputs stay sample-aligned and form a true analytic pair.

This FIR design is correct by construction. With the default 191-tap kernel at 48 kHz the measured analytic-signal magnitude ripple is < 0.1% above ~1 kHz and < 2.5% down to ~500 Hz (the kernel is rate-independent, so these corner frequencies scale with the sample rate). Like every Hilbert transformer it cannot produce exact quadrature at DC, and the odd-length antisymmetric (Type III) design also rolls off approaching Nyquist - both inherent, not defects (lengthen the kernel for more sub-500 Hz accuracy).

Note
Introduces a latency of getLatencySamples() = kCenter samples on BOTH outputs. The real branch is the delayed input, so callers that mix the "dry" path from real stay phase-aligned with the shifted/wet path.
Template Parameters
TSample type (float or double).

Definition at line 62 of file Hilbert.h.

Member Function Documentation

◆ getLatencySamples()

template<FloatType T>
static constexpr int dspark::Hilbert< T >::getLatencySamples ( )
inlinestaticconstexprnoexcept

FIR group-delay latency applied to both outputs, in samples.

Definition at line 152 of file Hilbert.h.

◆ prepare()

template<FloatType T>
void dspark::Hilbert< T >::prepare ( double  sampleRate)
inlinenoexcept

Prepares the transformer. The FIR kernel is sample-rate independent; sampleRate is accepted for API symmetry.

Parameters
sampleRateThe system sample rate. Must be > 0 (invalid values, including NaN, are ignored).

Definition at line 77 of file Hilbert.h.

◆ process()

template<FloatType T>
Result dspark::Hilbert< T >::process ( input)
inlinenoexcept

Processes one sample, returning the analytic signal {real, imag}.

Uses a mirrored (double-write) delay line so the convolution window is one contiguous span, dispatched to the SIMD dot product - an order of magnitude faster than a wrapped per-tap loop for 191 taps. (Half of the kernel taps are exact zeros - the ideal Hilbert kernel vanishes on even indices - but a contiguous dot product still beats a strided read that would skip them; same trade-off as the framework's half-band FIRs.)

Parameters
inputReal-valued input sample.

Definition at line 99 of file Hilbert.h.

◆ processBlock()

template<FloatType T>
void dspark::Hilbert< T >::processBlock ( std::span< const T >  input,
std::span< T >  outReal,
std::span< T >  outImag 
)
inlinenoexcept

Processes a block of samples. Optimized for CPU cache.

Precondition
Both output spans must be at least input.size() long. Violations assert in debug builds; release builds clamp to the shortest span.

Definition at line 126 of file Hilbert.h.

◆ reset()

template<FloatType T>
void dspark::Hilbert< T >::reset ( )
inlinenoexcept

Resets the delay line. Mandatory when seeking or starting playback.

Definition at line 145 of file Hilbert.h.


The documentation for this class was generated from the following file: