Code generation app fails due to 'Function call failed' caused by toolbox function

I'm trying to convert the code from the Matlab example 5G New Radio Polar Coding using the Matlab Coder app. To do this I seperated out the loop into its own function. However, I'm running into issues at the 'Check for Run-Time Issues' stage giving me a 'Generation of trial code failed' error. I attached a screenshot of the error report. However, this error is caused in a function that is a part of the 5G toolbox, not the function that I'm trying to turn into C code. Can I fix this error without changing the function from the toolbox, or will I need to make my own seperate version that I edit myself in order to circumvent/fix this 'Non-constant expression or empty matrix.' error? Or is something else going on that I'm not seeing here?
Below the function I'm trying to convert. It's copied from the example and minimally changed.
function [errStats, numferr] = frames(K, poly, E, nMax, iIL, crcLen, iBIL, noiseVar, numFrames, L) %#codegen
% Channel
chan = comm.AWGNChannel('NoiseMethod','Variance','Variance',noiseVar);
% Error meter
ber = comm.ErrorRate;
numferr = 0;
for i = 1:numFrames
% Generate a random message
msg = randi([0 1],K,1);
% Attach CRC
msgcrc = nrCRCEncode(msg,poly);
% Polar encode
encOut = nrPolarEncode(msgcrc,E,nMax,iIL);
N = length(encOut);
% Rate match
modIn = nrRateMatchPolar(encOut,K+crcLen,E,iBIL);
% Modulate
modOut = nrSymbolModulate(modIn,'QPSK');
% Add White Gaussian noise
rSig = chan(modOut);
% Soft demodulate
rxLLR = nrSymbolDemodulate(rSig,'QPSK',noiseVar);
% Rate recover
decIn = nrRateRecoverPolar(rxLLR,K+crcLen,N,iBIL);
% Polar decode
decBits = nrPolarDecode(decIn,K+crcLen,E,L,nMax,iIL,crcLen);
% Compare msg and decoded bits
errStats = ber(double(decBits(1:K)), msg);
numferr = numferr + any(decBits(1:K)~=msg);
end
end

Réponses (1)

You didn't mention the size of the pArrayPtrLLR. I couldn't figure out what is the corresponding variable in your m file. The dynamic size is not supported. Before using them, you need to define the size of the pArrayPtrLLR like zeros(100,100).

3 commentaires

I didn't mention it, because I did not write the function nrPolarDecode that calls lclPolarDecode that calls initializeDataStructures. All three functions are a part of the 5G toolbox. The initialisation setup I picked these values for now:
% Code parameters
K = 64; % Message length in bits, including CRC, K > 30
E = 180; % Rate matched output length, E <= 8192
% EbNo = 0.8; % EbNo in dB
EbNo = j;
L = 8; % List length, a power of two, [1 2 4 8]
numFrames = 1000; % Number of frames to simulate
linkDir = 'UL'; % Link direction: downlink ('DL') OR uplink ('UL')
R = K/E; % Effective code rate
decBits changes depending on the size of K and E, though. In the code I provided N, L, and m that are used in
[sttStr, arrayPtrLLR, arrayPtrC] = initializeDataStructures(N,L,m);
are
N = 256;
L = 8;
m = 8;
but for
K = 54;
E = 124;
then N, L, and m will be
N = 128;
L = 8;
m = 7;
So, if I want to define the size of pArrayPtrLLR I would need to change the functions as provided by the 5G toolbox. My question is there a way to avoid this and only change something in my function only?
I understand more clearly. Have you ever tried to disable dynamic memory allocation? Maybe Matlab determines the size of the pArrayPtrLLR.
cfg.EnableDynamicMemoryAllocation = false;
Matlab suggests the define all variables should be specific class, size, and complexity to generate fixed-size vectors. You can find the detailed information in
Do you mean just adding the line to the main code that calls the frames function? If so, that did not change anything unfortunately. The code ran fine if just run in Matlab, but trying to create C Code from it I'm getting the same 'function call' errors.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Code Analysis dans Centre d'aide et File Exchange

Produits

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by