This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

dsp.NCO

Generate real or complex sinusoidal signals

Description

The numerically controlled oscillator, or NCO object generates real or complex sinusoidal signals. The amplitude of the generated signal is always 1.

To generate real or complex sinusoidal signals:

  1. Create the dsp.NCO 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

nco = dsp.NCO
nco = dsp.NCO(Name,Value)

Description

example

nco = dsp.NCO returns an NCO System object™, nco, that generates a multichannel real or complex sinusoidal signal, with independent frequency and phase in each output channel.

example

nco = dsp.NCO(Name,Value) returns an NCO System object, nco, with each specified property set to the specified value.

Properties

expand all

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

Specify the source of the phase increment as 'Property' or 'Input port'.

Specify the phase increment as an integer-valued scalar or vector.

Dependencies

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the source of the phase offset as 'Property' or 'Input port'.

Specify the phase offset as an integer-valued scalar or vector.

Dependencies

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Set this property to true to add internal dithering to the NCO algorithm. Dithering is added using the PN Sequence Generator.

Specify the number of dither bits as a positive integer.

Dependencies

This property applies only when you set the Dither property to true.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Set this property to true to enable quantization of the accumulated phase.

Specify the number of quantizer accumulator bits as an integer scalar greater than 2 and less than the accumulator word length (CustomAccumulatorDataType). This property determines the number of entries in the lookup table of sine values.

Dependencies

This property applies only when you set the PhaseQuantization property to true.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Set this property to true to output the phase quantization error.

Dependencies

This property applies only when you set the PhaseQuantization property to true.

Specify the type of the output signal.

Specify the number of samples per frame of the output signal. When the PhaseOffsetSource property is 'Input port', and the PhaseIncrementSource property is 'Property', the number of rows or frame size of the phase offset input determines the number of samples per frame of the output signal. When you set both the PhaseOffsetSource and PhaseIncrementSource properties to 'Input port', the number of rows in the inputs must be 1, and the samples per frame of the output signal is 1.

Dependencies

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Specify the output data type as 'double', 'single' or 'Custom'. When you select 'Custom', you must also set the CustomOutputDataType property.

Fixed-Point Properties

This constant property has a value 'Floor'.

This constant property has a value 'Wrap'.

This constant property has a value 'Custom'.

Specify the accumulator fixed-point type as an unscaled numerictype object with a Signedness of Auto.

Specify the output fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies only when you set the OutputDataType property to Custom.

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 = nco()
Y = nco(phInc)
Y = nco(OFFSET)
Y = nco(phInc,OFFSET)
[Y,cosine] = nco(___)
[Y,qErr] = nco(___)

Description

Y = nco() returns a sinusoidal signal when the PhaseIncrementSource and the PhaseOffsetSource properties are both set to 'Property'.

Y = nco(phInc) returns a sinusoidal signal, Y, generated by the NCO with the specified phase increment, phInc.

Y = nco(OFFSET) returns a sinusoidal signal, Y, with phase offset, OFFSET, when the PhaseOffsetSource property is set to 'Input port'.

Y = nco(phInc,OFFSET) returns a sinusoidal signal, Y, with phase increment, phInc, and phase offset, OFFSET, when the PhaseIncrementSource and the PhaseOffsetSource properties are both 'Input port'. phInc and OFFSET must both be row vectors of the same length, where the length determines the number of channels in the output signal.

[Y,cosine] = nco(___) returns a sinusoidal signal, Y, and a cosinusoidal signal, cosine, when the Waveform property is set to 'Sine and cosine'. This syntax can include any of the input arguments in previous syntaxes.

[Y,qErr] = nco(___) returns a sinusoidal signal, Y, and output quantization error, qErr, when the PhaseQuantization and the PhaseQuantizationErrorOutputPort properties are both true.

Input Arguments

expand all

Phase increment, specified as a scalar or a row vector, where each element corresponds to a separate channel.

When both PhaseIncrementSource and PhaseOffsetSource properties are set to 'Input port', the two inputs, phInc and OFFSET must have the same number of channels.

Dependencies

This property applies only when the PhaseIncrementSource property is set to 'Input port'.

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

Phase offset, specified as a row vector or a matrix. The number of rows of OFFSET determines the number of samples per frame of the output signal. The number of columns of OFFSET determines the number of channels of the output signal.

