-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnudftd.c
71 lines (55 loc) · 1.25 KB
/
nudftd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdlib.h>
#include <math.h>
#include "nudftd.h"
void nudftd(double *f_re, double *f_im, int N, int n, int d, double *omega, double *alpha_re, double *alpha_im)
{
int j, k, carry;
int *i;
size_t ind;
i = calloc(d, sizeof(int));
ind = 0;
while(1)
{
for(j = 0; j < n; j++)
{
double gamma, co, si;
gamma = 0;
for(k = 0; k < d; k++)
{
gamma += (i[k]-N/2)*omega[k+j*d];
}
gamma = 2*M_PI*gamma/N;
co = cos(gamma);
si = sin(gamma);
if(alpha_im == NULL)
{
f_re[ind] += co*alpha_re[j];
f_im[ind] += si*alpha_re[j];
}
else
{
f_re[ind] += co*alpha_re[j]-si*alpha_im[j];
f_im[ind] += si*alpha_re[j]+co*alpha_im[j];
}
}
carry = 1;
k = 0;
while(carry > 0 && k < d)
{
i[k]++;
carry = 0;
if(i[k] == N)
{
i[k] = 0;
carry = 1;
}
k++;
}
if(carry)
{
break;
}
ind++;
}
free(i);
}