Skip to content

NCO — Raw Phase Accumulator

NCO exposes the bare uint32 phase accumulator — useful when you need the raw phase word rather than a sin/cos lookup. freq is a normalised frequency in cycles/sample.

Raw uint32 phase

from doppler.source import NCO

nco = NCO(0.25)
ph = nco.steps_u32(16)
print(ph)
[         0 1073741824 2147483648 3221225472          0 1073741824
 2147483648 3221225472          0 1073741824 2147483648 3221225472
          0 1073741824 2147483648 3221225472]

The accumulator wraps at 2³² (0.25 × 2³² = 2³⁰ = 1073741824 per step).

Overflow carry

steps_u32_ovf returns (phases, carry)carry[i] is 1 whenever the accumulator wrapped on that sample:

nco = NCO(0.25)
phases, carry = nco.steps_u32_ovf(16)
print(carry)
[0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1]

The carry fires at indices 3, 7, 11, 15 — once every full cycle.

Scaled output

Scale the phase into [0, nmax) with a fixed-point multiply (no division):

nco2 = NCO(0.25, nmax=1000)
scaled = nco2.steps_u32_scaled(16)
print(scaled)
[  0 250 500 750   0 250 500 750   0 250 500 750   0 250 500 750]