Due Date: Week of May 01, 2017 1 George Mason University ECE 201: Introduction to Signal Analysis Computer Project Part II Project Description Due to the length and scope of this project, it will be broken down into two parts. As a result, the project will be worth two labs in terms of your lab grade. This document is Part II of the project. Lab Report Your project report that you will submit by the due date will contain write-ups for what is asked for in both parts of the project. There is an Instructor Verification Sheet that must be filled out and signed by your lab TA or instructor, and turned in to your TA. Honor Code Forgeries and plagiarism are a violation of the honor code and any reasonable suspicion of an honor code violation will be reported. You are allowed to discuss lab exercises with other students, but the submitted work should be original and it should be your own work. 1 Introduction The goal of this project is to introduce 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. In Part I of the project, you designed a system that will generate the DTMF signals to dial a telephone number. In this part, you will design and implement the bandpass FIR filters that are required in order to automatically decode the DTMF signals. Your complete system will consist of a touch tone dialer and a DTMF decoder. 2 Background 2.1 Telephone Touch Tone 2 Dialing Telephone touch pads generate dual tone multi frequency (DTMF) signals to dial a telephone. When a key is pressed, the tones of the corresponding column and row (in Fig. 1) are generated and summed, hence dual tone. In Part I of this project, you wrote a function dtmfdial, to implement a DTMF dialer that generates the appropriate dual tone for each key on the pad of a telephone as specified in Fig. 1. The features of your program are: 1. The input to the function is a vector of numbers, each one being between 1 and 12, with 1 9 corresponding to the digits, 10 corresponds to the * key, 11 is the 0 key, and 12 is the # key. 2. The output is a vector containing the DTMF tones, sampled at f s = 11025 Hz. The duration of each tone is about 0.2 sec. with a silence of about 0.05 sec. long to separate the DTMF tones. 1 The due date is for a single project report that contains the required information from parts I and II. 2 Touch Tone is a registered trademark
freqs 1209 Hz 1336 Hz 1477 Hz 697 Hz 1 2 3 770 Hz 4 5 6 852 Hz 7 8 9 941 Hz * 0 # Figure 1: DTMF encoding table for Touch Tone dialing. When any key is pressed the tones of the corresponding column and row are generated and summed. 3. The frequency information is given as two 4 3 matrices (tone rows and tone cols): one containing the row frequencies, the other the column frequencies. A digit is translated into the correct location in these 4 3 matrices by using quotients and remainders. Your function should create the appropriate tone sequence to dial an arbitrary phone number and, when played through a telephone handset, will be able to dial the phone. 3 Project Part II: DTMF Decoding In this part of the project, you are to design a decoder that will take the dual tone output from youra dialer and determine what key was entered. There are several steps to decoding a DTMF signal: 1. Divide the signal into shorter time segments representing individual key presses. 2. Filter the individual segments to extract the possible frequency components. Bandpass filters can be used to isolate 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, *, 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. A filterbank is nothing more than a bank of filters that are connected in parallel. The filter bank in Fig. 2 consists of seven bandpass filters where each filter passes only one of the seven possible DTMF frequencies. The input signal for all the filters is the same DTMF signal. Here is how the system works: 1. 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. 2. By determining which two filters produce the largest output, the frequencies may be determined. 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 that sinusoid. 3. These frequencies are then used to determine the DTMF code.
697 Hz y 1 [n] 770 Hz y 2 [n] x[n] 852 Hz y 3 [n] 1336 Hz y 6 [n] 1477 Hz y 7 [n] Figure 2: Filter bank consisting of bandpass filters which pass frequencies corresponding to the seven DTMF component frequencies listed in Fig. 1. 1 0.8 0.6 0.4 0.2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Normalized Frequency (x π rad/sample) Figure 3: L-point averaging filters for lengths L = 5, 9, 11, 15, 21. 3.1 Bandpass Filter Design As we have seen, an L-point averaging filter, h[n] = 1 L 1 δ[n k] L k=0 is a lowpass filter, and the width of the passbands of these filters is inversely proportional to L. For example, shown in Fig. 3 are L-point averaging filters for L = 5, 9, 11, 15, 21. Note that as the length L increases, the width of the passband decreases. To isolate the tones generated by a DTMF dialer, we would like to design a bank of bandpass filters. To do so, recall what we leaned about modulation: multiplying a signal by cosine shifts the spectrum of the signal up in frequency and down in frequency by an amount equal to the frequency of the cosine that is being modulated. Therefore, it should be clear that if we multiply the L-point averaging filter by a cosine of frequency ˆω c, h[n] = 2 L cos (ˆω cn), 0 n < L
0.1 5 10 2 0 5 10 2 0.1 0 2 4 6 8 10 12 14 16 18 20 1.5 Normalized Frequency (x π rad/sample) 1 0.5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Normalized Frequency (x π rad/sample) Figure 4: The impulse response and frequency response magnitude of a bandpass filter of length L = 21 with a passband centered at ˆω = 0.2π. then the result will be a bandpass filter centered at ˆω = ˆω c. For example, to design a bandpass filter with a center frequency of 0.2π, we would set ˆω c = 0.2π. In this case, the impulse response and frequency response magnitude would be as shown in Fig. 4. As with the lowpass filter, the bandwidth of the bandpass filter is controlled by L; the larger the value of L, the smaller the bandwidth. BANDPASS FILTER (centered at 0.4π) 1 Magnitude 0.8 0.6 0.4 STOPBAND 0.2 PASSBAND STOPBAND 0 0 0.5 1 1.5 2 2.5 3 Frequency (radians) Figure 5: The frequency response of an FIR bandpass filter is shown with its passband andvstopband regions. (a) Design a bandpass filter with L = 40 that will pass a cosine with a frequency ˆω = 0.4π. Make a plot of the frequency response magnitude and phase. (b) Measure the response of the filter (magnitude and phase) at the following frequencies: ˆω = 0.1πk, for k = 10, 9,..., 9, 10. Summarize the values in a table.
The passband of the bandpass filter is defined by the region of the frequency response where H(e j ˆω ) is close to its maximum value of one. Typically, the passband width is defined as the length of the frequency region where H(e j ˆω ) is greater than 1/ 2 = 0.707. Note: you can use MATLAB s find function to locate those frequencies where the magnitude satisfies H(e j ˆω ) 0.707 (similar to Fig. 5). Similarly, the stopband of the bandpass filter is defined by the region of the frequency response where H(e j ˆω ) is close to zero. Here, the stopband will be defined as the region where H(e j ˆω ) is less than 0.1. (c) Use the plot of the frequency response for the length-40 bandpass filter from part (a), and determine the passband width. Make two other plots of bandpass filters for L = 20 and L = 80, and measure the passband width in both. Then explain how the width of the passband is related to filter length L, i.e., what happens when L is doubled or halved. (d) Comment on the selectivity of the length-80 bandpass filter. Use the frequency response to explain how the filter is able to pass the components at ˆω = ±0.4π, while reducing or rejecting the others at ˆω = 0.1πk for k ±4. (e) If the input signal to the length-40 FIR BPF is x[n] = 7 + 7 cos(0.4πn + π/2) + 7 cos(0.5πn + π/4) find (by hand) the output signal (this should be a formula or an equation). (Hint: use the magnitude and phase measurements from part (a).) Comment on the relative amplitudes of the three signal components in the output signal. 3.2 DTMF Decoding A DTMF 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 determine which two frequencies are most likely to be contained in the DTMF tone. In a practical system where noise and interference are also present, this scoring process is a crucial part of the system design, but we will only work with noise-free signals to understand the basic functionality in the decoding system. To make the whole system work, it will be necessary to write three mfiles: dtrun, dtscore and dtdesign. An additional mfile called dtcut that you will use is available on the course web page, in the lab section. The main mfile should be named dtrun.m. It will call dtdesign.m, dtcut.m, and dtscore.m. The following sections lead you through the process of writing these functions. 3.2.1 Simple Bandpass Filter Design: dtdesign.m The FIR filters that will be used in the filter bank (Fig. 2) are finite-length cosines of the form: ( ) 2πfb n h[n] = β cos, 0 n L 1 f s where L is the filter length, and f s is the sampling frequency. The constant β gives flexibility for scaling the filter s gain to meet a constraint such as making the maximum value of the frequency response equal to one. The parameter f b defines the frequency location of the passband, e.g., we pick f b = 852 if we want to isolate the 852 Hz component. The bandwidth of the bandpass filter is controlled by L; the larger the value of L, the narrower the bandwidth.
function hh = dtdesign(fcent, L, fs) DTDESIGN hh = dtdesign(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. Figure 6: Skeleton of the dtdesign.m function. Complete this function with additional lines of code. (a) Devise a strategy for picking the constant β so that the maximum value of the frequency response will be equal to one. Write the one or two lines of MATLAB code that will do this scaling operation in general. There are two approaches here: (i) Mathematical: derive a formula for β from the formula for the frequency response of the BPF. Then use MATLAB to evaluate this closed-form expression for β. (ii) Numerical: let MATLAB measure the peak value of the unscaled frequency response, and then have MATLAB compute β to scale the peak to be one. (b) Complete the mfile dtdesign.m given in Fig. 6. This function should produce all seven bandpass filters needed for the DTMF filter bank system. The function should store the filters in the columns of the matrix hh whose size will be L 7. The rest of this section describes how to design the BPF to satisfy the following design criterion: 3 Filter Requirements The filter length L should be designed so that only one frequency lies within the passband of each BPF and all other DTMF frequencies lie in the stopband. (c) Generate the seven (scaled) bandpass filters with L = 25 and f s = 11025. Plot the magnitude of the frequency responses together on one plot (the range 0 ˆω π is sufficient because H(e j ˆω ) is symmetric). Indicate the locations of each of the 7 DTMF frequencies (697, 770, 852, 941, 1209, 1336, and 1477 Hz) on this plot to illustrate whether or not the passbands are narrow enough to separate the DTMF frequency components. Hint: use the hold command and markers as you did in the warm-up. (d) Repeat the previous part with L = 100 and f s = 11025. The width of the passband is supposed to vary inversely with the filter length L. Explain whether or not that is true by comparing the length 25 and length 100 cases. (e) Determine the smallest value of L so that the filter design specification is met, and demonstrate that your filters satisfy this design requirement. 3 Recall the definitions of passband and stopbands given in Section 3.1.
3.2.2 A Scoring Function: dtscore.m The final objective is decoding a process that requires a binary decision on the presence or absence of the individual tones. In order to make the signal detection an automated process, we need a score function that rates the different possibilities. (a) Complete the dtscore function based on the skeleton given in Fig. 7. The input signal xx to the dtscore function must be a short segment from the DTMF signal. The task of breaking up the signal so that each short segment corresponds to one key is done by the function dtcut prior to calling dtscore. The implementation of the FIR bandpass filter is done with the conv function, but your could also use the filter function. The running time of the convolution function is proportional to the filter length L. Therefore, the filter length L must satisfy two competing constraints: L should be large so that the bandwidth of the BPF is narrow enough to isolate individual frequency components, but making it too large will cause the program to run slowly. Try to make your system work reliably with the smallest possible value for L. function sc = dtscore(xx, hh) DTSCORE usage: sc = dtscore(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] Figure 7: Skeleton of the dtscore.m function. Complete this function with additional lines of code. (b) Use the following rule for scoring: the score equals one when max y i[n] 0.95; otherwise, it is zero. The signal y i [n] is the output of the i-th BPF. Note: Prior to filtering and scoring, make sure that the input signal x[n] is normalized to the range [ 2, +2]. With this scaling the two sinusoids that make up x[n] should each have amplitudes of approximately 1.0. 4 Therefore the scoring threshold of 0.95 corresponds to a 95 level for detecting the presence of one sinusoid. Be careful to scale only x[n] and not y i [n]. (c) The scoring rule above depends on proper scaling of the frequency response of the bandpass filters. Explain why the maximum value of the magnitude for H(e j ˆω ) must be equal to one. Consider the fact that both sinusoids in the DTMF tone will experience a known gain (or attenuation) through the bandpass filter, so the amplitude of the output can be predicted if we control both the frequency response and the amplitude of the input. 4 The two sinusoids in a DTMF tone have frequencies that are not harmonics. When plotted versus time, the peaks of the two sinusoids will eventually line up. n
Note: When debugging your program it might be useful to have a plot command inside the dtscore.m function. If you plot the first 200 500 points of the filtered output, you should be able to see two cases: either y[n] is a strong sinusoid with an amplitude close to one (when the filter is matched to one of the component frequencies), or y[n] is relatively small when the filter passband and input signal frequency are mismatched. 3.3 DTMF Decode Function: dtrun.m The DTMF decoding function, dtrun must use information from dtscore to determine which key was pressed based on an input DTMF tone. The skeleton of this function in Fig. 8 includes the help comments. function keys = dtrun(xx,l,fs) DTRUN keys = dtrun(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 = dtdesign( 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] = dtcut(xx,fs); <--Find the tone bursts keys = []; for kk=1:length(nstart) x_seg = xx(nstart(kk):nstop(kk)); <--Extract one DTMF tone.. <=========================================FILL IN THE CODE HERE. end Figure 8: Skeleton of dtrun.m. Complete the for loop in this function with additional lines of code. The function dtrun should work as follows: (i) First, dtrun will design the seven bandpass filters that are needed. (ii) Next, the input signal that is created with your DTMF dial function needs to be broken into individual segments. This is done with a call from dtrun to dtcut, a program that has been provided to you, (iii) For each segment, dtrun will make a call to your dtscore function to score the different BPF outputs. The score returned from dtscore must be either a 1 or a 0 for each frequency. (iv) The final step is to determine the key for that segment (You must add the logic to decide which key is present). (v) The final output is the list of decoded keys. The decoding (step iv) works as follows: If exactly one row frequency and one column frequency are scored as 1 s, then an unique key is identified and the decoding is probably successful. In this case, you can determine the key by using the row and column index. It is possible that there might
be an error in scoring if too many or too few frequencies are scored as 1 s. In this case, you should return an error indicator (perhaps by setting the key equal to 1). There are several ways to write the dtrun function, but you should avoid excessive use of if statements to test all 12 cases. Hint: use MATLAB s logicals (e.g., help find) to implement the tests in a few statements. 3.3.1 Testing Once you get your system working there should be no errors with a large value of L, but when you try to reduce the filter length, the error indicator (key equal to 1) would tell you that the filter length is getting too small. Run tests to find the minimum value for L that gives reliable operation. In you lab report, describe how you tested the system to get this minimum value for L. 3.4 Telephone Numbers The functions dtdial.m and dtrun.m can be used to test the entire DTMF system as shown in Fig. 9. You could also use random digits (e.g., ceil(11.9*rand(1,22)+0.09)) in place of 1:12 in dtdial. For the dtrun function to work correctly, all the mfiles must be on the MATLAB path. >>fs = 11025; <--use this sampling rate in all functions >>xx = dtdial( 1:12, fs ); >>soundsc(xx, fs) >>L = 201; <--overkill, this filter length is way too long >>dtrun(xx, L, fs) ans = 1 2 3 4 5 6 7 8 9 10 11 12 Figure 9: Testing the DTMF system. It is also essential to have short pauses in between the tone pairs so that dtcut can parse out the individual signal segments. If you are presenting this project in a lab report, demonstrate a working version of your programs by running it on the following phone number: 124-867-5309 In addition, make a spectrogram of the signal from dtdial to illustrate the presence of the dual tones. 3.5 Demo When you submit your lab report, you must demonstrate your work to your TA. Get your code and files ready for the demo. You should call dtrun for a signal xx provided by your TA. The output should be the decoded telephone number. The evaluation criteria is shown at the end of the verification sheet.
Lab Project ECE-201 Spring - 2017 INSTRUCTOR VERIFICATION PAGE Turn in this sheet to your TA. Name: Date of Lab: Part 3.1 in Part I of the project: Explain the row-column indexing into frequency table: Write the table below, and then write down the playing order of the frequencies. Determine the total length of the soundsc() signal in seconds. Verified: Date/Time: Part 3.3 in Part I of the project: Complete the dialing function dtmfdial.m: Verified: Date/Time: DTMF Decoding Evaluation Does the designed DTMF decoder decodes the telephone numbers correctly for the following values of L? L=30 All Numbers Most None L=53 All Numbers Most None L=75 All Numbers Most None
Appendix function [nstart,nstop] = dtcut(xx,fs) DTCUT Find the DTMF tones within x[n] usage: [nstart,nstop] = dtcut(xx,fs) xx = input signal vector fs = sampling frequency length of nstart = M = number of tones found nstart is the set of STARTING indices nstop is the set of ENDING indices Looks for regions of silence at least 10 millisecs long with tones longer than 100 msec setpoint = 0.02; zero everything below 2 zero xx = xx(:) / max(abs(xx)); normalize xx Lx = length(xx); Lz = round(0.01*fs); xx = filter(ones(1,lz) / Lz, 1, abs(xx)); xx = diff(xx > setpoint); jkl = find(xx ~= 0) ; xx(jkl); if xx(jkl(1)) < 0, jkl = [1; jkl]; end if xx(jkl(end)) > 0, jkl = [jkl; Lx]; end jkl ; indx = []; while length(jkl)>1 if jkl(2)>(jkl(1)+10*lz) indx = [indx, jkl(1:2)]; end jkl(1:2) = []; end nstart = indx(1,:); nstop = indx(2,:);