forked from SixByNine/sigproc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcprofc.c
49 lines (36 loc) · 979 Bytes
/
cprofc.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
#include <math.h>
#define NBINMAX 8192
void cprofc(float *prof, int nbins, float *amp, float *pha)
{
int i,nh,n2;
int forward = 1, back = -1, real = 1, complex = 0;
float temp[NBINMAX][2];
nh = nbins/2;
n2 = nbins*2;
for(i=0;i<nh;i++) {
temp[i][0] = prof[2*i];
temp[i][1] = prof[2*i+1];
temp[nh+i][0] = 0.;
temp[nh+i][1] = 0.;
}
ffft_(&temp[0][0],&nbins,&forward,&real);
for(i=0;i<nh+1;i++) {
amp[i] = sqrt(temp[i][0]*temp[i][0] + temp[i][1]*temp[i][1]);
pha[i] = 0.;
if(amp[i] > 0.)
pha[i] = atan2(temp[i][1],temp[i][0]);
}
}
void uncprofc(float *amp, float *pha, int nbins, float *c)
{
int i,nh;
nh = nbins/2;
for(i=0;i<nh;i++) {
c[2*i] = amp[i]*cos((double)pha[i]);
c[2*i+1] = amp[i]*sin((double)pha[i]);
}
for(i=1;i<nh+1;i++) { /* Important to set Nyquist component!!! */
c[2*nbins-2*i] = amp[i]*cos((double)pha[i]);
c[2*nbins-2*i+1] = -amp[i]*sin((double)pha[i]);
}
}