

\documentclass[11pt]{article}

\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0.5in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.1in}

\usepackage{times}
\usepackage{psfig}
\usepackage{fancyheadings}

\begin{document}

\pagestyle{fancy}
\cfoot{Physical Layer: \thepage}   

\title{Computer Networks:  the Physical Layer}

\author{Norman Matloff \\
Dept. of Computer Science \\
University of California at Davis\\
        \copyright{}2001, N. Matloff}                      

\date{April 17, 2001}

\maketitle

\section{Goals of This Unit}

In this unit we will look at the physical properties of media which are
used in computer networks.  Our main emphasis is on the capacity of a
network, meaning the maximum number of bits per second which can be
loaded onto it.  We will use the mathematical technique of {\bf Fourier
series} to illustrate the role of {\bf bandwidth} in our network and in
our data.

This will help not only to understand the physical limitations of
networks, but also to lay the groundwork for our later unit on
{\bf multiplexing}. 

\section{Media}

Network signals might be propagated through {\bf guided} media
such as metal wires (twisted pairs, coaxial cable, etc.) or optical 
fibers (flashing light, off for 0, on for 1), or in free space, such 
as with radio waves or microwaves. 
  
\section{Signal Types}

A signal may be in {\bf digital} form, e.g. 0-1 bits with a low
voltage meaning 0 and a high voltage meaning 1.  The graph of
a digital signal over time has a ``square wave'' shape.

On the other hand, {\bf analog} forms look ``wavy.''  A modem, 
for instance, sends a low-pitched sound for a 0 and a high pitch 
for a 1; the sounds themselves look like sine waves when graphed 
against time.

\section{Data Types}

Just as the signals of interest can be either digital or analog,
the data encoded by those signals could be either digital, such
as numbers or characters, or analog, such as voices.

Either type of data can be encoded within either type of signal.
We noted above, for instance, that a modem encodes digital data
onto analog signals.  Voice data, on the other hand, though inherently
analog, can be {\bf digitized}:  A person's voice graphed against 
time is a continuous curve, but we can sample it at regular intervals, 
typically 8,000 times per second.  At each sample point, we record 
the numerical height of the curve (i.e. the numerical value of the 
loudness).  This gives us numbers, which comprise digital data.
These can be stored in a disk file as with a game program, 
sent through the Internet as with Real Audio transmission of
radio programs, and so on.

\section{Spectral Analysis}

Recall from calculus that we can write a function x(t) as a
Taylor series, which is an ``infinite polynomial'':

\begin{equation}
x(t) = \sum_{n=0}^{\infty} c_n t^n 
\end{equation}

For instance, for $e^t$,

\begin{equation}
e^t = \sum_{n=0}^{\infty} \frac{1}{n!} t^n
\end{equation}

Recall also that we say a function x(t) (where t is time) is 
{\bf periodic} with period T if if x(u+T) = x(u) for all u.  
The {\bf fundamental frequency} of x is then defined to be the
number of periods per unit time, 

\begin{equation}
f_0 = {1 \over T }
\end{equation}

Suppose x(t) is a digital or analog periodic signal transmitted in 
some medium.  We can write x as an ``infinite 
trig polynomial,'' i.e. a {\bf Fourier series}:
 
\begin{equation}
x(t) = {\sum_{n=0}^{\infty } {a_n} \cos ( 2 \pi n  f_0 t)} +
{\sum_{n=1}^{\infty} {b_n} \sin ( 2 \pi n f_0 t)}
\end{equation}

Here, instead of having a series of terms 

\begin{equation}
1 ,\  t ,\  t^2 ,\  t^3 ,\ ...
\end{equation}

as in a Taylor series, we have a series of terms

\begin{equation}
1 ,\  \cos (2 \pi f_0 t) ,\  \cos (4 \pi f_0 t) ,\  \cos (6 \pi f_0
t),\  ...
\end{equation}

and similar sine terms.  Note that the frequences in those cosines are
integer multiples, called {\bf harmonics}, of the fundamental frequency
of x, $f_0$.

