Analysis number from dtmf sound

hello, i have a wav file, which use dtmf i do spectrogram on the file and i receive 10 amplitude peak how can i return the 2 frequency of each peak (high and low frequency)

2 Comments

Stephen23
Stephen23 on 17 Sep 2014
Edited: Stephen23 on 17 Sep 2014
MATLAB provides this DTMF example , and you can also find some DTMF submissions on FEX.
i understand this, but i don't know how to extract the frequency peak amplitude

Sign in to comment.

 Accepted Answer

Star Strider
Star Strider on 17 Sep 2014
You did not post your data so I cannot be specific. You can get the frequency and time output as vectors from spectrogram:
  • [S,F,T] = spectrogram(...) returns a vector of frequencies, F , and a vector of times, T , at which the spectrogram is computed. F has length equal to the number of rows of S . T has length k (defined above) and the values in T correspond to the center of each segment.
There is probably no neat and efficient way to do what you want. I would loop through S at each time, sort and threshold the amplitudes to find the indices of the values >-35dB or so, then use the indices returned by sort to determine the frequencies. (Using the find function is also a possibility, but I am not certain it would make this more efficient.)

9 Comments

The S (spectrogram) output does have the amplitudes, but you have to take the absolute value of it to get them (the plot is the spectrogram):
[x,fs] = audioread('phonecall.wav');
[S,F,T] = spectrogram(x, 1024, 3/4*1024, [], fs, 'yaxis');
Sa = abs(S);
[r, c] = find(Sa >= 40);
Fr = F(r);
Tc = T(c)';
FT = [Tc Fr];
figure(1)
mesh(Sa)
view([0 90])
xlabel('Time (s)')
ylabel('Frequency (Hz)')
The ‘Sa’ variable are the absolute values of the spectrogram. The ‘find’ call returns the row and column indices of the elements that are >40dB. The ‘Fr’ and ‘Tc’ variables are the frequencies and times respectively of the occurrences of the tones that are >40dB. The ‘FT’ matrix combines them so you can see that there are two tones for each time. This is not exact, there are sometimes three frequencies listed for every time, but in all cases two of them are close to each other. You will have to determine the tolerances and then classify the two tones at each time.
Experiment with the threshold in the find call (40dB here) to get the accuracy you need.
You have the frequencies and the times they occurred in the ‘FT’ matrix. This should be everything you need to get started.
the phone number contain 10 symbol so FT should contain 20 frequency (10 high and 10 low)
but my FT contain 32 frequency
I changed your spectrogram call and changed the threshold, and added assignments creating a cell array that isolates the times and frequencies. You will have to characterise the frequencies and decode them.
I actually detected 12 unique times with this code, so there are actually 12 symbols and 24 frequencies.
Note that ‘FrqTime’ elements are all either (2x2) or (3x2), so while the discrimination with these changes is about as good as it is possible to expect, you will have to sort through them to distinguish the frequencies. As with the ‘FT’ matrix, the first column of each element is time and the second is frequency.
------------------------------------------------
The full, revised code:
[x,fs] = audioread('phonecall.wav');
[S,F,T] = spectrogram(x, 1024, 512, 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),:);
end
FrqTime{4:6} % Display ‘FreqTime’ Sample
the resolve is : 0546427316 so there are 10 symbol and 20 frequencies :(
Change the spectrogram call to:
[S,F,T] = spectrogram(x, 1024, 512*3/4, 256*3, fs, 'yaxis');
That should produce the result you want.
Do not change anything else in my code!
I don’t know how robust my code is (how well it would work in other situations), but it works essentially perfectly here.
thank very very much! this real answer
only one thing, if you can explain me why you did you coose these parameters in spectrogram
My pleasure!
I simply experimented until I get the result I needed, first with the length of the fft, then with noverlap. That is frequently necessary in real-world situations, and is the only way to solve some problems. Signal processing analysis and filtering frequently depends on the signals being processed, including sampling rate, noise, and desired output.
hi again, i need a liitle help: 1. the function spctrogram is IIR or FIR fillter? 2.i try to learn from the help about spectrogram, but who can explain me better than help?
To the best of my knowledge, there are no filters at all involved in spectrogram. It uses a fft with windowing.

Sign in to comment.

More Answers (1)

rafi
rafi on 17 Sep 2014
hello Star Strider,
i attach my audio+ code that i write
i don't understand from your answer how can i find threshold amplitudes because vector S contain fft, no amplitudes

Asked:

on 17 Sep 2014

Commented:

on 6 Oct 2014

Community Treasure Hunt

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

Start Hunting!