OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RelativeFFTLowPass.cpp
Go to the documentation of this file.
2 #include "Physics/Physics.h"
3 #include "gsl/gsl_fft_real.h"
4 #include "gsl/gsl_fft_halfcomplex.h"
5 
6 using namespace std;
7 
9  threshold_m(threshold)
10 { }
11 
13  const int M = LineDensity.size();
14  double max_four_coef = 0.0;
15 
16  gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
17  gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
18  double *LD = new double[M];
19 
20  for(int i = 0; i < M; ++ i) {
21  LD[i] = LineDensity[i];
22  }
23  gsl_fft_real_transform(LD, 1, M, real, work);
24 
25  gsl_fft_real_wavetable_free(real);
26 
27  for(int i = 0; i < M; ++ i) {
28  if(fabs(LD[i]) > max_four_coef) {
29  max_four_coef = fabs(LD[i]);
30  }
31  }
32  max_four_coef *= threshold_m;
33 
34  for(int i = 0; i < M; ++ i) {
35  if(fabs(LD[i]) < max_four_coef) {
36  LD[i] = 0.0;
37  }
38  }
39 
40  gsl_fft_halfcomplex_wavetable *hc = gsl_fft_halfcomplex_wavetable_alloc(M);
41 
42  gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
43 
44  gsl_fft_halfcomplex_wavetable_free(hc);
45  gsl_fft_real_workspace_free(work);
46 
47  for(int i = 0; i < M; ++ i) {
48  LineDensity[i] = LD[i];
49  }
50 
51  delete[] LD;
52 }
53 
54 void RelativeFFTLowPassFilter::calc_derivative(vector<double> &LineDensity, const double &h) {
55  const int M = LineDensity.size();
56  const double gff = 2.* Physics::pi / (h * (M - 1));
57  double max_four_coef = 0.0;
58  double temp;
59 
60  gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
61  gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
62  double *LD = new double[M];
63 
64  for(int i = 0; i < M; ++ i) {
65  LD[i] = LineDensity[i];
66  }
67  gsl_fft_real_transform(LD, 1, M, real, work);
68 
69  gsl_fft_real_wavetable_free(real);
70 
71  for(int i = 1; i < M; ++ i) {
72  if(fabs(LD[i]) > max_four_coef) {
73  max_four_coef = fabs(LD[i]);
74  }
75  }
76  max_four_coef *= threshold_m;
77 
78  LD[0] = 0.0;
79  for(int i = 1; i < M; i += 2) {
80  temp = LD[i];
81  if(fabs(LD[i+1]) > max_four_coef) {
82  temp = LD[i];
83  LD[i] = -LD[i+1] * gff * (i + 1) / 2;
84  } else {
85  LD[i] = 0.0;
86  }
87  if(fabs(temp) > max_four_coef) {
88  LD[i+1] = temp * gff * (i + 1) / 2;
89  } else {
90  LD[i+1] = 0.0;
91  }
92  }
93 
94  gsl_fft_halfcomplex_wavetable *hc = gsl_fft_halfcomplex_wavetable_alloc(M);
95 
96  gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
97 
98  gsl_fft_halfcomplex_wavetable_free(hc);
99  gsl_fft_real_workspace_free(work);
100 
101  for(int i = 0; i < M; ++ i) {
102  LineDensity[i] = LD[i];
103  }
104 
105  delete[] LD;
106 }
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Definition: PETE.h:815
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
void calc_derivative(std::vector< double > &histogram, const double &h)
constexpr double pi
The value of .
Definition: Physics.h:31
RelativeFFTLowPassFilter(const double &threshold)
void apply(std::vector< double > &LineDensity)