Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FT and FFT

4 views
Skip to first unread message

Jean-Christophe

unread,
Mar 28, 2010, 6:25:35 AM3/28/10
to
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
}
}
//------------------------------------------------------------

Glenn

unread,
Mar 28, 2010, 6:46:20 AM3/28/10
to

Barry Schwarz

unread,
Mar 28, 2010, 1:58:53 PM3/28/10
to
On Sun, 28 Mar 2010 03:25:35 -0700 (PDT), Jean-Christophe
<5...@free.fr> wrote:

>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

Jean-Christophe

unread,
Mar 28, 2010, 2:03:33 PM3/28/10
to
On Mar 28, 11:46 am, Glenn

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 -

0 new messages