入力を取得し、DFT (離散フーリエ変換) を実行してから、これらの値からゼロクロッシングの数を取得する必要があるプロジェクトに取り組んでいます。
アルゴリズムをコーディングしましたが、複素数を使用しており、それらを操作/計算する方法がわかりません。コードは次のとおりです。
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;
vector< complex<double> > DFT(vector< complex<double> >& theData)
{
// Define the Size of the read in vector
const int S = theData.size();
// Initalise new vector with size of S
vector< complex<double> > out(S, 0);
for(unsigned i=0; (i < S); i++)
{
out[i] = complex<double>(0.0, 0.0);
for(unsigned j=0; (j < S); j++)
{
out[i] += theData[j] * polar<double>(2, (-2 * PI * i * j / S));
}
}
return out;
}
int main(int argc, char *argv[]) {
vector< complex<double> > numbers;
numbers.push_back(128);
numbers.push_back(127);
vector< complex<double> > testing = DFT(numbers);
for(unsigned i=0; (i < testing.size()); i++)
{
cout << testing[i] << endl;
}
}
たとえば、実行したい場合:
if(testing[i] >= 0)
{
// blah blah
}
その後、エラーが返されます。アイデアや提案はありますか?複素数を使用せずに DFT を作成することは可能ですか?