MATLAB Coder: Undefined function or Variable, the first assignment to a local variable determines its class

조회 수: 3 (최근 30일)
Hi,
I am using MATLAB Coder to convert a simple FSK Modem to C Code. Following are my codes:
Modulator Function:
function modSignal = my4FSKmod(data)
M = 4;
freqSep = 200;
fskMod = comm.FSKModulator(M,freqSep,'BitInput',1);
modSignal = step(fskMod,data);
end
Demodulator Function:
function demodData = my4FSKdemod(receivedSignal)
M = 4;
freqSep = 200;
fskDemod = comm.FSKDemodulator(M,freqSep,'BitOutput',1);
demodData = zeros(100,1);
demodData = step(fskDemod,receivedSignal);
end
My Test Code:
data = randi([0 1],100,1);
mod_out = my4FSKmod(data);
demod_out = my4FSKdemod(mod_out);
isequal(data,demod_out);
I went through few MATLAB Answer links and introduced the intialization of the 'demodData', but I still get this issue. Am I missing anything? kindly advice
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 9월 20일
You should probably not be building your modulator and demodulator every step. You should be building them at the time you initialize your system, save the variable somewhere handy, and recall it each time you need it. This is especially important for carrying on processing of a partially-used buffer (your packets are probably going to be varying size, due to data compression and error correction that you insert.)
mounika
mounika 2019년 9월 20일
Thank you Walter for your respone. So is it okay if I create another function (as I have to convert it to c) where I initialise the modulator and demodulator and later use the for modulation and demodulation.
It will be greatly helpful, if you can provide an example on how to
Thanks in Advance

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Modulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by