How can i detect frequency of dtmf tone (.wav )file

i have a DTMF tone as a ( .wav ) file , this tone consist of a lot of numbers , and i want to detect its frequency then i want to know the numbers which the tone belong to note i have a .wav file and i want to detect it how can i do this ?

 Accepted Answer

This code works with the attached (‘real world’) file provided by someone else who was interested in isolating the frequencies. This goes one step further and decodes the signal into its key-pad number positions:
pc = load('phonecall.mat');
x = pc.x;
fs = pc.fs;
% [S,F,T] = spectrogram(x, 1024, 512, 256*3, fs, 'yaxis');
[S,F,T] = spectrogram(x, 1024, 512*3/4, 256*3, fs, 'yaxis');
Sa = abs(S);
[r, c] = find(Sa >= 30);
Fr = F(r);
Tc = T(c)';
FT = [Tc Fr];
[C, ia, ic] = unique(FT(:,1)); % Find Unique Times
for k1 = 1:size(C,1) % Create Cell Array By Time
FrqTime{k1} = FT(FT(:,1) == C(k1),:); % Time & Frequency Cell
end
original_f = [697 770 852 941 1209 1336 1477]; % DTMF Frequencies
dtmf_dcd = [1 5; 1 6; 1 7; 2 5; 2 6; 2 7; 3 5; 3 6; 3 7; 4 5; 4 6; 4 7]; % Combination Codes w.r.t. ‘original_f’
nbr_map = ['1' '2' '3' '4' '5' '6' '7' '8' '9' '*' '0' '#']; % Number Key Map
for k1 = 1:size(C,1)
freq_dist = abs(bsxfun(@minus, FrqTime{k1}(:,2), original_f)); % Distance Of ‘FrqTime’ Frequencies From ‘original_f’ Frequencies
[~,freq_pos(:,k1)] = min(freq_dist,[],2); % Frequency Positions Of ‘FrqTime’ In ‘original_f’
num_pad(k1) = nbr_map(ismember(dtmf_dcd, freq_pos(:,k1)', 'rows')); % Map To Number Key Pad
end
I posted the sound file as a .mat file because it’s no longer possible to attach a .wav file. (It’s no longer an accepted file format.)
The first part of the code uses the spectrogram function to define the times and frequencies, then thresholds them, finds unique times, and creates a cell array of the time and frequency combinations. The second part finds the minimum distances between the ‘correct’ DTMF frequencies and the frequencies in ‘FrqTime’, then uses the ismember function to find the rows in ‘dtmf_dcd’ (‘dtmf decode’) that match ‘freq_pos’ (‘frequency position’) and uses those to map to ‘nbr_map’ elements that correspond to the row combinations in ‘dtmf_dcd’. The decoded DTMF signal is in the ‘num_pad’ string vector.
I cannot promise that it will work with your signal. You may have to experiment with the spectrogram call and the threshold (the ‘find(Sa >= 30)’ call).
There are probably File Exchange contributions that do this, and perhaps more efficiently, but I had fun writing this, so I’m posting it!

4 Comments

Thanks a lot
but i am bigenner in MATLAB , and i think this code is so complex for me .. can you help me by simple code to understand it eaisly ?
My pleasure.
That is about as simple and efficient as I can make that code. The ‘Sa’ assignment are the absolute values (magnitudes) of the complex values of the results spectogram produces. It thresholds them to ignore the noise, eliminating all those <30. The ‘Fr’ and ‘Tc’ assignments are the corresponding frequencies (rows) and times (columns) of those frequencies, respectively. The ‘FT’ matrix is the matrix of those values. The ‘FrqTime’ cell array are the unique elements of those vectors (eliminating duplicates). (I do not use the ‘ia’ and ‘ic’ outputs of unique. I did not simplify the unique call to eliminate them before I posted my code.) The ‘original_f’ vector are the actual frequencies (Hz) used in DTMF. The ‘dtmf_dcd’ matrix rows are the combinations that correspond to the elements of ‘nbr_map’. The loop goes through each second column of ‘FrqTime’ and compares it to the values in each row of ‘dtmf_dcd’, and uses that value (index) to assign the appropriate value of ‘nbr_map’ to each element of the ‘num_pad’ variable. The ‘num_pad’ vector are the decoded tones.
I encourage you to search through the MATLAB documentation and read about each of the functions I use in my code. The documentation explains the functions much better and much more completely than I ever would be able to. You will then be able to understand in some detail how my code works. Experiment with the various functions.
Explore the examples given in the documentation, then on your own. This is reasonably complicated code, so take your time to go through it.
i get errors when i run it :(
What errors?
It worked for me without error when I ran it with the file I included here. (I would not have posted it if did not run without errors.) I wrote it with R2015b, but it should work with all recent MATLAB releases.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!