# Demo entry 6642440

m

Submitted by anonymous on Sep 24, 2017 at 09:59
Language: Matlab. Code size: 1.4 kB.

```function digits = tt_decode(x)
% DTMFDET   DTMF Tone Detection Using Goertzel Algorithm.
%
%  Y = tt_decode(X) returns the DTMF coded sequence
%  in present vector X. The sound sample frequency
%  is given by 8000.
%
LIM = .3; % Limit for detecting tone (if the intensity of the freq from goertzel is less the LIM* the max intensity, the tone wont be detected)
NUM= ['1' '2' '3' 'A' '4' '5' '6' 'B' '7' '8' '9' 'C' '*' '0' '#' 'D'];
f_low = [697 770 852 941]; f_high = [1209 1336 1477 1633];
N = 205;%the DFT length
YL = zeros(4,floor(length(x)/N));
YH = YL;

for i = 1 : 4                  %use the gfft function to evaluate the energy of
for j=1:floor(length(x)/N) %low frequency and high frequency each sampling section
YL(i,j) = abs(gfft(x(N*(j-1)+1:N*j),N,f_low(i)*N/8000));
YH(i,j) = abs(gfft(x(N*(j-1)+1:N*j),N,f_high(i)*N/8000));
end
end

YL(YL<LIM*max(YL(:))) = 0;  %l1，h1 store the maximum value of each sampling section
[l1,l2] = max(YL);          %l2，h2 store the position of the maximum value of each sampling section
YH(YH<LIM*max(YH(:))) = 0;
[h1,h2] = max(YH);

r = NUM((l2-1)*4+h2);       %use‘-’to identify the undetected section
r(l1==0) = '-';
r(h1==0) = '-';
k=1;
for i = 2:length(r)         %get DTMF signal
if r(i)~='-'&r(i)~=r(i-1)
num(k)=r(i);
k=k+1;
end
end
display('the number is:')
num
```

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.