Andreas
10-03-2009, 12:31 PM
Hi there!
Trying to run an ft on 2d data with libfftw3 gives me wrong results
until I run the same problem a second time. I'm using windows with the
pre-built dll's, and get the problem while compiling with mingw and
VS.
Has anybody of you encountered a similar problem?
The following code gives an example. I do an forward transformation on
some kind of delta peak and print the results.
Every hint would be great!
Andreas
#include "fftw3.h"
#include <cstring>
void fft(int height, int width){
// prepare the input array
fftw_complex *img;
img = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*width*height);
memset(img, 0, sizeof(fftw_complex)*width*height);
img[0][0] = 1.;
// now the ouput array
fftw_complex * out;
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*height*width);
memset(out, 0, sizeof(fftw_complex)*height*width);
// create a plan and run it
fftw_plan p;
p = fftw_plan_dft_2d(height, width, img, out, FFTW_FORWARD,
FFTW_UNALIGNED);
if(p == NULL)
printf("Planing failed!\n");
fftw_execute(p);
// print output
printf("Out = %dx%d\n", height, width);
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++)
printf("%1.2e i%1.2e\t", out[width*i+j][0], out[width*i+j][1]);
printf("\n");
}
printf("\n\n");
// clean up
fftw_destroy_plan(p);
fftw_free(img);
fftw_free(out);
}
int main()
{
// bad run
fft(2, 2);
// sucessfull run
fft(2, 2);
getchar();
return 0;
}
Trying to run an ft on 2d data with libfftw3 gives me wrong results
until I run the same problem a second time. I'm using windows with the
pre-built dll's, and get the problem while compiling with mingw and
VS.
Has anybody of you encountered a similar problem?
The following code gives an example. I do an forward transformation on
some kind of delta peak and print the results.
Every hint would be great!
Andreas
#include "fftw3.h"
#include <cstring>
void fft(int height, int width){
// prepare the input array
fftw_complex *img;
img = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*width*height);
memset(img, 0, sizeof(fftw_complex)*width*height);
img[0][0] = 1.;
// now the ouput array
fftw_complex * out;
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*height*width);
memset(out, 0, sizeof(fftw_complex)*height*width);
// create a plan and run it
fftw_plan p;
p = fftw_plan_dft_2d(height, width, img, out, FFTW_FORWARD,
FFTW_UNALIGNED);
if(p == NULL)
printf("Planing failed!\n");
fftw_execute(p);
// print output
printf("Out = %dx%d\n", height, width);
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++)
printf("%1.2e i%1.2e\t", out[width*i+j][0], out[width*i+j][1]);
printf("\n");
}
printf("\n\n");
// clean up
fftw_destroy_plan(p);
fftw_free(img);
fftw_free(out);
}
int main()
{
// bad run
fft(2, 2);
// sucessfull run
fft(2, 2);
getchar();
return 0;
}