将双精度*转换为双精度(*)出错

Error converting double* to double(*)

本文关键字:双精度 出错 转换      更新时间:2023-10-16

下面的代码应该使用fftw3库返回正弦信号的fft:

# include <stdlib.h>
# include <stdio.h>
# include <time.h>
# include <fftw3.h>
# include <iostream>
# include <cmath>
using namespace std;
int main (void)
{
   int i;
   const int N=256;
   double Fs=1000;//sampling frequency
   double T=1/Fs;//sample time 
   double f=500;//frequency
   double *in;
   fftw_complex *out;
   double t[N-1];//time vector 
   fftw_plan plan_forward;
   in = (double*) fftw_malloc( sizeof( double ) * N );
   out = (fftw_complex*) fftw_malloc( sizeof( fftw_complex ) * N );
   for (int i=0; i<N; i++)
   {
     t[i] = i*T;
     in[i] = 0.7 *sin(2*M_PI*f*t[i]);// generate sine waveform
   }
   plan_forward = fftw_plan_dft_1d ( N, in, out, FFTW_FORWARD, FFTW_ESTIMATE );
   fftw_execute ( plan_forward );
   printf ( "n" );
   printf ( "  Output FFT Coefficients:n" );
   printf ( "n" );
   for ( i = 0; i < N; i++ )
   {
     printf ( "  %3d  %12f  %12fn", i, out[i][0], out[i][1] );
   }
   fftw_destroy_plan ( plan_forward );
   fftw_free ( in );
   fftw_free ( out );
   return 0;
 }

我得到的错误是不能将‘double*’ to ‘double (*)[2]转换为fftw_plan函数中的参数2。

有人知道如何解决这个问题吗?

in变量也需要是fftw_complex *,而不是double *。FFTW的复杂数据类型恰好是double[2],因此错误消息:编译器期望指向double[2]的指针,但您传递的是指向double的指针。

我所要做的就是将函数fftw_plan_dft_1d更改为fftw_plan_dft_r2c_1d