function b = vector_quant(v,k)


% v:  speech vectors ,mel scaled.
% k:  no.of centroids reqd. Here k=16.


c=mean(v,2);                      % finding initial codebook
e = 0.01;                         % splitting parameter

c(:,1)=c(:,1) + c(:,1)*e;         % splitting the codebook into 2.
c(:,2)=c(:,1) - c(:,1)*e;

d=euclid_dist(v,c);               % calculating the  euclidean distance.
[m,id]=min(d,[],2);               % finding the minimum distance.

[rows,cols]=size(c);


for j=1:cols

   c(:,j)=mean(v(:,find(id==j)),2);  % finding the centroid of the new cluster.

end;

n=1;n=n*2;

while cols < k                   % updating the code book to get the reqd. no.

     for i = 1:cols                  % of code vectors.

        c(:,i)=c(:,i) + c(:,i)*e;
        c(:,i+n)=c(:,i) - c(:,i)*e;
     
     end;

     d=euclid_dist(v,c);          % calculating the  euclidean distance  

     [m,i]=min(d,[],2);           % finding the minimum distance

     [rows,cols] = size(c);

       for j=1:cols

        c(:,j)=mean(v(:,find(i==j)),2);  % finding the centroid of the new cluster

       end;
  
     n=n*2;

end

b=c;


   