FSK Modem - Lab18
FSK Modem - Lab18
Pre-Lab and Warm-Up: You should read at least the Pre-Lab and Warm-up sections of this lab assignment
and go over all exercises in the Pre-Lab section before going to your assigned lab session.
Verification: The Warm-up section of each lab must be completed during your assigned Lab time and
the steps marked Instructor Verification must also be signed off during the lab time. One of the laboratory
instructors must verify the appropriate steps by signing on the Instructor Verification line. When you have
completed a step that requires verification, simply demonstrate the step to the TA or instructor. Turn in the
completed verification sheet to your TA when you leave the lab.
Lab Report: It is only necessary to turn in a report on Section 4 with graphs and explanations. You are
asked to label the axes of your plots and include a title for every plot. In order to keep track of plots, include
your plot inlined within your report. If you are unsure about what is expected, ask the TA who will grade
your report.
1 Introduction
The goal of this lab is to understand a simple modem, the Frequency Shift Keying (FSK) Modem, referred
to by the International Telecommunications Union (I.T.U.) as V.21. Here is a quick recap of the operation
of the v.21 FSK modem. The V.21 modem communicates 1’s and 0’s by sending either a 1650 Hz tone or
a 1850 Hz tone, respectively, for 1/300 sec. Thus the overall data rate is 300 bits/second (one bit is sent in
1/300-th of a second). Even though 300 bps is quite slow in comparison to the theoretical maximum of 56
kilobits per second over a phone line, the V.21 protocol is still used in almost every modem call, because
receiving it is so simple. A V.21 modem call can be received without using difficult techniques such as
equalizers, cancellers and matched filters. Furthermore, it can be received accurately even in the presence of
a significant amount of noise. For these reasons, V.21 is used to perform the initial handshake between two
modems, meaning that V.21 is a way to communicate some basic startup and control information between
the two modems. You can hear the V.21 modem tones at home when your V34, V.90, V.92 phone line
modem or fax machine starts a phone call. V.21 is also used to transmit caller ID information over the phone
line.
1.1 Modulator
In Lab 17 you built a FSK modulator for encoding text data into binary data and then into a FSK waveform.
If you were able to make this system work, you can use it to generate signals for this lab. If your system did
not work, we have provided a modulator called qdfsk that you can use in your experiments with decoding.
1.2 Demodulator
The receiver for V.21 must determine which of the two tones is present, and must make this decision every
1/300-th of a second. Furthermore, the receiver must synchronize with the bit interval, meaning that it must
learn where the starting and ending times of each bit are located. This synchronization is essential to making
reliable “0-1” decisions because the transition times must be avoided. A block diagram of the FSK V.21
demodulator is given in Fig. 1. Each of the main sections will be described in more detail below.
e−j2πfc t
1.2.1 Mixing
A basic operation that most modems need to perform is frequency shifting of the input signal. According to
the frequency-shifting property of the Fourier Transform, this can be done by simply multiplying the input
signal by a complex exponential.
w(t) = x(t)e−j2πfc t
This effect can best be understood by thinking of x(t) as a sum of complex exponentials and observing what
happens to each individual frequency component. In this case, x(t) is
x(t) = cos(2πf1 t) = 12 ej2πf1 t + 12 e−j2πf1 t .
When x(t) is multiplied by the given complex exponential at frequency −fc Hz, the exponents simply add
and the resulting w(t) is as follows:
w(t) = 12 ej2π(f1 −fc )t + 21 ej2π(−f1 −fc )t .
Note that the new frequencies in w(t) are simply the old frequencies shifted down (to the left on the f axis)
by fc , i.e., f1 − fc and −f1 − fc . Also note that w(t) is complex so we no longer have the condition of
complex conjugate symmetry between the two complex exponential components. This simply means that
now our signal is really two signals: a real part signal and an imaginary part signal. If we want to filter this
complex signal with a real filter, we simply filter the real part and the imaginary part separately with the
same filter. In M ATLAB, the filter( ) function does this very thing for you.
The purpose of the filter is to remove the complex exponential with frequency −f1 − fc while leaving
the other component whose frequency is f1 − fc . Thus, the filter output should be of the form
y(t) = Aej2π(f1 −fc )t ,
where A will depend on the gain of the filter in its passband. For V.21 FSK, we will choose fc so that the
original frequencies of +1650 Hz and +1850 Hz in x(t) are shifted to −100 Hz and +100 Hz respectively,
and these are the frequencies passed by the filter. This is achieved by choosing fc = 1750.
Figure 2: FSK system demodulator system simulated as a discrete-time system at a sampling rate of fsamp .
1.2.4 Slicing
Imag
x(t) - x[n] w[n]- Digital y[n] s[n] d[n]
C/D -
⊗ LPF
-
⊗
- - part
Im{ }
-
6 6
6
complex
Ts = 1/fsamp e−j ω̂c n - Unit - conj
Delay (y[n − 1])∗
{ }∗
Figure 3: Frequency estimation in a dual-frequency FSK system can be performed with a slicer.
Another basic operation of most modems is to measure the frequency of a received tone. This could
1
Remember that the frequency response of a digital filter, H(ej ω̂ ), is a function of the frequency variable ω̂ that runs from
ω̂ = −π to ω̂ = +π.
If the objective were to determine the frequency ω̂0 , then it is sufficient to take the imaginary part
and use d[n] to calculate the ArcSin(·) to get an estimate of ω̂0 . However, the FSK V.21 system is even
simpler than that, because we only need to decode two cases: a zero or a one. When ω̂0 < 0 we have a “1”,
and when ω̂0 > 0 we have a “0.” In addition, the sign of ω̂0 is the same as the sign of |A|2 sin(ω̂0 ), so we
only need to check the sign bit of d[n] to perform the decoding.
As will be seen in the final implementation of this lab, the recovery of the V.21 signal reduces to dis-
criminating between a +100 Hz tone and a −100 Hz tone. Taking the imaginary part of s[n], the slicer
output, will provide an easy way to determine whether a 1650 Hz or 1850 Hz tone was originally present.
Thus we can define b[n] as an estimate of the bit that is represented by the slicer output at time n.
when d[n] ≥ 0
0
b[n] = (3)
1 when d[n] < 0
In M ATLAB, you can use the find( ) function to implement (3) by creating a zero vector of the same
length as d[n] and then changing all locations where d[n] < 0 to 1.
This sequence should be +1 at each transition point. For noiseless signals in our simulation, these indicator
points should be exactly 60 samples apart in the preamble part because it consists of four groups of two
consecutive ones followed by two concecutive zeros, etc. In a practical situation, there may be some “jitter”
in the locations that you might need to accomodate.
In any case, if we locate the beginning of the signal, then after about 8 × 60 = 480 samples, we should
find the eighth marker, which is the beginning of the group of eight 1s in the marker.
where nbeg is the sample location of the end of the marker bits (beginning of the message bits). The end of
the message is marked by 16 consecutive 1s, which decode to 255,255.
Finally, after we have determined the sequence of bits and grouped them into bytes, we must convert the
resulting binary number into ASCII symbols. This completes the decoding simulation. How to do this in
the M ATLAB simulation is suggested in Section 2.1.
2 Pre-Lab Exercises
2.1 Binary Stream to ASCII
The FSK decoder involves the operation of converting 8-bit patterns to ASCII. The M ATLAB functions
bin2dec and char can convert a bit stream to ASCII. Try the following example:
bb = [0,1,0,0,0,0,0,1], char(bin2dec(char(bb+abs(’0’))))
In order to understand this example, you might want to see what each char and bin2dec operator pro-
duces. Modify the example above so that it can do more than one ASCII character. Complete the loop
below:
inbits = round(rand(1,64)); %-- 64 random bits become 8 random characters
outchar = [];
for kk=1:8:length(inbits)
bb = inbits( ?? : ?? ); %<=====FILL in code here
outchar = [outchar, ???????? ]; %<=====FILL in code here
end
outchar
3 Warm-up
For the exercises in this warm-up, you will need the FSK encode/modulator from Lab 17. If your own t
h
k
n
version is not yet ready, then you can use the FSK encoder/modulator called qdfsk() which can be in the
CD-ROM
ZIP file called FSK Lab18.zip, which can be found at the ‘M ATLAB Files’ link. Look for the file called
FSK Lab18.zip
qdfsk.p.
(a) In case you did not design the filter discussed in Section 2.3, go back and do that part.
(b) Use xx = qdfsk(’Tech’,300,9000) to create an FSK signal for a bit stream. This encoder
runs at 300 bps and uses a sampling rate of 9000 Hz. If you have your own working FSK generator,
you can use that M-file instead.
(c) Process the FSK signal created in the previous part through the mixer (with fc = 1750 Hz) and the
lowpass filter that you designed in the pre-lab. Make a plot of the output signal in the time domain.
Label the horizontal axis with time in seconds. Since the output is complex-valued, plot the real part
only.
Instructor Verification (separate page)
(d) It is possible to view the spectrogram of the input and output of the lowpass filter, but some care
is needed. First of all, for the 300 bps signal, an extremely short window length is needed when
calling specgram, e.g., specgram(xx,32,fs), because the bit duration is only 30 samples at
fsamp = 9000 Hz. Secondly, the specgram plot for a complex input signal extends from 0 to fsamp ,
so negative frequency components actually show up at high frequencies. For example, −2000 Hz
would show up at 9000 − 2000 = 7000 Hz when fsamp = 9000 Hz.
(a) For the input to the slicer, use the filtered output signal from the previous section. Or, if you are unsure
of that output, make a test signal by synthesizing y[n] as a single complex exponential:
y[n] = ej ω̂1 n
Find the correct value for ω̂1 from fs = 9000 Hz and f1 = 100 Hz.
(c) Now s[n] (the slicer output) can be obtained by using the conj() function in M ATLAB. Plot the
imaginary part of the slicer output ss and compare this to the predicted value which is a constant:
sin(2π(100)/9000)
4 Lab Exercises
In the Warm-up section, you should have completed the implementation of all parts of the FSK demodulator,
so the only thing left is the “decoder” that will synchronize on the bits and group them into 8-bit bytes.
4.1 Transmitter/Modulator
For this lab, you can use your own FSK transmitter, or an FSK transmitter will be provided for you in the
M-file called qdfsk. The transmitter/modulator must be set to run at a sampling rate of 9000 Hz. A
realistic simulation would use 8000 Hz because phone lines are 8000 Hz, but 9000 Hz keeps our sampling
rate an integer multiple of 300 which is our symbol/bit rate. One useful test message is ’@U ’ because it
contains runs of consecutive zeros, consecutive ones, and also alternating zeros and ones. Note that the FSK
transmitter has an optional input parameter that will allow you to add noise to the FSK signal for a more
realistic simulation. It is probably a good idea to begin your program development and initial testing with
no noise.
NOTE: if you are unable to produce a working function for this module of the decoder, you can use the
M-file called qdjump.m which is in the ZIP archive FSK Lab18.zip.
4.5 Others
Be sure to include the following in your lab report:
1. Plots of the specgram or sketches of the spectrum for the signals into the mixer, out of the mixer,
and after the LPF.
3. A description of your technique for synchronizing the bits and bytes, based on your knowledge of the
training signal and the data flags.
4. A comparison of the received bits to the transmitted pattern for a simple case. These ought to be
identical when there were no distortions, which is the (unrealistic) condition for this lab.
5 Supplementary Thoughts
In this lab we built a modem, a digital form of communication, which is generally speaking far superior to
analog communication. The magic of digital is that if the bits are recovered correctly (and there are a variety
of advanced techniques to achieve this), then all the distortions of the channel, noise, and modem imper-
fections along the way are effectively eliminated. In this lab, the digital magic occurs when the decision is
made to convert the slicer output d[n] into b[n] which is either a 0 or a 1 bit. A cell phone is a good example
of the magic of digital. In spite of the horrible channel between you and the cell tower (which is changing
as you cruise down the interstate while talking on your cell phones) and all the ambient noise, the data bits
can be heavily encoded and recovered properly, thus achieving digital quality.
Part 3.1(c): Show the output from the lowpass filter. Confirm that its frequency is either -100 Hz or +100
Hz. In addition, sketch the filter specifications (in the space below) that you used to create the filter.
Verified: Date/Time:
Part 3.2(c): Demonstrate that the slicer will give a constant output when the input is a single complex expo-
nential.
Verified: Date/Time: