Reputation:
here is my code 4 fft calc using bluestein algorithm in c++
#include <iostream>
#include <cmath>
#include <complex>
#define pi 3.14
using namespace std;
int main()
{
int n, k, N;
std::complex<double> y, z, sum = 0, x[] = { 1, 2, 2, 1 };
int i = sqrt(-1);
N = 4;
for (k = 0; k <= N - 1; k++)
{
y = exp(pi*k*N*k*i);
for (n = 0; n <= N - 1; n++)
{
z = exp((pi*(k*k - 2 * k*n*i)) / N);
sum += (x[n] * z);
}
x[k] = (sum * y);
cout << "The fft of x[n] is = " << x[k] << endl;
}
return 0;
}
i need out put as {6, -1-i, 0, -1+j} when v run in visual studio 2013. if possible plz help me to declare input array generally.
Upvotes: 0
Views: 363
Reputation: 5840
the << operator is overladed like this http://en.cppreference.com/w/cpp/numeric/complex/operator_ltltgtgt
however you can just use this to get desired output:
cout << "The fft of x[n] is = " << x[k].real() << "+"<< x[k].imag()<< "i" << endl;
Upvotes: 1