function yq=DDQ(x,th)
% This function applies the differential dynamical quantization 
% to input x, with a noise tolerance th.
% -----------------------------------------------------------------------
%                COPYRIGHT (2014): J. S. Armand EYEBE FOUDA
% -----------------------------------------------------------------------

[m,n]=size(x);
if n>m
    x=x';
    m=n;
end
Mx=max(abs(x))+eps;
x=x/Mx;
[zc1 Index1]=sort(x,1,'ascend');
%     .....................................
    mini=zc1(1);kj=1;zz=zc1;
    for jj=2:m
        stt=abs(zc1(jj)-zc1(jj-1));
        if stt>=th
            zz(jj-1)=mini;
%             Ic(kj)=jj;
            kj=kj+1;
            mini=zc1(jj);
        else
            zz(jj-1)=mini;
            zz(jj)=mini;
        end
    end
    
%     .........................................
    yq(Index1)=zz*Mx;
end