Need help for DTMF Scoring fucntion

2 views (last 30 days)
I have written a code for DTMF tone generation. Now for decodiing purpose, i have written code for dtmfscore
function ss = dtmfscor(xx, freq, L, fs)
if (nargin < 4), fs = 8000; end;
hh = (2/L)*cos(2*pi*freq*(0:L-1)/fs);
ss = (mean(conv(xx,hh).^2) > mean(xx.^2)/5);
the book says that input signal xx to dtmfscor function is actually a short segment from DTMF signal.The task of breaking up the signal so that each segment correspond to one key will be done by another function prior to calling dtmfscore.I m confused about xx. how to address this issue
Plz help me and give me rough skecth of algorithm I am stuck for last 2 days

Accepted Answer

Wayne King
Wayne King on 19 Oct 2011
I wouldn't write it like this because the dtmfscor function needs to know which column of tones it needs. But if you call the following:
>>[tones,ss] = dtmfking;
function [tones,ss] = dtmfking
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
% construct table of frequencies
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
Fs = 8000; % Sampling frequency 8 kHz
N = 800; % Tones of 100 ms
t = (0:N-1)/Fs; % 800 samples at Fs
pit = 2*pi*t;
tones = zeros(N,size(f,12));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
end
ss = dtmfscor(tones,697,20,8000);
%Here i am giving the first freq and first column to cross check
function ss = dtmfscor(tones, freq, L, fs)
if (nargin < 4), fs = 8000; end;
hh = (2/L)*cos(2*pi*freq*(0:L-1)/fs);
ss = (mean(conv(tones(:,1),hh).^2) > mean(tones(:,1).^2)/5);
end
end

More Answers (10)

Wayne King
Wayne King on 19 Oct 2011
I'm assuming xx is the output of your other function as you have stated.
It of course doesn't have to be called xx, xx is just a place holder in your function definition. Then you just feed that output to dtmfscor().
What exactly do you mean you're confused about xx?

moonman
moonman on 19 Oct 2011
Thanks a lot Wayne King. i am stuck with this part for last two days
This is exact statement of book. I have written code for DTMF generation which is working fine.
The next objective is decoding - a process that requires a binary decision on the presence or absence of the individual frequencies. In order to make the signal detection an automated process, we need a score function that rates the different possibilities. (a) Complete the dtmfscor function based on the skeleton given in Table 2. Assume that the input signal xx to the dtmfscor function is actually a short segment from the DTMF signal. The task of breaking up the signal so that each segment corresponds to one key will be done by another function prior to calling dtmfscor.
Now i have written code for dtmfscor, What does he mean by small segment.How to go about this all
thanks i lot
  2 Comments
Wayne King
Wayne King on 19 Oct 2011
It sounds like he is saying to segment your signal, parse your signal so that each segment corresponds to key only. Then you pass that part to your dtmfscor() function which detects which key was passed. You want to make sure the signal you pass contains only one key so that you can make the correct decision.
Have you looked at:
>>dtmfdemo
and the doc example for goertzel
Wayne King
Wayne King on 19 Oct 2011
"corresponds to ONE key only."

Sign in to comment.


moonman
moonman on 19 Oct 2011
Thanks a lot Wayne King for giving hint of Goertzel
Kindly explain me overall picture of scanrion
1. I have written a function A which generates DTMF tones. The output of this function is dtmf. function [dtmf]=dtmfdial(x);
2. Now I want to write a function which will make segments of each key. this is my effort.Now kindly help me how can i use this in dtmfscor
Here is my effort
function [dtmfseg]=dtmfseg(x);
%This function produces DTMF Tone corresponding to given
%key number
low_fg = [697 770 852 941]; % Low frequency group
high_fg = [1209 1336 1477]; % High frequency group
f = [];
seg=[];
for a=1:4,
for b=1:3,
f = [ f [low_fg(a);high_fg(b)] ];
end
end
disp('Table of Frequencies is shown')
table=f'
dur=.5; %Duration for each tone is .5 sec
fs=8000; % Sampling Freq is 8000 Hz for tones
tt=0:(1/fs):dur;
n=length(x);
D=cell(1,n);
xx=cell(1,n);
for k=1:n % This loop will continue for number of keys
if x(k)==1
freqa=table(1,1); %Freq is picked from table(row1,col1)
freqb=table(1,2); %Freq is picked from table(row1,col2)
else if x(k)==2
freqa=table(2,1);
freqb=table(2,2);
else if x(k)==3
freqa=table(3,1);
freqb=table(3,2);
else if x(k)==4
freqa=table(4,1);
freqb=table(4,2);
else if x(k)==5
freqa=table(5,1);
freqb=table(5,2);
else if x(k)==6
freqa=table(6,1);
freqb=table(6,2);
else if x(k)==7
freqa=table(7,1);
freqb=table(7,2);
else if x(k)==8
freqa=table(8,1);
freqb=table(8,2);
else if x(k)==9
freqa=table(9,1);
freqb=table(9,2);
else if x(k)=='*'
freqa=table(10,1);
freqb=table(10,2);
else if x(k)==0
freqa=table(11,1);
freqb=table(11,2);
else x(k)='#';
freqa=table(12,1);
freqb=table(12,2);
end
end
end
end
end
end
end
end
end
end
end
% Both the tones are generated
tone1=sin(2*pi*freqa*tt); % Tone of First Frequency
tone2=sin(2*pi*freqb*tt); % Tone of Second Frequency
tone=tone1+tone2; % Now both tones are added
%***** We are making this loop to pick the segment of tone of each %key*****
for w=1:500
seg(w)=tone(w); % making segment
sil_dur=.1; % Defining silence duration between tones
sil_freq=0; % Since we want to keep silence, so frequency is zero
sil_tt=0:(1/fs):sil_dur;
sil_tone=sin(2*pi*sil_freq*sil_tt); % Generating silence tone
D{k} = [tone,sil_tone]; % Concatinatiing tones and then silence
xx{k}=[seg];
end %end of for loop
dtmfseg = cat(2, xx{:})

