%fuzzykmeansforspeech.m
function [M,COV,INDEX,m,D,J]=fuzzykmeansforspeech(DATA,n,N)
subplot(2,2,1)
plot3(DATA(1,:),DATA(2,:),DATA(3,:),'r*')
s1=size(DATA,2);
s2=size(DATA,2)/n;
r=0;
M=[];
J=[];
for i=1:1:n
M{i}=mean(DATA(:,(i-1)*s2+1:1:(i-1)*s2+s2)')';
end
p=10; th=0.01;
for iteration=1:1:N
%Computation of distance matrix
for i=1:1:s1
for j=1:1:n
D(i,j)=(DATA(:,i)-M{j})'*(DATA(:,i)-M{j});
end
end
m=zeros(s1,n);
[P,Q]=find(D<th);
for i=1:1:length(P)
m(P(i),:)=0;
m(P(i),Q(i))=1;
end
%Computation of membership matrix
for i=1:1:s1
for j=1:1:n
s=0;
for k=1:1:n
if(k~=j)
s=s+(D(i,j)/(D(i,k)+eps))^(1/(p-1));
else
s=s+1;
end
end
m(i,j)=1/(s+eps) ;
end
end
[P,Q]=find(D<th);
for i=1:1:length(P)
m(P(i),:)=0;
m(P(i),Q(i))=1;
end
for j=1:1:n
NUM=0;
DEN=0;
for i=1:1:s1
NUM=NUM+(m(i,j)^p)*DATA(:,i);
DEN=DEN+m(i,j)^p;
end
M{j}=NUM/(DEN+eps);
end
J=[J sum(sum((m.^p).*D))];
for k=1:1:n
C{k}=[];
INDEX{k}=[];
end
S=0;
for i=1:1:size(DATA,2)
D1=[];
for j=1:1:n
D1=[D1 sum((DATA(:,i)-M{j}).^2)];
end
[P,Q]=min(D1);
C{Q}=[C{Q} DATA(:,i)];
INDEX{Q}=[INDEX{Q} i];
end
end
for i=1:1:n
COV{i}=cov(C{i}');
end