Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EE 5410 Signal Processing

MATLAB Exercise 1


Telephone Touch-Tone Signal Encoding and Decoding


Intended Learning Outcomes:

On completion of this MATLAB laboratory exercise, you should be able to

1 Generate and decode telephone touch-tone signals

1 Understand the impact of additive noise in decoding touch-tone signals

Deliverable:

1 Each student is required to submit an answer sheet which contains only answers

to the questions in this document on or before 23 September 2022. Background:

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, which are depicted in Table 1, are generated and summed to give 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, and mathematically, it can be generated as

x(t) = cos(2π ⋅ 770t) + cos(2π ⋅ 1336t)

In fact, the frequencies in Table 1 are chosen to avoid harmonics. No frequency is an integral 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 dialled signal in the presence of non-linear line distortion.

Frequency (Hz)

1209

1336

1477

697

1”

2”

3”

770

4”

5”

6”

852

7”

8”

9”

941

“*”

0”

“#

Table 1: DTMF encoding for touch-tone dialling

Decoding of DTMF signals can be achieved via using a simple finite impulse response (FIR) filter bank which is shown in Figure 1. The filter bank consists of 7 bandpass filters (BPFs) where each filter passes only one of the 7 possible DTMF frequencies. 

 

 

 

 

 

 

Detect

dual tones

Figure 1: Block diagram for DTMF signal decoding

When the input x[n] to the filter bank is a DTMF signal, the outputs from two of the BPFs should be larger than the rest. If we detect the two largest outputs, the two corresponding frequencies can be found. These frequencies are then used as row and column pointers to determine the key from the DTMF code. A possible measure of the output levels can be 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.

Procedure:

1.    If you are not familiar with MATLAB, you can view the MATLAB introduction by typing intro at the MATLAB prompt. This short introduction will demonstrate some of the basics of using MATLAB. Or you can explore the MATLAB help capability which is available at the command line, such as help, help plot and help clear, where plot and clear are command names. Apart from a number of MATLAB reference books such as [1]-[2] which can be found in City University’s library, many on-line MATLAB resources, including [3]-[4], are available.

2.    Create a file named toneA.m” with the following MATLAB code:

clear all

Fs=4000;

Ts=1/Fs;

t=[0:Ts:0.3];

F_A=440;              %Frequency of note A is 440 Hz

A=sin(2*pi*F_A*t);

sound(A,Fs);

Type toneA at the command line and then answer the following:

(a)     What is the time duration of A?

(b)      How many elements are there in A?

(c)      Modify toneA.m by changing F_A=440” to F_A=800” . Can you hear any difference? Describe the difference if any.

(d)     The frequencies of notes B, C#, D, E and F# are 493.88 Hz, 554.37 Hz, 587.33 Hz, 659.26 Hz and 739.99 Hz, respectively. Write a MATLAB file named “song.m” to produce a piece of music with notes in the following order : A, A, E, E, F#, F#, E, E, D, D, C#, C#, B, B, A, A. Assign the duration of each note as 0.3s.

3.    Create a file named tone.m” with the following MATLAB code:

function x = tone(frequency, observation_length);          % x=tone(frequency, observation_length) is used to generate % a sinusoidal signal x with frequency and observation     % length specified in the arguments.

fs = 4000;

Ts = 1/fs;

t = [0:Ts:observation_length];

x = cos(2*pi*frequency*t);

Note that tone is a user-defined MATLAB function. Try the following commands: help tone and y=tone(200,0.5). What are the uses of these two commands?

4.   Write a  MATLAB function  named  dtmfdial.m, to  implement a  DTMF dialer based on the frequency table in Table 1. A skeleton of dtmfdial.m is given as follows:

function xx=dtmfdial(keyName)

%DTMFDIAL   Create a DTMF tone

%usage: xx=dtmfdial(keyName)

% keyName = character which is one of the valid key names

% xx = signal vector that corresponds to the DTMF dtmf.keys = ['1','2','3';

'4','5','6';

'7','8','9';

'*','0','#'];

ff_cols = [1209,1336,1477];

ff_rows = [697;770;852;941];

dtmf.colTones = ones(4,1)*ff_cols;

dtmf.rowTones = ff_rows*ones(1,3);

Complete dtmfdial.m so that it implements the following:

(i)       The input to the function is one of the valid key names, i.e., ‘1’ to ‘#’.          (ii)      The output should be a vector of samples at sampling frequency fs  = 8000

Hz containing the DTMF tone. Each DTMF signal is the sum of a pair of sinusoidal signals with same amplitudes of 1, and the time duration is 0.2s.

(iii)      The   frequency   information   is   given   in   two   4 × 3   matrices,   namely,

