Hello sir,
I am working on a project where one of the task is to find the FFT of an audio file that I have. The audio file basically contain sound from a 'trumpet'. It is of 5s duration.Firstly I use 'audioread' function to read the file which gave me a vector i.e a discrete time samples of audio. Then when I took fft to see the frequency of sound clip, it showed me max peak at 0 Hz. How is it possible? I am not getting it. The code works fine for other sounds.
I will share the code that I am using please tell me where I am going wrong.
[c,fs]=audioread('T4.wav');
c=c';
dft=fft(c);
dft=dft(1:length(c)/2+1);
fval=fs*(0:length(c)/2)/length(c);
[Max,I]=max(abs(dft));
plot(fval,abs(dft))
fprintf('Maximum occurs at %3.2f Hz.\n',fval(I))

 Réponse acceptée

Star Strider
Star Strider le 3 Mar 2017

0 votes

The ‘0 Hz’ peak is the constant (or d-c, direct current) offset. To eliminate it and see the other frequencies in your signal, subtract the mean from your signal before taking the fft.
Example:
[c,fs]=audioread('T4.wav');
c = c-mean(c);
c=c';
dft=fft(c)
.. REST OF YOUR CODE ...

6 commentaires

Nachiket Patki
Nachiket Patki le 5 Mar 2017
Thank you sir. I got it.
Star Strider
Star Strider le 5 Mar 2017
My pleasure.
Nachiket Patki
Nachiket Patki le 5 Mar 2017
Modifié(e) : Nachiket Patki le 5 Mar 2017
Ok so now I got the desired frequencies, now there is one thing that I am looking for is to classify.I have total of 10 frequencies. I want to classify them as say Type A and Type B. Can we classify them using power spectral density or may be using STFT? or any other technique should be used in this scenario?
Star Strider
Star Strider le 5 Mar 2017
You have to do the classification using a classifier function, for example the fitcdiscr (link) (or classify) function to do a linear discriminant classification. There are several other classifiers. The classifier you choose depends on the problem you want to solve.
The Fourier transform and similar functions do not do classification.
Nachiket Patki
Nachiket Patki le 6 Mar 2017
Ok let me try this out. I will ask doubt if I get stuck. Thank you sir.
Star Strider
Star Strider le 6 Mar 2017
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (1)

Community Treasure Hunt

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

Start Hunting!

Translated by