Hamming Code その3

Communication toolboxにあるsyndtableという関数を使用すると、ハミング符号のerror syndromeから誤りの位置をtable-lookupで求めることが出来ます。この関数を用いて、復号化の部分を書き換えてみました。参考リンク decoding table de2bi

clear all;
rand('state', 123);
numData=40;

M=3;
[H,G, N, K] = hammgen(M);
G = flipud(fliplr(G));
H = flipud(fliplr(H));
GenPol=gfprimdf(M);
dec_table = syndtable(H);

% Coding and Decoding
msg = randint(numData, K, [0, 1]);
coded_msg = mod(msg*G, 2);
err=randerr(numData, N, [0, 1; 0.2, 0.8;]);
rcv_msg = mod(coded_msg + err, 2);
err_syndrome = mod(rcv_msg*H', 2);

for ii=[1:numData]
   err_location = dec_table(bi2de(err_syndrome(ii,:),'left-msb')+1, :) > 0;
   fixed_msg = rcv_msg(ii,:);
   fixed_msg(err_location) = ~fixed_msg(err_location);
   fixed_msg_buf(ii,:)=fixed_msg(1:K);
end
[numError, BER] = biterr(msg, fixed_msg_buf);
disp(['BER num2str is ', num2str(BER)]);