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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 17 Sep. 2014

0 Stimmen

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 Kommentare

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.
rafi
rafi am 17 Sep. 2014
the phone number contain 10 symbol so FT should contain 20 frequency (10 high and 10 low)
but my FT contain 32 frequency
Star Strider
Star Strider am 17 Sep. 2014
Bearbeitet: Star Strider am 17 Sep. 2014
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
rafi
rafi am 17 Sep. 2014
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.
rafi
rafi am 17 Sep. 2014
thank very very much! this real answer
only one thing, if you can explain me why you did you coose these parameters in spectrogram
Star Strider
Star Strider am 17 Sep. 2014
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.
rafi
rafi am 6 Okt. 2014
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?
Star Strider
Star Strider am 6 Okt. 2014
To the best of my knowledge, there are no filters at all involved in spectrogram. It uses a fft with windowing.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

rafi
rafi am 17 Sep. 2014

0 Stimmen

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

Community Treasure Hunt

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

Start Hunting!

Translated by