Homework 2
Physical and Data Link Layers 

powered by FreeFind

Modified: 


Overview The purpose of the homework is to develop an intuition about data representation when carried over a medium such as wire and how bits are physically represented on a medium, useful for understanding the physical layer of communication protocols. The homework is also designed to introduce basic networking features using the Java language necessary to implement networked applications at key points in this course.

Waves are the data carriers of communications. Sound is carried by waves that travel through a medium such as air, water, or many solids. Electrical waves are used for communication over wire and many other mediums, light waves are carriers over optical mediums. Two common wave characteristics used in representing data is amplitude and frequency modulation. 

Amplitude of a loud sound is greater than a quite sound. Frequency of a high pitched sound is greater than a low pitched sound. The figure below left illustrates a sine wave with amplitude from -1 to 1 and frequency of 4 Hertz (Hz.) or 4 wave cycles per second. A 4 Hz. sound would be a very low frequency monotone below the normal human hearing level. Modulating the frequency as in the figure below right allows one group of waves to be distinguished from another, for example, the three narrow waves stand out from the other waves. The three narrow waves occur in the same time period as one of the wider waves or with a frequency three times greater. Since the longer, lower frequency waves have a frequency of 4 Hz. the narrow, 3 times higher frequency waves have a frequency of 12 Hz. Using frequency modulation for carrying binary data, the higher frequency waves might represent a 1 and the lower frequency waves represent a 0 so that the right graph could represent 01002.
 

 

Sound waves from a human voice are more complex than data carrying waves because we modulate both frequency (i.e. pitch) and amplitude (i.e. volume) simultaneously. A few of the sound waves produced when the instructor yodels are in the figure below. 


Assignment 1

Overview

The assignment purpose is to develop some intuition about sound wave characteristics to help in understanding waves in general. Sounds that you make will be sampled and digitized into a spreadsheet for analysis of wave frequency. An analysis tool called the Fast Fourier Transform (FFT) after the mathematician Jean Baptiste Fourier (who developed the mathematics about two hundred years ago) will be used to determine the spectrum of frequencies making up a sampled sound.

Analog to digital conversion - Though we consider data as a fixed binary value in fact it exists in a changing analog form of a voltage level, frequency, etc. Using a wire medium, data can be represented by analog voltages that must be converted into a corresponding binary number. For example, we can define the analog +1 to -1 voltage to digital data as in the following table where a -1 volt corresponds to a binary 00, -0.5 volts at 01, etc. The analog voltage is sampled at some regular interval and  converted to the corresponding binary value by an analog-to-digital converter. Recall from the text that a signal frequency of 2000 Hz. requires sampling at 4000 samples per second (double the signal frequency) to reconstruct the original signal.
 

Analog 
Voltage
Digital
Data
-1 00
-0.5 01
+0.5 10
+1 11

The figure below is a screen shot of a spreadsheet after sampling the sound of the instructor's voice for a period of 0.2048 or about 1/5 second. The number of samples taken were 2048 and the samples were taken at 0.0001 second intervals, 2048*0.0001 sec.=0.2048 sec. The digitized sound recorded from the microphone is displayed in the chart at top left of the spreadsheet.

The lower right frequency power spectrum chart displays the FFT analysis of that sound. The power spectrum details the relative contribution of each frequency to the wave where the major frequency component of the sound analyzed is about 9 (i.e. the highest point of the graph) occurring at about 420 on the FFT chart which is a frequency of about 2050 Hz. A frequency is calculated from the power spectrum graph by dividing a value from the X-axis of the chart by the duration of the sample. From the power spectrum, the sampled frequency of 420 waves per 0.2048 sec. (i.e. 420/0.2048=2050 Hz.). Other frequency components contribute relatively less to the overall sound as indicated by their smaller power value.

Equipment - In LF-111A

  1. Excel and spreadsheets for analyzing waves.
  2. Proto-Board digital designer.
  3. Analog-to-digital converter.
  4. Microphone.
  5. Computer in LF-111A labeled Sound/Generator.
  6. Sound source such as a musical instrument, your voice, ...

Procedure

There are two parts to the assignment, the first part analyzes a pure signal of a sine and square wave using the Generator , the second part analyzes the sounds of your voice and a tuning fork using the Sound.

