Skip to content

Python NCO API

Numerically Controlled Oscillator — 32-bit phase accumulator with a 2^16-entry sine LUT (~96 dBc SFDR), backed by dp_nco_t.

Source: python/dsp/doppler/nco/_nco.pyi


Nco

Numerically Controlled Oscillator wrapping dp_nco_t.

Parameters:

Name Type Description Default
norm_freq float

Normalised frequency f/fs (cycles per sample). Typical range [−0.5, 0.5).

required

get_freq

get_freq() -> float

Return the current normalised frequency (f/fs).

Returns the value last passed to __init__ or :meth:set_freq.

get_phase

get_phase() -> int

Return the raw 32-bit phase accumulator value.

Normalised: get_phase() / 2**32 gives the fractional phase in [0, 1). Useful for polyphase branch selection: get_phase() >> (32 - log2(num_phases)).

get_phase_inc

get_phase_inc() -> int

Return the phase increment (fixed-point frequency).

This is the uint32 added to the accumulator each sample: phase_inc = round(norm_freq × 2**32).

Useful for polyphase branch selection::

branch = phase >> (32 - log2(num_phases))

where phase advances by get_phase_inc() each tick.

set_freq

set_freq(norm_freq: float) -> None

Update the normalised frequency without resetting the phase.

reset

reset() -> None

Reset the phase accumulator to zero.

execute_cf32

execute_cf32(n: int = 1) -> NDArray[np.complex64]

Generate n complex tone samples (float32 I/Q).

execute_cf32_ctrl

execute_cf32_ctrl(ctrl: NDArray[float32] | int) -> NDArray[np.complex64]

Generate complex tone samples with per-sample FM control.

Parameters:

Name Type Description Default
ctrl NDArray[float32] | int

1-D float32 array of per-sample normalised-frequency deviations, or an integer n to generate n samples with zero control (equivalent to :meth:execute_cf32).

required

Returns:

Type Description
NDArray[complex64]

Same length as ctrl (or n samples if int).

execute_u32

execute_u32(n: int = 1) -> NDArray[np.uint32]

Return n raw 32-bit phase accumulator values.

execute_u32_ctrl

execute_u32_ctrl(ctrl: NDArray[float32] | int) -> NDArray[np.uint32]

Raw phase accumulator values with per-sample FM control.

Pass an integer n for zero control (free-running).

execute_u32_ovf

execute_u32_ovf(n: int = 1) -> tuple[NDArray[np.uint32], NDArray[np.uint8]]

Phase accumulator values plus per-sample overflow flags.

Returns:

Name Type Description
phases NDArray[uint32]

1-D uint32 array of length n.

overflows NDArray[uint8]

1-D uint8 array; element is 1 when the accumulator wrapped (i.e. one input period elapsed), 0 otherwise.

execute_u32_ovf_ctrl

execute_u32_ovf_ctrl(ctrl: NDArray[float32] | int) -> tuple[NDArray[np.uint32], NDArray[np.uint8]]

Phase + overflow with per-sample FM control.

Pass an integer n for zero control (free-running).

destroy

destroy() -> None

Release the underlying C resource (also called on GC).