【发布时间】:2015-10-07 19:09:41
【问题描述】:
好的,所以我一直在研究以下问题一段时间,但似乎无法找到答案。简而言之,我正在为雷达信号实现断层成像,似乎无法让 FFTW 给我除零以外的输出。我正在通过 C++ 实现并使用 FFTW3 库。
现在的输入是场景原点的模拟点散射体,它具有所有真实的相位响应(参见rxphase 变量)。由于使用的带宽等原因,过滤后的接收信号的 IFFT 应该相当大(我还没有对其进行缩放),但每个脉冲我都得到了零。
摘自我的代码:
void ifftshift(std::vector<phdata> &argin, std::size_t count){
int k = 0;
int c = (int)floor((float)count/2);
if (count % 2 == 0)
{
for (k=0; k<c;k++)
{
complex<double> tmp = argin[k];
argin[k] = argin[k+c];
argin[k+c] = tmp;
}
}
else
{
complex<double> tmp = argin[count-1];
for (k=c-1; k>=0; k--)
{
argin[c+k+1] = argin[k];
argin[k] = argin[c+k];
}
argin[c] = tmp;
}
};
void main(){
std::vector<complex<double> > filteredData;
// Number of pulses across the aperture
std::int pulses = 11;
// Define the frequency vector
std::vector<double> freq;
std::double freqmin = 9 * pow(10,9);
std::double freqmax = 11 * pow(10,9);
std::vector<complex<double> > outData;
std::vector<complex<double> > rxphase;
for (int i = 0; i<64; i++)
{
freq.push_back(freqmin + (((freqmax-freqmin)/64)*i));
}
// Create a (samples X pulses) array of complex doubles
rxphase.assign(64, std::vector<complex<double> > (11, {1,0}) );
fftw_complex *in, *out;
fftw_plan plan;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * image.Nfft );
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * image.Nfft );
plan = fftw_plan_dft_1d(image.Nfft, in, out, FFTW_BACKWARD, FFTW_MEASURE);
// iterate through pulses to back project across the aperture
for ( int i=0; i<=pulses; i++ )
{
// Reset vectors for each pulse
filteredData.clear();
outData.clear();
for ( int ii=0; ii<freq.size(); ii++ )
{
// Apply simple ramp filter
filteredData.push_back(freq[ii]*rxphase[ii][i]);
}
// Shift the data to put the center frequency at DC position (zero index)
ifftshift(filteredData, filteredData.size());
for (int ii=0; ii<filteredData.size(); ii++)
{
std::cout << filteredData[ii] ;
}
std::cout << std::endl;
// filteredData is what I expect it to be.
// Recast the vector to the type needed for FFTW and compute FFT
in = reinterpret_cast<fftw_complex*>(&filteredData[0]);
for (int ii=0; ii<filteredData.size(); ii++)
{
std::cout << "(" << (in[ii])[0] << "," << (in[ii])[1] << ");";
}
std::cout << std::endl;
// values for in are the same as for filteredData, as expected.
fftw_execute(plan);
for (int ii=0; ii<filteredData.size(); ii++)
{
std::cout << "(" << (out[ii])[0] << "," << (out[ii])[1] << ");";
}
std::cout << std::endl;
// The values for out are all (0,0)
}
fftw_destroy_plan(plan);
//fftw_free(in); error here
//fftw_free(out); error here
};
任何帮助将不胜感激。
编辑:代码应该更完整一些。
【问题讨论】:
-
我真的不能说这里出了什么问题,但是当您从 c++ 代码使用 FFTW 时,我建议您使用 FFTW++。