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) {
32void 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);
74void 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);
126void 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];
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)
185void 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 convlv(const std::vector< double > &data, const std::vector< double > &respns, const int &isign, std::vector< double > &ans)
void ludcmp(std::vector< double > &a, std::vector< int > &indx, double &d)
void lubksb(std::vector< double > &a, std::vector< int > &indx, std::vector< double > &b)
void savgol(std::vector< double > &c, const int &np, const int &nl, const int &nr, const int &ld, const int &m)
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
constexpr double c
The velocity of light in m/s.
void apply(std::vector< double > &histogram)
std::vector< double > Coefs_m
std::vector< double > CoefsDeriv_m
SavitzkyGolayFilter(int np, int nl, int nr, int m)
void calc_derivative(std::vector< double > &histogram, const double &h)