Isolating k fourier peaks
7 views (last 30 days)
Show older comments
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')
0 Comments
Accepted Answer
Star Strider
on 22 Oct 2019
4 Comments
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.)
More Answers (0)
See Also
Categories
Find more on AI for Signals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!