# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# dsp.HDLNCO System object

Package: dsp

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

## Description

The HDL NCO System object™ generates real or complex sinusoidal signals. In addition, the HDL NCO System object provides hardware-friendly control signals, optional reset signal, optional valid input signal, optional phase output signal, and an optional external dither input signal. It uses the same phase accumulation and lookup table technology as implemented in the NCO System object. You can use the lookup table compression option to significantly reduce the lookup table size with less than one LSB loss in precision. The System object does not support the property that allows the block to synthesize the LUT to a ROM on an FPGA.

 Note:   Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj) and y = obj() perform equivalent operations.

## Construction

HDLNCO = dsp.HDLNCO returns a numerically controlled oscillator (NCO) System object, HDLNCO, that generates a real or complex sinusoidal signal. The amplitude of the generated signal is always 1.

HDLNCO = dsp.HDLNCO(Name,Value) returns an HDL NCO System object, HDLNCO, with additional options specified by one or more Name,Value pair arguments. Name is a property name and Value is the corresponding value. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN. Properties not specified retain their default values.

HDLNCO = dsp.HDLNCO(Inc,'PhaseIncrementSource','Property') returns an HDL NCO System object, HDLNCO, with the PhaseIncrement property set to Inc. Inc is 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.

### Input Arguments

 Inc An integer scalar value for the PhaseIncrement property. To use this value, set the PhaseIncrementSource property to Property. Default: 100

## Properties

This object supports double for simulation but not for HDL code generation. When a data input is fixed point, or when no data input ports are enabled, the object computes the output waveform based on the fixed-point property settings. When a data input is floating-point, the object ignores NumDitherBits, PhaseQuantization, NumQuantizerAccumulatorBits, LUTCompress, and the fixed-point data type properties, and computes a double-precision output waveform.

 PhaseIncrementSource Select which phase increment the object uses. Set PhaseIncrementSource to Property to use the PhaseIncrement property. Set PhaseIncrementSource to Input port to use an input argument of the step method. The default is Input port. hnco = dsp.HDLNCO(...,'PhaseIncrementSource','Property','PhaseIncrement',phIncr, ...) PhaseIncrement Specify the phase increment as an integer scalar. This property is applicable when you set the PhaseIncrementSource property to Property. The default value of this property is 100. PhaseOffsetSource Select which phase offset the object uses. Set PhaseOffsetSource property to Property to use the PhaseOffset property. Set PhaseOffsetSource property to Input port to use an input argument of the step method. The default is Property. hnco = dsp.HDLNCO(...,'PhaseOffsetSource','Property','PhaseOffset',phOffset,...) PhaseOffset Specify the phase offset as an integer scalar. This property is applicable when you set the PhaseOffsetSource property to Property. The default value of PhaseOffset is 0. DitherSource Select which dither size the object uses. Set DitherSource property to Property to use the NumDitherBits property. Other options are Input port to use an input argument of the step method, or None to disable dithering. The default is Property. hnco = dsp.HDLNCO(...,'DitherSource','Property','NumDitherBits',ditherBits,...) NumDitherBits Specify the number of dither bits as a positive integer. This property is applicable when you set the DitherSource property to Property. The default value of NumDitherBits is 4. PhaseQuantization Set this property to true to enable quantization of the accumulated phase. The default value of PhaseQuantization is true. hnco = dsp.HDLNCO(...,'PhaseQuantization',true,'NumQuantizerAccumulatorBits',accumBits,...) NumQuantizerAccumulatorBits Specify the number of quantizer accumulator bits as an integer scalar greater than 1 and less than the accumulator word length. NumQuantizerAccumulatorBits determines the number of entries in the lookup table of sine values. This property is applicable when you set PhaseQuantization to true. The default value of this property is 12. LUTCompress Set this property to true to enable lookup table compression. The object uses the Sunderland compression method to reduce the size of the lookup table. The default value of this property is false. Waveform Choose whether the output of the object is Sine, Cosine, Complex exponential, or Sine and cosine signals. If you select Complex exponential, the output is of the form sine + j*cosine. If you select Sine and cosine, the step method returns an additional output. The default is Sine. PhasePort Set PhasePort to true to return the current phase along with the output from the step method. The default value of this property is false. ResetAction Set ResetAction to true to enable a reset argument to the step method. The default value of this property is false. ValidInputPort Set ValidInputPort to false to disable the ValidIn input argument to the step method. The default value is true. OverflowAction Overflow mode for fixed-point operations. OverflowAction is a constant property with value Wrap. RoundingMethod Rounding mode for fixed-point operations. RoundingMethod is a constant property with value Floor. AccumulatorDataType Accumulator data type description. This property is a constant with value Binary point scaling. AccumulatorSigned Select signed or unsigned accumulator data format. This property is a constant. All output is signed format. AccumulatorWL Accumulator word length. Default is 16 bits. AccumulatorFL Accumulator fraction length. This property is a constant with value 0 bits. OutputDataType Specify the output signal data type. Options are: double, single, and Binary point scaling. If this property is set to Binary point scaling, the output sign, word length, and fraction length are taken from the following three properties. The default is Binary point scaling. OutputSigned Select signed or unsigned output data. This property is a constant. All output is signed format. OutputWL Output data word length. The default is 16 bits. OutputFL Output data fraction length. The default is 14 bits.

## Methods

 step Process inputs using the HDL optimized NCO (Numerically Controlled Oscillator)
Common to All System Objects
clone

Create System object with same property values

getNumInputs

Expected number of inputs to a System object

getNumOutputs

Expected number of outputs of a System object

isLocked

Check locked states of a System object (logical)

release

Allow System object property value changes

## Examples

expand all

This example shows how to design an HDL-compatible NCO source.

F0 = 510;     % Output frequency = 510 Hz
df = 0.05;    % Frequency resolution = 0.05 Hz
minSFDR = 96; % Spurious free dynamic range >= 96 dB
Ts = 1/4000;  % Sample period = 1/4000 seconds
dphi = pi/2;  % Desired phase offset = pi/2;

Calculate the number of accumulator bits required for the frequency resolution, and the number of quantized accumulator bits to satisfy the SFDR requirement.

Nacc = ceil(log2(1/(df*Ts)));
actdf = 1/(Ts*2^Nacc); % Actual frequency resolution achieved
Nqacc = ceil((minSFDR-12)/6);

Calculate the phase increment and offset.

phIncr = round(F0*Ts*2^Nacc);
phOffset = 2^Nacc*dphi/(2*pi);

Construct a NCO HDL System object™. Set the properties to the values calculated. Call the object to generate data points in a sine wave. The input to the object is a valid signal.

Note: This object syntax runs only in R2016b or later. If you are using an earlier release, replace each call of an object with the equivalent step syntax. For example, replace myObject(x) with step(myObject,x).

hdlnco = dsp.HDLNCO('PhaseIncrementSource','Property', ...
'PhaseIncrement',phIncr,...
'PhaseOffset',phOffset,...
'NumDitherBits',4, ...
'NumQuantizerAccumulatorBits',Nqacc,...
'AccumulatorWL',Nacc)
for k = 1:1/Ts
y(k) = hdlnco(true);
end
hdlnco =

dsp.HDLNCO with properties:

PhaseIncrementSource: 'Property'
PhaseIncrement: 16712
PhaseOffsetSource: 'Property'
PhaseOffset: 32768
DitherSource: 'Property'
NumDitherBits: 4
PhaseQuantization: true
NumQuantizerAccumulatorBits: 14
LUTCompress: false
ResetAction: false
ValidInputPort: true
Waveform: 'Sine'
PhasePort: false

Use get to show all properties

Plot the mean-square spectrum of the 510 Hz sine wave generated by the NCO.

sa = dsp.SpectrumAnalyzer('SampleRate',1/Ts);
sa.SpectrumType = 'Power density';
sa.PlotAsTwoSidedSpectrum = false;
sa(y');

expand all