Skip to content

Commit 1a2cd18

Browse files
author
Unknown
committed
Added complex number support to normalization function.
1 parent 5a92d9f commit 1a2cd18

3 files changed

Lines changed: 90 additions & 3 deletions

File tree

rss_ringoccs/diffrec/src/__window_function_normalization.c

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ double Window_Normalization_Long(long *ker, long dim,
111111
}
112112

113113
double Window_Normalization_Long_Long(long long *ker, long dim,
114-
double dx, double f_scale){
115-
114+
double dx, double f_scale)
115+
{
116116
/* Declare variable for indexing. */
117117
long i;
118118

@@ -128,4 +128,59 @@ double Window_Normalization_Long_Long(long long *ker, long dim,
128128
return SQRT_2 * f_scale / T1;
129129
}
130130

131+
float Window_Normalization_Complex_Float(complex float *ker, long dim,
132+
float dx, float f_scale)
133+
{
134+
/* Declare variable for indexing. */
135+
long i;
136+
137+
/* Compute the Free-Space integral. */
138+
complex float T1 = 0.0;
139+
140+
for (i=0; i<dim; ++i){
141+
T1 += ker[i];
142+
}
143+
T1 = cabsf(T1 * dx);
144+
145+
/* Retur the normalization factor. */
146+
return SQRT_2 * f_scale / T1;
147+
}
148+
149+
double Window_Normalization_Complex_Double(complex double *ker, long dim,
150+
double dx, double f_scale)
151+
{
152+
/* Declare variable for indexing. */
153+
long i;
154+
155+
/* Compute the Free-Space integral. */
156+
complex double T1 = 0.0;
157+
158+
for (i=0; i<dim; ++i){
159+
T1 += ker[i];
160+
}
161+
T1 = cabs(T1 * dx);
162+
163+
/* Retur the normalization factor. */
164+
return SQRT_2 * f_scale / T1;
165+
}
166+
167+
long double Window_Normalization_Complex_Long_Double(complex long double *ker,
168+
long dim, long double dx,
169+
long double f_scale)
170+
{
171+
/* Declare variable for indexing. */
172+
long i;
173+
174+
/* Compute the Free-Space integral. */
175+
complex long double T1 = 0.0;
176+
177+
for (i=0; i<dim; ++i){
178+
T1 += ker[i];
179+
}
180+
T1 = cabsl(T1 * dx);
181+
182+
/* Retur the normalization factor. */
183+
return SQRT_2 * f_scale / T1;
184+
}
185+
131186
#endif

rss_ringoccs/diffrec/src/__window_functions.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RSS_RINGOCCS_WINDOW_FUNCTIONS_H
22
#define RSS_RINGOCCS_WINDOW_FUNCTIONS_H
33

4+
#include <complex.h>
45
#include "__math_functions.h"
56

67
/* Kaiser-Bessel function with alpha = 2pi */
@@ -86,6 +87,16 @@ extern double Window_Normalization_Long(long *ker, long dim,
8687
double Window_Normalization_Long_Long(long long *ker, long dim,
8788
double dx, double f_scale);
8889

90+
extern float Window_Normalization_Complex_Float(complex float *ker, long dim,
91+
float dx, float f_scale);
92+
93+
extern double Window_Normalization_Complex_Double(complex double *ker, long dim,
94+
double dx, double f_scale);
95+
96+
extern long double Window_Normalization_Complex_Long_Double(
97+
complex long double *ker, long dim, long double dx, long double f_scale
98+
);
99+
89100
/* Kaiser-Bessel function with arbitrary alpha. */
90101
extern float Kaiser_Bessel_Al_Float(float x, float W, float alpha);
91102

rss_ringoccs/diffrec/src/_window_functions.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,28 @@ static PyObject *window_norm(PyObject *self, PyObject *args){
5151
dim = PyArray_DIMS(arr)[0];
5252
data = PyArray_DATA(arr);
5353

54-
if (typenum == NPY_FLOAT){
54+
if (typenum == NPY_CFLOAT){
55+
return PyFloat_FromDouble(
56+
Window_Normalization_Complex_Float(
57+
(complex float *)data, dim, dx, f_scale
58+
)
59+
);
60+
}
61+
else if (typenum == NPY_CDOUBLE){
62+
return PyFloat_FromDouble(
63+
Window_Normalization_Complex_Double(
64+
(complex double *)data, dim, dx, f_scale
65+
)
66+
);
67+
}
68+
else if (typenum == NPY_CLONGDOUBLE){
69+
return PyFloat_FromDouble(
70+
Window_Normalization_Complex_Long_Double(
71+
(complex long double *)data, dim, dx, f_scale
72+
)
73+
);
74+
}
75+
else if (typenum == NPY_FLOAT){
5576
return PyFloat_FromDouble(
5677
Window_Normalization_Float((float *)data, dim, dx, f_scale)
5778
);

0 commit comments

Comments
 (0)