Trouble generating MEX/ C code for a function containing DSP System object constructor

16 Ansichten (letzte 30 Tage)
Hi,
I am trying to generate a MEX file and C code for a function, but its failing and giving the following error:
codegen genNCO -args {F0}
??? Cannot compute constant value for argument #4 for this System object constructor. All arguments to the constructor of this System object must be constants for code generation. One way to supply a constant value is to pass it to the main function using Simulink non-tunable parameters (for MATLAB Function block) or coder.newtype('constant',...) (for MATLAB Coder).
Error in ==> genNCO Line: 43 Column: 12
Code generation failed: Open error report.
Error using codegen
The function genNCO is defined as:
function y_NCO = genNCO(F0)
%#codegen
Points = 2^13;
Fs = 250e3;
Ts = 1/Fs;
minSFDR = 80;
dphi = pi/2;
Nacc = 13;
Nqacc = ceil((minSFDR-12)/6);
phIncr = round(F0*Ts*2^Nacc);
phOffset = 2^Nacc*dphi/(2*pi);%2^Nacc*dphi/(2*pi);
NaccType = numerictype([],Nacc);
% Declare System objects as persistent
persistent hnco;
% Initialize persistent System objects only once. Do this with 'if isempty(persistent variable).' This condition will be false after the first time.
if isempty(hnco)
hnco = dsp.NCO('PhaseIncrementSource', 'Property',...
'PhaseIncrement', phIncr,...
'PhaseOffset', phOffset,...
'NumDitherBits', 4,...
'NumQuantizerAccumulatorBits', Nqacc,...
'SamplesPerFrame', Points,...
'CustomAccumulatorDataType', NaccType);
end
y_NCO = step(hnco);
y_NCO = double(y_NCO.');
I also tried defining values needed by hnco as follows:
Nacc = coder.newtype('double',13);%ceil(log2(1/(df*Ts)));
Nqacc = coder.newtype('double',ceil((minSFDR-12)/6));
phIncr = coder.newtype('double',round(F0*Ts*2^Nacc));
phOffset = coder.newtype('double',2^Nacc*dphi/(2*pi));%2^Nacc*dphi/(2*pi);
NaccType = coder.newtype('embedded.fi',numerictype([],Nacc1));
but it didn't help and the build fails.
Can someone tell me how to pass these values to hnco as to have a successful build for MEX and C- code? Thanks.

Antworten (0)

Kategorien

Mehr zu C Code Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by