Error in coding
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt Fig
2011-3-26
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.
回答(3 个)
Matt Fig
2011-3-26
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;
0 个评论
Walter Roberson
2011-3-26
You appear to have missed the part before the diagram on that page:
modelName = 'commLLRvsHD';
open_system(modelName);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!