Extract Corresponding Frequency value from the peak amplitude

3 views (last 30 days)
I have started this code to decode and detect the DTMF character from the wavfile. I am very new to MATLAB and need a urgent help to extract the corresponding frequencies (x-axis) from the peak value (locs) so that i can complete my assignment.
close all;
clear all;
clc;
% Load file, obtain information and play sound
Dialtone = 'DTMFDigit1.wav'; % Input Tone
audioread(Dialtone); %To read the wave file
info = audioinfo(Dialtone);
display(info); % Verify the sudio information
[Dialtone, fs] = audioread(Dialtone); % To obtain the sample rate
sound(Dialtone, fs) % Play Sound
% Plot of the DTMF tone in time domain
N = length(Dialtone); % Obtain total number of samples
idx = 0:N-1;
t = idx*(1/fs);
figure(1);
plot(t, Dialtone) % Plot the signal in time domain
title('Dial Tone Time Waveform'); % plot title3
xlabel('Time'), ylabel('Amplitude'); % plot axis labels
% Plot of the DTMF tone in Frequency domain
n = 2^nextpow2(N); % identify an input length that is the next power of 2
Y = fft(Dialtone,n);
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(n/2))/n;
figure(2);
plot(f,P1)
title("Single-Sided Amplitude Spectrum of Dialtone")
title("Single-Sided Amplitude Spectrum of Dialtone")
xlabel("frequency (Hz)")
ylabel("|P1(f)|")
[pks,locs] = findpeaks(abs(P1),'SortStr','descend','NPeaks',2);

Answers (1)

KSSV
KSSV on 26 Sep 2022
f(locs)
  1 Comment
Rajesh Kanesan
Rajesh Kanesan on 26 Sep 2022
Thanks for your response , I have started this code to decode and detect the DTMF character from the wavfile using the FFT approach. I am very new to MATLAB and need a urgent help to extract the corresponding frequencies (x-axis) from the peak value (locs) so that i can complete this assignment.I wish to get the result in the order of X-axis , frequency rather than the sorted Y-axis peak amplitude value. Could you please help as my assignement due in 24hours?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!