Extracting the fundamental frequency of a .wav file

12 vues (au cours des 30 derniers jours)
Rosano Rosano Sánchez
Rosano Rosano Sánchez le 19 Oct 2012
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.

Réponse acceptée

Wayne King
Wayne King le 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 commentaires
Marco Macedo
Marco Macedo le 28 Mai 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 le 2 Nov 2020
Modifié(e) : Mohit Motwani le 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by