0% found this document useful (0 votes)
13 views9 pages

DSP Assignment 4

The document describes the design and implementation of a digital signal processing system for decoding dual-tone multi-frequency (DTMF) signals. It includes the design of bandpass filters tuned to DTMF frequencies, a scoring function to detect tones, and a decoding function to recognize sequences of tones as dialed digits or letters. Functions and code snippets are provided as examples.

Uploaded by

gvvvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

DSP Assignment 4

The document describes the design and implementation of a digital signal processing system for decoding dual-tone multi-frequency (DTMF) signals. It includes the design of bandpass filters tuned to DTMF frequencies, a scoring function to detect tones, and a decoding function to recognize sequences of tones as dialed digits or letters. Functions and code snippets are provided as examples.

Uploaded by

gvvvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Digital Signal Processing: Assignment 4

1. Introduction
DTMF- dual tone multiple frequency
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 # D

3. Warm-Up
3.1 DTMF Dial function.
function xx=dtmfdial(keyNames,fs)
%DTMFDIAL Create a signal vector of tones which will dial
% a DTMF (Touch Tone) telephone system.
% usage: xx=dtmfdial(keyNames,fs)
% keyNames=vector of characters containing valid key names
% fs=sampling frequency
% xx=signal vector that is the concatenation of DTMF tones.
dtmf.keys = ['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D'];
dtmf.colTones = ones(4,1)*[1209,1336,1477,1633];
dtmf.rowTones = [697;770;852;941]*ones(1,4);
xx=[];
for zz=1:length(keyNames)
kk=keyNames(zz);
xx=[xx,zeros(1,400)];
[ii,jj]=find(kk==dtmf.keys);
row_f=dtmf.rowTones(ii,jj);
col_f=dtmf.colTones(ii,jj);
xx=[xx,cos(2*pi*row_f*(0:1600)/fs)+cos(2*pi*col_f*(0:1600)/fs)];
end
soundsc(xx,fs);
3.2 Simple Bandpass Filter Design. h[n] = βcos(ωn) 0< n < L
3.2.a β=0.0385
% 3.2.a
ww=0:(pi/1000):pi;
n=(0:50); % length is 51
h=cos(0.2*pi*n); % assume the beta value is 1
HH=freqz(h,1,ww); % get the frequency response
peak_v=max(abs(HH)); % find the peak value
h_1=1/peak_v*cos(0.2*pi*(0:50)); % freq response peak value is 1
HH_1=freqz(h_1,1,ww); % get the frequency response
plot(ww,abs(HH_1));
3.2.b The two bounds of passband frequencies are 0.5781 rad and 0.6817 rad. The Passband width
is 0.1037 rad.
% 3.2.b
pb=find(abs(HH_1)>=0.707); % magnitude should be higher than 1/sqrt(2)
BW1=ww(pb(1)); % first in x axis
BW2=ww(pb(length(pb))); % last in x axis
delta_BW=BW2-BW1; %find the bandpass width
3.2.c fs=8000 Hz,
f1=0.5781*8000=4624.8 rad/s to f2=0.6817*8000=5453.6 rad/s .

4. Lab exercises
4.1 Simple Bandpass Filter Design: dtmfdesign.m
4.1.b
% 4.1.b
function hh = dtmfdesign(fb,L,fs)
%DTMFDESIGN
% hh = dtmfdesign(fb, L, fs)
% returns a matrix (L by length(fb)) where each column contains
% the impulse response of a BPF, one for each frequency in fb
% fb = vector of center frequencies
% L = length of FIR bandpass filters
% fs = sampling freq
% Each BPF must be scaled so that its frequency response has a
% maximum magnitude equal to one.
ww = 0:pi/1000:pi;
hh = zeros(L,length(fb)); % create a L*length(fb) matrix
beta = zeros(1, length(fb)); % create a vector ,length is length of fb
for k = 1:length(fb)
h = cos(2*pi*fb(k)*(0:L-1)/fs);
HH = freqz(h,1,ww);
beta(k) = 1/max(abs(HH)); % get the beta value
hh_1 = h*beta(k); % freq response peak value is 1
hh(:,k) = hh_1;
end

4.1.c L_min=84
% 4.1.c
ww=0:pi/1000:pi;
for L = 40:100
t = dtmfdesign([697,770],L,8000);
h_1 = t(:,1);
HH_1 = freqz(h_1,1,ww);
stb_index = find(abs(HH_1)>=0.25);
stb_right = ww(stb_index(1)+length(stb_index)-1);
if (2*pi*770/8000>=stb_right)
L_min = L;
break
end
end
4.1.d L=40 and fs=8000
% 4.1.d
ww=0:(pi/1000):pi;
L=40;
fs=8000;
for kk = 1:8
t = dtmfdesign([697,770,852,941,1209,1336,1477,1633],L,fs);
h_d = t(:,kk);
HH_d = freqz(h_d,1,ww_d);
plot(ww,abs(HH_d));
end

4.1.e L=80 and fs=8000


