Skip to content

File hbdecim_core.h

FileList > hbdecim > hbdecim_core.h

Go to the source code of this file

Halfband 2:1 decimator for CF32 IQ samples. More...

  • #include "clib_common.h"

Classes

Type Name
struct hbdecim_state_t

Public Functions

Type Name
hbdecim_state_t * hbdecim_create (size_t num_taps, const float * h)
Allocate and initialise a halfband 2:1 decimator.
void hbdecim_destroy (hbdecim_state_t * r)
size_t hbdecim_execute (hbdecim_state_t * r, const float _Complex * in, size_t num_in, float _Complex * out, size_t max_out)
Decimate a block of CF32 samples by 2.
size_t hbdecim_get_num_taps (const hbdecim_state_t * r)
double hbdecim_get_rate (const hbdecim_state_t * r)
void hbdecim_reset (hbdecim_state_t * r)

Detailed Description

Lifted from dp_hbdecim_cf32_t (c/src/hbdecim.c). Only the cf32 variant is ported; dp_hbdecim_r2cf32 (real-input D2) is a separate object and a separate session.

Algorithm: two dual-write circular delay lines hold even-indexed and odd-indexed input samples separately. Per output sample: * Push x[2m] → even delay line. * Push x[2m+1] → odd delay line. * Compute symmetric FIR (N/2 paired multiplies) + scaled delay tap.

Which delay line carries the FIR is determined by N: N even (fir_on_even=1): FIR on even_dl; delay from odd_dl[centre]. N odd (fir_on_even=0): FIR on odd_dl at offset +1; delay from even_dl[centre].

Coefficients are scaled by 0.5 inside hbdecim_create — this is the polyphase identity normalisation; do not remove it.

Lifecycle:

hbdecim_state_t *r = hbdecim_create(num_taps, h_fir);
size_t n = hbdecim_execute(r, in, num_in, out, max_out);
hbdecim_destroy(r);

Public Functions Documentation

function hbdecim_create

Allocate and initialise a halfband 2:1 decimator.

hbdecim_state_t * hbdecim_create (
    size_t num_taps,
    const float * h
) 

Parameters:

  • num_taps Length of the FIR branch (the row from kaiser_prototype(phases=2) that has more than one significant coefficient).
  • h FIR coefficients, length num_taps (float32). Copied internally and scaled by 0.5.

Returns:

Non-NULL on success, NULL on invalid args or OOM.


function hbdecim_destroy

void hbdecim_destroy (
    hbdecim_state_t * r
) 

Free all resources. NULL is a no-op.


function hbdecim_execute

Decimate a block of CF32 samples by 2.

size_t hbdecim_execute (
    hbdecim_state_t * r,
    const float _Complex * in,
    size_t num_in,
    float _Complex * out,
    size_t max_out
) 

Processes input pairs (even, odd); one output per pair. If num_in is odd, the trailing even sample is buffered and consumed on the next call.

Output-buffer sizing: allocate at least (num_in + 1) / 2 samples.

Parameters:

  • r Must be non-NULL.
  • in Input CF32 samples.
  • num_in Number of input samples.
  • out Output buffer.
  • max_out Capacity of out in samples.

Returns:

Number of output samples written.


function hbdecim_get_num_taps

size_t hbdecim_get_num_taps (
    const hbdecim_state_t * r
) 

Returns the FIR branch length passed to hbdecim_create.


function hbdecim_get_rate

double hbdecim_get_rate (
    const hbdecim_state_t * r
) 

Always returns 0.5 (rate is fixed by design).


function hbdecim_reset

void hbdecim_reset (
    hbdecim_state_t * r
) 

Zero both delay lines and clear the pending-sample flag. num_taps and coefficients are preserved.



The documentation for this class was generated from the following file native/inc/hbdecim/hbdecim_core.h