×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# Using fft (Fast Fourier Transform)

 Forum Search FAQs Links MVPs

## Using fft (Fast Fourier Transform)

(OP)
Hi.

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.

Cheers

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)

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

(OP)
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);
plot(f,2*abs(Y(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)

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

Fe

### RE: Using fft (Fast Fourier Transform)

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

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

Cheers!

#### 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.

#### 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

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!