Skip to content

File hbdecim_r2c_core.h

FileList > doppler > hbdecim > hbdecim_r2c_core.h

Go to the source code of this file

Real-to-complex halfband 2:1 decimator (Architecture D2). More...

  • #include "doppler/clib_common.h"
  • #include "doppler/dp_state.h"

Public Types

Type Name
typedef struct hbdecim_r2c_state hbdecim_r2c_state_t
Opaque real-to-complex halfband decimator state.

Public Functions

Type Name
size_t dp_hbdecim_r2c_consumed (const hbdecim_r2c_state_t * r)
Input samples the last dp_hbdecim_r2c_execute() took.
hbdecim_r2c_state_t * dp_hbdecim_r2c_create (size_t num_taps, const float * h)
Allocate a real-to-complex halfband decimator.
void dp_hbdecim_r2c_destroy (hbdecim_r2c_state_t * r)
Free the coefficients, both delay lines and the state.
size_t dp_hbdecim_r2c_execute (hbdecim_r2c_state_t * r, const float * in, size_t num_in, float _Complex * out, size_t max_out)
Decimate real float32 input by 2, producing CF32.
size_t dp_hbdecim_r2c_get_num_taps (const hbdecim_r2c_state_t * r)
FIR branch length N.
double dp_hbdecim_r2c_get_rate (const hbdecim_r2c_state_t * r)
Output-to-input sample-rate ratio (fixed by design).
void dp_hbdecim_r2c_get_state (const hbdecim_r2c_state_t * r, void * blob)
Serialize r's mutable state intoblob .
void dp_hbdecim_r2c_reset (hbdecim_r2c_state_t * r)
Zero history and output parity without freeing.
int dp_hbdecim_r2c_set_state (hbdecim_r2c_state_t * r, const void * blob)
Restore mutable state from blob (same num_taps).
size_t dp_hbdecim_r2c_state_bytes (const hbdecim_r2c_state_t * r)
Bytes dp_hbdecim_r2c_get_state() writes (envelope + payload).

Macros

Type Name
define HBDECIM_R2C_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('H', 'B', 'R', '2')
define HBDECIM_R2C_STATE_VERSION 1u

Detailed Description

Lifted from dp_hbdecim_r2cf32_t (c/src/hbdecim.c). Accepts real float32 input and produces CF32 IQ at half the input rate, with an embedded fs/4 frequency shift (same effect as mixing with e^{jπn/2} before decimating, at zero extra multiplications).

The output at sample m is: y(m) = (FIR(even) + j·delay(odd)) · (-1)^m

where the sign pattern (-1)^m provides the fs/4 shift correction. That form is for an even FIR branch length N; for odd N the roles swap (I comes from the delay branch, Q from the FIR on the odd stream). Both rails are then scaled by 2 so a real tone of amplitude A comes out as a complex tone of amplitude A (the analytic-signal convention), matching the unity DC gain of the complex sibling (dp_hbdecim_dc_gain()).

Lifecycle:

hbdecim_r2c_state_t *r = dp_hbdecim_r2c_create(num_taps, h);
size_t n = dp_hbdecim_r2c_execute(r, in, num_in, out, max_out);
dp_hbdecim_r2c_destroy(r);

Public Types Documentation

typedef hbdecim_r2c_state_t

Opaque real-to-complex halfband decimator state.

typedef struct hbdecim_r2c_state hbdecim_r2c_state_t;

Allocate with dp_hbdecim_r2c_create(); free with dp_hbdecim_r2c_destroy(). Holds the scaled, sign-modulated FIR coefficients, two dual-write delay rings (even and odd input samples), a held trailing sample and the output parity.


Public Functions Documentation

function dp_hbdecim_r2c_consumed

Input samples the last dp_hbdecim_r2c_execute() took.

size_t dp_hbdecim_r2c_consumed (
    const hbdecim_r2c_state_t * r
) 

Equal to its num_in unless out filled first; then the caller resumes at in + consumed. 0 after create, reset and set_state.

Parameters:

  • r Must be non-NULL.

Returns:

Input samples taken by the last execute.


function dp_hbdecim_r2c_create

Allocate a real-to-complex halfband decimator.

hbdecim_r2c_state_t * dp_hbdecim_r2c_create (
    size_t num_taps,
    const float * h
) 

