#include <MathAlgo/FFT.hh>
#include <Base/Math/Random.hh>
#include <iostream>
#include <iomanip>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
bool debug=false;
int data_length=100;
int num_sin=5;
double const_offset=0.0;
double *sin_freq=new double[num_sin], *phase_offs=new double[num_sin];
cout << "#using sin waves with freq and phase offset : "<<endl;
for (int i=0; i<num_sin; i++)
cout <<"#freq: "<< sin_freq[i]<<" \tphase offset: "<<phase_offs[i]<<endl;
double *p=in;
for (int l=0; l<data_length; l++, p++){
*p=const_offset;
for (int i=0; i<num_sin; i++)
*p+=sin(2*M_PI*sin_freq[i]*l+phase_offs[i]);
if (debug)
cout <<"sample "<< setw(4) << l <<" : "<<setw(15)<<*p<<endl;
}
int res_length=(data_length>>1)+1;
double *phase=new double[res_length], *mag=new double[res_length];
cout << "#result of fft: "<<endl;
cout <<setw(4)<<"#num"<<setw(15)<<"freq"<<setw(15)<<"mag"<<setw(15)
<<"phase"<<endl;
for (int i=0; i<res_length; i++){
cout <<setw(4)<<i
<<setw(15)<<(double)i/(double)data_length
<<setw(15)<<mag[i]
<<setw(15)<<phase[i]<<"\n";
}
if (argc>0)
cout << "# pipe outputt into file: "<<argv[0]<<" > tmp.dat"<<endl
<< "# and view with gnuplot : echo \"plot \\\"tmp.dat\\\" u 2:3 t \\\"magnitude\\\" w l, \\\"tmp.dat\\\" u 2:4 t \\\"phase\\\" w l; pause 99999;\" |gnuplot"<<endl;
delete[] sin_freq;
delete[] phase_offs;
delete[] phase;
delete[] mag;
return 0;
}