ECE 466-MATLAB代写
时间:2023-04-12
ECE 466 - SS 2023 - Class Project
Dual-Tone Multi-Frequency (DTMF) Signal Decoding
Due Date: 11:59pm - May 5th, 2023
• This project is to be done individually. Each student must work on the project
independently and develop own analyses and computer code in its entirety.
• Data required for this project are available for download on D2L. You will also find
reference materials and code there. Whether you begin working right away or not,
be sure you download the data and make sure you can load it into MATLAB as soon
as possible to avoid last-minute difficulties.
• Reports and MATLAB code will be graded primarily on completeness in addressing
the assignment and quality of results. Reports must be typed, not handwritten;
well-organized; and must clearly explain your design, decisions and analysis that
went into it. Code must be provided in the form specified below, and should be
commented well-enough to be clearly understandable.
1 Project Description
Touch tone™ phone pads generate so-called Dual-Tone Multi-Frequency (DTMF) signals to
communicate control and routing information over the telephone lines to the switching station.
These signals are decoded at the switching station to properly route the call and connect two
phones.
In the DTMF protocol, each digit, from 0 to 9, and the symbols ′∗′ and ′#′ are represented
by the sum of two equal-amplitude tones (sinusoids)
x(t) = A sin(2πf1t) +A sin(2πf2t) (1)
where f1 is one of four ”low” frequencies, f2 is one of four ”high” frequencies, and A is the
amplitude of the sinusoids. The total number of possible symbols represented in this way is
4× 4 = 16, and as such the system can accommodate four additional symbols. The frequencies
used by the DTMF signaling scheme are shown in Table 1. Rows of the table correspond to
1
Table 1: DTMF Keypad Frequencies
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 # D
Table 2: Other telephone tones
Tone Frequencies Cadence
Dial Tone f1 = 350 Hz, f2 = 440 Hz Continuous
Ring Back Tone f1 = 440 Hz, f2 = 480 Hz 1 sec on + 3 sec off
Busy Tone f1 = 480 Hz, f2 = 620 Hz 0.5 sec on + 0.5 sec off
DND/No more f1 = 480 Hz, f2 = 620 Hz 0.25 sec on + 0.25 sec off
Error Tonne f1 = 480 Hz, f2 = 620 Hz 0.25 sec of each tone
Confirmation Tone f1 = 350 Hz, f2 = 440 Hz Three bursts of tone 0.1 sec on + 0.1 sec off
Transfer/Conf Tone f1 = 350 Hz, f2 = 440 Hz 0.1 sec on + 0.1 sec off
”low” frequencies, whereas columns correspond to ”high” frequencies. For example, according
to Table 1 and (1), the digit 4 is represented by
x(t) = A sin(2π770t) +A sin(2π1209t).
Note that the frequencies in the table are chosen to avoid harmonics, as none is a multiple of
any other, and none is equal to the sum or difference of any other. Symbols in the last column
are reserved for future use. When dialing a number, a dialing tone is transmitted, followed
by a sequence of 10 signals with frequencies based on Table 1, according to the number they
represent.
Additional signaling tones, besides the basic symbols, for the DTMF system are listed in
Table 2.
1.1 System specifications
Telephone quality voice signals are usually sampled at 8 kHz. This value also ensures that there
will be no aliasing even with the highest DTMF tone (1633 Hz). Specifications for the DTMF
signaling system are outlined by the International Telecommunications Union (ITU) CCITT
Red Book, vol. VI, Fascicle VI.1, Oct. 1984. Some important ones are listed below:
Frequency tolerance. Any frequency within 1.5% of the ideal frequencies in Table 1 should
be deemed as a valid signal. Any frequency above 3.5% of a valid frequency should be ignored.
2
Tone duration. Tones less than 23ms long should not be detected. Tones at least 40ms long
should always be detected. Interruptions that are less than 10ms long are not to be interpreted
as two separate signals. This implies that digits should be spaced by at least 10ms.
Frequency twists. Upper frequency must be no more than 8 dB below, or 4 dB above, the
lower frequency.
2 Project Requirements
Write a MATLAB function that accepts as input a .mat file containing an audio signal of a
DTMF (touch-tone) dialing sequence, and correctly identifies and prints out the number that
was dialed. Your processing architecture will rely on Goertzel’s algorithm to identify the tones,
but may vary in the details of the Goertzel parameters and other functions and steps that you
use. The MATLAB Signal Processing Toolbox includes a function goertzel that you may
employ.
You will also write a report for your project. Items to be included in your report:
1. An overview description of how your algorithm works. This must include a block diagram
of the major processing steps with a description of the rationale behind each step. It
should identify the major MATLAB functions or code blocks corresponding to each major
function in your block diagram.
2. A brief description of the theory underlying the processing steps. Explain the analyses
and design decisions that led to each of your parameter choices.
3. A complete listing of the MATLAB programs used. Code must be sufficiently modular and
well commented to be understood readily. Listings must also be included for any functions
used, except for those which are built into either MATLAB or its Signal Processing
Toolbox.
Upload a single .zip file containing your MATLAB code and written report on D2L by the
deadline. Late submissions will NOT be accepted. See below for further instructions on naming
the zip file and how your code must be organized. Your program will be tested by applying it
to three test signals (not the same three provided for development of your algorithm.)
Start working early. If you encounter problems, ask questions during office hours.
3 References
Several reference papers are provided in the section for this project on D2L. Although thor-
ough reading and understanding may not be necessary, you may find these sources useful for
ideas about processing approaches and pitfalls. Remember that apart from using Goertzel’s
algorithm, other details are up to you.
3
4 Data
Sample data sequences are located in the tt_samples.zip file available on D2L. The following
files are included in the zip
• Three sample touch tone audio files. Each is a MATLAB .mat file, with a name in the
form nnn-nnn-nnnn_nn.mat. The portion of the file name before the underscore character
is the phone number encoded in the file. The portion after the underscore denotes the
signal-to-noise ratio in dB. For example, a file named 517-001-4520_25.mat would be
an audio sequence dialing the number 517-001-4520 observed in noise at SNR = 25
dB. The data is always sampled at 8 kHz. Use MATLAB’s load command to load the
data, which will appear as a single vector with the name signal. You can also use the
commands sound(signal,8000) or soundsc(signal,8000) to listen to the signal. Each
sample signal includes a 1 sec dial tone at the beginning, followed by the ten digits of
the phone number, followed by 1 sec of silence. The digits are separated by quiet spaces.
Duration of the digits varies randomly between 80 ms and 400 ms, while the duration
of quiet spaces varies randomly between 50 ms and 200 ms. White noise is added at
the specified SNR, including the “quiet” spaces between the digits and the one second of
“silence” at the end. The signals will have neither short interruptions in them, nor any
frequency “twist” (imbalance between the amplitude of the two tones). There will always
be exactly 10 digits (standard U.S. telephone number), but you should not rely on this
fact in your code.
• The MATLAB file tt_create.m that was used to generate the sample data. This file will
be useful to see how the test sequences were generated, and you can use it to generate
new test sequences of your own. You can also modify this file if you want to generate
test sequences with different parameters, e.g. by introducing “twist” into the data, or
allowing interruptions in digits.
5 Signal Processing issues
The following are some considerations and questions you must deal with in designing your
decoding algorithm
1. Analysis window. You will want to analyze the frequency content of a short segment of
the signal at a time. You will need to decide the length and amount of overlap among
segments. Issues to consider include the following:
• The segment length should be long enough to provide adequate frequency resolution
between DTMF tones; and
• The segments should be short enough to recognize that there are two different tones
(digits) when they are separated by the minimum digit spacing of at least 10ms.
4
Thoroughly document and provide a rationale for your parameter choices.
2. DFT Size N : What DFT size will guarantee retrieval of the frequencies in your data
within the 1.5% accuracy required by the DTMF specification? Do you want to use one
value of N for all eight frequencies, or one for the low band and one for the high band, or
a different N optimized for each frequency you are trying to detect? As before, document
and justify your choice of N .
3. Detection threshold: Since there will be noise present, provide a mechanism to determine
if there is a signal present, or if a segment represents a ”quiet” space. Since the signal
starts out with a dial tone, you do not have the luxury of a noise-only segment at the
beginning. One approach could be to compare outputs across Goertzel filters to seek
the maximum, or alternatively compare the average output with some minimum value.
Either way, justify your thresholding mechanism.
4. High and low bands. Many DTMF structures start by filtering the data into two bands,
one passing all high tones, and the other all low tones. If you choose to do this, justify
your parameter choices.
5. Decision logic. Your basic filtering and frequency analysis will identify the frequencies
present in the data as a function of time. You will then have to devise some decision logic
to convert this information into a series of digits.
6 MATLAB code submission and evaluation
1. Your deliverable must contain the entire MATLAB code, including all functions and
subfunctions and data files required to run your algorithm on a test signal. Place all
files in a single flat directory (no subdirectories inside) and create a zip file with the
name YourLastName_YourFirstName_Project.zip. Do not include any functions that
are built into MATLAB or its Signal Processing Toolbox.
2. Your top level function must have as its first line
function digits = tt_decode(x)
Furthermore, it must work when all of the files in your zip file have been unzipped and
placed in the working MATLAB directory.
3. Your program should produce an output: that is simply the phone number that is de-
tected, in phone number format, i.e. the output should look something like
517-001-4520
5
if that was the signal passed into it.
4. Your code will be tested by executing the command
digits = tt_decode(signal)
using various test signals as the input variable signal. Be absolutely certain that
your program will run correctly when unzipped into the MATLAB work di-
rectory and this command is typed into MATLAB.
The test will consist of running your algorithm with several sound files representing various
phone numbers different from those in tt_samples with fairly good SNRs. Also a sequence
of signals corresponding to new phone numbers with SNRs decreasing from 50 dB to 20
dB in 10 dB steps, and then down to 0 dB in 5 dB steps will be applied. The purpose
of this test is to see determine the noise level at which your algorithm “breaks” (either
crashes or returns an incorrect phone number). You can use tt_create to create your
own test signals with various SNRs, in exactly the same way I will create all of my test
signals.
7 Grading
Your grade in this project will be calculated as follows:
• Code performance: 70%
– Performance on assorted high-SNR signals: 30%
– Performance on decreasing-SNR signals: 30%
– Correctness of output format: 10%
• Report: 30%
– Algorithm and parameter description and rationale: 10%
– Code listing and readability: 10%
– General report quality (complete but succinct, figs and writing): 10%
6
Appendix A Windowing
When processing even infinite duration signals, we are forced to process finite segments of them.
This is equivalent to multiplying a signal x[n] with a window w[n]
v[n] = x[n]w[n]
which in the frequency domain becomes convolution of the corresponding DTFTs
V (ejω) = X(ejω) ∗W (ejω) = 1

