Main Content

NCO

Generate real or complex sinusoidal signals

  • Two versions of NCO blocks

Libraries:
DSP System Toolbox / Signal Operations
DSP System Toolbox / Sources

Description

The NCO block generates a multichannel real or complex sinusoidal signal, with independent frequency and phase in each output channel. The amplitude of the created signal is always 1. The NCO block supports real inputs only. All outputs are real except for the output signal in Complex exponential mode. For more information on how the block computes the output, see Algorithms.

To produce a multichannel output, specify a vector quantity for the Phase increment and Phase offset parameters. Both parameters must have the same length, which defines the number of output channels. Each element of each vector is applied to a different output channel.

Examples

Ports

Input

expand all

Phase increment signal, specified as a real-valued scalar or vector. The input must have an integer data type, or a fixed-point data type with zero fraction length. The dimensions of the phase increment signal depend on how you choose to specify the Phase offset parameter:

  • When you specify the Phase offset on the block dialog box, the Phase increment must be a scalar or a vector with the same length as the Phase offset value. The block applies each element of the vector to a different channel, and therefore the vector length defines the number of output channels.

  • When you specify the Phase offset via the an input port, the offset port treats each column of the input as an independent channel. The Phase increment length must equal the number of columns in the input to the offset port.

Dependencies

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

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Phase offset signal, specified as a real-valued scalar, vector, or a full matrix. The input must have an integer data type, or a fixed-point data type with zero fraction length. The block treats each column of the input to the offset port as an independent channel. The number of channels in the phase offset must match the number of channels in the data input. For each frame of the input, the block can apply different phase offsets to each sample and channel.

Dependencies

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

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Sinusoidal output signal specified as a scalar, vector, or matrix. You can specify the data type of the signal using the Output data type parameter.

Dependencies

To enable this port, set Output signal to Sine or Sine and cosine.

Data Types: single | double | fixed point

Cosinusoidal output signal specified as a scalar, vector, or matrix. You can specify the data type of the signal using the Output Data Type parameter.

Dependencies

To enable this port, set Output signal to Cosine or Sine and cosine.

Data Types: single | double | fixed point

Complex exponential output, specified as a scalar, vector, or matrix. You can specify the data type of the signal using the Output Data Type parameter.

Dependencies

To enable this port, set Output signal to Complex exponential.

Data Types: single | double | fixed point
Complex Number Support: Yes

Phase quantization error specified as a scalar, vector, or matrix.

Dependencies

To enable this port, select the Show phase quantization error port check box.

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Main

Phase adder parameters

Choose how you specify the phase increment. The phase increment can come from an input port or from the dialog box parameter.

  • If you select Input port, the inc input port appears on the block icon.

  • If you select Specify via dialog, the Phase increment parameter appears.

Dependencies

When the block comes from the Signal Operations library, the default value of the Phase increment Source parameter is Input port.

When the block comes from the Sources library, the default value of the Phase increment Source parameter is Specify via dialog.

Specify the phase increment as an integer-valued scalar or vector. Only integer data types, including fixed-point data types with zero fraction length, are allowed. The dimensions of the phase increment depend on those of the phase offset:

  • When you specify the phase offset on the block dialog box, the phase increment must be a scalar or a vector with the same length as the phase offset. The block applies each element of the vector to a different channel, and therefore the vector length defines the number of output channels.

  • When you specify the phase offset via an input port, the offset port treats each column of the input as an independent channel. The phase increment length must equal the number of columns in the input to the offset port.

Dependencies

To enable this parameter, set Phase increment source to Specify via dialog.

Choose how you specify the phase offset. The phase offset can come from an input port or from the dialog box.

  • If you select Input port, the offset port appears on the block icon.

  • If you select Specify via dialog, the Phase offset parameter appears.

Specify the phase offset as an integer-valued scalar or vector. Only integer data types, including fixed-point data types with zero fraction length, are allowed. When you specify the phase offset using this dialog box parameter, it must be a scalar or vector with the same length as the phase increment. Scalars are expanded to a vector with the same length as the phase increment. Each element of the phase offset vector is applied to a different channel of the input, and therefore the vector length defines the number of output channels.

Dependencies

To enable this parameter, set Phase offset source to Specify via dialog.

Select to add internal dithering to the NCO algorithm. Dithering is added using the PN Sequence Generator (Communications Toolbox) from the Communications Toolbox™ product.

Specify the number of dither bits as a positive integer.

Dependencies

To enable this port, select the Add internal dither check box.

To enable quantization of the accumulated phase, select this check box.

Specify the number of quantized accumulator bits as a scalar integer greater than one, and less than the accumulator word length. This value determines the number of entries in the lookup table.

