Homework 2
|
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.

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.
|
![]() |
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.
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


Questions
Sound
| \j2sdk1.4.1_03\bin\java -cp . -jar Tcp2Sound.jar TCP port: 888 TCP connections: 1 Channels: 1 Sample rate: 8000.0 Waiting for connection |

SIN(B1)+SIN(B1*3)/3+SIN(B1*5)/5+SIN(B1*7)/7
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.
Questions
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.
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.
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.
|
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.
working
correctly, retry double clicking. Questions
- How many different voltage levels are used? Not how many bits per character but how many different voltage levels.
- 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?
- What is the marking voltage, high or low (i.e. when no data received, the time when no characters are being sent)?
- 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.
- The number of samples that were taken from the beginning of the start bit and to, but not including the stop bit?
- What is the number of bits from the beginning of the start bit and to, but not including the stop bit?
- From the two earlier questions, what is the average number of samples taken per bit?
- 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?
- 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.

Document last modified: