# How do you find the most probable state path given an observed sequence with infinite emissions values in MATLAB?

I have created code to output observed values of a Hidden Markov Model. I see that 'hmmviterbi' would give you the most probable state sequence given an observed sequence, transmission matrix, and emission matrix. Is there a way to use this function if you don't have an emission matrix? My emission values are pulled from a normal distribution with mean dependent on 3 different states and standard deviation 1. If there is no way around to use 'hmmviterbi', how can you code on your own to produce the most probable state sequence? I am unsure how to deal with the infinite emission values. Here is my code for the initial HMM:

N = 3; %%the three states are [-1 0 1]
%A is transition prob matrix
A = [.99,.005,.005;.005,.990,.005;.005,.005,.990];
%pi is initial state vector
pi = [1/3,1/3,1/3];
%T is # of observations per simulation
T = 1000;
%n is # of simulations
n = 5;
%Allocate space for the state matrix
State = zeros(n,T);
Observe = zeros(n,T);
%loop over # of simulations

for i=1:1:n
x = rand(1);
if x <= (1/3)
State(i,1) = 1;
elseif x > (1/3) && x <= (2/3)
State(i,1) = 2;
else
State(i,1) = 3;
end
if State(i,1) == 1
b = -1;
elseif State(i,1) == 2
b = 0;
else
b = 1;
end

Observe(i,1)= normrnd(b,1);
for k=2:1:T
State(i,k) = randsample(3, 1, true, A(State(i,k-1),:));
if State(i,k) == 1
c = -1;
elseif State(i,k) == 2
c = 0;
else
c = 1;
end
Observe(i,k)= normrnd(c,1);
end
end
for i = 1:1:n
for k = 1:1:T
if State(i,k)==1
State(i,k)=-1;
elseif State(i,k)==2
State(i,k)=0;
else
State(i,k)=1;
end
end
end
$$$$


As for your precise point on how to handle the emission values : in the continuous case, you do not have a transition matrix $$B$$, whose elements are the $$b_{S_j}(O_i)$$, representing probability of the (discrete) observation $$O_i$$ conditioned on the discrete state $$S_j$$. Instead, $$b_{S_j}(O_i)$$ will be taken as the probability density function of the gaussian distribution, evaluated at the (continuous) value $$O_i$$, with mean parametrized by the hidden state $$S_j$$ and standard-deviation of 1. This is done by normpdf in Matlab
• In the discrete case, you have an emission matrix $B$ which works just like the transition matrix $A$ in your code sample. In the continuous case, you have $b_{S_j}(O_i) = \mathcal{N}(O_i,\mu_{S_j},\sigma_{S_j})$, i.e. the gaussian distribution whose mean and standard-deviation depends on the hidden state, evaluated at point $O_i$. In matlab this would give, using your notations: normpdf(Observe(n,t), mu(State(n,t)), 1), for all simulations n for all instants t, where mu` is a vector containing different means. May 5 '19 at 9:41