function z=encode_ham1511(x)
% z=encode_ham1511(x)
%
% Hamming 15,11 channel encoder
% x : uncoded bit sequence
% z : encoded bit sequence
% x,z are column vectors

if size(x,2) ~= 1
    error('x should be a column.');
end

a=length(x)/11; 

if a~=round(a)
    error('The length of x must be a multiple of 11.');
end

% Parity matrix P
P = [1 1 0 0; ...
     1 0 1 0; ...
     0 1 1 0; ...
     1 1 1 0; ...
     1 0 0 1; ...
     0 1 0 1; ...
     1 1 0 1; ...
     0 0 1 1; ...
     1 0 1 1; ...
     0 1 1 1; ...
     1 1 1 1];

% Generator matrix G
G = [eye(11) P];

% Message M
M=zeros(a,11);
for m=1:a
    M(m,:) = x(11*(m-1)+1:11*m);
end

Z=mod(M*G,2);

z=zeros(a*15,1);
for m=1:a
     z(15*(m-1)+1:15*m) = Z(m,:).';
end
 