No BSD License  

Highlights from
parchk

from parchk by Jim Simos
Adds an overall parity check bit to the input Code.

C2=parchk(C1)
function C2=parchk(C1)

% PARCHK Adds an overall parity check bit
% to the code C1.The output code C2 is the 
% extended code.C1 must be a binary fixed 
% length block code.
% For example if C1=[1 0 0 1 ; 1 1 1 0] then
% C2=parchk(C1),returns C2=[1 0 0 1 0 ; 1 1 1 0 1].
%
%  See also INT2VEC.
%
%  Copyright (c) 2005 by Jim Simos , email:jsimos@math.uoa.gr
%  $Revision : 1.0 $  $Date: 30/9/2005 21:00:30 PM $

%-----Begin Function-----%

% Initializing variables

[rows,cols]=size(C1);
C2=[];

%----Main function-----%

for i=1:rows,
    codeword=C1(i,:);
    w=weight(codeword);
    final_codeword=[codeword,mod(w,2)];
    C2=[C2 ; final_codeword];
end

%-----End Function-----%

%--Auxiliary Functions--%

function w=weight(c)

% WEIGHT Calculates the weight 
% of the codeword c.

w=0;

for i=1:size(c,2),
   w=w+c(i);
end   

Contact us at files@mathworks.com