How to use phase increment input on NCO

33 views (last 30 days)
Mike
Mike on 18 Sep 2025
Answered: Spoorthy Kannur about 11 hours ago
I'm trying to setup a simple model to use an NCO where the output frequency is adjustable via a constant block. Eventually the intent is to use this NCO source as part of a freuqency correction block, but trying to get something basic working first.
I followed the instructions here for setting up the NCO block: Design an NCO Source Block - MATLAB & Simulink
My Matlab script for setup looks like this:
%% Basic NCO Setup
fs = 1e6;
f0 = 110e3;
deltaF = 0.05;
sfdr = 96;
Ts = 1/fs;
phase_offset = pi/2;
% Calc Parameters
N = ceil(log2(1 / (deltaF * Ts)));
actualDeltaF = 1 / (Ts*(2^N));
P = ceil((sfdr - 12) / 6);
phase_inc = round((f0 * 2^N) / fs);
p_offset = round((2^N) * phase_offset / (2*pi));
When I configure the NCO block to have the phase increment value specified by dialog, everything works as expected. The sample rate and carrier freuqency are as expected per the Matlab calculations. However, when I configure it to use phase increment source by input port and use a constant block, the sample rate of the NCO becomes 5Hz and the carrier freuqency is < 0.5Hz. In both cases, the workspace variable 'phase_inc' is being used.
Here is the block diagram and the NCO properties dialog is shown below.
Question: What do I need to do to get the correct behavior when using the phase increment input port on the block?

Answers (1)

Spoorthy Kannur
Spoorthy Kannur 7 minutes ago
The behaviour may be due to a data type mismatch between the value expected by the NCO block and the value being fed into it through the input port.
When you use the dialog, MATLAB uses the workspace variable as-is, with its correct data type.
When you use the input port, the value coming from the constant block may be a double by default, but the NCO block (especially when configured for fixed-point) often expects an unsigned integer type (e.g., uint32 or uint64) for the phase increment. If the types don't match, Simulink may interpret the phase increment value incorrectly, resulting in a much lower frequency.
Also, ensure the NCO block's "Phase increment source" is set to "Input port" and the “sample time (Ts)” and other parameters are consistent with your script.
If this does not resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html).

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!