 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 the previous lecture, you have got a taste of some impairments and how they affect communications system performance. In this lecture, we are going to look at frequency offsets and a basic idea of how you can measure frequency offsets in GNU radio and some of the blocks in GNU radio particularly the phase block loop blocks that can be used to figure out the frequencies. Of course, the PLL block is useful because even in the presence of noise, it is able to detect the frequencies. That is something which we will see as we start with GNU radio. Before we actually get into the details of a PLL, let us actually just do a simple conceptual exercise. Let us actually mix two sinusoid of different frequencies and check what we get. So, I am just going to double click this SAMP rate and make it 1, 9, 2, 0, 0, 0. And first, let us just get a signal source, CTRL F for CMD F, we will get a signal source and we will make the signal source a cosine, we will keep the frequency at let us say 1,000, that is fine but we will make it a float. Next we will grab another signal source, we will just CTRL C and CTRL V, CTRL V rather and I will make this into a sine and let us say that you know let us make this plus delta F and if you do plus delta F, then we will just have a range for this delta F, so CTRL F for CMD F, we will say range and we will double click this range, we will call this delta F and we will make this go from 0 to let us say we will make it go from minus 10 to 10 hertz, step 0.1 and just to make it more visually pleasing, let us make it 10,000, we will also make this 10,000 and we are now going to mix these, so let us first get a throttle, CTRL F for CMD F, we will get a throttle, we will make the throttle a float and we will connect this and we will then do a mixing which is multiplication CTRL F for CMD F, we will get a multiply block and the multiply block is going to be connected over here, connected over here and now let us visualize what we get if we have a delta F, so CTRL F for CMD F and of course we need to also do a low pass filtering to remove the 2fc component, so I will just get a low pass filter, CTRL F for CMD F, we will say low pass filter, we will make the low pass filter have real coefficients and have cutoff at exactly 10,000 hertz, transition width of 1000 should do and then let us visualize what we get CTRL F for CMD F and I will grab a time sync and we will view what we get in this time sync. So now you can see that if there is no frequency offset, you end up getting something like 0 because cos into sin and you know there is not nothing much to check but if we have a delta F you can see that there is a movement, in fact let us make this delta F something significant, you can see that it is moving up and down to actually visualize this better, let us actually increase the number of points here by 10 fold and now if you have a frequency offset, you can sort of see that you can get this cycle and by measuring the frequency of this sinusoid, you will be able to get the frequency offset, let us increase this by one more amount and then let us just check, let us set it to 10 hertz, let us actually do one thing, let us actually also view this in the frequency domain, so I will just set CTRL F for CMD F, I will add a frequency sync, we will increase the number of points for the frequency sync also, we will make it 32768 and let us see what we get, initially you get, essentially you get zero and these are, these can be ignored for the moment, if you increase this to 10 hertz then if you zoom in over here, you will see that you are getting a peak at 10 hertz, that is exactly corresponding to these, so it is 396496 you know and so on, so that is exactly 10 hertz, so the key idea is that this kind of approach to measure the frequency difference by mixing can allow you to construct a filter where you can start adjusting the frequency of this sign so that you match it along with the phase, now this has been implemented in a, this has been implemented in the PLL blocks in Blue Radio, so CTRL F for CMD F and say PLL, you have this PLL carrier tracking frequency detector and regeneration, in fact we will be looking at the PLL frequency detector that actually has a more sophisticated version of this and using it to generate a carrier at the receiver in the presence of noise as well, let us first begin by adding a few variables and making some simple changes, first we will make the sample rate a little more convenient, we will set this to 19200, then we will choose our FC as 40 kHz and we will just track nominal changes, so CTRL F for CMD F and say variable and grab a variable over here and double click this variable and we will call it FC and set it to 40,000, we will also add a range to add a frequency offset and ensure that we are able to track it, so CTRL F for CMD F, we will say range QTGY range, we will call this range Delta F, Delta underscore F and let's say that it's default zero, let it go from minus 100 to 100 hertz and let's say step by 0.1, now we are ready, let us create a signal source, a complex signal source CTRL F for CMD F, we'll type signal, we have a signal source over here, we will double click it and we can set the frequency to FC plus Delta F, amplitude is 1, we will not have any phase currently, we will add a throttle, CTRL F for CMD F and we will say throttle, we will add noise to this, let's first create a range for noise standard deviation, CTRL F for CMD F, say range, double click it and call it noise SDD and at the baseband, complex baseband, we will now add this noise, CTRL F for CMD F, we will say noise, CTRL F add and we will add this noise but we should change the amplitude to noise SDD, noise SDD should be a number which goes from 0 through 3 and let's say step 0.1, now the next thing that we need is actually a, we will use a PLL frequency detector, so CTRL F for CMD F, PLL, we'll say PLL frequency detector, of course we can also track it with the phase but we're just going to use a frequency detector to begin with, now a PLL frequency detector takes the input with three parameters and gives a float output, the float output is essentially corresponds to the frequency, let's set these values, the loop bandwidth is the loop filter bandwidth, we will set it to 6.28 upon 100 that is they recommended that a value between you know 0 and 2 pi by 100, the minimum phase per sample corresponds to the minimum frequency that you want to detect, since we are expecting about minus 100 to 100 hertz of frequency shifts, let's actually just write that carefully, so it's 2 pi times, so I write 6.28 times FC minus 100 divided by sampling rate, similarly the maximum we expect is a 100 hertz deviation 6.28 times FC plus 100 divided by sampling rate, now this essentially is going to give us our frequency detector, to verify that things are working, let us just add a QT GUI time sink, so I'll say CTRL F, I'll say QT GUI time sink and we'll add a real value time sink and we'll call this frequency detector, okay, so now let's just see what the output is in this case, if I execute this flow graph, so I have an output which is close to 0.86, now if I move this delta F, you will see that it varies ever so slightly, let's zoom in over here, by moving this you can see that this is essentially moving up and down, so what is essentially happening is this, the PLL is actually getting an estimate of this particular frequency and after estimating this frequency it is translating it into an amplitude or a voltage value, so as you can see this amplitude now can be used to generate a frequency, let's actually do that, so CTRL F for CMD F, we will say VCO stands for voltage control oscillator, we'll get a complex voltage control oscillator, we will specify the sampling rate, a SAM rate, now the sensitivity is basically going to convert the, it's a constant which takes care of converting the voltage to a frequency, so in this case the values are between 1.30 to 1.31 and we know that the midpoint that is something like 1.308 is going to correspond to 40 kHz, so let's actually try this, so I'm just going to say 2 pi times, we'll just do this calculation carefully, so 506, 116, so it's about 1.308, so then if we connect this over here, rather than inspect the frequency which we get, the CTRL F for CMD F and we'll say FREQ, we'll grab a QT GUI frequency sync, let's add two inputs and connect the generated frequency with this, now this sensitivity should actually correspond to, actually this is a slight change, this sensitivity should correspond to 40,000 Hz, so we'll say this is actually 6.28 times 40,000 divided by 1.30833, let's verify what we get, amplitude should be 1 and if we now execute this flow graph, you get a frequency close to 40 kHz and we see that these two essentially are matching because if you remove this you get the same, now if you increase or decrease this delta F, you will see that the change is essentially getting reflected, now in the presence of noise, you will see that this particular frequency which is the original one is a very good carrier but there is the noise is essentially affecting the generated carrier also, the reason is because your frequency measurement in this frequency detector has very very slight issues, one approach to handle it is to just smoothen this out with a low pass filter, for example, I'm just going to say CTRL F for CMD F, say low pass filter and we can actually either do this or we can actually just do something simpler with averaging, let's just remove this, let's actually just do some simpler approach with averaging, so CTRL F for CMD F and say interpolating, we'll grab an interpolating FIR filter and let's make it float to float and interpolation can be 1, the taps we want to just average, so we'll just make it, let's say 1 times, let's say 0.1 times 10, this will give you a 10-fold averaging, it's just going to average, just a moving average of the last 10 samples and if we now connect the VCO through this filter, then you will see that even the presence of noise, it's going to be much more stable, so if you can make this even more, let's say let's make it 0.01 to 100, you'll find that it's even more sharp, okay, so by averaging, you're able to get the frequency back and let us actually view the frequencies, the sinusoid that are generated, so I'm just going to remove this, I'm going to remove this time sink and CTRL F for CMD F, add a time sink, this time sink we will add two inputs and the two inputs are the original and the generated one, and if you observe them, you will see that, let's observe only the real parts, you can see that they both have very, very similar frequencies, the very slight offset, okay, the offsets are of course, because of the fact that we have very minor, you know, differences in terms of the floating point and everything, the frequency domain you can see, but these kinds of offsets can easily be handled, so you can see that the PLL is tracking the frequency offsets very, very closely and this works even in the presence of noise, you can see that even if I increase noise, you're able to roughly see the tracking giving the same frequency, now if you add the PLL with the feedback and account for the phase offset also, the lock will be very, very good and you will not suffer from this issue, so in this way, a PLL can be used in order to track the frequency, of course we did not consider the case where there is a modulation on top of this carrier, that is something which you can learn from the references, but the concept is very, very similar. So in this lecture, you got a taste of how phase lock loops work in GNU radio, in particular, while it may be confusing to see how you are able to just get the frequency from, you know, you are able to get the frequency just from a pure carrier, the key idea is that even in the presence of noise, the phase lock loop essentially does a good job and in fact with a bit of filtering, the phase lock loop is able to track the frequency offsets as well. In the subsequent lecture, we are going to look at some other approaches where if we don't want to track the phase and frequency, how you can get away without having to use a phase lock loop. Thank you.