 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. This lecture will be a continuation of our delay estimation using GNU radio. In the previous lecture we essentially confirmed what we discussed in the lectures earlier that is the maximum likelihood estimate of delay under the presence of a single s of t can essentially be obtained by just maximizing the location or rather finding the location of the maximum peak when you perform match filtering. However in the presence of multiple symbols or multiple signals there is now a combination effect that you get. For example if you send a root trace cosine shape pulse then the same analysis that we did in class will not work and you have to make some adjustments. So using some simple template functions such as a ramp and some root trace cosine based examples we will see how we can measure the measure the delay and we will then link this to what we have seen in the previous class as well as the theoretical discussion that we had and these adjustments will allow you to make delay estimates in the presence of noise even for more complicated modulation systems. Let us now embark upon our second delay estimation related exercise. In this case we will be going with the same approach which we have been used to where we actually send an 8k kind of 8 kilo symbols per second data stream and then see what happens when you have delays. So let's first change this sampling rate to a convenient 192 triple zero then let us begin. We will first grab our random source so control F R N D O M will grab a random source random source we will change it to byte and we will make the maximum is 4. Next we will get the control F and we will get our constellation encoder. So constellation encoder of course the constellation encoder needs a constellation so we will do that momentarily control F for command F C O N S T so we will get this constellation object which by default has a nice QPSK constellation so we will say my const and that's fine and this will be my const M Y C O N S T. So we have our constellation ready let's add a throttle so control F for command F we'll say throttle next let us actually introduce over sampling but we will do that in a systematic way so let's actually define our parameters I like I mentioned we want 8000 samples per second so control F for command F let me say variable so I'll grab this variable I double click it I will call it S P S which is samples per symbol and since I want 8000 I'll say Sam rate double divide integer divide 8000 so this makes it 24 next I'm going to create a variable called my pulse because that I want the pulse which we used to be generic so we can keep swap keep swapping it control F for command F variable we already have a variable here double click it and I'm going to call it my pulse right so now we are going to create my pulse of course needs some value over here so let's actually do do one thing let's actually choose some pulse such as let's say we use an RRC pulse I'll call it RRC underscore tabs then let's actually create the RRC tabs so control F for command F we'll say RRC RRC filter tabs so I'm going to call this RRC tabs the gain I'm going to set the gain to actually root of SPS that is root 24 which is around 4.89 and the symbol rate is 8000 and my RRC tabs are ready I'm next going to add an interpolating FIR filter control F for command F interpolating FIR filter and the interpolating FIR filter essentially uses an interpolation of SPS that is sample symbol and uses my pulse as the pulse shaper and we are now set we can now view this in a GUI time seeing control F for command F we'll say time and to grab a QT GUI time sink and place it over here if you know execute this flow graph you can see that there is this moving thing but I want this to actually match I want it to be like a static image because I want this to match this thousand samples so what I'm going to do is I'm going to just set the number of points to something like 1000 times length of my let's do this times SPS and let's see whether I get a nice plot yes I get a nice static plot and these are the indeed the up sampled kind of symbols let's also set give a get the auto let's get a grid actually the grid is very useful now we want to now just do the decimating FIR filter of course after noise so let's actually do that let's actually add noise over here so control F for command F and say add and I'm going to double-click on this this is fine sorry what is a control F for command F and say noise and I get a noise source control F for command F I'm going to also get a range to set the noise way it's noise standard deviation so I'll call this N O N O I S E STD for noise standard deviation default value point zero one start at zero stop it let's say three step 0.01 that should be good enough so now I have the noise STD I will set the amplitude of my Gaussian noise to noise STD I'm adding them at the baseband I'm not doing the FC conversion here to avoid any you know too much of complexity so now I have this interpolating FIR filter followed by noise source now I'm going to add a delay in between here but let's add that later this should be followed by a decimating FIR filter and the decimating FIR filter should essentially take the reverse of my pulse and sample at the right location so let's actually just take a decimating FIR filter so control F for command F is a decimating FIR filter and for convenience you can use the arrow keys to rotate this in this way so now we have the decimating FIR filter and the decimation will be S B S tabs will be my pulse square bracket colon colon minus one to flip it okay so now I'm going to add a QT GUI time sink let's say I'm just going to do control C control V so I have this I'll use right arrow twice to rotate it connect it over here and I think the number of points here can just be a thousand which should be good enough let's execute this flow graph okay so now you have this oops you have this because it's slightly shaking because of the noise if you remove the noise there is no shaking okay and if you want to make sure that your constellation is right let's remove this and add a constellation sink control F for command F C O N S T and you'll grab a QT GUI constellation sink right arrow right arrow to rotate it connect it over here run your flow graph and you get this nice QPSK constellation points with a little bit of noise so there is no problem there's no delay related issues here now the question is when you have a delay what should you do now over here I have decimated it but what you should actually do is you should actually take a decimating F or a filter which does not do decimation and then find out where the take the absolute value and find out where the peak is if you recall from the slide you have to convolve with the matched filter and find the location of the peak of the magnitude so let us actually do that I'm gonna just to copy and control C and control V of this filter and going to remove the decimation so that I actually have the delay so now I'm and I'm going to add a compensated delay here let's do some let's make some changes okay let's do control F or command F let's say I grab a range and QT GUI range I'm going to add I'm going to actually add this and call it comp underscore delay this is the compensatory delay okay which I need to provide and this compensatory delay is what I'm going to this is basically to compensate for the delay which I encounter this is going to be a number between 0 and SPS and will be an integer so this compensatory delay is going to be here so I'm going to see control F or command F delay grab a delay block and connect it over here and call it comp actually I should be SPS minus comp delay so there is a reason why I'm actually doing this the reason is because when I measure the delay the delay is essentially going to be a number between 0 and SPS now to undo that delay I'm going to have to do negative of that since I cannot do negative delay I'm just going to go from the next symbol onwards and come back by that amount the second thing I'm going to do is I'm actually going to add a delay over here so let me just bring this down and let me rotate this by turning it right a little bit okay I'm now going to add a delay so control F for command F or let's just to control C control V over here get this delay rotate it to the left like this and this delay is going to be a random delay so I'm going to call this r a n d o m underscore delay which is fine and this random delay I'm going to make it a random number just take last time so control it for command F I'll say import I'm going to grab this import block and say import num pi as NP which is very convenient and now I'm going to add a control for command I'm going to say I'm going to add a variable and this variable is going to be random delay and I'm going to call it NP dot random dot rand int 0 SPS so I can it's enough to consider delays of up to SPS because SPS plus 1 is the same as 1 SPS the same as 0 delay because we are not going to consider one symbol of offset as any delay because we can always just get back the symbols by synchronizing properly so now I have a random delay which is included over here this one should be a random delay now if I double click this say okay you get random delays and this is matched to that I'm going to connect it over here I'm going to connect it over here and I'm also going to view the random delay by adding a GUI number sync so control F for command F QT GUI number sync and I'm going to create a constant source to connect this number sync so control F for command F C O N S T and this constant source is going to be a float double click a float which has the value random delay now we are going to connect this I think we are set let us just check what we are missing yeah filter so this this filter we have to just visualize it after taking the absolute value so let's just grab a control control F or command F let's say complex abs to complex to mag complex to mag square I think complex to mag is enough and we'll add a time sync control F for command F I will grab a time sync QT GUI time sync connect connect this over here and I think this can be let me just look at this I think this can be the same I just do thousand times SPS and check whether that works and let's execute this this should be a float now we are ready to execute this flow graph okay so let's now first check one thing they say that this delay is seven which means if I add a compensatory delay of 1 2 3 4 5 6 7 I get back my constellation point so this part is clear if there is a delay of 7 I'm going to delay my I'm going to advance by 7 I cannot advance by 7 so I'm advancing by SPS minus 7 so that's how this comp delay minus thing work if you don't believe me if you just reduce this you get a nice constellation now let us look at these this is the original waveform this is what you get by doing the abs okay you have these kinds of things now it is not it is instructive to look at these in the same and figure this figure them out first but I want to actually do something a little more simple before going to this so I'm going to increase the number of inputs in my time sink to three then I want to view the real and imaginary parts of the in of the received inputs directly here so for example if you look over here this is the delayed let's say this is the delayed output right so I want to split this into the real and imaginary parts and view them let's maybe put this in the third and then controller for command F complex to float and let's rotate this complex to float like so connect it over here connect the real part here imaginary part here okay so now if you visualize this right and let's also make one more change rather than use the RRC let's use something simpler I'm going to use something very simple I'm just going to use NP dot a range let's say SPS divided by SPS I'm going to use a ramp okay I'm just going to use the simple ramp and now if you execute the flow graph you get these nice peaks if you remember what we saw in the if you remember what we saw in the slides we are looking for these peaks and if you something like a ramp these peaks are very distinctive let's actually do one thing let's actually perform a calibration let us suppose that there is no delay so let's actually do one thing let's remove this random delay by just multiplying it by zero so there is no random delay let us now look for the peaks there is a peak at the beginning at zero and the next peak occurs at 0.1195 milliseconds then the next peak occurs at 0.2456 milliseconds and so on so this actually is very simple to understand if you remember we chose 8000 symbols per second as the transmission rate so the zero and this is point this must be close to 0.125 fact 0.125 occurs here the point it's actually because this and this are included and then this must be close to 0.24 0.25 that is because 0.125 milliseconds is the gap between two symbols therefore let us now just check this out so you have the first let's say first peak we will assume is over here and if you look carefully let's remove the noise as well and let's add a grid let's reset this the first peak is around 0.12 milliseconds now if we add a random delay let's add a random delay and execute it the first peak actually occurs let's say at 0.1471 let's say okay or you know let's we can take this one or this one I'm just going to take this one let's say this is at 0.156 and without the delay say that you know let's first do it without the delay once again so without the delay our peak occurs at around 0.12 milliseconds so and then with the with the delay so it will be 0.12 is our reference so with the delay we're going to check for our peak any peak is good enough because we can do a modulo let's choose this peak it's at 0.116 so let's now see what this peak means yeah so 0.16 minus 0.12 this is a millisecond so divide by thousand times 1920000 gives us about 7.68 that means it's about seven or eight samples of delay let's check it says data 0 is 8 which makes sense because if I now do press 8 here and set the 8 as the compensated delay I get my constellation back let's do this one more time if I execute the flow graph and go to the beginning let's look for my this peak over here this peak is 0.1562 562 6.95 so seven that means eight because it's seven from the beginning so eight samples so if I choose eight samples I get my constellation back close yeah it's seven okay seven or a big I think I might have just rounded it off incorrectly and the data this random is also seven let's try it one more time and I'll tell you carefully what I'm doing I'm again going to the very beginning and I'm finding this peak I'm you can choose this one I'm always choosing the second one this peak is let's do it very accurately close to a 0.151 0.151 milliseconds so that is 0.151 minus 0.12 upon a thousand it's a 5.952 that means the delay should be six if I set this to six I get my constellation so in this manner I can figure out the precise delay by just looking at the absolute value as was predicted in the slides that is if I take the absolute value and find the location of the peak I am able to identify the precise location of the delay and then I am able to compensate for the delay that is remember this is SPS minus compensated delay because I'm advancing it I cannot advance it so I'm essentially going one symbol ahead and a few samples back to align the constellation now let's go back to our RRC by just changing to RRC taps now with RRC taps things become a little tricky okay they become a little tricky because essentially your peaks are not looking alike now before we go further let us actually just ensure that we see the same delay over here so we remove this connection and connect this over here so that we essentially end up seeing the same delay we can actually rotate this in this manner and make this more neat so that we see the same signal so let me move things around to make some space for you so that the flow graph is clear yeah should be clearer now now if you execute this flow graph yeah you will see that things are much clearer now in this case also there are some peaks and you know you can actually try to figure it out so in a sense what is happening is that there are these peaks which are a little strange now to actually comprehend the delay from here if you remember what we did in class the peak detector like the absolute value maximization works for a single s of t but when you have a combination like this you have to be more careful so let's actually use a grid now this is a qpsk constellation that has some properties for example 1 plus 1j and so on but let me make a small change and move to a more simple qpsk constellation that is 1j minus 1 minus 1j this is a simpler qpsk constellation because if you execute it you will see that you know let me just you he says the delay is 10 so let me just says set the delay to 10 you will see that this constellation is more easy to reason out because in this constellation whenever the i part is plus 1 the j bar the q part is 0 when the i part is plus 0 minus 1 the j part is 0 whenever the j q part is plus 1 minus 1 the i part is 0 so then it's very easy to reason for example let's identify the location of the symbols here let's remove noise temporarily over here you can see that the red line which is the q is 0 so the i is minus 1 similar over here the i is 0 the q is minus 1 over here the q is 0 the i is plus 1 so this makes things easier to reason now in this situation what happens is that whenever the i or q is exactly 1 that means that the magnitude essentially has you know the magnitude essentially is exactly 1 when you're at any of these points the magnitude is exactly 1 so if you look at the zero crossings of this green line that is enough for you to figure out where the peaks are so let's use that approach now to figure things out so I'm going to execute this flow graph and I'm going to identify one of the zero crossings so let's say I identify I am going to add a grid and I'm going to remove noise temporarily so this looks like let's say this looks like a good place so the zero crossing occurs at around 0.204 milliseconds so that's our reference 204 milliseconds and now we should actually calibrate without any delay apologies so let's make sure that our random delay is removed so the random delay is this times zero if you execute our flow graph now let's calibrate our system yeah so now let's add a grid okay so now let's say that 0.12 milliseconds is where we get a zero crossing so 0.12 milliseconds is going to be our reference let us now add back the random delay 0.12 being our reference now let's check where the zero crossing is add a grid so 0.12 was our you know reference now we get this crossing the one exactly crossing the one happens around 0.12 which 0.12 yeah is over here let's let's let's repeat it again without let's just do it once more so let's not add the have a delay so there's no random delay now let's again do our calibration where is the first crossing of the one by the magnitude let's say we add the grid over here in fact let's add the grid in our sync anyway so we just double click this we just say grid yes we don't want autoscale because we'll zoom now we have the grid let's actually look at the crossing of the one so actually it crosses the one at the right at the beginning and then it crosses once again around let's let's get this accurately let's remove the noise around 0.125 milliseconds which makes complete sense because it's 8000 samples per second now let's add back the random delay with the random delay now let's see where it crosses one and again let's temporarily remove noise so that we get an accurate value so it's they say at 0.1826 1825 let's see what this translates to 0.1825 minus 0.125 milliseconds so convert it to seconds times 192 triple 0 about 11 samples is the prediction let's see what we get 11 so let's put 11 here I got my constellation back let's do it once again but this time let's do it blind let's not actually guess the delay so I'm going to do one thing I'm just going to right click this and say disable and right click this and say disable so that we don't see the actual delay okay so now let's execute the slow graph we can't see the delay here so it's our challenge we have to figure it out let's see the one crossing is at around let's say let's we can use this one we can use the any of the one crossings because if we can always take a modulo later so it's about 0.396 let's say 0.396 okay so 0.396 this is 52 and 52 modulo SPS so our SPS if you remember is 24 about four samples let's check 1 2 3 4 you understand why it was 4 because I just took modulo SPS because the number of symbols sorry the number of samples for each symbol is exactly 24 so if I get 52 I just keep subtracting 24 till I get a number less than 24 let's play the game one more time okay in this case I'm going to choose this point because it's very clear crossing of the peak crossing of one rather 0.3 triple 2 is what I get 0.3 triple 2 about 14 let's check with 14 and I got my constellation back so in this manner by appropriately observing the properties of the constellation you can get back the you can get back the exact delay and by the way this approach which we used was actually did not depend on the exact data we just use the properties of the constellation in summary we use an approach like this we'll correctly can enable this you can always just try to find the correct way to find the delay and calibrate your system of course more sophisticated methods are available but this gives you an example of how practically you can extract the delays for various kinds of modulations and pulses and these some of these ideas are what go into practical system implementations as well in this lecture we have seen a slightly more complicated example of delay estimation wherein unlike the previous case where we had a single s of t we have a sequence of modulated symbols that is summation b k g of t minus k t in this case also however a careful understanding of the structure of the waveforms allows you to find the delay accurately one point that you must note is that we did this visually in the presence of noise a visual inspection is insufficient so you would essentially build a system that takes into account the crossings of the ones in a more systematic manner and average to obtain a more accurate value of the delay and this is something that can be built quite easily as a system we will continue this discussion from the next class onwards with other aspects of receiver impairments such as you know frequency offsets and several others and put things together to come up with a practical receiver adjustment system thank you