简体   繁体   中英

bit error rate calculation 15,11 hamming code graph

Below, in my code is supposes to find the simulation BER. But I am getting error on this code where nErrors = biterr(dataIn,dataDec2) this line gives matrix dimensions mismatch.

Is there anyone who can help me in this??

close all;
clear all;

M = 2;                 % Modulation order
k = log2(M);            % Bits per symbol
EbNoVec = -4:2:0;      % Eb/No values (dB)
No = -10;
numSymPerFrame = 100;   % Number of PSK symbols per frame
berEst2 = zeros(size(EbNoVec));
G2=[1 1 0 0 1 0 0 0 0 0 0 0 0 0 0; 
0 1 1 0 0 1 0 0 0 0 0 0 0 0 0; 
0 0 1 1 0 0 1 0 0 0 0 0 0 0 0; 
1 0 1 0 0 0 0 1 0 0 0 0 0 0 0;
1 0 0 1 0 0 0 0 1 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 1 0 0 0 0 0;
1 1 1 0 0 0 0 0 0 0 1 0 0 0 0;
0 1 1 1 0 0 0 0 0 0 0 1 0 0 0;
1 0 1 1 0 0 0 0 0 0 0 0 1 0 0;
1 1 0 1 0 0 0 0 0 0 0 0 0 1 0;
1 1 1 1 0 0 0 0 0 0 0 0 0 0 1   ];
H2= gen2par(G2);
decoding2 = syndtable(H2); 
Pt2 = zeros(size(EbNoVec));
for n = 1:length(EbNoVec)
% Convert Eb/No to SNR
snrdB = EbNoVec(n) + 10*log10(15/11);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
Pt2(n)= 10^((snrdB-10)/10);
while numErrs < 100
    % Generate binary data and convert to symbols
    dataIn = randi([0 1],numSymPerFrame,k)
    dataSym = bi2de(dataIn)
    dataEnc2 = encode(dataIn,15,11,'linear/binary',G2)
    % PSK modulation

    txSig = pskmod(dataEnc2,M);

    % Pass through AWGN channel
    rxSig = awgn(txSig,snrdB,'measured');

    % Demodulate the noisy signal
    rxSym = pskdemod(rxSig,M);
    % Convert received symbols to bits
    dataOut = de2bi(rxSym,k);
    dataDec2 =decode(rxSym,15,11,'linear/binary',G2, decoding2);
    % Calculate the number of bit errors
    nErrors = biterr(dataIn,dataDec2);

    % Increment the error and bit counters
    numErrs = numErrs + nErrors;
    numBits = numBits + numSymPerFrame*k;
end

% Estimate the BER
berEst2(n) = numErrs/numBits;


end
berTheory2 = berawgn(EbNoVec,'psk',M,'nondiff');
hold on 
semilogy(EbNoVec,berEst1,'r','LineWidth',2);

I debugged your code with a breakpoint on Line 46 [nErrors = biterr(dataIn,dataDec2)]. It seems the dataIn array is 100 x 1 and dataDec2 is a 110 x 1 array. 'biterr' function calculates the number of places where the two vectors of equal length differ.

This will give you a better explanation. https://www.mathworks.com/help/comm/ref/biterr.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM