function [combs] = bintab(M); 
%------------------------------------------------------------------------------- 
% function [combs] = bintab(M);  
% creates a 2^M x M matrix consisting of binary representations 
%   of the numbers 0 through 2^M -1. 
% the 1st column corresponds to the MSB (i.e. 2^(M-1)), the 
%   Mth column corresponds to the LSB (i.e. 2^(0)).    
%------------------------------------------------------------------------------- 

%-------------------------------------% 
% April 10, 1994                      % 
% Stephen P. Czenszak                 % 
% Duke University                     % 
%-------------------------------------% 

combs = zeros(2,M); 
combs(1,1) = 0; combs(2,1) = 1; 
for i = 2:M 
  mux = zeros(2^i,2^(i-1)); 
  for j = 1:length(mux(1,:)) 
    mux(j*2-1:j*2,j) = ones(2,1);  
  end  
  combs = mux*combs; 
  combs(1:2:length(combs(:,1)),i) = ones(length(combs(:,1))/2,1);      
end 
temp1 = combs(length(combs(:,1))/2+1:length(combs(:,1)),:);   
temp2 = combs(1:length(combs(:,1))/2,:); 
combs = [temp1;temp2]; combs = flipud(combs); 
