Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

fft on samples of an audio file in matlab

Asked by ir on 24 Apr 2013

I'm trying to extract information from a sound file in order to use it in a video classification algorithm I'm working on.

My problem is that I don't know how to work exactly with audio files in matlab.

Below is what I need to accomplish:

-open the audio file and get the sampling rate/frequency.

- I need to work on a window of 2 seconds so I have to loop over the file and get each 2 sec as a window and then do the ftt on each window.

After that it is my turn to use these values to do what I want

any help would be appreciated

Thanks.

0 Comments

ir

Products

No products are associated with this question.

2 Answers

Answer by Carlos on 24 Apr 2013
Accepted answer

If you have a .wav audio named filename you can do

[y, Fs] = wavread(filename)

Where Fs is the sampling frecuency and y your audio samples.

Knowing the sample frecuency you can find the number of samples in 2 seconds (2*Fs).

Before performing the FFT algorithm of 2*Fs points you should apply some kind of windowing.You can find more about windows using doc window.

In order to find more about how to calculate the FFT type doc FFT in your Matlab command window.

2 Comments

ir on 24 Apr 2013

Actually, I'm working with mp3 file so I can't use wavread, I tried data = dsp. AudioFileReader("..."); but the length(data) is one, I'm not sure why it is like this. Also I used data = audioread(".."); but data does not seem a vector because I checked its size and it is [4186368 2], that means this audio file contains 2 channels do you have any idea about which channel should I use?

Carlos on 24 Apr 2013

It seems you are working with a stereo signal channel. You can sum the stereo signals and divide by two to obtain a mono signal.

Look at these other answers that deal with stereo to mono conversion.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/44379

http://www.mathworks.com/matlabcentral/newsreader/view_thread/126472

Carlos
Answer by ir on 24 Apr 2013

I see, thanks for your help

0 Comments

ir

Contact us