- berawgn: provides the BER of an AWGN channel https://www.mathworks.com/help/comm/ref/berawgn.html
Why does the theoretical BER not coincide with the simulation one?
12 次查看(过去 30 天)
显示 更早的评论
clc;
clear all;
close all;
M = 4; % Modulation order
K = log2(M); % Bits per symbol
EbNoVec = (-10:1:10); % Eb/No values (dB)
numSymPerFrame = 100; % Number of PSK symbols per frame
N=10^6;
berEst = zeros(size(EbNoVec));
for i = 1:length(EbNoVec)
snrdB = EbNoVec(i) + 10*log10(K);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e6
% Generate binary data and convert to symbols
dataIn = randi([0 1],N,1);
n = 7; % Kolichestvo vsekh bitov na simvol.
k = 4;
txEncoded = encode(dataIn,n,k, 'hamming');%%%%%%%%%%%%%%
dataSym = bit2int(txEncoded,K);
% QAM modulate using 'Gray' symbol mapping
txSig = pskmod(dataSym,M);
% Pass through AWGN channel
rxSig = awgn(txSig,snrdB,'measured');
% Demodulate the noisy signal
rxSym = pskdemod(rxSig,M);
% Convert received symbols to bits
dataOut = int2bit(rxSym,K);
rxDecoded = decode(dataOut,n,k,'hamming');
% Calculate the number of bit errors
nErrors = biterr(dataIn,rxDecoded);
% Increment the error and bit counters
numErrs = numErrs + nErrors;
numBits = numBits + N;
end
% Estimate the BER
berEst(i) = numErrs/numBits;
end
berTheory = berawgn(EbNoVec,'psk',M, 'nondiff');
semilogy(EbNoVec,berEst,'*')
hold on
semilogy(EbNoVec,berTheory)
grid
legend('Estimated BER','Theoretical BER')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
0 个评论
回答(1 个)
Rangesh
2023-12-26
Hi Vtoroy,
I understand that you are seeking to identify why the theoretical value of BER does not align with the simulation results.
It's important to note that the use of a hamming code aims to reduce the BER by correcting the error. However, the function "berawgn" used for the theoretical value calculation does not account for the application of the hamming code. Consequently, there is a decrease in the BER rate compared to the theoretical values. That’s why there is a discrepancy in the simulation and the theoretical results.
To observe how the results compare, you can eliminate the encoding performed through the hamming code. Here is the modified code without the hamming code encoding:
M = 4; % Modulation order
K = log2(M); % Bits per symbol
EbNoVec = (-10:1:10); % Eb/No values (dB)
numSymPerFrame = 100; % Number of PSK symbols per frame
N=10^6;
berEst = zeros(size(EbNoVec));
for i = 1:length(EbNoVec)
snrdB = EbNoVec(i) + 10*log10(K);
% Reset the error and bit counter
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e6
% Generate binary data and convert to symbols
dataIn = randi([0 1],N,1);
n = 7; % Kolichestvo vsekh bitov na simvol.
k = 4;
% txEncoded = encode(dataIn,n,k, 'hamming');%%%%%%%%%%%%%%
dataSym = bit2int(dataIn,K);
% QAM modulate using 'Gray' symbol mapping
txSig = pskmod(dataSym,M);
% Pass through AWGN channel
rxSig = awgn(txSig,snrdB,'measured');
% Demodulate the noisy signal
rxSym = pskdemod(rxSig,M);
% Convert received symbols to bits
dataOut = int2bit(rxSym,K);
% rxDecoded = decode(dataOut,n,k,'hamming');
% Calculate the number of bit errors
nErrors = biterr(dataIn,dataOut);
% Increment the error and bit counters
numErrs = numErrs + nErrors;
numBits = numBits + N;
end
% Estimate the BER
berEst(i) = numErrs/numBits;
end
berTheory = berawgn(EbNoVec,'psk',M, 'nondiff');
semilogy(EbNoVec,berEst,'*')
hold on
semilogy(EbNoVec,berTheory)
grid
legend('Estimated BER','Theoretical BER')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
For further understanding, you can refer the following documentation:
I hope this resolves your query.
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!