Skip to content

File HalfbandDecimator_core.h

FileList > doppler > HalfbandDecimator > HalfbandDecimator_core.h

Go to the source code of this file

Halfband 2:1 decimator for CF32 IQ (adapter over hbdecim_core). More...

  • #include "doppler/hbdecim/hbdecim_core.h"

Public Types

Type Name
typedef hbdecim_state_t dp_HalfbandDecimator_state_t

Public Functions

Type Name
dp_HalfbandDecimator_state_t * dp_HalfbandDecimator_create (const float * h, size_t h_len)
Create a HalfbandDecimator with caller-supplied FIR taps. Implements a 2:1 polyphase halfband decimator over CF32 IQ. The caller provides the FIR branch coefficient array h; use doppler.resample.kaiser_num_taps(2, atten, pb, sb) to size it and scipy or the built-in bank helper to design the prototype. Output length is approximately x_len / 2 per execute() call.
void dp_HalfbandDecimator_destroy (dp_HalfbandDecimator_state_t * state)
Free the coefficients, delay lines and the state.
size_t dp_HalfbandDecimator_execute (dp_HalfbandDecimator_state_t * state, const float _Complex * x, size_t x_len, float _Complex * out, size_t max_out)
Decimate x by 2 using the polyphase halfband FIR filter. Each (even, odd) input pair yields one output: one phase runs through the symmetric FIR branch and the other through a pure delay weighted 0.5. State persists between calls: a sample left unpaired at the end of a block (counting one held from the previous call) is held for the next, so contiguous blocks give identical output to one large block.
size_t dp_HalfbandDecimator_execute_max_out (dp_HalfbandDecimator_state_t * state, size_t x_len)
The most outputs one dp_HalfbandDecimator_execute() call overx_len inputs can write:(x_len + 1) / 2 .
size_t dp_HalfbandDecimator_get_num_taps (const dp_HalfbandDecimator_state_t * state)
Number of FIR branch taps as passed to create. The pure-delay branch has no taps; only the FIR branch has length num_taps (it runs on the even-indexed inputs when num_taps is even, the odd-indexed ones when it is odd). The total prototype length is 2 * num_taps - 1.
double dp_HalfbandDecimator_get_rate (const dp_HalfbandDecimator_state_t * state)
Fixed decimation rate — always 0.5. The halfband decimator is structurally 2:1; this property exists for API parity with Resampler and RateConverter.
void dp_HalfbandDecimator_get_state (const dp_HalfbandDecimator_state_t * state, void * blob)
Serialize the decimator's delay-line state into blob .
void dp_HalfbandDecimator_reset (dp_HalfbandDecimator_state_t * state)
Zero all delay lines. Coefficients and num_taps preserved. Call between signal bursts to suppress transient ringing from prior filter state. The next execute() after reset produces the same output as a freshly created decimator fed the same input. Any sample held for the next call is dropped too.
int dp_HalfbandDecimator_set_state (dp_HalfbandDecimator_state_t * state, const void * blob)
Restore state from blob ; DP_OK, or DP_ERR_INVALID if rejected.
size_t dp_HalfbandDecimator_state_bytes (const dp_HalfbandDecimator_state_t * state)
Serialized-state byte size (forwarded to the hbdecim leaf).

Detailed Description

Thin adapter over hbdecim_state_t. The caller supplies a FIR coefficient array at construction; use resample.build_bank(2, ...) from Python to generate a suitable halfband prototype.

Lifecycle:

float h[] = { ... };  // num_taps FIR branch coefficients
dp_HalfbandDecimator_state_t *r =
    dp_HalfbandDecimator_create(h, num_taps);
float _Complex out[512];
size_t n = dp_HalfbandDecimator_execute(r, in, 1024, out, 1024);
dp_HalfbandDecimator_destroy(r);

Public Types Documentation

typedef dp_HalfbandDecimator_state_t

typedef hbdecim_state_t dp_HalfbandDecimator_state_t;

