#include <fstream>
#include <iostream>
string tempPath="/tmp";
vector<string> args(3); args[0]=string("--silent"); args[1]=string("--path"); args[2]=tempPath;
int count=11;
ofstream out((tempPath+"/ComplexFFTExampleTest.m").c_str());
out<<"function [INr, INc, pwrSpec]=ComplexFFTExampleTest(inR, inC)"<<endl;
out<<"IN=fft(inR+i*inC);"<<endl;
out<<"INr=real(IN);"<<endl;
out<<"INc=imag(IN);"<<endl;
out<<"pwrSpec=abs(IN);"<<endl;
out<<"end"<<endl;
out.close();
vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > input(2), output(3);
input[0]=Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Random(count, 1);
input[1]=Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Random(count, 1);
octave.
runM(
"ComplexFFTExampleTest", input, output);
for (int i=0; i<count; i++){
c_re(fftData.
in[i])=input[0](i,0);
c_im(fftData.
in[i])=input[1](i,0);
}
cout<<"octave real :"<<endl;
cout<<output[0].transpose()<<endl;
cout<<"fft real :"<<endl;
for (int i=0; i<count; i++)
cout<<"\noctave imag :"<<endl;
cout<<output[1].transpose()<<endl;
cout<<"fft imag :"<<endl;
for (int i=0; i<count; i++)
cout<<endl;
double error=0.0, maxError=0.0;
for (int i=0; i<count; i++){
double er=abs(
c_re(fftData.
out[i])-output[0](i,0))+abs(
c_im(fftData.
out[i])-output[1](i,0));
error+=er;
if (er > maxError)
maxError=er;
}
cout<<'\n'<<"The total fwdTransform error = "<<error<<endl;
cout<<'\n'<<"The maximum fwdTransform error = "<<maxError<<endl;
error=0.0, maxError=0.0;
for (int i=0; i<count; i++){
double er=abs(
c_re(fftData.
in[i])/(
float)count-input[0](i,0))+abs(
c_im(fftData.
in[i])/(
float)count-input[1](i,0));
error+=er;
if (er > maxError)
maxError=er;
}
cout<<'\n'<<"The total invTransform error = "<<error<<endl;
cout<<'\n'<<"The maximum invTransform error = "<<maxError<<endl;
error=0.0, maxError=0.0;
for (int i=0; i<count; i++){
error+=er;
if (er > maxError)
maxError=er;
}
cout<<'\n'<<"The total power spectrum error = "<<error<<endl;
cout<<'\n'<<"The maximum power spectrum error = "<<maxError<<endl;
}