www.pudn.com > dtmf_dec.rar > dtmf_dec.m


function xx=dtmf_dec_duzhou(x); 
 
tone = ['1' '2' '3' 'A' '4' '5' '6' 'B' '7' '8' '9' 'C' '*' '0' '#' 'D'  'e'  ];   
Fs = 8000 ; Ts = 1/Fs ;    % Fs is the sampling rate 
T_duration = 30; magnitude=1;             % minmum of signal duration is 40ms, we choose 30ms  
T = T_duration/1000 ;      % the unit is ms 
block = floor(T * Fs);     % defining the size of the block 
length_all = ceil(length(x)/block);  % determine the numbers of the block 
zero_x = zeros( 1, (length_all*block)-length(x) ); % if the length of x less than the all block 
x = [x zero_x];                                    % then add zeros to it     
N=205;                           % we choose the number from the paper 
k=[18 20 22 24 31 34 38 42];     % we chose the value of k according to the value of N  
d_init=[]; LIMIT=1e6*magnitude;            % limit the threshold to distinguish the DTMF from the speech or noise 
for n=0:length_all-1, 
    Spectrum = zeros(1,8);        % it only needs 8 spectrum 
    period = (1:block) + block*n ;      %  
    for m = 1:8, 
        Spectrum(m) = Goertzel( x(period) , k(m) , N ) ; 
    end 
    Spectrum = reshape(Spectrum,4,2);    % devide the power of low and high frequency into two column  
    [max_mag max_index] = max(Spectrum); % find the hightest two power of low and high frenquency 
                                         % get their index respectively  
    tone_index = (max_index(1)-1)*4 + max_index(2); %  according to the index of the 
                                                    %  Spectrum we could get the index of 
    if ( max_mag(1) * max_mag(2) < LIMIT )          %  the tone 
        tone_index=17;   
    end 
    d_init=[d_init tone(tone_index)];  
end 
% the part of output % 
count = 1;                 % initialize count to '1' 
tone_sig_index=[];         % since the array started with '1', not '0' 
if (d_init(1)~='e')        % so we should check the signal is right or 
    d(1)=d_init(1);        % not then initialize it to '1' 
    count = 2; 
    tone_sig_index=[1]; 
end 
for i = 2 : length(d_init) 
    if ( d_init(i) ~= 'e' ) & ( d_init(i) ~= d_init(i-1) )  %  
        d(count) = d_init(i);  
        count = count+1; 
        tone_sig_index = [tone_sig_index i ]; 
    end 
end 
len_x=length(tone_sig_index); 
sig_show=[]; 
for n=1:len_x, 
    sig_show=[sig_show d_init(tone_sig_index(n))]; 
end 
xx=sig_show;