HalfbandDecimator state: an alias of hbdecim_state_t, so every function here forwards to the dp_hbdecim_* leaf unchanged.


Public Functions Documentation

function dp_HalfbandDecimator_create

Create a HalfbandDecimator with caller-supplied FIR taps. Implements a 2:1 polyphase halfband decimator over CF32 IQ. The caller provides the FIR branch coefficient array h; use doppler.resample.kaiser_num_taps(2, atten, pb, sb) to size it and scipy or the built-in bank helper to design the prototype. Output length is approximately x_len / 2 per execute() call.

dp_HalfbandDecimator_state_t * dp_HalfbandDecimator_create (
    const float * h,
    size_t h_len
) 

Parameters:

  • h Float32 FIR branch coefficients (the branch of the halfband prototype with more than one nonzero tap, not the whole prototype). Must be symmetric, h[k] == h[h_len-1-k]: only the first h_len/2 are read, and for odd h_len the centre tap is ignored in favor of the fixed 0.5 delay branch. Copied and scaled by 0.5; must be non-NULL.
  • h_len Number of coefficients in h (the FIR branch length reported by num_taps). Must be > 0.

Returns:

A new state owned by the caller (free with dp_HalfbandDecimator_destroy()); NULL if h is NULL, h_len is 0, or allocation fails.

>>> from doppler.resample import HalfbandDecimator
>>> import numpy as np
>>> h = np.array([0.0625, 0.25, 0.375, 0.25, 0.0625],
...              dtype=np.float32)
>>> hb = HalfbandDecimator(h=h)
>>> hb.num_taps, hb.rate
(5, 0.5)

function dp_HalfbandDecimator_destroy

Free the coefficients, delay lines and the state.

void dp_HalfbandDecimator_destroy (
    dp_HalfbandDecimator_state_t * state
) 

Parameters:


function dp_HalfbandDecimator_execute

Decimate x by 2 using the polyphase halfband FIR filter. Each (even, odd) input pair yields one output: one phase runs through the symmetric FIR branch and the other through a pure delay weighted 0.5. State persists between calls: a sample left unpaired at the end of a block (counting one held from the previous call) is held for the next, so contiguous blocks give identical output to one large block.

size_t dp_HalfbandDecimator_execute (
    dp_HalfbandDecimator_state_t * state,
    const float _Complex * x,
    size_t x_len,
    float _Complex * out,
    size_t max_out
) 

Parameters:

  • state Pointer to a valid dp_HalfbandDecimator_state_t.
  • x CF32 input array. A sample left unpaired at the end is held for the next call.
  • x_len Number of input samples.
  • out Output buffer; must hold at least (x_len + 1) / 2 samples, which is dp_HalfbandDecimator_execute_max_out(). Python refuses a shorter out=. In C a shorter one drops nothing: the call stops at a pair boundary and dp_hbdecim_consumed() says how much input it took.
  • max_out Capacity of out in elements. Emission stops there, so the return value is the number actually written.

Returns:

Number of CF32 samples written to out: min((x_len + held) / 2, max_out), where held is 1 if a trailing sample was carried in from the previous call. 0 if x_len or max_out is 0.

>>> from doppler.resample import HalfbandDecimator
>>> import numpy as np
>>> h = np.array([0.0625, 0.25, 0.375, 0.25, 0.0625],
...              dtype=np.float32)
>>> hb = HalfbandDecimator(h=h)
>>> y = hb.execute(np.zeros(100, dtype=np.complex64))
>>> y.shape, y.dtype
((50,), dtype('complex64'))

function dp_HalfbandDecimator_execute_max_out

The most outputs one dp_HalfbandDecimator_execute() call overx_len inputs can write:(x_len + 1) / 2 .

size_t dp_HalfbandDecimator_execute_max_out (
    dp_HalfbandDecimator_state_t * state,
    size_t x_len
) 

