Extracting the fundamental frequency of a .wav file

5 views (last 30 days)
I have a .wav file, which I read with wavread and later do the fft.
If Y=fft(y,N), being y the vector with the samples of the .wav file and Y the fourier transformation of y.
How can I make a relation between the frequencies and the samples of Y? I want to get the frequency in wich Y has the highest value.
Thanks.

Accepted Answer

Wayne King
Wayne King on 19 Oct 2012
Here is an example you can modify with your input y
For even length y:
Fs = 1000;
t = 0:0.001:1-0.001;
y = cos(2*pi*100*t)+randn(size(t));
ydft = fft(y);
freq = 0:Fs/length(y):Fs/2;
ydft = ydft(1:length(y)/2+1);
plot(freq,abs(ydft))
[maxval,idx] = max(abs(ydft));
freq(idx) %this is frequency corresponding to max value
For odd length y
t = 0:0.001:1;
y = cos(2*pi*100*t)+randn(size(t));
ydft = fft(y);
freq = 0:Fs/length(y):Fs/2;
ydft = ydft(1:floor(length(y)/2)+1);
[maxval,idx] = max(abs(ydft));
freq(idx) %this is frequency corresponding to max value
  3 Comments
Marco Macedo
Marco Macedo on 28 May 2020
Hello, i´m really late xD but how can i extract the frequenct of the first peak? that is the fundamental frequency
Mohit Motwani
Mohit Motwani on 2 Nov 2020
Edited: Mohit Motwani on 2 Nov 2020
what if I compute an n-point fft like
ydft = fft(y, 2048);
Should I still use this line?
ydft = ydft(1:2048/2);

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!