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

k = input('Input the number of information bits, k = ');
r = input('Input the number of redundant bits, n-k = ');
n = k+r;

t = 0;          % Inital value of error correcting capability
test = 0;       % To test if bound is still 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
        t = t+1;
    else
        t=t-1;
        test = 1;
    end
end
fprintf('The maximum correcting capability is t = %d\n',t);