A decoding system needs two by 016AH4B


Introduction to Signal

  Lab Report 6

   Name of the Student:        Babak R Ghazi

   Lab Section:                          L03

   Recitation Instructor:   Dr. John Bordelon

   Submitted to:

        MATLAB is a useful programming tool that, for this particular lab, can be used to
study the response of FIR filters to inputs such as complex exponentials and sinusoids. In
addition we will use FIR filters to study properties such as linearity and time-invariance.
The purpose of this lab is not only to use sinusoidal signal to transmit information (in this
case dial tones) but to learn how to characterize a filter by knowing how it reacts to
different frequency components in the input.


In the first part of the lab, two signals need to play one after the other. This is done by
concatenation. To do this in MATLAB, you must first make each signal a row vector, and
then using the matrix building notation described below:

                               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.
Next, a DTMF dialer must be produced. This MATLAB function, dtmfdial.m takes in
a vector nums (the vector containing the integers 1-12 that correspond to the keypad) and
a sampling frequency fs and returns the appropriate tone sequence variable dtmfsig to
dial an arbitrary phone number. In Figure 1a, you can see the MATLAB code for
dtmfdial.m and in Figure 1b, you can see the spectrogram of the tones 1-12 when
[1:12] is passed in for nums and 11025 is passed in for fs.

 function dtmfsig = dtmfdial(nums,fs)
 %DTMFDIAL Create a vector of tones which will dial
 % a DTMF (Touch Tone) telephone system.
 % usage: dtmfsig = dtmfdial(nums,fs)
 % nums = vector of numbers ranging from 1 to 12
 % fs = sampling frequency
 % dtmfsig = vector containing the corresponding tones.
 tone_cols = ones(4,1)*[1209,1336,1477];
 tone_rows = [697;770;852;941]*ones(1,3);
 for ii = 1:length(nums) % loop thru the keys
 kk = nums(ii); % assign particular key
 xx = [xx,zeros(1,round(fs*silence))]; % length of silence between tones
 krow = ceil(kk/3);
 kcol = rem(kk-1,3)+1;
 xx = [xx, (cos(2*pi*(tone_cols(krow,kcol))/fs*(0:(fs*tone_len-1)))...

                                         Figure 1a

                                            Figure 1b

In the next part of the lab, a bandpass filter must be designed that will pass a frequency
component at ŵ=0.4. The filter must be of length L equal to 40. One way to do this is to
define the impulse response of an L-point FIR as:

                      h[n] =(2/L) *cos (Wc*n) where 0 <= n < L

where L is the filter length, and Wc is the center frequency that defines the frequency
location of the passband. A plot of the frequency response magnitude and phase in this
particular case is shown in Figure 2a. A table of the frequency response values is shown
in Figure 2b. Next, plots for L=20 and L=80 are made. You can see all the plots of the
frequency response magnitude and phase for L=40, L=20, and L=80 respectively in
Figure 2c. Looking at the graph you can see that passband width is inversely related to
the filter length. The passband width for L=40 is 0.14, L=20 is 0.28 and L=80 is 0.07.
The passband width is at a minimum when L=80 and at a maximum when L=20.
Comparing the passband width at L=40 with L=20, you can see that the width is doubled
when the filter length is halved. Comparing the passband width at L=40 with L=80, you
can see that the width is halved when the filter length is doubled.

         Figure 2a

 Frequency Response Values
Omega hat Magnitude Phase
       0       1.3079
       0       1.6298
       0       1.7991
       0       2.5886
       0       1.6649
       0       0.9302
       1            0
       0      -3.0731
       0      -3.0083
       0       2.7203
           0       3.1416
        0      -2.7203
        0       3.0083
        0       3.0731
        1            0
        0      -0.9302
        0      -1.6649
        0      -2.5886
        0      -1.7991
        0      -1.6298
        0      -1.3079
         Figure 2b

                                            Figure 2c
                                  (L=40, L=20, L=80 respectively)

If you look at the frequency response magnitude of the length-80 bandpass filter in Figure 2c
you can see how it is more selective then the length-20 or length-40 bandpass filter’s
frequency response magnitudes. The filter is able to pass the components at ŵ =0.4pi while
rejecting the surrounding components at ŵ =0.1k for k   5. If the input signal to the length-
40 bandpass filter was:

                       x[n]=10 + 10cos(0.4 + /2) + 10cos(0.5 + /4)

Well you know that the bandpass filter will only pass when ŵ=0.4. Then the formula for the
output signal would be:

                                    y[n]=10cos(0.4 + /2)

In the next part of the lab, we begin the DTMF Decoding. A decoding system needs two
pieces: a set of bandpass filters (BPF) to isolate individual frequency components, and a
detector to determine whether or not a given component is present. The detector must
“score” each BPF output and decide which of the tow frequencies are most likely to be
contained in the DTMF tone. In a real world application where noise and interference are
present, “scoring” is a crucial part of the system design, even though the signals we will
be working with are all noise-free.

The first part of the DTMF Decoding is the dtmfdesign.m function. This MATLAB
function takes the variable fcent(a vector containing the center frequencies), L (the length
of the FIR bandpass filters) and fs (the sampling frequency.) The functions will return a L by
M matrix, where M is the number of center frequencies. You can see the code for
dtmfdesign.m in Figure 3.1

function hh = dtmfdesign(fcent, L, fs)
% hh = dtmfdesign(fcent, L, fs)
% returns a matrix (L by length(fcent)) where each column is the
% impulse response of a BPF, one for each frequency in fcent
% fcent = vector of center frequencies
% L = length of FIR bandpass filters
% fs = sampling freq
% The BPFs must be scaled so that the maximum magnitude
% of the frequency response is equal to one.
nn = 0:1:L-1;
hh = [];
for i=1:length(fcent)
    hn = cos(fcent(i)*2*pi*nn/fs);
    ww2 = freqz(hn,1,ww);
    B = (1/(max(abs(ww2))));
    B = B .* hn;
    hh = [hh,B'];

                                          Figure 3a

Looking at Figure 3a you can see that the function produces an M number of bandpass filters
(in this case M=length(fcent)=7) and stores the filters in the columns of the matrix hh whose
size is L x 7. Passing in [697, 770, 852, 941, 1209, 1336, 1477] for fcent, 25 for L and
11025 for fs will give us the seven bandpass filters. In Figure 3b you can see a plot of the
magnitude of the frequency responses from 0  ŵ  . In Figure 3c you can see a zoomed in
version of Figure 3b with the DTMF frequencies labeled.

Figure 3b

                   697Hz 770Hz 852Hz 941Hz 1209Hz 1336Hz 1477Hz
                     1     2     3     4     5      6      7

                               1 2 3 4           5    6     7

                                          Figure 3c

Now we will increase L to 100 and leave fcent and fs the same. The width of the passband
should vary inversely with the filter length L as discussed above. Comparing Figure 3b to
Figure 3d supports the theory that the width of the passband varies inversely width the filter
length L. Now, we will choose L such that only one frequency lies within the passband of the
BPF and all other DTMF frequencies lie in the stopband (where frequencies in the passband
are greater than 0.707 and frequencies in the stopband are less than 0.25) In Figure 3e, you
can see that the selectivity (which is directly related to the magnitude of L) of the bandpass
filters allows only one component to pass while rejecting the others. In the case of Figure 3e
we have made our passbands narrow enough so that only one frequency component lies in the
passband while all others lie in the stopband.

Figure 3d

Figure 3e

The next function we will write is called dtfmscore.m, which will be used primarily to
make a binary decision on the presence or absence of individual tones. The function will take
in the variable xx (the input DTMF tone) and hh (the impulse response of one bandpass
filter) and will return a variable sc as described below:
         sc = 1 if max(|y[n]|) is greater than, or equal to, 0.95
         sc = 0 if max(|y[n]|) is less than 0.95

The MATLAB code for dtfmscore.m can be seen in Figure 4a.

 function sc = dtmfscore(xx, hh)
 % usage: sc = dtmfscore(xx, hh)
 % returns a score based on the max amplitude of the filtered output
 % xx = input DTMF tone
 % hh = impulse response of ONE bandpass filter
 % The signal detection is done by filtering xx with a length-L
 % BPF, hh, and then finding the maximum amplitude of the output.
 % The score is either 1 or 0.
 % sc = 1 if max(|y[n]|) is greater than, or equal to, 0.95
 % sc = 0 if max(|y[n]|) is less than 0.95
 xx = xx*(2/max(abs(xx))); %---Scale x[n] to the range [-2,+2]
 xx2 = firfilt(hh,xx);
 n = max(abs(xx2));
 if(n >= .95)
      sc = 1;
      sc = 0;

                                         Figure 4a

The final DTMF decoding function we will write, dtmfrun.m will use the previous
function dtmfscore.m to determine which key was pressed based on a input DTMF
tone. The function takes in xx (a DTMF waveform), L (the filter length) and fs (the
sampling frequency). The function returns the variable keys, which contain the
decoded keys, found in xx. In my MATLAB code, I had dtmfrun return the keys
as characters so that keys 10-12 (*, 0, #) would show up correctly. If a key is found that
isn’t one of the keys from 1-12 in the matrix dtmfkeys, the functions will simply return
‘?’ in its place. This could happen if you use an L that is too small. If you choose your L
to be greater than or equal to 57, then dtmfrun should decode the keys perfectly. Any L
less then 57 could cause ‘?’ to be returned for one or more keys. I found this out by
reducing L until a ‘?’ appeared somewhere in the keys output variable. In Figure 5a,
you can see the dtmfrun function. In Figure 5b you can see dtmfrun in action. In
Figure 5c you can see a spectrogram of the number 508-436-9217 (which can be seen
decoded in Figure 5b)

function keys = dtmfrun(xx,L,fs)
%DTMFRUN keys = dtmfrun(xx,L,fs)
% returns the list of key numbers found in xx.
% xx = DTMF waveform
% L = filter length
% fs = sampling freq
freqs = [697,770,852,941,1209,1336,1477];
hh = dtmfdesign( freqs,L,fs );
% hh = L by 7 MATRIX of all the filters. Each column contains the
% impulse response of one BPF (bandpass filter)
[nstart,nstop] = dtmfcut(xx,fs); %<--Find the tone bursts
keys = [];
for kk=1:length(nstart)
    n = [];
    x_seg = xx(nstart(kk):nstop(kk)); %<--Extract one DTMF tone
    for i=1:length(freqs)
         sc = dtmfscore(x_seg,hh(:,i));
         n = [n,sc];
    a = n(1:4);
    b = n(5:end);
    problem = ~(sum(a)==1 & sum(b)==1);
    if (problem)
         key = '?';
         row = find(a==1);
         col = find(b==1);
         key = dtmfkeys(row,col);
    keys = [keys,key];

                              Figure 5a

>> dtmfrun(dtmfdial([1,2,3,4,5,6,7,8,9,10,11,12],11025),57,11025)
ans =

>> dtmfrun(dtmfdial([1,2,3,4,5,6,7,8,9,10,11,12],11025),25,11025)
ans =

>> dtmfrun(dtmfdial([1,2,3,4,5,6,7,8,9,10,11,12],11025),100,11025)
ans =

>> dtmfrun(dtmfdial([5,11,8,4,3,6,9,2,1,7],11025),100,11025)
                               Figure 4b
ans =

                              Figure 5b

                                       Figure 5c


       The methods used to encode numbers into DTMF and then decode the DTMF
tones back into numbers as described in the procedure worked quite well. Using values of
L greater than or equal to 57 provide sufficient selectivity in determining the
corresponding numbers (keys) of the DTMF tones. Overall, the decoding worked well
and was 100% accurate for values of L greater than or equal to 57.


To top