1 00:00:00,000 --> 00:00:04,980 Thanks for coming. I really apologize for the mix-up that I had earlier. 2 00:00:05,360 --> 00:00:10,040 So today I'm going to talk about digital signal processing for software-defined radio. 3 00:00:10,920 --> 00:00:13,840 I also like to call it software-defined radio in a nutshell. 4 00:00:14,240 --> 00:00:20,380 And so the reason that I wanted to do this talk is that a lot of you have probably messed around with software-defined radios, 5 00:00:20,480 --> 00:00:24,620 and so this talk isn't an introduction to software-defined radios. 6 00:00:24,620 --> 00:00:33,900 But a lot of people really don't know how they work and sort of the theory behind how data gets modulated and sent over the air. 7 00:00:34,380 --> 00:00:41,480 And so I think there's sort of a lot of what I'll call script kitties of software-defined radio these days. 8 00:00:41,680 --> 00:00:48,940 And so in my own work trying to figure this out on my own, 9 00:00:48,980 --> 00:00:54,600 I've learned a few key concepts that I want to talk about. 10 00:00:54,620 --> 00:01:02,940 One of the key concepts that I want to talk about today, and it sort of covers the essential tools for building your own software-defined radio applications. 11 00:01:03,660 --> 00:01:09,180 It's not going to go deep into the theory or the math or exactly how it works, 12 00:01:09,280 --> 00:01:13,700 but this talk is intended to give you an idea of 13 00:01:13,700 --> 00:01:18,620 what you don't know and what you should go out and learn more about on your own. 14 00:01:19,860 --> 00:01:24,240 So first a very quick introduction to how radios work. 15 00:01:24,620 --> 00:01:33,740 And how, and this would be useful for later explaining how this gets translated into the digital domain. 16 00:01:35,220 --> 00:01:38,600 So as you all probably know, atoms are made of protons and electrons. 17 00:01:38,700 --> 00:01:42,080 These exert a force on each other. 18 00:01:42,180 --> 00:01:49,660 So unlike particles attract, like particles repel, you should all basically know that. 19 00:01:49,760 --> 00:01:53,900 And you can define a relative force. 20 00:01:54,620 --> 00:02:13,540 That is created by one of these particles by imagining a theoretical test charge and moving it around sort of around this electron here and then measuring the force that is exerted on that test charge. 21 00:02:13,760 --> 00:02:24,200 And so then you can express this electric field as a field basically on the force per unit charge of this test charge. 22 00:02:26,780 --> 00:02:36,420 And so if you move this test charge away from this electron, sort of further out, there's less force exerted on it, 23 00:02:36,480 --> 00:02:40,460 but that also means that you have to do some work to move it over here. 24 00:02:40,660 --> 00:02:45,760 And so this difference is called the potential difference or voltage. 25 00:02:45,960 --> 00:02:51,440 And this is what radios measure and use to communicate. 26 00:02:52,540 --> 00:02:54,360 So the way that, 27 00:02:54,620 --> 00:03:01,260 they do that is, so for example, you might have a dipole antenna, and it might induce a voltage 28 00:03:01,260 --> 00:03:09,820 on the dipole antenna. So you have, you sort of push some electrons to one side. And so on the 29 00:03:09,820 --> 00:03:15,880 other side, there's effectively positive charge, you can think of it as charged particles, but 30 00:03:15,880 --> 00:03:23,700 basically, it's an absence of electrons. And so to actually transmit this information, 31 00:03:23,700 --> 00:03:33,240 what a radio will do is alternate the polarity here, and create these reversing electric fields, 32 00:03:33,380 --> 00:03:40,360 which then propagate through space. And then when they hit another antenna, they will also 33 00:03:40,360 --> 00:03:46,460 induce a voltage on the receiving antenna. And you can measure that as a voltage and 34 00:03:46,460 --> 00:03:51,180 recover information that way. So this is all fine and dandy. But 35 00:03:52,240 --> 00:03:53,600 then the problem comes, 36 00:03:53,700 --> 00:03:59,220 well, how do you separate all these transmitters and receivers from each other? I mean, you can't 37 00:03:59,220 --> 00:04:10,300 just, you know, do this and expect everything to work, you need to allow multiple users of the 38 00:04:10,300 --> 00:04:17,320 airwaves. And so the way that they do that is, let's see here, through different frequencies. 39 00:04:19,160 --> 00:04:21,380 And so the way that 40 00:04:24,260 --> 00:04:25,460 you do that is, let's see here, through different frequencies. And so the way that you do that is, 41 00:04:25,460 --> 00:04:32,300 you have these carrier frequencies, which is sort of how, how much you you reverse the voltage 42 00:04:32,300 --> 00:04:38,420 going into the antenna. And then you modulate that with different types of modulation. So 43 00:04:39,400 --> 00:04:45,200 some of the very simplest types of modulation, for example, is amplitude modulation, 44 00:04:45,500 --> 00:04:53,260 where you have a constant frequency of moving electrons back and forth. But what you do is you 45 00:04:53,700 --> 00:04:58,140 the amplitude of how much power is going back and forth. And then there's frequency modulation, 46 00:04:59,240 --> 00:05:04,140 where you actually change the frequency at which you move the electrons around. 47 00:05:05,360 --> 00:05:08,480 And so if you've been playing around with software-defined radios, 48 00:05:09,320 --> 00:05:15,600 you can actually visualize this. So this is a spectrum display here, and you can actually see 49 00:05:16,220 --> 00:05:23,160 here's a commercial FM radio station, and you can sort of see the frequencies of the carrier 50 00:05:23,160 --> 00:05:32,920 going back and forth here. And the takeaway from this slide is that different transmitters get 51 00:05:32,920 --> 00:05:38,620 allocated sort of different frequencies, and so you can see them across the spectrum. 52 00:05:39,200 --> 00:05:42,860 And this applies widely. 53 00:05:46,280 --> 00:05:53,080 And so if you wanted to actually recover this signal digitally, one thing that you 54 00:05:53,080 --> 00:05:59,200 could think about doing is just taking your antenna, stuffing it into an analog-to-digital 55 00:05:59,200 --> 00:06:05,720 converter, and getting out that voltage, and then doing some magic that I'll talk about later, 56 00:06:05,820 --> 00:06:11,380 and recovering your signal that you wanted to transmit. Now, unfortunately, 57 00:06:13,340 --> 00:06:18,940 since you're transmitting stuff on these carrier waves that can go up into the gigahertz range, 58 00:06:19,120 --> 00:06:22,920 you would have to have an analog-to-digital converter, 59 00:06:23,080 --> 00:06:31,000 that samples extremely fast to recover enough of that wave to recover the signal. So instead, 60 00:06:33,140 --> 00:06:40,380 yeah, this is what I just said. So basically, there's something called the Nyquist rate. So 61 00:06:41,240 --> 00:06:49,860 if you have an incoming signal that is, say, this red signal here, but you're only sampling 62 00:06:49,860 --> 00:06:53,060 it at these black points, then the only way you can recover that signal is by sampling it at the 63 00:06:53,060 --> 00:07:00,320 only thing that you can recover is an alias at a lower frequency. And so one of the challenges 64 00:07:00,320 --> 00:07:08,480 in software-defined radios is, well, software-defined radios is actually dealing with 65 00:07:08,480 --> 00:07:13,980 this bandwidth limitation of analog to digital converters and conversely to transmit digital 66 00:07:13,980 --> 00:07:21,440 to analog converters. So the way that they actually do this is software-defined radios 67 00:07:21,440 --> 00:07:31,700 shift frequencies down to or up from zero hertz, sometimes known as a baseband. And the math behind 68 00:07:31,700 --> 00:07:38,900 it sort of exploits this trig identity where if you multiply two sine waves of two different 69 00:07:38,900 --> 00:07:49,340 frequencies, what you get are two different, a sum of two different frequencies and two different 70 00:07:49,340 --> 00:07:49,740 waves. 71 00:07:49,740 --> 00:07:55,120 And the frequencies of those two waves are both the sum of the frequencies and the difference of the 72 00:07:55,120 --> 00:08:04,280 frequencies. And so what you can do if you, say, want to tune into 89.5, what you can do is have a 73 00:08:04,280 --> 00:08:14,100 local oscillator run at 89.5 and then shift. If you get, if you receive something at 89.5, then 74 00:08:14,100 --> 00:08:19,640 the difference goes down to zero. There will also be something at twice 89.5, and you 75 00:08:19,640 --> 00:08:27,540 just filter that out before it goes to the analog to digital converter. And this is sort of how it 76 00:08:27,540 --> 00:08:36,380 looks like as a block diagram there. As I said, you know, you usually use the difference and filter 77 00:08:36,380 --> 00:08:46,500 out the sum. So there's one more trick that's commonly used in software-defined radios, and that 78 00:08:46,500 --> 00:08:49,260 is to use complex signals. 79 00:08:49,640 --> 00:08:58,760 And so what that basically means is you have both an in-phase wave and an out-of-phase, a 90 degrees 80 00:08:58,760 --> 00:09:09,200 out-of-phase carrier, local oscillator signal. And you actually have two different signal paths here, and 81 00:09:09,200 --> 00:09:18,600 you use them independently. And what this gets you is the ability to represent negative frequencies. So, 82 00:09:18,700 --> 00:09:19,200 for example, 83 00:09:19,200 --> 00:09:19,500 you 84 00:09:19,500 --> 00:09:31,180 can think of a oscillator as going around this unit circle at a particular speed, and that encodes the 85 00:09:31,180 --> 00:09:39,260 frequency. And if you look at the Y component, you would get, say, a sine wave. If you look at the X 86 00:09:39,260 --> 00:09:49,220 component, then you get a cosine wave. And so with this, you can not only represent the rotational speed or the 87 00:09:49,220 --> 00:09:56,860 frequency, but also which way it's going. And this is how you can represent negative frequencies. And this is also why 88 00:09:59,560 --> 00:10:12,180 you will also see a lot of I's and Q's in software-defined radios. So I stands for in-phase, Q stands for quadrature. So crimes, 89 00:10:12,180 --> 00:10:19,740 90 degrees out of phase. All right, so now that we have a signal that we're receiving, 90 00:10:21,100 --> 00:10:28,320 how do we actually get data out of it? So say that we want to monitor some unknown data source 91 00:10:28,320 --> 00:10:36,020 or unknown modem, and we want to start demodulating it. So the typical steps for 92 00:10:37,100 --> 00:10:43,700 demodulation are first frequency shifting. So usually what you'll do in a software-defined 93 00:10:43,700 --> 00:10:49,020 radio is the hardware will shift it down to some intermediate frequency, which is 94 00:10:49,560 --> 00:10:55,920 maybe not zero. It could be zero. But then you actually want to bring it all the way down to 95 00:10:55,920 --> 00:11:04,300 zero. And part of the reason you might do that in software is because the local oscillator of 96 00:11:04,300 --> 00:11:06,000 your radio might not match the frequency of your radio. So you might want to bring it down to 97 00:11:06,020 --> 00:11:09,940 zero to match the oscillator of the remote radio. And you have to do carrier tracking to make sure 98 00:11:09,940 --> 00:11:20,700 everything demodulates correctly. You need to filter out any signals that aren't of interest 99 00:11:20,700 --> 00:11:28,740 after you do the frequency shifting. Filtering is also used to avoid inter-symbol interference, 100 00:11:29,120 --> 00:11:35,840 which I'll talk about later. Once you do filtering, you have to synchronize both 101 00:11:35,840 --> 00:11:36,000 audio and video. So you have to synchronize both audio and video. So you have to synchronize 102 00:11:36,020 --> 00:11:45,980 onto the carrier frequency of the remote radio as well as the bit clock of the sender so that 103 00:11:45,980 --> 00:11:56,700 you know when to sample the Cygnal. From there, it gets a bit easier. You will sample the 104 00:11:56,700 --> 00:12:05,940 incoming signal at a fixed rate. And then you can recover cymbals from that which are bits. 105 00:12:06,020 --> 00:12:11,140 So the difference between a bit and a symbol, so a bit is just a 0 and a 1, a symbol can be 106 00:12:11,920 --> 00:12:14,040 multiple level. So you can have like 107 00:12:16,140 --> 00:12:19,120 So there's like QAM, so you can have like a 108 00:12:20,940 --> 00:12:26,920 16 or 32 or 256 different symbols which can encode many different 109 00:12:27,440 --> 00:12:32,660 bits in a single sort of constellation point, and I'll talk about that very shortly. 110 00:12:32,660 --> 00:12:37,360 Then once you get out the bit stream, then there are some extra things 111 00:12:37,360 --> 00:12:45,260 that are all in the digital domain, and I think I won't talk about much about those because 112 00:12:46,480 --> 00:12:51,860 I think working with bits is more familiar to people. But there, 113 00:12:52,600 --> 00:12:55,020 I'll briefly touch on those later. 114 00:12:56,640 --> 00:13:00,800 All right, so now I'm going to get into some of the nitty-gritty details of 115 00:13:01,740 --> 00:13:02,380 how 116 00:13:02,660 --> 00:13:04,160 digital signal processing 117 00:13:05,120 --> 00:13:09,600 works, how some of the common tools you use in digital signal processing. 118 00:13:10,100 --> 00:13:16,600 And so the first one that I want to talk about is filtering, and filtering is one of the most fundamental tools of digital signal processing. 119 00:13:17,500 --> 00:13:21,420 So what this does is it takes in a signal and 120 00:13:23,240 --> 00:13:28,160 you can imagine it as like sort of a graphical equalizer. It can 121 00:13:28,740 --> 00:13:30,960 boost frequencies, it can drop frequencies, 122 00:13:30,960 --> 00:13:35,340 so you have filters like a low-pass filter, a high-pass filter. 123 00:13:36,020 --> 00:13:44,240 So these are graphs in the frequency domain, so you have a frequency going across the x-axis here and the 124 00:13:44,240 --> 00:13:46,080 amplitude or the attenuation 125 00:13:46,980 --> 00:13:50,580 is in the y-direction here. And so you can, 126 00:13:50,740 --> 00:13:59,600 for example, a low-pass filter will allow all low frequencies through, but then after a certain cutoff point, which is usually 127 00:13:59,600 --> 00:14:01,780 at negative 3 dB, 128 00:14:02,580 --> 00:14:06,860 is the cutoff frequency, then it just sort of goes downhill from there. 129 00:14:07,660 --> 00:14:10,220 And so if you build these in 130 00:14:11,380 --> 00:14:16,160 hardware, it's very hard to get a very sharp cutoff. 131 00:14:17,640 --> 00:14:19,720 It's a bit easier to do digitally, 132 00:14:19,840 --> 00:14:24,220 but it's a trade-off between how sharp you want your filter and how much computation you want to do. 133 00:14:24,940 --> 00:14:26,580 And then there's other types of 134 00:14:27,400 --> 00:14:29,580 simple frequency filters, such as the 135 00:14:29,580 --> 00:14:35,780 bandpass filter, which only allows certain frequencies through, and a notch filter, which cuts out some frequencies. 136 00:14:38,960 --> 00:14:44,540 So one way you can describe filters is by what's known as their impulse response. 137 00:14:45,120 --> 00:14:49,240 And so the way to think of that is, if you have a 138 00:14:49,240 --> 00:14:55,660 signal like this in the time domain, which is all zero except for a single blip at one point to 139 00:14:56,660 --> 00:14:59,060 one, and you send it through this filter, 140 00:14:59,060 --> 00:15:04,360 you look at the signal that comes out of that filter. So for example, if you 141 00:15:04,960 --> 00:15:10,260 send this through a low-pass filter here, you might get this response out of the filter. 142 00:15:11,320 --> 00:15:14,720 And so, this is actually how you build 143 00:15:15,360 --> 00:15:18,400 what are known as finite impulse response filters. 144 00:15:19,120 --> 00:15:24,020 And so the way that those work is you take this impulse response that you want 145 00:15:24,700 --> 00:15:27,160 for your filter function, and 146 00:15:27,160 --> 00:15:29,040 you put it in what's known as the 147 00:15:29,060 --> 00:15:30,640 as a filter kernel here. 148 00:15:30,800 --> 00:15:34,700 So just imagine that those points that were here 149 00:15:34,700 --> 00:15:36,240 are now in here. 150 00:15:37,060 --> 00:15:40,540 And when you push samples into this buffer, 151 00:15:41,240 --> 00:15:47,220 what you do is you multiply component-wise 152 00:15:47,220 --> 00:15:51,720 the incoming samples with their corresponding positions 153 00:15:51,720 --> 00:15:54,460 in the filter kernel, and then sum them all up 154 00:15:54,460 --> 00:15:57,780 and spit them out as the output signal. 155 00:15:57,780 --> 00:15:59,680 So this is known as convolution. 156 00:16:00,540 --> 00:16:03,560 This is how finite impulse response filters work, 157 00:16:03,680 --> 00:16:04,620 or fur filters. 158 00:16:04,780 --> 00:16:07,860 If you see things about fur filters in GNU Radio, for example, 159 00:16:08,060 --> 00:16:10,060 this is exactly what they're talking about. 160 00:16:11,260 --> 00:16:12,760 These are called taps. 161 00:16:12,960 --> 00:16:16,640 So if you see something that refers to the number of taps, 162 00:16:18,280 --> 00:16:20,340 this is exactly what they're talking about. 163 00:16:20,520 --> 00:16:22,660 And so as you can see, the more taps you have, 164 00:16:22,760 --> 00:16:24,860 the more computation you have to do, 165 00:16:24,900 --> 00:16:26,480 and so the slower it is. 166 00:16:28,980 --> 00:16:31,920 So this is a fur filter with five taps. 167 00:16:34,720 --> 00:16:39,400 So another way that you can determine the filter taps is 168 00:16:40,660 --> 00:16:44,620 so you can take the frequency response that you want, 169 00:16:44,660 --> 00:16:48,580 say, on those graphs from the filtering slide 170 00:16:48,580 --> 00:16:52,200 and use what's known as the inverse Fourier transform. 171 00:16:52,700 --> 00:16:57,760 And so what a Fourier transform does is it converts signals, 172 00:16:57,780 --> 00:17:03,160 signals between the time domain or sort of the received signal that you get 173 00:17:03,160 --> 00:17:04,820 and the frequency domain. 174 00:17:05,420 --> 00:17:09,760 And so to make that a bit more concrete, 175 00:17:09,900 --> 00:17:14,820 so if you have like an oscilloscope and you see like a wave going up and down there, 176 00:17:14,900 --> 00:17:17,940 that's sort of representation in the time domain. 177 00:17:18,080 --> 00:17:22,360 So you have time across the bottom and amplitude up the y-axis, 178 00:17:22,500 --> 00:17:23,840 whereas in the frequency domain, 179 00:17:24,040 --> 00:17:27,760 you would see sort of a peak right at where the frequency is. 180 00:17:27,780 --> 00:17:32,980 And so Fourier transforms are used to go between the time domain 181 00:17:32,980 --> 00:17:34,040 and the frequency domain. 182 00:17:36,260 --> 00:17:36,840 All right. 183 00:17:36,860 --> 00:17:42,960 So at this point, we have some in-phase and quadrature samples 184 00:17:44,540 --> 00:17:47,120 at approximately zero hertz. 185 00:17:47,820 --> 00:17:55,480 And what's interesting about IQ samples is that every modulation scheme can be described just 186 00:17:55,480 --> 00:17:57,760 by the amplitude of these i's and q's. 187 00:17:57,780 --> 00:17:58,600 And so in this case, we're going to use the i and q symbol, 188 00:18:00,520 --> 00:18:01,260 the i and q symbol. 189 00:18:01,260 --> 00:18:01,660 And we're going to use the i and q symbol to represent the i and q signals or signals. 190 00:18:02,120 --> 00:18:10,660 And the way that you can do that is represent these i and q points on a graph, 191 00:18:10,860 --> 00:18:14,740 a two-dimensional graph, i on one axis, q on another axis, 192 00:18:14,940 --> 00:18:17,400 in what's known as a constellation diagram. 193 00:18:18,900 --> 00:18:26,340 So for example, in a very simple case where you have say, let's see, 194 00:18:26,460 --> 00:18:27,760 like 180 degrees. 195 00:18:27,760 --> 00:18:33,500 degree phase reversal for transmitting different bits. You don't care about the 196 00:18:33,500 --> 00:18:37,400 the quadrature stuff. You're only looking at the amplitude of the in-phase 197 00:18:37,400 --> 00:18:44,600 signal. And so it's either, you know, it's either a regular amplitude or it's an 198 00:18:44,600 --> 00:18:52,180 inverted signal. Now if you want to get a bit crazier, you can start putting these 199 00:18:52,180 --> 00:18:59,000 different points anywhere in this constellation diagram here. So for 200 00:18:59,000 --> 00:19:07,160 example, you can encode two bits at a time by having different amplitudes of 201 00:19:07,160 --> 00:19:13,480 both the the INQ symbols. And you can get as arbitrarily complex as you want. So 202 00:19:13,480 --> 00:19:19,280 this is like 16 QAM, which stands for quadrature amplitude 203 00:19:19,280 --> 00:19:21,960 modulation. So you basically 204 00:19:21,960 --> 00:19:22,160 . . . 205 00:19:22,160 --> 00:19:27,760 amplitude modulating both the I's and the Q's, and you can represent four 206 00:19:27,760 --> 00:19:34,820 bits per point there. Now the issue is that when you send these over the air 207 00:19:36,460 --> 00:19:41,560 there will be interference. The components won't be perfect. There will 208 00:19:41,560 --> 00:19:47,380 be some noise introduced in the system, and so what you get is, say, for bits 209 00:19:47,380 --> 00:19:52,040 or symbols that you send with that constellation diagram, you might receive 210 00:19:52,040 --> 00:19:59,100 something like that. And as long as there's enough separation between them, 211 00:19:59,180 --> 00:20:04,440 then you can recover those symbols and you can add some error correction later 212 00:20:04,440 --> 00:20:10,020 once you get a bit stream to make it even more robust. All right, so in 213 00:20:10,020 --> 00:20:16,620 principle all you need to do to transmit a digital signal is just have a 214 00:20:16,620 --> 00:20:17,360 use case. 215 00:20:17,360 --> 00:20:23,200 an in-phase and quadrature phase signal being transmitted at a particular frequency for a 216 00:20:23,200 --> 00:20:29,960 certain amount of time, and then immediately jump to a different set of amplitudes for your INQ 217 00:20:29,960 --> 00:20:36,780 signals. And then you just keep hopping it around at the data rate that you want. Now, unfortunately, 218 00:20:36,780 --> 00:20:47,540 this takes an infinite amount of bandwidth. And as I discussed earlier, you want to use only a 219 00:20:47,540 --> 00:20:55,280 finite part of the RF spectrum for your own signal to share it with others. And so the reason why 220 00:20:55,280 --> 00:21:02,900 this takes infinite bandwidth goes back to a little bit of math where square waves are just 221 00:21:02,900 --> 00:21:06,320 some of odd harmonics. 222 00:21:06,780 --> 00:21:17,180 So, if you have this square wave at some frequency, that is effectively the sum of the sine wave at 223 00:21:17,180 --> 00:21:24,040 that frequency plus a sine wave at three times that frequency, five times that frequency, and it 224 00:21:24,040 --> 00:21:29,840 just keeps going off to infinity. And so if you keep summing them up together, you get closer and 225 00:21:29,840 --> 00:21:35,520 closer to a square wave. And so what you're effectively doing by transmitting different 226 00:21:35,520 --> 00:21:36,760 points is you're transmitting different waves. And so you're transmitting different points. 227 00:21:36,760 --> 00:21:43,760 creating a square wave of amplitudes. And so this takes infinite bandwidth. And so the way that you 228 00:21:43,760 --> 00:21:49,980 deal with that, or one way that you can deal with that, is you just say, okay, I don't care. I'm 229 00:21:49,980 --> 00:21:56,500 just going to send, I'm going to use an infinite amount of bandwidth, and then I'm going to filter 230 00:21:56,500 --> 00:22:02,900 it out so that I only take up as much bandwidth as I'm allowed. Now, the problem with that is once 231 00:22:02,900 --> 00:22:09,840 you start filtering that, then the symbols that you're sending start to smear together. Because 232 00:22:10,500 --> 00:22:14,420 you're destroying some information by filtering out those high frequency components. 233 00:22:15,820 --> 00:22:18,760 This is known as inter-symbol interference. 234 00:22:21,380 --> 00:22:24,840 There is a cool trick that allows you to minimize 235 00:22:24,840 --> 00:22:31,940 inter-symbol interference. And typically you use a raised a cosine filter. 236 00:22:32,900 --> 00:22:35,120 to minimize this inter-symbol interference. 237 00:22:35,620 --> 00:22:37,220 And so here's what that is. 238 00:22:38,780 --> 00:22:42,700 So here's the impulse response of a raised cosine filter. 239 00:22:44,020 --> 00:22:47,300 And so if you have a square wave and you send it through here, 240 00:22:47,420 --> 00:22:49,160 this is effectively a low-pass filter. 241 00:22:49,360 --> 00:22:51,820 So it limits the amount of bandwidth that you're using. 242 00:22:52,340 --> 00:22:59,600 However, the interesting thing to note here is that on these T boundaries, 243 00:22:59,600 --> 00:23:03,440 boundaries, which are your bit, your symbol intervals, 244 00:23:03,820 --> 00:23:11,640 the amplitude of this impulse response at each of these T's except at zero is zero. 245 00:23:12,140 --> 00:23:19,140 And so effectively what happens is if you send the symbols out 246 00:23:19,140 --> 00:23:22,480 and put it through this filter, 247 00:23:23,200 --> 00:23:28,140 so say you transmit one and it generates sort of this signal here, 248 00:23:28,280 --> 00:23:29,040 and then you transmit, 249 00:23:29,600 --> 00:23:38,020 well, the interesting thing here is that at the precise time that that two is being transmitted, 250 00:23:38,160 --> 00:23:43,300 the contribution from all other symbols is zero right at this point. 251 00:23:43,480 --> 00:23:47,640 And this is how you can get effectively zero inter-symbol interference 252 00:23:47,640 --> 00:23:52,840 while still taking up a limited amount of bandwidth. 253 00:23:53,260 --> 00:23:59,320 And so this is the magic that makes most digital modulation schemes, 254 00:23:59,740 --> 00:24:03,460 There are some others, but I'm not going to get into that today. 255 00:24:05,360 --> 00:24:14,740 So one other twist here is that you might do this filtering completely on the sender side, 256 00:24:14,960 --> 00:24:15,940 and that would make sense. 257 00:24:16,360 --> 00:24:22,580 However, in the presence of noise and different effects sending it over the air, 258 00:24:22,720 --> 00:24:27,100 it's actually more optimal to do half of the filtering on the transmitter side 259 00:24:27,100 --> 00:24:29,580 and half of the filtering on the receiver side. 260 00:24:29,600 --> 00:24:34,920 And so if you have two filters and you multiply their effect together, 261 00:24:36,780 --> 00:24:39,900 you basically multiply their frequency response together. 262 00:24:40,200 --> 00:24:43,300 And so if you wanted to do half the filtering on the transmit side, 263 00:24:43,440 --> 00:24:44,900 half the filtering on the receive side, 264 00:24:45,120 --> 00:24:49,240 you basically do a square root of the filter that you want, 265 00:24:49,340 --> 00:24:56,440 or you take the square root of the frequency attenuation that you want. 266 00:24:56,500 --> 00:24:59,580 So your raised cosine filter now becomes a root filter, 267 00:24:59,580 --> 00:25:00,480 or you can call it a raised cosine filter. 268 00:25:00,860 --> 00:25:04,720 And so if you see this in GNU Radio, this is exactly what it's doing. 269 00:25:04,840 --> 00:25:11,180 It's applying that filter to avoid inter-symbol interference. 270 00:25:14,180 --> 00:25:18,160 So one other thing that you might have noticed back there, 271 00:25:18,260 --> 00:25:21,400 is that to avoid this inter-symbol interference, 272 00:25:21,780 --> 00:25:25,840 we have to precisely sample at this point. 273 00:25:26,080 --> 00:25:29,560 If we sample here, then we effectively get the confirmation. 274 00:25:29,560 --> 00:25:32,920 We get the contribution of this symbol, of this symbol, of this symbol, 275 00:25:33,020 --> 00:25:34,620 and so it gets a bit noisy. 276 00:25:35,500 --> 00:25:40,580 And if it's too bad, then you can't actually recover the symbol that you wanted. 277 00:25:40,920 --> 00:25:45,940 And so to get no inter-symbol interference, 278 00:25:46,300 --> 00:25:50,600 what you need to do is sample at precisely the right time. 279 00:25:50,720 --> 00:25:53,400 Now, that seems fine in theory, 280 00:25:53,560 --> 00:25:57,800 say, you know, the transmitter is sending out 9600 bits per second, 281 00:25:57,920 --> 00:25:59,040 and the receiver is also, 282 00:25:59,560 --> 00:26:02,100 sampling at 9600 bits per second. 283 00:26:02,600 --> 00:26:07,560 The problem is that these radios are made of real components, 284 00:26:07,680 --> 00:26:11,060 and real components won't have an exact frequency. 285 00:26:13,000 --> 00:26:14,600 And also you need to, 286 00:26:14,680 --> 00:26:18,420 so there will be some drift between the transmitter and receiver, 287 00:26:18,680 --> 00:26:20,020 and so you have to lock on to that. 288 00:26:20,140 --> 00:26:23,220 And you also have to lock on to the phase. 289 00:26:23,320 --> 00:26:29,240 So even if you're in a situation where your frequency is perfectly locked, 290 00:26:29,240 --> 00:26:33,620 you need to know sort of where you are in here. 291 00:26:33,700 --> 00:26:34,840 So you don't want to sample here. 292 00:26:34,900 --> 00:26:37,360 You don't want to sample here and here. 293 00:26:37,540 --> 00:26:42,040 You want to know that you sample right at the peak of that symbol. 294 00:26:44,640 --> 00:26:49,440 And so this gives rise to something known as an eye diagram. 295 00:26:49,720 --> 00:26:56,820 So this is sort of a sample eye diagram from a patent I found. 296 00:26:57,040 --> 00:26:57,780 And so, 297 00:26:58,960 --> 00:27:02,040 this sort of visualizes what happens 298 00:27:03,300 --> 00:27:06,340 when you sample early or sample late. 299 00:27:06,480 --> 00:27:08,580 So if you sample right on time, 300 00:27:08,700 --> 00:27:12,240 you'll notice that the recovered signal 301 00:27:12,620 --> 00:27:16,520 is pretty clearly defined at this point, this point, or this point. 302 00:27:16,740 --> 00:27:19,180 But if you're off a bit, 303 00:27:19,420 --> 00:27:23,840 then there's less margin of error here. 304 00:27:25,480 --> 00:27:26,480 And so, 305 00:27:26,480 --> 00:27:28,300 in the presence of noise, 306 00:27:28,420 --> 00:27:31,120 you could get confused to actually which point 307 00:27:31,120 --> 00:27:33,840 you're actually trying to receive. 308 00:27:34,500 --> 00:27:35,060 And so, 309 00:27:35,180 --> 00:27:39,220 part of engineering these radio systems 310 00:27:39,220 --> 00:27:40,680 is to make this eye, 311 00:27:41,500 --> 00:27:42,600 as it's known, 312 00:27:42,640 --> 00:27:45,740 as wide as possible so that you can tolerate the most 313 00:27:46,940 --> 00:27:50,720 frequency and phase errors and noise and things like that. 314 00:27:52,540 --> 00:27:53,860 So one way to 315 00:27:55,200 --> 00:27:58,340 synchronize to the sender is a simple approach, 316 00:27:58,540 --> 00:28:01,740 which is to just correlate it with a known signal. 317 00:28:02,180 --> 00:28:04,160 This is often called a preamble. 318 00:28:04,400 --> 00:28:11,420 And an easy way to do that is to use our friend convolution again. 319 00:28:11,700 --> 00:28:14,660 Put in the signal that you want to look for, 320 00:28:15,540 --> 00:28:17,360 do the exact same thing, 321 00:28:17,480 --> 00:28:21,080 and out pops a number that represents 322 00:28:21,080 --> 00:28:25,300 how similar the input signal is to the signal that you're looking for. 323 00:28:25,700 --> 00:28:28,520 And so this is a quick and dirty way to 324 00:28:28,520 --> 00:28:30,340 synchronize the phase, 325 00:28:30,460 --> 00:28:34,520 assuming that the frequency is close enough. 326 00:28:34,700 --> 00:28:36,540 And for some simple systems, 327 00:28:37,800 --> 00:28:39,200 this is good enough. 328 00:28:39,300 --> 00:28:39,800 For example, 329 00:28:40,000 --> 00:28:43,100 yesterday I was talking about sniffing SCADA systems 330 00:28:43,100 --> 00:28:46,340 with a module that I wrote in GNU Radio. 331 00:28:46,900 --> 00:28:50,280 And this is actually good enough to 332 00:28:50,820 --> 00:28:52,120 synchronize onto the bit timing 333 00:28:52,120 --> 00:28:54,360 and decode all the bits, 334 00:28:54,460 --> 00:28:56,500 even though the frequency doesn't quite match up. 335 00:28:56,580 --> 00:28:58,520 It doesn't become a problem unless 336 00:28:59,200 --> 00:29:01,120 you get too far out of sync. 337 00:29:01,320 --> 00:29:03,460 And the packets are small there, so it works. 338 00:29:06,820 --> 00:29:08,420 Yeah, so as I said, 339 00:29:08,560 --> 00:29:09,540 clocks will drift. 340 00:29:09,620 --> 00:29:11,960 If you want to deal with the clock drift issue, 341 00:29:13,640 --> 00:29:14,100 basically, 342 00:29:15,060 --> 00:29:18,440 you have to do something more advanced. 343 00:29:18,640 --> 00:29:19,100 So 344 00:29:19,100 --> 00:29:21,460 one way to do this is 345 00:29:21,460 --> 00:29:24,380 you compute some sort of function 346 00:29:24,380 --> 00:29:25,760 between the phase error 347 00:29:25,760 --> 00:29:28,260 of the received signal 348 00:29:28,260 --> 00:29:30,020 and what you want. 349 00:29:30,920 --> 00:29:33,160 This phase error will be noisy, 350 00:29:33,300 --> 00:29:34,960 so you put itself through 351 00:29:34,960 --> 00:29:37,140 some sort of low pass filter and use that 352 00:29:37,140 --> 00:29:38,520 in a feedback loop. 353 00:29:39,320 --> 00:29:42,140 And so this is called a phase lock loop, 354 00:29:42,380 --> 00:29:45,920 which is used to recover timing and phase. 355 00:29:46,060 --> 00:29:48,000 You can use a higher order filter 356 00:29:48,000 --> 00:29:50,080 where you not only lock onto phase, 357 00:29:50,200 --> 00:29:51,660 but also lock onto the frequency. 358 00:29:52,920 --> 00:29:55,140 And this is starting to get into 359 00:29:55,140 --> 00:29:58,280 some weird voodoo math magic 360 00:29:59,420 --> 00:30:01,920 that I don't fully understand 361 00:30:01,920 --> 00:30:05,660 and I don't expect many other people to as well. 362 00:30:05,780 --> 00:30:09,460 There is a lot of control theory behind it 363 00:30:09,460 --> 00:30:11,200 for feedback loops and things like that. 364 00:30:12,280 --> 00:30:14,000 But the takeaway point is that 365 00:30:14,000 --> 00:30:15,720 you can use these 366 00:30:15,720 --> 00:30:17,500 to recover both 367 00:30:17,500 --> 00:30:19,020 phase and frequency information 368 00:30:19,020 --> 00:30:19,900 of the transmitter. 369 00:30:21,100 --> 00:30:23,820 The one downside to this approach 370 00:30:23,820 --> 00:30:25,900 is that it takes time 371 00:30:25,900 --> 00:30:29,600 for these PLLs to lock. 372 00:30:29,880 --> 00:30:33,280 And so if you're dealing with 373 00:30:33,280 --> 00:30:36,240 short packets that are sent in bursts, 374 00:30:36,600 --> 00:30:39,780 you usually will use a simple preamble. 375 00:30:42,240 --> 00:30:46,100 So the final thing that you need to do is 376 00:30:46,100 --> 00:30:48,060 deal with carrier recovery. 377 00:30:48,750 --> 00:30:55,660 So if your baseband frequency 378 00:30:55,660 --> 00:30:57,560 is not precisely matched 379 00:30:58,100 --> 00:30:59,860 with the transmitter, 380 00:31:00,080 --> 00:31:01,800 then what will actually happen 381 00:31:01,800 --> 00:31:03,620 to your IQ diagram is 382 00:31:03,620 --> 00:31:04,880 it will start to rotate. 383 00:31:05,800 --> 00:31:08,180 And so what you can do is 384 00:31:08,180 --> 00:31:10,720 you can measure this as well 385 00:31:10,720 --> 00:31:13,800 and then create another feedback loop 386 00:31:13,800 --> 00:31:15,480 to correct for this. 387 00:31:16,100 --> 00:31:18,780 And then lock in on the transmitter's 388 00:31:18,780 --> 00:31:21,640 carrier signal to sort of stabilize this 389 00:31:21,640 --> 00:31:25,000 so you can do your symbol recovery 390 00:31:26,160 --> 00:31:29,100 and still stay sane. 391 00:31:29,920 --> 00:31:33,860 And so you can do this independently 392 00:31:33,860 --> 00:31:37,720 of bit timing recovery as well. 393 00:31:38,080 --> 00:31:41,000 You can do them in either order, 394 00:31:41,100 --> 00:31:43,660 but I believe usually for simplicity, 395 00:31:44,820 --> 00:31:46,000 interestingly enough, 396 00:31:47,480 --> 00:31:49,460 timing recovery is done first 397 00:31:49,460 --> 00:31:51,360 before carrier recovery 398 00:31:51,360 --> 00:31:52,580 and sort of the signal chain. 399 00:31:53,980 --> 00:31:57,260 So one other thing that I'll just briefly mention 400 00:31:57,260 --> 00:32:00,480 is that when you send a signal over the air, 401 00:32:00,560 --> 00:32:02,080 it won't necessarily have 402 00:32:02,080 --> 00:32:03,540 a flat frequency response. 403 00:32:03,780 --> 00:32:05,260 So that will distort 404 00:32:05,810 --> 00:32:08,000 the incoming constellation that you see. 405 00:32:08,860 --> 00:32:12,340 And there are, again, feedback algorithms 406 00:32:12,340 --> 00:32:16,080 to sort of estimate how sending signals 407 00:32:16,080 --> 00:32:19,040 over the air distorts the signal. 408 00:32:19,240 --> 00:32:23,200 So briefly, one way that you could do that is 409 00:32:23,200 --> 00:32:27,080 you know what the sender is sending. 410 00:32:27,360 --> 00:32:29,020 You know what you received. 411 00:32:29,240 --> 00:32:31,080 You know if you modulated itself 412 00:32:31,080 --> 00:32:33,040 what that signal is supposed to look like. 413 00:32:33,200 --> 00:32:35,000 And so then you can look at the difference 414 00:32:35,000 --> 00:32:36,240 between the received signal 415 00:32:36,240 --> 00:32:38,880 and the signal that you thought you should receive 416 00:32:38,880 --> 00:32:44,740 and then develop a filter to undo that 417 00:32:46,800 --> 00:32:49,260 distortion that you get over the air. 418 00:32:50,700 --> 00:32:54,520 Now, this is used for higher data rate stuff. 419 00:32:54,960 --> 00:32:58,040 In practice, if you're dealing with low data rate stuff 420 00:32:58,040 --> 00:32:59,100 like I have been, 421 00:32:59,560 --> 00:33:01,600 you can just completely ignore it 422 00:33:01,600 --> 00:33:06,700 and assume that the air channel is completely flat. 423 00:33:08,620 --> 00:33:10,500 So just leave that at that 424 00:33:10,500 --> 00:33:12,160 as one thing that you can add. 425 00:33:12,320 --> 00:33:14,640 And that gets very complicated very fast. 426 00:33:15,580 --> 00:33:16,580 All right. 427 00:33:16,640 --> 00:33:18,660 So after you've done timing and carrier recovery, 428 00:33:19,260 --> 00:33:20,860 it's really simple now. 429 00:33:20,960 --> 00:33:24,140 All you got to do is if you receive a little blip here 430 00:33:24,140 --> 00:33:26,620 is just find the closest constellation point. 431 00:33:26,760 --> 00:33:28,420 And that's as easy as, you know, 432 00:33:28,420 --> 00:33:31,360 just drawing some imaginary lines 433 00:33:31,360 --> 00:33:33,960 and finding the closest point. 434 00:33:34,060 --> 00:33:37,540 And that's basically all there is to simple recovery. 435 00:33:38,900 --> 00:33:42,060 So once you've got that, now you've got bits. 436 00:33:42,120 --> 00:33:44,100 And bits are nice and familiar. 437 00:33:44,100 --> 00:33:45,460 And we all love bits. 438 00:33:47,040 --> 00:33:50,420 After that, there might still be some post-processing 439 00:33:50,420 --> 00:33:51,240 that you need to do. 440 00:33:51,380 --> 00:33:53,680 So for example, if you send packets, 441 00:33:53,860 --> 00:33:56,600 you need to know where exactly those packets start 442 00:33:56,600 --> 00:33:58,960 because you're only receiving a bunch of bits. 443 00:33:59,560 --> 00:34:02,740 So you need to then synchronize on the frames 444 00:34:02,740 --> 00:34:04,100 that you receive over the air. 445 00:34:04,200 --> 00:34:07,200 And they themselves will often have preambles. 446 00:34:07,340 --> 00:34:10,680 And the preambles can be used for both timing recovery 447 00:34:10,680 --> 00:34:13,520 and frame synchronization, things like that. 448 00:34:14,100 --> 00:34:15,800 There's something called bit scrambling. 449 00:34:15,980 --> 00:34:20,120 And so this is used to sort of whiten the spectrum 450 00:34:21,000 --> 00:34:27,340 and have it more efficiently use the RF spectrum 451 00:34:27,340 --> 00:34:29,800 and sort of flatten out the frequency 452 00:34:29,800 --> 00:34:33,240 of the transmitted signal. 453 00:34:33,820 --> 00:34:36,800 And then this is not for security. 454 00:34:37,000 --> 00:34:40,260 This is just for making the RF a bit nicer. 455 00:34:40,320 --> 00:34:42,940 And so if you want to reverse engineer a modem, 456 00:34:42,940 --> 00:34:47,320 you'll look for like shift registers and XORs 457 00:34:47,320 --> 00:34:48,540 and things like that. 458 00:34:48,580 --> 00:34:50,760 That's used in the bit scrambling. 459 00:34:51,880 --> 00:34:55,120 And so finally, there's error correction. 460 00:34:55,360 --> 00:34:58,560 So if you send stuff over the air, there will be noise. 461 00:34:58,740 --> 00:35:00,100 Some bits will get corrupted. 462 00:35:00,800 --> 00:35:03,480 You want to detect when those errors happen. 463 00:35:03,640 --> 00:35:05,580 So you can use something like a CRC. 464 00:35:05,920 --> 00:35:09,100 But the problem is then you can't recover from those errors. 465 00:35:09,220 --> 00:35:10,140 That might be fine. 466 00:35:10,240 --> 00:35:11,680 You might just want to retransmit it. 467 00:35:11,680 --> 00:35:13,580 If you want to get even fancier, 468 00:35:13,720 --> 00:35:16,300 there are error correction algorithms that will, 469 00:35:16,440 --> 00:35:19,260 by transmitting redundant information, 470 00:35:19,960 --> 00:35:21,980 if you lose a bit of that information 471 00:35:21,980 --> 00:35:25,200 or if a bit of that information is corrupted, 472 00:35:25,520 --> 00:35:28,500 then you can actually recover 473 00:35:28,500 --> 00:35:32,440 what you originally intended to send or receive. 474 00:35:32,760 --> 00:35:37,620 And so to sort of wrap this up conceptually 475 00:35:37,620 --> 00:35:41,380 how this all works is you have your hardware here. 476 00:35:41,680 --> 00:35:42,320 You have your antenna. 477 00:35:42,580 --> 00:35:44,880 You have your hardware local oscillator here. 478 00:35:44,920 --> 00:35:47,360 It mixes it down to some intermediate frequency. 479 00:35:47,620 --> 00:35:50,420 You sample it with an analog to digital converter. 480 00:35:51,400 --> 00:35:52,840 Now you're in software. 481 00:35:53,440 --> 00:35:56,440 In software, you have another local oscillator 482 00:35:56,440 --> 00:36:00,400 that more precisely locks onto the transmitter's carrier. 483 00:36:00,560 --> 00:36:01,180 You mix that. 484 00:36:01,320 --> 00:36:05,980 You apply a low pass filter or maybe some equalization. 485 00:36:06,220 --> 00:36:07,160 You do timing recovery. 486 00:36:07,420 --> 00:36:09,060 You do carrier recovery. 487 00:36:09,340 --> 00:36:10,900 And then finally, you get, 488 00:36:11,680 --> 00:36:13,540 you're a bit decision out of that. 489 00:36:13,660 --> 00:36:16,140 And then you can deal with bits. 490 00:36:19,360 --> 00:36:21,620 So if you want more information 491 00:36:21,620 --> 00:36:24,060 about any of the things I talked about right now, 492 00:36:24,100 --> 00:36:27,320 it's sort of a whirlwind tour of different things, 493 00:36:27,480 --> 00:36:28,440 different topics. 494 00:36:28,660 --> 00:36:30,400 So there's Michael Ostman's series 495 00:36:30,400 --> 00:36:33,680 of software-defined radio videos he made. 496 00:36:35,000 --> 00:36:36,840 He made the HackerRef. 497 00:36:36,940 --> 00:36:39,000 And as part of the Kickstarter campaign, 498 00:36:39,420 --> 00:36:41,660 he is making a whole video series 499 00:36:41,680 --> 00:36:48,480 taking you through all of the magic of DSP and SDR. 500 00:36:49,800 --> 00:36:52,380 And they're really interesting. 501 00:36:52,660 --> 00:36:54,820 And I highly recommend them. 502 00:36:55,080 --> 00:36:58,620 There's also Ziff.org's videos about signals. 503 00:36:59,160 --> 00:37:01,580 They go into some rants about, like, 504 00:37:01,580 --> 00:37:06,140 why you don't need 96 kilohertz audio at 24 bits 505 00:37:06,140 --> 00:37:08,360 for, you know, in listening use. 506 00:37:08,400 --> 00:37:11,360 And they have all these interesting things of, like, 507 00:37:11,360 --> 00:37:14,520 showing how bit dithering works and noise floors 508 00:37:14,520 --> 00:37:17,680 and all that crazy stuff and sampling theory. 509 00:37:18,180 --> 00:37:20,600 And they're short, but they're great. 510 00:37:20,820 --> 00:37:22,500 And then finally, a lot of this, 511 00:37:22,600 --> 00:37:26,080 I got from the Scientists and Engineers Guide 512 00:37:26,080 --> 00:37:30,380 to Digital Signal Processing by Stephen Smith. 513 00:37:30,660 --> 00:37:32,420 It's available online for free. 514 00:37:32,500 --> 00:37:33,640 All the PDFs are there. 515 00:37:33,960 --> 00:37:36,140 If you like it, you can buy a copy on Amazon. 516 00:37:36,980 --> 00:37:39,940 But I find the PDFs or the website's just fine. 517 00:37:39,940 --> 00:37:43,980 So with that, I'd like to thank you for listening. 518 00:37:44,380 --> 00:37:46,300 And I apologize for the late start, 519 00:37:46,400 --> 00:37:49,140 but hopefully this was informative for you all. 520 00:37:49,200 --> 00:37:49,700 Thank you.