∫ π
−π
X(ejθ)W (ej(ω−θ))dθ. (2)
In the simplest case this window is the so-called rectangular one
w[n] =
{
1, 0 ≤ n ≤ L− 1
0, otherwise
with DTFT
W (ejω) = e−jω(L−1)/2
sin(ωL/2)
sin(ω/2
.
We have also seen examples of different windows in Chap. 7 of your textbook and Lecture
9. MATLAB provides implementations of many windows and also has a ”Window Designer”
app accessible by the windowDesigner command. Fig. 1 shows the DTFT W (ejω) of a shifted
rectangular window w[n] = ejω0n, 0 ≤ n ≤ L − 1 of length L, and illustrates some important
parameters of the window. The so-called ”main lobe” of the window is centered at ω0. The
other lobes are termed ”side lobes”. The 3dB width is the range of frequencies which a signal
can pass without its power being attenuated by more than a factor of 2. Some properties, such
as the width of the main lobe, and the amplitude of the side lobes for different windows are
outlined in Table 3. Note that the window shape (type) and the length L affects the main lobe
width, and correspondingly determines the resolution in the frequency domain.
The convolution in (2) smears the DTFT of X(ejω). In the case of sinusoids, this causes
oscillations in the magnitude of the frequency response. As an example, consider the discrete-
time signal
x[n] = cos(ω0n) + 0.75 cos(ω1n), −∞ < n <∞. (3)
After windowing x[n] with a window w[n], the DTFT of v[n] is
V (ejω) =
1
2
W (ej(ω−ω0)) +
1
2
W (ej(ω+ω0)) +
0.75
2
W (ej(ω−ω1)) +
0.75
2
W (ej(ω+ω1)) (4)
so the DTFT of the window is shifted to the frequencies ±ω0 and ±ω1 and appropriately scaled.
Fig. 1 shows this effect for a rectangular window of length 64 and different values of ω1 and
ω2. From the figures we can see that the smearing caused by windowing affects our ability to
distinguish the two sinusoids, especially when their frequencies are close.
Typically, larger L decreases the mainlobe width, and consequently increases frequency
resolution, at the cost of time resolution.
7
Figure 1: DTFT of w[n] = ejω0n, 0 ≤ n ≤ L− 1.
Table 3: Comparison of commonly used windows of length L.
Type of window Peak side lobe amplitude (Relative) (dB) Approximate Width of Main Lobe 3dB Bandwidth
Rectangular −13 4π/(L+ 1) 0.89 2πL
Hann −31 8π/L 1.44 2πL
Hamming −41 8π/L 1.30 2πL
Blackman −57 12π/L 1.68 2πL
8
Figure 2: (a) Magnitude of the DTFT W (ejω) of a rectangular window of length 64. (b)
Magnitude of the DTFT V (ejω) = X(ejω) ∗W (ejω) when x[n] is the sum of two sinusoids at
frequencies ω0 = 2π/6 and ω1 = 2π/3. (c) Magnitude of the DTFT V (e
jω) = X(ejω) ∗W (ejω)
when x[n] is the sum of two sinusoids at frequencies ω0 = 2π/14 and ω1 = 4π/15. (d) Magnitude
of the DTFT V (ejω) = X(ejω) ∗W (ejω) when x[n] is the sum of two sinusoids at frequencies
ω0 = 2π/14 and ω1 = 2π/12. (e) Magnitude of the DTFT V (e
jω) = X(ejω) ∗W (ejω) when
x[n] is the sum of two sinusoids at frequencies ω0 = 2π/14 and ω1 = 4π/25.
9
Appendix B Effects of frequency sampling
Recall that the Discrete Fourier Transform (DFT) is a sampled version of the continuous DTFT,
X[k] = X(ejω)|ω=2πk/N , for k = 0, . . . , N − 1.
This sampling of the frequency domain can, in many cases, produce misleading results. To see
this consider Fig. 3. Fig. 3(a) shows the windowed sequence (rectangular window)
v[n] = cos(

16
n) + 0.75 cos(

8
n), 0 ≤ n ≤ 63.
Fig. 3(b) shows the magnitude of the DTFT V (ejω) in the solid line, whereas the dots indicate
the magnitude of the samples of the DFT |V [k]| for N = 64. In this case, ω1 = 2π8 corresponds
to the DFT sample k = 8 as 2πk64 =
2π8
64 =

16 = ω1 and ω0 =

16 corresponds to the DFT sample
k = 4 as 2πk64 =
2π4
64 =

16 = ω0. Note that the locations of the peaks in the DFT coincide with
the locations of the maximum peaks in the DTFT. Fig. 3(c) shows the same DTFT and the
samples of the DFT for N = 128. With this finer sampling of the frequencies the windowing
effects in the spectrum are becoming more evident!
Fig. 4 is another example of the issues caused by frequency sampling. Fig. 4(a) shows the
windowed sequence (rectangular window)
v[n] = cos(

14
n) + 0.75 cos(

15
n), 0 ≤ n ≤ 63.
Fig. 4(b) shows the magnitude of the DTFT V (ejω) in the solid line, whereas the dots indicate
the magnitude of the samples of the DFT |V [k]| for N = 64. In this case, 2πkN = 2πk64 cannot
take the value 2π14 or

15 (the frequencies in our signal) for any integer value of k. Thus in
this case the locations of the peaks in the DFT values will not correspond with the peaks in
the DTFT and the relative amplitudes of the peaks in the DFT will not necessarily reflect the
relative amplitudes of the peaks in the DTFT.
This effect, where the DFT sometimes yields misleading shapes, or significantly different
shapes for similar signals is termed the picket fence effect. Straddle (or scallop) loss is defined
as the loss in amplitude when a sinusoidal frequency does not correspond to a DFT sample
frequency, i.e. the DFT samples miss the peak of the DTFT sinc. The maximum loss in such
a case is when the DFT sample is approximately half the width of the main lobe off-center.
Fig. 5 shows the straddle loss in dB for various windows, as a function of ”bins”, i.e. 1 bin
corresponds to a (discrete) frequency difference of 2πN .
In addition to the window length L, the sampling period N of the DFT determines the
resolution in the frequency domain. Larger N can somewhat mitigate the picket fence effects,
however it increases complexity.
10
(c)
Figure 3: (a) Sequence that is a sum of two sinusoids multiplied by a rectangular window of
length L = 64. (b) Magnitude of the DTFT V (ejω) (solid line) and magnitude of the samples
of the DFT |V [k]| for N = 64. (c) Magnitude of the DTFT V (ejω) (solid line) and magnitude
of the samples of the DFT |V [k]| for N = 128.
11
(b)
Figure 4: (a) Sequence that is a sum of two sinusoids multiplied by a rectangular window of
length L = 64. (b) Magnitude of the DTFT V (ejω) (solid line) and magnitude of the samples
of the DFT |V [k]| for N = 64.
Figure 5: Straddle loss for various windows. Original figure: https://en.wikipedia.org/
wiki/Spectral_leakage
12
Appendix C Notes on parameter selection
C.1 The MATLAB Goertzel function.
You can access the Goertzel algorithm in MATLAB using the goertzel command. For a
sequence x[n] goertzel returns its DFT X[k] for specific frequency indices k. Suppose the
length of x[n] is N and we want to compute the DFT for the frequencies ωk =
2πk
N , k =
0, 1, . . . , 4. This can be accomplished by
freq_indices = 0:4; %k=0,1,...4
X = goertzel(x,freq_indices);
Computation of the DFT for specific continuous time frequencies f can be accomplished by
appropriately selecting the frequency indices.
C.2 DFT analysis example
Suppose that we want to analyze a signal sampled at Fs = 1/Ts = 8 kHz. The desired frequency
resolution (3dB mainlobe width) is 20Hz, and we will be using a Hamming window, as it has
reduced DTFT sidelobes. The desired maximum frequency sampling error is ±2 Hz. Based on
the aforementioned specifications we want to figure out the number of samples required for our
window L and the DFT period N .
Let’s start from the desired frequency resolution. Looking at Table 3 we see that the 3dB
bandwidth for the Hamming window is 1.30 2πL radians (Note this is in discrete-time frequency
units). First, we have to convert 20 Hz into radians, using the relationships Ω = 2πf and
ω = ΩTs = Ω/Fs. Based on these the desired 3 dB bandwidth in radians is 0.005π. Then
solving for L in 1.30 2πL = 0.005π we obtain L = 520. This is our window size that conforms to
our frequency resolution specifications.
Next, let’s look at the frequency sample error and what this means for the DFT period N .
In general, we know that our N should be greater than or equal to our sequence length (in
this case L = 520). An N -point DFT samples the DTFT at 2πkN radians. Since we have that
ω = ΩTs = Ω/Fs and Ω = 2πf , this means that the DFT takes samples every
k
NTs
= kN Fs Hz.
The DFT samples are spaced FsN Hz apart. If we wish to have a maximum frequency sampling
error of ±2 Hz, this means that frequency samples should be spaced 4 Hz or less apart; Solving
for N , we obtain N ≥ Fs/4 = 2000 samples.
C.3 Compliance with CCITT specifications
Frequency tolerance.
• Recall that any frequency within 1.5% of an ideal frequency (see Table 1) should be
deemed a valid signal. The tolerance around the frequencies ranges from 10.5 to 24.5 Hz.
13
Note that we don’t need samples within 1.5% of arbitrary frequencies, only the 8 DTMF
ones considered in Table 1 (not the dial tones).
• Any frequency outside 3.5% of an ideal frequency should be ignored. The rejection range
around frequencies ranges from 24.4 to 57.2Hz.
The above considerations constrain the DFT period N , requiring that DFT samples aren’t
too close or too far. A lower bound on N is provided by the window/frame length L. If N is
large enough, we will have a DFT sample close to any frequency of interest. However, as N
grows so does computational complexity.
An easy way to find the smallest N that works is to let MATLAB run a loop over a range of
N values: At each iteration of this loop find the nearest DFT indices k per DTMF signal, and
assess the error. Then select the smallest N for which the largest error is smaller than 1.5%.
Tone duration
• Tones less than 23ms long should not be detected. At a sampling rate of 8kHz, this
suggests that tones whose length is less than 184 samples should not be detected.
• Tones at least 40ms long should always be detected. At a sampling rate of 8kHz, this
corresponds to 320 samples.
• Interruptions of less than 10ms are not to be interpreted as two separate signals. A 10ms
interruption between digits corresponds to 80 samples at a sampling rate of 8 kHz.
Frequency resolution
Note that the smallest low band difference is 770 − 697 = 73Hz, whereas the highest band
difference is 127Hz. The window length should be chosen accordingly to be able to distinguish
the different DTMF frequencies.
Finally, note that whether specifications are met or not depends also on the decision logic.
essay、essay代写