 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 are going to study an initial example of how we can estimate the delay. If you recall in class the estimation of the delay of a signal S of t involved essentially maximizing the absolute value of the convolution of the received signal with the match filter. We will take a very simple template function or a set of simple template functions and then show that the peak indeed gives us a good estimate of the delay and we will confirm this by performing random delays as well and ensuring that we are able to estimate the delay correctly consistently with the maximum likelihood estimate based approach that we have seen in the class. Our next pursuit is delay estimation. In other words, maximum likelihood delay estimation. As we have covered in the lecture, in this case if you take an overlap with the S of t that is a template function but modify it to have different values of tau a and theta we can in effect just verify that the final solution boils down to maximizing the magnitude of y convolved with the match filter and finding out the location tau that maximizes this modulus. This is what we will start with in the beginning. Let us begin by constructing a very simple example. I have first set the sampling rate to one nine two triple zero. Now we will first create just a simple pulse and then see the impact of delay on this particular pulse. So let us begin. I am now going to first create a vector source. So I am going to do control f for command f type V E C T and grab the vector source and place it on my flow graph. Let us make the vector source have a particular filter. Let's say that let's say that we want the vector source to have about let's say two thousand or let's say a thousand samples. So let us actually create a variable that will hold our filter so I'll say my pulse and we want to make sure that the length is a thousand or let's say let's keep the length to a thousand. So we're going to say plus square bracket zero that is this is going to create a list containing zero and we want as many elements as needed to fill in the length to a thousand. So we'll say length of my pulse. Okay. Oh, we should say thousand minus length of my pulse. So the reason is because my pulse will essentially be the pulse S of T and we're going to now start searching for the delay in this particular example. So now my pulse is missing. So let us create a variable. So I'll say control f for command f say my pulse sorry way I'll say variable V A R I and double click will say that this is my pulse and for starters, let us just make this let's say a hundred ones so I'm just going to say one times 100. So we are just going to have 100 samples of one followed by 900 samples of zero. In fact, this is going to be this is going to be perfect because we can just now use this to perform our match filtering as well. Let's add our throttle but before that let's make this into a float because we don't need complex. Let's add a throttle control F D H R and grip the throttle, we grab the throttle and we connect it but of course we need to make the throttle into a float. Then remember this is the template pulse which is sent and at the receiver we are going to perform a convolution with the matched filter. The match filter is just my pulse reversed. So of course it's symmetric in this case but let me still just add it. So control f for command f I'll say inter or let's say decimating even though it doesn't matter decimating FIR filter will say float to float real taps and connect it and the taps must be my pulse and just in case I'm just going to put square bracket colon colon minus one to reverse it even though this my pulse is symmetric. If you change the program it will result in a pulse which is not symmetric. So I'm just swapping it around and finally I'm going to add a QT GUI time sink. So control F for command F would say time and grab this QT GUI time sink double click it make it float connect it. Now I'm just going to carefully choose the length of this number of points for this QT GUI time sink. Here we have a thousand and here we have my pulse which is of length 100. So this should ideally be about 1100 actually 1099 but I'm going to make this length 1100 so that I get a nice static kind of picture. Let me now run this flow graph it's it is moving a little probably because I did not get the length correct. So in this case it is 1000 followed by 100. So it's may let me check if it is 1099 works okay it's still moving okay let us just set it to 1000 that should essentially just take care of everything yes. So now if you execute this flow graph you will essentially see this particular shape and if you notice where the peak is the peak is going to be at 0.514 millisecond okay. Now what does 0.514 millisecond correspond to let's inspect I'm just going to open a python prompt just to do some calculations. So we said it's 0.515 0.515 milliseconds so upon a thousand times 192 triple 0 corresponds to about 99 samples and it's 99 samples from the beginning 0 which means it is the 100th sample which makes complete sense because the length of the filter is a 100. Now if I add any amount of delay then I will be able to figure out how much you know the shift of this peak will tell me how much the sampling point delay will be in other words I've not taken the absolute value here but because it's already positive but if I add a random delay in between this point like between this and the decimating FIR filter then the shift in the peak will tell me the exact sampling point just for fun let's do that I'm going to delete this I'm going to do control f for command f and say delay and let's just put the delay element here make it float and we'll make this delay something called r a n d o m random underscore delay it's a variable and we need to get that variable okay now this random delay let us do one thing let us actually generate it randomly so I'm just going to say control f for command f I'm going to say constant or let me say variable VRI and if I grab this variable and double-click it and I'm going to say this is random underscore delay and I can use numpy to get a random delay I will do in p dot random dot rand int and it's a 0 through 50 so it's going to give me a number between 0 and 49 of course I have to import numpy as NP so I say control f for command f and I'll grab the import block and say import numpy as NP now we are set now every time I generate this a new random delay or every time I run this a new random delay will appear if I run it again okay each time you run the flow graph you'll essentially get a new random delay for example you keep doing this you'll get a new random delay now let us actually figure out what the delay is okay let's figure out what the delay is by just looking at the pulse which we get okay so and I'm also going to do one thing to cross check our answer I'm going to add a way to view this delay so control f for command f and I will say QT GUI number sync so this number sync will display a number so my delay is between 0 and 100 so I can just call it let's say short and number of inputs one minimum is 0 maximum is 50 and let me add a constant source control f for command f c o n s the constant source constant source I think of type short yes and this constant store source will be the random delay if I now execute this flow graph you can see that the random delay is 17 here now let's verify what this random delay is as shown here okay the time over here at which the peak occurs is 0 point let's say 604 604 milliseconds 0.604 milliseconds so divide by 1000 to get seconds times 1 9 2 0 0 0 gives me 116 so that corresponds to about a 117 samples of delay now 117 samples of delay if you take modulo 50 that's exactly 17 which is what you get over here it's 17 samples of delay that makes complete sense let's do it one more time if I run it again I'm not going to look below I'm just going to look at this number at the peak so this is 0. I'm just going to say 0.6927 okay 0.6927 so 0.6927 by 1000 so this corresponds to 133 so 134 must be the number the modulo will give me 34 this is correct just something to keep in mind that you must actually before doing this take absolute value so I did not do that so let me just add an absolute value so controller for command f I'll say abs and I'm guessing that I can take float here and I'll connect this I'll connect this and now let me change my filter to something else let me change my filter to let's say instead of this I'll do np.a range let's say minus 50 through 50 it's like a ramp okay which goes minus 50 to 50 has the same 100 length so now let's check what this is yeah I can't add you know zeros that way an array so I let me just put list here so that becomes a list which is going to take care of things now if I execute this once again I get a very similar kind of pulse but I get to you know this kind of pattern because of the modulus operation because of the ramp now let's look at the peak over here peak is at let's say 0.6767 6767 let's see what 6767 means about 130 so 131 should be my answer and 131 modulo 50 is 31 so we got it so this method which is proposed in the slides which we saw does indeed work very well to find the delays but let us also see how this translates when we actually implemented in a practical scenario with all our you know interpolation and pulse shape which is closer to root rate cosine and so on. In this lecture using GNU radio we have essentially seen how we can simulate the effect of a delay and use the ML that is maximum likelihood delay estimation approach to characterize the delay appropriately. One limitation is that we used a single pulse which is consistent with what we did in class but a practical approach would require you to estimate the delay when you have a symbol a signal that is more complicated and has several data sequences as well. In the next lecture we will try to put together a simulation based on this and see how well that works and what adjustments have to be made in such a scenario thank you.