I'm writing a frequency analyzer so I implemented
a Fourier Transform and it's working pretty well.
Now I need to speed-up the computing of the FT :
that would be great if someone could post
here a comprehensive routine for the FFT.
TIA
Note : the following code is not otimized, it's just
here to show the clarity of the Fourier Transform.
//------------------------------------------------------------
// time = time buffer input
// freq = frequency buffer output
// size = buffer size
//------------------------------------------------------------
void FT( double *time, double *freq, unsigned int size )
{
const double dpi = 6.283185307179586476925286766559;
double phi, real, imag; // angle, real and imaginary part
unsigned int f, t; // buffer indexes
for( f=0; f < size; ++f ) // frequency index
{
real = imag = 0.0; // reset cumulative values
for( t=0; t < size; ++t ) // time index
{
phi = dpi * (double)(f) * (double)(t) / (double)(size); // angle
real += time[t] * cos(phi); // real part
imag += time[t] * sin(phi); // imaginary part
}
freq[f] = pow((real*real)+(imag*imag),0.5) / (double)(size); //
amplitude
}
}
//------------------------------------------------------------
Hi Jean-Christophe
Look in the code of a library:
http://www.google.dk/search?q=fft+c%2B%2B+library
http://www.google.dk/search?q=fft+c+library
May 10, 2007, A Simple and Efficient FFT Implementation in C++, Part I:
http://www.drdobbs.com/embedded-systems/199500857
http://www.mathtools.net/C_C__/FFT/index.html
Glenn
>Hi all,
>
>I'm writing a frequency analyzer so I implemented
>a Fourier Transform and it's working pretty well.
>Now I need to speed-up the computing of the FT :
>that would be great if someone could post
>here a comprehensive routine for the FFT.
>
>TIA
>
>
>
>
>Note : the following code is not otimized, it's just
>here to show the clarity of the Fourier Transform.
>//------------------------------------------------------------
>// time = time buffer input
>// freq = frequency buffer output
>// size = buffer size
>//------------------------------------------------------------
>void FT( double *time, double *freq, unsigned int size )
>{
>const double dpi = 6.283185307179586476925286766559;
You have a system where double has 30 significant digits? And the
input will also?
>double phi, real, imag; // angle, real and imaginary part
>unsigned int f, t; // buffer indexes
>
> for( f=0; f < size; ++f ) // frequency index
> {
> real = imag = 0.0; // reset cumulative values
>
> for( t=0; t < size; ++t ) // time index
> {
> phi = dpi * (double)(f) * (double)(t) / (double)(size); // angle
Why the superfluous casts?
> real += time[t] * cos(phi); // real part
> imag += time[t] * sin(phi); // imaginary part
> }
>
> freq[f] = pow((real*real)+(imag*imag),0.5) / (double)(size); //
>amplitude
Hence the oft repeated recommendation to avoid // comments when
posting to Usenet.
Why the superfluous parentheses and cast?
> }
>}
>//------------------------------------------------------------
--
Remove del for email
Thanks Glen !
> Hi Jean-Christophe
> Look in the code of a library:
>
> http://www.google.dk/search?q=fft+c%2B%2B+libraryhttp://www.google.dk/search?q=fft+c+library
>
> http://www.fftw.org/
>
> May 10, 2007, A Simple and Efficient FFT Implementation in C++, Part I:http://www.drdobbs.com/embedded-systems/199500857
>
> http://www.mathtools.net/C_C__/FFT/index.html
>
> Glenn- Hide quoted text -
>
> - Show quoted text -