Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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

The HDL NCO System object™ generates real or complex sinusoidal signals, while providing hardware-friendly control signals. The object uses the same phase accumulation and lookup table algorithm as implemented in the NCO System object. When you use integer or fixed-point input signals, or use the object as a source with no input signal, the object uses quantized integer accumulation to create a sinusoid signal.

The HDL NCO System object provides these features:

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 argument for external dither.

An optional reset argument that triggers a reset of the phase to its initial value during the sinusoid output generation.

An optional output argument for the current NCO phase.

The System object does not support the property that allows the NCO HDL Optimized block to synthesize the lookup table to a ROM when using HDL Coder™ with an FPGA target.

Given a desired output frequency *F*_{0}, calculate
the *phase increment* input value using

$$phaseincrement=(\frac{{F}_{0}\cdot {2}^{N}}{{F}_{s}})$$

where *N* is the accumulator word length and

$${F}_{s}=\frac{1}{{T}_{s}}=\frac{1}{sampletime}$$

You can specify the phase increment using a property or an input argument.

The frequency resolution of an NCO is defined by

$$\Delta f=\frac{1}{{T}_{s}\cdot {2}^{N}}\text{Hz}$$

Given a desired phase offset (in radians), calculate the *phase offset*
input value using

$$phaseoffset=\frac{{2}^{N}\cdot desiredphaseoffset}{2\pi}$$

You can specify the phase offset using a property or an input argument.

When you use floating-point input signals, the object does not quantize the accumulation. Therefore, you must choose increment and offset values to represent a fraction of 2π without quantization.

To generate real or complex sinusoidal signals:

Create the

`dsp.HDLNCO`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

`hdlnco = dsp.HDLNCO`

`hdlnco = dsp.HDLNCO(Name,Value)`

`hdlnco = dsp.HDLNCO(Inc,'PhaseIncrementSource','Property') `

creates a numerically
controlled oscillator (NCO) System
object, `hdlnco`

= dsp.HDLNCO`hdlnco`

, that generates a real or complex sinusoidal
signal. The amplitude of the generated signal is always 1.

sets properties using one or more name-value pairs. Enclose each property name in single
quotes. For example,
`hdlnco`

= dsp.HDLNCO(`Name,Value`

)

hdlnco = dsp.HDLNCO('NumQuantizerAccumulatorBits',14, ... 'AccumulatorWL',17);

creates
an NCO with the `hdlnco`

= dsp.HDLNCO(`Inc`

,'PhaseIncrementSource','Property') `PhaseIncrement`

property set to
`Inc`

, an integer scalar. To use the PhaseIncrement
property, set the PhaseIncrementSource property to `'Property'`

. You can add
other `Name,Value`

pairs before or after
`PhaseIncrementSource`

.

**For versions earlier than R2016b, use the step
function to run the System object algorithm. The arguments to
step are the object you created, followed by
the arguments shown in this section.**

**For example, y = step(obj,x) and y = obj(x) perform equivalent operations.**

```
[Y,ValidOut]
= hdlnco(Inc,ValidIn)
```

```
[Y,ValidOut]
= hdlnco
```

```
[Y,ValidOut]
= hdlnco(Inc,Offset,Dither,ValidIn)
```

`[Y,Phase,ValidOut] = hdlnco(___)`

The object returns the waveform value, `Y`

, as a sine value, a cosine
value, a complex exponential value, or a [`Sine,Cosine`

] pair of values,
depending on the Waveform property.

`[`

returns a waveform, `Y`

,`ValidOut`

]
= hdlnco`Y`

, using waveform parameters from properties
rather than input arguments.

To use this syntax, set the PhaseIncrementSource, PhaseOffsetSource, and DitherSource
properties to `'Property'`

and ValidInputPort
to `false`

. These properties are independent of each other. For example:

hdlnco = dsp.HDLNCO('PhaseIncrementSource','Property', ... 'PhaseIncrement',phIncr,... 'PhaseOffset',phOffset,... 'ValidInputPort',false,... 'NumDitherBits',4)

`[`

returns a waveform, `Y`

,`ValidOut`

]
= hdlnco(`Inc`

,`Offset`

,`Dither`

,`ValidIn`

)`Y`

, with phase increment,
`Inc`

, phase offset, `Offset`

, and dither,
`Dither`

.

This syntax applies when you set the PhaseIncrementSource, PhaseOffsetSource, and DitherSource
properties to `'Input port'`

. These properties are independent of each
other. You can mix and match the activation of these arguments.
`PhaseIncrementSource`

is `'Input port'`

by default.
For example:

hdlnco = dsp.HDLNCO('PhaseOffsetSource','Input port',... 'DitherSource','Input port') for k = 1:1/Ts y(k) = hdlnco(phIncr,phOffset,ditherBits,true); end

`[`

returns a waveform, `Y`

,`Phase`

,`ValidOut`

] = hdlnco(___)`Y`

, and current phase, `Phase`

.

To use this syntax, set the PhasePort
property to `true`

. This syntax can include any of the arguments from
other syntaxes. For example:

hdlnco = dsp.HDLNCO('PhaseOffsetSource','Input port',... 'DitherSource','Input port',... 'PhasePort',true) for k = 1:1/Ts [phase(k),y(k)] = hdlnco(phIncr,phOffset,ditherBits,true); end

To use an object function, specify the
System
object as the first input argument. For
example, to release system resources of a System
object named `obj`

, use
this syntax:

release(obj)

[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.