clear all
close all
load HMM
load TESTLPC
DATA=[];
for i=1:1:3
DATA=[DATA TESTLPC{i}(1:1:mx,:)];
end
DATA1=[];
for i=1:1:size(DATA,2)
temp=DATA(:,i);
DATA1=[DATA1 reshape(temp,13,14)];
end
DATA1=E'*DATA1;
%Generating probability of the first word
S=5;
F=14;
G=[];
INDEX=[];
for x=1:1:15
DATA=DATA1(:,(x-1)*F+1:1:(x-1)*F+F);
GP=[];
for w=1:1:3
p= HMMMODEL{w}{1};
M=zeros(5,14);
M(1,1)=gaussvalue(DATA(:,1),HMMMODEL{w}{3}{1},...
HMMMODEL{w}{2}{1});
%Alignment using viterbi algorithm
for j=2:1:F
M(1,j)=M(1,j-1)*p(1,1)*gaussvalue(DATA(:,j),...
HMMMODEL{w}{3}{1},HMMMODEL{w}{2}{1});
end
% M(2,2)=M(1,1)*p(1,2)*gaussprob(DATA(:,2),...
% HMMMODEL{w}{2}{2},HMMMODEL{w}{3}{2});
for i=2:1:S
for j=2:1:i
M(j,i)=max( M(j-1,i-1)*p(j-1,j)*gaussvalue(DATA(:,i),...
HMMMODEL{w}{3}{j},HMMMODEL{w}{2}{j}),...
M(j,i-1)*p(j,j)*gaussvalue(DATA(:,i),HMMMODEL{w}{3}{j},...
HMMMODEL{w}{2}{j}));
end
end
for i=S+1:1:F
for j=2:1:S
M(j,i)=max( M(j-1,i-1)*p(j-1,j)*gaussvalue(DATA(:,i),...
HMMMODEL{w}{3}{j},HMMMODEL{w}{2}{j}),...
M(j,i-1)*p(j,j)*gaussvalue(DATA(:,i),HMMMODEL{w}{3}{j},...
HMMMODEL{w}{2}{j}));
end
end
%Backtrace to compute generating probability
trace=[5];
Q=5;
for i=(F-1):-1:1
if(Q==1)
trace=[trace 1];
else
[Y,Z]=max([M(Q,i) M(Q-1,i)]);
trace=[trace Q-Z+1];
Q=Q-Z+1;
end
end
o=trace(length(trace):-1:1);
gp=gaussvalue(DATA(:,1),HMMMODEL{w}{3}{o(1)},HMMMODEL{w}{2}{o(1)});
for i=2:1:F
gp=gp*p(o(i-1),o(i))*gaussvalue(DATA(:,i),HMMMODEL{w}{3}{o(i)},...
HMMMODEL{w}{2}{o(i)});
end
GP=[GP gp];
end
[V,I]=max(GP);
G=[G;GP];
INDEX=[INDEX I];
end