Generator

  1. Locate a computer marked Generator.
  2. Download Generator spreadsheet by right clicking and saving.
  3. Start Excel. 
    1. Enable macros by:
      1. Tools | Macro | Security | Low
    2. Open the spreadsheet just saved.
  4. Make sure the Tcp/Comm server is running. It automatically starts when the machine is booted - you can minimize but do not close it. It should appear as at right. 
  5. To generate and analyze a signal:
  6. To perform the FFT:
  7. To calculate the frequency off the graph:
  8. Repeat Steps 4-6 except:

Questions

  1. How many obvious peaks could be distinguished in the FFT graph of the sine wave? 
  2. What was the frequency at the highest peak of the sine wave FFT?
  3. How many obvious peaks could be distinguished in the FFT graph of the square wave?
  4. What was the frequency of the three highest peaks of the square wave FFT?
  5. Was it obvious that the square wave FFT included the frequency of the sine wave and many lower peak sine wave frequencies? 
  6. Divide the FFT frequency of the highest peak (fundamental frequency) into the frequency of the next two highest peaks. Explain the resulting numbers.

Sound  

  1. Locate a computer marked Sound.
  2. Download Sound spreadsheet by right clicking and saving.
  3. Start Excel. 

    Click Play on the spreadsheet to play the square data in column A. The yellow box with show Playing while data is played and Done when finished.

  4. Tuning fork - The tuning fork generates a single frequency sound wave when lightly struck.
  5. Singing/Humming/Croaking
  6. Turn OFF the microphone when done otherwise the battery will run down.

Questions

  1. What is the fundamental frequency of the tuning fork? Is the tuning fork a single frequency, that is how many peaks?
  2. What was the fundamental frequency for your lowest voice? How many peaks (harmonics)?
  3. What was the fundamental frequency for your highest voice? How many peaks (harmonics)?

Turn In


Assignment 2

Overview

The purpose of the assignment is to gain insight into how low-level binary data is reliably transmitted over a wire medium. The assignment will examine in detail the physical layer protocol  for serial data communications using the RS-232-C standard. The attraction of this protocol is that it is relatively simple to understand, operates at a relatively slow rate to allow observation with inexpensive instruments, and is ubiquitous.

Networks consist of two or more devices connected in some way to communicate and usually share resources. A simple, point-to-point computer network is illustrated at right where two computers' serial interfaces are wired together so that each can receive what the other transmits. Note that as with a telephone where the talker's mouth-piece and listener's ear-pieces are connected so it is that the transmit of one computer is connected to the receive of the other. This particular wiring scheme is aptly known as a null modem because the short distance wire connections eliminate the need for two connecting modems. Two wires are required for two-way communication using the serial port, one for each computer to transmit to the other. The ground wire provides a common ground reference for the signals.

Serial data communication simply means that data bits are transmitted one after the other over a single wire or other medium. Most networks use only a single medium due to the expense of connecting more than a single wire between two distant points. Cutting your telephone cord would reveal only two wires, one for talking and one for listening. We speak serially, rather than making all sounds of a word at once, we string the sounds together in a specific order. Your ear is another example of a serial device since sound waves arrive and are processed one after another. Speech and hearing do handle multi-frequency signals, allowing us to speak and hear a large frequency range of sounds simultaneously, and multi-amplitude signals, allowing us to speak and hear a large range of volumes.

Physical devices for telephone communication are the wire and telephone as compared to the dial tone or busy signal. Physical devices of our simple computer network examined here are the wire and the serial interface hardware. Generally, any hardware concerned with transmitting and receiving bits are lumped together into the network physical layer.

Data link layer of a network sends and receives bits to and from the physical layer. The bits for a single character arrive serially or one after another and, for serial communications, are often assembled into an eight bit character by the data link layer. A common function of the data link layer is to detect and possibly correct transmission errors. A parity bit is often added for error detection in serial communication.


Physical and Data Link Layer of Serial Interfaces - Serial interfaces of computers generally follow the RS-232-C standard specifying the physical layer for mechanical connection, voltage levels and circuit definition of the communication channel. The channel usually directly connect only two machines at a time, an example of a point-to-point connection.

Binary representation - Digital data can be represented in a binary format. For RS-232-C standards, each character is transmitted as a series of positive and negative voltages corresponding to binary 0 and 1. To send a character S having ASCII code 010100112  the sending computer serial port hardware converts each data bit into a voltage. For typical RS-232-C interfaces the voltages may range from -12 to +12 volts. Observing the sending wire voltage with an oscilloscope one might record voltages for the character S of:

