34 #include <MathAlgo/FFT.hh>
35 #include <Base/Math/Random.hh>
42 int main(
int argc,
char *argv[])
51 double const_offset=0.0;
52 double *sin_freq=
new double[num_sin], *phase_offs=
new double[num_sin];
56 cout <<
"#using sin waves with freq and phase offset : "<<endl;
57 for (
int i=0; i<num_sin; i++)
58 cout <<
"#freq: "<< sin_freq[i]<<
" \tphase offset: "<<phase_offs[i]<<endl;
61 fft.
Init(data_length);
66 for (
int l=0; l<data_length; l++, p++){
68 for (
int i=0; i<num_sin; i++)
69 *p+=sin(2*M_PI*sin_freq[i]*l+phase_offs[i]);
71 cout <<
"sample "<< setw(4) << l <<
" : "<<setw(15)<<*p<<endl;
78 int res_length=(data_length>>1)+1;
79 double *phase=
new double[res_length], *mag=
new double[res_length];
84 cout <<
"#result of fft: "<<endl;
85 cout <<setw(4)<<
"#num"<<setw(15)<<
"freq"<<setw(15)<<
"mag"<<setw(15)
87 for (
int i=0; i<res_length; i++){
89 <<setw(15)<<(double)i/(
double)data_length
91 <<setw(15)<<phase[i]<<
"\n";
95 cout <<
"# pipe outputt into file: "<<argv[0]<<
" > tmp.dat"<<endl
96 <<
"# 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;
void GetMagnitude(double *mag)
returns the resulting magnitude, mag must be of length size/2+1 (rounded downwards) ...
void Compute(double *in)
slow, memcopys in to internal input data
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Wrapper to the fftw3 library.
double * GetInput()
returns the internal data.
void Init(int size)
initializes the internal variables.
void DumpResult(std::ostream &os=std::cout)
void GetPhase(double *phase)
returns the resulting phase, phase must be of length size/2+1 (rounded downwards) ...
class for producing random numbers from different distributions