NCO / DDS frequency calculator

Frequency tuning word (FTW) of a numerically controlled oscillator (NCO) or direct digital synthesizer (DDS): the value loaded into the phase accumulator for a wanted output frequency, the frequency you actually get and the worst-case spur from phase truncation.

Oscillator
Output

Frequency resolution
-
Tuning word (decimal)
-
Tuning word (hex)
-
Actual output frequency
-
Frequency error
-
Phase truncation spur
-

Formulas

Δf = fclk / 2N

FTW = round(fout · 2N / fclk), factual = FTW · fclk / 2N

The accumulator adds FTW every clock cycle and wraps at 2N, so the output frequency is always a whole multiple of Δf and the error is at most Δf / 2. Outputs above fclk / 2 alias back into the first Nyquist zone.

Keeping only the top P bits of the phase for the sine lookup adds spurs. Their worst-case level is about −6.02 · P dBc, a rule of thumb from the DDS literature; the real level depends on the tuning word and drops when the phase is dithered.

Need this in RTL, in a MATLAB model or on real hardware? Discuss your project.