2 #include "gsl/gsl_fft_real.h"
3 #include "gsl/gsl_fft_halfcomplex.h"
10 NumberPointsLeft_m(nl),
11 NumberPointsRight_m(nr),
14 CoefsDeriv_m(np, 0.0) {
20 std::vector<double> temp(LineDensity.size(), 0.0);
22 LineDensity.assign(temp.begin(), temp.end());
26 std::vector<double> temp(LineDensity.size(), 0.0);
28 LineDensity.assign(temp.begin(), temp.end());
32 void savgol(std::vector<double> &
c,
const int &np,
const int &nl,
const int &
nr,
const int &ld,
const int &m) {
33 int j, k, imj, ipj, kk, mm;
36 if (np < nl + nr + 1 || nl < 0 || nr < 0 || ld > m || nl + nr < m) {
37 std::cerr <<
"bad args in savgol" <<
std::endl;
40 std::vector<int> indx(m + 1, 0);
41 std::vector<double> a((m + 1) * (m + 1), 0.0);
42 std::vector<double> b(m + 1, 0.0);
44 for (ipj = 0; ipj <= (m << 1); ++ipj) {
45 sum = (ipj ? 0.0 : 1.0);
46 for (k = 1; k <=
nr; ++k)
47 sum += (
int)
pow((
double)k, (
double)ipj);
48 for (k = 1; k <= nl; ++k)
49 sum += (
int)
pow((
double) - k, (
double)ipj);
50 mm = (ipj < 2 * m - ipj ? ipj : 2 * m - ipj);
51 for (imj = -mm; imj <= mm; imj += 2)
52 a[(ipj + imj) / 2 * (m + 1) + (ipj - imj) / 2] =
sum;
56 for (j = 0; j < m + 1; ++j)
61 for (kk = 0; kk < np; ++kk)
63 for (k = -nl; k <=
nr; ++k) {
66 for (mm = 1; mm <= m; ++mm)
67 sum += b[mm] * (fac *= k);
74 void convlv(
const std::vector<double> &data,
const std::vector<double> &respns,
const int &isign, std::vector<double> &ans) {
76 int m = respns.size();
78 double *tempfd1 =
new double[
n];
79 double *tempfd2 =
new double[
n];
81 gsl_fft_halfcomplex_wavetable *hc;
82 gsl_fft_real_wavetable *
real = gsl_fft_real_wavetable_alloc(n);
83 gsl_fft_real_workspace *
work = gsl_fft_real_workspace_alloc(n);
86 for (
int i = 0; i <
n; ++ i) {
91 tempfd1[0] = respns[0];
92 for (
int i = 1; i < (m + 1) / 2; ++i) {
93 tempfd1[i] = respns[i];
94 tempfd1[n - i] = respns[m - i];
97 gsl_fft_real_transform(tempfd1, 1, n, real, work);
98 gsl_fft_real_transform(tempfd2, 1, n, real, work);
100 gsl_fft_real_wavetable_free(real);
101 hc = gsl_fft_halfcomplex_wavetable_alloc(n);
104 for (
int i = 1; i < n - 1; i += 2) {
105 double tmp = tempfd1[i];
106 tempfd1[i] = (tempfd1[i] * tempfd2[i] - tempfd1[i + 1] * tempfd2[i + 1]);
107 tempfd1[i + 1] = (tempfd1[i + 1] * tempfd2[i] + tmp * tempfd2[i + 1]);
109 tempfd1[0] *= tempfd2[0];
110 tempfd1[n - 1] *= tempfd2[n - 1];
113 gsl_fft_halfcomplex_inverse(tempfd1, 1, n, hc, work);
115 for (
int i = 0; i <
n; ++i) {
119 gsl_fft_halfcomplex_wavetable_free(hc);
120 gsl_fft_real_workspace_free(work);
126 void ludcmp(std::vector<double> &a, std::vector<int> &indx,
double &d) {
127 const double TINY = 1.0e-20;
128 int i, imax = -1, j, k;
129 double big, dum,
sum, temp;
132 std::vector<double> vv(n, 0.0);
135 for (i = 0; i <
n; ++i) {
137 for (j = 0; j <
n; ++j)
138 if ((temp =
std::abs(a[i * n + j])) > big) big = temp;
141 std::cerr <<
"Singular matrix in routine ludcmp" <<
std::endl;
147 for (j = 0; j <
n; ++j) {
148 for (i = 0; i < j; ++i) {
150 for (k = 0; k < i; ++k)
151 sum -= a[i * n + k] * a[k * n + j];
155 for (i = j; i <
n; ++i) {
157 for (k = 0; k < j; ++k)
158 sum -= a[i * n + k] * a[k * n + j];
160 if ((dum = vv[i] *
std::abs(sum)) >= big) {
167 for (k = 0; k <
n; ++k) {
168 dum = a[imax * n + k];
169 a[imax * n + k] = a[j * n + k];
176 if (a[j * n + j] == 0.0) a[j * n + j] = TINY;
178 dum = 1. / a[j * n + j];
179 for (i = j + 1; i <
n; ++i)
185 void lubksb(std::vector<double> &a, std::vector<int> &indx, std::vector<double> &b) {
186 int i, ii = 0, ip, j;
190 for (i = 0; i <
n; ++i) {
195 for (j = ii - 1; j < i; ++j)
196 sum -= a[i * n + j] * b[j];
201 for (i = n - 1; i >= 0; --i) {
203 for (j = i + 1; j <
n; ++j)
204 sum -= a[i * n + j] * b[j];
205 b[i] = sum / a[i * n + i];
void lubksb(std::vector< double > &a, std::vector< int > &indx, std::vector< double > &b)
constexpr double c
The velocity of light in m/s.
void ludcmp(std::vector< double > &a, std::vector< int > &indx, double &d)
std::vector< double > CoefsDeriv_m
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
void calc_derivative(std::vector< double > &histogram, const double &h)
SavitzkyGolayFilter(int np, int nl, int nr, int m)
void apply(std::vector< double > &histogram)
void convlv(const std::vector< double > &data, const std::vector< double > &respns, const int &isign, std::vector< double > &ans)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or work
void savgol(std::vector< double > &c, const int &np, const int &nl, const int &nr, const int &ld, const int &m)
std::vector< double > Coefs_m
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.