Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to plot a sound recording's FFT with a meaningful frequency axis?

Status
Not open for further replies.

maxplanck735

Computer
Mar 28, 2006
2
Can someone either explain or refer me to a good tutorial regarding Matlab that illustrates how to create a plot of the FFT of an audio file that has a meaningfully indexed/numbered frequency axis? This is stumping me at the moment, probably because I don't understand the inner mathematical workings of the FFT, which results in my not knowing what frequency value should be associated with which element in the array that is the result of the FFT. I've studied the Matlab help file for a long time to try to figure this out on my own, and am still stumped.

Here is my situation outlined in Matlab code, for easy understanding. I am hoping that someone can tell me what to define the variable/array "f" as in order to produce a meaningful plot of "triangle.wav" 's frequency spectrum, i.e. a spectrum in which the proper frequency value is associated with and plotted with the proper element of the FFT's output. (Note: in the example below, I've removed the latter half of the FFT's output due to the fact that the FFT's output is always perfectly symmetrical about a point near the data point(s) with the middlemost index number(s)).


>> [x,fs] = wavread('C:\Matlab7\terrorist.wav');

>> fs

fs =

44100


>> X = abs(fft(x));

>> length(X)

ans =

32647

>> Y = X(1:length(X)/2+1);

>> length(Y)

ans =

16324

>>f = ????????????

>> plot(f,Y)
 
Replies continue below

Recommended for you

As you have guessed, X gives both positive and negative frequencies so you only need half. But you chose the left half so it will look flipped left/right.

I would choose the right half
Y = X(length(X-1)/2:length(X));

This will be 16324 frequency bins bounded on the lower and upper side by 0hz and 44100 hz.
df = 44100/16324
f=df/2:df:44100-df/2

You might want to double check this for yourself.



=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
It is very useful to synthesize a sine wave and analyse that using any new FFT function. This will reveal many things about the coding of that function, as there are several decisions that need to be made, which should be mentioned in the Help, but may not be.

Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
I made an error. Matlab starts with 0 frequency in bin 1 so you were correct to use
Y = X(1:length(X)/2+1);

I think this will still work with df and f as above.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor