Contents

NCO

Generate real or complex sinusoidal signals

Library

Signal Operations

dspsigops

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

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

The NCO block supports real inputs only. All outputs are real except for the output signal in Complex exponential mode.

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.

Fixed-Point Data Types

The following diagram shows the data types used within the NCO block.

  • You can set the accumulator and output data types in the block dialog as discussed in Dialog Box below.

      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.

  • The phase increment and phase offset inputs must be integers or fixed-point data types with zero fraction length.

  • You specify the number of quantized accumulator bits in the Number of quantized accumulator bits parameter.

  • The phase quantization error word length is equal to the accumulator word length minus the number of quantized accumulator bits, and the fraction length is zero.

Examples

The NCO block is used in the GSM Digital Down ConverterGSM Digital Down Converter product example. Open this example by typing dspddc at the MATLAB® command line.

You can also try the following example. Design an NCO source with the following specifications:

  • Desired output frequency F0=510 Hz

  • Frequency resolution Δf=0.05 Hz

  • Spurious free dynamic range SFDR90 dB

  • Sample period Ts=1/8000 s

  • Desired phase offset π/2

  1. Calculate the number of required accumulator bits from the equation for frequency resolution:

    Δf=1Ts2NHz0.05=1180002NHzN=18

    Note that N must be an integer value. The value of N is rounded up to the nearest integer; 18 accumulator bits are needed to accommodate the value of the frequency resolution.

  2. Using this best value of N, calculate the frequency resolution that will be achieved by the NCO block:

    Δf=1Ts2NHzΔf=118000218 HzΔf=0.0305

  3. Calculate the number of quantized accumulator bits from the equation for spurious free dynamic range and the fact that for a lookup table with 2P entries, P is the number of quantized accumulator bits:

    SFDR=(6P+12)dB96 dB=(6P+12) dBP=14

  4. Select the number of dither bits. In general, a good choice for the number of dither bits is the accumulator word length minus the number of quantized accumulator bits; in this case 4.

  5. Calculate the phase increment:

    phase increment=round(F02NFs)phase increment=round(5102188000)phase increment=16712

  6. Calculate the phase offset:

    phase offset=2accumulator word lengthdesired phase offset2πphase offset=218π22πphase offset=65536

  7. Type ex_nco_exampleex_nco_example at the MATLAB command line to open the following model:

    The NCO block in the model is populated with the specifications and quantities you just calculated. The output word length and fraction length depend on the constraints of your hardware; this example uses a word length of 16 and a fraction length of 14. You can verify that the specifications of this problem have been met by looking at the NCO Characterization pane of the NCO block.

  8. Experiment with the model to observe the effects on the output shown on the Spectrum Analyzer. For example, try turning dithering on and off, and try changing the number of dither bits.

Dialog Box

The Main pane of the NCO dialog appears as follows.

Phase increment source

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

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

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

Phase increment

Specify the phase increment. Only integer data types, including fixed-point data types with zero fraction length, are allowed. The dimensions of the phase increment are dictated by 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.

This parameter is visible only if you set the Phase increment source parameter to Specify via dialog.

Phase offset source

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

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

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

When you specify the phase offset via an input port, it can be a scalar, vector, or a full matrix. 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. Only integer data types, including fixed-point data types with zero fraction length, are allowed.

Phase offset

Specify the phase offset. When you specify the phase offset using this parameter rather than via an input port, 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. Only integer data types, including fixed-point data types with zero fraction length, are allowed.

This parameter is visible only if Specify via dialog is selected for the Phase offset source parameter.

Add internal dither

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

Number of dither bits

Specify the number of dither bits.

This parameter is visible only if Add internal dither is selected.

Quantize phase

Select to enable quantization of the accumulated phase.

Number of quantized accumulator bits

Specify the number of quantized accumulator bits. This determines the number of entries in the lookup table. The number of quantized accumulator bits must be less than the accumulator word length.

This parameter is visible only if Quantize phase is selected.

Show phase quantization error port

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

This parameter is visible only if Quantize phase is selected.

Output signal

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

Sample time

Specify the sample time in seconds when the block is acting as a source. When either the phase increment or phase offset come in via block input ports, the sample time is inherited and this parameter is not visible.

Samples per frame

Specify the number of samples per frame. When the value of this parameter is 1, the block outputs a sample-based signal. When the value is greater than 1, the block outputs a frame-based signal of the specified size. In frame-based mode, 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.

This parameter is only visible if either Phase increment source or Phase offset source is set to Specify via dialog.

The Data Types pane of the NCO dialog appears as follows.

Rounding mode

The rounding mode used for this block when inputs are fixed point is always Floor.

Overflow mode

The overflow mode used for this block when inputs are fixed point is always Wrap.

Accumulator

Specify the word length of the accumulator data type. The fraction length is always zero; this is an integer data type.

Output

Specify the output data type.

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

The NCO Characterization pane of the NCO dialog appears as follows.

The NCO Characterization pane does not have any parameters. Instead, it provides you with details on the NCO signal currently being implemented by the block:

  • Number of data points for lookup table — 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

  • Quarter wave sine lookup table size — The quarter wave sine lookup table size is defined by

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

  • Theoretical spurious free dynamic range — 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

Supported Data Types

PortSupported Data Types

inc

  • Fixed point with zero fraction length

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

offset

  • Fixed point with zero fraction length

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

sin

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

Qerr

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

See Also

PN Sequence GeneratorCommunications System Toolbox
Sine WaveDSP System Toolbox

Was this topic helpful?