dtmf.colTones and dtmf.rowTones. To translate a key into the correct locations of the two matrices, the find function can be used. An example of using find when keyName='3' is:

[ii,jj] = find('3'==dtmf.keys)

ii=1 and jj=3 will then be obtained.

(iv)      Play the sound of the DTMF tone using soundsc.

5.    One simple way to implement a BPF for a single frequency is to use the following impulse response:

h[n] = cos( ωn),            0 ≤ n < L

where ω is the center discrete-time frequency of the BPF and L  is the FIR filter length. Use MATLAB to generate the impulse response of the BPF with ω = 0.2π .

(a)     Try the cases of L = 50  and L = 500 . Plot the magnitudes of the frequency

spectra of the two filters using freqz. What do you expect about the shape of the magnitude when L → ∞ ? An example of using freqz is:

[a,b] = freqz(h);     %h is the impulse response

plot(b,abs(a));

(b)      Compute the energies of h[n] for L = 50   and L = 500 . The energy of h[n]

is defined as

Eh  =  h[n] 2

(c)     To relate the discrete-time frequency with the continuous-time frequency, the impulse response of the BPF for DTMF decoding is determined as:

h[n] =  cos,           0 n < L

where  fb    is  the  center frequency  of the  BPF  and  f s    is  the  sampling frequency, both in Hz.

Which filter will give a better DTMF decoding performance, h[n] with L = 50 or L = 500 ? Explain your answer.

6.   Write      a      MATLAB      function      named      dtmfdetect.m  (function dtmfdetect(keyName,L,noise_power)) to implement a DTMF encoder and decoder in a noisy environment. The requirements of the dtmfdetect function are given as follows:

(i)       The input to the function consists of one of the valid key names, filter length of the  BPF  and  noise  power.  That  is,  dtmfdetect ('1',50,1) will generate a DTMF tone 1” with L = 50 and the tone is corrupted by a zero- mean white Gaussian noise with power of 1. The output will show the result of the detection, namely, displaying a message of The detected key is 1, if it is correct.

(ii)       Each  DTMF signal is the sum of a  pair of sinusoidal signals with same

amplitudes of  1,  and the time duration  is  0.2s with  sampling frequency f s  = 8000 .

(iii)      To add a zero-mean white Gaussian noise to the noise-free DTMF tone, you

can use the randn command. An example of using randn is:

noise = sqrt(0.1)*randn(1,10);

where a zero-mean Gaussian noise sequence of length 10 with power of σ 2  = 0. 1 will be generated.

(iv)      To detect the DTMF tone frequencies, you first need to pass the signal to a

filter bank of 7 BPFs whose center frequencies are 697 Hz, 770 Hz, 852 Hz, 941  Hz,  1209  Hz,  1336  Hz and  1477  Hz. The DTMF tone can then be deduced from the two outputs with the largest energies. An example of producing the output signal given the input and FIR filter coefficients is

y=conv(x,h);     % x is the input and h is the filter

% impulse response

An example of computing the energy of a signal is

energy = sum(y.*y);

Try your dtmfdetect function with various keys, different L  ( L = 50 and L = 500 ) and noise powers ( σ 2  = 0 , σ2  = 10 and σ2  = 100 ). For each setting, perform 20 trials and record the number of correct detections in the following table. For example, if the DTMF tone is “1” , and “1” is correctly detected 18 times at  L = 50 and σ 2  = 0 , write down the number 18 in the corresponding entry.

Key

L = 50

σ 2  = 0

L = 500

σ 2  = 0

L = 50

σ2  = 10

L = 500

σ2  = 10

L = 50  σ2  = 100

L = 500 σ2  = 100

1

 

 

 

 

 

 

2

 

 

 

 

 

 

3

 

 

 

 

 

 

4

 

 

 

 

 

 

5

 

 

 

 

 

 

6

 

 

 

 

 

 

7

 

 

 

 

 

 

8

 

 

 

 

 

 

9

 

 

 

 

 

 

0

 

 

 

 

 

 

*

 

 

 

 

 

 

#

 

 

 

 

 

 

References:

[1]    S.  Attaway,  MATLAB: A  Practical  Introduction  to  Programming  and  Problem

Solving, 5th Edition, Butterworth-Heinemann, 2019

[2]    A . Gilat, MATLAB: An Introduction with Applications, 5th Edition, John Wiley &

Sons, 2015

[3]   https://help.eng.cam.ac.uk/software/matlab/

[4]   https://www.mathworks.com/help/matlab/index.html

[5]    L . Schenker, "Pushbutton calling with a two-group voice-frequency code,"  The

Bell System Technical Journal, vol.39, no . 1, pp .235–255, 1960

[6]    J. H. McClellan, R. W . Schafer and M. A. Yoder, Signal Processing First, Prentice-

Hall, 2003