I want to take FFT of my signal and reconstruct it back via IFFT. It seems the real part of odd numbered samples and image part of even numbered samples are multiplied by -1 which can be observed below:
For example if I have
[995] (-0.382624, 0.000000) std::complex<double>
[996] (-0.831434, 0.000000) std::complex<double>
[997] (-1.000000, 0.000000) std::complex<double>
[998] (-0.831506, 0.000000) std::complex<double>
[999] (-0.382743, 0.000000) std::complex<double>
Some of the values(not all) having the negative sign like below
[995] (0.382624, 0.000000) std::complex<double>
[996] (-0.831434, -0.000000) std::complex<double>
[997] (1.000000, 0.000000) std::complex<double>
[998] (-0.831506, 0.000000) std::complex<double>
[999] (0.382743, -0.000000) std::complex<double>
Is there any explanation for this behavior?
I am using FFTW library and I wrap it a bit like below ;
in = sharpFFT(in, true);
in = swapVectorWithIn(in);
in = sharpFFT(in, false);
for ( auto& elem : in)
elem /= in.size();
using CDataType = std::vector< std::complex<double> > ;
inline
CDataType swapVectorWithIn( const CDataType& in )
{
auto middlePos = in.begin() + in.size()/2;
CDataType returnVal( middlePos , in.end() );
returnVal.insert( returnVal.end(), in.begin(), middlePos);
return returnVal;
}
inline
CDataType sharpFFT( CDataType& in, bool isForward )
{
const int N = in.size() ;
std::vector< std::complex<double> > out (N);
fftw_plan my_plan;
if (!isForward)
my_plan = fftw_plan_dft_1d(N, reinterpret_cast<fftw_complex*>(&in[0]),
reinterpret_cast<fftw_complex*>(&out[0]), FFTW_BACKWARD, FFTW_ESTIMATE);
else
my_plan = fftw_plan_dft_1d(N, reinterpret_cast<fftw_complex*>(&in[0]),
reinterpret_cast<fftw_complex*>(&out[0]), FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(my_plan);
if (!isForward)
{
std::transform(out.begin(), out.end(), out.begin(), [N]( std::complex<double>& elem ){
return elem / (double)N;
});
}
return out;
}
std::rotate
$\endgroup$