差错控制编码 - 汉明软译码

时间:2017-06-20 23:50:52

标签: matlab decoding hamming-code

我想使用Euclidean距离(带有fonction repmat)创建汉明软解码器。我尝试编程,但它不能按我的意愿工作,我找不到合适的BER。

有人在我的解码器中检测到错误吗?

%软解码

Matlab代码:

n = 7; k = 4; Rate = k/n;   
G = [1 0 0 0 1 1 0 ; 0 1 0 0 1 0 1 ; 0 0 1 0 0 1 1 ; 0 0 0 1 1 1 1];
Eb_N0 = 0:10;                          
ber = zeros(1,11);          
words = 10000;
for kk = 1:11
    E_N0 = 10^(Eb_N0(kk)/10);           
    sigma = 1/(2*Rate*E/N0);  
    for jj = 1:words
        m = rand(1,4)>1/2; 
        c = mod(m*G,2);     
        x = 2*c-1;                     % Modulated code word
        w = sqrt(sigma)*randn(1,n);    % additive white gaussian noise
        y = x+w ;                      % receive vector
        N = 2^k;
        X = zeros(N,n);
        for yy = 0:N-1
            m = base2dec(dec2bin(yy,k).',2).';
            X(yy+1,:) = x;             % Set of modulated code words
        % Euclid. distance between y and each of the 16 modulated code words x
           dist = sqrt(sum(abs(X - repmat(y,[2^k,1])).^2,2)); 
        end
        [dmin, ind] = min(dist); 
        r = X(ind,:); 
        CodeDecode = r(1:4); %decoded info symbols
       % counting error 
       error = sum(m ~= CodeDecode);
       ber(kk) = ber(kk) + error;

    end  

end

ber = ber/(k*words);
theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0/10))); % theoretical ber uncoded AWGN
figure
semilogy(theoryBer,'b-');
hold on
semilogy(ber,'o-r');
legend('theory - uncoded','Soft Hamming')
title('BER for BPSK in AWGN with Hamming')
xlabel('Eb/N0 ')
ylabel('Ber')

0 个答案:

没有答案