[MUSIC] So we're going to talk about analog versus digital. If you remember several lectures ago we talked about embedded systems, IT devices, and their interface. And so at the input they have a set of sensors that receive data about the outside world. Though the sensors could be simple things like buttons or something like that but it could be a microphone, a light sensor, a camera, something like that. But it senses data about the outside world. And then actuators on the other end, output data to the outside world. So maybe they're lights, LEDs or speakers, or just a screen or something like that. Okay, but they send data to the outside world. So there's this interface, sensors at the input side, actuators at the output side. And so these devices, they're sensing physical phenomenon okay, so if you look at the sensors, the sensors are sensing physical phenomenon and physical phenomenon are often analog signals. Okay, now let me describe this difference between analog and digital just very briefly. Analog, actually a very quick way to say it is, analog to digital is the same as the difference between real numbers and integers. Okay, if you remember that, right. Real numbers are continuous. So if you get the number, real numbers between 0 and 1, there's an infinite number of real numbers between 0 and 1. 0.5, 0.6, 0.7, whatever fraction you can think of. That's an infinite number of values, of real values, between 0 and 1. Now integers, however, can only be 0, or 1, or 2, or so on. No fractions, so between 0 and 1, there's just integers 0, integer 1, it's a finite number, and a much smaller number, so no fractions. So that difference between real numbers and integers is the same as the difference between analog and digital. So if you look at an analog value, let's take light, okay, I've got a lot of light, I've got these lights pointing at my face. Okay? Lights, they can be, generally, they have analog values, the brightness has an analog value. So you can take a light and have a dimmer switch connected to it and make it a little brighter or a little darker, right, and depending on how fine your control is you can have a lot of possible values between totally off and totally on. And it's a smooth transition, you can hit every possible value between completely dark versus completely bright by turning your dimmer switch. So in this way, light is generally an analog phenomenon. Also sound, you can see the same thing there. Sound I'm talking, right. I can talk quietly, I can talk loudly, [LAUGH] right? I can talk in between. So I can adjust my volume anywhere in between completely quiet and completely loud. Again, an analog phenomenon. So the universe. The world in general to the perception of humans is analog. Now physicists will say look, the world is digital. If you look down at a subatomic level, look at quarks and they have fixed states. Maybe things are digital in reality. Okay? They are discreet. Either as high or low. Plus, minus. Right? Maybe, but to our human perceptions the world is analog. So, a lot of these phenomena that you want to sense are analog, sound, touch, right? You can push hard, push soft. Things like this? They're analog phenomena. Now, digital phenomena is something that's either off or on, or at least has some discrete number of states. So for instance these lights, I could just hook them to a switch. They're wall switches, right? I hit off and the whole thing goes off, or it goes on, right? So maybe I'm using my light in a digital way. It's either all off or all on. All right? That's digital. Or that's discrete, really. And digital is a version of that. But that's, so that's basically the difference between analog and digital. This is also, you get the same definition in terms of watches, right? So my watch is a digital watch, right? It shows digital numbers. One second, two seconds. It doesn't show fractions between seconds. But if you look at an analog clock where that second hand is can point at any fractional number between seconds, right? So this is analog to digital. Now the reason we bring this up is because these embedded systems are interacting with the real world. And the real world, to our perceptions, is largely analog. So say I want to have a sensor that senses the brightness of light. That sensor is generally going to be an analog sensor because it's got to be able to sense, assuming that the light is not either off or on, it could be a little bright, a little dark, it's got to be an analog sensor. Now the problem with this is that our systems, the microcontrollers that we have, they are digital systems. So, they only understand digital data, specifically zeroes and ones, okay? Zeroes and ones, binary data, that's binary. Zero or one, that's digital. In order for our program on our microcontroller to be able to use information from sensors, that analog signal has been converted to a digital value. And that is what analog to digital conversion is for. So we're not going to talk in great detail about how it's performed. Now, I have a slide, in a while I'll show you a little bit about it. But how it's performed is a complicated thing, but just understand that what it does is it takes an analog value and converts it to a digital number. Now, this digital representation is maybe an approximation of the actual analog value, but that's okay. It can be a pretty accurate approximation, as accurate as we need. So we need analog to digital conversion at a lot of our inputs. Not all, some of our inputs can be buttons, like push buttons. Then that's actually naturally digital. It's either pushed or not, so zero one. But other analog inputs, like lights and sounds and stuff like that, those things typically have to go through analog to digital conversion before they can be used in our system. Now on the output end, you usually need digital to analog conversion, or you often need digital to analog conversion. So let's say I have a microcontroller and it's outputting some sound to some speakers. These speakers are analog devices, they need analog signal. But the microcontroller is outputting zeros and ones, so you need digital to analog conversion to take those digital signals, convert them to analog and then drive the speaker with them. So it's very common to see digital to analog conversion on the output of a system and analog to digital conversion on the input. Because in the middle of that system, in that microcontroller, it's almost all digital. It's primarily digital. So the world is often analog, so you need conversion on either end. So just to give you a little example [COUGH] of how you might convert, how you might form analog to digital conversion. You take some analog signal, a wave form over time, and we see one right here. This is, let's say it's a sound way, okay. So if the sound wave, sound is pressure. Pressure through the air. And it changes over time. So you can measure sound waves you can look at sound like we've seen here in this picture where the x axis is time. And the y axis is pressure in the air. And that's actually a sine wave that you're looking at right there so that's like a pure tone. One frequency just a [SOUND] you know, a frequency as pure as you can get, that's a sine wave. That's what it would sound like at some frequency. So the Y-axis is generally the pressure, the air pressure. Now a microphone, the job of a microphone, is to take that pressure and convert it into voltage. Okay? Because our machines can't understand pressure, they understand voltage, they read voltages. So if you look at the Y-axis as it's labelled, it says voltage, and then in parentheses, pressure. So what they're showing is the voltage at the output of the microphone. But still it's an analog waveform. It's smooth, the red line, it's analog. And it changes smoothly over time. Now the analog to digital converter will take that waveform and represent it piece by piece as a set of digital numbers. So you can see that step. So if you look at that red waveform it's smooth. It's real numbers. It's an analog waveform. Superimpose on that you see the stair-stepping. They see essentially just a stair-stepping signal. That's always has discreet values. So there are those levels, those horizontal lines, each one represents a discreet digital number. And you know, 1, 2, 3, 4, 5. And if you look at that stair stepping wave form that's overlapped on top of the analog wave form. It only ever hits one of those lines. It's never in-between, right. It's at a line or up or down, right. That's digital. So you can take this analog wave form, this red one and approximate it with this stair stepping digital wave form and so at every time, every unit of time, the digital wave form is always at a fixed voltage value in this case, right? And so you can just have a series of voltage values over different points in time and store it. And that is an approximate representation of analog wave form. And that is what analog to digital conversion does. And we need it to, in order to represent any kind of analog input data to the system. And note that on the outputs to the actuators you get the opposite going on. So you start with the digital waveform, the stair stepping waveform. And the digital to analog conversion converts it into that red or something close to that red, smooth analog waveform that you see. And that gets sent out to whatever your actuator is. Say a speaker, or something like that. Thank you. [MUSIC]