-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiraconfig.py
More file actions
executable file
·159 lines (127 loc) · 3.52 KB
/
iraconfig.py
File metadata and controls
executable file
·159 lines (127 loc) · 3.52 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#
# Configuration management for IRA
#
# Marcus Leech, Science Radio Laboratories, Inc.
#
import os
import numpy
import math
import sys
def compute_notches(notchlist,flen,bw,freq,dm):
tmptaps = numpy.zeros(flen, dtype=numpy.complex)
binwidth = bw / flen
for i in range(0,flen):
tmptaps[i] = complex(1.0,0.0)
added=0
#
# Compute a multi-bin notch filter (a comb filter)
# based on the input notch list
#
for i in notchlist:
diff = i - freq
if int(i) <= 0:
break
if ((i < (freq - bw/2)) or (i > (freq + bw/2))):
continue
idx = diff/binwidth
idx = round(idx)
if (idx < 0):
idx = -1 * idx
idx = ((flen)-1) - idx
while (idx < 0):
idx = idx + 1
tmptaps[int(idx)] = complex(0.0, 0.0)
added = added + 1
if (added <= 0):
tmptaps = [complex(1.0,0.0),complex(1.0,0.0),complex(1.0,0.0)]
return (numpy.fft.ifft(tmptaps))
#
# Compute a de-dispersion filter
# From Hankins, et al, 1975
#
# This code translated from dedisp_filter.c from Swinburne
# pulsar software repository
#
def compute_dispfilter(dm,doppler,bw,centerfreq):
npts = compute_disp_ntaps(dm,bw,centerfreq)
tmp = numpy.zeros(npts, dtype=numpy.complex)
M_PI = 3.14159265358
DM = dm/2.41e-10
#
# Because astronomers are a crazy bunch, the "standard" calculation
# is in Mhz, rather than Hz
#
centerfreq = centerfreq / 1.0e6
bw = bw / 1.0e6
isign = int(bw / abs (bw))
# Center frequency may be doppler shifted
cfreq = centerfreq / doppler
# As well as the bandwidth..
bandwidth = bw / doppler
# Bandwidth divided among bins
binwidth = bandwidth / npts
# Delay is an "extra" parameter, in usecs, and largely
# untested in the Swinburne code.
delay = 0.0
# This determines the coefficient of the frequency response curve
# Linear in DM, but quadratic in center frequency
coeff = isign * 2.0*M_PI * DM / (cfreq*cfreq)
# DC to nyquist/2
n = 0
for i in range(0,int(npts/2)):
freq = (n + 0.5) * binwidth
phi = coeff*freq*freq/(cfreq+freq) + (2.0*M_PI*freq*delay)
tmp[i] = complex(math.cos(phi), math.sin(phi))
n += 1
# -nyquist/2 to DC
n = int(npts/2)
n *= -1
for i in range(int(npts/2),npts):
freq = (n + 0.5) * binwidth
phi = coeff*freq*freq/(cfreq+freq) + (2.0*M_PI*freq*delay)
tmp[i] = complex(math.cos(phi), math.sin(phi))
n += 1
return(numpy.fft.ifft(tmp))
#
# Compute minimum number of taps required in de-dispersion FFT filter
#
def compute_disp_ntaps(dm,bw,freq):
NTLIMIT=65536*2
#
# Dt calculations are in Mhz, rather than Hz
# crazy astronomers....
mbw = bw/1.0e6
mfreq = freq/1.0e6
f_lower = mfreq-(mbw/2)
f_upper = mfreq+(mbw/2)
# Compute smear time
Dt = dm/2.41e-4 * (1.0/(f_lower*f_lower)-1.0/(f_upper*f_upper))
# ntaps is now bandwidth*smeartime
ntaps = bw*Dt
if (ntaps < 32):
ntaps = 32
# special "flag" from command-line invoker to get around a bug
# in Gnu Radio involving the FFT filter implementation
# we can *never* increase the size of an FFT filter at runtime
# but can decrease it. So there's a special "startup" flag (dm=1500.0)
# that causes us to return the NTLIMIT number of taps
#
if (dm >= 1500.0):
ntaps = NTLIMIT
if (ntaps > NTLIMIT):
ntaps = NTLIMIT
ntaps = int(math.log(ntaps) / math.log(2))
ntaps = int(math.pow(2,ntaps+1))
return(int(ntaps))
def writepid():
f=open("receiver.pid","w")
pid=os.getpid()
f.write(str(pid)+"\n")
f.close()
return(pid)
def writevars(varnames,vars):
f=open("variables.dump","w")
for i in range(0,len(varnames)):
f.write(varnames[i]+"="+str(float(vars[i]))+"\n")
f.close()
return 1