Compute Floating-Point Phase Increment for NCO HDL Optimized

This example shows how to use the NCO HDL Optimized block with floating-point input. A numerically controlled oscillator (NCO) is designed to work on quantized data types. To account for the lack of phase quantization when using floating-point inputs, you must adjust the floating-point phase increment.

When you use the NCO with quantized data types, the phase increment value depends on the size of the accumulator. For a fixed-point, N-bit accumulator to generate output samples with a desired output frequency of F0 and sample frequency of Fs, the phase increment must be:

Phase_increment = (F0*2^N)/Fs

If you use a phase offset, it also must be quantized by the size of the accumulator. For example, for an offset of pi/2:

Phase_offset = (pi/2)*2^N/(2*pi)

When an input to the block is floating point, the block ignores the parameters related to fixed-point settings: Number of dither bits, Quantize phase, Number of quantizer accumulator bits, Enable look up table compression method, and the Data Types tab.

When you use a floating-point phase-increment input, you must adjust the value of the increment to account for the lack of phase quantization. For a floating-point accumulator to generate output samples with a desired output frequency of F0 and sample frequency of Fs, the phase increment must be:

Phase_increment = 2*pi*F0/Fs

The phase offset for a floating-point NCO is straightforward. For example, for an offset of pi/2:

Phase_offset = pi/2

The example model shows two versions of the NCO HDL Optimized block. The Fixed-Point NCO uses quantized data types for the input phase increment and phase offset. The increment and offset values are calculated for a 22-bit accumulator. The output type is set to double, even though the block internally operates on fixed-point data types.

The Floating-Point NCO uses double data type for the input phase increment and phase offset. The double input signals force the block to use floating-point internal calculations. The increment and offset values are calculated to work with a double data type accumulator.

After simulation, the scope shows that the generated waveforms from the fixed-point block and the floating-point block both achieve the target output frequency and phase offset.

modelname = 'HDLNCO_FloatingPointPhaseIncr';
open_system(modelname)
sim(modelname)

The same input phase increment and phase offset calculations apply when using the dsp.HDLNCO System object™.

See Also

Blocks

System Objects