Lab 5: Digital Communication – FSK Modem 1 Overview

advertisement
ELEG-212 Signals and Communications
Fall 2004
Lab 5: Digital Communication – FSK Modem
1 Overview
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. 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 second. 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 compared with the theoretical maximum of 56
kilobits per second over a phone line, the V.21 format is still used in almost every modem call.
This is due to the fact that receiving and decoding 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 as an initial handshake between two modems, meaning that
V.21 is a way to communicate some basic startup/control information between the two modems.
You can hear the V.21 modem tones at home when your V.34, 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 Transmitter
1.1.1 Converting from Text String to Binary String
An FSK modem is a digital communication system, so it transmits zeros and ones. In order to
transmit messages in an alphabet, there must be a binary representation for each character in the
alphabet. The standard for this representation is ASCII where eight bits are used to represent
characters, numbers and special punctuation. For example, the upper-case character ’A’ is
represented in ASCII with the number 65, which has an 8-bit binary form as 01000001; lowercase ’b’ is 98 in ASCII, or 01100010.
Therefore, if we want to encode a message, such as ’Hello World’, for the FSK modem, we
must turn the eleven characters of the message into 0’s and 1’s. Since blanks are counted as
characters, we would end up with 88 bits. Given a vector of bits, we could generate the
appropriate sinusoids by agreeing to the convention that 1650 Hz is used for a “1”, and 1850 Hz
is used for “0”.
MATLAB has some useful functions for doing ASCII conversion and also for turning decimal
numbers into bits. Check out help on the following functions:
CHAR Convert numeric values to character array (string)
ABS Convert character array (string) to numeric values
DEC2BIN Convert decimal integer to a binary string
BIN2DEC Convert binary string to decimal integer
Run the script char(30:50), please refer to its help to understand the result. Also, try the
following MATLAB expression abs([’ABC’;’b01’]), and note that the ASCII equivalents
are returned in a matrix1. To test your knowledge at this point, write a MATLAB expression that
1
In MATLAB, a string is actually an array of characters, so [’ABC’;’b01’] is a 2 × 3 array. Use size to verify this fact.
1/11
ELEG-212 Signals and Communications
Fall 2004
will give the binary representation for the message ’Hi!’. Use the optional argument in
dec2bin to get an 8-bit string for each character (with leading zeros). Notice that, when you
convert a text string into binary format, you will get a column vector, each row is an 8-bit long
binary string. You may want to use MATLAB function reshape to form your binary message
into one string, so that it will be easier to generate your FSK signal in the next step. Be aware that
the function reshape is based on column-wise operation. By convention, we send the most
significant bit of byte first2. For example, ’H’ corresponds to 01001000, and ’i’ 01101001.
So, the binary string sent out should be in order 0100100001101001.
1.1.2 Generate an FSK Signal
One part of the FSK encoder must take a binary bit stream and create a sinusoid for each bit. The
duration of each sinusoid will determine the bit rate, e.g., 300 bits/second (bps) requires a
duration of 1/300 sec. You must complete the function below and use it to generate the FSK
signal. The functionality of this program is to covert a binary string into a FSK waveform
consisting of dual tone sinusoids, given the sampling rate and the bit duration. The only given
script in the program is to convert the input binary string to a vector containing 0’s and 1’s.
function xx = fsk_gen( bitstr, fs, bdur )
%FSK_GEN generate the FSK sinusoids at 1650 and 1850 Hz
% 1650 encodes a "1", 1850 encodes a "0"
%
% bitstr = STRING of zeros and ones.
% fs = sampling rate
% bdur = duration of the sinusoid for one bit
%
(this determine the "bit rate")
% xx = synthesized FSK signal
%
inbits = abs(bitstr) - abs(’0’);%convert bit string to numbers
%%
%%%%%%%%%%%% put your code here %%%%%%%%%%%%%%%%%%%
To test your function, input character ’H’, use a duration of 50 millisec, even though that is only
20 bps, because then it will be easy to identify the tones on a spectrogram. Use a sampling rate of
9000 samples/second. Make a spectrogram of the generated FSK signal in order to show how the
individual bits correspond to sinusoids. Use a window length that is the default of 128. Your
spectrogram plot should look like Fig. 1. Notice those vertical bars on the spectrogram plot, and
try to explain the cause of it. Conceptually, what could be the solution to this problem?
2
This is called the Big-Endian convention. As expected, there is a Little-Endian convention, too. The debate on choosing one over the
other has been going on for decades. Check online materials for more details.
2/11
ELEG-212 Signals and Communications
Fall 2004
Figure 1. The spectrogram of the FSK signal when send letter ‘H’.
1.2 Receiver
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. A block diagram of the FSK V.21 demodulator is given in
Fig. 2. Each of the main sections will be described in more detail below.
Figure 2: Block diagram of the FSK V.21 demodulator.
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 − j 2π fct
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
1
1
x(t ) = cos(2π f1t ) = e j 2π f1t + e− j 2π f1t .
2
2
3/11
ELEG-212 Signals and Communications
Fall 2004
When x(t ) is multiplied by the given complex exponential at frequency − f c Hz, the exponents
simply add and the resulting w(t ) is as follows:
1
1
w(t ) = e j 2π ( f1 − fc )t + e − j 2π ( f1 + fc ) t .
2
2
Note that the new frequencies in w(t ) are simply the old frequencies shifted down (to the left on
the f axis) by f c , i.e., f1 − f c and − f1 − f c . 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 MATLAB, the filter()
function does this very thing for you.
The purpose of the filter is to remove the complex exponential with frequency − f1 − f c while
leaving the other component whose frequency is f1 − f c . Thus, the filter output should be of the
form
y (t ) = Ae j 2π ( f1 − fc )t ,
where A will depend on the gain of the filter in its passband. For V.21 FSK, we will choose f c 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
f c = 1750.
1.2.2 Discrete-Time Simulation
The MATLAB implementation of the FSK V.21 modem is a simulation. This means that even
though we seem to have continuous-time signals such as x(t ) and w(t ) , we actually use sampled
versions in the MATLAB program. For this simulation, we will choose the input sampling
frequency to be
fsamp = 9000Hz.
(1)
This value is chosen to be rather high so that the input signal will appear to be continuous if we
use the MATLAB plot() command. In Fig. 3 the continuous-time signals have been replaced
with their sampled versions, e.g., x(t ) becomes x[n] , w(t ) becomes w[n] , and so on. The
complex exponential used in the mixer must also be converted from e
− jωˆ n
signal e c . What is ωˆ c ?
− j 2π f c t
to a discrete-time
Figure 3: FSK system demodulator system simulated as a discrete-time system at a sampling rate
of fsamp .
4/11
ELEG-212 Signals and Communications
Fall 2004
1.2.3 Low Pass Filter Design
The other thing that must be done in converting the block diagram of Fig. 2 to the simulation
block diagram in Fig. 3 is to replace the analog filter by a digital filter. This filter must pass the
band of frequencies equivalent to ±100 Hz, and it must remove the higher frequencies generated
at the output of the mixer which are - f c - 1650 = -3400 and - f c - 1850 = -3600 Hz.
Since the digital filter is typically used to filter signals that are sampled analog signals, it is
important to know how the band edges of the digital filter can be expressed in terms of the
desired analog cutoff frequencies. This can be done if the sampling frequency fsamp is known. For
example, if we want to have a lowpass filter with an effective cutoff frequency of 1500 Hz, and
we are using a digital filter running at fsamp = 9000 Hz, then the digital filter must have its cutoff
frequency3 at ω̂ = 2 π (1500/9000) =
1
π.
3
In the FSK V.21 system, the frequency shifting of the mixer will generate spectrum lines that
must be removed by filtering. If we demand that these unwanted spectrum components must be
reduced in magnitude by a factor of 100, then we have given the specifications on the stopband
ripple. A reduction by a factor of 100 means that the stopband ripple must be less than 0.01, or 40 dB. The passband, on the other hand, must be made wide enough so that the desired frequency
components will go through the LPF with little or no change. Since the LPF’s frequency response
will have a passband ripple, we will use a specification on the passband of 1 dB, which forces the
passband magnitude to lie between 0.89 and 1.12. For detailed digital filter design, refer to
Section 1.3 of this lab.
1.2.4 Frequency Estimation: Slicing
Another basic operation of most modems is to measure the frequency of a received tone. This
could be accomplished by optimal filtering algorithms such as matched filters designed to
enhance the tones of interest. However, if you are guaranteed to be looking at only one tone at a
given time and the noise is not severe (both of which are true for V.21), then there is a simpler
method that can be employed to save computation when measuring frequency.
Figure 4: Frequency estimation in a dual-frequency FSK system can be performed with a slicer.
Slicing is defined as follows:
s[n] = y[n] y*[n − 1].
3
Remember that the frequency response of a digital filter, H ( e ) , is a function of the frequency variable ω̂ that runs from
jωˆ
ω̂ = −π to ω̂ = π .
5/11
(2)
ELEG-212 Signals and Communications
Fall 2004
It is a non-linear operation, but in the case where x[n] is a single cosine input, the filter output
will be of the form y[n] = Ae
jωˆ 0 n
, where ωˆ 0 = m200π / fsamp . In this case, the output of the
slicer (2) reduces to
s[n] = ( Ae j ωˆ 0 n ) ( A*e− jωˆ 0 ( n −1) ) .
After adding the exponents, the output simplifies to
s[n] =| A |2 e jωˆ 0 .
If the objective were to determine the frequency ω̂ 0 , then it is sufficient to take the imaginary
part
d [n] = Im{s[n]} = Im{| A |2 e jωˆ 0 }
⇒
d [n] =| A |2 sin(ωˆ 0 )
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
discriminating 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 .
⎧0
b[n] = ⎨
⎩1
when d [n] ≥ 0
when d [n] < 0
(3)
In MATLAB, 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.
Table 1: FSK Decoding Rule
Note that y[n − 1] can easily be obtained from y[n] by with a delay of one sample. In the
interest of keeping the vectors the same size, the filter() command can be used to create
y[n − 1] :
y1 = filter([0 1],1,y)
1.2.5 Decoding the Message
Now we must extract the bit information from the output signal d [n] . Remember that the
sampled waveform x[n] is a variable frequency sinusoid that can switch frequency every 30
6/11
ELEG-212 Signals and Communications
Fall 2004
samples (assuming bit rate of 300 bps and sampling rate of 9000 samples/sec) and the sinusoid
switches between 1650 Hz to represent a 1 and 1850 Hz to represent a 0.
In our discrete-time simulation, the signal d [n] at the output of the slicer is either positive or
negative at each sample time, and we have just seen that the sign of this signal is an indicator of
whether a 1 or a 0 is being encoded at any particular sample time n . Now we should remember
that if the bit rate is 300 bps and the sampling rate is 9000 Hz, this means that each bit of the
encoded message is actually represented by a group of 30 consecutive samples.
We can determine the sequence of bits by simply looking at the signal during each bit interval.
Since each of these intervals is 30 samples long, we can find the middle (where the answer is
likely to most robust) by simply “sampling” the sequence b[n] at a point that is offset by 15
samples from the beginning of each bit interval. When there is noise in the communication
channel, which is always true in real life, you don’t want to base your result on only one sample
in each bit interval. One way to mitigate the noise effect is to use a “majority vote” scheme, that
is, in one bit interval, if more than half of 30 samples are negative, then it is more likely that the
decoded bit is a 1.
At last, we need to group the bits into 8-bit sets then convert them into ASCII symbols. This
completes the decoding simulation. The MATLAB functions bin2dec and char can convert a
bit stream to ASCII. Try the following example:
bstr = [0 1 0 0 1 0 0 0]
char(bin2dec(char(bstr+abs(’0’))))
1.3 Filter Design
When you implement the FSK decoder, it will be necessary to have lowpass and (possibly)
bandpass filters. We had previously encountered a similar filter design problem in the DTMF
system, where several bandpass filters were needed. In that case, we used FIR filters that had
acceptable passbands, but were actually quite poor in their stopband behavior. The objective of
this part is to investigate two ways to get better filters4.
1.3.1 GUI for Filter Design
The process of filter design involves a trade off between the filter length L , the band edges, and
the stopband and passband ripples. If we use a GUI we can manipulate these trade-offs directly
on the screen and see immediately how the magnitude response changes as we try to satisfy the
desired filter specs. Figure 5 shows the magnitude response of a digital FIR filter obtained with
the MATLAB GUI called filtdemo.
Decibels: One feature of the magnitude plot in Fig. 5 is that the vertical axis is logarithmic in
ˆ
units called decibels (dB), i.e., the quantity plotted is 20 log10 | H (e jω ) | . When using a dB-scale,
the passband, which ideally has a magnitude of one, should be 0 dB. In the stopband, we might
ˆ
have a value like | H (e jω ) | = 0.01 which is -40 dB.
If we consider the case of a lowpass filter (LPF) such as Fig. 5, then we can describe the passband
as extending from f = 0 to a cutoff frequency, f = f p Hz; and the stopband is the region
4
The Signal Processing Toolbox in MATLAB provides numerous functions that will perform filter design, but often this toolbox is
not available.
7/11
ELEG-212 Signals and Communications
Fall 2004
f ≥ f s Hz. Even though the frequencies are given in hertz, the filter design GUI yields a digital
filter. The sampling frequency fsamp controls the relationship between the given analog cutoff
frequencies, f p and f s , and the filter’s frequency response H (e jω ) which is actually a function
ˆ
of ω̂ .
Question: Determine the values of ω̂ for the passband and stopband edges in Fig. 5.
1.3.2 Using the GUI
The filter type is controlled by the drop-down menu in the upper right-hand corner of the GUI.
There are several choices, but the only ones of interest for FIR design in this lab are REMEZ or
KAISER. For given ripple specs, the REMEZ design will give a shorter filter, so it might be
preferred, but either method is acceptable for this lab.
The filter specifications can be entered into the GUI in two ways: either in the text boxes on the
upper right part of the window, or by dragging the green bars that indicate the desired passband
and stopband regions. The bars can be moved up and down to change the desired ripple sizes, but
the ends of the bars can also be moved horizontally to change the desired bandedges.
The filter order (which is L - 1) can be calculated automatically by the GUI, or the user can enter
a specific value. This option is controlled by the radio buttons on the right side of the GUI
Figure 5: The filtdemo MATLAB GUI for digital filter design. The magnitude is given in dB
(decibels). The frequency axis is labeled in hertz from DC to half the sampling frequency. (Note
that fsamp = 6000 Hz in this figure.)
8/11
ELEG-212 Signals and Communications
Fall 2004
In Fig. 5, the value of M = 23 was entered by hand. Obviously, the stopband cutoff frequency
f s must be greater than the passband cutoff frequency f p . If we try to make f s and f p nearly
equal, then the filter length L would have to be very large, so it is customary to allow a
transition region between the passband and stopband.
Once the magnitude response has been manipulated into a desirable form, the filter coefficients
can be extracted from the GUI by running the following in the command window.
[bb,aa] = filtdemo(’getfilt’);
Since this is an FIR filter, only the vector bb is needed. It will contain all of the filter
coefficients for the FIR filter.
2 Procedures
2.1 FSK Modem in VAB
In this demonstration VAB part, you will hear what a two-tone FSK transmitter sounds like. The
worksheet 2-Tone FSK Transmitter.Lst can be found on desktop of every computer in
the lab, and it looks like that shown in Fig. 6.
Every time you type in a letter, you will hear a pattern of tones repeating itself. Different letters
will have different tone patterns. Based on the knowledge you have got from Section 1.1, explain
the relationship between the letter you type and the tone pattern you hear.
Figure 6. Two-tone FSK transmitter worksheet.
9/11
ELEG-212 Signals and Communications
Fall 2004
Suppose you are about to construct a 2-Tone FSK Receiver.Lst worksheet, you want to
pair two computers up and form a two-tone FSK air modem just like you did on LAB 4 (DTMF
modem). Suppose you have ideal bandpass filters for those two tones (their lengths are suitable),
and noise effect can be ignored. Now, do you think your air modem will work properly? What
could go wrong? Try to find the most critical issue we are not considered here. Explain why it is
critical.
2.2 Implement FSK Modem in Matlab
The main task of this lab is to construct a FSK modem implementation in Matlab. To recap, your
simulation file should contain the following steps:
1) Define parameters, including sampling frequency and bit duration. Define a message that
you want to transmit, for example, you can use ‘Hi! I am yourname@UD’.
2) Load the filter coefficients obtained with the following specifications: fsamp = 9000, f p
= 200 Hz, f s = 1000 Hz, stopband ripples less than -40 dB, and passband ripples less
than 1 dB. Use the GUI method to design your filter.
3) Convert your message into a binary string as described in Section 1.1.1.
4) Pass this binary string into your program fsk_gen() created in Section 1.1.2.
5) Add certain amount of Gaussian noise onto your signal. It is probably a good idea to
begin your program development and initial testing with no noise.
6) Mix your signal as described in Section 1.2.1.
7) Lowpass filter the mixer output using the coefficients in step 2).
8) Use slicer to get the frequency estimation, and convert your signal to a binary string as
described in Section 1.2.4.
9) Convert the binary string into a character based message as described in Section 1.2.5.
Compare the decoded message and the original message.
Always remember, to simulate a complete system like this, you should create and test each single
building block of your system before you put them together, to make sure that they all function
correctly. So, you probably need to do some separate tests for the FSK generator, for the mixer
and for the slicer etc.
When your FSK modem is working, try the following exercises:
A. Choose the magnitude of your noise to be 0.3. First, use “middle bit” scheme, run your
simulation 20 times, count how many times you get your received message correct. Then,
use “majority vote” scheme, repeat 20 simulations. Compare the results. Explain the
difference.
B. Change your LP filter f s = 800 Hz, keep everything else the same. Your will get a better
filter in terms of transition time. Apply this filter to your communication system, observe
the result. Try to explain why. (Hint: each bit interval has 30 samples.) What can be
inferred from this observation?
Comments: A lot of practical issues in FSK modem, such as “smooth phase” and synchronization,
are not covered to keep the lab in a manageable level.
10/11
ELEG-212 Signals and Communications
Fall 2004
3 Report Components
Your report should answer the questions asked in both the VAB and MATLAB components of
the laboratory. Please make sure that the questions are answered fully, along with any explanation
or justification necessary, and that plots are appropriately labeled and referenced.
11/11
Download