Accelerating the pace of engineering and science

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

## Construction

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

HNCO = dsp.HDLNCO(Name,Value) returns an HDL NCO System object, HNCO, 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

HNCO = dsp.HDLNCO(Inc, 'PhaseIncrementSource','Property') returns an HDL NCO System object, HNCO, with the PhaseIncrement property set to Inc. Inc is an integer scalar. To use the PhaseIncrement property, you must also 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, you must set the PhaseIncrementSource property to Property. Default: 100

## Properties

 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 object's output 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. 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

 clone Create HDLNCO System object with same property values isLocked Locked status (logical) release Allow property value and input characteristics change step Process inputs using the HDL optimized NCO (Numerically Controlled Oscillator)

## Examples

expand all

### Design an NCO Source

Design an NCO source according to specifications.

Specifications:

```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/8000 sec
dphi = pi/2;  % Desired phase offset = pi/2;
```

Calculate number of accumulator bits required for the frequency resolution.

``` Nacc = ceil(log2(1/(df*Ts)));
actdf = 1/(Ts*2^Nacc); % Actual frequency resolution achieved
```

Calculate number of quantized accumulator bits required from the SFDR requirement.

```  Nqacc = ceil((minSFDR-12)/6);
```

Calculate the phase increment.

```phIncr = round(F0*Ts*2^Nacc);
```

Calculate the phase offset.

```phOffset = 2^Nacc*dphi/(2*pi);
```

Construct NCO HDL System object�.

```hnco = dsp.HDLNCO('PhaseIncrementSource', 'Property', ...
'PhaseIncrement', phIncr,...
'PhaseOffset', phOffset,...
'NumDitherBits', 4, ...
'NumQuantizerAccumulatorBits', Nqacc,...
'AccumulatorWL',Nacc)

for k= 1:1/Ts
y(k) = step(hnco,true);
end
```
```hnco =

System: dsp.HDLNCO

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

```

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

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

## Algorithms

### Lookup Table Algorithm

When you enable lookup table (LUT) compression, the HDL NCO System object applies the Sunderland compression method. Sunderland techniques use trigonometric identities to divide each phase of the quarter sine wave into three components and express it as:

$\mathrm{sin}\left(A+B+C\right)=\mathrm{sin}\left(A+B\right)\mathrm{cos}C+\mathrm{cos}A\mathrm{cos}B\mathrm{cos}C-\mathrm{sin}A\mathrm{sin}B\mathrm{sin}C$

If the phase has 12 bits, the components are defined as:

• A , the four most significant bits

$\left(0\le A\le \frac{\pi }{2}\right)$

• B, the following four bits

$\left(0\le B\le \frac{\pi }{2}×{2}^{-4}\right)$

• C, the four least significant bits

$\left(0\le C\le \frac{\pi }{2}×{2}^{-}{}^{8}\right)$

Because C is small enough that sin(C)≅1 and cos(C)≅0 , the equation is approximated by:

$\mathrm{sin}\left(A+B+C\right)\approx \mathrm{sin}\left(A+B\right)+\mathrm{cos}A\mathrm{sin}C$

The HDL NCO System object implements this equation with one LUT for sin(A+B) and one LUT for cos(A)sin(C). The second term is a fine correction factor and can be truncated to fewer bits without losing precision. With the default accumulator size of 16 bits, and the example phase width of 12 bits, the LUTs use only 28×16 plus 28×4 bits (5kb). A quarter sine lookup table would use 212×16 bits (65kb). This approximation is accurate within 1 LSB which gives an SNR of at least 60 dB on the output. See L. Cordesses, "Direct Digital Synthesis: A Tool for Periodic Wave Generation (Part 1)", IEEE Signal Processing Magazine, DSP Tips & Tricks column, pp. 50–54, Vol. 21, No. 4 July 2004.