for ii=1:M,
    ss=bin(ii-1,k);
    for jj=k:-1:2,
        gray(ii,jj)=xor(ss(jj),ss(jj-1));
    end
    gray(ii,1)=ss(1);
end
for ii=1:M,
    ss=bin(ii-1,k);
    ungray(ii,1)=ss(1);
    for jj=2:k,
        ungray(ii,jj)=xor(ungray(ii,jj-1),ss(jj));
    end
end
for ii=1:M,
    NCons(ii)=dec(ungray(ii,:));
end

if modu=='QPSK',
    for ii=1:4,
        s(ii)=cos(pi*(2*NCons(ii)+1)/4)+j*sin(pi*(2*NCons(ii)+1)/4);
    end
elseif modu=='MPSK',
    for ii=1:M,
        s(ii)=cos(2*pi*NCons(ii)/M)+j*sin(2*pi*NCons(ii)/M);
    end
elseif modu=='MQAM',
    s(1:8) =[ -3+3*j -1+3*j  3+3*j 1+3*j -3+j -1+j 3+j 1+j ];
    s(9:16)=conj(s(1:8));
end
         