The set of coefficients \{${a_n}$\}, \{$ {b_n}$\} is called the 
{\bf frequency spectrum} of x.\footnote{We can also write x as an
\underline{integral} of trig functions, rather than a sum of such
functions. Then the spectrum is a continuous range of numbers,
rather than the discrete points $a_n$ and $b_n$.  We will not
pursue this point here.}  The coefficients are calculated as
follows:

\begin{equation}
a_0 = \frac{1}{T} \int_0^T x(t) dt
\end{equation}

\begin{equation}
\label{eight}
a_n = \frac{2}{T} \int_0^T x(t) cos(2 \pi n f_0 t) dt
\end{equation}

\begin{equation}
b_n = \frac{2}{T} \int_0^T x(t) sin(2 \pi n f_0 t) dt
\end{equation}

In other words, suppose x(t) is the loudness of your voice at time t.
Your voice is a sum of components at various frequencies, and $a_n$ and
$b_n$ represent the loudness of the n-th frequency.

Because of the periodic nature of the functions involved, we can
shift the range of integration by equal amounts on the lower and
upper bounds, and it is often convenient to do so.  Any lower and upper
bounds which differ by the amount T will give the same answer.

For example, consider cases in which the function x(t) is symmetric
around 0.  Then it is natural to take our lower and upper bounds to be
-T/2 and T/2, for the following reason.  Note that the sine function is
\underline{anti}-symmetric, i.e.  sin(-t) = -sin(t).  This implies that
$x(t) sin(2 \pi n f_0 t)$, the integrand in

\begin{equation}
b_n = \frac{2}{T} \int_{- \frac{T}{2}}^{\frac{T}{2}} x(t) 
sin(2 \pi n f_0 t) dt
\end{equation}

will also be anti-symmetric.  That implies that we know without even
performing the calculation that $b_n = 0$, so we have saved ourselves
some computation.

Note that the $a_n$ and $b_n$ are independent of our bit rate.  Here is
how to see this:  Suppose for example that we were to send the same
signal but at half the bit rate, say because we changed modems.  Call
the new signal y(t) and the new period T'.  Then y(t) = x(0.5t), and T'
= 2T.  The period in terms of numbers of bits has not changed, but the
time to send those bits has doubled.  

Then for example

