function a = unqam(z,M)

S=length(z);
[a,b]=size(z);
if (a>b)
   x=z.';
else
   x=z;
end;
x=ones(M,1)*x;

rootM=sqrt(M);
C=-rootM+2*(1:rootM)'-1;
C=C*ones(1,rootM);
C=C+i*C';
C=C(:);
d=2;
sigma2s=d^2*(M-1)/6;
C=C/sqrt(sigma2s);
C=C*ones(1,S);

[Y,I]=min(abs(x-C));
a=C(I);
