#include <fstream>
#include <iostream>
#include <stdlib.h>
string tempPath="/tmp";
vector<string> args(3);
args[0]=string("--silent");
args[1]=string("--path");
args[2]=tempPath;
int count=7;
ofstream out((tempPath+"/Real2DFFTExampleTest.m").c_str());
out<<"function [INr, INc, pwrSpec]=RealFFTExampleTest(in)"<<endl;
out<<"IN=fft2(in);"<<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(1), output(3);
input[0]=Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Random(count, count);
octave.
runM(
"Real2DFFTExampleTest", input, output);
for (
int i=0; i<fftData->
getXSize(); i++)
for (
int j=0; j<fftData->
getYSize(); j++)
fftData->
in[i*count+j]=input[0](i,j);
double error=0., maxError=0.;
for (
int i=0; i<fftData->
getXSize(); i++) {
error+=err;
if (err>maxError)
maxError=err;
}
}
cout<<"the total error for the fwd transform is = "<<error<<endl;
cout<<"the max error for the fwd transform is = "<<maxError<<endl;
error=0.; maxError=0.;
for (
int i=0; i<fftData->
getXSize(); i++) {
double err=abs(fftData->
power[i*(
int)round(fftData->
getXSize()/2.)+j]-output[2](i,j));
error+=err;
if (err>maxError)
maxError=err;
}
}
cout<<"the total error for the power spectrum is = "<<error<<endl;
cout<<"the max error for the power spectrum is = "<<maxError<<endl;
delete fftData;
delete fft;
}