$$
a_n = \frac{2}{T'} \int_0^{T'} y(t) cos(2 \pi n \frac{1}{T'} t) dt
$$

If one uses the facts that y(t) = x(0.5t), and T' = 2T, and then one
does the change-of-variable u = 0.5t, we find we get the same integral
for $a_n$ as before, in Equation (\ref{asubn}).

The intuition here is that although the graph of the curve y(t) would
be a ``stretched out'' version of x(t), it would still have the same
shape, and the same weighting would occur for all the sine and cosine
terms.

All this assumes a periodic signal.  But strictly speaking, the signals
we send are not periodic.  Consider, for example, a text file transfer,
transmitted as a digital signal.  The characters in the file do not
follow a periodic pattern, and thus the bits we send do not follow a
periodic pattern, and the graph of the signal against time will not be
periodic.  However, for the purpose of analyzing the speed capacity of a
given physical medium to transmit the data, we can imagine the signal to
be periodic.  If for instance the text file includes the sentence ``The
quick brown fox jumped,'' we can ask how fast the medium could transmit
the corresponding signals if the sentence were to be transmitted again
and again (resulting in periodic signals).  And for voice data
transmitted in analog form, for instance, the signals are periodic
during short time intervals.

\section{Bandwidth:  How to Read the {\it San Francisco Chronicle}
Business Section}

The popular press, especially business or technical sections, will often
use the term {\bf bandwidth}.  What does this mean?

Any transmission medium has a natural range [$f_{min}$,$ f_{max}$] of
frequencies that it can handle well.  For example, an ordinary
voice-grade telephone line can do a good job of transmitting signals of
frequencies in the range 0 Hz to 4000 Hz, where ``Hz'' means cycles per
second.  Signals of frequencies outside this range suffer fade in
strength, i.e are {\bf attenuated}, as they pass through the phone line.
We call the frequency interval [0,4000] the {\bf effective bandwidth}
(or just the {\bf bandwidth}) of the phone line.

In addition to the bandwidth of a {\bf medium}, we also speak of the
bandwidth of a {\bf signal}.  For instance, although your voice is a
mixture of many different frequencies, represented in the Fourier series
for your voice's waveform, the really low and really high frequency
components, outside the range [340,3400], have very low power, i.e.
their $a_n$ and $b_n$ coefficients are small.  Most of the power of your
voice signal is in that range of frequencies, which we would call the
effective bandwidth of your voice waveform.\footnote{This is also the
reason why digitized speech is sampled at the rate of 8,000 samples per second.
A famous theorem, due to Nyquist, shows that the sampling rate should be
double the maximum frequency.  Here the number 3,400 is ``rounded up''
to 4,000, and after doubling we get 8,000.}

Obviously, in order for your voice to be heard well on the other end of
your phone connection, the bandwidth of the phone line must be at least
as broad as that of your voice signal, and that is the case.  However,
the phone line's bandwidth is not much broader than that of your voice
signal.  So, some of the frequencies in your voice will fade out before
they reach the other person, and thus some degree of distortion will
occur.  It is common, for example, for the letter `f' spoken on one end
to be mis-heard as `s'on the other end.  This also explains why your
voice sounds a little different on the phone than in person.  Still,
most frequencies are reproduced well and phone conversations work well.

On the other hand, dogs have a hearing range which extends about twice
as high as that of humans.  Since the bandwidth of a phone line was
designed to only cover most of the frequency range of human voice,
then there are sounds which a dog would hear clearly at the scene
of the sound, but which the dog could not hear if listening to that
scene over the phone. 

We often use the term ``bandwidth'' to literally refer to width, i.e.
the width of the interval [$f_{min}$,$ f_{max}$], $f_{max} - f_{min}$. 

There is huge variation in bandwidth among transmission media.  As we
have seen, phone lines have bandwidth intervals covering values on the
order of $10^3$.  For optical fibers, these numbers are more on the
order of $10^{15}$.  Suppose that for a given medium $f_{min} = f_0$ and
$f_{max}$ = N $f_0$.  Then the signal 

\begin{equation}
x(t) = {\sum_{n=0}^{ \infty } {a_n} \cos ( 2 \pi n  f_0 t)} +
{\sum_{n=1}^{ \infty } {b_n} \sin ( 2 \pi n f_0 t)}
\end{equation}

is in effect truncated by the transmission medium to 

\begin{equation}
x_N(t) = {\sum_{n=0}^{ N } {a_n} \cos ( 2 \pi n  f_0 t)} +
{\sum_{n=1}^{ N } {b_n} \sin ( 2 \pi n f_0 t)}  
\end{equation}

i.e. an error is made and x(t) is distorted.  The larger N is, the less
distortion.  For any given signal, the higher $f_{max}$ of the
transmission medium, the less distortion.\footnote{Or, if we fix a level
of quality we consider acceptable for a received signal, the larger N
is, the more signals we can {\bf multiplex} onto the given medium.  This
will be explored later.}

Now from calculus, for any given signal x(t),
${a_n},{b_n} \to 0$ as\  $n \to \infty$.

Thus, the $a_n$ and $b_n$ get small after a while, say, after $a_M$ and $b_M$.
So,

\begin{equation} 
x(t) \approx 
{\sum_{n=0}^{ M } {a_n} \cos ( 2 \pi n  f_0 t)} +
{\sum_{n=1}^{ M } {b_n} \sin ( 2 \pi n f_0 t)} 
\end{equation}

As long as we send x(t) along a transmission medium for which
$N \geq M$, x(t) will be received with reasonable fidelity.

\section{Effect of Bandwidth on Transmission Rates}

In order to get an idea of the relation of bandwidth to transmission
rate, suppose we are sending the bit pattern 101010101010..., and that
in our transmission medium a level (say volts, tenths of volts, or
whatever), a 1 represents a 1 bit and a -1 represents a 0.  Note that we
are just using 101010101010... as an example; our transmission medium
must be able to send all bit patterns.  But we will use this one to
illustrate the issues involved, so we can see the how the bandwidth of
our transmission medium limits how fast we can send bits.

Suppose we are sending at the rate of $2 \times 10^6$ bits per second.
What will be the period for the signal 101010101010 above?  In terms of
bit times, the period is two bit times.  How much is that in seconds?
At our 2 million bits/sec rate, each bit takes 0.5 millionths of a
second, i.e. 0.5 microsecond.  Thus our period is T = 1 microsecond, and
the fundamental frequency $f_0$ is 1 megaherz (MHz, i.e. million cycles
per second).  (Recall that the fundamental frequency is the number of
periods per unit time.)

The period consists of two bit times, specifically one 1 bit and one 0
bit, each taking T/2 time to transmit.  We could describe x(t) as having
the value 1 from 0 to $\frac{T}{2}$, the value -1 from $\frac{T}{2}$ to
T, and so on, repeating in this manner from $- \infty$ to $\infty$.

Using the formulas, we find that all $b_n$ will be 0, and all even-numbered
$a_n$ will be 0.  Thus we need only calculate the integrals for
$a_1, a_3, a_5$ and so on, using equation (\ref{eight}), and these
coefficients turn out to be $\frac{4}{\pi}, -\frac{4}{3\pi},
\frac{4}{5\pi}$, et cetera.

Note that since $f_0$ is 1 MHz, these nonzero coefficients will be 
for cosine terms with frequencies 1 MHz, 3 MHz, 5 MHz, et cetera.
Now suppose our transmission medium only transmits frequencies 
up to 5 MHz.  Then even though we place onto our transmission
medium x(t)---a squarewave with values 1, -1, 1, -1, etc.---the
medium will distort x(t) to the function

\begin{equation}
\frac{4}{\pi} 
[cos(2 \pi \cdot f_0 t) - 
\frac{1}{3} cos(2 \pi \cdot 3 f_0 t) + 
\frac{1}{5} cos(2 \pi \cdot 5 f_0 t)]
\end{equation}

Using microseconds for our horizontal axis (since T = 1 microsecond), 
a plot of this series would look like this:

\vspace{0.2in}
\par
\psfig{file=Sine5.PS}
\par      

So, even though x(t) is distorted, the result is not a bad approximation
to the original waveform!  We could design circuitry that would be able
to distinguish well between a 1 bit and a 0 bit in this
case.\footnote{Of course, this is not accounting for other factors, such
as further distortion of the waveform, such as by line noise.}  For
example, we could design the receiver to treat any signal which is
greater than 0.8 during 80\% of a bit time as a 1, and any signal which
is less than -0.8 during 80\% of a bit time as a -1.

In other words, a medium which transmitted all frequencies up to
5 MHz would be able to successfully send a 2,000,000 bit rate, or at
least for the bit pattern we have looked at here, 101010... 

{\bf The point of all this is that the bandwidth of the transmission
medium determines the maximum bit rate at which one can send.}  If
the transmission medium only passed frequencies up to 4 MHz, we
would only get two cosine terms, and thus a much poorer approximation
to x(t), maybe so poor that it would produce bit-recognition errors;
we would thus probably be forced to transmit at a lower rate.

Likewise if we retain the medium with bandwidth 5 MHz but double our
bit rate to 4,000,000 bits per second, we will have the same 
$a_n$ and $b_n$ (recall our earlier discussion that the $a_n$ and $b_n$ are
independent of the bit rate), but $f_0$ would double, and thus the
harmonic frequencies $n f_0$ would all double, thus removing some of
them from our medium's bandwidth.

\section{Bit Encodings}

Where does one bit start and the next begin?  For instance, suppose
our line has a high voltage for a 1 and a low voltage for a 0, and
suppose that our sending device were to send 10 1s in a row.  Then
the line would be high for 10 bit times, but how would the receiver
know that this is not, for example, only nine 1s?  There is no
``boundary'' between bits.

Theoretically speaking, this problem is solved by having a clock on the
receiver end, carefully marking off bit times.  If we are sending at,
say, 10,000 bits per second, that would mean that each bit takes 100
millionths of a second, i.e. 100 microseconds.  So if the receiver sees
the line is high for 1000 microseconds, then the receiver knows that
this must be 1000/100 = 10 1 bits.

The problem with this is that there will be discrepancies between
the sender and receiver clocks.  Over time, this discrepancy will
accumulate and eventually the receiver will be off a full bit time from
the sender---and thus the receiver will look at the wrong bit.

In order to deal with this, we design the receiver to frequently
resynchronize itself with the sender.  The way this is typically done is
to have the receiver look for {\bf line transitions}, i.e. changes from
1 to 0 or vice versa.  Since a transition occurs between two consecutive
bits, the receiver can use this to resynchronize its clock with that
of the sender.  

But if we happen to send a long string of 1s, the receiving clock won't
have this chance to resynchronize.  One method of dealing with this is
{\bf non-return-to-zero-inverted} (NRZI) coding, which works as follows.
If we wish to send a 1 bit, we place a voltage opposite to what we sent
in the previous bit.  In other words, if the previous line level had
been low, we now put a high value on the line, and vice versa.  If we
wish to send a 0, we send the same voltage level as in the previous bit.

The idea here is to force frequent line transitions.  This scheme
does this, since every 1 bit will be coded as a line transition.
Thus the receiver has frequent opportunities to resynchronize its
clock.

That solves the problem of having a long string of 1s in our message,
but it doesn't cover cases in which we happen to send long strings of
0s.  Both problems are addressed by {\bf Manchester} coding, which
forces a bit transition in {\it each} bit time.  Under this system, if
we wish to send a 0 bit, we hold the line at low voltage for one
transmission bit time (which will be half a data bit time) and then
bring it up to high voltage for one transmission bit time.  If we wish
to send a 1 bit, we have the line high for a transmission bit time and
then low for a transmission bit time.  This guarantees a line transition
during each data bit, so the receiver has a chance to resynchronize its clock
during every data bit.

But Manchester is wasteful---each data bit now needs two transmission
bit times to send.  Thus for any given transmission line, and thus for
any given maximum line bandwidth, and thus for any given maximum
transmission bit rate,  it cuts down the allowable data bit transmission
rate by half.  

Note that Manchester coding also changes the pattern in which we uses
our transition line's frequency bandwidth.  For instance, recall our
earlier example, in which we were transmitting at 2 MHz, and our message
consisted of 101010...  Using Manchester coding, the values on our line
would be 100110011001..., which has a quite different Fourier series
than would the 101010... pattern we would use without Manchester coding.    

So, compromise schemes have been developed, such as the
famous 4B/5B system.  Under this scheme, each group of four message bits
is coded in five bit times.  Here is the translation table:

\begin{verbatim}
data    coding
----    ------
0000    11110
0001    01001
0010    10100
0011    10101
0100    01010
0101    01011
0110    01110
0111    01111
1000    10010
1001    10011
1010    10110
1011    10111
1100    11010
1101    11011
1110    11100
1111    11101
\end{verbatim}

The five-bit code is then sent using NRZI.  For example, suppose
we wish to send 1011, and that the last state of the line had been
high.  Then we would send 1011 as low-low-high-low-high.  
(Make sure you understand this point.)

Note that in all the five-bit codes above, there is never more than
one leading 0 and never more than two trailing 0s.  So, if two data
items are sent back-to-back, we cannot have more than three consecutive
0s.  This solves the original NRZI problem concerning long strings of
0s discussed earlier, and since NRZI itself handles the problem of
long strings of 1s, you can see that the 4B/5B scheme works pretty
well. 

\end{document}

