# NCO HDL Optimized

Generate real or complex sinusoidal signals—optimized for HDL code generation

• Library:
• DSP System Toolbox HDL Support / Signal Operations

DSP System Toolbox HDL Support / Sources

## Description

The NCO HDL Optimized block generates real or complex sinusoidal signals, while providing hardware-friendly control signals. The block uses the same phase accumulation and lookup table algorithm as implemented in the NCO block. The block uses quantized integer accumulation to create a sinusoid signal.

The NCO HDL Optimized block provides these features:

• Optional frame-based output.

• A lookup table compression option to reduce the lookup table size. This compression results in less than one LSB loss in precision. See Lookup Table Compression for more information.

• An optional input port for external dither.

• An optional reset port that resets the phase accumulator to its initial value.

• An optional output port for the current NCO phase.

Given a sample time, Ts, and the desired output frequency resolution Δf, calculate the necessary accumulator size by using $Nacc=\mathrm{ceil}\left({\mathrm{log}}_{2}\left(\frac{1}{{T}_{s}\cdot \Delta f}\right)\right)$.

Assuming that your desired output frequency Fo is much lower than the Nyquist frequency, you can determine the acceptable quantization at the output of the accumulator by using an approximation for the noise per bit in dB and the desired spurious free dynamic range (SFDR). The quantized word length to achieve a specified SFDR is $Nq=\mathrm{ceil}\left(\frac{SFDR-12}{6}\right)$.

For a desired output frequency Fo, calculate the phase increment by using $phaseincrement=\mathrm{round}\left({F}_{0}{T}_{s}{2}^{Nacc}\right)$, where Nacc is the accumulator word length. You can specify the phase increment using a parameter or an input port.

Given a desired phase offset (in radians), calculate the phase offset input value by using $phaseoffset=\frac{{2}^{Nacc}\cdot desiredphaseoffset}{2\pi }$. You can specify the phase offset using a parameter or an input port.

## Ports

Note

• This block appears in the Sources libraries with Phase increment source parameter set to `Property`. The only input port is valid.

• This block appears in the Signal Operations libraries with Phase increment source parameter set to `Input port`. This configuration shows the optional input port inc.

This icon shows the optional ports of the NCO HDL Optimized block.

### Input

expand all

Phase increment, specified as a scalar integer.

`double` and `single` data types are supported for simulation but not for HDL code generation.

#### Dependencies

To enable this port, set the Phase increment source parameter to ```Input port```.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixdt([],N,0)`

Phase offset, specified as a scalar integer.

`double` and `single` data types are supported for simulation but not for HDL code generation.

#### Dependencies

To enable this port, set the Phase offset source parameter to ```Input port```.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixdt([],N,0)`

Dither, specified as an integer or a column vector of integers. The length of the vector must equal the Samples per frame parameter value.

`double` and `single` data types are supported for simulation but not for HDL code generation.

#### Dependencies

