OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FixedFFTLowPass.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  number_frequencies_m(N)
10 { }
11 
13  const int M = LineDensity.size();
14  gsl_fft_halfcomplex_wavetable *hc;
15  gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
16  gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
17  double *LD = new double[M];
18  for(int i = 0; i < M; ++ i) {
19  LD[i] = LineDensity[i];
20  }
21  gsl_fft_real_transform(LD, 1, M, real, work);
22 
23  for(int i = 2 * number_frequencies_m + 1; i < M; ++ i) {
24  LD[i] = 0.0;
25  }
26 
27  gsl_fft_real_wavetable_free(real);
28  hc = gsl_fft_halfcomplex_wavetable_alloc(M);
29 
30  gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
31 
32  gsl_fft_halfcomplex_wavetable_free(hc);
33  gsl_fft_real_workspace_free(work);
34 
35  for(int i = 0; i < M; ++ i) {
36  LineDensity[i] = LD[i];
37  }
38  delete[] LD;
39 }
40 
41 void FixedFFTLowPassFilter::calc_derivative(vector<double> &LineDensity, const double &h) {
42  const int M = LineDensity.size();
43  const double gff = 2. * Physics::pi / (h * (M - 1));
44  double temp;
45 
46  gsl_fft_halfcomplex_wavetable *hc;
47  gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
48  gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
49  double *LD = new double[M];
50 
51  for(int i = 0; i < M; ++ i) {
52  LD[i] = LineDensity[i];
53  }
54  gsl_fft_real_transform(LD, 1, M, real, work);
55 
56  gsl_fft_real_wavetable_free(real);
57 
58  LD[0] = 0.0;
59  for(int i = 1; i < 2 * number_frequencies_m + 1; i += 2) {
60  temp = LD[i];
61  LD[i] = -LD[i+1] * gff * (i + 1) / 2;
62  LD[i+1] = temp * gff * (i + 1) / 2;
63  }
64 
65  for(int i = 2 * number_frequencies_m + 1; i < M; ++ i) {
66  LD[i] = 0.0;
67  }
68 
69  hc = gsl_fft_halfcomplex_wavetable_alloc(M);
70 
71  gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
72 
73  gsl_fft_halfcomplex_wavetable_free(hc);
74  gsl_fft_real_workspace_free(work);
75 
76  for(int i = 0; i < M; ++ i) {
77  LineDensity[i] = LD[i];
78  }
79 
80  delete[] LD;
81 }
82 
FixedFFTLowPassFilter(const int &N)
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
constexpr double pi
The value of .
Definition: Physics.h:31
void apply(std::vector< double > &LineDensity)
void calc_derivative(std::vector< double > &histogram, const double &h)