How can I detect the number pressed from a dtmf tone (.mat) file?

23 views (last 30 days)
I have a DTMF tone that is a .mat file, it just consists of one button press on a telephone and i want to be able to detect the number pressed and output it to the command line. How exactly can I do this?
I posted an example of the .mat file
  3 Comments
Elliot Wyllie
Elliot Wyllie on 1 May 2021
I have, none of them really worked for me and none used a .mat file
DGM
DGM on 1 May 2021
A mat file is just a container for any sort of variable that matlab can hold. The mat file just contains a vector and a scalar specifying the sampling frequency.
Using this FEX submission I just randomly picked:
load('dial_0.mat')
thiskey = decode(y',1,fs,numel(y)/fs)
gives
thiskey =
0
Of course, the documentation and parameterization for this function is pretty terrible, but that's some kind of tradition on the File Exchange.

Sign in to comment.

Accepted Answer

DGM
DGM on 1 May 2021
Basing off of this example:
% this loads two variables:
% fs -- sampling rate
% y -- signal vector
load('dial_0.mat');
Nt = 205;
source_tones = [697 770 852 941 1209 1336 1477]';
symbols = {'1','2','3';'4','5','6';'7','8','9';'*','0','#'};
k = round(source_tones/fs*Nt); % Indices of the DFT
estim_f = round(k*fs/Nt); % Frequencies at which the DFT is estimated
tone = y(1:205);
% Estimate DFT using Goertzel
ydft = goertzel(tone,k+1);
% find the two most powerful frequencies
[~,sourcetoneidx] = sort(abs(ydft),'descend');
sourcetoneidx = sourcetoneidx(1:2);
% sourcetoneidx should contain one index from
% each group of source tones (first four, last three)
row = min(sourcetoneidx);
col = max(sourcetoneidx)-4;
% look up the symbol in the table
thissymbol = symbols{row,col}
gives
thissymbol =
'0'
  4 Comments
Elliot Wyllie
Elliot Wyllie on 1 May 2021
Edited: Elliot Wyllie on 1 May 2021
Jeez that stuff goes right over my head, im a bit of a beginner when it comes to coding and signal processing. Im assuming I would have to rework all that code to fit the .mat file because decode file seems to work based off the encode file.
DGM
DGM on 1 May 2021
Edited: DGM on 3 May 2021
At this point, I wouldn't worry too much about using the FEX code directly. Like I said, it's a mess and requires the user input a bunch of extraneous parameters because it was probably designed only to do a particular thing (yes, probably it was just made to recycle the tones generated by the encoder).
That's why I cleaned it up and reduced it to a simplified script that takes the mat-file as given. No parameters needed, just a filename (assuming your mat-files all contain variables called fs and y).
EDIT:
I cleaned up my suggested code and made a encoder/decoder set of tools. Hopefully these will be a better resource to the next person that has the same task:
There's no special toolboxes needed, and it should be compatible back to at least R2009b.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!