 Welcome to this lecture on digital communication using GNU radio. My name is Kumar Appaya and I belong to the Department of Electrical Engineering IIT Bombay. In this lecture, we will conclude our discussion of the Viterbi algorithm with an example. If you recall in the previous lecture, we computed an incremental metric and we claim that the incremental metric can be used to make decisions on the fly when you perform maximum likelihood sequence estimation. The incremental metric had this form. Just to remember the notation, the ZK was essentially obtained by taking the inner product of Y with SB at the KT time instant. And if you now look at the H, that was the autocorrelation of P's evaluated at KT. Let us now perform this for the example which we were looking at. If you recall for the example we were looking at, we obtained an effective P of T that had this form. The form was, this is 1, 2, 3, 4. The value here is minus half. It is half. The value here is 1. For this Pt, we are going to now perform the Viterbi algorithm for a certain example. But as a prerequisite, we need to compute H at 0, H1, H2 and so on. So, let us actually compute our values of H for this. H0, in this case everything is real and we will assume BPSK as well, is integral P of T, we are going to P star of T to P's T square. This is very easy to evaluate. It is, if you look over here, the value is 1, the value is half, the value is minus half. So, you get 1 plus 1 by 4 plus 1 by 4, that is 3 by 2. That is your H0. Now, for H1, you have to be careful. To compute H1, we can just do integral P of T and P of T minus capital T, remember the rate of signaling capital T is essentially 2. We have half a symbol per second. To do this integral, we can just shift this by 2. So, I am going to now delay this by 2. Put 1 here, half here, minus half here. So, if you now perform this overlap integral, it is very evident that this 1 multiplies by minus half and you get minus half. And this is also equal to H of minus 1 conjugate, which is H of minus 1. In this case, it is real. And interestingly, in this case, there is nothing much else that you have to do. This is essentially all that you have. Now, let us move ahead. This lambda k B k S k gives you the incremental metric for the transition from S k to S k plus 1. Now, we are going to use this. So, let me just take this below, make a copy. I am just going to make a copy and paste it. And we are going to now perform an example. And the example that we are going to perform is one where we are going to use PPSK. We are going to assume that B 0 is always plus 1. Then, we have these sequence of received Ys. Y 0 is minus 1. Y 1 is 2. Y 2 is minus 2. Y 3 is 1.5. This is what is received. Y 0 does not really matter because we know B 0 is 1 already. We will use Y 1, Y 2 and Y 3 to figure out what sequence was sent. To do this, we are going to draw what is called a Trellis diagram of the states. What is a Trellis diagram? In this case, we have BPSK. So, let us actually draw our Trellis diagram. I am going to draw for B 0, what are the possible values it takes plus 1? Nothing else. For B 1, what are the possible values it takes? Plus 1 or minus 1. Now, if you look at the interpretation of that incremental metric, that was about going from B SSK to SK plus 1. So, in this case, we were going from S 1 to S 2 and that can be using B 1 or B 2. That is basically the interpretation. For B 2, 2 states, for B 3, 2 states and so on. Now, the actual thing we have to do is to compute the matrix which are going to come here and that is what we are going to do using this particular expression. Now, let us look at this expression for the application here. Now, in the initial computation, we are going to simplify this because there are some observations which we are going to make. Mod BK square is always 1 for BPSK. In fact, for any quam, it does not matter. So, and H 0 is a fixed number. This term can go away. Similarly, in our case, what is our capital L? Our capital L is 1. Why? Because we computed H, it had only a dependence on L equal to 1. So, we have our autocorrelation sequence essentially was minus half 1 half and minus half 1 minus half. So, this has a dependence only on 1. So, it is actually m is equal to surprisingly k minus 1 to k minus 1. It has only one term. So, our incremental metric actually gets simplified significantly. So, our incremental metric if you simplify this will turn out to be, maybe I will write it below. Over here it is B star k z k. B star k z k and remember your z k is basically what you get from the y. It is B star k z k minus and you have real part of B star k. In this case, the real part goes away, the conjugate goes away. It is B k times it is B k minus 1 H 1. Therefore, this number is actually half, this number is B k minus 1 and this number is just B k. Therefore, our simplified expression is going to be lambda k B k s k. I can just simplify it easily. I am just going to write my z as y directly. So, I am just going to write this as B k y k. The middle term goes away because it was just 1 always and why did I write this? Because this was minus half actually I mean I am sorry minus half sorry because H 1 was minus half this is a minus and minus that became plus half. So, now this became my metric B k y k plus half B k B k minus 1. Now, let us look at the values we got minus 1 2 minus 2 1.5. Now, we are going to write our first metric lambda k B 0 s k. What is the metric if the B 1 is actually plus 1? Let us write it B k is equal to plus 1. Then, what is the metric? We get 1 times y 1 and what is my y 1? y 1 is minus 1 minus 1 plus half times minus 1 plus 1 plus half B k B k minus 1. So, if B k is plus 1 and I think my y 0 as I am sorry y 1 is 2 I am so sorry if you remember y 1 is 2 that is the mistake I made. So, I am sorry let me correct this. So, let us do this again B k is plus 1. So, 2 plus and B k is plus 1 half is 2.5. Let us compute the branch metric for the other approach with B k is minus 1 actually B 1 I wanted to write B 1 over here it is actually correct it ok. So, this is B 1 if B 1 is minus 1 what do I get y is still 2 and B 1 is minus 1. So, minus 2 and B 0 is plus 1. So, minus half this is minus 2.5. So, what I am going to do is in this particular trellis diagram I am actually going to write these metrics because these are the metrics that I am going to see I essentially want to maximize this quantity this lambda B. So, I am going to write these on the bar over here. So, 2.5 for going here minus 2.5 I am going here. So, what does this mean? The branch metric based on the y I got for going from plus 1 to plus 1 is 2.5 for plus 1 to minus 1 B 1 being minus 1 is 2.5. Now, you cannot say that because the minus 1 metric is smaller of course, you will I mean you then I have to decide it is plus 1 you cannot do that because you are doing a sequence wise detection. Therefore, you cannot make an incremental decision at this stage you have to go to the next stage and then check. So, let us actually do that ok. Now, let us suppose that B 1 is plus 1 or B 1 is minus 1 and check out all the transitions that can occur based on this. Now, if you remember in our expressions for in our discussion we said that one symbol depends only on the next symbol that manifests evidently over here because we have only one hop dependence. So, B 1 depends on B 0 B 2 depends on B 1. Now, let us compute further matrix lambda k B 1 and this was actually S k was S 2 let us say S 1. So, B 1 will say S yeah will say B 1 S 1 yes ok. Now, what do we do? We are going to say if B 2 is plus 1 if B 2 is minus 1 and we are going to use this expression again. The only thing is our y, y is minus 2. So, y is minus 2. So, let us make the substitution ok y is minus 2 B 2 is plus 1. So, minus 2 and this is minus 1 times what is the previous yeah ok. So, we are going to have 4 matrix I am sorry yes. So, we need 4 matrix I am sorry yeah. Now, because we have to check for 1 to minus 1 to minus 1 minus 1 to plus 1 and so on. So, let us now look at all the 4 cases B 1 B 2 ok plus 1 plus 1 plus 1 minus 1 minus 1 plus 1 minus 1 minus 1 and to recall our y 2 is minus 2. So, since our y 2 is minus 2 we have in this case B 2 is plus 1 minus 2 and over here the product is plus 1 1.5. Next B 1 is plus 1 B 2 is minus 1. So, let us put it here B 2 is minus 1. So, minus 1 times 2 is 2 plus and we have half times this product that is minus. So, 1 to minus 1 we have 1.5 next we will do this 1 minus 1 plus 1. So, B 2 is plus 1. So, you will get minus 2 over here plus half times the product minus half this gives me minus 2.5. Finally, minus 1 plus 1 for minus 1 plus 1 sorry minus 1 minus 1 rather I have minus n to minus is plus. So, 2 plus and minus 1 to minus 1 half 2.5. So, now these 4 metrics can be entered into the trellis 1 1 corresponds to minus 1.5 let us do that. So, I am going to write minus 1.5 over here let me write it more neatly. Similarly, 1 minus 1 corresponds to 1.5. So, 1 to minus 1 corresponds to 1.5. Next minus 1 to 1 corresponds to minus 2.5. Finally, minus 1 to minus 1 corresponds to 2.5 ok. Let us now pause for a minute these increments are additive that is what we proved in the previous lecture. Therefore, let us now observe that over here over here there are 2 paths combining plus 1 plus 1 plus 1 plus 1 minus 1 plus 1. So, plus 1 plus 1 plus 1 what is the metric 2.5 minus 1.5 which is 1 plus 1 minus 1 plus 1 what is the metric minus 2.5 minus 2.5 is minus 5. So, for plus 1 plus 1 plus 1 is both of these branches combined here you can make the decision that among these 2 only 1 of them is optimal that is this one not the other one because the metric for this is larger. But now there is a merging of 2 different trellis paths in minus 1 also. So, at minus 1 if you get plus 1 plus 1 minus 1 it is 2.5 plus 1.5 which is 4 from plus 1 minus 1 plus 1 to minus 2.5 plus 2.5 it is 0. Therefore, at here this is the optimal path, but you cannot make a decision among these 2 paths right away because further sequences also have a role why B 2 remember depends on S 3 as well that is B 2 has some part of its information going to the next symbol. So, you cannot make these decisions, but what you have already done is you have said of the 1, 2, 3, 4 trellis paths available only 2 are surviving in other words only these 2 are the likely sequence patterns that I am going to hold till time 2. Of course, later on you can if there they you know the if the metrics diverge significantly you can make decisions of course, but these are the 2 surviving paths. Let us just do one more step ok y 3 is 1.5 let me now do lambda k lambda k P 2 S 2 that is this metric indicates what we go to the next ok. Now, let us do the same thing I am just going to write my y my y is y 3 is minus y 3 is 1.5 I do not I have to check the sign 1.5 y 3 is 1.5. Now B 2 B 3 plus 1 plus 1 plus 1 minus 1 minus 1 plus 1 minus 1 minus 1 and just to remember our metric is B k y k plus half B k B k minus 1 ok our B k is this. So, this is going to give me 1.5 plus half which is 2 this is going to give me minus 1.5 minus half which is minus 2 this is going to give me 1.5 minus half which is 1 and this is going to give me minus 1.5 plus half which is minus 1. So, 1 to 1 is 2 let us write that 1 to 1 is 2 1 to minus 1 is minus 2 then minus 1 to 1 is 1 and minus 1 to minus 1 is minus 1. So, this is minus 1 this is plus 1. Now, let us compute the matrix for the others also let us compute the matrix. So, now over here there are 2 surviving paths. So, for the straight on path to go from plus 1 to plus 1 is actually going to be 2.5 to minus 1 2.5 minus 1.5 is 1 plus 2 is 3. Then if you now look at this particular path and if you now look at 2 if you ok let us look at this path and these this path merge over here. So, the straight on path has 2.5 minus 1.5 is 1 plus 2 is 3 then this particular path has 2.5 plus 1.5 which is 4 plus 1 is 5. Therefore, this is the only path that is going to survive and this path essentially goes away. But there is also one more possible path over here which you have to take into account 2.5 plus 1.5 minus 1 that gives you 3. These two paths are surviving because the other goes away. Why is this decision correct? The reason is because even if you keep going further and further the matrix at the points where the paths merge are not going to essentially change because as you make decisions in future you do not need to revisit these past matrix because the decisions about these symbols can be made based on the information that you have. So, therefore over here for example because both the optimal paths traverse this route you can safely say that the optimal decision for B2 is minus 1 and the optimal decision for B1 is 1. Even when the paths do not merge if at some points they merge you can make decisions if they do not start merging you can still stop at some point and try to make optimal decisions based on the branch matrix. This algorithm is the celebrated Witterbie algorithm which is used for maximum likelihood sequence estimation. It is also used in hidden Markov model based applications wherein you have these situations where a continuous stream of inputs is being made available to you and you are computing a probabilistic metric that allows you to optimize. So, in this manner you can actually revisit the derivation of this Witterbie algorithm you rather the branch matrix and then see how you can put these on a trellis and the trellis essentially allows you to make computations implementing these is very easy into to do in python. For example, you can just search on it you will find Witterbie algorithm implementations for python. This exact implementation we are not going to do in GNU radio directly because of the fact that implementing this in GNU radio is rather cumbersome and tedious. Instead one step that we are going to further make is to say that okay maximum likelihood sequence estimation is good but can I do something simpler? Okay if you want to do that then you have to make a realization. So, realization is that maximum likelihood sequence estimation is optimal whatever other method you want to use will be suboptimal. Now even though MLSD maximum sequence estimation can be done you still want to use some other methods it could be because even this complexity is too much for you to implement and you are okay with some other method where you just have to let's say deconvolve the channel or find out the symbols in some other way which could be suboptimal. So that is what we will be seeing in further lectures. So to summarize we have basically done the branch metric related computations and the MLSE is the optimal detection strategy in AWGN but if you recall a naive strategy that is trying out all possible combinations of symbols requires exponentially many computations. In the example that we discussed you required 4 power thousand computations for thousand QPSK symbols which was prohibitive. So by breaking the computation down we can exploit combinations and sequences that is if you get incremental metrics and then compute you can make decisions on the fly as you as and when you start observing some patterns that okay this is the optimal decision path that you have to take. Now the subsequent discussions are okay Viterbi algorithm is great but are there some simpler and easier to implement methods that we can use to make our decisions on symbols that is going to be our next task. So in summary while Viterbi algorithm is optimal there are suboptimal algorithms also which can come in handy and that is what we are going to see in the subsequent lectures. Thank you.