Not enough input arguments.

% function for realizing M-QAM modulation %
function simSerMQAM = mQAM(M, EsN0dB)
j = sqrt(-1); % imaginary unit %
numSim = 7*10^5; % number of simulation symbols %
k = sqrt(1/((2/3)*(M-1))); % factor for normalizing energy %
Not enough input arguments.
Error in mQAM (line 6)
k = sqrt(1/((2/3)*(M-1))); % factor for normalizing energy %

Answers (1)

It seems, you are striaght away running the code using run/ F5 key.
Save your code into function, with the name mQAM.m, go the directory where the file is present.
M = define your variable ;
EsN0dB = define your value ;
% Now call the function
simSerMQAM = mQAM(M, EsN0dB) ;

7 Comments

i see what you mean. defining the used variables before running it. only thing is that I havent been given M so what can i do?
You must be having idea on what M and other variables are.
No need to see. You need to provide inputs thats it.
I figured out M and the code works but it doesnt give an output???
EbN0dB = [-3:14]; % multiple Eb/N0 values %
M = 16 ;
% function for realizing M-QAM modulation %
function simSerMQAM = mQAM(M, EsN0dB)
j = sqrt(-1); % imaginary unit %
numSim = 7*10^5; % number of simulation symbols %
k = sqrt(1/((2/3)*(M-1))); % factor for normalizing energy %
m = (1:sqrt(M)/2); % alphabets %
alphaMqam = [-(2*m-1) 2*m-1];
errSymsQAM = zeros(1, length(EsN0dB));
for ii = 1:length(EsN0dB)
infoSyms = randsrc(1,numSim,alphaMqam) + j*randsrc(1,numSim,alphaMqam);
infoSymsQAM = k*infoSyms; % normalization of energy to 1 %
noise = 1/sqrt(2)*(randn(1,numSim) + j*randn(1,numSim)); % white guassian noise, 0dB variance %
tranSymsQAM = infoSymsQAM + 10^(-EsN0dB(ii)/20)*noise; % additive white gaussian noise %
% demodulation %
tranSymsRe = real(tranSymsQAM)/k; % real part %
tranSymsIm = imag(tranSymsQAM)/k; % imaginary part %
% rounding to the nearest alphabet %
recSymsRe = 2*floor(tranSymsRe/2)+1;
recSymsRe(recSymsRe >max(alphaMqam)) = max(alphaMqam);
recSymsRe(recSymsRe <min(alphaMqam)) = min(alphaMqam);
% rounding to the nearest alphabet %
recSymsIm = 2*floor(tranSymsIm/2)+1;
recSymsIm(recSymsIm >max(alphaMqam)) = max(alphaMqam);
recSymsIm(recSymsIm <min(alphaMqam)) = min(alphaMqam);
demoSyms = recSymsRe + j*recSymsIm;
% counting the number of symbol errors %
errSymsQAM(ii) = size(find((infoSyms - demoSyms)),2);
end
simSerMQAM = errSymsQAM/numSim;
end
It is working very fine.
EbN0dB = [-3:14]; % multiple Eb/N0 values %
M = 16 ;
simSerMQAM = mQAM(M,-3:14) ;
simSerMQAM
simSerMQAM = 1×18
0.8102 0.7906 0.7662 0.7404 0.7103 0.6754 0.6350 0.5891 0.5372 0.4806 0.4186 0.3534 0.2868 0.2219 0.1628 0.1088 0.0679 0.0369
% function for realizing M-QAM modulation %
function simSerMQAM = mQAM(M, EsN0dB)
j = sqrt(-1); % imaginary unit %
numSim = 7*10^5; % number of simulation symbols %
k = sqrt(1/((2/3)*(M-1))); % factor for normalizing energy %
m = (1:sqrt(M)/2); % alphabets %
alphaMqam = [-(2*m-1) 2*m-1];
errSymsQAM = zeros(1, length(EsN0dB));
for ii = 1:length(EsN0dB)
infoSyms = randsrc(1,numSim,alphaMqam) + j*randsrc(1,numSim,alphaMqam);
infoSymsQAM = k*infoSyms; % normalization of energy to 1 %
noise = 1/sqrt(2)*(randn(1,numSim) + j*randn(1,numSim)); % white guassian noise, 0dB variance %
tranSymsQAM = infoSymsQAM + 10^(-EsN0dB(ii)/20)*noise; % additive white gaussian noise %
% demodulation %
tranSymsRe = real(tranSymsQAM)/k; % real part %
tranSymsIm = imag(tranSymsQAM)/k; % imaginary part %
% rounding to the nearest alphabet %
recSymsRe = 2*floor(tranSymsRe/2)+1;
recSymsRe(recSymsRe >max(alphaMqam)) = max(alphaMqam);
recSymsRe(recSymsRe <min(alphaMqam)) = min(alphaMqam);
% rounding to the nearest alphabet %
recSymsIm = 2*floor(tranSymsIm/2)+1;
recSymsIm(recSymsIm >max(alphaMqam)) = max(alphaMqam);
recSymsIm(recSymsIm <min(alphaMqam)) = min(alphaMqam);
demoSyms = recSymsRe + j*recSymsIm;
% counting the number of symbol errors %
errSymsQAM(ii) = size(find((infoSyms - demoSyms)),2);
end
simSerMQAM = errSymsQAM/numSim;
end
ahhhh i see
i didnt have these lines thats why
simSerMQAM = mQAM(M,-3:14) ;
simSerMQAM
i got the values now.
what about this error?
Unable to perform assignment because the left and right sides have a different number of elements.
Error in mQAM34 (line 35)
recPhase(find(recPhase <0)) = recPhase(find(recPhase >0)) + 2*pi;
Seems that
find(recPhase <0)
and
find(recPhase >0)
have a different number of elements.
Or is it just a typing error with the < and > signs ?

Sign in to comment.

Products

Asked:

on 2 Apr 2022

Commented:

on 2 Apr 2022

Community Treasure Hunt

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

Start Hunting!