A 2:1 decimator emits one output per input pair, and at most one sample is held over from the previous call, so (x_len + held) / 2 never exceeds this. It is a true per-call bound, which is what lets the binding accept an out= of len(x) // 2 + 1 and allocate no more than that when it sizes the output itself (doppler#2644; this used to return a fixed 32768, which the binding then demanded of every out=).

Parameters:

  • state State; ignored.
  • x_len Number of inputs the call will be given.

Returns:

(x_len + 1) / 2; 0 for an empty call.


function dp_HalfbandDecimator_get_num_taps

Number of FIR branch taps as passed to create. The pure-delay branch has no taps; only the FIR branch has length num_taps (it runs on the even-indexed inputs when num_taps is even, the odd-indexed ones when it is odd). The total prototype length is 2 * num_taps - 1.

size_t dp_HalfbandDecimator_get_num_taps (
    const dp_HalfbandDecimator_state_t * state
) 

Parameters:

  • state State. Must be non-NULL.

Returns:

The h_len passed to dp_HalfbandDecimator_create().

>>> from doppler.resample import HalfbandDecimator
>>> import numpy as np
>>> h = np.array([0.0625, 0.25, 0.375, 0.25, 0.0625],
...              dtype=np.float32)
>>> HalfbandDecimator(h=h).num_taps
5

function dp_HalfbandDecimator_get_rate

Fixed decimation rate — always 0.5. The halfband decimator is structurally 2:1; this property exists for API parity with Resampler and RateConverter.

double dp_HalfbandDecimator_get_rate (
    const dp_HalfbandDecimator_state_t * state
) 

Parameters:

  • state State; ignored.

Returns:

Always 0.5 (output rate / input rate).

>>> from doppler.resample import HalfbandDecimator
>>> import numpy as np
>>> h = np.array([0.0625, 0.25, 0.375, 0.25, 0.0625],
...              dtype=np.float32)
>>> HalfbandDecimator(h=h).rate
0.5

function dp_HalfbandDecimator_get_state

Serialize the decimator's delay-line state into blob .

void dp_HalfbandDecimator_get_state (
    const dp_HalfbandDecimator_state_t * state,
    void * blob
) 

The blob is the hbdecim leaf's (HBDECIM_STATE_MAGIC envelope): both delay rings, their heads and any held trailing sample.

Parameters:

  • state State. Must be non-NULL. Not modified.
  • blob Caller-owned buffer of at least dp_HalfbandDecimator_state_bytes(state) bytes.

function dp_HalfbandDecimator_reset

Zero all delay lines. Coefficients and num_taps preserved. Call between signal bursts to suppress transient ringing from prior filter state. The next execute() after reset produces the same output as a freshly created decimator fed the same input. Any sample held for the next call is dropped too.

void dp_HalfbandDecimator_reset (
    dp_HalfbandDecimator_state_t * state
) 

Parameters:

  • state State. Must be non-NULL.
>>> from doppler.resample import HalfbandDecimator
>>> import numpy as np
>>> h = np.array([0.0625, 0.25, 0.375, 0.25, 0.0625],
...              dtype=np.float32)
>>> hb = HalfbandDecimator(h=h)
>>> _ = hb.execute(np.ones(64, dtype=np.complex64))
>>> hb.reset()
>>> hb.num_taps
5

function dp_HalfbandDecimator_set_state

Restore state from blob ; DP_OK, or DP_ERR_INVALID if rejected.

int dp_HalfbandDecimator_set_state (
    dp_HalfbandDecimator_state_t * state,
    const void * blob
) 

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID if the envelope (magic, version, endianness, size) rejects.


function dp_HalfbandDecimator_state_bytes

Serialized-state byte size (forwarded to the hbdecim leaf).

size_t dp_HalfbandDecimator_state_bytes (
    const dp_HalfbandDecimator_state_t * state
) 

Parameters:

  • state State. Must be non-NULL.

Returns:

dp_hbdecim_state_bytes(state); depends on num_taps.



The documentation for this class was generated from the following file native/inc/doppler/HalfbandDecimator/HalfbandDecimator_core.h