Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.HDLNCO System object

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.

Given a desired output frequency F0, calculate the phase_increment input value using

phase increment=(F02NFs)

where N is the accumulator word length and

Fs=1Ts=1sample time

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

The frequency resolution of an NCO is defined by

Δf=1Ts2NHz

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

phase offset=2Ndesired phase offset2π

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

To generate real or complex sinusoidal signals:

  1. Create the dsp.HDLNCO object and set its properties.

  2. 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).

Creation

Syntax

HDLNCO = dsp.HDLNCO
HDLNCO = dsp.HDLNCO(Name,Value)
HDLNCO = dsp.HDLNCO(Inc,'PhaseIncrementSource','Property')

Description

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.

example

HDLNCO = dsp.HDLNCO(Name,Value) returns an HDL NCO System object, HDLNCO, with properties set using one or more name-value pairs. Enclose each property name in single quotes.

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.

Properties

expand all

Note

This object supports floating point types 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.

When you switch to using a floating-point phase increment, you must adjust the value of the increment to account for the lack of phase quantization.

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Waveform Generation

Source of phase increment, specified as 'Input port', or 'Property'. You can set the phase increment from an input argument or from a property.

Phase increment for generating the waveform, specified as a scalar integer. double and single are allowed for simulation but not for HDL code generation.

Dependencies

This property applies when you set the PhaseIncrementSource property to 'Property'.

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

Source of phase offset, specified as 'Input port', or 'Property'. You can set the phase offset from an input argument or from a property.

Phase offset, specified as a scalar integer. double and single are allowed for simulation but not for HDL code generation.

Dependencies

This property applies when you set the PhaseOffsetSource property to 'Property'.

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

Source of number of dither bits, specified as 'Input port', 'Property', or 'None'. You can set the dither from an input port or from a parameter, or you can disable dither. When you select 'Property', configure the dither in NumDitherBits property.

Number of dither bits, specified as a positive integer.

Dependencies

This property applies when you set the DitherSource property to 'Property'.

Whether to quantize accumulated phase, specified as true or false. When this option is enabled, the NCO output is calculated by quantizing 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 using the NumQuantizerAccumulatorBits property.

The frequency resolution of an NCO is defined by

Δf=1Ts2NHz

When you disable this option,

Number of quantizer accumulator bits, specified as an integer scalar greater than 1 and less than the accumulator word length. The lookup table of sine values has 2NumQuantizerAccumulatorBits entries.

Dependencies

This property applies when you set PhaseQuantization to true.

Whether to enable lookup table compression, specified as true or false. By default, the object implements a compressed lookup table. The Sunderland compression method reduces the size of the lookup table with less than one LSB loss in precision. The spurious free dynamic range (SFDR) is empirically 1-3dB lower than the non-compressed case. With a compressed lookup table, you can increase the word length of the accumulator, and the number of quantize bits, to improve the performance. For detail of the compression method, see Algorithms.

When this option is disabled, the output matches the output of the dsp.NCO System object.

Type of output waveform. If you select 'Complex exponential', the output is of the form sine + j*cosine. If you select 'Sine and cosine', the object returns an additional output.

Whether to return current phase, specified as true or false. Set this property to true to return the current phase along with the output waveform.

Control Signals

Whether to enable reset argument, specified as true or false. Set this property to true to enable a reset argument to the object.

Whether to enable valid input signal, specified as true or false. Set this property to false to disable the ValidIn input argument to the object.

Data Types

Overflow mode for fixed-point operations. OverflowAction is a read-only property with value 'Wrap'.

Rounding mode for fixed-point operations. RoundingMethod is a read-only property with value 'Floor'.

Accumulator data type. This property is read-only, with value 'Binary point scaling'. The accumulator sign, word length, and fraction length are taken from the following three properties.

Signed or unsigned accumulator data format. This property is read-only. All output is signed format.

Accumulator word length, in bits, specified as a scalar integer.

Accumulator fraction length, in bits, specified as a scalar integer.

Output data type. If this property is set to 'Binary point scaling', the output sign, word length, and fraction length are taken from the following three properties.

Signed or unsigned output data format. This property is read-only. All output is signed format.

Output word length, in bits, specified as a scalar integer.

Output fraction length, in bits, specified as a scalar integer.

Usage

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.

Syntax

[Y,ValidOut] = HDLNCO(Inc,ValidIn)
[Y,ValidOut] = HDLNCO
[Y,ValidOut] = HDLNCO(Inc,Offset,Dither,ValidIn)
[Y,Phase,ValidOut] = HDLNCO(___)

Description

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.

[Y,ValidOut] = HDLNCO(Inc,ValidIn) returns a sinusoidal signal, Y, generated by the HDLNCO System object, with the specified phase increment, Inc. When ValidIn is true, Inc is added to the accumulator.

example

[Y,ValidOut] = HDLNCO returns a waveform, 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. You can mix and match the activation of these arguments. For example:

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

example

[Y,ValidOut] = HDLNCO(Inc,Offset,Dither,ValidIn) returns a waveform, 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

[Y,Phase,ValidOut] = HDLNCO(___) returns a waveform, Y, and output 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

Input Arguments

expand all

Phase increment, specified as a scalar integer. double and single are allowed for simulation but not for HDL code generation.

Dependencies

The object accepts this argument when you set the PhaseIncrementSource property to 'Input port'.

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

Enable signal, specified as a logical scalar. The object increments the phase when ValidIn input is high. When ValidIn is low, the phase is held.

Dependencies

The object accepts this argument when you set the ValidInputPort property to true.

Data Types: logical

Phase offset, specified as a scalar integer. T double and single are allowed for simulation but not for HDL code generation.

Dependencies

The object accepts this argument when you set the PhaseOffsetSource property to 'Input port'.

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

Dither, specified as a scalar integer. double and single are allowed for simulation but not for HDL code generation.

Dependencies

The object accepts this argument when you set the DitherSource property to 'Input port'.

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

Request reset of the accumulator, specified as a logical scalar value. The object resets the accumulator to zero when Reset is high.

Dependencies

The object accepts this argument when you set the ResetAction property to true.

Data Types: logical

Output Arguments

expand all

Waveform, returned as a scalar fixed-point or floating-point value, or as a [Sine,Cosine] pair of values.

Dependencies

The type of the output waveform depends on the Waveform property.

  • 'Sine' (default) — returns a generated sine wave

  • 'Cosine' — returns a generated cosine wave

  • 'Complex exponential' — returns a wave in the form sine + j*cosine

  • 'Sine and cosine' — returns a pair of values representing corresponding sine and cosine waves

Validity of the Y output, returned as a logical scalar. When ValidOut is high, the data output is valid. When ValidOut is low, the data output is not valid.

Data Types: logical

Current phase of the NCO, returned as a scalar of type fixdt(1,M,-Z), where M is the number of quantized accumulator bits, and Z is the accumulator word length. The object returns Phase as floating point if the input to the object is floating point. Floating point is allowed for simulation but not for HDL code generation.

Dependencies

The object returns this additional output when you set the PhasePort property to true.

Data Types: single | double | fixdt(1,NumQuantizerAccumulatorBits,-AccumulatorWL)

Object Functions

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)
stepRun System object algorithm
cloneCreate duplicate System object
getNumInputsNumber of inputs required to call the System object
getNumOutputsNumber of outputs from calling the System object
isLockedDetermine if System object is locked
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

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');

Algorithms

expand all

See Also

System Objects

Blocks

Introduced in R2013a

Was this topic helpful?