【发布时间】:2018-04-23 08:19:12
【问题描述】:
我在 C 中有一个大小为 1001(行)*144(列)的二维双复数数组。我想对每一行应用 FFT,最后想要 4096*144 格式的输出。这里N点= 4096。最后将结果与matlab输出进行比较。 我正在使用著名的 FFTW C 库。我已经阅读了tutorials,但无法理解如何正确使用。我应该使用哪个例程,例如 1D 例程或 2D 例程,然后如何使用?
#更新
double complex reshaped_calib[1001][144]={{1.0 + 0.1 * I}};
double complex** input; //[4096][144];
// have to take dynamic array as I was getting segmentation fault here
input = malloc(4096 * sizeof(double complex*));
for (i = 0; i < 4096; i++) {
input[i] = malloc(144* sizeof(double complex));
}
// input is array I am sending to fftw to apply fft
for (i= 0; i< 1001; i++)
{
for (j= 0; j< 144; j++)
{
input[i][j]=reshaped_calib[i][j];
}
}
// Pad the extra rows
for (i= 1001; i< 4096; i++)
{
for (j= 0; j< 144; j++)
{
input[i][j] = 0.0;
}
}
int N=144, howmany=4096;
fftw_complex* data = (fftw_complex*) fftw_malloc(N*howmany*sizeof(fftw_complex));
i=0,j=0;
int dataCount=0;
for(i=0;i<4096;i++)
{
for(j=0;j<144;j++)
{
data[dataCount++]=CMPLX(creal(input[i][j]),cimag(input[i][j]));
}
}
int istride=1, idist=N;// as in C data as row major
// ... if data is column-major, set istride=howmany, idist=1
// if data is row-major, set istride=1, idist=N
fftw_plan p = fftw_plan_many_dft(1,&N,howmany,data,NULL,howmany,1,data,NULL,howmany,1,FFTW_FORWARD,FFTW_MEASURE);
fftw_execute(p);
【问题讨论】:
-
您只需将输入数组补零至所需大小 (4096x144),然后使用简单的复数到复数 2D FFT。
-
@PaulR 我试图实现你的想法。明显做错了什么。出现分段错误。可以看看吗?
-
如果我们要帮助您调试,您需要发布minimal reproducible example。