我正在尝试将一个复数数组(我创建了一个名为 Complex 的类,它只存储一个实部和虚部)到下面的 dft 函数中,并让它吐出一些结果。我尝试了 x 的许多变体 - 包括 x[]、x[3]、* x来尝试将数据数组传递到 dft 函数中,但我不断收到“对 'Complex::dft(Complex* ,整数,整数)”。
如果我刚刚做了一些非常愚蠢和明显的事情,我提前道歉,但我已经盯着这个看了好几个小时,一直在画一个空白。任何帮助将不胜感激。
谢谢
这是我的 dft 函数:
#include <iostream>
#include "Complex.h"
#include "ofstream_add.h"
#include <cmath>
const double PI=4*atan(1.0);
Complex dft(Complex x[], int N, int n)
{
Complex holder;
Complex sum = Complex(0,0);
Complex temp;
for (int k=0; k<N; k++)
{
temp = Complex(cos(2.0*PI*k*n/N),-sin(2.0*PI*k*n/N));
sum = sum + x[k] * temp;
}
double conv = N; //convert integer to double as complex takes in doubles
Complex complexN((1/conv),(1/conv));
holder = complexN * sum;
return holder;
}
这是我的主要程序:
#include <iostream>
#include <iomanip>
#include "Complex.h"
#include "ofstream_add.h"
int main()
{
int N = 3;
Complex holder;
Complex y[N];
double re,im,ansRe,ansIm;
Complex a(2,1.7);
Complex b(3.5,1.2);
Complex c(4.2,2.3);
Complex x[3] = {a, b, c};
for (int n=0;n<N;n++)
{
//does some processing on the array of complex numbers an spits out a
//real and imaginary part
double ansRe = holder.dft(x,N,n).getReal();
double ansIm = holder.dft(x,N,n).getImag();
//stores the result in a new complex number
y[n].setReal(ansRe);
y[n].setImag(ansIm);
}
}