%function s=allpam(M,N_s,sigma2);
%This function generates all combinations for the given 
%alphabet.  For example, 
%
%       allpam(2,2,1) would return:
%
%         [ -1     1    -1     1
%           -1    -1     1     1 ]
%
% The inputs are alphabet size, source vector length, 
% and source variance.

% A.Klein 2/20/98

function s=allpam(M,N_s,sigma2);

s=zeros(N_s,M^N_s);
s(:,1)=ones(N_s,1);

for i=2:M^N_s
  s(:,i)=s(:,i-1);
  incr=0;  
  index=1;
  while index<N_s
    if (s(index,i)==M)&(~incr)
      s(index,i)=1;
      s(index+1,i)=s(index+1,i)+1;
      incr=1;
    elseif s(index,i)>M
      s(index,i)=s(index,i)-M;
      s(index+1,i)=s(index+1,i)+1;
    elseif ~incr
      s(index,i)=s(index,i)+1;
      incr=1;
    end
    index=index+1;
    if (index==N_s)&(~incr)
      s(index,i)=s(index,i)+1;
      incr=1;
    end
  end
end

s=2*s-M-1;
norm=sqrt(3*sigma2/(M^2-1));
s=norm*s;