moonman
moonman on 19 Oct 2011
Plz guide me for this

Wayne King
Wayne King on 19 Oct 2011
Can't you do something like this
function tones = dtmfseg
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
% construct table of frequencies
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
Fs = 8000; % Sampling frequency 8 kHz
N = 800; % Tones of 100 ms
t = (0:N-1)/Fs; % 800 samples at Fs
pit = 2*pi*t;
tones = zeros(N,size(f,12));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
end
end
>>tones = dtmfseg;
gives you the output array tones, which is a matrix where each column is a tone (including * and #).
Then each column of the matrix is one of your xx to use with your detection algorithm.
Obviously you can adjust the length as you wish.

moonman
moonman on 19 Oct 2011
Ok thanks King, i was thinking to make short segment of every input. For example if there are 2 keys, then i will make segment of 2 keys but u have given a good idea to make segment of all keys and then use them as required. I will work on it now
Thanks again

moonman
moonman on 19 Oct 2011
Sir King, sorry i am bothering u again, actually i am weak in functions so i m getting stuck. But i hope if this problem is solved then i can move ahead
AS per ur code, the segments have been made. Now as per book i am using dtmfscor function and i want to test it for first freq and column is first So ideally the answer should be returned as 1(True) as freq is present in tone[1] but i am getting error in the code
function tones = dtmfking
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
% construct table of frequencies
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
Fs = 8000; % Sampling frequency 8 kHz
N = 800; % Tones of 100 ms
t = (0:N-1)/Fs; % 800 samples at Fs
pit = 2*pi*t;
tones = zeros(N,size(f,12));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
end
end
%Here i am giving the first freq and first column to cross check
%function
ss = dtmfscor(tones, freq, L, fs)
freq=697;
if (nargin < 4), fs = 8000; end;
hh = (2/L)*cos(2*pi*freq*(0:L-1)/fs);
ss = (mean(conv(tones[1],hh).^2) > mean(xx.^2)/5);
These both functions are in one file. I am getting error
>> tones=dtmfking ??? Error: File: dtmfking.m Line: 29 Column: 22 Unbalanced or unexpected parenthesis or bracket.

Wayne King
Wayne King on 19 Oct 2011
Hi Moonman, here is a modification that outputs only one tone:
function tone = dtmfseg(symb)
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
[truefalse,toneChoice] = ismember(symb,symbol);
if truefalse
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
% construct table of frequencies
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
Fs = 8000; % Sampling frequency 8 kHz
N = 800; % Tones of 100 ms
t = (0:N-1)/Fs; % 800 samples at Fs
pit = 2*pi*t;
tone = sum(sin(f(:,toneChoice)*pit))';
else
error('Your input is invalid');
end
end
You would call it like this (for example):
>>tone = dtmfseg('2');

moonman
moonman on 19 Oct 2011
Sir king thanks for ur effort but book requirement is this one
the book says that input signal xx to dtmfscor function is actually a short segment from DTMF signal.The task of breaking up the signal so that each segment correspond to one key will be done by another function prior to calling dtmfscore.I m confused about xx. how to address this issue
I think what u did earilier was in connection withmy requirement
my dtmfscor function is ready Now i want to give input to it a short segment and then verify it with the frequency
I hope i have understood the book problem properly If u can spare some seconds, u can have look at this site I have posted the book page here
I have already generted the DTMF tone by a function which works by this command soundsc(dtmfdial([1 7 '*' '#' 1 3 4 0 7 9 0 3 5]),8000);
Thanks a lot for helping me out in this issue. I am really grateful to u for ur patience and helping attitude

moonman
moonman on 21 Oct 2011
Thanks King I am following ur guidance and things are working smooth uptill now

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!