×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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)

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

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.

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

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.

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

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.

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

(OP)
Thanks a lot for the help =)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources