Hi guys, before posting here I really searched on forum here about my issue and I found something relevant to viterbi decoder and there's already built functions that simulink provide, but I really didn't understand them, I mean by that I didn't understand how do I use them in my question, so feel free if you'd like to use them it's acceptable for me.
My problem is : (attaching a video of my problem explanation : https://www.youtube.com/watch?v=dKIf6mQUfnY so it's recommended and preferable to understand my problem and waste your time reading my problem below is see the video because it's explained more understandable on the video , the state machine is given for me and there's no need to implement it, so it's as input to my function )
I have a diagram of state machine (on the left side in the photo below) , every dots respectively represent the current state that Im in,
first point represents state : 00
second point below the first point represents state: 10
third point below the second point represents state: 01
fourth point below the third point represents state : 11
So graphically what I explained above is :
00 first point
10 second point
01 third point
11 fourth point
this state machine is given to the function, every Arrow in the state machine (the left side in my photo below) represent:
given input bit (zero or 1) / current state output , so for first point 00 there's two arrows crossing from it, first row if the input is zero then it's 0/00 , this means that the given input bit is zero and output is 00 , the second arrow from state 00 if the input bit is 1 then it will transit to state 10 (it was 00 and if input 1 from left side then it will be 10) and output is 11 ..etc for all state shows in the left side in my attached photo below.
so my function that Im trying to implement in matlab is viterbi decode according to hamming distance!
As you see in the photo above, the right side of my photo is what my function is going to do and return according to it the required output, my function is actually what it does is decoding according to given state machine diagram and by hamming distance the input data to figure what are the bits.
for example lets assume my input is : input = [0 0 0 1 0 1 1 0 1 0];
so if we look at left side of attached photo above, we see that over all arrows on state machine output are two bits (00 , 01 , 10 ,11) so we must devide the input to two bits and it will be like this : 00 01 01 10 10
and now we calculate the hamming distance between every two pairs of the given input with out state machine arrows outputs, this means:
input as I said devided it to pairs : 00 01 01 10 10
so now I look to state machine outputs and I start from first point there's two arrows 0/00 , 1/11 so I look at my input first pair 00 , and do comparing by hamming distance (hamming distance is the number of differences between the two compared patterns ) , for first row that cross fro first point of state machine 0/00 the output (second pattern) is 00 I compare to the the first pair of my input which it's also 00 so the hamming distance is 0 because (00 compared to 00 has no differences) ..so you see on the right side of my photo that there's an arrow below 00 has hamming distance 0. I look now for the second arrow that cross from first point 00 of state machine (left side) I see it's 1/11 so here the output as shown is 11 compared to right side at my input pair 00 the hamming distance is 2 (00 compared to 11 => hamming distance is 2 because the differences between 00 and 11 is 2) , so if you look on the right side of my photo you see under 00 there's two arrows one with hamming distance 0, second arrow with hamming distance 2 .
Now I go to the second pair input on the right side which it's 01 , now do the comparing between 01 to the outputs of states of my state machine on the left side, this means we look at first point of my state machine which it's 0/00 for first arrow, second arrow it's 1/11, I compare 00 and 11 (second outputs that's shown on my arrows of my state machine). so I look at 01 at right side of my photo, and take all hamming distance between it to 00 and 11 .
Under 01, for first arrow on the right side , I look at 01 and 00 so I see hamming distance is 1, so the value on that arrow is 1, so the value of that arrow is =1+ (hamming distance on the previous arrow which it's zero in my case ) = 1 . Now I look to second arrow under 01 on the right side the hamming distance between 11 and 01 is 1, so the value of that arrow is 1+( (hamming distance on the previous arrow which it's zero in my case ) =1 .
I complete like this scheme under whole states on right side 00 01 01 10 10 and for each state on the right side I take the hamming distance according to state machine on the left side respectively.
After I finish all states on the right side, I take for every state the minimum distance under of it and if there's two hamming distance with the same value I return one of them(doesn't matter) like min(2,2)=2 ..
so after taking all the minimum distance under each state at the right side (on the photo I circlued by red circules on the path I I take -minimum hamming distances), I retrun respectively the input bits from state machine on the left side for each state corresponded to the minimum hamming distance path that I drew on thew right side, in my case this means the path is: (I mean ny the path what's circuled in red circles)
00 00 11 10 10
so I look at state machine on left side and correspondingly to that path to my left side state machine I take its input values , I mean by input values the left side of the value of my arrow for instance if it was 1/11 the left side of 1/11 is 1 and the right side is 11 ..
So correspondingly to the path that I drew on the right side I look on the left side and take all the input values of my arrows respectively to the path that I drew on the right side.
So the output in my case is array of binary integers which it's :
output=[0 0 1 1 0];
Note once again if two haming distances under any states of the right side having the same values so it doesn't matter which arrow to return because they have the same value.
In addition, the state machine on the left side is given to the function that I want to implement and there's no need to implement it again, it's given as input to my function.
Any assistance please how do I implement that in matlab? thanks alot, I really appreciate your help to me.
Im posting here because I really tried about two weeks struggling my problem and at the end unfortunately Im not getting the required output and my code is too long aside to that my algorithm is too long, here's my code down what I tried:
function [code]= encode_data(message1)
code1= [code1 outp];
input=[ input (rcvdmsg(j))* 2 + (rcvdmsg(j+1))];
op_table=[00 00 11; 01 11 00; 10 10 01; 11 01 10];
ns_table=[0 0 2; 1 0 2; 2 1 3; 3 1 3];
transition_table=[0 1 1 55; 0 0 1 1; 55 0 55 1; 55 0 55 1];
em_c=M_a + aem(i,t);
em_r=temp_metric(1,k) + aem(temp_parent(1, k)+1,t);
if( em_c< em_r)
em_c=M_b + aem(i,t);
em_r=temp_metric(1,k) + aem(temp_parent(1, k)+1,t);
if( em_c < em_r)
temp_parent=[temp_parent cs cs];
temp_state=[temp_state ns_a ns_b];
temp_metric=[temp_metric M_a, M_b];
aem(xx1, t+1)=temp_metric(1, h) + aem(xx2, t);
slm_loc=find( aem(:, t+1)==slm );
dec_op=[dec_op, transition_table((sseq(p)+1), (sseq(p+1)+1))];
it would be appreciated if anyone could help to implement my problem solution in matlab !