FT and FFT


J

Jean-Christophe

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;
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
}
}
//------------------------------------------------------------
 
Ad

Advertisements

G

Glenn

Jean-Christophe said:
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;
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+++library
http://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
 
B

Barry Schwarz

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?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top