%%Doug Van Nort   MUMT 611 Final Project
%
%We train our Flute Model Here, using Baum-Welch
%
%dhmm_em is from the HMM toolbox of Kevin Murphy


O = 73;  % we first quantize to 16 possible obervations
Q = 100; % we use 10 states: 1 for each analysis frame


% initial guess of parameters - random matrices
prior1_F = [1 zeros(1,Q-1)];      %we use a left-to-right model, and so this is our initial state distribution
transmat1_F = mk_stochastic(rand(Q,Q));
obsmat1_F = mk_stochastic(rand(Q,O));


trdata_F = [OFL(1,:);OFL(3,:);OFL(6:12,:);OFL(14:16,:);OFL(18:19,:);OFL(21,:);OFL(23:26,:);OFL(28:31,:);OFL(33:36,:);...
            OFR(1,:);OFR(3,:);OFR(6:12,:);OFR(14:16,:);OFR(18:19,:);OFR(21,:);OFR(23:26,:);OFR(28:31,:);OFR(33:36,:)];

% improve guess of parameters using EM (Baum-Welch)

[LL_F, prior_F, transmat_F, obsmat_F] = dhmm_em(trdata_F, prior1_F, transmat1_F, obsmat1_F, 'max_iter', 5);