% File: minred.m
% Description:
% Use of the Hamming bound to find the number of redundant bits given
% the dimension of the code and desired error correcting capability.
% Copyright (c) 2005. Robert Morelos-Zaragoza. All rights reserved.

k = input('Input the number of information bits, k = ');
t = input('Input the desired error correcting capability, t = ');

n = k+1;        % Inital value of length
test = 0;       % To test if bound is satisfied
while test ~= 1
    % Compute the volume of a Hamming sphere of radius t
    S = 0;
    for i=0:t
        S = S + nchoosek(n,i);
    end
    % Compare with the number of syndromes
    if 2^(n-k) >= S
        test = 1;
    else
        n = n+1;
    end
end
fprintf('The minimum number of redundant bits is n-k = %d\n',n-k);