Commit 65385676 authored by Laurent Belcour's avatar Laurent Belcour

Adding functionality to the Fourier transform module

parent daed4acb
...@@ -95,7 +95,7 @@ class arguments ...@@ -95,7 +95,7 @@ class arguments
{ {
int i = 0; int i = 0;
size_t pos = 1; size_t pos = 1;
while(pos != std::string::npos) while(pos != std::string::npos && i<size)
{ {
size_t ppos = s.find(',', pos); size_t ppos = s.find(',', pos);
...@@ -112,7 +112,6 @@ class arguments ...@@ -112,7 +112,6 @@ class arguments
++i; ++i;
} }
} }
std::cout << std::endl ;
return res; return res;
} }
} }
......
...@@ -25,7 +25,7 @@ int main(int argc, char** argv) ...@@ -25,7 +25,7 @@ int main(int argc, char** argv)
plugins_manager manager(args) ; plugins_manager manager(args) ;
if(args.is_defined("help")) { if(args.is_defined("help")) {
std::cout << "<<HELP>> data2gnuplot --input data.file --output gnuplot.file --loader loader.so" << std::endl ; std::cout << "<<HELP>> fouriertransform --input data.file --output gnuplot.file --loader loader.so --in [input vector] --raw gnuplot.file" << std::endl ;
std::cout << " - input and output are mandatory parameters" << std::endl ; std::cout << " - input and output are mandatory parameters" << std::endl ;
return 0 ; return 0 ;
} }
...@@ -58,10 +58,11 @@ int main(int argc, char** argv) ...@@ -58,10 +58,11 @@ int main(int argc, char** argv)
std::cout << "<<INFO>> will export " << d->size() << " elements" << std::endl ; std::cout << "<<INFO>> will export " << d->size() << " elements" << std::endl ;
double theta_in = (double)args.get_float("theta", 0.0f);
double phi_in = (double)args.get_float("phi", 0.0f);
vec in(3), out(3) ; vec in(3), out(3) ;
vec arg_in = args.get_vec("in", 2);
double theta_in = (double)arg_in[0];
double phi_in = (double)arg_in[1];
in[0] = cos(phi_in)*sin(theta_in); in[0] = cos(phi_in)*sin(theta_in);
in[1] = sin(phi_in)*sin(theta_in); in[1] = sin(phi_in)*sin(theta_in);
in[2] = cos(theta_in); in[2] = cos(theta_in);
...@@ -79,7 +80,8 @@ int main(int argc, char** argv) ...@@ -79,7 +80,8 @@ int main(int argc, char** argv)
out[1] = sin(phi)*sin(theta); out[1] = sin(phi)*sin(theta);
out[2] = cos(theta); out[2] = cos(theta);
vec v = d->value(in, out) ; vec v = d->value(in, out) ;
xdata[j] = j-N/2; xdata[j] = theta;
data[j] = v[0] ; data[j] = v[0] ;
/* /*
...@@ -92,10 +94,7 @@ int main(int argc, char** argv) ...@@ -92,10 +94,7 @@ int main(int argc, char** argv)
} }
// Create the MATLAB defintion of objects // Create the MATLAB defintion of objects
// MATLAB defines a quad prog as mxArray *d, *x, *f;
// 1/2 x' H x + f' x with A x <= b
//
mxArray *d, *x;
d = mxCreateDoubleMatrix( N, 1, mxREAL); d = mxCreateDoubleMatrix( N, 1, mxREAL);
x = mxCreateDoubleMatrix( N, 1, mxREAL); x = mxCreateDoubleMatrix( N, 1, mxREAL);
memcpy((void *)mxGetPr(d), (void *) data, N*sizeof(double)); memcpy((void *)mxGetPr(d), (void *) data, N*sizeof(double));
...@@ -108,21 +107,35 @@ int main(int argc, char** argv) ...@@ -108,21 +107,35 @@ int main(int argc, char** argv)
output[BUFFER_SIZE] = '\0'; output[BUFFER_SIZE] = '\0';
engOutputBuffer(ep, output, BUFFER_SIZE) ; engOutputBuffer(ep, output, BUFFER_SIZE) ;
engEvalString(ep, "normd = sum(d) / max(size(d));"); engEvalString(ep, "normd = sum(d) / max(size(d));");
std::cout << output << std::endl ;
engEvalString(ep, "d = d ./ normd;"); engEvalString(ep, "d = d ./ normd;");
std::cout << output << std::endl ; engEvalString(ep, "ff = fftshift(fft(d));");
engEvalString(ep, "f = real(fftshift(fft(d)));"); engEvalString(ep, "f = sqrt(real(ff).^2 + imag(ff).^2);");
std::cout << output << std::endl ;
engEvalString(ep, "normf = sum(f) / max(size(f));"); engEvalString(ep, "normf = sum(f) / max(size(f));");
std::cout << output << std::endl ;
engEvalString(ep, "f = f ./ normf;"); engEvalString(ep, "f = f ./ normf;");
std::cout << output << std::endl ; // engEvalString(ep, "plot(x, f, x, d)");
engEvalString(ep, "plot(x, f, x, d)"); // std::cout << output << std::endl ;
std::cout << output << std::endl ;
f = engGetVariable(ep, "f");
std::ofstream out_fourier(args["output"].c_str(), std::ios_base::trunc);
double* val = (double*)mxGetData(f) ;
for(int i=0; i<N; ++i)
{
out_fourier << i - N/2 << "\t" << val[i] << std::endl ;
}
out_fourier.close();
char c; if(args.is_defined("raw"))
std::cin >> c ; {
std::ofstream out_raw(args["raw"].c_str(), std::ios_base::trunc);
for(int i=0; i<N; ++i)
{
out_raw << xdata[i] << "\t" << data[i] << std::endl ;
}
out_raw.close();
}
mxDestroyArray(x);
mxDestroyArray(d);
engClose(ep); engClose(ep);
} }
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment