%% File: dohamming.m
howmany=32;
%% Read data as nibbles
infile='coriolan.txt';
f=fopen(infile,'rb');
A=fread(f,howmany,'ubit4');
fclose(f);
%% Convert nibbles to vectors in GF(2)
% NOTE: Message becomes a sequence of
% 4-vectors over GF(2)
m = gf(de2bi(A,[],2))';
%% Haming encode the file
h=MyHamming;
code=encode(h,m);
%% Apply BSC to code
p=0.05;
err=gf(rand(size(code))<=p);
r=code+err;
%% Decode
code1=decode(h,r);
m1=code1(1:4,:);
%% Count uncorrected bit errors (silent data corruption)
[sum(err==1);sum(m1~=m)]'