+12 -12 +12 -12 +12 +12 -12 -12
    0   1     0    1    0     0    1    1   = S

Sending a single S seems simple enough but suppose that S A Y was sent. The bits would be:

01010011 01000001 01011001
      S           A             Y

which, because of the added spaces that frame each letter's bits, is still obvious to us which bits form each letter. But remove the spaces and it becomes more difficult to distinguish:

010100110100001101011001

No data - Also, consider that the computers are not always sending data but some voltage must still be present on the wire so that either a 1 or 0 is always on the wire. If 1 is used to represent no data, the SAY characters would appear on the wire as:

111111111101010011010000110101100111111111

making it even harder to pick out the data. Adding spaces to frame the data helps us see where data starts and stop:

1111111111 01010011 01000001 01011001 11111111
No data              S               A               Y           No data

Start and stop - Part of the serial interface's job is to frame the bits of each data, using a start bit to indicate the start of the data, and a stop bit for the end of the data. Remember that the start and stop bits are 1 or 0 just like the data. If you have setup a modem on a computer you may be familiar with these terms. Logically, if a 1 is used for no data a 0 must be used for the start bit in order to distinguish between no data and the start of data. The stop bit separates data items (e.g. 'S' followed by and 'A') so it must be distinguishable from a following start bit by having the opposite value, hence it is a 1, the same as no data. Using the start and stop bits the SAY now would be sent as a stream of bits (B designates the start and E the stop bit):

1111111111 0 01010011 1 0  01000001 1 0 01011001  1 11111111
     No data    B       S         E  B    A             E B     Y            E  No data

Baud rate - The start bit marks the beginning of the sender's data. From the start bit the receiver can count to determine when to read each data bit. The baud rate  defines the time each bit exists or the time to wait between reading (or sending) bits. For RS-232-C a baud rate of 10 means 10 bits could be sent each second which includes start, data, and stop bits. Each bit would then exist for 1/10 second. To read the data sent, the receiver detects the start bit, waits 1/10 second, read a data bit, wait 1/10 second read another data bit, etc. The start bit then serves to synchronize the sender and the receiver, since each have their own clock used to send and receive bits and the clocks which may drift apart during periods when no data is being sent (i.e. a long series of 1111111111's).

Parity - If the physical layer operated perfectly, the start, data, stop bit format would work error free. Unfortunately, most mediums including wire have physical characteristics (it acts as an antennae, capacitor, resistor, etc.) that make it a less than perfect medium. Error detection is usually added by the serial interface hardware in the form of a parity bit for each data item sent. Parity can be computed in a number of ways. Even parity means that the number of 1's in the data and the parity is an even number. It can be computed by counting the number of 1's in the data and if even number of 1's  the parity is 0, if an odd number of 1's the parity is 1. The code 010100112 for the letter S has four 1's so for even parity the parity bit is 0.

Data transmission - The following example illustrates transmission of character 'S' encoded using the ASCII specification. The ASCII code for 'S' is 010100112 which, by protocol, is sent reversed as 11001010 in a serial fashion, one bit following another. The even parity of 010100112 is a 0. A 0 bit is represented by a high voltage, a 1 bit by a low voltage. Time is represented as moving from left (earlier) to right (later), the start bit B is sent before the stop bit E.
 

                                           _      _____