When both PhaseIncrementSource and PhaseOffsetSource properties are set to 'Input port', phInc and OFFSET must have the same number of channels.

Dependencies

This property applies only when the PhaseOffsetSource property is set to 'Input port'.

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

Output Arguments

expand all

NCO output, returned as a vector or a matrix. The number of rows in the output signal is determined by:

  • SamplesPerFrame property –– When PhaseOffsetSource is set to 'Property'

  • OFFSET input argument –– When PhaseOffsetSource is set to 'Input port'

The number of channels in the output signal is determined by the number of channels in the phase offset and the phase increment signals, which must be equal.

The data type of the output is determined by the OutputDataType property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Cosinusoidal signal, returned as a vector or a matrix. The cosine output signal has the same size and data type as the sinusoidal signal, Y.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Output quantization error, returned as a vector or a matrix. The qErr output signal has the same size as the sinusoidal signal, Y.

Dependencies

This output is only available when both the PhaseQuantization and the PhaseQuantizationErrorOutputPort properties are set to true.

Data Types: fi

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)

expand all

infoCharacteristic information about generated signal
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

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

Design an NCO source according to given specifications.

df = 0.05; % Frequency resolution = 0.05 Hz
minSFDR = 96; % Spurious free dynamic range >= 96 dB
Ts = 1/8000; % Sample period = 1/8000 sec
dphi = pi/2; % Desired phase offset = pi/2;

Calculate number of accumulator bits required for the given frequency resolution.

Nacc = ceil(log2(1/(df*Ts)));

Actual frequency resolution achieved.

actdf = 1/(Ts*2^Nacc);

Calculate number of quantized accumulator bits required from the SFDR requirement

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

Calculate the phase offset

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

Design the NCO source.

nco = dsp.NCO('PhaseOffset', phOffset,...
    'NumDitherBits', 4, ...
    'NumQuantizerAccumulatorBits', Nqacc,...
    'SamplesPerFrame', 1/Ts, ...
    'CustomAccumulatorDataType', numerictype([],Nacc));
san = dsp.SpectrumAnalyzer('SampleRate', 1/Ts, ...
    'PlotAsTwoSidedSpectrum', false);

View the output of the NCO source on a spectrum analyzer. Change the output frequency in the middle of the simulation from 510 Hz to 1520 Hz.

tic;
while toc < 10

    if toc < 5
        F0 = 510;
    else
        F0 = 1520;
    end
    % Calculate the phase increment
    phIncr = int32(round(F0*Ts*2^Nacc));
    y = nco(phIncr);
    san(y)
end

The characteristic information of the NCO object is defined by the following fields:

  • NumPointsLUT — Number of data points in the lookup table.

  • SineLUTSize — Quarter-wave sine lookup table size in bytes.

  • TheoreticalSFDR — Theoretical spurious free dynamic range (SFDR) in dBc.

  • FrequencyResolution — Frequency resolultion of the NCO.

To obtain the above characteristics for a specific NCO object, call the info function on the object.

nco = dsp.NCO
nco = 
  dsp.NCO with properties:

                PhaseIncrementSource: 'Input port'
                   PhaseOffsetSource: 'Property'
                         PhaseOffset: 0
                              Dither: true
                       NumDitherBits: 4
                   PhaseQuantization: true
         NumQuantizerAccumulatorBits: 12
    PhaseQuantizationErrorOutputPort: false
                            Waveform: 'Sine'
                     SamplesPerFrame: 1
                      OutputDataType: 'Custom'

  Show all properties

info(nco)
ans = struct with fields:
           NumPointsLUT: 1025
            SineLUTSize: 2050
        TheoreticalSFDR: 84
    FrequencyResolution: 1.5259e-05

The fields and their corresponding values change depending on the settings of the object. For instance, if the PhaseQuantization property is set to false, the TheoreticalSFDR field does not appear.

nco.PhaseQuantization = false;
info(nco)
ans = struct with fields:
           NumPointsLUT: 16385
            SineLUTSize: 32770
    FrequencyResolution: 1.5259e-05

Algorithms

This object implements the algorithm, inputs, and outputs described on the NCO block reference page. The object properties correspond to the block properties, except there is no object property that corresponds to the Sample time block parameter. The objects assumes a sample time of one second.

Extended Capabilities

See Also

Functions

System Objects

Introduced in R2012a