I am learning fftw (replace the self-defined fft function) in c++. In the old code, I have the algorithm designed in std::vector samples storage. According to the document, I use casting to interact the fftw datatype to my data (in std::vector).
#include <fftw3.h>
#include <vector>
#include <iostream>
#include <complex>
using namespace std;
void main(void)
{
std::vector< complex<double> > x(4);
x[0] = std::complex<double>(0.0, 0.0);
x[1] = std::complex<double>(1.0, 0.0);
x[2] = std::complex<double>(0.0, 2.0);
x[3] = std::complex<double>(3.0, 3.0);
// print the vector, looks good
for (int i=0; i<4; i++)
{
cout << x[i] << endl;
}
// refer fftw datatype to the std::vector by casting
fftw_complex* in = reinterpret_cast<fftw_complex*>(&x[0]);
// print in reference, gives random numbers
for (int i=0; i<4; i++)
{
cout << *in[i*2] << " " << *in[i*2+1] << endl;
}
}
But in seems not really pointing to the right place, it shows random numbers instead. Besides above question, my purpose is to generate a vector with 8 elements (example), the first 4 element refer to the std::vector but the last four is initialized as some constant. Is that possible to have *in pointing to the first in vector and then pointing to 4 constant values somewhere else, so I can fftw "in"? Thanks.