% 4.1.e
ww=0:(pi/1000):pi;
L=80;
fs=8000;
for kk = 1:8
t = dtmfdesign([697,770,852,941,1209,1336,1477,1633],L,fs);
h_e = t(:,kk);
HH_e = freqz(h_e,1,ww_d);
plot(ww,abs(HH_e));
end
4.2 A Scoring Function: dtmfscore.m
4.2.b
% 4.2.b
function sc = dtmfscore(xx, hh)
%DTMFSCORE
% 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.59
% sc = 0 if max(|y[n]|) is less than 0.59
xx = xx*(2/max(abs(xx))); %--Scale the input x[n] to the range [-2,+2]
yy = conv(xx,hh);
if (max(abs(yy)))>=0.59
sc=1;
else
sc=0;
end
ww=200:500;
plot(ww,yy(200:500));

4.2.d The maximum value of the magnitude for the frequency response must be equal to one
because when the sinusoids in the DTMF pass the band-pass filter, it will experience a known gain.
In order to be convenient to get the scoring threshold (59% level), we set the max value to be one.
Thus, the scoring threshold will be 0.59.
4.2.e
% 4.2.e matched
hh_c = dtmfdesign(941,84,8000);
xx=dtmfdial('0',8000);
p=dtmfscore(xx,hh_c);
% 4.2.e mismatched
hh_c = dtmfdesign(941,84,8000);
xx=dtmfdial('A',8000);
p=dtmfscore(xx,hh_c);

4.3 DTMF Decode Function: dtmfrun.m


% 4.3
function keys = dtmfrun(xx,L,fs)
%DTMFRUN keys = dtmfrun(xx,L,fs)
% returns the list of key names found in xx.
% keys = array of characters, i.e., the decoded key names
% xx = DTMF waveform
% L = filter length
% fs = sampling freq
%
center_freqs = [697,770,852,941,1209,1336,1477,1633];
dtmf.keys = ['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D'];
hh = dtmfdesign( center_freqs,L,fs );
% hh = L by 8 MATRIX of all the filters. Each column contains the
% impulse response of one BPF (bandpass filter)
%
[nstart,nstop] = dtmfcut(xx,fs); %<--Find the beginning and end of tone bursts
keys = [];
p = zeros(1,8); % store the score values
for kk=1:length(nstart)
x_seg = xx(nstart(kk):nstop(kk)); %<--Extract one DTMF tone
for ii = 1:8
p(ii) = dtmfscore(x_seg,hh(:,ii)); %determine the score value
end
num_freq = find(p==1);
if length(num_freq)>2 % check whether there is any error in
score
keys = [keys,'-1'];
else
row_index = find(p(1:4)==1); % get the row index
col_index = find(p(5:8)==1); % get the column index
keys = [keys,dtmf.keys(row_index,col_index)];
end
end
end

4.4 Telephone Numbers


fs=8000;
L=100;
tk='407*891323#BADC';
xx=dtmfdial(tk,fs);
dtmfrun(xx,L,fs);
clear,clc;
% % 3.2.a
% ww=0:(pi/1000):pi;
% n=(0:50); % length is 51
% h=cos(0.2*pi*n); % assume the beta value is 1
% HH=freqz(h,1,ww); % get the frequency response
% peak_v=max(abs(HH)); % find the peak value
% h_1=1/peak_v*cos(0.2*pi*(0:50)); % freq response peak value is 1
% HH_1=freqz(h_1,1,ww); % get the frequency response
% plot(ww,abs(HH_1));
%
% % 3.2.b
% pb=find(abs(HH_1)>=0.707); % magnitude should be higher than 1/sqrt(2)
% BW1=ww(pb(1)); % first in x axis
% BW2=ww(pb(length(pb))); % last in x axis
% delta_BW=BW2-BW1; % find the bandpass width

% % 4.1.c
% ww=0:pi/1000:pi;
% for L = 40:100
% t = dtmfdesign([697,770],L,8000);
% h_1 = t(:,1);
% HH_1 = freqz(h_1,1,ww);
% stb_index = find(abs(HH_1)>=0.25);
% stb_right = ww(stb_index(1)+length(stb_index)-1);
% if (2*pi*770/8000>=stb_right)
% L_min = L;
% break
% end
% end

% % 4.1.d
% ww=0:(pi/1000):pi;
% L=40;
% fs=8000;
% for kk = 1:8
% t = dtmfdesign([697,770,852,941,1209,1336,1477,1633],L,fs);
% h_d = t(:,kk);
% HH_d = freqz(h_d,1,ww_d);
% plot(ww,abs(HH_d));
% hold on
% end

% % 4.1.e
% ww=0:(pi/1000):pi;
% L=80;
% fs=8000;
% for kk = 1:8
% t = dtmfdesign([697,770,852,941,1209,1336,1477,1633],L,fs);
% h_e = t(:,kk);
% HH_e = freqz(h_e,1,ww_d);
% plot(ww,abs(HH_e));
% hold on
% end

% % 4.2.e
% hh_c = dtmfdesign(941,84,8000);
% xx=dtmfdial('0',8000);
% p=dtmfscore(xx,hh_c);

% 4.4
fs=8000;
L=100;
tk='407*891323#BADC';

You might also like