OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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#include <cmath>
7
9 threshold_m(threshold)
10{ }
11
12void RelativeFFTLowPassFilter::apply(std::vector<double> &LineDensity) {
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 (std::abs(LD[i]) > max_four_coef) {
29 max_four_coef = std::abs(LD[i]);
30 }
31 }
32 max_four_coef *= threshold_m;
33
34 for (int i = 0; i < M; ++ i) {
35 if (std::abs(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
54void RelativeFFTLowPassFilter::calc_derivative(std::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
59 gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
60 gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
61 double *LD = new double[M];
62
63 for (int i = 0; i < M; ++ i) {
64 LD[i] = LineDensity[i];
65 }
66 gsl_fft_real_transform(LD, 1, M, real, work);
67
68 gsl_fft_real_wavetable_free(real);
69
70 for (int i = 1; i < M; ++ i) {
71 if (std::abs(LD[i]) > max_four_coef) {
72 max_four_coef = std::abs(LD[i]);
73 }
74 }
75 max_four_coef *= threshold_m;
76
77 LD[0] = 0.0;
78 for (int i = 1; i < M; i += 2) {
79 double temp = LD[i];
80 if (std::abs(LD[i+1]) > max_four_coef) {
81 temp = LD[i];
82 LD[i] = -LD[i+1] * gff * (i + 1) / 2;
83 } else {
84 LD[i] = 0.0;
85 }
86 if (std::abs(temp) > max_four_coef) {
87 LD[i+1] = temp * gff * (i + 1) / 2;
88 } else {
89 LD[i+1] = 0.0;
90 }
91 }
92
93 gsl_fft_halfcomplex_wavetable *hc = gsl_fft_halfcomplex_wavetable_alloc(M);
94
95 gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
96
97 gsl_fft_halfcomplex_wavetable_free(hc);
98 gsl_fft_real_workspace_free(work);
99
100 for (int i = 0; i < M; ++ i) {
101 LineDensity[i] = LD[i];
102 }
103
104 delete[] LD;
105}
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double pi
The value of.
Definition: Physics.h:30
RelativeFFTLowPassFilter(const double &threshold)
void calc_derivative(std::vector< double > &histogram, const double &h)
void apply(std::vector< double > &LineDensity)