-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ground_Receiver.py
441 lines (375 loc) · 18.4 KB
/
Ground_Receiver.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block
# Generated: Wed Dec 7 14:35:35 2016
##################################################
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from PyQt4 import Qt
from gnuradio import analog
from gnuradio import blocks
from gnuradio import digital
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio import qtgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import numpy as np
import osmosdr
import sip
import sys
import time
class top_block(gr.top_block, Qt.QWidget):
def __init__(self, rate=2e6, samps_per_sym=4):
gr.top_block.__init__(self, "Top Block")
Qt.QWidget.__init__(self)
self.setWindowTitle("Top Block")
try:
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
except:
pass
self.top_scroll_layout = Qt.QVBoxLayout()
self.setLayout(self.top_scroll_layout)
self.top_scroll = Qt.QScrollArea()
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
self.top_scroll_layout.addWidget(self.top_scroll)
self.top_scroll.setWidgetResizable(True)
self.top_widget = Qt.QWidget()
self.top_scroll.setWidget(self.top_widget)
self.top_layout = Qt.QVBoxLayout(self.top_widget)
self.top_grid_layout = Qt.QGridLayout()
self.top_layout.addLayout(self.top_grid_layout)
self.settings = Qt.QSettings("GNU Radio", "top_block")
self.restoreGeometry(self.settings.value("geometry").toByteArray())
##################################################
# Parameters
##################################################
self.rate = rate
self.samps_per_sym = samps_per_sym
##################################################
# Variables
##################################################
self.nfilts = nfilts = 32
self.excess_bw = excess_bw = 0.2
self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(samps_per_sym), excess_bw, 5*samps_per_sym*nfilts)
self.samp_rate = samp_rate = rate
self.pulse_shaping_taps = pulse_shaping_taps = np.convolve(np.array((1,)*samps_per_sym), np.array(rrc_taps))
self.bt = bt = 0.5
self.samp_rate_0 = samp_rate_0 = rate
self.matched_filter_0 = matched_filter_0 = pulse_shaping_taps
self.matched_filter = matched_filter = pulse_shaping_taps
self.gaussian_taps = gaussian_taps = firdes.gaussian(1, samps_per_sym, bt, 1)
self.freq_offset = freq_offset = 0
self.firdes_tap = firdes_tap = firdes.low_pass(1, samp_rate, 15000, 50000, firdes.WIN_BLACKMAN, 6.76)
self.BPSK = BPSK = digital.constellation_calcdist(([-1, 1]), ([0, 1]), 4, 1).base()
##################################################
# Blocks
##################################################
self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
self.rtlsdr_source_0.set_sample_rate(rate/2)
self.rtlsdr_source_0.set_center_freq(904958600, 0)
self.rtlsdr_source_0.set_freq_corr(0, 0)
self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
self.rtlsdr_source_0.set_gain_mode(True, 0)
self.rtlsdr_source_0.set_gain(40, 0)
self.rtlsdr_source_0.set_if_gain(40, 0)
self.rtlsdr_source_0.set_bb_gain(40, 0)
self.rtlsdr_source_0.set_antenna('', 0)
self.rtlsdr_source_0.set_bandwidth(1e6, 0)
self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
1024, #size
firdes.WIN_BLACKMAN_hARRIS, #wintype
905e6, #fc
samp_rate, #bw
"", #name
1 #number of inputs
)
self.qtgui_freq_sink_x_0_0.set_update_time(0.10)
self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10)
self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB')
self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
self.qtgui_freq_sink_x_0_0.enable_grid(False)
self.qtgui_freq_sink_x_0_0.set_fft_average(1.0)
self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
self.qtgui_freq_sink_x_0_0.enable_control_panel(False)
if not True:
self.qtgui_freq_sink_x_0_0.disable_legend()
if "complex" == "float" or "complex" == "msg_float":
self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True)
labels = ['', '', '', '', '',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["blue", "red", "green", "black", "cyan",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in xrange(1):
if len(labels[i]) == 0:
self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i])
self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i])
self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i])
self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i])
self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_freq_sink_x_0_0_win)
self.qtgui_const_sink_x_0_0_0 = qtgui.const_sink_c(
1024, #size
"CMA Constellation", #name
1 #number of inputs
)
self.qtgui_const_sink_x_0_0_0.set_update_time(0.10)
self.qtgui_const_sink_x_0_0_0.set_y_axis(-2, 2)
self.qtgui_const_sink_x_0_0_0.set_x_axis(-2, 2)
self.qtgui_const_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
self.qtgui_const_sink_x_0_0_0.enable_autoscale(False)
self.qtgui_const_sink_x_0_0_0.enable_grid(True)
self.qtgui_const_sink_x_0_0_0.enable_axis_labels(True)
if not True:
self.qtgui_const_sink_x_0_0_0.disable_legend()
labels = ['', '', '', '', '',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["blue", "red", "red", "red", "red",
"red", "red", "red", "red", "red"]
styles = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
markers = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in xrange(1):
if len(labels[i]) == 0:
self.qtgui_const_sink_x_0_0_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_const_sink_x_0_0_0.set_line_label(i, labels[i])
self.qtgui_const_sink_x_0_0_0.set_line_width(i, widths[i])
self.qtgui_const_sink_x_0_0_0.set_line_color(i, colors[i])
self.qtgui_const_sink_x_0_0_0.set_line_style(i, styles[i])
self.qtgui_const_sink_x_0_0_0.set_line_marker(i, markers[i])
self.qtgui_const_sink_x_0_0_0.set_line_alpha(i, alphas[i])
self._qtgui_const_sink_x_0_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0_0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_0_win)
self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c(
1024, #size
"CMA Constellation", #name
1 #number of inputs
)
self.qtgui_const_sink_x_0_0.set_update_time(0.10)
self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2)
self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2)
self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
self.qtgui_const_sink_x_0_0.enable_autoscale(False)
self.qtgui_const_sink_x_0_0.enable_grid(True)
self.qtgui_const_sink_x_0_0.enable_axis_labels(True)
if not True:
self.qtgui_const_sink_x_0_0.disable_legend()
labels = ['', '', '', '', '',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["blue", "red", "red", "red", "red",
"red", "red", "red", "red", "red"]
styles = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
markers = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in xrange(1):
if len(labels[i]) == 0:
self.qtgui_const_sink_x_0_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i])
self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i])
self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i])
self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i])
self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i])
self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i])
self._qtgui_const_sink_x_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_win)
self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
1024, #size
"Costas Constellation", #name
1 #number of inputs
)
self.qtgui_const_sink_x_0.set_update_time(0.10)
self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
self.qtgui_const_sink_x_0.enable_autoscale(False)
self.qtgui_const_sink_x_0.enable_grid(True)
self.qtgui_const_sink_x_0.enable_axis_labels(True)
if not True:
self.qtgui_const_sink_x_0.disable_legend()
labels = ['', '', '', '', '',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["blue", "red", "red", "red", "red",
"red", "red", "red", "red", "red"]
styles = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
markers = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in xrange(1):
if len(labels[i]) == 0:
self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])
self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_const_sink_x_0_win)
self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (1, ), 905e6, samp_rate)
self.digital_pfb_clock_sync_xxx_0_0 = digital.pfb_clock_sync_ccf(samps_per_sym, 2*3.14/100.0, (rrc_taps), nfilts, nfilts/2, 1.5, 1)
self.digital_map_bb_0 = digital.map_bb(([0,1]))
self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
self.digital_costas_loop_cc_0 = digital.costas_loop_cc(2*3.14/100.0, 2, False)
self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(BPSK)
self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(7, 1, 0.01, samps_per_sym/2)
self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, 'C:\\Users\\kylepiette\\Desktop\\Results.bin', False)
self.blocks_file_sink_0.set_unbuffered(False)
self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
self.analog_agc_xx_0.set_max_gain(65536)
##################################################
# Connections
##################################################
self.connect((self.analog_agc_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0))
self.connect((self.digital_cma_equalizer_cc_0, 0), (self.qtgui_const_sink_x_0_0, 0))
self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0))
self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0))
self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0))
self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_map_bb_0, 0))
self.connect((self.digital_map_bb_0, 0), (self.blocks_file_sink_0, 0))
self.connect((self.digital_pfb_clock_sync_xxx_0_0, 0), (self.digital_cma_equalizer_cc_0, 0))
self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.digital_pfb_clock_sync_xxx_0_0, 0))
self.connect((self.rtlsdr_source_0, 0), (self.analog_agc_xx_0, 0))
self.connect((self.rtlsdr_source_0, 0), (self.qtgui_freq_sink_x_0_0, 0))
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "top_block")
self.settings.setValue("geometry", self.saveGeometry())
event.accept()
def get_rate(self):
return self.rate
def set_rate(self, rate):
self.rate = rate
self.set_samp_rate(self.rate)
self.set_samp_rate_0(self.rate)
self.rtlsdr_source_0.set_sample_rate(self.rate/2)
def get_samps_per_sym(self):
return self.samps_per_sym
def set_samps_per_sym(self, samps_per_sym):
self.samps_per_sym = samps_per_sym
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.samps_per_sym), self.excess_bw, 5*self.samps_per_sym*self.nfilts))
self.set_pulse_shaping_taps(np.convolve(np.array((1,)*self.samps_per_sym), np.array(self.rrc_taps)))
self.set_gaussian_taps(firdes.gaussian(1, self.samps_per_sym, self.bt, 1))
def get_nfilts(self):
return self.nfilts
def set_nfilts(self, nfilts):
self.nfilts = nfilts
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.samps_per_sym), self.excess_bw, 5*self.samps_per_sym*self.nfilts))
def get_excess_bw(self):
return self.excess_bw
def set_excess_bw(self, excess_bw):
self.excess_bw = excess_bw
self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0/float(self.samps_per_sym), self.excess_bw, 5*self.samps_per_sym*self.nfilts))
def get_rrc_taps(self):
return self.rrc_taps
def set_rrc_taps(self, rrc_taps):
self.rrc_taps = rrc_taps
self.set_pulse_shaping_taps(np.convolve(np.array((1,)*self.samps_per_sym), np.array(self.rrc_taps)))
self.digital_pfb_clock_sync_xxx_0_0.update_taps((self.rrc_taps))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.qtgui_freq_sink_x_0_0.set_frequency_range(905e6, self.samp_rate)
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, 15000, 50000, firdes.WIN_BLACKMAN, 6.76))
def get_pulse_shaping_taps(self):
return self.pulse_shaping_taps
def set_pulse_shaping_taps(self, pulse_shaping_taps):
self.pulse_shaping_taps = pulse_shaping_taps
self.set_matched_filter_0(self.pulse_shaping_taps)
self.set_matched_filter(self.pulse_shaping_taps)
def get_bt(self):
return self.bt
def set_bt(self, bt):
self.bt = bt
self.set_gaussian_taps(firdes.gaussian(1, self.samps_per_sym, self.bt, 1))
def get_samp_rate_0(self):
return self.samp_rate_0
def set_samp_rate_0(self, samp_rate_0):
self.samp_rate_0 = samp_rate_0
def get_matched_filter_0(self):
return self.matched_filter_0
def set_matched_filter_0(self, matched_filter_0):
self.matched_filter_0 = matched_filter_0
def get_matched_filter(self):
return self.matched_filter
def set_matched_filter(self, matched_filter):
self.matched_filter = matched_filter
def get_gaussian_taps(self):
return self.gaussian_taps
def set_gaussian_taps(self, gaussian_taps):
self.gaussian_taps = gaussian_taps
def get_freq_offset(self):
return self.freq_offset
def set_freq_offset(self, freq_offset):
self.freq_offset = freq_offset
def get_firdes_tap(self):
return self.firdes_tap
def set_firdes_tap(self, firdes_tap):
self.firdes_tap = firdes_tap
def get_BPSK(self):
return self.BPSK
def set_BPSK(self, BPSK):
self.BPSK = BPSK
def argument_parser():
parser = OptionParser(usage="%prog: [options]", option_class=eng_option)
parser.add_option(
"-r", "--rate", dest="rate", type="eng_float", default=eng_notation.num_to_str(2e6),
help="Set Sample rate [default=%default]")
parser.add_option(
"-s", "--samps-per-sym", dest="samps_per_sym", type="intx", default=4,
help="Set Samples/symbol [default=%default]")
return parser
def main(top_block_cls=top_block, options=None):
if options is None:
options, _ = argument_parser().parse_args()
from distutils.version import StrictVersion
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls(rate=options.rate, samps_per_sym=options.samps_per_sym)
tb.start()
tb.show()
def quitting():
tb.stop()
tb.wait()
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.exec_()
if __name__ == '__main__':
main()