The Flutter Shutter Density Estimator
 All Files Functions Macros Pages
routines.cpp
Go to the documentation of this file.
1 /*routines.cpp*/
2 /*
3 * Copyright 2014 IPOL Image Processing On Line http://www.ipol.im/
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
35 #include <stdlib.h>
36 #include <math.h>
37 #include <iostream>
38 #include <fstream>
39 #include <vector>
40 #include "routines.h"
41 
42 #ifndef ABS
43 
46 #define ABS(x) (((x) > 0) ? (x) : (-(x)))
47 #endif
48 
49 
50 #ifndef M_PI
51 
54 #define M_PI 3.14159265358979323846
55 #endif
56 
57 
58 
59 
60 using namespace std;
66 
74 std::vector<double> fileToVector(const char *name)
75 {
76  std::vector<double> code;
77  ifstream fin;
78  fin.open(name); // open a file
79  if (!fin.good())
80  cerr << "file not found" << endl; // in case file not found.
81  std::ifstream input (name);
82  std::string lineData;
83 
84  while(getline(input, lineData))
85  {
86  code.push_back(::atof(lineData.c_str()));
87  }
88 
89  return code;
90 }
91 
92 
93 
94 
95 
101 
112 double abs_hat_alpha(std::vector<double> code, double xi)
113 {
115  //initialization
116  double re_abs_hat_alpha=0; //real part
117  double im_abs_hat_alpha=0; //imaginary part
118  //Main loop
119  //cout << "code.size" << code.size() << "\n" ;
120  for (unsigned k=0; k<code.size(); k++)
121  { //cout << "code de k" << code[k] << "\n" ;
122  im_abs_hat_alpha =im_abs_hat_alpha+code[k]*sin(-xi*(k+0.5));
123  re_abs_hat_alpha =re_abs_hat_alpha+code[k]*cos(-xi*(k+0.5));
124  }
125 
126  if (ABS(xi)>0) //avoiding 0/0
127  {
128  im_abs_hat_alpha =im_abs_hat_alpha*sin(xi/2)
129  /(xi/2);//ELSE =1;
130  re_abs_hat_alpha =re_abs_hat_alpha*sin(xi/2)
131  /(xi/2); //ELSE =1;
132  }
133 
134  return(pow(im_abs_hat_alpha*im_abs_hat_alpha+
135  re_abs_hat_alpha*re_abs_hat_alpha,0.5));
139 }
140 
141 
142 
143 
144 
150 
162 double w_prime_estimator(double xi, std::vector<double> code,
163  double epsilon)
164 {
165  if (ABS(xi)>0) //avoiding 0/0
166  {return((pow(abs_hat_alpha(code, xi+epsilon),4)*
167  pow(sin((xi+epsilon)/2)/((xi+epsilon)/2),2)-
168  (pow(abs_hat_alpha(code, xi),4))*// this is \frac 1 sinc
169  pow(sin(xi/2)/(xi/2),2))/epsilon);}
170  return((pow(abs_hat_alpha(code, xi+epsilon),4)-
171  (pow(abs_hat_alpha(code, xi),4)))/epsilon);
172 }
173 
174 
175 
double abs_hat_alpha(std::vector< double > code, double xi)
Definition: routines.cpp:112
#define ABS(x)
Definition: routines.cpp:46
std::vector< double > fileToVector(const char *name)
Given the file name oof a text file containing a flutter code store the values in a vector of doubles...
Definition: routines.cpp:74
double w_prime_estimator(double xi, std::vector< double > code, double epsilon)
Definition: routines.cpp:162