Dependencies

To enable this port, select the Quantize phase check box.

Select to output the phase quantization error. When you select this check box, the Qerr port appears on the block icon.

Dependencies

To enable this parameter, select the Quantize phase check box.

Output Parameters

Choose whether the block outputs a Sine, Cosine, Complex exponential, or both Sine and cosine signals. If you select Sine and cosine, the two signals output on different ports.

When the block is acting as a source, specify the sample time in seconds as a positive scalar.

Dependencies

To enable this parameter, both Phase increment source and Phase offset source must be set to Specify via dialog. When either the phase increment or phase offset come in via a block input port, the sample time is inherited and this parameter is not visible.

Specify the number of samples per frame as a positive integer. When the value is greater than one, the phase increment and phase offset can vary from channel to channel and from frame to frame, but they are constant along each channel in a given frame.

When the phase offset input port exists, it has the same frame status as any output port present. When the phase increment input port exists, it does not support frames.

Dependencies

To enable this parameter set Phase increment source and/or Phase offset source to Specify via dialog.

Data Types

This parameter is read-only.

When the input is fixed point, the NCO block always uses the rounding mode Floor.

This parameter is read-only.

When the input is fixed point, the NCO block always uses the overflow mode Wrap.

Specify a Word length for the Accumulator as a positive integer from 2 to 128. The Data Type is always Binary point scaling, and the Fraction length is always 0.

Specify a Data Type for the block Output.

  • Choose double or single for a floating-point implementation.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.

Note

The lookup table for this block is constructed from double-precision floating-point values. Thus, the maximum amount of precision you can achieve in your output is 53 bits. Setting the word length of the Output data type to values greater than 53 bits does not improve the precision of your output.

Specify a Word length for the block Output as a positive integer from 2 to 128.

Dependencies

To enable this parameter, set the Data Type for the Output to Binary point scaling.

Specify a Fraction length for the block Output as a scalar integer.

Dependencies

To enable this parameter, set the Data Type for the Output to Binary point scaling.

NCO Characterization

The NCO Characterization pane provides you with read-only details on the NCO signal currently being implemented by the block:

The lookup table is implemented as a quarter-wave sine table. The number of lookup table data points is defined by

2number of quantized accumulator bits2+1

Example: 1025

The quarter wave sine lookup table size is defined by

(number of data points for lookup table)(output word length)8 bytes

Example: 2050 bytes

The spurious free dynamic range (SFDR) is calculated as follows for a lookup table with 2P entries:

SFDR=(6P) dB           without ditherSFDR=(6P+12) dB    with dither

Example: 84 dBc

The frequency resolution is the smallest possible incremental change in frequency and is defined by:

Δf=1Ts2NHz

Example: 15.2588 uHz

Dependencies

The frequency resolution only appears when you set Phase increment source and Phase offset source to Specify via dialog.

Block Characteristics

Data Types

fixed point | integer

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

More About

expand all

Algorithms

The block implements the algorithm as shown in the following diagram:

The implementation of a numerically controlled oscillator (NCO) has two distinct parts. First, a phase accumulator accumulates the phase increment and adds in the phase offset. In this stage, an optional internal dither signal can also be added. The NCO output is then calculated by quantizing the results of the phase accumulator section and using them to select values from a lookup table. Since the lookup table contains a finite set of entries, in its normal mode of operation, the NCO block allows the adder’s numeric values to overflow and wrap around. The Fixed-Point infrastructure then causes overflow warnings to appear on the command line. This overflow is of no consequence.

Given a desired output frequency F0, calculate the value of the Phase increment block parameter with

phase increment=(F02NFs)

where N is the accumulator word length and

Fs=1Ts=1sample time

The frequency resolution of an NCO is defined by

Δf=1Ts2NHz

Given a desired phase offset (in radians), calculate the Phase offset block parameter with

phase offset=2Ndesired phase offset2π

The spurious free dynamic range (SFDR) is estimated as follows for a lookup table with 2P entries, where P is the number of quantized accumulator bits:

SFDR=(6P) dB           without ditherSFDR=(6P+12) dB    with dither

The NCO block uses a quarter-wave lookup table technique that stores table values from 0 to π/2. The block calculates other values on demand using the accumulator data type, then casts them into the output data type. This can lead to quantization effects at the range limits of a given data type. For example, consider a case where you would expect the value of the sine wave to be –1 at π. Because the lookup table value at that point must be calculated, the block might not yield exactly –1, depending on the precision of the accumulator and output data types.

Extended Capabilities

Version History

Introduced before R2006a

See Also

Blocks

Objects