To enable this port, set the Dither source parameter to `Input port`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixdt([],N,0)`

Control signal that enables NCO operation, specified as a Boolean scalar. When this signal is `1`, the block increments the phase and captures any input values. When this signal is `0`, the block holds the phase accumulator and ignores any input values.

When the Samples per frame parameter is greater than `1`, this value enables processing of Samples per frame samples.

Data Types: `Boolean`

Control signal that resets the accumulator, specified as a Boolean scalar. When this signal is `1`, the block resets the accumulator to its initial value. This signal does not reset the output samples in the pipeline.

#### Dependencies

To enable this port, select the Enable accumulator reset input port parameter.

Data Types: `Boolean`

### Output

expand all

Generated waveform, returned as a scalar or as a column vector with length equal to the Samples per frame parameter value. The output can be a single port that returns sin or cos values, a single port that returns exp values representing `cosine + j*sine`, or two ports that return sin and cos values, respectively. When all input values are fixed-point type or all input ports are disabled, the block determines the output type using the Output data type parameter. When any input value is floating-point type, the block ignores the Output data type parameter. In this case, the block returns the waveform as floating-point values.

Floating-point data types are supported for simulation but not for HDL code generation.

#### Dependencies

By default, this output port is a sine wave, sin. The port label and format changes based on the Type of output signal parameter.

Current phase of NCO, returned as a scalar or as a column vector with length equal to the Samples per frame parameter value. The phase is the output of the quantized accumulator with offset and increment applied. If quantization is disabled, this port returns the output of the accumulator with offset and increment applied.

The values are of type `fixdt(1,N,0)`, where `N` is the Number of quantizer accumulator bits parameter value. If quantization is disabled, then `N` is the Accumulator Word length parameter value If any input value is floating-point type, the block returns the phase as a floating-point value.

Floating-point data types are supported for simulation but not for HDL code generation.

#### Dependencies

To enable this port, select the Enable phase port parameter.

Data Types: `single` | `double` | `fixdt(1,N,0)`

Control signal that indicates validity of output data, returned as a Boolean scalar. When output valid is `1`, the values on the sin, cos, exp, and phase ports are valid. When output valid is `0`, the values on the output ports are not valid.

When the Samples per frame parameter is greater than `1`, this signal indicates the validity of all elements in the output vector.

Data Types: `Boolean`

## Parameters

expand all

### Main

Note

This block supports `double` and `single` input for simulation but not for HDL code generation. When all input values are fixed-point type or all input ports are disabled, the block determines the output type using the Output data type parameter. When any input value is floating-point type, the block ignores the Output data type parameter. In this case, the block returns the waveform and optional phase as floating-point values.

To use the Fixed-Point Designer™ data type override feature, you can obtain a `double` output value by applying `double` input data to one of the optional ports.

You can set the phase increment with an input port or by entering a value for the parameter. If you select `Property`, the Phase increment parameter appears for you to enter a value. If you select `Input port`, the inc port appears on the block.

Phase increment for the generated the waveform, specified as an integer.

#### Dependencies

To enable this parameter, set the Phase increment source parameter to `Property`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `fixdt([],N,0)`

You can set the phase offset with an input port or by entering a value for the parameter. If you select `Property`, the Phase offset parameter appears for you to enter a value. If you select `Input port`, the offset port appears on the block.

Phase offset for the generated waveform, specified as an integer.

#### Dependencies

To enable this parameter, set the Phase offset source parameter to `Property`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `fixdt([],N,0)`

You can set the dither from an input port or from a parameter. If you select `Property`, the Number of dither bits parameter appears. If you select `Input port`, a port appears on the block. If you select `None`, the block does not add dither.

Number of dither bits, specified as a positive integer.

#### Dependencies

To enable this parameter, set the Dither source parameter to `Property`.

When you set this value to `1`, the block has scalar input and output. When this value is greater than `1`, the dither port expects a column vector of length Samples per frame and the sin, cos, exp, and phase ports return column vectors of length Samples per frame.

By default, the block implements a noncompressed lookup table, and the output of this block matches the output of the NCO block. When you enable this option, the block implements a compressed lookup table. The Sunderland compression method reduces the size of the lookup table, losing less than one LSB of precision. The spurious free dynamic range (SFDR) is empirically 1–3 dB lower than the noncompressed case. The hardware savings of the compressed lookup table allow room to improve performance by increasing the word length of the accumulator and the number of quantize bits. For detail of the compression method, see Algorithms.

Select this parameter to enable the reset accum port. When reset accum is `1`, the block resets the accumulator to its initial value.

If you select `Sine` or `Cosine`, the block shows the applicable port, sin or cos. If you select `Complex exponential`, the output is of the form `cosine + j*sine` and the port is labeled exp. If you select ```Sine and cosine```, the block shows two ports, sin and cos.

Select this parameter to return the current NCO phase on the phase port. The phase is the output of the quantized accumulator, with offset and increment applied. If quantization is disabled, this port returns the output of the accumulator, with offset and increment applied.

### Data Types

Rounding mode for fixed-point operations. Rounding Mode is a read-only parameter with value `Floor`.

Overflow mode for fixed-point operations. Overflow mode is a read-only parameter. Fixed-point numbers wrap around on overflow.

Accumulator data type description. This parameter is read-only, with value `Binary point scaling`. The block defines the fixed-point data type using the Accumulator Signed, Accumulator Word length, and Accumulator Fraction length parameters.

This parameter is read-only. All output is signed format.

Units are in bits. This value must include the sign bit.

If you clear the Quantize phase parameter, this parameter must be less than or equal to 17 bits for HDL code generation. This limitation is because, in the nonquantized case, the lookup table of sine values has 2AccumulatorWordLength-2 entries.

This parameter is read-only. The accumulator fraction length is zero bits.

The accumulator operates on integers. If the phase increment is `fixdt` type with a fractional part, the block returns an error.

When you select this parameter, the block quantizes the result of the phase accumulator to a fixed bit-width. This quantized value is used to select a waveform value from the lookup table. Select the resolution of the lookup table by using the Number of quantizer accumulator bits parameter.

The frequency resolution of an NCO is defined by $\Delta f=\frac{1}{{T}_{s}\cdot {2}^{N}}\text{Hz}$, where N is the Number of quantizer accumulator bits parameter value.

When you clear this parameter, the block uses the full accumulator data type as the address of the lookup table. In this case, N is the Accumulator Word length parameter value.

Number of quantizer accumulator bits, specified as an integer scalar greater than 4 and less than the accumulator word length. This parameter must be less than or equal to 17 bits for HDL code generation. The lookup table of sine values has 2NumQuantizerAccumBits-2 entries.

#### Dependencies

To enable this parameter, select the Quantize phase parameter.

Specify the data type for the sin, cos, and exp ports. This parameter is ignored if any input is of floating-point type. In that case, the output data type is floating-point.

If you select `Binary point scaling`, the block defines the fixed-point data type using the Output Signed, Output Word length, and Output Fraction length parameters.

This parameter is read-only. All output is signed format.

Units are in bits. This value must include the sign bit.

Units are in bits.

## Algorithms

expand all

The NCO implementation depends on whether you select Enable look up table compression method.

Without lookup table compression, the block uses the same quarter-sine lookup table as the NCO block. The size of the LUT is 2Number of quantizer accumulator bits-2×Output word length bits.

If you do not enable Quantize phase, then Number of quantizer accumulator bits=Accumulator Word length. Consider the impact on simulator memory and hardware resources when you select these parameters.

## Compatibility Considerations

expand all

Behavior changed in R2020a

Behavior changed in R2020a

Behavior changed in R2020a

## References

[1] Cordesses, L., "Direct Digital Synthesis: A Tool for Periodic Wave Generation (Part 1)." IEEE Signal Processing Magazine. Volume 21, Issue 4, July 2004, pp. 50–54.

## Extended Capabilities

### Objects

Introduced in R2013a

Watch now