Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFT for n Points (non power of 2 )

I need to know a way to make FFT (DFT) work with just n points, where n is not a power of 2.

I want to analyze an modify the sound spectrum, in particular of Wave-Files, which have in common 44100 sampling points. But my FFT does not work, it only works with points which are in shape like 2^n.

So what can I do? Beside fill up the vector with zeros to the next power of 2 ?! Any way to modify the FFT algorithm?

Thanks!

like image 640
ShuftY Avatar asked Dec 26 '13 09:12

ShuftY


2 Answers

You can use the FFTW library or the code generators of the Spiral project. They implement FFT for numbers with small prime factors, break down large prime factors p by reducing it to a FFT of size (p-1) which is even, etc.

However, just for signal analysis it is questionable why you want to analyze exactly one second of sound and not smaller units. Also, you may want to use a windowing procedure to avoid the jumps at the ends of the segment.

like image 197
Lutz Lehmann Avatar answered Sep 22 '22 04:09

Lutz Lehmann


Aside from padding the array as you suggest, or using some other library function, you can construct a Fourier transform with arbitrary length and spacing in the frequency domain (also for non-integer sample spacings).

This is a well know result and is based on the Chirp-z transform (or Bluestein's FFT). Another good reference is given by Rabiner and can be found at the above link.

In summary, with this approach you don't have to write the FFT yourself, you can simply use an existing high-performance FFT and then apply the convolution theorem to a suitably scaled and conditioned version of your signal.

The performance will still be, O(n*log n), multiplied by some implementation-dependent scaling factor.

like image 23
Bruce Dean Avatar answered Sep 21 '22 04:09

Bruce Dean