Volts  _______|  |___|        |  |  |   |        |_____________
       1  1  1  1  0  1  1  0  0  1  0  1  0   0   1  1  1  1  1  1  1
      No data    |B|  Data 'S' ASCII code |P | E|    No data          
                                time-->                  
                                   
          B = Start bit (opposite of no data representation).
          P = Parity bit (0 as even number of 1's in ASCII 'S' code).
          E = Stop bit (same as no data representation).

Local area networks typically communicate over a broadcast medium where more than two machines can connect to the same medium simultaneously, requiring additional protocol to determine which machine can transmit exclusively and addressing to the specific receiver interface. Ethernet interfaces sense when others are transmitting and wait until the medium is clear before transmitting. Token ring interfaces pass a token from one interface to the next and only transmit when in possession of the token. Local area network data, addressing and other bits are still generally represented as differences in voltage levels or amplitude similar to RS-232-C.


Data Link Layer The 0's and 1's of the RS-232-C  physical layer correspond to the following format:

The data link layer generally is responsible for sending and receiving bits in the proper order, framing the data (e.g. start and stop bits) and checking for errors.  The physical layer simply delivers the bits across some medium. Note that different formats exist that vary the number of data bits, parity (i.e. even, odd or none) and number of stop bits. Obviously, both the RS-232-C sender and receiver data link layers should use the same protocol and parameters for successful communication.


Assignment 2 - Data Framing

The assignment sends characters arriving on an Internet connection out the computer's serial port. The data is transmitted out the serial port as a series of high and low voltages corresponding to the bits of the character and control bits for framing and error detection. An analog-to-digital converter receives the voltages and reports the voltages back over a second Internet connection read by an Excel spreadsheet VBA program. These voltages are graphed in Excel to identify each start, stop, parity, and data bit similar to the overview example above. The computer is www.csci.ius.edu located on campus.

Equipment/Software

  1. Serial computers in LF-111A
  2. Java

Procedure

The general idea is to send some characters out the serial port and measure the corresponding voltage levels.

Sending characters

The following sends characters to a server program which outputs the characters to the serial port. The computer is www.csci.ius.edu located on campus.

  1. Locate a computer marked Serial.
  2. Copy and paste the following Java program into a file named sender.java
  1. Compile and execute by the following:

One thousand 'S' characters should be sent to the serial port of the computer though it won't be obvious yet. The sender is probably working OK if  "Client closed connection" is printed after about 20 seconds, since it connected and sent 1000 'S' characters then disconnected.

Graphing Characters

Recall that your Java sender.java program sends characters to a server program which outputs the character out the serial port. The LabPro analog-to-digital converter measures the voltage for the bits received which can be read by Excel and graphed.

  1. Download Serial spreadsheet by right clicking and saving.
  2. Start Excel. 
    1. Enable macros by:
      • Tools | Macro | Security | Low
    2. Open the spreadsheet just saved.
    3. Change Samples to 300.
    4. Right click on the Signal graph. Change Source Data to Data Range =Sheet1!A1:A300.
  3. With the sender.java program running:
    1. Double Click in a spreadsheet cell to record the characters. The yellow box will show Working while data is being recorded and Done when finished. 
    2. In a few seconds the data should be graphed in the Signal chart similar to at right. If nothing new is graphed something is not working correctly, retry double clicking. 
    3. It may take several run attempts to "catch"  characters sent by the sender.java program. It will be obvious that a character has been detected when the graph has a signal with square waves of high and low voltages displayed. If the graph displays garbage or no voltage, either keep trying to catch a character by transmitting more 'S' characters at a time.
    4. On the plot notice that periods when no data voltage is transmitted predominate. Find the start bit of a character and locate the bits of one character (ASCII representation of an 'S' in binary is 01010011). Remember that the left-most bit is sent first, with start bits and even parity  0 1 1 0 0 1 0 1 0 0 .

Questions

  1.  Capture the character 'S'.
  1. How many different voltage levels are used? Not how many bits per character but how many different voltage levels.
  2. The ASCII code for 'S' is 01010011. From the graph, what are the observed voltages for a 0 and for a 1, high or low?
  3. What is the marking voltage, high or low (i.e. when no data received, the time when no characters are being sent)?
  4. The number of samples that were taken of the start bit alone? Use the mouse to point to the beginning and end of the start bit. Due to sampling vagrancies, this will often vary by one sample, more or less.
  5. The number of samples that were taken from the beginning of the start bit and to, but not including the stop bit?
  6. What is the number of bits from the beginning of the start bit and to, but not including the stop bit?
  7. From the two earlier questions, what is the average number of samples taken per bit?
  8. One sample is taken every 0.0001 seconds. How long was required to transmit bits from the beginning of the start bit and to, but not including the stop bit?
  9. Given the following table of bits per second that can be transmitted, what is the actual baud rate of the serial port transmission? Possible transmission rates are: 50, 75, 110, 134.5, 150, 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600.
  1. In the sender.java program, modify to send one of your initials instead of the 'S' in the remaining questions. Capture your initial.
    1. Print the graph of one complete character.
    2. On the graph, for one character, label each bit as start, stop, parity, and data bits. Indicate the character sent.
  2. Give a  diagram (hand drawn) of the connection between the two computers in the figure at right showing pin number, code, and function of an RS-232-C interface for a DB-25 pin connector. You can find the information by searching the Internet for "RS-232 pin-out".

Turn In



Document last modified: