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);
}