Engineering Our Digital Future Student Lab Manual Copyright 2004-2005 The Infinity Project All Rights Reserved V1.1 : TA B L E C O N T E N TS OF Preface - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - i Introduction to Block Diagram Design - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - iii CHAPTER 1: THE WORLD OF MODERN Introduction - - - - - - - - - - - 1.0: Testing Your System - - - - 1.1: High-tech Demos - - - - - - - ENGINEERING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1-2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1-3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1-13 CHAPTER 2: CREATING DIGITAL MUSIC Introduction - - - - - - - - - - - - - - - 2.1: Plots of Speech - - - - - - - - - - - 2.2: Generating Sine and Cosine Signals 2.3: Listening to Sines and Cosines - - - 2.4: Measuring a Tuning Fork - - - - - - 2.5: Building the Sinusoidal MIDI Player - 2.6: The Spectogram - - - - - - - - - - 2.7: Sketch Wave with MIDI - - - - - - - 2.8: Sketch Waves with Envelope Functions 2.9: Echo Generator- - - - - - - - - - - 2.10: Sound Effects - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2-2 2-3 2-11 2-17 2-24 2-30 2-38 2-43 2-46 2-51 2-54 CHAPTER 3: IMAGE QUANTIZATION Introduction - - - - - - - - - 3.1: Image Quantization - - - 3.2: Image Sampling - - - - 3.3: Aliasing in Movies- - - - 3.4: Color Representation - - 3.5: Resolution Trade-offs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3-2 3-3 3-18 3-34 3-38 3-49 CHAPTER 4: MATH YOU CAN SEE Introduction - - - - - - - - - - - - - - - - 4.1: Brightness and Contrast - - - - - - - 4.2: Threshold and Negation- - - - - - - - 4.3: Adding and Subtracting Images - - - - 4.4: Adding and Subtracting Shifted Images 4.5: Sharpening Images - - - - - - - - - - 4.6: Edge Detectors - - - - - - - - - - - - 4.7: Averaging and Median Smoothing Filters 4.8: Design of an Object Counter - - - - - 4.9: Design of a Motion Detector- - - - - - 4.10: Design of a Blue Screen - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4-2 4-3 4-16 4-32 4-39 4-46 4-57 4-65 4-74 4-85 4-91 - - - - - - i : CHAPTER 5: DIGITIZING THE WORLD Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5-2 5.1: Aliased Sinusiods, Speech, and Music - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5-3 5.2: Quantization and Clipping - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5-17 CHAPTER 6: CODING INFORMATION FOR STORAGE AND SECRECY Introduction - - - - - - - - - - - - - - - - - - - - - - - - - 6.1: Speech Compression - - - - - - - - - - - - - - - - - - 6.2: Rotational Encoder and Decoder - - - - - - - - - - - - 6.3: Pseudo-Random Number Generator - - - - - - - - - - - - - - - - - - - - - - - - 6-2 6-3 6-7 6-13 CHAPTER 7: COMMUNICATING WITH ONES AND ZEROS Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 7.1: Audio Communication of Messages Using One Tone Per Letter - - - 7.2: Effects of Weak Signals and Noise - - - - - - - - - - - - - - - - - 7.3: Different Codes - - - - - - - - - - - - - - - - - - - - - - - - - - - 7.4: Audio Communications Using Several Simultaneous Tones - - - - - 7.5: Audio Communications Of Messages Using Serial Binary Transmission 7.6: Touchtone Telephone- - - - - - - - - - - - - - - - - - - - - - - - 7.7: Audio Communication Using Two Tones - - - - - - - - - - - - - - 7.8: How a Facsimile Works - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 7-2 7-3 7-12 7-15 7-17 7-22 7-26 7-29 7-32 CHAPTER 8: NETWORKS FROM THE TELEGRAPH TO THE INTERNET Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - 8.1: Multiple-User Network with Meshed Connections - - - - - 8.2: Multiple User Network Using a Single Router - - - - - - - 8.3: Multiple User Network Using Several Routers - - - - - - - 8.4: Multiple-User Network With Choice of Transmission Path - 8.5: Internet Performance - - - - - - - - - - - - - - - - - - - 8.6: Exploring the Internet - - - - - - - - - - - - - - - - - - - Appendix A: Troubleshooting Guide- - - - - - - - - - - - - - - Appendix B: Running MIDI-VAB Labs - - - - - - - - - - - - - - - - - - - - - - - - - - - 8-2 8-3 8-7 8-12 8-18 8-24 8-30 A-1 A-4 ii - - - - - - - - - - Engineering Our Digital Future - Student Lab Manual Preface The laboratory experiences and procedures described in this manual are designed to supplement the Engineering Our Digital Future textbook with hands-on interactive exploration of ideas and relationships from the text. Each laboratory from an Infinity Project Experiment box has a corresponding laboratory description with step-by step instructions. Although the individual laboratories on sounds or images or communications may focus on different topics, a common approach is used for all. Students can quickly create a laboratory design, test it, and improve it using the Infinity Laboratory Kit. The kit includes a SPEEDY 33 circuit board which has a digital signal processor (DSP) chip and two small microphones on it. A camera is included for video input, and a set of speakers can be connected to the DSP board. The kit also includes the Visual Application Builder (VAB) software which is used to create designs and then run them. The laboratories are based on a block diagram approach to problem solving that is used throughout the text. Big projects are broken up into several smaller functions or jobs, and each of these small jobs is individually more manageable than the one big job. Each small job is represented by a block, and blocks are connected to form the complete project or process. This approach works well on almost any large project whether it is an engineering design or planning a class picnic or producing a play. When all the small jobs are done well and the interactions between the small jobs are well planned, the larger project will be successful. This block diagram approach to design is widely used in engineering practice. It is powerful and efficient because it allows us to concentrate on what we want the project to do at a functional level. The blocks take care of many of the details of implementation for us. At a later time we might want to look at the details of how an individual block does its job to make the project better, but we do not have to worry about all the details of all the blocks before we can start. How to use this manual A basic laboratory experience has been designed for each laboratory described in the Engineering Our Digital Future textbook. In most cases a laboratory uses an interactive Visual Application Builder (VAB) worksheet with the SPEEDY 33 digital signal processing circuit board and a PC. A few of the laboratories use other typical computer resources such as a media player application. The easy-to-use basic laboratories demonstrate ideas and relationships described in the text, and complete step-by step instructions are provided for each. In some cases students and instructors may wish to use a basic laboratory as a starting platform for a more advanced project. Almost all of the basic laboratories have the potential to be extended in many directions depending on the amount of time available and the special interests of the class At the end of some of the laboratories there are optional additional procedures called Quantitative Investigations or Further Explorations. These either use the worksheets in a more quantitative way or modify the worksheet to have additional capabilities. These optional sections may be used as written or they may be skipped without loss of continuity. And like the basic laboratories, they may be extended even further for special class projects. The laboratories follow the development of the material in the text book and also grow in design sophistication as progress is made through the chapters. The first chapter of the text contains a broad overview to the rest of the book, and there are no specific laboratory experiences directly related to it. Instead, one of the simple installation test laboratories is used to demonstrate the basic techniques needed to modify worksheets and then run them. © Copyright 2004 The Infinity Project. All rights reserved. i Engineering Our Digital Future - Student Lab Manual Chapters 2 to 5 focus on designs that convert audio and image data to numbers and then analyze them or improve them or use them to create new audio and image data. In Chapters 6 to 8 more complex blocks are used for coding and communication. An important benefit of these laboratory experiences is that they provide a way to show concrete demonstrations, in the form of images or sound, of mathematical concepts that are often considered only in abstraction. For example, the order of operations or the application of the distributive law shown on paper may involve simply moving parentheses and combining factors. When operations are done in a different order on sound or images, it is much easier to see the result of the change. This helps build an intuitive understanding. The concepts of a function, a function of a function, and an inverse function are explored visually in Laboratory 4.2 in the form of a mapping from input image values to output image values. Concepts of digital data representation using a limited set of values are a basic part of most of the audio and image laboratories. When using these laboratories it is important to remember that they are engineering design laboratories and that engineering design includes science, mathematics, value judgments, and trade-offs between competing demands. For example, a project specification might call for high quality and low cost. But reducing cost at some level may cause an unacceptable reduction in quality, and different people may have different ideas about what is unacceptable. These laboratories include a combinations of analytical questions about observations which do have a well defined answer, and judgments about balancing competing requirements. While there may be no “right answer” to the judgment questions, students should always be able to justify their answers. It is often the challenge of balancing competing demands that leads to creative new solutions. Additional information about laboratories can be found at www.infinity-project.org. Acknowledgement The authors gratefully acknowledge the tireless efforts of John D. Norris for his technical support and Rosemary G. Aguilar for composition and formatting. Without their support this laboratory manual would not have been brought to fruition. ii © Copyright 2004 The Infinity Project. All rights reserved. Engineering Our Digital Future - Student Lab Manual Introduction to Block Diagram Design What is a block diagram and how is it used? A block diagram tells us what small jobs or processes we need in order to get a larger project done. Each block has a specific function to perform. Each block also has specific set of inputs and outputs. By connecting the output of one block to the input of another, we can have the combined function of both blocks. This allows us to take simple elements that are individually easy to understand and combine them to achieve a more complex goal. The selection of the specific blocks and the way they are connected determines how the larger project will operate and how well it will work. A block diagram describes all the small jobs that are needed, but it does not tell us exactly how to do each small job. For example, an engineer might decide that a particular block in a big project could be done best with a special custom designed circuit or with a general purpose computer program or with a mechanical device. The choice would depend on things like how well each of the methods works, how hard each is to do, and how much each would cost. In these laboratories our blocks will create instructions for the digital signal processing (DSP) circuit on the SPEEDY 33 board or for the PC. Both the PC and the external DSP board have very fast processors for computation, but they are designed to work best in different circumstances. The PC is the better choice for interaction with the user through the keyboard and mouse and display screen. It also can hold large amounts of data in the memory on its disk. In contrast, the DSP board is better suited for handling audio signals and producing outputs immediately without delays that are normally associated with PCs and PC software. In some cases, such as laboratories using images, the blocks in our block diagram will use the PC. In other cases, for example when audio signals are used, the blocks will use the SPEEDY 33 DSP board. Although we normally keep the DSP board connected to the PC, it is possible to load instructions into the DSP board and then disconnect it so that it can run independently from the computer. This is important when the project must be small and mobile like a cellular telephone or most robotics applications. How does a block diagram make instructions for the PC or the DSP board? The Visual Application Builder (VAB) software allows us to quickly make block diagrams on a computer screen worksheet with a simple graphical editing method. We can select blocks from a library that do the jobs we need and then place these blocks on the worksheet. After we have connected the inputs and outputs of the blocks on the worksheet, we have a visual block diagram of our complete process. The VAB automatically converts the blocks from our block diagram into instructions for the PC or the DSP board. When we start our worksheet, the PC and DSP board will execute those instructions and perform the functions our block diagram describes. Suppose, for example, we want to simply connect a sound input from a microphone to a set of speakers so we could hear the sound. First we would select a microphone block and a speaker block from the library and add them to our worksheet. Then we would draw a line from the microphone output to the speaker input to make the connection. That would complete our design. After starting the worksheet, whatever sound was picked up by the microphone would be heard coming from the speakers. If we wanted to add sounds together or change the sound from the microphone, we would put more blocks between the microphone and speaker. Blocks used in these laboratories © Copyright 2004 The Infinity Project. All rights reserved. iii Engineering Our Digital Future - Student Lab Manual Every block has a well defined function or job. It also has a well defined set of inputs and outputs. For example, a block might have two inputs, a number and an image. Sometimes blocks also have parameters or control inputs which can change the function of a block. A block could be as simple as an adder block which adds its two inputs together to create an output sum. We can have an adder block for sounds or an adder block for images. A block can also perform a complex function such as analyzing an image sequence to find the locations where there is motion. Most projects that are interesting respond to the world we experience and cause something to happen in the world we experience. So in addition to simple and complex processing blocks, we also need input and output blocks. These blocks are very important because they transfer audio and image information between the DSP board and the outside world. Input Blocks: Blocks which have no inputs on the worksheet represent input devices. That means that the block input comes from outside VAB as described below. The VAB has a variety of input blocks. • • • • • A microphone block has an input from the sound in the air around it. The block includes both the connection to the physical microphone, which converts the pressure variations in the air around it to electrical signals, and the electronic circuit on the DSP board which converts the electrical signal into a sequence of numbers. The microphone block creates an output signal, which is a sequence of numbers, for use as an input by other blocks in a worksheet. A camera is also an input device. Its input comes from the light that falls on the camera's sensors, and its output is a set of numbers defining the content of an image. A block that reads from a stored data file can be used as an input block for sounds and images. A keyboard gets its input from the keys you type. Its output is a string of characters that can be used by other blocks A block can also get its input from a mathematical operation. For example, an input block can use a cosine function to create a cosine signal for other blocks to use. Output Blocks: Blocks which have no outputs on the worksheet represent output devices. That means that whatever output the block produces goes outside VAB as described below. The VAB also has many different kinds of output blocks. • • A speaker is an example of an output device. Its input is a signal or sequence of numbers from the output of some block on the worksheet. Its output is the sound we hear from the speakers. The block includes both the circuit which converts a sequence of numbers into an electrical signal and the connection to the physical speakers that produce the sound from the electrical signal. Visual output blocks include image displays, plots of graphs, and numeric or text displays. Simple rules for connecting blocks: Blocks can be connected to build a worksheet using a few simple rules. • • • iv Wires drawn between blocks represent information that is produced by one block and used by the other. A wire can carry an audio signal or an image or a simple number. This means that the input of a block should be connected to the output of another block that is of the “same type.” Only one wire can be connected to each input of a block. The output of a block can be connected to inputs of many blocks. © Copyright 2004 The Infinity Project. All rights reserved.