RISA
cuda_kernels_filter.h
Go to the documentation of this file.
1 /*
2  * This file is part of the RISA-library.
3  *
4  * Copyright (C) 2016 Helmholtz-Zentrum Dresden-Rossendorf
5  *
6  * RISA is free software: You can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RISA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RISA. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Date: 30 November 2016
20  * Authors: Tobias Frust (FWCC) <t.frust@hzdr.de>
21  *
22  */
23 
24 #ifndef CUDA_KERNELS_FILTER_H_
25 #define CUDA_KERNELS_FILTER_H_
26 
27 #define _USE_MATH_DEFINES
28 #include <cmath>
29 
30 namespace risa {
31 namespace cuda {
32 
33 __global__ void filterSL(int x, int y, cufftComplex *data) {
34  int j = blockIdx.y * blockDim.y + threadIdx.y;
35  int i = blockIdx.x * blockDim.x + threadIdx.x;
36  if (i < x && j < y) {
37  const float w = (float) i / (float) (x - 1) * M_PI;
38  const float divisor = 2.0 * (x - 1);
39  float temp;
40  if (i == 0)
41  temp = 0.0;
42  else
43  temp = w * fabsf(sinf(w) / (M_PI * w));
44  data[i + j * x].x *= temp / divisor;
45  data[i + j * x].y *= temp / divisor;
46  }
47 }
48 
49 __global__ void filterRamp(int x, int y, cufftComplex *data) {
50  int j = blockIdx.y * blockDim.y + threadIdx.y;
51  int i = blockIdx.x * blockDim.x + threadIdx.x;
52  if (i < x && j < y) {
53  //Rampenfilter
54  const float divisor = 2 * (x - 1);
55  data[i + j * x].x *= (float) i / (x - 1) * M_PI / divisor;
56  data[i + j * x].y *= (float) i / (x - 1) * M_PI / divisor;
57  }
58 }
59 
60 __global__ void filterHamming(int x, int y, cufftComplex *data) {
61  int j = blockIdx.y * blockDim.y + threadIdx.y;
62  int i = blockIdx.x * blockDim.x + threadIdx.x;
63  if (i < x && j < y) {
64  float temp;
65  const float divisor = 2 * (x - 1);
66  const float w = (float) i / (x - 1) * M_PI;
67  if (i == 0)
68  temp = 0.0;
69  else
70  temp = w * (0.54 + 0.46 * cosf(w));
71  data[i + j * x].x *= temp / divisor;
72  data[i + j * x].y *= temp / divisor;
73  }
74 }
75 
76 __global__ void filterHanning(int x, int y, cufftComplex *data) {
77  int j = blockIdx.y * blockDim.y + threadIdx.y;
78  int i = blockIdx.x * blockDim.x + threadIdx.x;
79  if (i < x && j < y) {
80  float temp;
81  const float divisor = 2 * (x - 1);
82  const float w = (float) i / (x - 1) * M_PI;
83  if (i == 0)
84  temp = 0.0;
85  else
86  temp = w * (0.5 + 0.5 * cosf(w));
87  data[i + j * x].x *= temp / divisor;
88  data[i + j * x].y *= temp / divisor;
89  }
90 }
91 
93 
99 template <typename T>
100 auto inline sheppLogan(const T w, const T d) -> T {
101  const T ret = std::sin(w/(2.0*d))/(w/(2.0*d));
102  return ret;
103 }
104 
106 
112 template <typename T>
113 auto inline cosine(const T w, const T d) -> T {
114  const T ret = std::cos(w/(2.0*d));
115  return ret;
116 }
117 
119 
125 template <typename T>
126 auto inline hamming(const T w, const T d) -> T {
127  const T ret = 0.54 + 0.46 * std::cos(w/d);
128  return ret;
129 }
130 
132 
138 template <typename T>
139 auto inline hanning(const T w, const T d) -> T {
140  const T ret = (1 + std::cos(w/d))/ 2.;
141  return ret;
142 }
143 
144 }
145 }
146 
147 #endif /* CUDA_KERNELS_FILTER_H */
auto cosine(const T w, const T d) -> T
computes the value of the Cosine-filter function
__global__ void filterHanning(int x, int y, cufftComplex *data)
auto sheppLogan(const T w, const T d) -> T
computes the value of the Shepp-Logan-filter function
__global__ void filterRamp(int x, int y, cufftComplex *data)
auto hanning(const T w, const T d) -> T
computes the value of the Hanning-filter function
__global__ void filterHamming(int x, int y, cufftComplex *data)
__global__ void filterSL(int x, int y, cufftComplex *data)
auto hamming(const T w, const T d) -> T
computes the value of the Hamming-filter function