将双精度*转换为双精度(*)出错
Error converting double* to double(*)
下面的代码应该使用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
。
相关文章:
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 正在将csv文件读取为双精度矢量
- 我可以信任表示整数的浮点或双精度来保持精度吗
- 如何在C++中的同一函数中使用字符串和双精度
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 检查是否以特定精度给出双精度
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- C 字符串返回字符串的整数/双精度/长整型值
- 为什么将双精度转换为 int 似乎在第 16 位数字之后将其四舍五入?
- 如何使双精度值的 C++ 和 C# 中的结果相同
- 使用浮点数和双精度数的非常小数字的数学
- 为什么双精度数据类型在C++中出错?
- 在 C# 中从二进制值转换为双精度值时出错
- 将双精度转换为整数时出错
- 将lower_bound与矢量<对<字符串、双精度一起使用时出错>>
- 用C++计算小双精度数时出错
- 在双精度的 qt 中使用模运算符时出错
- 为双精度值分配内存时出错
- 将双精度*转换为双精度(*)出错
- 使用EXPECT_EQ计算双精度或浮点数的和时出错