Isolating k fourier peaks

7 views (last 30 days)
Shawn Cooper
Shawn Cooper on 22 Oct 2019
Commented: Star Strider on 22 Oct 2019
I have imported an audio file of a musical triad (three notes) and then taken its fourier transform to find the fundamental frequencies of the chord. From this transform, I would like to automatically select the three highest peaks in magnitude and determine where they fall on the x (frequency) axis.
My initial thought was to utilize maxk, but this obviously chooses the three highest points overall, even if they are on the same "peak".
Ultimately, I would like the return to be a vector (or array) with the three most prominent frequencies (and their magnitude, if it's an array).
clear all
%import file
[x,Fs] = audioread('eqt-CMajor.wav');
sound(x,Fs);
T = 1/Fs;
L = length(x);
t = (0:L-1)*T;
%change two channel input to one channel output
xMono = sum(x, 2) / size(x, 2);
%fourier transform and plot
Y = fft(xMono);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure(2)
plot(f,P1)
%attempt to identify frequency of the three highest magnitude peaks
[M, Hz] = maxk(f,3,'ComparisonMethod','abs')

Accepted Answer

Star Strider
Star Strider on 22 Oct 2019
Use the Signal Processing Toolbox findpeaks function, with the name-value pair arguments SortStr and NPeaks.
  4 Comments
Shawn Cooper
Shawn Cooper on 22 Oct 2019
Works as advertised, thank you for the help!
Star Strider
Star Strider on 22 Oct 2019
As always, my pleasure!
(I apologise for the delay in responding last night — I was off doing other things for a while.)

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!