%file name: hamma.m %Written by Dr. James S. Kang, Cal Poly Pomona. %Calculate the codeword for the given data u when Hamming code is used. %u = input data such as [0 1 0 1]. %v = codeword = [u c], where c is the checking part. %To run the program, try % >>hamma([1 1 0 1]) function[H,G,v] = hamma(u) k=size(u,2); %k = length of u. m=ceil(log(k)/log(2)); if 2^m-1-m < k m=m+1; end n=k+m; Im=eye(m); Q=zeros(m,k); nc = 0; %nc = number of columns in Q matrix. count=0; d=zeros(m)'; while nc < k count=count+1; b=dec2bin(count); if sum(b)>1 nc=nc+1; s=size(b,1); if s