The coefficients are copied and stored as h[k] * (-1)^k * 0.5 (the fs/4 modulation baked into the taps). As in hbdecim_core.h, only the first num_taps/2 are read, so the branch must be symmetric.

Parameters:

  • num_taps FIR branch length N. Must be > 0.
  • h FIR coefficients, float32, length num_taps. Copied; the caller keeps ownership. Must be non-NULL.

Returns:

A new state owned by the caller (free with dp_hbdecim_r2c_destroy()), with zeroed history and parity 0; NULL if num_taps is 0, h is NULL, or allocation fails.


function dp_hbdecim_r2c_destroy

Free the coefficients, both delay lines and the state.

void dp_hbdecim_r2c_destroy (
    hbdecim_r2c_state_t * r
) 

Parameters:


function dp_hbdecim_r2c_execute

Decimate real float32 input by 2, producing CF32.

size_t dp_hbdecim_r2c_execute (
    hbdecim_r2c_state_t * r,
    const float * in,
    size_t num_in,
    float _Complex * out,
    size_t max_out
) 

One complex output per (even, odd) input pair, counting a sample held from the previous call as the first of the block. A sample left unpaired at the end is held for the next call, so contiguous blocks give the same output as one large block. Size out for the whole block, (num_in + 1) / 2 samples. A shorter out drops nothing: the call stops at the pair boundary after the last output it has room for, and dp_hbdecim_r2c_consumed() says how much input it took, so the caller offers in + consumed again and the outputs resume exactly as one whole call gives (doppler#2643). A trailing sample is held only when it is the last input; with max_out 0 the call writes nothing and takes at most that one sample.

Parameters:

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

Returns:

Number of output samples written: min((num_in + held) / 2, max_out), where held is 1 when a trailing sample was carried in from the previous call.


function dp_hbdecim_r2c_get_num_taps

FIR branch length N.

size_t dp_hbdecim_r2c_get_num_taps (
    const hbdecim_r2c_state_t * r
) 

Parameters:

  • r State. Must be non-NULL.

Returns:

The num_taps passed to dp_hbdecim_r2c_create().


function dp_hbdecim_r2c_get_rate

Output-to-input sample-rate ratio (fixed by design).

double dp_hbdecim_r2c_get_rate (
    const hbdecim_r2c_state_t * r
) 

Parameters:

  • r State; ignored.

Returns:

Always 0.5.


function dp_hbdecim_r2c_get_state

Serialize r's mutable state intoblob .

void dp_hbdecim_r2c_get_state (
    const hbdecim_r2c_state_t * r,
    void * blob
) 

Parameters:

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

function dp_hbdecim_r2c_reset

Zero history and output parity without freeing.

void dp_hbdecim_r2c_reset (
    hbdecim_r2c_state_t * r
) 

Clears both delay lines and their heads, drops any held trailing sample and sets the (-1)^m output parity back to +1.

Parameters:

  • r State. Must be non-NULL.

function dp_hbdecim_r2c_set_state

Restore mutable state from blob (same num_taps).

int dp_hbdecim_r2c_set_state (
    hbdecim_r2c_state_t * r,
    const void * blob
) 

The envelope (magic, version, endianness, size) is validated, and the payload's ring heads and flags checked, before anything is written; on rejection r is unchanged.

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID if the blob's envelope or payload check refuses.


function dp_hbdecim_r2c_state_bytes

Bytes dp_hbdecim_r2c_get_state() writes (envelope + payload).

size_t dp_hbdecim_r2c_state_bytes (
    const hbdecim_r2c_state_t * r
) 

Parameters:

  • r State. Must be non-NULL.

Returns:

Blob size in bytes; depends on num_taps through the ring length, so a blob fits only a same-num_taps instance.


Macro Definition Documentation

define HBDECIM_R2C_STATE_MAGIC

#define HBDECIM_R2C_STATE_MAGIC `DP_FOURCC ('H', 'B', 'R', '2')`

Envelope magic ("HBR2") that tags an hbdecim_r2c state blob.


define HBDECIM_R2C_STATE_VERSION

#define HBDECIM_R2C_STATE_VERSION `1u`

Payload layout version of an hbdecim_r2c state blob.



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