Showing posts with label Digital. Show all posts
Showing posts with label Digital. Show all posts
The Sampling Theorem (Nyquist)
The definition of proper sampling is quite simple. Suppose you sample a continuous signal in some manner. If you can exactly reconstruct the analog signal from the samples, you must have done the sampling properly. Even if the sampled data appears confusing or incomplete, the key information has been captured if you can reverse the process.
Picture 1 shows several sinusoids before and after digitization. The continuous line represents the analog signal entering the ADC, while the square markers are the digital signal leaving the ADC. In (a), the analog signal is a constant DC value, a cosine wave of zero frequency. Since the analog signal is a series of straight lines between each of the samples, all of the information needed to reconstruct the analog signal is contained in the digital data. According to our definition, this is proper sampling.
Picture 1: Illustration of proper and improper sampling
The sine wave shown in (b) has a frequency of 0.09 of the sampling rate. This might represent, for example, a 90 cycle/second sine wave being sampled at 1000 samples/second. Expressed in another way, there are 11.1 samples taken over each complete cycle of the sinusoid. This situation is more complicated than the previous case, because the analog signal cannot be reconstructed by simply drawing straight lines between the data points. Do these samples properly represent the analog signal? The answer is yes, because no other sinusoid, or combination of sinusoids, will produce this pattern of samples (within the reasonable constraints listed below). These samples correspond to only one analog signal, and therefore the analog signal can be exactly reconstructed. Again, an instance of proper sampling.
In (c), the situation is made more difficult by increasing the sine wave's frequency to 0.31 of the sampling rate. This results in only 3.2 samples per sine wave cycle. Here the samples are so sparse that they don't even appear to follow the general trend of the analog signal. Do these samples properly represent the analog waveform? Again, the answer is yes, and for exactly the same reason. The samples are a unique representation of the analog signal. All of the information needed to reconstruct the continuous waveform is contained in the digital data. How you go about doing this will be discussed later in this chapter. Obviously, it must be more sophisticated than just drawing straight lines between the data points. As strange as it seems, this is proper sampling according to our definition.
In (d), the analog frequency is pushed even higher to 0.95 of the sampling rate, with a mere 1.05 samples per sine wave cycle. Do these samples properly represent the data? No, they don't! The samples represent a different sine wave from the one contained in the analog signal. In particular, the original sine wave of 0.95 frequency misrepresents itself as a sine wave of 0.05 frequency in the digital signal. This phenomenon of sinusoids changing frequency during sampling is called aliasing. Just as a criminal might take on an assumed name or identity (an alias), the sinusoid assumes another frequency that is not its own. Since the digital data is no longer uniquely related to a particular analog signal, an unambiguous reconstruction is impossible. There is nothing in the sampled data to suggest that the original analog signal had a frequency of 0.95 rather than 0.05. The sine wave has hidden its true identity completely; the perfect crime has been committed! According to our definition, this is an example of improper sampling.
This line of reasoning leads to a milestone in DSP, the sampling theorem. Frequently this is called the Shannon sampling theorem, or the Nyquist sampling theorem, after the authors of 1940s papers on the topic. The sampling theorem indicates that a continuous signal can be properly sampled, only if it does not contain frequency components above one-half of the sampling rate. For instance, a sampling rate of 2,000 samples/second requires the analog signal to be composed of frequencies below 1000 cycles/second. If frequencies above this limit are present in the signal, they will be aliased to frequencies between 0 and 1000 cycles/second, combining with whatever information that was legitimately there.
Two terms are widely used when discussing the sampling theorem: the Nyquist frequency and the Nyquist rate. Unfortunately, their meaning is not standardized. To understand this, consider an analog signal composed of frequencies between DC and 3 kHz. To properly digitize this signal it must be sampled at 6,000 samples/sec (6 kHz) or higher. Suppose we choose to sample at 8,000 samples/sec (8 kHz), allowing frequencies between DC and 4 kHz to be properly represented. In this situation there are four important frequencies: (1) the highest frequency in the signal, 3 kHz; (2) twice this frequency, 6 kHz; (3) the sampling rate, 8 kHz; and (4) one-half the sampling rate, 4 kHz. Which of these four is the Nyquist frequency and which is the Nyquist rate? It depends who you ask! All of the possible combinations are used. Fortunately, most authors are careful to define how they are using the terms. Here, they are both used to mean one-half the sampling rate.
Picture 2 shows how frequencies are changed during aliasing. The key point to remember is that a digital signal cannot contain frequencies above one-half the sampling rate (i.e., the Nyquist frequency/rate). When the frequency of the continuous wave is below the Nyquist rate, the frequency of the sampled data is a match. However, when the continuous signal's frequency is above the Nyquist rate, aliasing changes the frequency into something that can be represented in the sampled data. As shown by the zigzagging line in Picture 2, every continuous frequency above the Nyquist rate has a corresponding digital frequency between zero and one-half the sampling rate. If there happens to be a sinusoid already at this lower frequency, the aliased signal will add to it, resulting in a loss of information. Aliasing is a double curse; information can be lost about the higher and the lower frequency. Suppose you are given a digital signal containing a frequency of 0.2 of the sampling rate. If this signal were obtained by proper sampling, the original analog signal must have had a frequency of 0.2. If aliasing took place during sampling, the digital frequency of 0.2 could have come from any one of an infinite number of frequencies in the analog signal: 0.2, 0.8, 1.2, 1.8, 2.2, ... .
Picture 2: Conversion of analog frequency into digital frequency during sampling
Just as aliasing can change the frequency during sampling, it can also change the phase. For example, look back at the aliased signal in Picture 1 (d). The aliased digital signal is inverted from the original analog signal; one is a sine wave while the other is a negative sine wave. In other words, aliasing has changed the frequency and introduced a 180E phase shift. Only two phase shifts are possible: 0E (no phase shift) and 180E (inversion). The zero phase shift occurs for analog frequencies of 0 to 0.5, 1.0 to 1.5, 2.0 to 2.5, etc. An inverted phase occurs for analog frequencies of 0.5 to 1.0, 1.5 to 2.0, 2.5 to 3.0, and so on.
Now we will dive into a more detailed analysis of sampling and how aliasing occurs. Our overall goal is to understand what happens to the information when a signal is converted from a continuous to a discrete form. The problem is, these are very different things; one is a continuous waveform while the other is an array of numbers. This "apples-to-oranges" comparison makes the analysis very difficult. The solution is to introduce a theoretical concept called the impulse train.
Picture 3 (a) shows an example analog signal. Picture 3 (c) shows the signal sampled by using an impulse train. The impulse train is a continuous signal consisting of a series of narrow spikes (impulses) that match the original signal at the sampling instants. Each impulse is infinitesimally narrow. Between these sampling times the value of the waveform is zero. Keep in mind that the impulse train is a theoretical concept, not a waveform that can exist in an electronic circuit. Since both the original analog signal and the impulse train are continuous wave forms, we can make an "apples-apples" comparison between the two.
Picture 3: The sampling theorem in the time and frequency domains
Now we need to examine the relationship between the impulse train and the discrete signal (an array of numbers). This one is easy; in terms of information content, they are identical. If one is known, it is trivial to calculate the other. Think of these as different ends of a bridge crossing between the analog and digital worlds. This means we have achieved our overall goal once we understand the consequences of changing the waveform in Picture 3 (a) into the waveform in Picture 3 (c).
Three continuous wave forms are shown in the left-hand column in Picture 3. The corresponding frequency spectra of these signals are displayed in the right-hand column. This should be a familiar concept from your knowledge of electronics; every waveform can be viewed as being composed of sinusoids of varying amplitude and frequency. Later chapters will discuss the frequency domain in detail.
Picture 3 (a) shows an analog signal we wish to sample. As indicated by its frequency spectrum in (b), it is composed only of frequency components between 0 and about 0.33 fs, where fs is the sampling frequency we intend to use. For example, this might be a speech signal that has been filtered to remove all frequencies above 3.3 kHz. Correspondingly, fs would be 10 kHz (10,000 samples/second), our intended sampling rate.
Sampling the signal in (a) by using an impulse train produces the signal shown in (c), and its frequency spectrum shown in (d). This spectrum is a duplication of the spectrum of the original signal. Each multiple of the sampling frequency, fs, 2fs, 3fs, 4fs, etc., has received a copy and a left-for-right flipped copy of the original frequency spectrum. The copy is called the upper side-band, while the flipped copy is called the lower side-band. Sampling has generated new frequencies. Is this proper sampling? The answer is yes, because the signal in (c) can be transformed back into the signal in (a) by eliminating all frequencies above ½fs. That is, an analog low-pass filter will convert the impulse train, (b), back into the original analog signal, (a).
If you are already familiar with the basics of DSP, here is a more technical explanation of why this spectral duplication occurs. In the time domain, sampling is achieved by multiplying the original signal by an impulse train of unity amplitude spikes. The frequency spectrum of this unity amplitude impulse train is also a unity amplitude impulse train, with the spikes occurring at multiples of the sampling frequency, fs, 2fs, 3fs, 4fs, etc. When two time domain signals are multiplied, their frequency spectra are convolved. This results in the original spectrum being duplicated to the location of each spike in the impulse train's spectrum. Viewing the original signal as composed of both positive and negative frequencies accounts for the upper and lower side-bands, respectively. This is the same as amplitude modulation.
Picture 3 (e) shows an example of improper sampling, resulting from too low of sampling rate. The analog signal still contains frequencies up to 3.3 kHz, but the sampling rate has been lowered to 5 kHz. Notice that fs, 2fs, 3fs ... along the horizontal axis are spaced closer in (f) than in (d). The frequency spectrum, (f), shows the problem: the duplicated portions of the spectrum have invaded the band between zero and one-half of the sampling frequency. Although (f) shows these overlapping frequencies as retaining their separate identity, in actual practice they add together forming a single confused mess. Since there is no way to separate the overlapping frequencies, information is lost, and the original signal cannot be reconstructed. This overlap occurs when the analog signal contains frequencies greater than one-half the sampling rate, that is, we have proven the sampling theorem.
Microcontrollers
Microcontrollers are integrated circuits which consists of microprocessor with additional units like memories, input/output units (peripherals), etc. With this way of implementation, microcontrollers provide savings in time and space, and of course money. Abbreviated way of marking the microcontrollers is MCU (Microcontroller Unit), µC, or uC. In general, microcontrollers are designed so that they can execute a lot of different tasks, which provides an opportunity for their use in various devices. The function or the task that microcontroller executes depends on the program which is written (recorded) in it. The application of the microcontrollers is wide, from the toys, cars, industry, etc.
In fact, one microcontroller can consists of different components. However, every microcontroller consists of several basic blocks, which are necessary for its normal functioning. Typical block-diagram of a microcontroller with its basic components is shown on the Picture 1.
Picture 1: Typical block-diagram of a microcontroller
Central Processing Unit
The Central Processing Unit (CPU) is the heart of the microcontroller. The CPU is connecting element between the rest of the units of the MCU and it coordinate their work. The main function of the CPU consists of three phases and these three phases are: catch, decode and execute. In other words, the program which is written in the MCU consists of programming instructions and the task of the CPU is to find the current instruction (catch), then to decode it, because every programming instruction is coded, and finally, after decoding the instruction (that means that the CPU now knows which instruction is that) CPU needs to execute the instruction. So, the executing of the program which is written in the MCU is nothing else, but executing the programming instructions which the program consists of, successively, one after another. From the other side, this unit (CPU) allows executing of the arithmetic and logical operations, reading and writing data from and into the memory, data transfer between the peripheral components, and also data transfer between the memory and the peripheral components. For the above mentioned arithmetic and logical operations, and the data transfer, is charge a separate section from the CPU, which is called Arithmetic Logic Unit (ALU).
Memory
The memory stores the data which MCU operates with. The MCU have its own data (working) and program memory. Each of the memories is divided on certain parts which are called memory locations, and each of these locations have its own address. The CPU recognizes the certain memory location by its own address. The link which connects the CPU and the memory of the MCU is called bus. Actually, the data is transmitted via the bus. From the aspect of the PIC (Programmable Inteligent Computer) microcontrollers, the data memory, also known as RAM (Random Access Memory), is a memory which is used by the program of the microcontroller during its own execution. In this memory are stored all temporary data necessary for the program execution. More recently, all manufacturers of microcontrollers have begun to add and EEPROM (Electrically Erasable Programmable Read-Only Memory) memory, as a separate part of the data memory. This memory have the ability to save data even when the power supply is off, which is not the case with the RAM memory. This way, the microcontroller can store important parameters, so that it declares its independence. The program memory is that memory in which is stored, or written (recorded) the program for the microcontroller. Today's technology allows more times to write and erase from this memory, allowing one microcontroller to be used with different versions and improvements of the previous recorded programs, or to write in it completely different (new) program. Here it's good to mention, that the memory in some microcontrollers can be used in different ways. Thus, for example, the RAM memory, including and EEPROM memory, can contain any executable program.
Input/Output Ports
In the microcontroller there is a input/output unit which allows it to communicate with the external world. It is actually the most pins or leads that are visible on the microcontroller. The pins are grouped into groups where each group is called port. The port can be input or output. The microcontroller can send and receive data through the ports. In other words, the CPU can set the pins of a port to high or low logical level, or it can read the logical level which exists on the pins of a port. The ports of the microcontroller can also be two-way or duplex, or input and output, depending on the implementation. On many microcontrollers, some of the input/output pins have a double role, or they can perform two functions.
Timer
This integral part of the microcontroller is free counter. Its value, the counter state, increases with time at certain time intervals. These time intervals are equal. Thanks to this, the microcontroller can find the time passed between two events using the values of the counter. So, this is very useful, and from the other side, necessary component (unit) of each microcontroller. Using this unit, the microcontroller can perform different time-depending instructions, measure a flow, measure a duration of some physical phenomena, and so on.
Microcontrollers can have various other units as integral parts. Usually this depends on the manufacturers and the opportunities that they want to implement into their microcontrollers. For example, other unit can be the unit for serial communication which allows serial synchronous and/or asynchronous communication between the microcontroller and some other device. Another unit can be analog/digital convertors - the unit which allows the microcontroller to recognize and operate with analog signals, or in other words, to convert these signals in binary form, so they can be understandable for the CPU and ready for further operations. Also, nowadays most often integrated units in the microcontrollers are USB and LAN units. These units allows the MCU to communicate through USB (Universal Serial Bus) and through network (LAN - Local Area Network).
Architecture of the microcontrollers
There are two types of architectures that are used for implementation of the microcontrollers, Von Neumann and Harvard. At Von Neumann architecture the data and the program memory are connected with the CPU by one bus, or the access to the data and the instructions goes through the same bus. This type of architecture is older, and here it's obviously that the memories must share the space, or the capacity for transfer of different types of data. This results in lower speed of execution of the instructions. From the other side, the Harvard architecture is advanced progress in the design of the microcontrollers. At Harvard architecture, the data and the program memory are separated and they are connected with the CPU through two different buses. This way, the flow of information is increased, and the working speed also is increased.
Flip-flop Circuits
When we talk about the logic circuits, there is a special class of logic which is called sequential logic. Here, the output of the circuit depends not only from the state of the input, but and from the state of the output itself. This kind of sequential logic element is known as Flip-flop. There are many types of flip-flop circuits. Characteristic of these circuits is that they have ability to store (memory) certain logic state. Flip-flops are implemented with appropriate connection of the basic logic gates.
SR Flip-flop
The SR flip-flop is one of the best known and simplest circuit for storing a bit-information. On Picture 1 are shown the symbol, the schematic symbol and the table of truth of SR flip-flop. The inputs of the circuit are marked with S (set) and R (reset). The outputs are Q and its negation. When we send a pulse on the input S, then we say that the circuit is set. When we send a pulse on the input R, then we say that the circuit is reset. Q' is inverse state of the state of Q (when Q is true, Q' is false). If the inputs S and R are both 0, then the outputs remains the same as the last set or reset to the circuit. As we can see from the table of truth, if S = 1 and R = 0, then output Q = 1. In other case, if S = 0 and R = 1, then output Q = 0. However, if both of the inputs S and R are 1, then the output of the circuit is unpredictable and because of that the state when S = 1 and R = 1 is not allowed.
Picture 1: SR Flip-flop - symbol, schematic symbol and table of truth
D Flip-flop
The input of this circuit is marked as D (data). The symbol of the D Flip-flop an its table of truth are shown on Picture 2. The other input of the circuit, which signed as >, is actually the clock signal (clk). The logic state of the input D is send to the output only if there is a positive pulse on the clock input. If there is a change of the state of the input D, this change will be not send to the output Q until the next positive pulse of the clock signal.
Picture 2: D Flip-flop - symbol and table of truth
T Flip-flop
The symbol of the T Flip-flop an its table of truth are shown on Picture 3. The output of this circuit is changing its state for every positive pulse from the clock signal that is send to the input T. This means that the output signal of this circuit have two times lower frequency from the frequency of the input (clock) signal. So, this circuit can be used for dividing the frequency of the input clock signal with ratio 2:1. If we connect two of this circuits in series, then we will have the dividing with ratio 4:1, etc.
Picture 3: T Flip-flop - symbol and table of truth
JK Flip-flop
This circuit have two inputs marked as J and K. The third input (>) is for the clock signal. On Picture 4 are shown the symbol of the JK Flip-flop an its table of truth. If input J = 1 and input K = 0, then when the clock signal have the positive pulse the output Q is set (Q = 1). If J = 0 and K = 1, then in case of the positive pulse of the clock signal the output Q is reset (Q = 0). In the case when both of the inputs J and K are 1, then in case of the positive pulse of the clock signal the output Q is changing its state. And finally, when both of the inputs J and K are 0, then in case of the positive pulse of the clock signal the output Q doesn't change its state. The advantage of this circuit is that there is no unpredictable state as in the case of the RS flip-flop.
Picture 4: JK Flip-flop - symbol and table of truth
Logic Gates
Logic gates are electronics circuits which process logic signals. The values (states) of the logic signals are true or false, therefore they are represent in binary form with 0 and 1. There are two ways of representing these values, one is so called positive logic - where 0 = false and 1 = true, and the other is so called negative logic - where 0 = true and 1 = false. Normally the positive supply voltage (+Vs) represents true or 1, and the negative or 0 V (this depends on the electronics technology used for logic gates circuits) represents false or 0.
Every logic gate execute some logic function. The basic logic gates are identified by their logic function, so we have NOT, AND, OR, NAND, NOR, XOR and XNOR gate. With different combination in connection of these logic gates, we can implement block that will be execute some more complex logic function. The simple logic function can be implemented with switches or diodes, for example, switches in series can perform AND function and switches in parallel can perform OR function.
NOT Gate
The NOT gate (also known as inverter) inverts the state of the input signal and send it to its output. If we have a true state on the input, then the output will have false state, and vice versa if we have a false state on the input of the gate, then the state of the output will be true. On the Picture 1 are shown the traditional symbol of NOT Gate, the table of truth which shows the state of the output for every possible state of the input and the logic function of the gate. The table of truth is a good way to represent the logic function of a gate. If IN = A and OUT = Q, then Q = NOT A, and this is actually the logic function of the NOT Gate.
Picture 1: NOT Gate - symbol, table of truth and logic function
AND Gate
The AND Gate executes the AND logic function with its inputs and sends the result to its output. An AND Gate can have two or more inputs, and its output is true only if all inputs are true. On the Picture 2 are shown the traditional symbol of AND Gate with two inputs, the table of truth and the logic function of the gate. If IN 1 = A and IN 2 = B, then Q = A AND B.
Picture 2: AND Gate - symbol, table of truth and logic function
OR Gate
The OR Gate executes the OR logic function with its inputs and sends the result to its output. An OR gate can have two or more inputs, and its output is true if at least one input is true. On the Picture 3 are shown the traditional symbol of OR Gate with two inputs, the table of truth and the logic function of the gate. If IN 1 = A and IN 2 = B, then Q = A OR B.
Picture 3: OR Gate - symbol, table of truth and logic function
NAND Gate
This gate is actually an AND Gate with the inverted output. An NAND gate can have two or more inputs, and its output is true if not all inputs are true. On the Picture 4 are shown the traditional symbol of NAND Gate with two inputs, the table of truth and the logic function of the gate. The inverted output is shown by the 'o' on the output. If IN 1 = A and IN 2 = B, then Q = NOT (A AND B).
Picture 4: NAND Gate - symbol, table of truth and logic function
NOR Gate
This gate is an OR Gate with the inverted output. An NOR gate can have two or more inputs, and its output is true if no inputs are true. On the Picture 5 are shown the traditional symbol of NOR Gate with two inputs, the table of truth and the logic function of the gate. If IN 1 = A and IN 2 = B, then Q = NOT (A OR B).
Picture 5: NOR Gate - symbol, table of truth and logic function
XOR Gate
The exclusive OR Gate executes the XOR logic function with its two inputs and sends the result to its output. The output is true if either input 1 or input 2 is true, but not when both are true or both are false. In other words, the output of XOR Gate is true if its two inputs are different. The XOR Gate can have only two inputs. On the Picture 6 are shown the traditional symbol of XOR Gate, the table of truth and the logic function of the gate. If IN 1 = A and IN 2 = B, then Q = (A AND NOT B) OR (B AND NOT A).
Picture 6: XOR Gate - symbol, table of truth and logic function
XNOR Gate
This gate is an XOR Gate with the inverted output. The output is true if both of the inputs are true or if both of the inputs are false. In other words, the output is true if inputs are same. The XNOR Gate can only have two inputs. On the Picture 7 are shown the traditional symbol of XNOR Gate, the table of truth and the logic function of the gate. If IN 1 = A and IN 2 = B, then Q = (A AND B) OR (NOT A AND NOT B).
Picture 7: XNOR Gate - symbol, table of truth and logic function
Subscribe to:
Posts (Atom)











