Signal Processing First
Lab 09: Encoding and Decoding Touch-Tone Signals
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
This lab introduces a practical application where sinusoidal signals are used to transmit information: a
touch-tone dialer. Bandpass FIR filters can be used to extract the information encoded in the waveforms.
The goal of this lab is to design and implement bandpass FIR filters in MATLAB, and to do the decoding
automatically. In the experiments of this lab, you will use firfilt (), or conv (), to implement filters
and freqz () to obtain the filter's frequency response.¹ As a result, you should learn how to characterize a
filter by knowing how it reacts to different frequency components in the input.
1.1 Review
In a previous lab, you learned about both L-Point Average and Nulling Filters.
Another very important FIR filter is known as the Band-Pass Filter (BPF). For the rest of the lab, you will
learn how to design these filters and how to use them to do certain tasks for you. One practical example is
the dual tone multiple frequency (DTMF) signals used to dial a telephone. Read the following Background
section before coming to the lab to speed up the sign-off process in the lab.
1.2 Background: Telephone Touch Tone Dialing
Telephone touch-tone² pads generate dual tone multiple frequency (DTMF) signals to dial a telephone.
When any key is pressed, the sinusoids of the corresponding row and column frequencies (in Fig. 1) are
generated and summed, hence dual tone. As an example, pressing the 5 key generates a signal containing
the sum of the two tones at 770 Hz and 1336 Hz together.
The frequencies in Fig. 1 were chosen (by the design engineers) to avoid harmonics. No frequency
is an integer multiple of another, the difference between any two frequencies does not equal any of the
frequencies, and the sum of any two frequencies does not equal any of the frequencies.³ This makes it easier
to detect exactly which tones are present in the dialed signal in the presence of non-linear line distortions.
'If you are working at home and do not have the function freqz.m, there is a substitute available in the SP First toolbox
called freekz.m.
2Touch Tone is a registered trademark
³More information can be found at: http://www.genave.com/dtmf.htm, or search for "DTMF" on the Internet.
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7.
Prentice Hall, Upper Saddle River, NJ 07458. 2003 Pearson Education, Inc.
1 FREQS
1209 Hz
1336 Hz
1477 Hz
1633 Hz
697 Hz
1
2
3
A
770 Hz
4
5
6
B
852 Hz
7
8
9
C
941 Hz
*
0
#
Ꭰ
Figure 1: Extended DTMF encoding table for Touch Tone dialing. When any key is pressed the tones of
the corresponding column and row are generated and summed. Keys A-D (in the fourth column) are not
implemented on commercial and household telephone sets, but are used in some military and other signaling
applications.
1.3 DTMF Decoding
There are several steps to decoding a DTMF signal:
1. Divide the time signal into short time segments representing individual key presses.
2. Filter the individual segments to extract the possible frequency components. Bandpass filters can be
used to isolate the sinusoidal components.
3. Determine which two frequency components are present in each time segment by measuring the size
of the output signal from all of the bandpass filters.
4. Determine which key was pressed, 0-9, A-D, *, or # by converting frequency pairs back into key
names according to Fig. 1.
It is possible to decode DTMF signals using a simple FIR filter bank. The filter bank in Fig. 2 consists
of eight bandpass filters which each pass only one of the eight possible DTMF frequencies. The input signal
for all the filters is the same DTMF signal.
697 Hz
Y1[n]
770 Hz
Y2[n]
852 Hz
Y3 [n]
x[n]
°
1477 Hz
Y6 [n]
1633 Hz
Y7[n]
Figure 2: Filter bank consisting of bandpass filters (BPFs) which pass frequencies corresponding to the eight
DTMF component frequencies listed in Fig. 1. The number is each box is the center frequency of the BPF.
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7.
Prentice Hall, Upper Saddle River, NJ 07458. 2003 Pearson Education, Inc.
2 Here is how the system should work: When the input to the filter bank is a DTMF signal, the outputs
from two of the bandpass filters (BPFs) should be larger than the rest. If we detect (or measure) which two
outputs are the large ones, then we know the two corresponding frequencies. These frequencies are then
used as row and column pointers to determine the key from the DTMF code. A good measure of the output
levels is the peak value at the filter outputs, because when the BPF is working properly it should pass only
one sinusoidal signal and the peak value would be the amplitude of the sinusoid passed by the filter. More
discussion of the detection problem can be found in Section 4.
2 Pre-Lab
2.1 Signal Concatenation
In a previous lab, a very long music signal was created by joining together many sinusoids. When two
signals were played one after the other, the composite signal was created by the operation of concatenation.
In MATLAB, this can be done by making each signal a row vector, and then using the matrix building
notation as follows:
XX =
( xx, xxnew ];
where xxnew is the sub-signal being appended. The length of the new signal is equal to the sum of the
lengths of the two signals xx and xxnew. A third signal could be added later on by concatenating it to xx.
2.1.1 Comment on Efficiency
=
In MATLAB the concatenation method, xx
[ XX,
xxnew ], would append the signal vector xxnew
to the existing signal xx. However, this becomes an inefficient procedure if the signal length gets to be very
large. The reason is that MATLAB must re-allocate the memory space for xx every time a new sub-signal
is appended via concatenation. If the length xx were being extended from 400,000 to 401,000, then a clean
section of memory consisting of 401,000 elements would have to be allocated followed by a copy of the
existing 400,000 signal elements and finally the append would be done. This is clearly inefficient, but would
not be noticed for short signals.
An alternative is to pre-allocate storage for the complete signal vector, but this can only be done if the
final signal length is known ahead of time.
2.1.2 Encoding from a Table
Explain how the following program uses frequency information stored in a table to generate a long signal
via concatenation. Determine the size of the table and all of its entries, and then state the playing order of the
frequencies. Determine the total length of the signal played by the soundsc function. How many samples
and how many seconds?
ftable =
fs
8000;
[1;2;3;4;5]*[80,110]
XX =
[ ] ;
disp('
Here we go through the Loop
keys = rem (3:12, 10) + 1;
for ii =
1:length(keys)
kk = keys (ii);
XX
= [xx, zeros (1,400)];
krow = ceil (kk/2);
kcol = rem (kk-1, 2) + 1;
XX =
[xx, cos (2*pi* ftable (krow, kcol) * (0:1199)/fs) ];
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7.
Prentice Hall, Upper Saddle River, NJ 07458. 2003 Pearson Education, Inc.
3 end
soundsc (xx, fs);
2.2 Overlay Plotting
Sometimes it is convenient to overlay information onto an existing MATLAB plot. The MATLAB command
hold on will inhibit the figure erase that is usually done just before a new plot. Demonstrate that you
can do an overlay by following these instructions:
(a) Plot the magnitude response of the 5-point averager, created from
HH=freqz (ones (1,5)/5,1,ww)
Make sure that the horizontal frequency axis extends from ―π to +π.
(b) Use the stem function to place vertical markers at the zeros of the frequency response.
hold on,
stem (2*pi/5* [−2,-1,1,2],0.3*ones (1,4), 'r.'), hold off
3 Warm-up: DTMF Synthesis
3.1 DTMF Dial Function
Write a function, dtmfdial.m, to implement a DTMF dialer based on the frequency table defined in
Fig. 1. A skeleton of dtmfdial.m is given in Fig. 3. In this warm-up, you must complete the dialing code
function xx = dtmfdial (keyNames, fs)
%DTMFDIAL Create a signal vector of tones which will dial
응
==
% usage:
응
응
...
응
a DTMF (Touch Tone) telephone system.
XX = dtmfdial (keyNames, fs)
keyNames
XX =
fs =
vector of characters containing valid key names
sampling frequency
signal vector that is the concatenation of DTMF tones.
dtmf.keys
['1','2'
=
3'
'4''
5
'A';
'6','B' ;
ירי
8', '9', 'C' ;
'*', '0','%','D′];
dtmf.colTones =
ones (4,1) * [1209,1336,1477,1633];
dtmf.rowTones = [697;770;852; 941] *ones (1,4);
Figure 3: Skeleton of dtmfdial.m, a DTMF phone dialer. Complete this function with additional lines of
code.
so that it implements the following:
1. The input to the function is a vector of characters, each one being equal to one of the key names on
the telephone. The MATLAB structure called dtmf contains the key names in the field dtmf.keys
which is a 4 × 4 array that corresponds exactly to the keyboard layout in Fig. 1.
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7.
Prentice Hall, Upper Saddle River, NJ 07458. 2003 Pearson Education, Inc. 2. The output should be a vector of samples with sampling rate fs
=
8000 Hz containing the DTMF
tones, one tone pair per key. Remember that each DTMF signal is the sum of a pair of (equal am-
plitude) sinusoidal signals. The duration of each tone pair should be exactly 0.20 sec., and a silence,
about 0.05 sec. long, should separate the DTMF tone pairs. These times can be declared as fixed code
in dtmfdial. (You do not need to make them variable in your function.)
3. The frequency information is given as two 4×4 matrices (dtmf.colTones and dtmf.rowTones):
one contains the column frequencies, the other has the row frequencies. You can translate a key such
as the 6 key into the correct location in these 4 × 4 matrices by using MATLAB's find function. For
example, the key 6 is in row 2 and column 3, so we would generate sinusoids with frequencies equal
to dtmf.colTones (2,3) and dtmf.rowTones (2,3).
To convert an key name to its corresponding row-column indices, consider the following example:
[ii,jj]
=
find('3' ==dtmf.keys)
Also, consult the MATLAB code in Section 2.1 above and modify it for the 4×4 tables in dtmfdial.m.
4. You should implement error checking so that an illegitimate key name is rejected.
Your function should create the appropriate tone sequence to dial an arbitrary phone number. When played
through a telephone handset, the output of your function will be able to dial the phone. You could use
specgram to check your work.4
Instructor Verification (separate page)
3.2 Simple Bandpass Filter Design
The L-point averaging filter is a lowpass filter. Its passband width is controlled by L, being inversely
proportional to L. It is also possible to create a filter whose passband is centered around some frequency
other than zero. One simple way to do this is to define the impulse response of an L-point FIR as:
h[n] = ẞcos (ŵen), 0 ≤ n