FFTW 3.01 and C++
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
FFTW 3.01 and C++

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
Heureka
Guest





Posted: Mon Dec 26, 2005 1:15 am    Post subject: FFTW 3.01 and C++ Reply with quote

Hi,

I hope this is not off topic!

I'm trying to make use of the FFTW library (V3.01) but I have some
difficulties working out the data types which comes with the library - and
possibly the coding too! Below I have pasted in my current source code which
should calculate the FFT of real input data. The input is a sinusoid signal
and I'm looking for non-zero data in the output vector but all I get is
zeros. I'm fairly green in terms of c++ programming so there might be some
really basic problems with my code. Furthermore, I'm not really sure how to
extract data from the output vector (a vector of the fftw_complex) Does
anyone know how to do this?

Cheers
Thomas

// FFT specific

int N = 256;

// Input test signal

double input[256];

char txt[256];

for(int indx=0; indx<256; indx++)

{

input[indx]=cos(2.f*22.f/7.f*1000.f*(indx/20000.f));

sprintf(txt,"sample[%d]= %f",indx,input[indx]);

OutputDebugString(txt);

}


double *in;

fftw_complex *out;

fftw_plan p;


in = (double *)fftw_malloc(sizeof(double) * N);

out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);

p = fftw_plan_dft_r2c_1d(N, in, out, FFTW_MEASURE);

fftw_execute(p); /* repeat as needed */

fftw_destroy_plan(p);


in = input;

fftw_free(in);

fftw_free(out);

for(int indx=0; indx<256; indx++)

{

sprintf(txt,"re[%d]=%f,& im[%d]=%f", indx, &out[indx][0], indx,
&out[indx][1]);

OutputDebugString(txt);

sprintf(txt,"re[%d]=%f,& im[%d]=%f", indx, out[indx][0], indx,
out[indx][1]);

OutputDebugString(txt);

}
Back to top
Heureka
Guest





Posted: Mon Dec 26, 2005 1:15 am    Post subject: Re: FFTW 3.01 and C++ Reply with quote

Hi ,

I found a bug so here is the sourcecode that still isn't working! :)
// FFT specific

int N = 256;

// Input test signal

double input[256];

char txt[256];

for(int indx=0; indx<256; indx++)

{

input[indx]=cos(2.f*22.f/7.f*1000.f*(indx/20000.f));

sprintf(txt,"sample[%d]= %f",indx,input[indx]);

OutputDebugString(txt);

}


double *in;

fftw_complex *out;

fftw_plan p;


in = (double *)fftw_malloc(sizeof(double) * N);

out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);

in = input;

p = fftw_plan_dft_r2c_1d(N, in, out, FFTW_MEASURE);


fftw_execute(p); /* repeat as needed */

for(int indx=0; indx<256; indx++)

{

sprintf(txt,"re[%d]=%f,& im[%d]=%f", indx, &out[indx][0], indx,
&out[indx][1]);

OutputDebugString(txt);

}

fftw_destroy_plan(p);

fftw_free(in);

fftw_free(out);
Back to top
Heureka
Guest





Posted: Mon Dec 26, 2005 5:15 pm    Post subject: Re: FFTW 3.01 and C++ Reply with quote

"William C Bonner" <wbonner@wimsworld.com> wrote in message
news:1135608574.878347.126730@g44g2000cwa.googlegroups.com...
Quote:
Why do people use the fftw library routines on a dsp?

I would assume that using DSP optimized libraries would get faster
results, and be more optimized for memory access as well.

I use fftw on the PC, for general purpose FFT calculations, but in that
case, having source code that compiles cross platform is helpful. Also,
I have not found better optimized distributable C/C++ FFT routines.

Hi,


Thanks for your reply. The transform is now working correctly. I found the
bug this morning :)

Cheers
Thomas
Back to top
William C Bonner
Guest





Posted: Mon Dec 26, 2005 5:15 pm    Post subject: Re: FFTW 3.01 and C++ Reply with quote

I've not uaed the latest version of fftw, but it appears that you are
missing several steps..

You create your raw data in the array input, but I never see you copy
that to the array "in" that you are using for the fftw routines.

I never see you use the "out" array before you free it up again.
(actually you use the array immediately after you free it, so I'm
surprised that you don't get some sort of exception.)
Back to top
William C Bonner
Guest





Posted: Mon Dec 26, 2005 5:15 pm    Post subject: Re: FFTW 3.01 and C++ Reply with quote

Why do people use the fftw library routines on a dsp?

I would assume that using DSP optimized libraries would get faster
results, and be more optimized for memory access as well.

I use fftw on the PC, for general purpose FFT calculations, but in that
case, having source code that compiles cross platform is helpful. Also,
I have not found better optimized distributable C/C++ FFT routines.
Back to top
Michel Rouzic
Guest





Posted: Tue Dec 27, 2005 5:15 pm    Post subject: Re: FFTW 3.01 and C++ Reply with quote

Heureka wrote:
Quote:
in = (double *)fftw_malloc(sizeof(double) * N);

out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);

Idk if it's the same with fftw_malloc as with the regular malloc, but
you should not cast the result of a malloc(). you have to include
stdlib.h (if i remember good)

btw, you say it's C++, but you can call that C, cuz all you type here
was in C
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB