Contact US

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!

*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

Using fft (Fast Fourier Transform)

Using fft (Fast Fourier Transform)

Using fft (Fast Fourier Transform)


In the example on how to use fft, once they have the signal, they do this:

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;

Meaning that they get the next power of 2 from length of y (the signal), and then they calculate the NFFT-points fft, to then divide it by L (length of y).
¿Can you tell me why they do that?

What I'm trying to do is capture a sound signal and then with the fft get the frequency of that signal.

Thank you!

RE: Using fft (Fast Fourier Transform)

It is called zero padding. It is fast and has the advantage that usually small differences in the length of the signal don't affect the resolution.

Personally I don't like it and don't do it.


Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies  http://eng-tips.com/market.cfm?

RE: Using fft (Fast Fourier Transform)

The power of 2 FFT is more efficient.  That would be the big driver.  Some FFT algorithms like the one in excel won't except any input lenght that is not a power of 2.

The zero padding as Greg says doesn't hurt, in fact gives finer "frequency resolution"... sort of.  

Eng-tips forums: The best place on the web for engineering discussions.

RE: Using fft (Fast Fourier Transform)

Thank you very much for both of your answers!

The thing is that I capture the sound of a guitar, let's say an 'A', and after doing the fft and plot the result, I can see a peak where the main frequency should be, but it shows a number that is not supposed to be the one for 'A' (let's say I get a peak on 29, and the frequency's supposed to be 110), so I was looking for the answer on that business with the n-point fft...

¿You reckon what am I doing wrong?

Thanks again!

RE: Using fft (Fast Fourier Transform)

To be more specific:

in the example, after calculatin the fft with Y=fft(y,NFFT)/L , to show the graph (and get the frequency from there), they do:

f = Fs/2*linspace(0,1,NFFT/2+1);

so maybe I should do something like that (not exactly that though, I guess, cos it gives me that wrong frequency I told you about), but I'm not really sure why they do the 2*abs(Y(1:NFFT/2+1). The only thing I kinda get is that they represent half of the signal only cos you have all the info you need there.


RE: Using fft (Fast Fourier Transform)

The first bin is DC.  The second bin is 1/T, where T is the length of your (possibly padded) signal.  Other bins are multiples of this.  Learning a formula for the frequency axis is (in my view) a waste of time.  Derive it from first principles each time instead.

- Steve

RE: Using fft (Fast Fourier Transform)

do a search. I recall vividly posting an example FFT script.  


RE: Using fft (Fast Fourier Transform)

Thanks a lot everyone.

I'll do a search around the forum to look for those fft examples, and if I'm still confused about it, I'll post the code I wrote so you can check it. :)

RE: Using fft (Fast Fourier Transform)

Ok, everything looks correct now :) Thanksalot everyone, you've been tremendly helpful.


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! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close