Error in coding

2 views (last 30 days)
Sherif
Sherif on 26 Mar 2011
The following code taken from
is not workign , plese some one help me to make it work. Two errors were displayed.
EbNo = 2:0.5:8; % information rate Eb/No in dB
codeRate = 1/2; % code rate of convolutional encoder
nBits = 4; % number of bits in a 16-QAM symbol
Pavg = 10; % average signal power of a 16-QAM modulated si
gnal
snr = EbNo - 10*log10(1/codeRate) + 10*log10(nBits); % SNR in dB
noiseVarVector = Pavg ./ (10.^(snr./10)); % noise variance
% Initialize variables for storing the BER results
ber_HD = zeros(1, length(EbNo));
ber_SD = zeros(1, length(EbNo));
ber_LLR = zeros(1, length(EbNo));
% Loop over all noiseVarVector values
for idx=1:length(noiseVarVector)
noiseVar = noiseVarVector(idx);
sim(modelName);
% Collect BER results
ber_HD(idx) = BER_HD(1);
ber_SD(idx) = BER_SD(1);
ber_LLR(idx) = BER_LLR(1);
end
% Perform curve fitting and plot the results
fitBER_HD = real(berfit(EbNo, ber_HD));
fitBER_SD = real(berfit(EbNo, ber_SD));
fitBER_LLR = real(berfit(EbNo, ber_LLR));
semilogy(EbNo, ber_HD, 'r*', ...
EbNo, ber_SD, 'g*', ...
EbNo, ber_LLR, 'b*', ...
EbNo, fitBER_HD, 'r', ...
EbNo, fitBER_SD, 'g', ...
EbNo, fitBER_LLR, 'b');
legend('Hard Decision Decoding','Soft Decision Decoding','Unquantized Decodi
ng');
xlabel('Eb/No (dB)'); ylabel('BER');
title('LLR vs. Hard Decision Demodulation with Viterbi Decoding');
grid on;
  1 Comment
Matt Fig
Matt Fig on 26 Mar 2011
It is always helpful to give more information rather than less. For example, what did the error messages say? Copy and paste the error messages.

Sign in to comment.

Answers (3)

Matt Fig
Matt Fig on 26 Mar 2011
Do have the correct toolboxes? Did you format the code correctly? It looks like there is some wrapping going on even on the page you got it from. Try this:
EbNo = 2:0.5:8;
codeRate = 1/2;
nBits = 4;
Pavg = 10;
snr = EbNo - 10*log10(1/codeRate) + 10*log10(nBits);
noiseVarVector = Pavg ./ (10.^(snr./10)); % noise variance
% Initialize variables for storing the BER results
ber_HD = zeros(1, length(EbNo));
ber_SD = zeros(1, length(EbNo));
ber_LLR = zeros(1, length(EbNo));
% Loop over all noiseVarVector values
for idx=1:length(noiseVarVector)
noiseVar = noiseVarVector(idx);
sim(modelName);
% Collect BER results
ber_HD(idx) = BER_HD(1);
ber_SD(idx) = BER_SD(1);
ber_LLR(idx) = BER_LLR(1);
end
% Perform curve fitting and plot the results
fitBER_HD = real(berfit(EbNo, ber_HD));
fitBER_SD = real(berfit(EbNo, ber_SD));
fitBER_LLR = real(berfit(EbNo, ber_LLR));
semilogy(EbNo, ber_HD, 'r*', ...
EbNo, ber_SD, 'g*', ...
EbNo, ber_LLR, 'b*', ...
EbNo, fitBER_HD, 'r', ...
EbNo, fitBER_SD, 'g', ...
EbNo, fitBER_LLR, 'b');
legend('Hard Decision','Soft Decision','Unquantized Decoding');
xlabel('Eb/No (dB)'); ylabel('BER');
title('LLR vs. Hard Decision Demodulation with Viterbi Decoding');
grid on;

Sherif
Sherif on 26 Mar 2011
that coding was also not working, following error message has occoured.
??? Undefined function or variable 'modelName'.
Error in ==> Untitled4 at 16 sim(modelName);
can you please correct it ..?

Walter Roberson
Walter Roberson on 26 Mar 2011
You appear to have missed the part before the diagram on that page:
modelName = 'commLLRvsHD';
open_system(modelName);

Tags

Community Treasure Hunt

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

Start Hunting!