Thanks for coming. I really apologize for the mix-up that I had earlier. So today I'm going to talk about digital signal processing for software-defined radio. I also like to call it software-defined radio in a nutshell. 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, and so this talk isn't an introduction to software-defined radios. 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. And so I think there's sort of a lot of what I'll call script kitties of software-defined radio these days. And so in my own work trying to figure this out on my own, I've learned a few key concepts that I want to talk about. 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. It's not going to go deep into the theory or the math or exactly how it works, but this talk is intended to give you an idea of what you don't know and what you should go out and learn more about on your own. So first a very quick introduction to how radios work. And how, and this would be useful for later explaining how this gets translated into the digital domain. So as you all probably know, atoms are made of protons and electrons. These exert a force on each other. So unlike particles attract, like particles repel, you should all basically know that. And you can define a relative force. 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. And so then you can express this electric field as a field basically on the force per unit charge of this test charge. And so if you move this test charge away from this electron, sort of further out, there's less force exerted on it, but that also means that you have to do some work to move it over here. And so this difference is called the potential difference or voltage. And this is what radios measure and use to communicate. So the way that, they do that is, so for example, you might have a dipole antenna, and it might induce a voltage on the dipole antenna. So you have, you sort of push some electrons to one side. And so on the other side, there's effectively positive charge, you can think of it as charged particles, but basically, it's an absence of electrons. And so to actually transmit this information, what a radio will do is alternate the polarity here, and create these reversing electric fields, which then propagate through space. And then when they hit another antenna, they will also induce a voltage on the receiving antenna. And you can measure that as a voltage and recover information that way. So this is all fine and dandy. But then the problem comes, well, how do you separate all these transmitters and receivers from each other? I mean, you can't just, you know, do this and expect everything to work, you need to allow multiple users of the airwaves. And so the way that they do that is, let's see here, through different frequencies. And so the way that you do that is, let's see here, through different frequencies. And so the way that you do that is, you have these carrier frequencies, which is sort of how, how much you you reverse the voltage going into the antenna. And then you modulate that with different types of modulation. So some of the very simplest types of modulation, for example, is amplitude modulation, where you have a constant frequency of moving electrons back and forth. But what you do is you the amplitude of how much power is going back and forth. And then there's frequency modulation, where you actually change the frequency at which you move the electrons around. And so if you've been playing around with software-defined radios, you can actually visualize this. So this is a spectrum display here, and you can actually see here's a commercial FM radio station, and you can sort of see the frequencies of the carrier going back and forth here. And the takeaway from this slide is that different transmitters get allocated sort of different frequencies, and so you can see them across the spectrum. And this applies widely. And so if you wanted to actually recover this signal digitally, one thing that you could think about doing is just taking your antenna, stuffing it into an analog-to-digital converter, and getting out that voltage, and then doing some magic that I'll talk about later, and recovering your signal that you wanted to transmit. Now, unfortunately, since you're transmitting stuff on these carrier waves that can go up into the gigahertz range, you would have to have an analog-to-digital converter, that samples extremely fast to recover enough of that wave to recover the signal. So instead, yeah, this is what I just said. So basically, there's something called the Nyquist rate. So if you have an incoming signal that is, say, this red signal here, but you're only sampling it at these black points, then the only way you can recover that signal is by sampling it at the only thing that you can recover is an alias at a lower frequency. And so one of the challenges in software-defined radios is, well, software-defined radios is actually dealing with this bandwidth limitation of analog to digital converters and conversely to transmit digital to analog converters. So the way that they actually do this is software-defined radios shift frequencies down to or up from zero hertz, sometimes known as a baseband. And the math behind it sort of exploits this trig identity where if you multiply two sine waves of two different frequencies, what you get are two different, a sum of two different frequencies and two different waves. And the frequencies of those two waves are both the sum of the frequencies and the difference of the frequencies. And so what you can do if you, say, want to tune into 89.5, what you can do is have a local oscillator run at 89.5 and then shift. If you get, if you receive something at 89.5, then the difference goes down to zero. There will also be something at twice 89.5, and you just filter that out before it goes to the analog to digital converter. And this is sort of how it looks like as a block diagram there. As I said, you know, you usually use the difference and filter out the sum. So there's one more trick that's commonly used in software-defined radios, and that is to use complex signals. And so what that basically means is you have both an in-phase wave and an out-of-phase, a 90 degrees out-of-phase carrier, local oscillator signal. And you actually have two different signal paths here, and you use them independently. And what this gets you is the ability to represent negative frequencies. So, for example, you can think of a oscillator as going around this unit circle at a particular speed, and that encodes the frequency. And if you look at the Y component, you would get, say, a sine wave. If you look at the X component, then you get a cosine wave. And so with this, you can not only represent the rotational speed or the frequency, but also which way it's going. And this is how you can represent negative frequencies. And this is also why 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, 90 degrees out of phase. All right, so now that we have a signal that we're receiving, how do we actually get data out of it? So say that we want to monitor some unknown data source or unknown modem, and we want to start demodulating it. So the typical steps for demodulation are first frequency shifting. So usually what you'll do in a software-defined radio is the hardware will shift it down to some intermediate frequency, which is maybe not zero. It could be zero. But then you actually want to bring it all the way down to zero. And part of the reason you might do that in software is because the local oscillator of your radio might not match the frequency of your radio. So you might want to bring it down to zero to match the oscillator of the remote radio. And you have to do carrier tracking to make sure everything demodulates correctly. You need to filter out any signals that aren't of interest after you do the frequency shifting. Filtering is also used to avoid inter-symbol interference, which I'll talk about later. Once you do filtering, you have to synchronize both audio and video. So you have to synchronize both audio and video. So you have to synchronize onto the carrier frequency of the remote radio as well as the bit clock of the sender so that you know when to sample the Cygnal. From there, it gets a bit easier. You will sample the incoming signal at a fixed rate. And then you can recover cymbals from that which are bits. So the difference between a bit and a symbol, so a bit is just a 0 and a 1, a symbol can be multiple level. So you can have like So there's like QAM, so you can have like a 16 or 32 or 256 different symbols which can encode many different bits in a single sort of constellation point, and I'll talk about that very shortly. Then once you get out the bit stream, then there are some extra things that are all in the digital domain, and I think I won't talk about much about those because I think working with bits is more familiar to people. But there, I'll briefly touch on those later. All right, so now I'm going to get into some of the nitty-gritty details of how digital signal processing works, how some of the common tools you use in digital signal processing. 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. So what this does is it takes in a signal and you can imagine it as like sort of a graphical equalizer. It can boost frequencies, it can drop frequencies, so you have filters like a low-pass filter, a high-pass filter. So these are graphs in the frequency domain, so you have a frequency going across the x-axis here and the amplitude or the attenuation is in the y-direction here. And so you can, for example, a low-pass filter will allow all low frequencies through, but then after a certain cutoff point, which is usually at negative 3 dB, is the cutoff frequency, then it just sort of goes downhill from there. And so if you build these in hardware, it's very hard to get a very sharp cutoff. It's a bit easier to do digitally, but it's a trade-off between how sharp you want your filter and how much computation you want to do. And then there's other types of simple frequency filters, such as the bandpass filter, which only allows certain frequencies through, and a notch filter, which cuts out some frequencies. So one way you can describe filters is by what's known as their impulse response. And so the way to think of that is, if you have a signal like this in the time domain, which is all zero except for a single blip at one point to one, and you send it through this filter, you look at the signal that comes out of that filter. So for example, if you send this through a low-pass filter here, you might get this response out of the filter. And so, this is actually how you build what are known as finite impulse response filters. And so the way that those work is you take this impulse response that you want for your filter function, and you put it in what's known as the as a filter kernel here. So just imagine that those points that were here are now in here. And when you push samples into this buffer, what you do is you multiply component-wise the incoming samples with their corresponding positions in the filter kernel, and then sum them all up and spit them out as the output signal. So this is known as convolution. This is how finite impulse response filters work, or fur filters. If you see things about fur filters in GNU Radio, for example, this is exactly what they're talking about. These are called taps. So if you see something that refers to the number of taps, this is exactly what they're talking about. And so as you can see, the more taps you have, the more computation you have to do, and so the slower it is. So this is a fur filter with five taps. So another way that you can determine the filter taps is so you can take the frequency response that you want, say, on those graphs from the filtering slide and use what's known as the inverse Fourier transform. And so what a Fourier transform does is it converts signals, signals between the time domain or sort of the received signal that you get and the frequency domain. And so to make that a bit more concrete, so if you have like an oscilloscope and you see like a wave going up and down there, that's sort of representation in the time domain. So you have time across the bottom and amplitude up the y-axis, whereas in the frequency domain, you would see sort of a peak right at where the frequency is. And so Fourier transforms are used to go between the time domain and the frequency domain. All right. So at this point, we have some in-phase and quadrature samples at approximately zero hertz. And what's interesting about IQ samples is that every modulation scheme can be described just by the amplitude of these i's and q's. And so in this case, we're going to use the i and q symbol, the i and q symbol. And we're going to use the i and q symbol to represent the i and q signals or signals. And the way that you can do that is represent these i and q points on a graph, a two-dimensional graph, i on one axis, q on another axis, in what's known as a constellation diagram. So for example, in a very simple case where you have say, let's see, like 180 degrees. degree phase reversal for transmitting different bits. You don't care about the the quadrature stuff. You're only looking at the amplitude of the in-phase signal. And so it's either, you know, it's either a regular amplitude or it's an inverted signal. Now if you want to get a bit crazier, you can start putting these different points anywhere in this constellation diagram here. So for example, you can encode two bits at a time by having different amplitudes of both the the INQ symbols. And you can get as arbitrarily complex as you want. So this is like 16 QAM, which stands for quadrature amplitude modulation. So you basically . . . amplitude modulating both the I's and the Q's, and you can represent four bits per point there. Now the issue is that when you send these over the air there will be interference. The components won't be perfect. There will be some noise introduced in the system, and so what you get is, say, for bits or symbols that you send with that constellation diagram, you might receive something like that. And as long as there's enough separation between them, then you can recover those symbols and you can add some error correction later once you get a bit stream to make it even more robust. All right, so in principle all you need to do to transmit a digital signal is just have a use case. an in-phase and quadrature phase signal being transmitted at a particular frequency for a certain amount of time, and then immediately jump to a different set of amplitudes for your INQ signals. And then you just keep hopping it around at the data rate that you want. Now, unfortunately, this takes an infinite amount of bandwidth. And as I discussed earlier, you want to use only a finite part of the RF spectrum for your own signal to share it with others. And so the reason why this takes infinite bandwidth goes back to a little bit of math where square waves are just some of odd harmonics. So, if you have this square wave at some frequency, that is effectively the sum of the sine wave at that frequency plus a sine wave at three times that frequency, five times that frequency, and it just keeps going off to infinity. And so if you keep summing them up together, you get closer and closer to a square wave. And so what you're effectively doing by transmitting different points is you're transmitting different waves. And so you're transmitting different points. creating a square wave of amplitudes. And so this takes infinite bandwidth. And so the way that you deal with that, or one way that you can deal with that, is you just say, okay, I don't care. I'm just going to send, I'm going to use an infinite amount of bandwidth, and then I'm going to filter it out so that I only take up as much bandwidth as I'm allowed. Now, the problem with that is once you start filtering that, then the symbols that you're sending start to smear together. Because you're destroying some information by filtering out those high frequency components. This is known as inter-symbol interference. There is a cool trick that allows you to minimize inter-symbol interference. And typically you use a raised a cosine filter. to minimize this inter-symbol interference. And so here's what that is. So here's the impulse response of a raised cosine filter. And so if you have a square wave and you send it through here, this is effectively a low-pass filter. So it limits the amount of bandwidth that you're using. However, the interesting thing to note here is that on these T boundaries, boundaries, which are your bit, your symbol intervals, the amplitude of this impulse response at each of these T's except at zero is zero. And so effectively what happens is if you send the symbols out and put it through this filter, so say you transmit one and it generates sort of this signal here, and then you transmit, well, the interesting thing here is that at the precise time that that two is being transmitted, the contribution from all other symbols is zero right at this point. And this is how you can get effectively zero inter-symbol interference while still taking up a limited amount of bandwidth. And so this is the magic that makes most digital modulation schemes, There are some others, but I'm not going to get into that today. So one other twist here is that you might do this filtering completely on the sender side, and that would make sense. However, in the presence of noise and different effects sending it over the air, it's actually more optimal to do half of the filtering on the transmitter side and half of the filtering on the receiver side. And so if you have two filters and you multiply their effect together, you basically multiply their frequency response together. And so if you wanted to do half the filtering on the transmit side, half the filtering on the receive side, you basically do a square root of the filter that you want, or you take the square root of the frequency attenuation that you want. So your raised cosine filter now becomes a root filter, or you can call it a raised cosine filter. And so if you see this in GNU Radio, this is exactly what it's doing. It's applying that filter to avoid inter-symbol interference. So one other thing that you might have noticed back there, is that to avoid this inter-symbol interference, we have to precisely sample at this point. If we sample here, then we effectively get the confirmation. We get the contribution of this symbol, of this symbol, of this symbol, and so it gets a bit noisy. And if it's too bad, then you can't actually recover the symbol that you wanted. And so to get no inter-symbol interference, what you need to do is sample at precisely the right time. Now, that seems fine in theory, say, you know, the transmitter is sending out 9600 bits per second, and the receiver is also, sampling at 9600 bits per second. The problem is that these radios are made of real components, and real components won't have an exact frequency. And also you need to, so there will be some drift between the transmitter and receiver, and so you have to lock on to that. And you also have to lock on to the phase. So even if you're in a situation where your frequency is perfectly locked, you need to know sort of where you are in here. So you don't want to sample here. You don't want to sample here and here. You want to know that you sample right at the peak of that symbol. And so this gives rise to something known as an eye diagram. So this is sort of a sample eye diagram from a patent I found. And so, this sort of visualizes what happens when you sample early or sample late. So if you sample right on time, you'll notice that the recovered signal is pretty clearly defined at this point, this point, or this point. But if you're off a bit, then there's less margin of error here. And so, in the presence of noise, you could get confused to actually which point you're actually trying to receive. And so, part of engineering these radio systems is to make this eye, as it's known, as wide as possible so that you can tolerate the most frequency and phase errors and noise and things like that. So one way to synchronize to the sender is a simple approach, which is to just correlate it with a known signal. This is often called a preamble. And an easy way to do that is to use our friend convolution again. Put in the signal that you want to look for, do the exact same thing, and out pops a number that represents how similar the input signal is to the signal that you're looking for. And so this is a quick and dirty way to synchronize the phase, assuming that the frequency is close enough. And for some simple systems, this is good enough. For example, yesterday I was talking about sniffing SCADA systems with a module that I wrote in GNU Radio. And this is actually good enough to synchronize onto the bit timing and decode all the bits, even though the frequency doesn't quite match up. It doesn't become a problem unless you get too far out of sync. And the packets are small there, so it works. Yeah, so as I said, clocks will drift. If you want to deal with the clock drift issue, basically, you have to do something more advanced. So one way to do this is you compute some sort of function between the phase error of the received signal and what you want. This phase error will be noisy, so you put itself through some sort of low pass filter and use that in a feedback loop. And so this is called a phase lock loop, which is used to recover timing and phase. You can use a higher order filter where you not only lock onto phase, but also lock onto the frequency. And this is starting to get into some weird voodoo math magic that I don't fully understand and I don't expect many other people to as well. There is a lot of control theory behind it for feedback loops and things like that. But the takeaway point is that you can use these to recover both phase and frequency information of the transmitter. The one downside to this approach is that it takes time for these PLLs to lock. And so if you're dealing with short packets that are sent in bursts, you usually will use a simple preamble. So the final thing that you need to do is deal with carrier recovery. So if your baseband frequency is not precisely matched with the transmitter, then what will actually happen to your IQ diagram is it will start to rotate. And so what you can do is you can measure this as well and then create another feedback loop to correct for this. And then lock in on the transmitter's carrier signal to sort of stabilize this so you can do your symbol recovery and still stay sane. And so you can do this independently of bit timing recovery as well. You can do them in either order, but I believe usually for simplicity, interestingly enough, timing recovery is done first before carrier recovery and sort of the signal chain. So one other thing that I'll just briefly mention is that when you send a signal over the air, it won't necessarily have a flat frequency response. So that will distort the incoming constellation that you see. And there are, again, feedback algorithms to sort of estimate how sending signals over the air distorts the signal. So briefly, one way that you could do that is you know what the sender is sending. You know what you received. You know if you modulated itself what that signal is supposed to look like. And so then you can look at the difference between the received signal and the signal that you thought you should receive and then develop a filter to undo that distortion that you get over the air. Now, this is used for higher data rate stuff. In practice, if you're dealing with low data rate stuff like I have been, you can just completely ignore it and assume that the air channel is completely flat. So just leave that at that as one thing that you can add. And that gets very complicated very fast. All right. So after you've done timing and carrier recovery, it's really simple now. All you got to do is if you receive a little blip here is just find the closest constellation point. And that's as easy as, you know, just drawing some imaginary lines and finding the closest point. And that's basically all there is to simple recovery. So once you've got that, now you've got bits. And bits are nice and familiar. And we all love bits. After that, there might still be some post-processing that you need to do. So for example, if you send packets, you need to know where exactly those packets start because you're only receiving a bunch of bits. So you need to then synchronize on the frames that you receive over the air. And they themselves will often have preambles. And the preambles can be used for both timing recovery and frame synchronization, things like that. There's something called bit scrambling. And so this is used to sort of whiten the spectrum and have it more efficiently use the RF spectrum and sort of flatten out the frequency of the transmitted signal. And then this is not for security. This is just for making the RF a bit nicer. And so if you want to reverse engineer a modem, you'll look for like shift registers and XORs and things like that. That's used in the bit scrambling. And so finally, there's error correction. So if you send stuff over the air, there will be noise. Some bits will get corrupted. You want to detect when those errors happen. So you can use something like a CRC. But the problem is then you can't recover from those errors. That might be fine. You might just want to retransmit it. If you want to get even fancier, there are error correction algorithms that will, by transmitting redundant information, if you lose a bit of that information or if a bit of that information is corrupted, then you can actually recover what you originally intended to send or receive. And so to sort of wrap this up conceptually how this all works is you have your hardware here. You have your antenna. You have your hardware local oscillator here. It mixes it down to some intermediate frequency. You sample it with an analog to digital converter. Now you're in software. In software, you have another local oscillator that more precisely locks onto the transmitter's carrier. You mix that. You apply a low pass filter or maybe some equalization. You do timing recovery. You do carrier recovery. And then finally, you get, you're a bit decision out of that. And then you can deal with bits. So if you want more information about any of the things I talked about right now, it's sort of a whirlwind tour of different things, different topics. So there's Michael Ostman's series of software-defined radio videos he made. He made the HackerRef. And as part of the Kickstarter campaign, he is making a whole video series taking you through all of the magic of DSP and SDR. And they're really interesting. And I highly recommend them. There's also Ziff.org's videos about signals. They go into some rants about, like, why you don't need 96 kilohertz audio at 24 bits for, you know, in listening use. And they have all these interesting things of, like, showing how bit dithering works and noise floors and all that crazy stuff and sampling theory. And they're short, but they're great. And then finally, a lot of this, I got from the Scientists and Engineers Guide to Digital Signal Processing by Stephen Smith. It's available online for free. All the PDFs are there. If you like it, you can buy a copy on Amazon. But I find the PDFs or the website's just fine. So with that, I'd like to thank you for listening. And I apologize for the late start, but hopefully this was informative for you all. Thank you.