How to, efficiently, identify telephone number from the key pressed data audio file?

A very common homework question. You are given an audio file(.wav) which has the recording of the keys pressed during a telephone call. You have to identify the telephone number from this audio file when you are given the sampling frequency & the duration for which one key is pressed.

From the given sampling frequency & duration of key press, I could manage to write a MATLAB code to identify the telephone number by taking (samp_freq * key_press_time) number of samples at a time, doing fft on it & finding the bin that gives me a peak. I used WAVREAD command to read the audio file.

One problem I noticed is that, if the duration of key press is different(1st key pressed for 1 sec, 2nd key for 2 sec, 3rd key for 0.5 sec & so on), my technique of separating the data & finding peak will fail.

How to get around this problem of random duration key press? I could think of 2 inefficient ways to do this.

1. During 1st iteration, take entire data & plot fft. If (no. of peaks > 1), take half data at a time plot fft. Keep on doing this until there is only 1 peak in the plot. But this technique will take a lot of time
2. WAVREAD the file, each key press data is separated by 0's. Thus take data between the 0's one at a time, plot fft & find peak & frequency. But this looks too simple to be used.

So is there any other effiecient method of finding the telephone number when the key press duration is random?

• Why not to try some activity detection, even based on energy envelope? It will determine boundaries of beeps and then process chunks. Of course providing that data is not very noisy. Otherwise pre-filter data with notch bandpass filter covering DTMF frequencies and perform activity detection on that. As simple as that.
– jojeck
Nov 26, 2014 at 9:06
• Kharo, it's the same problem that any embedded system has with button switches. you need to create a simple "state machine" in which one state is "key pressed" or "key held" and the other state is "no key pressed" only when there is a transition from "no key pressed" to "key pressed" do you enter a digit in the telephone number. (some might do that when a key is released, the opposite transition, but i would not recommend that.) Nov 26, 2014 at 17:13
• Anyway please refer for example to this article: Detection of Multi-tone Signals Based on Energy Operators
– jojeck
Nov 28, 2014 at 12:08