我正在尝试实施here中的路线来计算二维傅里叶变换:
#include <stdio.h>
#include <stdlib.h>
#include </usr/local/include/fftw3.h>
#include <math.h>
#define NUM_POINTS 600
#define REAL 0
#define IMAG 1
void acquire_from_somewhere(fftw_complex *signal) {
int i, j, m_gamma=2, Lambda=1;
double theta=0.095,kappa=5.;
for (i = 0; i < NUM_POINTS; ++i) {
for (j = 0; j < NUM_POINTS; ++j) {
double x = (double)i / (double)NUM_POINTS * M_PI, y = (double)j / (double)NUM_POINTS * M_PI;
signal[i][j][REAL] = Lambda*cos(theta/2)*cos(theta/2)*cos(m_gamma * atan(y/x));
signal[i][j][IMAG] =0.;
}}
}
void do_something_with(fftw_complex *result, double *mag) {
int i,j;
for (i = 0; i < NUM_POINTS; ++i) {
for (j = 0; j < NUM_POINTS; ++j) {
*mag = sqrt(result[i][j][REAL] * result[i][j][REAL] + result[i][j][IMAG] * result[i][j][IMAG]);
printf("%g\n", *mag);
}}
}
/* Resume reading here */
int main() {
double mag;
fftw_complex signal[NUM_POINTS][NUM_POINTS];
fftw_complex result[NUM_POINTS][NUM_POINTS];
fftw_plan plan = fftw_plan_dft_2d(NUM_POINTS,NUM_POINTS,
&signal[0][0],
&result[0][0],
FFTW_FORWARD,
FFTW_ESTIMATE);
acquire_from_somewhere(&signal[0][0]);
fftw_execute(plan);
do_something_with(&result[0][0], &mag);
// printf("%g\n", mag);
fftw_destroy_plan(plan);
return 0;
}
我遇到以下类型的错误:
FFT.c:26:21: error: subscripted value is not an array, pointer, or vector
signal[i][j][REAL] = Lambda*cos(theta/2)*cos(theta/2)*cos(m_gamma * atan(y/x));//Lambda*(cos(theta/2)*cos(theta/2)*cos(m_gamm...
~~~~~~~~~~~~^~~~~
我不确定在哪里看...我想,传递2D数组的传统方式对fftw_complex不起作用。如何解决我的错误?
答案 0 :(得分:0)
fftw_complex *signal
表示正在传递fftw_complex
的指针,可能是衰减的1D数组。
3D阵列衰变为指向2D阵列的指针。所以你应该把那个论点写成
fftw_complex (*signal)[][]
同样在你的问题中,你谈论的是2D阵列,但将signal
视为3D数组,不一致。