def test_001(self): """ Test the energy of a simple sequence (1, 2, -1, -2). """ # input and expected results src_data = (1, 1, 1, 1) expected_result = 1 # blocks fft_size = len(src_data) mavg_size = 1 src = blocks.vector_source_c(data=src_data) dst = blocks.probe_signal_f() ed = EnergySSArch(fft_size, mavg_size, EnergyDecision(1)) #radio_device = RadioDevice(the_source = src, the_sink = dst) radio_device = RadioDevice() radio_device.add_arch(source=src, arch=ed, sink=dst, uhd_device=None, name='ed') ################ FIM NOVO RADIO DEVICE ## flowgraph ##self.tb.add_arch(ed, radio_device, 'ed') self.tb.add_radio(radio_device) self.tb.run() result_data = dst.level() self.assertEqual(expected_result, result_data)
def test_004(self): """ Test EDTopBlock with a simple input (1, 2, 3, 4). """ arr = (1.0, 2.0, 3.0, 4.0) expected_result = 30 # before expected result was 2536 ed = EnergySSArch(fft_size=len(arr), mavg_size=1, algorithm=EnergyDecision(expected_result + 1) # (expected_out + 1) ) src = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed') self.tb.add_radio(device, 'ed') self.tb.start() self.tb.wait() ###self.assertEqual(expected_result , device.sink.output()[1]) self.assertEqual(expected_result, device.ed.output()[1]) # uses 'name' parameter of the add_arch method
def __init__(self): 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()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.center_freq = center_freq = 0 ################################################## # Blocks ################################################## self.freq_sweep_probe = blocks.probe_signal_f() def _center_freq_probe(): while True: val = self.freq_sweep_probe.level() try: self.set_center_freq(val) except AttributeError: pass time.sleep(1.0 / (10)) _center_freq_thread = threading.Thread(target=_center_freq_probe) _center_freq_thread.daemon = True _center_freq_thread.start() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_int*1, samp_rate,True) self.blocks_int_to_float_1 = blocks.int_to_float(1, 1) self.audio_sink_0 = audio.sink(samp_rate, "", True) self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, center_freq*300+300, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_i(samp_rate, analog.GR_SAW_WAVE, 0.1, 3, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_int_to_float_1, 0), (self.freq_sweep_probe, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_int_to_float_1, 0))
def test_001(self): """ Test RadioDevice instantiation. """ source = blocks.vector_source_c([1] * 8) sync = blocks.probe_signal_f() dev = RadioDevice() dev.add_arch(source=source, arch=None, sink=sync, uhd_device=None, name='None')
def __init__(self): gr.top_block.__init__(self, "Tutorial Two 4") Qt.QWidget.__init__(self) self.setWindowTitle("Tutorial Two 4") 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", "tutorial_two_4") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.blocks_probe_signal_x_0 = blocks.probe_signal_f() def _variable_function_probe_0_probe(): while True: val = self.blocks_probe_signal_x_0.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_probe_signal_x_0, 0))
def main(): global radio_obj, sig_probe radio_obj = radio( 0 ) sig_probe = blocks.probe_signal_f() radio_obj.block.connect(radio_obj.block.agc.offs, sig_probe) thread2 = Thread( target = rssi_function ) thread2.start() radio_obj.MainLoop()
def test_001(self): value = 12.3 repeats = 100 src_data = [value] * repeats src = blocks.vector_source_f(src_data) dst = blocks.probe_signal_f() self.tb.connect(src, dst) self.tb.run() output = dst.level() self.assertAlmostEqual(value, output, places=6)
def test_003(self): """ Test a more elaborate scenario with feedback. In this test the FeedbackTopBlock is utilized with n waveform algorithm as manager, an energy and a feedback algorithm. """ return """ ::TODO:: Update this test. """ # Random 'signal' utilized in the test arr = [random.random() for i in xrange(1024)] fft_size = 1024 # Bayes learning parameters in_th = 1 min_th = 0.001 max_th = 20 delta_th = 0.001 k = 1 # Feeback architecture bl_algo = BayesLearningThreshold(in_th=in_th, min_th=min_th, max_th=max_th, delta_th=delta_th, k=k) # detectors utilized bl = EnergyDetectorC(fft_size, 1, bl_algo) ev = WaveformSSArch(fft_size, WaveformDecision(0.7)) # top block t = FeedbackSSArch(block_manager=ev, block_learner=bl, feedback_algorithm=FeedbackAlgorithm(bl_algo, AlwaysTimeFeedback()) ### learner, manager, a_feedback_strategy ) source = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=source, arch=t, sink=sink, uhd_device=None, name='ss_arch') self.tb.add_path(t, device, 'ss') self.tb.run() # As the waveform will (probably) not detected the channel as occupied, the feedback system should decrease the threshold by 1 self.assertEqual(0, bl_algo.feedback)
def build_us_block(options): """ Builds the US top block. The RX path performs the ED sensing The TX path transmits a BER @param options """ # TOP BLOCK tb = OpERAFlow(name='US') # RX PATH if not options.tx_only: uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = 195512 the_source = uhd_source the_sink = blocks.probe_signal_f() rx_path = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=0.000005) ) device_source = RadioDevice() device_source.add_arch(source=the_source, arch=rx_path, sink=the_sink, uhd_device=None, name="source") ###tb.add_arch( abstract_arch = rx_path, radio_device = device_source, name_of_arch = 'rx') tb.ad_radio(device_source, 'rx') # TX PATH tx_path = PacketGMSKTx(name='a') Logger.add_to_print_list("a_bit_rate", 'bps') uhd_sink = UHDSink(device_addr = options.args) uhd_sink.samp_rate = options.samp_rate the_source = None the_sink = uhd_sink uhd_device = uhd_sink radio_sink = RadioDevice() #::TODO:: conferir se arch é mesmo tx_path, e fazer essa verificacao do tx_path e rx_path para todos os outros arquivos radio_sink.add_arch(source=the_source, arch=tx_path, sink=the_sink, uhd_device=uhd_device, name="sink") ###tb.add_arch( tx_path, radio_sink, 'tx', connection_type = OpERAFlow.CONN_SINK) tb.add_radio(radio_sink, 'tx') return tb
def set_window_and_reconnect(self, window): ''' Must be called while the flowgraph is locked already. ''' window = int(window) self.disconnect_all() self.__sink = blocks.probe_signal_f() self.connect( self, blocks.complex_to_mag_squared(), blocks.stream_to_vector(itemsize=gr.sizeof_float, nitems_per_block=window), blocks.max_ff(window), self.__sink) # shortcut method implementation self.level = self.__sink.level
def set_window_and_reconnect(self, window): ''' Must be called while the flowgraph is locked already. ''' # Use a power-of-2 window size to satisfy gnuradio allocation alignment without going overboard. window = int(2 ** math.floor(math.log(window, 2))) self.disconnect_all() self.__sink = blocks.probe_signal_f() self.connect( self, blocks.complex_to_mag_squared(), blocks.stream_to_vector(itemsize=gr.sizeof_float, nitems_per_block=window), blocks.max_ff(window), self.__sink) # shortcut method implementation self.level = self.__sink.level
def build_radio(options): """ @param options """ radio = RadioDevice(name='radio') ############################# # # RX PATH - sensing and packet # ############################# ss_and_rx_source = UHDSource("addr=%s" % options.my_ip) ss_sink = blocks.probe_signal_f() ss_path = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=5.0/10**4)) radio.add_arch(source=ss_and_rx_source, sink=ss_sink, arch=ss_path, name='ss', uhd_device=ss_and_rx_source) pkt_rx_path = PacketGMSKRx(callback=PktQueue()) radio.add_arch(source=ss_and_rx_source, sink=None, arch=pkt_rx_path, name='rx', uhd_device=ss_and_rx_source) ############################# # # TX PATH - packet # ############################# uhd_sink = UHDSink("addr=%s" % options.my_ip) pkt_tx_path = PacketGMSKTx() radio.add_arch(source=None, sink=uhd_sink, arch=pkt_tx_path, name='tx', uhd_device=uhd_sink) radio.set_samp_rate(200e3) return radio
def build_us_block(options): """ Builds the US top block. The RX path performs the ED sensing. The TX path transmits a BER. @param options """ # TOP BLOCK tb = OpERAFlow(name='US') # RX PATH uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = 195512 #::TODO:: nova versao do radiodevice --> atualizar the_source = uhd_source the_sink = blocks.probe_signal_f() ###device_source = RadioDevice(the_source = uhd_source, the_sink = blocks.probe_signal_f() ) device_source = RadioDevice() device_source.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=None, name="source") # ::TODO:: energyssarch NAO tem o parametro device!!! rx_path = EnergySSArch(device=device_source, fft_size=512, mavg_size=5, algorithm=None) #algorithm = EnergyDecision( th = 0.00000001 )) ## tb.add_arch( abstract_arch = rx_path, radio_device = device_source, name_of_arch = 'rx') tb.add_radio(device_source, "rx") # TX PATH tx_path = PacketGMSKTx() uhd_sink = UHDSink(device_addr=options.args) uhd_sink.samp_rate = options.samp_rate the_source = None the_sink = uhd_sink uhd_device = uhd_sink radio_sink = RadioDevice() radio_sink.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=uhd_device, name="sink") ####tb.add_arch( tx_path, radio_sink, 'tx', connection_type = OpERAFlow.CONN_SINK) tb.add_radio(radio_sink, "sink") return tb
def device_definition(): """ Definition of the devices used in the program. """ tb = OpERAFlow(name='US') uhd_source = UHDSource() uhd_source.samp_rate = 195512 energy = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=0)) radio = RadioDevice(name="radio") radio.add_arch(source=uhd_source, arch=energy, sink=blocks.probe_signal_f(), uhd_device=uhd_source, name='ss') tb.add_radio(radio, "radio") return tb, radio
def test_uhd_001(self): """ """ rx_uhd = PacketGMSKRx(10) source = blocks.vector_source_c( [1] * 8 ) sink = blocks.probe_signal_f() dev = RadioDevice() dev.add_arch(source=source, arch=rx_uhd, sink=sink, uhd_device=None, name='rx_uhd') rx_uhd.set_radio_device(dev) my_radio = rx_uhd.radio print my_radio samp_rate_radio = rx_uhd.radio._get_samp_rate print samp_rate_radio str_radio = rx_uhd.radio.my_str print str_radio
def __init__(self, input_rate, baud): gr.hier_block2.__init__( self, 'RTTY FSK demodulator', gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_float * 1), ) self.bit_time = bit_time = input_rate / baud fsk_deviation_hz = 85 # TODO param or just don't care self.__dc_blocker = grfilter.dc_blocker_ff(int(bit_time * _HALF_BITS_PER_CODE * 10), False) self.__quadrature_demod = analog.quadrature_demod_cf(-input_rate / (2 * math.pi * fsk_deviation_hz)) self.__freq_probe = blocks.probe_signal_f() self.connect( self, self.__quadrature_demod, self.__dc_blocker, digital.binary_slicer_fb(), blocks.char_to_float(scale=1), self) self.connect(self.__dc_blocker, self.__freq_probe)
def test_003(self): """ Test EDTopBlock with the input (1, 1, 1, 1, 1, 1, 1, 1). """ arr = (1, 1, 1, 1, 1, 1, 1, 1) expected_out = 8 ed = EnergySSArch(fft_size=len(arr), mavg_size=8, algorithm=EnergyDecision(expected_out - 1) ) src = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed') self.tb.add_radio(device, 'ed') self.tb.run() ##self.assertEqual(1 , device.sink.level()) # didn't work self.assertEqual(1, device.output()[0])
def test_002(self): """ Test a sequence with float number (0.1, 0.1, 0.1, 0.1). """ # input and expected results src_data = (0.1, 0.1, 0.1, 0.1) expected_result = 0 # blocks fft_size = len(src_data) mavg_size = 1 src = blocks.vector_source_c(data=src_data) ed = EnergyDetectorC(fft_size, mavg_size, EnergyDecision(1)) dst = blocks.probe_signal_f() # flowgraph self.tb.connect(src, ed, dst) self.tb.run() result_data = dst.level() self.assertEqual(expected_result, result_data)
def __init__(self): gr.top_block.__init__(self) options = get_options() self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) bitrate = 8000 first_decim = 125 out_sample_rate = sample_rate / first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps = out_sample_rate / bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.offset = options.offset sys.stderr.write("offset is: %dHz\n" % self.offset) taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf( first_decim, taps, self.offset, sample_rate) self.demod = digital.gmsk_demod(samples_per_symbol=sps) self.output = blocks.file_sink(gr.sizeof_char, options.output_file) self.connect((self.src, 0), (self.tuner, 0)) self.connect((self.tuner, 0), (self.demod, 0)) self.connect((self.demod, 0), (self.output, 0)) self.fm_demod = analog.fm_demod_cf(sample_rate / first_decim, 1, 5000, 3000, 4000) self.integrate = blocks.integrate_ff(32000) self.probe = blocks.probe_signal_f() self.connect((self.tuner, 0), (self.fm_demod, 0)) self.connect((self.fm_demod, 0), (self.integrate, 0)) self.connect((self.integrate, 0), (self.probe, 0)) def _variable_function_probe_0_probe(): while True: freq = self.tuner.center_freq() freq2 = freq + 0.2 * self.probe.level() print "Autotune: fix=%f old=%i new=%i" % ( self.probe.level(), self.ifreq + freq, self.ifreq + freq2) self.tuner.set_center_freq(freq2) time.sleep(5.0) _variable_function_probe_0_thread = threading.Thread( target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()
def __init__(self): gr.top_block.__init__(self, "Bpsk Receiverpoly") ################################################## # Variables ################################################## self.sps = sps = 8 self.probe_var = probe_var = 0 self.nfilts = nfilts = 32 self.eb = eb = 0.35 self.SNR = SNR = 500 self.transistion = transistion = 100 self.timing_loop_bw = timing_loop_bw = 6.28/100.0 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts/16, nfilts/16, 1.0/float(sps), 0.35, 11*sps*nfilts/16) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.probe_var_n = probe_var_n = 0 self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1] self.phase_bw = phase_bw = 6.28/100.0 self.noise_amp = noise_amp = probe_var/(10**(SNR/20)) self.matched_filter = matched_filter = firdes.root_raised_cosine(nfilts, nfilts, 1, eb, int(11*sps*nfilts)) self.interpolation = interpolation = 60000 self.eq_gain = eq_gain = 0.01 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist(([1,- 1]), ([0,1]), 2, 1).base() self.carrier = carrier = 10000 self.arity = arity = 2 ################################################## # Blocks ################################################## self.probe_rms = blocks.probe_signal_f() self.probe_avg_n = blocks.probe_signal_f() self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=decimation, decimation=interpolation, taps=(rrc_taps), fractional_bw=None, ) def _probe_var_n_probe(): while True: val = self.probe_avg_n.level() try: self.set_probe_var_n(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_n_thread = threading.Thread(target=_probe_var_n_probe) _probe_var_n_thread.daemon = True _probe_var_n_thread.start() def _probe_var_probe(): while True: val = self.probe_rms.level() try: self.set_probe_var(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_thread = threading.Thread(target=_probe_var_probe) _probe_var_thread.daemon = True _probe_var_thread.start() self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc(1, (filter.firdes.low_pass(1, samp_rate*10, sideband_rx,1000)), carrier, samp_rate) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts*2, nfilts/2, 1.5, 1) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constel) script, SNRinput, inputwav, outputBinary, delay= argv self.blocks_wavfile_source_0 = blocks.wavfile_source(inputwav, False) self.blocks_throttle_1_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_rms_xx_1 = blocks.rms_cf(0.01) self.blocks_rms_xx_0 = blocks.rms_cf(0.01) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, outputBinary, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_1 = blocks.delay(gr.sizeof_char*1, int(delay)) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, noise_amp, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_rms_xx_1, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.probe_rms, 0)) self.connect((self.blocks_rms_xx_1, 0), (self.probe_avg_n, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_delay_1, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_throttle_1_0_0, 0))
def __init__(self, port=65400, address="addr=192.168.10.2", seed1=1088): gr.top_block.__init__(self, "Ue") Qt.QWidget.__init__(self) self.setWindowTitle("Ue") 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", "UE") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.port = port self.address = address self.seed1 = seed1 ################################################## # Variables ################################################## self.seed2 = seed2 = seed1 + 384 self.pilot_symbols = pilot_symbols = (( 1, 1, 1, -1, ), ) self.pilot_carriers = pilot_carriers = (( -21, -7, 7, 21, ), ) self.payload_mod = payload_mod = digital.constellation_qpsk() self.occupied_carriers = occupied_carriers = ( range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ) self.header_mod = header_mod = digital.constellation_bpsk() self.fft_len = fft_len = 64 self.sync_word2 = sync_word2 = [ 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 0, 0, 0, 0, 0 ] self.sync_word1 = sync_word1 = [ 0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 0., 0., 0., 0., 0. ] self.seed6 = seed6 = seed1 + 4590 self.seed5 = seed5 = seed2 + 851 self.seed4 = seed4 = seed1 + 9027 self.seed3 = seed3 = seed1 + 2791 self.samp_rate = samp_rate = 500000 self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, payload_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 1) self.packet_length_tag_key = packet_length_tag_key = "packet_len" self.packet_len = packet_len = 12 self.noise_power = noise_power = 0 self.length_tag_key = length_tag_key = "frame_len" self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 1) self.h_2 = h_2 = 0 self.h_1 = h_1 = 0 self.h_0 = h_0 = 1 ################################################## # Blocks ################################################## self.s_2 = blocks.probe_signal_c() self.s_1 = blocks.probe_signal_c() self.s_0 = blocks.probe_signal_c() self.noise_variance = blocks.probe_signal_f() def _noise_power_probe(): while True: val = self.noise_variance.level() try: self.set_noise_power(val) except AttributeError: pass time.sleep(1.0 / (10)) _noise_power_thread = threading.Thread(target=_noise_power_probe) _noise_power_thread.daemon = True _noise_power_thread.start() def _h_2_probe(): while True: val = self.s_2.level() try: self.set_h_2(val) except AttributeError: pass time.sleep(1.0 / (10)) _h_2_thread = threading.Thread(target=_h_2_probe) _h_2_thread.daemon = True _h_2_thread.start() def _h_1_probe(): while True: val = self.s_1.level() try: self.set_h_1(val) except AttributeError: pass time.sleep(1.0 / (10)) _h_1_thread = threading.Thread(target=_h_1_probe) _h_1_thread.daemon = True _h_1_thread.start() def _h_0_probe(): while True: val = self.s_0.level() try: self.set_h_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _h_0_thread = threading.Thread(target=_h_0_probe) _h_0_thread.daemon = True _h_0_thread.start() self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((address, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(450e6, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.uhd_usrp_source_0.set_antenna("RX2", 0) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(True) self.qtgui_time_sink_x_0_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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_time_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) if complex == type(float()): self.qtgui_freq_sink_x_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.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.projectGT_variance_cc_0 = projectGT.variance_cc(5000) self.projectGT_IA_vectors_vcvc_0 = projectGT.IA_vectors_vcvc( fft_len, noise_power, 1, 2, (15, 25, 40, 45), length_tag_key) self.ofdm_rx_phase_1_0 = ofdm_rx_phase_1( pilot_symbols=pilot_symbols, header_mod=header_mod, payload_mod=payload_mod, sync_word2=sync_word2, sync_word1=sync_word1, fft_len=fft_len, packet_len=packet_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, samp_rate=samp_rate, ) self.channels_channel_model_4_0 = channels.channel_model( noise_voltage=0.1, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed6, block_tags=False) self.channels_channel_model_4 = channels.channel_model( noise_voltage=0.1, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed4, block_tags=False) self.channels_channel_model_3_0 = channels.channel_model( noise_voltage=0.05, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed5, block_tags=False) self.channels_channel_model_3 = channels.channel_model( noise_voltage=0.1, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed3, block_tags=False) self.channels_channel_model_2 = channels.channel_model( noise_voltage=0.11, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed2, block_tags=False) self.channels_channel_model_1 = channels.channel_model( noise_voltage=0.12, frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=seed1, block_tags=False) self.channels_channel_model_0 = channels.channel_model( noise_voltage=0.000, frequency_offset=0.0, epsilon=1.0, taps=((h_0, h_1, h_2)), noise_seed=0, block_tags=False) self.blocks_vector_to_stream_1 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, fft_len) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, fft_len) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 1, "134.214.146.135", port, 1472, True) self.blocks_tag_debug_3 = blocks.tag_debug(gr.sizeof_gr_complex * 1, "IA", "") self.blocks_tag_debug_3.set_display(True) self.blocks_tag_debug_1 = blocks.tag_debug( gr.sizeof_gr_complex * fft_len, "chnl_intrf", "") self.blocks_tag_debug_1.set_display(False) self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char * 1, "Payload_intrf", "") self.blocks_tag_debug_0.set_display(False) self.blocks_null_source_3_0 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_null_source_3 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_null_source_2_0 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_null_source_2 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_null_source_1 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex * 1) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_3_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_3 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_2_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_2 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_1 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_add_const_vxx_1_0 = blocks.add_const_vcc((0.0, )) self.blocks_add_const_vxx_1 = blocks.add_const_vcc((0.1, )) self.blocks_add_const_vxx_0 = blocks.add_const_vcc((0.8, )) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.s_0, 0)) self.connect((self.blocks_add_const_vxx_1, 0), (self.s_1, 0)) self.connect((self.blocks_add_const_vxx_1_0, 0), (self.s_2, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_mag_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_complex_to_mag_2, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.blocks_complex_to_mag_2_0, 0), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_complex_to_mag_3, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.blocks_complex_to_mag_3_0, 0), (self.blocks_float_to_complex_1_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_add_const_vxx_1, 0)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_add_const_vxx_1_0, 0)) self.connect((self.blocks_null_source_0, 0), (self.channels_channel_model_1, 0)) self.connect((self.blocks_null_source_1, 0), (self.channels_channel_model_2, 0)) self.connect((self.blocks_null_source_2, 0), (self.channels_channel_model_3, 0)) self.connect((self.blocks_null_source_2_0, 0), (self.channels_channel_model_3_0, 0)) self.connect((self.blocks_null_source_3, 0), (self.channels_channel_model_4, 0)) self.connect((self.blocks_null_source_3_0, 0), (self.channels_channel_model_4_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_vector_to_stream_1, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.ofdm_rx_phase_1_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.projectGT_variance_cc_0, 0)) self.connect((self.channels_channel_model_1, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.channels_channel_model_2, 0), (self.blocks_complex_to_mag_1, 0)) self.connect((self.channels_channel_model_3, 0), (self.blocks_complex_to_mag_2, 0)) self.connect((self.channels_channel_model_3_0, 0), (self.blocks_complex_to_mag_2_0, 0)) self.connect((self.channels_channel_model_4, 0), (self.blocks_complex_to_mag_3, 0)) self.connect((self.channels_channel_model_4_0, 0), (self.blocks_complex_to_mag_3_0, 0)) self.connect((self.ofdm_rx_phase_1_0, 2), (self.blocks_tag_debug_0, 0)) self.connect((self.ofdm_rx_phase_1_0, 0), (self.blocks_tag_debug_1, 0)) self.connect((self.ofdm_rx_phase_1_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.ofdm_rx_phase_1_0, 1), (self.blocks_vector_to_stream_1, 0)) self.connect((self.projectGT_IA_vectors_vcvc_0, 0), (self.blocks_tag_debug_3, 0)) self.connect((self.projectGT_IA_vectors_vcvc_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.projectGT_variance_cc_0, 0), (self.noise_variance, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.ofdm_rx_phase_1_0, 1), (self.projectGT_IA_vectors_vcvc_0, 0)) self.connect((self.ofdm_rx_phase_1_0, 0), (self.projectGT_IA_vectors_vcvc_0, 1))
def __init__(self, angle=0, samp_rate=1e6, threshold_dB=-70, rx_gain=0, samp_rate_sink=8000, tx_amp=10e-3, lowpass_cutoff_freq=1700, RF=2.49e9, fft_len=pow(2, 20), speed_samp_rate=1, DC_filter_num_elements=4, highpass_cutoff_freq=0): grc_wxgui.top_block_gui.__init__( self, title="CW Doppler Radar Simulator Single Target") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.angle = angle self.samp_rate = samp_rate self.threshold_dB = threshold_dB self.rx_gain = rx_gain self.samp_rate_sink = samp_rate_sink self.tx_amp = tx_amp self.lowpass_cutoff_freq = lowpass_cutoff_freq self.RF = RF self.fft_len = fft_len self.speed_samp_rate = speed_samp_rate self.DC_filter_num_elements = DC_filter_num_elements self.highpass_cutoff_freq = highpass_cutoff_freq ################################################## # Variables ################################################## self.target_speed = target_speed = 0 self.target_direction = target_direction = 0 self.tx_amp_tuner = tx_amp_tuner = tx_amp self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB self.speed_textbox = speed_textbox = target_speed self.rx_gain_tuner = rx_gain_tuner = rx_gain self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq self.doppler_freq_sim_tuner = doppler_freq_sim_tuner = 100 self.direction_textbox = direction_textbox = target_direction self.angle_tuner = angle_tuner = angle self.RF_tuner = RF_tuner = RF ################################################## # Blocks ################################################## _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._tx_amp_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, label="TX Signal Amp", converter=forms.float_converter(), proportion=0, ) self._tx_amp_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, minimum=0, maximum=100e-3, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tx_amp_tuner_sizer, 0, 17, 1, 26) _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_dB_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, label="Detected Target Threshold (dB)", converter=forms.float_converter(), proportion=0, ) self._threshold_dB_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, minimum=-90, maximum=-30, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 17) self.speed_probe = blocks.probe_signal_f() self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum") self.GridAdd(self.notebook, 5, 0, 13, 75) _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._lowpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, label="Lowpass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._lowpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, minimum=0, maximum=3000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 43, 1, 32) _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._highpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, label="High-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._highpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, minimum=0, maximum=1600, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 43, 1, 32) _doppler_freq_sim_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._doppler_freq_sim_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_doppler_freq_sim_tuner_sizer, value=self.doppler_freq_sim_tuner, callback=self.set_doppler_freq_sim_tuner, label="Doppler Frequency Simulator (Hz)", converter=forms.float_converter(), proportion=0, ) self._doppler_freq_sim_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_doppler_freq_sim_tuner_sizer, value=self.doppler_freq_sim_tuner, callback=self.set_doppler_freq_sim_tuner, minimum=-2000, maximum=2000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_doppler_freq_sim_tuner_sizer, 2, 17, 1, 58) self.direction_probe = blocks.probe_signal_i() _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._angle_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, label="Angle of Approach of the Target (Deg)", converter=forms.float_converter(), proportion=0, ) self._angle_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, minimum=0, maximum=89, num_steps=890, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_angle_tuner_sizer, 1, 17, 1, 26) _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._RF_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, label="Radar Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._RF_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, minimum=2.4e9, maximum=2.5e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 17) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="Time/Frequency CW Doppler Radar", win=window.blackmanharris, ) self.notebook.GetPage(1).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c( self.notebook.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=4096, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver Full Spectrum", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver ", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.tx_signal = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, 0.5, 0) def _target_speed_probe(): while True: val = self.speed_probe.level() try: self.set_target_speed(val) except AttributeError: pass time.sleep(1.0 / (2)) _target_speed_thread = threading.Thread(target=_target_speed_probe) _target_speed_thread.daemon = True _target_speed_thread.start() def _target_direction_probe(): while True: val = self.direction_probe.level() try: ############################################## if val == 1: #if the value is 1 the target is approaching. val = "Approaching" elif val == 2: #if the value is 2 the target is receding. val = "Receding" elif val == 0: #if the value is 0 there is no target in sight. val = "No Target Detected" self.set_target_direction(val) ############################################### except AttributeError: pass time.sleep(1.0 / (2)) _target_direction_thread = threading.Thread( target=_target_direction_probe) _target_direction_thread.daemon = True _target_direction_thread.start() self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Target Speed (Kph)", converter=forms.float_converter(), ) self.GridAdd(self._speed_textbox_text_box, 3, 0, 1, 17) self.rx_signal_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner, tx_amp_tuner, 0) _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, label="USRP RX Gain (dB)", converter=forms.float_converter(), proportion=0, ) self._rx_gain_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, minimum=0, maximum=70, num_steps=70, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 17) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate / samp_rate_sink), taps=None, fractional_bw=None, ) self.mixer = blocks.multiply_vcc(1) self.fft = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1) self._direction_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.direction_textbox, callback=self.set_direction_textbox, label="Target Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 4, 0, 1, 17) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len / 2) self.cwradar_doppler_velocity_single_target_ff_0 = cwradar.doppler_velocity_single_target_ff( fft_len / 2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner) self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream( gr.sizeof_float * 1, fft_len) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, fft_len) self.blocks_throttle_0_1_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector( gr.sizeof_float * 1, fft_len / 2) self.blocks_stream_to_vector_1 = blocks.stream_to_vector( gr.sizeof_float * 1, fft_len / 2) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_len) self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n( gr.sizeof_float, fft_len / 2, fft_len, fft_len / 2) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len / 2, fft_len, 0) self.blocks_complex_to_mag = blocks.complex_to_mag(fft_len) self.blocks_add_xx_1 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.awgn_channel_simulator = analog.noise_source_c( analog.GR_GAUSSIAN, 1e-3, 0) self.DC_filter_0 = blocks.multiply_const_vff( ([0] * DC_filter_num_elements + [1] * ((fft_len / 2) - DC_filter_num_elements))) self.DC_filter = blocks.multiply_const_vff( ([0] * DC_filter_num_elements + [1] * ((fft_len / 2) - DC_filter_num_elements))) ################################################## # Connections ################################################## self.connect((self.awgn_channel_simulator, 0), (self.blocks_add_xx_1, 0)) self.connect((self.tx_signal, 0), (self.blocks_add_xx_1, 1)) self.connect((self.rx_signal_0, 0), (self.blocks_add_xx_1, 2)) self.connect((self.mixer, 0), (self.blocks_throttle_0_1_0, 0)) self.connect((self.mixer, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_throttle_0_1_0, 0), (self.wxgui_fftsink2_full_spectrum, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_throttle_0_1_0, 0), (self.rational_resampler, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.mixer, 1)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft, 0)) self.connect((self.fft, 0), (self.blocks_complex_to_mag, 0)) self.connect((self.blocks_complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0)) self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0)) self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0)) self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0)) self.connect((self.blocks_add_xx_0, 0), (self.mixer, 0)) self.connect((self.tx_signal, 0), (self.blocks_add_xx_0, 1)) self.connect((self.awgn_channel_simulator, 0), (self.blocks_add_xx_0, 0)) self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 1)) self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 1), (self.direction_probe, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 0), (self.speed_probe, 0))
def __init__(self): gr.top_block.__init__(self, "If Else") Qt.QWidget.__init__(self) self.setWindowTitle("If Else") qtgui.util.check_set_qss() 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", "if_else") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.samp_rate = samp_rate = 32000 self.freq = freq = 1000 self.ampl = ampl = 1 ################################################## # Blocks ################################################## self.probe = blocks.probe_signal_f() self._freq_tool_bar = Qt.QToolBar(self) self._freq_tool_bar.addWidget(Qt.QLabel("freq"+": ")) self._freq_line_edit = Qt.QLineEdit(str(self.freq)) self._freq_tool_bar.addWidget(self._freq_line_edit) self._freq_line_edit.returnPressed.connect( lambda: self.set_freq(int(str(self._freq_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._freq_tool_bar) self._ampl_tool_bar = Qt.QToolBar(self) self._ampl_tool_bar.addWidget(Qt.QLabel("ampl"+": ")) self._ampl_line_edit = Qt.QLineEdit(str(self.ampl)) self._ampl_tool_bar.addWidget(self._ampl_line_edit) self._ampl_line_edit.returnPressed.connect( lambda: self.set_ampl(int(str(self._ampl_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._ampl_tool_bar) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate 'QT GUI Plot', #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True) self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, freq, ampl, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0) def _variable_function_probe_0_probe(): while True: val = self.probe.level() print val if val == 1: self.set_ampl(1) self.set_freq(1000) else: self.set_ampl(.3) self.set_freq(100) try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.probe, 0))
def __init__(self, meta_rate=10): gr.top_block.__init__(self, "FOX1D Receiver, Pipe to FoxTelem") Qt.QWidget.__init__(self) self.setWindowTitle("FOX1D Receiver, Pipe to FoxTelem") qtgui.util.check_set_qss() 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", "fox1d_rx_pipe_2") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.meta_rate = meta_rate ################################################## # Variables ################################################## self.samp_rate = samp_rate = 250e3 self.decim = decim = 5 self.baud = baud = 9600 self.xlate_taps_0 = xlate_taps_0 = firdes.low_pass( 1.0, samp_rate, samp_rate / 2, 1000, firdes.WIN_HAMMING, 6.76) self.xlate_taps = xlate_taps = firdes.low_pass(1.0, samp_rate, 15e3, 1000, firdes.WIN_HAMMING, 6.76) self.volume_0 = volume_0 = 0.01 self.volume = volume = 0.01 self.throttle_factor = throttle_factor = 1 self.samps_per_symb = samps_per_symb = samp_rate / decim / baud self.rf_lpf_cutoff = rf_lpf_cutoff = 8e3 self.fsk_deviation_hz = fsk_deviation_hz = 4000 self.fll_loop_bw_fine = fll_loop_bw_fine = 0.0001 self.fll_loop_bw = fll_loop_bw = math.pi / 200 self.doppler_func = doppler_func = 0 self.audio_lpf_cutoff = audio_lpf_cutoff = 6e3 ################################################## # Blocks ################################################## self.doppler_probe = blocks.probe_signal_f() self._volume_0_tool_bar = Qt.QToolBar(self) self._volume_0_tool_bar.addWidget(Qt.QLabel("volume_0" + ": ")) self._volume_0_line_edit = Qt.QLineEdit(str(self.volume_0)) self._volume_0_tool_bar.addWidget(self._volume_0_line_edit) self._volume_0_line_edit.returnPressed.connect( lambda: self.set_volume_0( eng_notation.str_to_num( str(self._volume_0_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._volume_0_tool_bar, 10, 0, 1, 2) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._volume_tool_bar = Qt.QToolBar(self) self._volume_tool_bar.addWidget(Qt.QLabel("volume" + ": ")) self._volume_line_edit = Qt.QLineEdit(str(self.volume)) self._volume_tool_bar.addWidget(self._volume_line_edit) self._volume_line_edit.returnPressed.connect(lambda: self.set_volume( eng_notation.str_to_num( str(self._volume_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._volume_tool_bar, 7, 4, 1, 2) for r in range(7, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self._throttle_factor_tool_bar = Qt.QToolBar(self) self._throttle_factor_tool_bar.addWidget( Qt.QLabel("throttle_factor" + ": ")) self._throttle_factor_line_edit = Qt.QLineEdit( str(self.throttle_factor)) self._throttle_factor_tool_bar.addWidget( self._throttle_factor_line_edit) self._throttle_factor_line_edit.returnPressed.connect( lambda: self.set_throttle_factor( eng_notation.str_to_num( str(self._throttle_factor_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._throttle_factor_tool_bar, 6, 4, 1, 2) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self._rf_lpf_cutoff_tool_bar = Qt.QToolBar(self) self._rf_lpf_cutoff_tool_bar.addWidget( Qt.QLabel("rf_lpf_cutoff" + ": ")) self._rf_lpf_cutoff_line_edit = Qt.QLineEdit(str(self.rf_lpf_cutoff)) self._rf_lpf_cutoff_tool_bar.addWidget(self._rf_lpf_cutoff_line_edit) self._rf_lpf_cutoff_line_edit.returnPressed.connect( lambda: self.set_rf_lpf_cutoff( eng_notation.str_to_num( str(self._rf_lpf_cutoff_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rf_lpf_cutoff_tool_bar, 6, 0, 1, 2) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._fll_loop_bw_fine_tool_bar = Qt.QToolBar(self) self._fll_loop_bw_fine_tool_bar.addWidget( Qt.QLabel("fll_loop_bw_fine" + ": ")) self._fll_loop_bw_fine_line_edit = Qt.QLineEdit( str(self.fll_loop_bw_fine)) self._fll_loop_bw_fine_tool_bar.addWidget( self._fll_loop_bw_fine_line_edit) self._fll_loop_bw_fine_line_edit.returnPressed.connect( lambda: self.set_fll_loop_bw_fine( eng_notation.str_to_num( str(self._fll_loop_bw_fine_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fll_loop_bw_fine_tool_bar, 7, 2, 1, 2) for r in range(7, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self._fll_loop_bw_tool_bar = Qt.QToolBar(self) self._fll_loop_bw_tool_bar.addWidget(Qt.QLabel("fll_loop_bw" + ": ")) self._fll_loop_bw_line_edit = Qt.QLineEdit(str(self.fll_loop_bw)) self._fll_loop_bw_tool_bar.addWidget(self._fll_loop_bw_line_edit) self._fll_loop_bw_line_edit.returnPressed.connect( lambda: self.set_fll_loop_bw( eng_notation.str_to_num( str(self._fll_loop_bw_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fll_loop_bw_tool_bar, 6, 2, 1, 2) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) def _doppler_func_probe(): while True: val = self.doppler_probe.level() try: self.set_doppler_func(val) except AttributeError: pass time.sleep(1.0 / (100)) _doppler_func_thread = threading.Thread(target=_doppler_func_probe) _doppler_func_thread.daemon = True _doppler_func_thread.start() self._audio_lpf_cutoff_tool_bar = Qt.QToolBar(self) self._audio_lpf_cutoff_tool_bar.addWidget( Qt.QLabel("audio_lpf_cutoff" + ": ")) self._audio_lpf_cutoff_line_edit = Qt.QLineEdit( str(self.audio_lpf_cutoff)) self._audio_lpf_cutoff_tool_bar.addWidget( self._audio_lpf_cutoff_line_edit) self._audio_lpf_cutoff_line_edit.returnPressed.connect( lambda: self.set_audio_lpf_cutoff( eng_notation.str_to_num( str(self._audio_lpf_cutoff_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._audio_lpf_cutoff_tool_bar, 7, 0, 1, 2) for r in range(7, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=1, decimation=4, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=1, decimation=4, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=48, decimation=50, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0_0 = qtgui.waterfall_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "corrected", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0_0.set_update_time(0.010) self.qtgui_waterfall_sink_x_0_0.enable_grid(False) self.qtgui_waterfall_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [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_waterfall_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0_0.set_intensity_range(-80, 0) self._qtgui_waterfall_sink_x_0_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_0_win, 2, 4, 2, 4) for r in range(2, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "Pre-D", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.010) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [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_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-80, 0) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 0, 4, 2, 4) for r in range(0, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate / 5 / 50 * 48, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 8, 2, 1, 6) for r in range(8, 9): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0_0_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_NONE, 1) self.qtgui_number_sink_0_0_0_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0_0_0_0.set_title("") labels = ['SNR', '', '', '', '', '', '', '', '', ''] units = ['dB', '', '', '', '', '', '', '', '', ''] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0_0_0.set_min(i, 0) self.qtgui_number_sink_0_0_0_0_0.set_max(i, 30) self.qtgui_number_sink_0_0_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0_0_0.set_label( i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_0_0_win, 6, 6, 1, 1) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 7): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_NONE, 1) self.qtgui_number_sink_0_0_0_0.set_update_time(0.010) self.qtgui_number_sink_0_0_0_0.set_title("") labels = ['Freq Offset', 'Phase', 'Error', '', '', '', '', '', '', ''] units = ['Hz', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0_0.set_min(i, -32767) self.qtgui_number_sink_0_0_0_0.set_max(i, 32767) self.qtgui_number_sink_0_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0_0.set_label( i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_0_win, 6, 7, 1, 1) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(7, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_2 = qtgui.freq_sink_f( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_2.set_update_time(0.10) self.qtgui_freq_sink_x_2.set_y_axis(-140, 10) self.qtgui_freq_sink_x_2.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_2.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_2.enable_autoscale(False) self.qtgui_freq_sink_x_2.enable_grid(False) self.qtgui_freq_sink_x_2.set_fft_average(1.0) self.qtgui_freq_sink_x_2.enable_axis_labels(True) self.qtgui_freq_sink_x_2.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_2.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_2.set_plot_pos_half(not False) 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_2.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_2.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_2.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_2.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_2.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_2_win = sip.wrapinstance( self.qtgui_freq_sink_x_2.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_2_win, 12, 0, 1, 8) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_1 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim / 50 * 48, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_1.set_update_time(0.10) self.qtgui_freq_sink_x_1.set_y_axis(-140, 10) self.qtgui_freq_sink_x_1.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_1.enable_autoscale(False) self.qtgui_freq_sink_x_1.enable_grid(False) self.qtgui_freq_sink_x_1.set_fft_average(1.0) self.qtgui_freq_sink_x_1.enable_axis_labels(True) self.qtgui_freq_sink_x_1.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_1.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_1.set_plot_pos_half(not False) 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_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_1.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_1.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_1.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_1_win = sip.wrapinstance( self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 10, 2, 1, 6) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "Pre-D", #name 2 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.010) self.qtgui_freq_sink_x_0.set_y_axis(-60, 0) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.2) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['pre-d', 'corr', '', '', '', '', '', '', '', ''] 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(2): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 4, 4) for r in range(0, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.low_pass_filter_0_0_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate / 5 / 50 * 48, audio_lpf_cutoff, 2e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate / decim, rf_lpf_cutoff, 2e3, firdes.WIN_HAMMING, 6.76)) self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc( 1, (xlate_taps_0), doppler_func, samp_rate) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( decim, (xlate_taps), 0, samp_rate) self.digital_fll_band_edge_cc_0_0 = digital.fll_band_edge_cc( samps_per_symb, .5, 1024, fll_loop_bw_fine) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc( samps_per_symb, .5, 1024, fll_loop_bw) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate * throttle_factor, True) self.blocks_tagged_stream_to_pdu_0_0 = blocks.tagged_stream_to_pdu( blocks.float_t, 'snr') self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu( blocks.float_t, 'rfo') self.blocks_stream_to_tagged_stream_0_0 = blocks.stream_to_tagged_stream( gr.sizeof_float, 1, 1, "snr") self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream( gr.sizeof_float, 1, 1, "rfo") self.blocks_socket_pdu_0_0 = blocks.socket_pdu("TCP_SERVER", '0.0.0.0', '52002', 10000, False) self.blocks_socket_pdu_0 = blocks.socket_pdu("TCP_SERVER", '0.0.0.0', '52001', 10000, False) self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_nlog10_ff_0_1 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff( (-1 * samp_rate / decim / (2 * math.pi), )) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff( (volume_0, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (volume, )) self.blocks_moving_average_xx_0_0_1 = blocks.moving_average_ff( 10000, 0.0001, 4000, 1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( 100000, 0.00001, 4000, 1) self.blocks_keep_one_in_n_0_0 = blocks.keep_one_in_n( gr.sizeof_float * 1, int(samp_rate * meta_rate)) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * 1, int(samp_rate / 4 * meta_rate)) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_gr_complex * 1, '/home/zleffke/captures/fox1d/20180914/FOX-1D_USRP_20180914_145014.657610_UTC_250k.fc32', False) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_divide_xx_0 = blocks.divide_ff(1) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.audio_sink_0 = audio.sink(48000, '', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=int(samp_rate), audio_decimation=1, ) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, samp_rate / 2, 1, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf( (samp_rate / decim) / (2 * math.pi * fsk_deviation_hz / 8.0)) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.blocks_socket_pdu_0, 'pdus')) self.msg_connect((self.blocks_tagged_stream_to_pdu_0_0, 'pdus'), (self.blocks_socket_pdu_0_0, 'pdus')) self.connect((self.analog_agc2_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.low_pass_filter_0_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_nlog10_ff_0_1, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_stream_to_tagged_stream_0_0, 0)) self.connect((self.blocks_keep_one_in_n_0_0, 0), (self.blocks_stream_to_tagged_stream_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_keep_one_in_n_0_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.doppler_probe, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.qtgui_number_sink_0_0_0_0, 0)) self.connect((self.blocks_moving_average_xx_0_0_1, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_moving_average_xx_0_0_1, 0), (self.qtgui_number_sink_0_0_0_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_freq_sink_x_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.qtgui_freq_sink_x_2, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_nlog10_ff_0_1, 0), (self.blocks_moving_average_xx_0_0_1, 0)) self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.blocks_tagged_stream_to_pdu_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.blocks_tagged_stream_to_pdu_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 1), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 2), (self.blocks_null_sink_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 3), (self.blocks_null_sink_0_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.digital_fll_band_edge_cc_0_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.digital_fll_band_edge_cc_0_0, 0), (self.qtgui_waterfall_sink_x_0_0, 0)) self.connect((self.digital_fll_band_edge_cc_0_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.digital_fll_band_edge_cc_0_0, 0)) self.connect((self.low_pass_filter_0_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_complex_to_mag_squared_0_0, 0))
def __init__(self, system, site_uuid, overseer_uuid): gr.top_block.__init__(self, "p25 receiver") #set globals self.is_locked = False self.system = system self.instance_uuid = '%s' % uuid.uuid4() self.log = logging.getLogger('overseer.p25_control_demod.%s' % self.instance_uuid) self.protocol_log = logging.getLogger('protocol.%s' % self.instance_uuid) self.log.info('Initializing instance: %s site: %s overseer: %s' % (self.instance_uuid, site_uuid, overseer_uuid)) self.site_uuid = site_uuid self.overseer_uuid = overseer_uuid self.control_channel = system['channels'][ system['default_control_channel']] self.control_channel_i = system['default_control_channel'] self.channel_identifier_table = {} try: self.modulation = system['modulation'] except: self.modulation = 'C4FM' self.channel_rate = 12500 symbol_rate = 4800 self.site_detail = {} self.site_detail['WACN ID'] = None self.site_detail['System ID'] = None self.site_detail['Control Channel'] = None self.site_detail['System Service Class'] = None self.site_detail['Site ID'] = None self.site_detail['RF Sub-system ID'] = None self.site_detail['RFSS Network Connection'] = None self.bad_messages = 0 self.total_messages = 0 self.quality = [] self.keep_running = True self.source = None # channel filter channel_rate = self.channel_rate * 2 self.control_prefilter = filter.freq_xlating_fir_filter_ccc( 1, (1, ), 0, channel_rate) # power squelch #power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True) #self.connect(self.channel_filter, power_squelch) autotuneq = gr.msg_queue(2) self.demod_watcher = demod_watcher(self) self.symbol_deviation = 600.0 if self.modulation == 'C4FM': # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = fm_demod = analog.quadrature_demod_cf( fm_demod_gain) moving_sum = blocks.moving_average_ff(10000, 1, 40000) subtract = blocks.sub_ff(1) divide_const = blocks.multiply_const_vff((0.0001, )) self.probe = blocks.probe_signal_f() self.connect(self.fm_demod, moving_sum, divide_const, self.probe) # symbol filter symbol_decim = 1 samples_per_symbol = channel_rate // symbol_rate symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol symbol_filter = filter.fir_filter_fff(symbol_decim, symbol_coeffs) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate) elif self.modulation == 'CQPSK': # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = fm_demod = analog.quadrature_demod_cf( fm_demod_gain) moving_sum = blocks.moving_average_ff(10000, 1, 40000) subtract = blocks.sub_ff(1) divide_const = blocks.multiply_const_vff((0.0001, )) self.probe = blocks.probe_signal_f() self.connect(fm_demod, moving_sum, divide_const, self.probe) #self.resampler = filter.pfb.arb_resampler_ccf(float(48000)/float(channel_rate)) self.resampler = blocks.multiply_const_cc(1.0) self.agc = analog.feedforward_agc_cc(1024, 1.0) self.symbol_filter_c = blocks.multiply_const_cc(1.0) gain_mu = 0.025 omega = float(channel_rate) / float(symbol_rate) gain_omega = 0.1 * gain_mu * gain_mu alpha = 0.04 beta = 0.125 * alpha * alpha fmax = 1200 # Hz fmax = 2 * pi * fmax / float(channel_rate) self.clock = repeater.gardner_costas_cc(omega, gain_mu, gain_omega, alpha, beta, fmax, -fmax) self.diffdec = digital.diff_phasor_cc() self.to_float = blocks.complex_to_arg() self.rescale = blocks.multiply_const_ff((1 / (pi / 4))) # symbol slicer levels = [-2.0, 0.0, 2.0, 4.0] slicer = op25.fsk4_slicer_fb(levels) # frame decoder self.decodequeue = decodequeue = gr.msg_queue(1000) qsink = blocks.message_sink(gr.sizeof_char, self.decodequeue, False) self.decoder = decoder = repeater.p25_frame_assembler( '', 0, 0, False, True, True, autotuneq, False, False) if self.modulation == 'C4FM': self.connect(self.control_prefilter, fm_demod, symbol_filter, demod_fsk4, slicer, decoder, qsink) elif self.modulation == 'CQPSK': self.connect(self.resampler, self.agc, self.symbol_filter_c, self.clock, self.diffdec, self.to_float, self.rescale, slicer, decoder, qsink) ################################################## # Threads ################################################## self.connector = frontend_connector() self.client_redis = client_redis() self.redis_demod_publisher = redis_demod_publisher(parent_demod=self) quality_check_0 = threading.Thread(target=self.quality_check) quality_check_0.daemon = True quality_check_0.start() # Adjust the channel offset # self.tune_next_control_channel() #self.receive_engine() receive_engine = threading.Thread(target=self.receive_engine) receive_engine.daemon = True receive_engine.start()
def __init__(self, freq=394e6, gain=0, sample_rate=2400000, args="", channel_bw=12500, listen_port=60100, ppm=0, output="channel%d.bits", output_offset=None, auto_tune=-1): gr.top_block.__init__(self, "TETRAPOL multichannel reciever") ################################################## # Parameters and variables ################################################## self.freq = freq self.gain = gain self.sample_rate = sample_rate self.args = args self.channel_bw = channel_bw self.listen_port = listen_port self.ppm = ppm self.output = output self.auto_tune = auto_tune # TODO: parametrize self.debug = True self.channels = channels = int(sample_rate/channel_bw) channel_symb_rate = 8000 samples_per_symbol = 2 self.channel_samp_rate = channel_samp_rate = \ channel_symb_rate * samples_per_symbol afc_period = 6 self.afc_gain = 1 self.afc_ppm_threshold = 100 if output_offset is None: self.output_offset = 0 else: self.output_offset = output_offset - ((channels - 1) // 2) ################################################## # Blocks - RPC server ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", listen_port), allow_none=True) self.xmlrpc_server_0.register_instance(self) threading.Thread(target=self.xmlrpc_server_0.serve_forever).start() ################################################## # Blocks - RX, demod, sink ################################################## self.src = osmosdr.source( args="numchan=" + str(1) + " " + "" + self.args ) self.src.set_sample_rate(sample_rate) self.src.set_center_freq(freq, 0) self.src.set_freq_corr(ppm, 0) # TODO: manual gain control self.src.set_gain_mode(True, 0) #self.src.set_gain(gain, 0) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, sample_rate) bw = (9200 + self.afc_ppm_threshold)/2 self.channelizer = pfb.channelizer_ccf( channels, firdes.low_pass(1, sample_rate, bw, bw*0.15, firdes.WIN_HANN), float(channel_samp_rate)/(sample_rate/channels), 100) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) self.valves = [] self.gmsk_demods = [] self.file_sinks = [] even_no_of_chs = not (channels % 2) center_ch = channels // 2 for ch_in in range(0, channels): ch_out = (ch_in + center_ch + 1) % channels if ch_out == center_ch and even_no_of_chs: null_sink = blocks.null_sink(gr.sizeof_gr_complex) self.connect( (self.channelizer, ch_out), (null_sink, 0)) continue valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex, open=True) gmsk_demod = digital.gmsk_demod( samples_per_symbol=samples_per_symbol, gain_mu=0.050, mu=0.5, omega_relative_limit=0.005, freq_error=0.0, verbose=False, log=False, ) o = output % (ch_in + self.output_offset) file_sink = blocks.file_sink(gr.sizeof_char, o, False) file_sink.set_unbuffered(True) self.connect( (self.channelizer, ch_out), (valve, 0), (gmsk_demod, 0), (file_sink, 0)) self.valves.append(valve) self.gmsk_demods.append(gmsk_demod) self.file_sinks.append(file_sink) ################################################## # Blocks - automatic fine tune ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=channels - even_no_of_chs, num_outputs=1, input_index=0, output_index=0, ) if auto_tune != -1: self.afc_selector.set_input_index(auto_tune) self.afc_demod = analog.quadrature_demod_cf(channel_samp_rate/(2*math.pi)) afc_samp = channel_samp_rate * afc_period / 2 self.afc_avg = blocks.moving_average_ff(afc_samp, 1./afc_samp*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(afc_period) if self.auto_tune == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_threshold: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "freq err: % .0f\tfreq: %f" % (err, freq) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch_in in range(0, channels - even_no_of_chs): ch_out = (ch_in + center_ch + 1) % channels self.connect((self.channelizer, ch_out), (self.afc_selector, ch_in)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) ################################################## # Blocks - signal strenght indication ################################################## self.pwr_probes = [] for ch in range(self.channels - even_no_of_chs): ch = (ch + center_ch + 1) % channels pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./channel_samp_rate) self.connect((self.channelizer, ch), (pwr_probe, 0)) self.pwr_probes.append(pwr_probe)
def __init__(self): gr.top_block.__init__(self, "NFM SCANNER") Qt.QWidget.__init__(self) self.setWindowTitle("NFM SCANNER") 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", "scanner") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.freqd = freqd = 0 self.stop_scan_a = stop_scan_a = 0 self.freq_set = freq_set = freqd self.variable_qtgui_label_0 = variable_qtgui_label_0 = stop_scan_a self.sql = sql = -50 self.samp_rate = samp_rate = 32000 self.s_rate = s_rate = 2 self.r_rate = r_rate = 240000 self.hold_scan = hold_scan = 0 self.gain = gain = 30 self.frequency = frequency = freq_set / 1000000 ################################################## # Blocks ################################################## self.stop_scan = blocks.probe_signal_f() def _stop_scan_a_probe(): while True: val = self.stop_scan.level() try: self.set_stop_scan_a(val) except AttributeError: pass time.sleep(1.0 / (100)) _stop_scan_a_thread = threading.Thread(target=_stop_scan_a_probe) _stop_scan_a_thread.daemon = True _stop_scan_a_thread.start() self._sql_range = Range(-100, 0, 1, -50, 50) self._sql_win = RangeWidget(self._sql_range, self.set_sql, "squelch", "dial", float) self.top_layout.addWidget(self._sql_win) self._s_rate_options = ( .5, 1, 2, 5, 10, ) self._s_rate_labels = ( ".5Hz", "1Hz", "2Hz", "5Hz", "10Hz", ) self._s_rate_tool_bar = Qt.QToolBar(self) self._s_rate_tool_bar.addWidget(Qt.QLabel("SCAN RATE" + ": ")) self._s_rate_combo_box = Qt.QComboBox() self._s_rate_tool_bar.addWidget(self._s_rate_combo_box) for label in self._s_rate_labels: self._s_rate_combo_box.addItem(label) self._s_rate_callback = lambda i: Qt.QMetaObject.invokeMethod( self._s_rate_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._s_rate_options.index(i))) self._s_rate_callback(self.s_rate) self._s_rate_combo_box.currentIndexChanged.connect( lambda i: self.set_s_rate(self._s_rate_options[i])) self.top_layout.addWidget(self._s_rate_tool_bar) _hold_scan_check_box = Qt.QCheckBox("hold_scan") self._hold_scan_choices = {True: 1, False: 0} self._hold_scan_choices_inv = dict( (v, k) for k, v in self._hold_scan_choices.iteritems()) self._hold_scan_callback = lambda i: Qt.QMetaObject.invokeMethod( _hold_scan_check_box, "setChecked", Qt.Q_ARG("bool", self._hold_scan_choices_inv[i])) self._hold_scan_callback(self.hold_scan) _hold_scan_check_box.stateChanged.connect( lambda i: self.set_hold_scan(self._hold_scan_choices[bool(i)])) self.top_layout.addWidget(_hold_scan_check_box) self._gain_range = Range(0, 50, 1, 30, 25) self._gain_win = RangeWidget(self._gain_range, self.set_gain, "GAIN", "dial", float) self.top_layout.addWidget(self._gain_win) self.freqb = blocks.probe_signal_f() self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel("scan" + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.valve = grc_blks2.valve(item_size=gr.sizeof_float * 1, open=bool(stop_scan_a or hold_scan)) self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.rtlsdr_source_0.set_sample_rate(r_rate) self.rtlsdr_source_0.set_center_freq(freq_set - 100000, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(2, 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(gain, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(r_rate, 0) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype freq_set, #fc r_rate, #bw "", #name True, #plotfreq True, #plotwaterfall False, #plottime False, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_win = sip.wrapinstance( self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(True) self.low_pass_filter_0 = filter.fir_filter_ccf( 5, firdes.low_pass(1, r_rate, 7500, 5000, firdes.WIN_HAMMING, 6.76)) self._frequency_tool_bar = Qt.QToolBar(self) if None: self._frequency_formatter = None else: self._frequency_formatter = lambda x: x self._frequency_tool_bar.addWidget(Qt.QLabel("frequency" + ": ")) self._frequency_label = Qt.QLabel( str(self._frequency_formatter(self.frequency))) self._frequency_tool_bar.addWidget(self._frequency_label) self.top_layout.addWidget(self._frequency_tool_bar) def _freqd_probe(): while True: val = self.freqb.level() try: self.set_freqd(val) except AttributeError: pass time.sleep(1.0 / (s_rate)) _freqd_thread = threading.Thread(target=_freqd_probe) _freqd_thread.daemon = True _freqd_thread.start() self.freqa = blocks.file_source( gr.sizeof_float * 1, "/home/jed/radio/PROJECTS/scanner/freqtest.dat", True) self.blocks_threshold_ff_0 = blocks.threshold_ff( 0.0000000001, .0001, 0) self.blocks_multiply_xx_2 = blocks.multiply_vff(1) self.blocks_multiply_xx_1 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, 10) self.blocks_add_xx_0 = blocks.add_vff(1) self.audio_sink_0 = audio.sink(48000, "", True) self.analog_sig_source_x_0 = analog.sig_source_c( r_rate, analog.GR_COS_WAVE, -100000, 1, 0) self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc( sql, 1e-3, 5, False) self.analog_nbfm_rx_0 = analog.nbfm_rx( audio_rate=48000, quad_rate=r_rate / 5, tau=75e-6, max_dev=5.0e3, ) ################################################## # Connections ################################################## self.connect((self.analog_nbfm_rx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.analog_nbfm_rx_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.analog_nbfm_rx_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_nbfm_rx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_delay_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_2, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_threshold_ff_0, 0), (self.stop_scan, 0)) self.connect((self.freqa, 0), (self.valve, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_pwr_squelch_xx_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.valve, 0), (self.freqb, 0))
def __init__(self, avg_len=256, nfft=2048, path="/captures/20200329", record_hz=10): gr.top_block.__init__(self, "/captures/20200329/LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data") Qt.QWidget.__init__(self) self.setWindowTitle("/captures/20200329/LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data") qtgui.util.check_set_qss() 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", "lro_playback") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.avg_len = avg_len self.nfft = nfft self.path = path self.record_hz = record_hz ################################################## # Variables ################################################## self.probe_snr_func = probe_snr_func = 0 self.probe_signal_func = probe_signal_func = 0 self.probe_offset_func = probe_offset_func = 0 self.probe_noise_func = probe_noise_func = 0 self.filename = filename = "LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data" self.snr_var = snr_var = "{:3.3f}".format(probe_snr_func) self.signal_var = signal_var = "{:3.3f}".format(probe_signal_func) self.samp_rate = samp_rate = 250e3 self.offset_var = offset_var = "{:3.3f}".format(probe_offset_func) self.offset_file = offset_file = "{:s}_{:s}".format(filename.split(".")[0], "offset") self.noise_var = noise_var = "{:3.3f}".format(probe_noise_func) self.variable_tag_object_0 = variable_tag_object_0 = gr.tag_utils.python_to_tag((0, pmt.intern("key"), pmt.intern("value"), pmt.intern("src"))) self.throttle_factor = throttle_factor = 10 self.snr_label = snr_label = snr_var self.signal_label = signal_label = signal_var self.rx_freq = rx_freq = 2271.2e6 self.offset_label = offset_label = offset_var self.offset_fp = offset_fp = "/".join([path,offset_file]) self.noise_label = noise_label = noise_var self.keep_n = keep_n = samp_rate/record_hz self.fp = fp = "/".join([path,filename]) self.file_l = file_l = filename.split(".")[0].split("_") self.fft_min = fft_min = -120 self.fft_max = fft_max = -80 self.decim = decim = 8 self.alpha = alpha = 1.0/(samp_rate/record_hz) ################################################## # Blocks ################################################## self.probe_offset = blocks.probe_signal_f() self._throttle_factor_tool_bar = Qt.QToolBar(self) self._throttle_factor_tool_bar.addWidget(Qt.QLabel('Throttle'+": ")) self._throttle_factor_line_edit = Qt.QLineEdit(str(self.throttle_factor)) self._throttle_factor_tool_bar.addWidget(self._throttle_factor_line_edit) self._throttle_factor_line_edit.returnPressed.connect( lambda: self.set_throttle_factor(eng_notation.str_to_num(str(self._throttle_factor_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._throttle_factor_tool_bar, 10, 2, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._samp_rate_tool_bar = Qt.QToolBar(self) self._samp_rate_tool_bar.addWidget(Qt.QLabel('SAMP_RATE'+": ")) self._samp_rate_line_edit = Qt.QLineEdit(str(self.samp_rate)) self._samp_rate_tool_bar.addWidget(self._samp_rate_line_edit) self._samp_rate_line_edit.returnPressed.connect( lambda: self.set_samp_rate(eng_notation.str_to_num(str(self._samp_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate_tool_bar, 9, 0, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.probe_snr = blocks.probe_signal_f() self.probe_signal = blocks.probe_signal_f() def _probe_offset_func_probe(): while True: val = self.probe_offset.level() try: self.set_probe_offset_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_offset_func_thread = threading.Thread(target=_probe_offset_func_probe) _probe_offset_func_thread.daemon = True _probe_offset_func_thread.start() self.probe_noise = blocks.probe_signal_f() self._fft_min_tool_bar = Qt.QToolBar(self) self._fft_min_tool_bar.addWidget(Qt.QLabel('fft_min'+": ")) self._fft_min_line_edit = Qt.QLineEdit(str(self.fft_min)) self._fft_min_tool_bar.addWidget(self._fft_min_line_edit) self._fft_min_line_edit.returnPressed.connect( lambda: self.set_fft_min(eng_notation.str_to_num(str(self._fft_min_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fft_min_tool_bar, 9, 2, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._fft_max_tool_bar = Qt.QToolBar(self) self._fft_max_tool_bar.addWidget(Qt.QLabel('fft_max'+": ")) self._fft_max_line_edit = Qt.QLineEdit(str(self.fft_max)) self._fft_max_tool_bar.addWidget(self._fft_max_line_edit) self._fft_max_line_edit.returnPressed.connect( lambda: self.set_fft_max(eng_notation.str_to_num(str(self._fft_max_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fft_max_tool_bar, 9, 3, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self._snr_label_tool_bar = Qt.QToolBar(self) if None: self._snr_label_formatter = None else: self._snr_label_formatter = lambda x: str(x) self._snr_label_tool_bar.addWidget(Qt.QLabel('SNR [dB]'+": ")) self._snr_label_label = Qt.QLabel(str(self._snr_label_formatter(self.snr_label))) self._snr_label_tool_bar.addWidget(self._snr_label_label) self.top_grid_layout.addWidget(self._snr_label_tool_bar, 3, 4, 1, 1) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._signal_label_tool_bar = Qt.QToolBar(self) if None: self._signal_label_formatter = None else: self._signal_label_formatter = lambda x: str(x) self._signal_label_tool_bar.addWidget(Qt.QLabel('Signal [dBFS]'+": ")) self._signal_label_label = Qt.QLabel(str(self._signal_label_formatter(self.signal_label))) self._signal_label_tool_bar.addWidget(self._signal_label_label) self.top_grid_layout.addWidget(self._signal_label_tool_bar, 1, 4, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self.sigmf_source_0 = gr_sigmf.source(fp, "cf32" + ("_le" if sys.byteorder == "little" else "_be"), False) self._rx_freq_tool_bar = Qt.QToolBar(self) self._rx_freq_tool_bar.addWidget(Qt.QLabel('FREQ'+": ")) self._rx_freq_line_edit = Qt.QLineEdit(str(self.rx_freq)) self._rx_freq_tool_bar.addWidget(self._rx_freq_line_edit) self._rx_freq_line_edit.returnPressed.connect( lambda: self.set_rx_freq(eng_notation.str_to_num(str(self._rx_freq_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rx_freq_tool_bar, 9, 1, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.010) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [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_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(fft_min, fft_max) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4, 0, 4, 4) for r in range(4, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "RHCP", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.010) self.qtgui_freq_sink_x_0.set_y_axis(fft_min, fft_max) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.05) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_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.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 4, 4) for r in range(0, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) def _probe_snr_func_probe(): while True: val = self.probe_snr.level() try: self.set_probe_snr_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_snr_func_thread = threading.Thread(target=_probe_snr_func_probe) _probe_snr_func_thread.daemon = True _probe_snr_func_thread.start() def _probe_signal_func_probe(): while True: val = self.probe_signal.level() try: self.set_probe_signal_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_signal_func_thread = threading.Thread(target=_probe_signal_func_probe) _probe_signal_func_thread.daemon = True _probe_signal_func_thread.start() def _probe_noise_func_probe(): while True: val = self.probe_noise.level() try: self.set_probe_noise_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_noise_func_thread = threading.Thread(target=_probe_noise_func_probe) _probe_noise_func_thread.daemon = True _probe_noise_func_thread.start() self._offset_label_tool_bar = Qt.QToolBar(self) if None: self._offset_label_formatter = None else: self._offset_label_formatter = lambda x: str(x) self._offset_label_tool_bar.addWidget(Qt.QLabel('Offset [Hz]'+": ")) self._offset_label_label = Qt.QLabel(str(self._offset_label_formatter(self.offset_label))) self._offset_label_tool_bar.addWidget(self._offset_label_label) self.top_grid_layout.addWidget(self._offset_label_tool_bar, 0, 4, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._noise_label_tool_bar = Qt.QToolBar(self) if None: self._noise_label_formatter = None else: self._noise_label_formatter = lambda x: str(x) self._noise_label_tool_bar.addWidget(Qt.QLabel('Noise [dBFS]'+": ")) self._noise_label_label = Qt.QLabel(str(self._noise_label_formatter(self.noise_label))) self._noise_label_tool_bar.addWidget(self._noise_label_label) self.top_grid_layout.addWidget(self._noise_label_tool_bar, 2, 4, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._keep_n_tool_bar = Qt.QToolBar(self) self._keep_n_tool_bar.addWidget(Qt.QLabel('keep_n'+": ")) self._keep_n_line_edit = Qt.QLineEdit(str(self.keep_n)) self._keep_n_tool_bar.addWidget(self._keep_n_line_edit) self._keep_n_line_edit.returnPressed.connect( lambda: self.set_keep_n(eng_notation.str_to_num(str(self._keep_n_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._keep_n_tool_bar, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.fft_vxx_0_0 = fft.fft_vcc(nfft/decim, True, (window.blackmanharris(nfft/decim)), True, 4) self.fft_vxx_0 = fft.fft_vcc(nfft, True, (window.blackmanharris(nfft)), True, 4) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate*throttle_factor,True) self.blocks_tag_share_0 = blocks.tag_share(gr.sizeof_float, gr.sizeof_gr_complex, 1) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, nfft/decim) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, nfft) self.blocks_nlog10_ff_0_0_0 = blocks.nlog10_ff(10, nfft/decim, -10*math.log10(nfft/decim)) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, nfft, -10*math.log10(nfft)) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((samp_rate/(2*math.pi), )) self.blocks_moving_average_xx_0_1 = blocks.moving_average_ff(int(samp_rate/record_hz), 1.0/(samp_rate/record_hz), 4000, 1) self.blocks_moving_average_xx_0_0 = blocks.moving_average_ff(int(avg_len), 1.0/(avg_len)/(nfft/decim*2), 4000, nfft/decim) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int(avg_len), 1.0/(avg_len)/nfft, 4000, nfft) self.blocks_max_xx_0_0 = blocks.max_ff(nfft/decim,1) self.blocks_max_xx_0 = blocks.max_ff(nfft,1) self.blocks_keep_one_in_n_0_0 = blocks.keep_one_in_n(gr.sizeof_float*1, int(samp_rate/record_hz)) self.blocks_complex_to_mag_squared_0_0_0 = blocks.complex_to_mag_squared(nfft/decim) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(nfft) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, probe_offset_func+samp_rate/4, 1, 0) self.analog_pll_freqdet_cf_0 = analog.pll_freqdet_cf(math.pi/200, math.pi/10, -math.pi/10) self._alpha_tool_bar = Qt.QToolBar(self) self._alpha_tool_bar.addWidget(Qt.QLabel('alpha'+": ")) self._alpha_line_edit = Qt.QLineEdit(str(self.alpha)) self._alpha_tool_bar.addWidget(self._alpha_line_edit) self._alpha_line_edit.returnPressed.connect( lambda: self.set_alpha(eng_notation.str_to_num(str(self._alpha_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._alpha_tool_bar, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) ################################################## # Connections ################################################## self.connect((self.analog_pll_freqdet_cf_0, 0), (self.blocks_tag_share_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0_0, 0), (self.blocks_moving_average_xx_0_0, 0)) self.connect((self.blocks_keep_one_in_n_0_0, 0), (self.probe_offset, 0)) self.connect((self.blocks_max_xx_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_max_xx_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_max_xx_0_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_max_xx_0_0, 0), (self.probe_noise, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_moving_average_xx_0_0, 0), (self.blocks_nlog10_ff_0_0_0, 0)) self.connect((self.blocks_moving_average_xx_0_1, 0), (self.blocks_keep_one_in_n_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_moving_average_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.blocks_max_xx_0, 0)) self.connect((self.blocks_nlog10_ff_0_0_0, 0), (self.blocks_max_xx_0_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.fft_vxx_0_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.probe_snr, 0)) self.connect((self.blocks_tag_share_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_pll_freqdet_cf_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_tag_share_0, 1)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.fft_vxx_0_0, 0), (self.blocks_complex_to_mag_squared_0_0_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.sigmf_source_0, 0), (self.blocks_throttle_0, 0))
def __init__(self): # Call the initialization method from the parent class gr.top_block.__init__(self) # Setup the parser for command line arguments parser = OptionParser(option_class=eng_option) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print settings to stdout") parser.add_option("-f", "--frequency", type="eng_float", dest="rx_freq", default=98.9E6, help="RX frequency in Hz") parser.add_option("-a", "--args", type="string", dest="uhd_args", default='type=b200', help="USRP device args") parser.add_option("-c", "--cal", type="eng_float", dest="rssi_cal_offset_dB", default=-50, help="RSSI calibration offset in dB") parser.add_option("-g", "--gain", type="eng_float", dest="src_gain_dB", default=50, help="USRP gain in dB") parser.add_option("-V", "--volume", type="eng_float", dest="volume_dB", default=30, help="Audio volume in dB") parser.add_option("-s", "--soundrate", type="eng_float", dest="snd_card_rate", default=48000, help="Sound card rate in Hz") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Define constants uhd_args = options.uhd_args self.rx_freq = options.rx_freq lo_offset_freq = 125E3 src_samp_rate = 500000 src_gain_dB = options.src_gain_dB rssi_cal_offset_dB = -50 volume_dB = options.volume_dB snd_card_rate = options.snd_card_rate # Print some info to stdout for verbose option if options.verbose: print 'USRP args string "%s" ' % uhd_args print 'RX frequency = %f MHz' % (self.rx_freq / 1E6) print 'Source sample rate = %i Hz' % src_samp_rate print 'USRP gain = %i dB' % src_gain_dB print 'RSSI cal offset= %i dB' % rssi_cal_offset_dB print 'Audio volume = %i dB' % volume_dB print 'Sound card rate = %i Hz' % snd_card_rate # Setup the USRP source self.src = uhd.usrp_source(uhd_args, uhd.io_type_t.COMPLEX_FLOAT32, 1) self.src.set_samp_rate(src_samp_rate) self.src.set_center_freq(self.rx_freq - lo_offset_freq, 0) self.src.set_gain(src_gain_dB, 0) # Generate taps for frequency translating FIR filter filter_taps = filter.firdes.low_pass(gain=1.0, sampling_freq=src_samp_rate, cutoff_freq=100E3, transition_width=25E3, window=filter.firdes.WIN_HAMMING) # Frequency translating FIR filter fxlate = filter.freq_xlating_fir_filter_ccc( decimation=2, taps=filter_taps, center_freq=lo_offset_freq, sampling_freq=src_samp_rate) # Wideband FM demodulator wbfm = analog.fm_demod_cf(channel_rate=src_samp_rate / 2, audio_decim=5, deviation=75000, audio_pass=15000, audio_stop=16000, gain=1.0, tau=75E-6) # Rational resampler resamp = filter.rational_resampler_fff(interpolation=snd_card_rate, decimation=src_samp_rate / 10) # Multiply for voulme control volume = blocks.multiply_const_ff(10**(volume_dB / 20) - 1) # Sound card sink sndcard = audio.sink(snd_card_rate, '', True) # Connect the blocks for audio monitoring self.connect(self.src, fxlate, wbfm, resamp, volume, sndcard) # Calculate power for RSSI c2magsqr = blocks.complex_to_mag_squared(1) # Integrate for mean power and decimate down to 1 Hz integrator = blocks.integrate_ff(decim=src_samp_rate / 2) # Take 10*Log10 and offset for calibrated power and src gain logten = blocks.nlog10_ff(10, 1, rssi_cal_offset_dB - src_gain_dB) # Probe the RSSI signal self.rssi = blocks.probe_signal_f() # Connect the blocks for the RSSI self.connect(fxlate, c2magsqr, integrator, logten, self.rssi)
def __init__(self, fftsize, samp_rate, gain, c_freq, windows): gr.top_block.__init__(self, "CalculateFFT") #Class variables self.samp_rate = samp_rate self.gain = gain self.fftsize = fftsize self.c_freq = c_freq self.dump1 = "/tmp/ramdisk/dump1" #View as null sinks self.dump2 = "/tmp/ramdisk/dump2" self.alpha = 0.01 #Integrate 100 FFTS 0.01 self.N = 100 #100 self.probe_var = probe_var = 0 blackman_harris = window.blackmanharris(self.fftsize) hanning = window.hanning(self.fftsize) rectangular = window.rectangular(self.fftsize) self.window = blackman_harris #Default window self.select_window = windows ###Selectable FFT Windows### if self.select_window == "blackman-harris": self.window = blackman_harris elif self.select_window == "hanning": self.window = hanning elif self.select_window == "rectangular": self.window = rectangular ########## GNURADIO BLOCKS ######### #################################### self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "master_clock_rate=120e6")), #Set the master_clock_rate, default = 200 MHz, alt 184.32 MHz and 120 MHz (Set) uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) #Configure USRP channel 0 self.uhd_usrp_source_0.set_samp_rate(self.samp_rate) self.uhd_usrp_source_0.set_center_freq(self.c_freq, 0) self.uhd_usrp_source_0.set_gain(self.gain, 0) self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 0) self.uhd_usrp_source_0.set_clock_source('internal', 0) #Signal and reference file sinks self.signal_file_sink_1 = blocks.file_sink(gr.sizeof_float*1, self.dump1, False) self.signal_file_sink_1.set_unbuffered(False) self.signal_file_sink_2 = blocks.file_sink(gr.sizeof_float*1, self.dump2, False) self.signal_file_sink_2.set_unbuffered(False) #Selector for GPIO switch self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_float*1, num_inputs=1, num_outputs=2+1, #+1 for the null sink input_index=0, output_index=0, ) self.blocks_null_sink = blocks.null_sink(gr.sizeof_float*1) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(self.alpha, self.fftsize) self.fft_vxx_0 = fft.fft_vcc(self.fftsize, True, (self.window), True, 1) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, self.fftsize) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, self.fftsize) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float*self.fftsize, self.N) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(self.fftsize) #Block connections self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blks2_selector_0, 0)) #Selector connections self.connect((self.blks2_selector_0, 1), (self.signal_file_sink_1, 0)) self.connect((self.blks2_selector_0, 2), (self.signal_file_sink_2, 0)) #Null sink connection self.connect((self.blks2_selector_0, 0), (self.blocks_null_sink, 0)) #PROBE SAMPLES self.probe_signal = blocks.probe_signal_f() self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.connect((self.blocks_complex_to_mag_0, 0), (self.probe_signal, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_mag_0, 0)) #Probe update rate def _probe_var_probe(): while True: val = self.probe_signal.level() try: self.set_probe_var(val) except AttributeError: pass time.sleep(10 / (self.samp_rate)) #Update probe variabel every 10/samp_rate seconds _probe_var_thread = threading.Thread(target=_probe_var_probe) _probe_var_thread.daemon = True _probe_var_thread.start()
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source(args=options.args) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36. / 25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc(4, math.pi / 4, math.pi / 100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2. / math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port) + ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect((self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1. / self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [ self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels ] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread( target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel / (2 * math.pi)) samp_afc = self.srate_channel * self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1. / samp_afc * self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % ( err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source( args=options.args ) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36./25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % (err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, ebn0_db=3.3, spread_factor=2**10, tailbiting=True): gr.top_block.__init__(self, "LECIM DSSS TxRx BER test") Qt.QWidget.__init__(self) self.setWindowTitle("LECIM DSSS TxRx BER test") qtgui.util.check_set_qss() 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", "dsss_sim_perfekt_sync_fg") self.restoreGeometry(self.settings.value("geometry").toByteArray()) self._lock = threading.RLock() ################################################## # Parameters ################################################## self.ebn0_db = ebn0_db self.spread_factor = spread_factor self.tailbiting = tailbiting ################################################## # Variables ################################################## self.cc_poly = cc_poly = [121, 91] self.pdu_size = pdu_size = 32 self.noise = noise = ( np.sqrt(1 * spread_factor / 10**(ebn0_db / 10.0)) * 1.0) self.len_tag_var = len_tag_var = "packet_len" self.cc_encoder_terminated = cc_encoder_terminated = map( (lambda a: fec.cc_encoder_make(32 * 8, 7, 2, (cc_poly), 0, fec. CC_TERMINATED, True)), range(0, 1)) self.cc_encoder_tailbiting = cc_encoder_tailbiting = map( (lambda a: fec.cc_encoder_make(32 * 8, 7, 2, (cc_poly), 0, fec. CC_TAILBITING, False)), range(0, 1)) self.cc_decoder_terminated = cc_decoder_terminated = map( (lambda a: fec.cc_decoder.make(32 * 8, 7, 2, (cc_poly), 0, -1, fec. CC_TERMINATED, True)), range(0, 1)) self.cc_decoder_tailbiting = cc_decoder_tailbiting = map( (lambda a: fec.cc_decoder.make(32 * 8, 7, 2, (cc_poly), 0, -1, fec. CC_TAILBITING, False)), range(0, 1)) ################################################## # Blocks ################################################## self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0.set_title("BER") labels = ['', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0.set_min(i, -1) self.qtgui_number_sink_0_0.set_max(i, 1) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_0_win) self.probe_ber_running = blocks.probe_signal_f() self.lpwan_dsss_spreading_bb_0 = lpwan.dsss_spreading_bb( len_tag_var, spread_factor, 123456, False, 0, 0) self.lpwan_dsss_normalize_ff_0 = lpwan.dsss_normalize_ff(len_tag_var) self.lpwan_dsss_interleaver_bb_0 = lpwan.dsss_interleaver_bb( len_tag_var) self.lpwan_dsss_diff_decoding_ff_0 = lpwan.dsss_diff_decoding_ff( len_tag_var, False, 0) self.lpwan_dsss_diff_coding_bb_0 = lpwan.dsss_diff_coding_bb( len_tag_var) self.lpwan_dsss_despread_simple_cc_0 = lpwan.dsss_despread_simple_cc( len_tag_var, spread_factor, 123456, False, 0, 0) self.lpwan_dsss_deinterleaver_ff_0 = lpwan.dsss_deinterleaver_ff( len_tag_var) self.fec_extended_tagged_encoder_0 = fec.extended_tagged_encoder( encoder_obj_list=cc_encoder_tailbiting if tailbiting else cc_encoder_terminated, puncpat='11', lentagname=len_tag_var, mtu=32) self.fec_extended_tagged_decoder_0 = self.fec_extended_tagged_decoder_0 = fec_extended_tagged_decoder_0 = fec.extended_tagged_decoder( decoder_obj_list=cc_decoder_tailbiting if tailbiting else cc_decoder_terminated, ann=None, puncpat='11', integration_period=10000, lentagname=len_tag_var, mtu=32) self.fec_ber_running = fec.ber_bf(False, 100, -7.0) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( ([-1, 1]), 1) self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream( gr.sizeof_char, 1, pdu_size, len_tag_var) self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb( 1, 8, len_tag_var, False, gr.GR_LSB_FIRST) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb( 8, 1, len_tag_var, False, gr.GR_LSB_FIRST) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_add_xx_0 = blocks.add_vcc(1) (self.blocks_add_xx_0).set_min_output_buffer(2097152) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, 256, 10000000)), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, noise, rnd.randint(0, 10000)) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.lpwan_dsss_despread_simple_cc_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.lpwan_dsss_deinterleaver_ff_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.fec_extended_tagged_encoder_0, 0)) self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.fec_ber_running, 1)) self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.fec_ber_running, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.fec_ber_running, 0), (self.probe_ber_running, 0)) self.connect((self.fec_ber_running, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.fec_extended_tagged_decoder_0, 0), (self.blocks_repack_bits_bb_0_0, 0)) self.connect((self.fec_extended_tagged_encoder_0, 0), (self.lpwan_dsss_interleaver_bb_0, 0)) self.connect((self.lpwan_dsss_deinterleaver_ff_0, 0), (self.lpwan_dsss_normalize_ff_0, 0)) self.connect((self.lpwan_dsss_despread_simple_cc_0, 0), (self.lpwan_dsss_diff_decoding_ff_0, 0)) self.connect((self.lpwan_dsss_diff_coding_bb_0, 0), (self.lpwan_dsss_spreading_bb_0, 0)) self.connect((self.lpwan_dsss_diff_decoding_ff_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.lpwan_dsss_interleaver_bb_0, 0), (self.lpwan_dsss_diff_coding_bb_0, 0)) self.connect((self.lpwan_dsss_normalize_ff_0, 0), (self.fec_extended_tagged_decoder_0, 0)) self.connect((self.lpwan_dsss_spreading_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (dab.parameters.dab_parameters) @param rx_params RX parameter object (dab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature2(2, 2, gr.sizeof_float*self.dp.num_carriers*2, gr.sizeof_char)) # output signature else: gr.hier_block2.__init__(self,"ofdm_demod", gr.io_signature (1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature2(2, 2, gr.sizeof_char*self.dp.num_carriers/4, gr.sizeof_char)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print "--> RX filter enabled" lowpass_taps = filter.firdes_low_pass(1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print "--> dynamic sample rate correction enabled" self.rate_detect_ns = dab.detect_null(dp.ns_length, False) self.rate_estimator = dab.estimate_sample_rate_bf(dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = dab.fractional_interpolator_triggered_update_cc(0,1) self.connect(self.rate_detect_ns, (self.resample,1)) self.updater = Timer(0.1,self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1: if verbose: print "--> static sample rate correction enabled" self.resample = gr.fractional_interpolator_cc(0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = dab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = dab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = dab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = dab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = dab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print "--> magnitude equalization enabled" self.equalizer = dab.magnitude_equalizer_vcc(dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = dab.frequency_interleaver_vcc(dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = dab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect((self.sync, 0), (self.sampler, 0), self.fft, (self.cfs, 0), self.phase_diff, (self.remove_pilot,0)) if self.rp.equalize_magnitude: self.connect((self.remove_pilot,0), (self.equalizer,0), self.deinterleave) else: self.connect((self.remove_pilot,0), self.deinterleave) if self.rp.softbits: if verbose: print "--> using soft bits" self.softbit_interleaver = dab.complex_to_interleaved_float_vcf(self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self,0)) else: self.connect(self.deinterleave, self.demapper, (self,0)) # control stream self.connect((self.sync, 1), (self.sampler, 1), (self.cfs, 1), (self.remove_pilot,1)) if self.rp.equalize_magnitude: self.connect((self.remove_pilot,1), (self.equalizer,1), (self,1)) else: self.connect((self.remove_pilot,1), (self,1)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n(gr.sizeof_gr_complex*self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = dab.modulo_ff(pi/2) self.phase_var_avg_mod = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd([rp.phase_var_estimate_alpha], [0,1-rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot,0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg,0), (self.phase_var_sqr,0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg,1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr,1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = dab.measure_processing_rate(gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect(self.fft, blocks.file_sink(gr.sizeof_gr_complex*dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect((self.cfs,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect(self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect((self.remove_pilot,0), blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot,1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect(self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect(self.equalizer, blocks.file_sink(gr.sizeof_gr_complex*dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect(self.softbit_interleaver, blocks.file_sink(gr.sizeof_float*dp.num_carriers*2, "debug/softbits.dat"))
def __init__( self, label="IQ", sampRate=1.0, centerFreq=0.0, fftPlotRange=[-120, 0], fftSizeN=10, rmsGainRange=[0, 11], enableSpectrum=True, enableTimeWaveform=True, enableWaterfall=True, enableRssiDisplay=True, enableRssi=True, fftGainLog=0.0, rssiPollRate=1.0, updatePeriod=0.1, rmsAvgGainExpInit=5, ): gr.hier_block2.__init__( self, "Freq and Time Sink (%s)" % (label, ), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), ) self.message_port_register_hier_out("freq") self.message_port_register_hier_in("freq") Qt.QWidget.__init__(self) self.top_layout = Qt.QVBoxLayout() self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.setLayout(self.top_layout) self._lock = threading.RLock() ################################################## # Parameters ################################################## self.centerFreq = centerFreq self.enableRssiDisplay = enableRssiDisplay and enableRssi self.enableRssi = enableRssi self.enableSpectrum = enableSpectrum self.enableTimeWaveform = enableTimeWaveform self.enableWaterfall = enableWaterfall self.fftGainLog = fftGainLog self.fftPlotRange = fftPlotRange self.fftSizeN = fftSizeN self.label = label self.rmsGainRange = rmsGainRange self.rssiPollRate = rssiPollRate self.sampRate = sampRate self.updatePeriod = updatePeriod ################################################## # Variables ################################################## self.rssi = rssi = "n/a" self.rmsAvgGainExp = rmsAvgGainExp = rmsAvgGainExpInit self.fftSize = fftSize = int(2**fftSizeN) self.fftGainLinear = fftGainLinear = 10.0**(float(fftGainLog) / 20) self.N = N = int(sampRate * updatePeriod) ################################################## # Blocks ################################################## self.tabs = Qt.QTabWidget() if self.enableSpectrum: self.tabs_widget_0 = Qt.QWidget() self.tabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_0) self.tabs_grid_layout_0 = Qt.QGridLayout() self.tabs_layout_0.addLayout(self.tabs_grid_layout_0) self.tabs.addTab(self.tabs_widget_0, "%s Spectrum" % (label, )) if self.enableWaterfall: self.tabs_widget_1 = Qt.QWidget() self.tabs_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_1) self.tabs_grid_layout_1 = Qt.QGridLayout() self.tabs_layout_1.addLayout(self.tabs_grid_layout_1) self.tabs.addTab(self.tabs_widget_1, "%s Waterfall" % (label, )) if self.enableTimeWaveform: self.tabs_widget_2 = Qt.QWidget() self.tabs_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_2) self.tabs_grid_layout_2 = Qt.QGridLayout() self.tabs_layout_2.addLayout(self.tabs_grid_layout_2) self.tabs.addTab(self.tabs_widget_2, "%s Time Waveform" % (label, )) self.top_grid_layout.addWidget(self.tabs, 0, 0, 1, 2) if self.enableRssiDisplay: self._rmsAvgGainExp_range = Range(rmsGainRange[0], rmsGainRange[1], 1, rmsAvgGainExp, 200) self._rmsAvgGainExp_win = RangeWidget( self._rmsAvgGainExp_range, self.set_rmsAvgGainExp, "Avg\nGain\n2^-[%s]" % (",".join(str(i) for i in rmsGainRange)), "dial", float) self.top_grid_layout.addWidget(self._rmsAvgGainExp_win, 1, 1, 1, 1) if self.enableWaterfall: self.waterfallSink = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype centerFreq, #fc sampRate, #bw "", #name 1 #number of inputs ) self.waterfallSink.set_update_time(updatePeriod) self.waterfallSink.enable_grid(True) if not True: self.waterfallSink.disable_legend() if complex == type(float()): self.waterfallSink.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [3, 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.waterfallSink.set_line_label(i, "Data {0}".format(i)) else: self.waterfallSink.set_line_label(i, labels[i]) self.waterfallSink.set_color_map(i, colors[i]) self.waterfallSink.set_line_alpha(i, alphas[i]) self.waterfallSink.set_intensity_range(fftPlotRange[0] + 20, fftPlotRange[1]) self._waterfallSink_win = sip.wrapinstance( self.waterfallSink.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_1.addWidget(self._waterfallSink_win, 0, 0, 1, 1) if self.enableTimeWaveform: self.timeSink = qtgui.time_sink_c( fftSize, #size sampRate, #samp_rate "", #name 1 #number of inputs ) self.timeSink.set_update_time(updatePeriod) self.timeSink.set_y_axis(-1, 1) self.timeSink.set_y_label("Amplitude", "") self.timeSink.enable_tags(-1, True) self.timeSink.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.timeSink.enable_autoscale(True) self.timeSink.enable_grid(True) self.timeSink.enable_control_panel(False) if not False: self.timeSink.disable_legend() labels = ["I", "Q", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "green", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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(2 * 1): if len(labels[i]) == 0: if (i % 2 == 0): self.timeSink.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.timeSink.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.timeSink.set_line_label(i, labels[i]) self.timeSink.set_line_width(i, widths[i]) self.timeSink.set_line_color(i, colors[i]) self.timeSink.set_line_style(i, styles[i]) self.timeSink.set_line_marker(i, markers[i]) self.timeSink.set_line_alpha(i, alphas[i]) self._timeSink_win = sip.wrapinstance(self.timeSink.pyqwidget(), Qt.QWidget) self.tabs_layout_2.addWidget(self._timeSink_win) if self.enableRssi: self.rmsCalc = blocks.rms_cf(2**-rmsAvgGainExp) self.nLog10 = blocks.nlog10_ff(20, 1, 0) self.keepOneInN = blocks.keep_one_in_n(gr.sizeof_float * 1, N if N > 0 else 1) self.rssiProbe = blocks.probe_signal_f() def _rssi_probe(): while True: val = self.rssiProbe.level() try: self.set_rssi(val) except AttributeError: pass time.sleep(1.0 / (rssiPollRate)) _rssi_thread = threading.Thread(target=_rssi_probe) _rssi_thread.daemon = True _rssi_thread.start() if self.enableRssiDisplay: self.numberSInk = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.numberSInk.set_update_time(updatePeriod) self.numberSInk.set_title("") labels = [ "\n".join((label, "RMS Mag")), "NBDDC", "", "", "", "", "", "", "", "" ] units = ["dBfs", "dBfs", "", "", "", "", "", "", "", ""] colors = [ ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black") ] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.numberSInk.set_min(i, fftPlotRange[0]) self.numberSInk.set_max(i, fftPlotRange[1]) self.numberSInk.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.numberSInk.set_label(i, "Data {0}".format(i)) else: self.numberSInk.set_label(i, labels[i]) self.numberSInk.set_unit(i, units[i]) self.numberSInk.set_factor(i, factor[i]) self.numberSInk.enable_autoscale(False) self._numberSInk_win = sip.wrapinstance( self.numberSInk.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._numberSInk_win, 1, 0, 1, 1) if self.enableSpectrum: self.freqSink = qtgui.freq_sink_c( fftSize, #size firdes.WIN_BLACKMAN_hARRIS, #wintype centerFreq, #fc sampRate, #bw "", #name 1 #number of inputs ) self.freqSink.set_update_time(updatePeriod) self.freqSink.set_y_axis(fftPlotRange[0], fftPlotRange[1]) self.freqSink.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.freqSink.enable_autoscale(False) self.freqSink.enable_grid(True) self.freqSink.set_fft_average(1.0) self.freqSink.enable_control_panel(False) if not False: self.freqSink.disable_legend() if complex == type(float()): self.freqSink.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "dark red", "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.freqSink.set_line_label(i, "Data {0}".format(i)) else: self.freqSink.set_line_label(i, labels[i]) self.freqSink.set_line_width(i, widths[i]) self.freqSink.set_line_color(i, colors[i]) self.freqSink.set_line_alpha(i, alphas[i]) self._freqSink_win = sip.wrapinstance(self.freqSink.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._freqSink_win, 0, 0, 1, 2) if self.enableSpectrum or self.enableWaterfall: self.fftGainMultiplier = blocks.multiply_const_vcc( (fftGainLinear, )) _fftsize_probe_thread = threading.Thread(target=self.checkFftScale) _fftsize_probe_thread.daemon = True _fftsize_probe_thread.start() ################################################## # Connections ################################################## if self.enableSpectrum or self.enableWaterfall: self.connect((self, 0), (self.fftGainMultiplier, 0)) if self.enableSpectrum: self.connect((self.fftGainMultiplier, 0), (self.freqSink, 0)) self.msg_connect((self, 'freq'), (self.freqSink, 'freq')) self.msg_connect((self.freqSink, 'freq'), (self, 'freq')) if self.enableWaterfall: self.connect((self.fftGainMultiplier, 0), (self.waterfallSink, 0)) self.msg_connect((self, 'freq'), (self.waterfallSink, 'freq')) if self.enableRssi: self.connect((self, 0), (self.rmsCalc, 0)) self.connect((self.rmsCalc, 0), (self.keepOneInN, 0)) self.connect((self.keepOneInN, 0), (self.nLog10, 0)) self.connect((self.nLog10, 0), (self.rssiProbe, 0)) if self.enableRssiDisplay: self.connect((self.nLog10, 0), (self.numberSInk, 0)) if self.enableTimeWaveform: self.connect((self, 0), (self.timeSink, 0))
def __init__(self, fftsize, samp_rate, gain, c_freq): gr.top_block.__init__(self, "Receiver") #Class variables self.samp_rate = samp_rate self.gain = gain self.fftsize = fftsize self.c_freq = c_freq self.dump1 = "/tmp/ramdisk/dump1" #View as null sinks self.dump2 = "/tmp/ramdisk/dump2" self.dump3 = "/tmp/ramdisk/dump3" self.dump4 = "/tmp/ramdisk/dump4" self.alpha = 0.01 #Integrate 100 FFTS 0.01 self.N = 100 #100 self.probe_var = probe_var = 0 self.probe_var_1 = probe_var_1 = 0 ########## GNURADIO BLOCKS ######### #################################### self.uhd_usrp_source_0 = uhd.usrp_source( ",".join( ("", "") ), #Set the master_clock_rate, default = 200 MHz, alt 184.32 MHz and 120 MHz (Set) uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Configure USRP channel 0 self.uhd_usrp_source_0.set_antenna("RX2", 0) self.uhd_usrp_source_0.set_samp_rate(self.samp_rate) self.uhd_usrp_source_0.set_center_freq(self.c_freq, 0) self.uhd_usrp_source_0.set_gain(self.gain, 0) self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 0) self.uhd_usrp_source_0.set_clock_source('external') #Configure USRP channel 1 self.uhd_usrp_source_0.set_antenna("RX2", 1) self.uhd_usrp_source_0.set_center_freq(self.c_freq, 1) self.uhd_usrp_source_0.set_gain(self.gain, 1) self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 1) #self.uhd_usrp_source_0.set_clock_source('external', 1) #Signal and reference file sinks channel 0 self.signal_file_sink_1 = blocks.file_sink(gr.sizeof_float * 1, self.dump1, False) self.signal_file_sink_1.set_unbuffered(False) self.signal_file_sink_2 = blocks.file_sink(gr.sizeof_float * 1, self.dump2, False) self.signal_file_sink_2.set_unbuffered(False) #Signal and reference file sinks channel 1 self.signal_file_sink_3 = blocks.file_sink(gr.sizeof_float * 1, self.dump3, False) self.signal_file_sink_3.set_unbuffered(False) self.signal_file_sink_4 = blocks.file_sink(gr.sizeof_float * 1, self.dump4, False) self.signal_file_sink_4.set_unbuffered(False) #Selector for GPIO switch channel 0 self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_float * 1, num_inputs=1, num_outputs=3, #+1 for the null sink input_index=0, output_index=0, ) #Selector for GPIO switch channel 1 self.blks2_selector_1 = grc_blks2.selector( item_size=gr.sizeof_float * 1, num_inputs=1, num_outputs=3, #+1 for the null sink input_index=0, output_index=0, ) #Div blocks channel 0 self.blocks_null_sink = blocks.null_sink(gr.sizeof_float * 1) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( self.alpha, self.fftsize) self.fft_vxx_0 = fft.fft_vcc(self.fftsize, True, (window.blackmanharris(self.fftsize)), True, 1) #Last argument threads, 1 default self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, self.fftsize) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, self.fftsize) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * self.fftsize, self.N) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( self.fftsize) #Div blocks channel 1 self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_float * 1) self.single_pole_iir_filter_xx_1 = filter.single_pole_iir_filter_ff( self.alpha, self.fftsize) self.fft_vxx_1 = fft.fft_vcc(self.fftsize, True, (window.blackmanharris(self.fftsize)), True, 1) self.blocks_vector_to_stream_1 = blocks.vector_to_stream( gr.sizeof_float * 1, self.fftsize) self.blocks_stream_to_vector_1 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, self.fftsize) self.blocks_keep_one_in_n_1 = blocks.keep_one_in_n( gr.sizeof_float * self.fftsize, self.N) self.blocks_complex_to_mag_squared_1 = blocks.complex_to_mag_squared( self.fftsize) #Block connections channel 0 self.connect((self.uhd_usrp_source_0, 0), self.blocks_stream_to_vector_0) self.connect(self.blocks_stream_to_vector_0, self.fft_vxx_0) self.connect(self.fft_vxx_0, self.blocks_complex_to_mag_squared_0) self.connect(self.blocks_complex_to_mag_squared_0, self.single_pole_iir_filter_xx_0) self.connect(self.single_pole_iir_filter_xx_0, self.blocks_keep_one_in_n_0) self.connect(self.blocks_keep_one_in_n_0, self.blocks_vector_to_stream_0) self.connect(self.blocks_vector_to_stream_0, self.blks2_selector_0) #Block connections channel 1 self.connect((self.uhd_usrp_source_0, 1), self.blocks_stream_to_vector_1) self.connect(self.blocks_stream_to_vector_1, self.fft_vxx_1) self.connect(self.fft_vxx_1, self.blocks_complex_to_mag_squared_1) self.connect(self.blocks_complex_to_mag_squared_1, self.single_pole_iir_filter_xx_1) self.connect(self.single_pole_iir_filter_xx_1, self.blocks_keep_one_in_n_1) self.connect(self.blocks_keep_one_in_n_1, self.blocks_vector_to_stream_1) self.connect(self.blocks_vector_to_stream_1, self.blks2_selector_1) #Selector connections channel 0 self.connect((self.blks2_selector_0, 1), self.signal_file_sink_1) self.connect((self.blks2_selector_0, 2), self.signal_file_sink_2) #Selector connections channel 1 self.connect((self.blks2_selector_1, 1), self.signal_file_sink_3) self.connect((self.blks2_selector_1, 2), self.signal_file_sink_4) #Null sink connection channel 0 self.connect((self.blks2_selector_0, 0), self.blocks_null_sink) #Null sink connection channel 1 self.connect((self.blks2_selector_1, 0), self.blocks_null_sink_1) #########PROBE SAMPLES channel 0########## self.probe_signal = blocks.probe_signal_f() self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.probe_signal, 0)) #########PROBE SAMPLES channel 1########## self.probe_signal_1 = blocks.probe_signal_f() self.blocks_complex_to_mag_1 = blocks.complex_to_mag(1) self.connect((self.uhd_usrp_source_0, 1), (self.blocks_complex_to_mag_1, 0)) self.connect((self.blocks_complex_to_mag_1, 0), (self.probe_signal_1, 0)) #Probe update rate def _probe_var_probe(): while True: val = self.probe_signal.level() try: self.set_probe_var(val) except AttributeError: pass time.sleep(10 / (self.samp_rate) ) #Update probe variabel every 10/samp_rate seconds _probe_var_thread = threading.Thread(target=_probe_var_probe) _probe_var_thread.daemon = True _probe_var_thread.start() #Probe update rate def _probe_var_probe_1(): while True: val = self.probe_signal_1.level() try: self.set_probe_var_1(val) except AttributeError: pass time.sleep(10 / (self.samp_rate) ) #Update probe variabel every 10/samp_rate seconds _probe_var_thread_1 = threading.Thread(target=_probe_var_probe_1) _probe_var_thread_1.daemon = True _probe_var_thread_1.start()
def __init__(self): 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()) ################################################## # Variables ################################################## self.offset_tune_freq = offset_tune_freq = -10E3 self.band_freq = band_freq = 7.055E6 self.usrp_clk_rate = usrp_clk_rate = 200E6 self.usrp_ask_freq = usrp_ask_freq = band_freq+offset_tune_freq self.usrp_DDC_freq = usrp_DDC_freq = np.round(usrp_ask_freq/usrp_clk_rate* 2**32)/2**32 * usrp_clk_rate self.fine_tuner_freq = fine_tuner_freq = 0 self.coarse_tuner_freq = coarse_tuner_freq = 0 self.samp_rate = samp_rate = 250000 self.lo_freq = lo_freq = usrp_DDC_freq + coarse_tuner_freq + fine_tuner_freq - offset_tune_freq self.record_check_box = record_check_box = False self.file_name_string = file_name_string = str(int(time.mktime(time.gmtime())))+"UTC_"+'{:.6f}'.format(lo_freq)+"Hz"+"_"+str(int(samp_rate/100))+"sps"+".raw" self.variable_function_probe_0 = variable_function_probe_0 = 0 self.file_name = file_name = file_name_string if record_check_box==True else "/dev/null" self.volume = volume = 5.0 self.rx_power_label = rx_power_label = '{:.1f}'.format(variable_function_probe_0) self.lo_freq_label = lo_freq_label = '{:.6f}'.format(lo_freq) self.gain_offset_dB = gain_offset_dB = 18.86 self.filter_taps = filter_taps = firdes.low_pass(1.0,2.5,0.1,0.02,firdes.WIN_HAMMING) self.filename_label = filename_label = file_name self.cw_filter_bw = cw_filter_bw = 1000 self.RX_power_offset_dB = RX_power_offset_dB = -35.2 ################################################## # Blocks ################################################## self._volume_layout = Qt.QVBoxLayout() self._volume_knob = Qwt.QwtKnob() self._volume_knob.setRange(0, 10.0, 1.0) self._volume_knob.setValue(self.volume) self._volume_knob.valueChanged.connect(self.set_volume) self._volume_layout.addWidget(self._volume_knob) self._volume_label = Qt.QLabel("Volume") self._volume_label.setAlignment(Qt.Qt.AlignTop | Qt.Qt.AlignHCenter) self._volume_layout.addWidget(self._volume_label) self.top_grid_layout.addLayout(self._volume_layout, 5,6,1,1) self._cw_filter_bw_options = (100, 500, 1000, ) self._cw_filter_bw_labels = ("100 Hz", "500 Hz", "1 kHz", ) self._cw_filter_bw_tool_bar = Qt.QToolBar(self) self._cw_filter_bw_tool_bar.addWidget(Qt.QLabel("CW Filter BW"+": ")) self._cw_filter_bw_combo_box = Qt.QComboBox() self._cw_filter_bw_tool_bar.addWidget(self._cw_filter_bw_combo_box) for label in self._cw_filter_bw_labels: self._cw_filter_bw_combo_box.addItem(label) self._cw_filter_bw_callback = lambda i: Qt.QMetaObject.invokeMethod(self._cw_filter_bw_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._cw_filter_bw_options.index(i))) self._cw_filter_bw_callback(self.cw_filter_bw) self._cw_filter_bw_combo_box.currentIndexChanged.connect( lambda i: self.set_cw_filter_bw(self._cw_filter_bw_options[i])) self.top_grid_layout.addWidget(self._cw_filter_bw_tool_bar, 5,5,1,1) self.blocks_probe_signal_x_0 = blocks.probe_signal_f() def _variable_function_probe_0_probe(): while True: val = self.blocks_probe_signal_x_0.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (5)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "addr=192.168.40.2")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec("B:A", 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(usrp_ask_freq, 0) self.uhd_usrp_source_0.set_gain(6, 0) self._rx_power_label_tool_bar = Qt.QToolBar(self) if None: self._rx_power_label_formatter = None else: self._rx_power_label_formatter = lambda x: x self._rx_power_label_tool_bar.addWidget(Qt.QLabel("RX Power (dBm)"+": ")) self._rx_power_label_label = Qt.QLabel(str(self._rx_power_label_formatter(self.rx_power_label))) self._rx_power_label_tool_bar.addWidget(self._rx_power_label_label) self.top_grid_layout.addWidget(self._rx_power_label_tool_bar, 4,7,1,1) _record_check_box_check_box = Qt.QCheckBox("Record") self._record_check_box_choices = {True: True, False: False} self._record_check_box_choices_inv = dict((v,k) for k,v in self._record_check_box_choices.iteritems()) self._record_check_box_callback = lambda i: Qt.QMetaObject.invokeMethod(_record_check_box_check_box, "setChecked", Qt.Q_ARG("bool", self._record_check_box_choices_inv[i])) self._record_check_box_callback(self.record_check_box) _record_check_box_check_box.stateChanged.connect(lambda i: self.set_record_check_box(self._record_check_box_choices[bool(i)])) self.top_grid_layout.addWidget(_record_check_box_check_box, 6,5,1,1) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=48000, decimation=2500, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band Waterfall", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0.enable_grid(False) if complex == type(float()): self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [5, 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_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-100, -70) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4,0,3,5) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype lo_freq, #fc samp_rate/100, #bw str(samp_rate/100) + " Hz Channel Spectrum", #name 2 #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(-120, -70) 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(True) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) if complex == type(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(2): 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_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 0,5,3,5) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band Spectrum", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-110, -60) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.2) if complex == type(float()): self.qtgui_freq_sink_x_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.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,3,5) self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate/100, 0.9*cw_filter_bw, 0.1*cw_filter_bw, firdes.WIN_BLACKMAN, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 10**(gain_offset_dB/20), samp_rate, 100E3, 20E3, firdes.WIN_HAMMING, 6.76)) self._lo_freq_label_tool_bar = Qt.QToolBar(self) if None: self._lo_freq_label_formatter = None else: self._lo_freq_label_formatter = lambda x: x self._lo_freq_label_tool_bar.addWidget(Qt.QLabel("LO Freq (Hz)"+": ")) self._lo_freq_label_label = Qt.QLabel(str(self._lo_freq_label_formatter(self.lo_freq_label))) self._lo_freq_label_tool_bar.addWidget(self._lo_freq_label_label) self.top_grid_layout.addWidget(self._lo_freq_label_tool_bar, 4,6,1,1) self.hilbert_fc_0_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.hilbert_fc_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(10, (filter_taps), lo_freq - usrp_DDC_freq, samp_rate) self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(10, (filter_taps)) self.fir_filter_xxx_0_0_0.declare_sample_delay(0) self._fine_tuner_freq_layout = Qt.QVBoxLayout() self._fine_tuner_freq_tool_bar = Qt.QToolBar(self) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_tool_bar) self._fine_tuner_freq_tool_bar.addWidget(Qt.QLabel("Fine Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._fine_tuner_freq_counter = qwt_counter_pyslot() self._fine_tuner_freq_counter.setRange(-500, 500, 1) self._fine_tuner_freq_counter.setNumButtons(2) self._fine_tuner_freq_counter.setValue(self.fine_tuner_freq) self._fine_tuner_freq_tool_bar.addWidget(self._fine_tuner_freq_counter) self._fine_tuner_freq_counter.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._fine_tuner_freq_slider.setRange(-500, 500, 1) self._fine_tuner_freq_slider.setValue(self.fine_tuner_freq) self._fine_tuner_freq_slider.setMinimumWidth(200) self._fine_tuner_freq_slider.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_slider) self.top_grid_layout.addLayout(self._fine_tuner_freq_layout, 3,5,1,5) self._filename_label_tool_bar = Qt.QToolBar(self) if None: self._filename_label_formatter = None else: self._filename_label_formatter = lambda x: x self._filename_label_tool_bar.addWidget(Qt.QLabel("File Name"+": ")) self._filename_label_label = Qt.QLabel(str(self._filename_label_formatter(self.filename_label))) self._filename_label_tool_bar.addWidget(self._filename_label_label) self.top_grid_layout.addWidget(self._filename_label_tool_bar, 6,6,1,3) self._coarse_tuner_freq_layout = Qt.QVBoxLayout() self._coarse_tuner_freq_tool_bar = Qt.QToolBar(self) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_tool_bar) self._coarse_tuner_freq_tool_bar.addWidget(Qt.QLabel("Coarse Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._coarse_tuner_freq_counter = qwt_counter_pyslot() self._coarse_tuner_freq_counter.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_counter.setNumButtons(2) self._coarse_tuner_freq_counter.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_tool_bar.addWidget(self._coarse_tuner_freq_counter) self._coarse_tuner_freq_counter.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._coarse_tuner_freq_slider.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_slider.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_slider.setMinimumWidth(50) self._coarse_tuner_freq_slider.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_slider) self.top_grid_layout.addLayout(self._coarse_tuner_freq_layout, 3,0,1,5) self.blocks_null_sink_1_0_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_null_sink_1_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, RX_power_offset_dB) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_integrate_xx_0 = blocks.integrate_ff(500) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, file_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_float_1_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self._band_freq_options = [1.84E6, 3.598E6, 7.055E6, 2.5E6, 5.0E6, 10.0E6] self._band_freq_labels = ["160m", "80m", "40m", "2.5 MHz", "5 MHz", "10 MHz"] self._band_freq_tool_bar = Qt.QToolBar(self) self._band_freq_tool_bar.addWidget(Qt.QLabel("Band"+": ")) self._band_freq_combo_box = Qt.QComboBox() self._band_freq_tool_bar.addWidget(self._band_freq_combo_box) for label in self._band_freq_labels: self._band_freq_combo_box.addItem(label) self._band_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._band_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._band_freq_options.index(i))) self._band_freq_callback(self.band_freq) self._band_freq_combo_box.currentIndexChanged.connect( lambda i: self.set_band_freq(self._band_freq_options[i])) self.top_grid_layout.addWidget(self._band_freq_tool_bar, 4,5,1,1) self.audio_sink_0 = audio.sink(48000, "", True) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate/100, analog.GR_COS_WAVE, 600, 1, 0) self.analog_agc3_xx_0 = analog.agc3_cc(1e-1, 1e-4, volume/100, 1, 1) self.analog_agc3_xx_0.set_max_gain(2**16) ################################################## # Connections ################################################## self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_float_1_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_float_0_0, 1), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_complex_to_float_0_0, 0), (self.blocks_null_sink_1_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_null_sink_1_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 1), (self.hilbert_fc_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 0), (self.hilbert_fc_0_0, 0)) self.connect((self.hilbert_fc_0_0, 0), (self.blocks_complex_to_float_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.qtgui_freq_sink_x_0_0, 1))
def __init__(self): gr.top_block.__init__(self, "Perseus Spectrum Sensing") Qt.QWidget.__init__(self) self.setWindowTitle("Perseus Spectrum Sensing") 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", "perseus_s_sensing") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.variable_funcion = variable_funcion = 0 self.show_test_statistics = show_test_statistics = False self.samp_rate = samp_rate = 20e6 self.packet_size = packet_size = 8192 self.oversampling = oversampling = 4 self.nfft = nfft = 2**15 self.freq_offset = freq_offset = variable_funcion self.decimation = decimation = 40 self.amplitude = amplitude = 0.125 self.RF_freq = RF_freq = 943e6 self.PSD_averaging = PSD_averaging = 600 self.ENABLE_TX1_variable_check_box = ENABLE_TX1_variable_check_box = True ################################################## # Blocks ################################################## self.probe = blocks.probe_signal_f() def _variable_funcion_probe(): while True: val = self.probe.level() try: self.set_variable_funcion(val) except AttributeError: pass time.sleep(1.0 / (0.1)) _variable_funcion_thread = threading.Thread( target=_variable_funcion_probe) _variable_funcion_thread.daemon = True _variable_funcion_thread.start() _show_test_statistics_check_box = Qt.QCheckBox( "Show Test Statistics (ReL and Rs)") self._show_test_statistics_choices = {True: True, False: False} self._show_test_statistics_choices_inv = dict( (v, k) for k, v in self._show_test_statistics_choices.iteritems()) self._show_test_statistics_callback = lambda i: Qt.QMetaObject.invokeMethod( _show_test_statistics_check_box, "setChecked", Qt.Q_ARG("bool", self._show_test_statistics_choices_inv[i])) self._show_test_statistics_callback(self.show_test_statistics) _show_test_statistics_check_box.stateChanged.connect( lambda i: self.set_show_test_statistics( self._show_test_statistics_choices[bool(i)])) self.top_layout.addWidget(_show_test_statistics_check_box) self.spectsensing_xs_plot_1 = spectsensing.xs_plot("") self._spectsensing_xs_plot_1_win = self.spectsensing_xs_plot_1 self.top_layout.addWidget(self._spectsensing_xs_plot_1_win) self.spectsensing_subband_selector_0 = spectsensing.subband_selector( 40, "Selection", 0, samp_rate) self.spectsensing_ss_subband_plot_0_0 = spectsensing.ss_subband_plot( show_test_statistics, "") self._spectsensing_ss_subband_plot_0_0_win = self.spectsensing_ss_subband_plot_0_0 self.top_layout.addWidget(self._spectsensing_ss_subband_plot_0_0_win) self.spectsensing_ss_pds_plot_0 = spectsensing.ss_pds_plot( nfft, samp_rate, 1024) self.spectsensing_ss_edge_plot_0 = spectsensing.ss_edge_plot( show_test_statistics, " ") self._spectsensing_ss_edge_plot_0_win = self.spectsensing_ss_edge_plot_0 self.top_layout.addWidget(self._spectsensing_ss_edge_plot_0_win) self.spectsensing_compute_statistics_0 = spectsensing.compute_statistics( nfft, samp_rate, 0.0065, 1e-9, 1e-9, 40, 54) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1020 * 64, #size samp_rate / 40, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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(2 * 1): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.nutaq_rtdex_source_S_S_0 = nutaq.rtdex_source( "nutaq_carrier_perseus_TX", gr.sizeof_short, 1, 0) self.nutaq_rtdex_source_S_S_0.set_type(0) self.nutaq_rtdex_source_S_S_0.set_packet_size(1300) self.nutaq_rtdex_source_S_S_0.set_channels("0") self.nutaq_rtdex_source_S_S = nutaq.rtdex_source( "nutaq_carrier_perseus_TX", gr.sizeof_short, 1, 3) self.nutaq_rtdex_source_S_S.set_type(0) self.nutaq_rtdex_source_S_S.set_packet_size(1200) self.nutaq_rtdex_source_S_S.set_channels("3") self.nutaq_rtdex_source_0_0_0 = nutaq.rtdex_source( "nutaq_carrier_perseus_TX", gr.sizeof_short, 1, 7) self.nutaq_rtdex_source_0_0_0.set_type(0) self.nutaq_rtdex_source_0_0_0.set_packet_size(packet_size) self.nutaq_rtdex_source_0_0_0.set_channels("2") (self.nutaq_rtdex_source_0_0_0).set_min_output_buffer(16384) self.nutaq_rtdex_sink_0 = nutaq.rtdex_sink("nutaq_carrier_perseus_TX", gr.sizeof_short, 1, 7) self.nutaq_rtdex_sink_0.set_type(0) self.nutaq_rtdex_sink_0.set_packet_size(packet_size) self.nutaq_rtdex_sink_0.set_channels("1") self.nutaq_radio420_tx_0_0 = nutaq.radio420_tx( "nutaq_carrier_perseus_TX", 2, 1) self.nutaq_radio420_tx_0_0.set_default_enable(1) self.nutaq_radio420_tx_0_0.set_default_tx_freq(RF_freq) self.nutaq_radio420_tx_0_0.set_default_reference(1) self.nutaq_radio420_tx_0_0.set_default_datarate(samp_rate * 2) self.nutaq_radio420_tx_0_0.set_default_calibrate(0) self.nutaq_radio420_tx_0_0.set_default_band(0) self.nutaq_radio420_tx_0_0.set_default_update_rate(1) self.nutaq_radio420_tx_0_0.set_default_tx_vga1_gain(-10) self.nutaq_radio420_tx_0_0.set_default_tx_vga2_gain(15) self.nutaq_radio420_tx_0_0.set_default_tx_gain3(3) self.nutaq_radio420_tx_0_0.set_default_tx_lpf_bandwidth(2) self.nutaq_radio420_tx_0_0.set_default_ref_clk_ctrl(0) self.nutaq_radio420_tx_0_0.set_default_rf_ctrl(0) self.nutaq_radio420_tx_0_0.set_default_tx_gain_ctrl(0) self.nutaq_radio420_tx_0_0.set_default_pll_cpld_ctrl(0) self.nutaq_radio420_tx_0 = nutaq.radio420_tx( "nutaq_carrier_perseus_TX", 1, 0) self.nutaq_radio420_tx_0.set_default_enable(1) self.nutaq_radio420_tx_0.set_default_tx_freq(RF_freq) self.nutaq_radio420_tx_0.set_default_reference(0) self.nutaq_radio420_tx_0.set_default_datarate(samp_rate * 2) self.nutaq_radio420_tx_0.set_default_calibrate(0) self.nutaq_radio420_tx_0.set_default_band(0) self.nutaq_radio420_tx_0.set_default_update_rate(1) self.nutaq_radio420_tx_0.set_default_tx_vga1_gain(-10) self.nutaq_radio420_tx_0.set_default_tx_vga2_gain(15) self.nutaq_radio420_tx_0.set_default_tx_gain3(3) self.nutaq_radio420_tx_0.set_default_tx_lpf_bandwidth(2) self.nutaq_radio420_tx_0.set_default_ref_clk_ctrl(0) self.nutaq_radio420_tx_0.set_default_rf_ctrl(0) self.nutaq_radio420_tx_0.set_default_tx_gain_ctrl(0) self.nutaq_radio420_tx_0.set_default_pll_cpld_ctrl(0) self.nutaq_radio420_rx_0_0 = nutaq.radio420_rx( "nutaq_carrier_perseus_TX", 2, 3) self.nutaq_radio420_rx_0_0.set_default_enable(1) self.nutaq_radio420_rx_0_0.set_default_rx_freq(RF_freq) self.nutaq_radio420_rx_0_0.set_default_reference(1) self.nutaq_radio420_rx_0_0.set_default_datarate(samp_rate * 2) self.nutaq_radio420_rx_0_0.set_default_calibrate(0) self.nutaq_radio420_rx_0_0.set_default_band(0) self.nutaq_radio420_rx_0_0.set_default_update_rate(1) self.nutaq_radio420_rx_0_0.set_default_rx_lna_gain(2) self.nutaq_radio420_rx_0_0.set_default_rx_vga1_gain(2) self.nutaq_radio420_rx_0_0.set_default_rx_gain2(0) self.nutaq_radio420_rx_0_0.set_default_rx_gain3(-8) self.nutaq_radio420_rx_0_0.set_default_rx_rf_filter(2) self.nutaq_radio420_rx_0_0.set_default_rx_lpf_bandwidth(2) self.nutaq_radio420_rx_0_0.set_default_ref_clk_ctrl(0) self.nutaq_radio420_rx_0_0.set_default_rf_ctrl(0) self.nutaq_radio420_rx_0_0.set_default_rx_gain_ctrl(0) self.nutaq_radio420_rx_0_0.set_default_pll_cpld_ctrl(0) self.nutaq_radio420_rx_0 = nutaq.radio420_rx( "nutaq_carrier_perseus_TX", 1, 2) self.nutaq_radio420_rx_0.set_default_enable(1) self.nutaq_radio420_rx_0.set_default_rx_freq(RF_freq) self.nutaq_radio420_rx_0.set_default_reference(0) self.nutaq_radio420_rx_0.set_default_datarate(samp_rate * 2) self.nutaq_radio420_rx_0.set_default_calibrate(0) self.nutaq_radio420_rx_0.set_default_band(0) self.nutaq_radio420_rx_0.set_default_update_rate(1) self.nutaq_radio420_rx_0.set_default_rx_lna_gain(2) self.nutaq_radio420_rx_0.set_default_rx_vga1_gain(2) self.nutaq_radio420_rx_0.set_default_rx_gain2(0) self.nutaq_radio420_rx_0.set_default_rx_gain3(-8) self.nutaq_radio420_rx_0.set_default_rx_rf_filter(2) self.nutaq_radio420_rx_0.set_default_rx_lpf_bandwidth(2) self.nutaq_radio420_rx_0.set_default_ref_clk_ctrl(0) self.nutaq_radio420_rx_0.set_default_rf_ctrl(0) self.nutaq_radio420_rx_0.set_default_rx_gain_ctrl(0) self.nutaq_radio420_rx_0.set_default_pll_cpld_ctrl(0) self.nutaq_custom_register_0_1_1 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 9) self.nutaq_custom_register_0_1_1.set_index(6) self.nutaq_custom_register_0_1_1.set_default_value(PSD_averaging) self.nutaq_custom_register_0_1_1.set_update_rate(1) self.nutaq_custom_register_0_1_0 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 7) self.nutaq_custom_register_0_1_0.set_index(2) self.nutaq_custom_register_0_1_0.set_update_rate(1) self.nutaq_custom_register_0_1 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 36) self.nutaq_custom_register_0_1.set_index(0) self.nutaq_custom_register_0_1.set_update_rate(1) self.nutaq_custom_register_0_0_0 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 8) self.nutaq_custom_register_0_0_0.set_index(3) self.nutaq_custom_register_0_0_0.set_default_value(7) self.nutaq_custom_register_0_0_0.set_update_rate(1) self.nutaq_custom_register_0_0 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 5) self.nutaq_custom_register_0_0.set_index(4) self.nutaq_custom_register_0_0.set_default_value(1) self.nutaq_custom_register_0_0.set_update_rate(1) self.nutaq_custom_register_0 = nutaq.custom_register( "nutaq_carrier_perseus_TX", 4) self.nutaq_custom_register_0.set_index(1) self.nutaq_custom_register_0.set_default_value(3) self.nutaq_custom_register_0.set_update_rate(1) self.nutaq_carrier_perseus_TX = nutaq.carrier( 0, "nutaq_carrier_perseus_TX", "192.168.0.101") self._freq_offset_range = Range(-1e7, 1e7, 1e4, variable_funcion, 200) self._freq_offset_win = RangeWidget(self._freq_offset_range, self.set_freq_offset, "freq_offset", "slider") self.top_layout.addWidget(self._freq_offset_win) self.digital_gmsk_mod_0 = digital.gmsk_mod( samples_per_symbol=oversampling, bt=0.71, verbose=False, log=False, ) self.digital_gmsk_demod_0 = digital.gmsk_demod( samples_per_symbol=oversampling, gain_mu=0.175, mu=0.5, omega_relative_limit=0.005, freq_error=0.0, verbose=False, log=False, ) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_char * 1, "192.168.0.100", 1234, 1472, True) self.blocks_throttle_0 = blocks.throttle( gr.sizeof_char * 1, 2 * 4e3 + 0 * samp_rate / 40 / (oversampling * 8 * 2), True) self.blocks_short_to_float_0_1_0 = blocks.short_to_float(1, 2**11) self.blocks_short_to_float_0_0_0_0 = blocks.short_to_float(1, 2**11) self.blocks_null_sink_1_3 = blocks.null_sink(gr.sizeof_float * 40) self.blocks_null_sink_1_2 = blocks.null_sink(gr.sizeof_float * 40) self.blocks_null_sink_1_1 = blocks.null_sink(gr.sizeof_float * 40) self.blocks_null_sink_1_0 = blocks.null_sink(gr.sizeof_float * 40) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_float * 40) self.blocks_multiply_const_vxx_0_3 = blocks.multiply_const_vff( (2.0**(16 * 2), )) self.blocks_multiply_const_vxx_0_2 = blocks.multiply_const_vcc( (amplitude, )) self.blocks_multiply_const_vxx_0_1_1 = blocks.multiply_const_vff( (2.0**(16 * 0), )) self.blocks_multiply_const_vxx_0_1_0_0 = blocks.multiply_const_vff( (2.0**(16 * 1), )) self.blocks_multiply_const_vxx_0_1_0 = blocks.multiply_const_vff( (2.0**(16 * 1), )) self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vff( (2.0**(16 * 0), )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (2.0**(16 * 2), )) self.blocks_interleave_0 = blocks.interleave(gr.sizeof_short * 1, 1) self.blocks_float_to_short_0_0_0 = blocks.float_to_short(1, 2**11 - 1) self.blocks_float_to_short_0_0 = blocks.float_to_short(1, 2**11 - 1) self.blocks_float_to_complex_0_0_0 = blocks.float_to_complex(1) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_char * 1, "/home/juan/Music/de_mi.mp3", True) self.blocks_deinterleave_0_0_1 = blocks.deinterleave( gr.sizeof_short * 1, 1) self.blocks_deinterleave_0_0_0 = blocks.deinterleave( gr.sizeof_short * 1, 1) self.blocks_deinterleave_0_0 = blocks.deinterleave( gr.sizeof_short * 1, 1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0_0 = blocks.add_vff(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b( grc_blks2.packet_encoder( samples_per_symbol=2, bits_per_symbol=8, preamble="", access_code="", pad_for_usrp=True, ), payload_length=128, ) self.blks2_packet_decoder_1 = grc_blks2.packet_demod_b( grc_blks2.packet_decoder( access_code="", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_1. recv_pkt(ok, payload), ), ) _ENABLE_TX1_variable_check_box_check_box = Qt.QCheckBox( "Enable Transmission") self._ENABLE_TX1_variable_check_box_choices = { True: True, False: False } self._ENABLE_TX1_variable_check_box_choices_inv = dict( (v, k) for k, v in self._ENABLE_TX1_variable_check_box_choices.iteritems()) self._ENABLE_TX1_variable_check_box_callback = lambda i: Qt.QMetaObject.invokeMethod( _ENABLE_TX1_variable_check_box_check_box, "setChecked", Qt.Q_ARG("bool", self._ENABLE_TX1_variable_check_box_choices_inv[i] )) self._ENABLE_TX1_variable_check_box_callback( self.ENABLE_TX1_variable_check_box) _ENABLE_TX1_variable_check_box_check_box.stateChanged.connect( lambda i: self.set_ENABLE_TX1_variable_check_box( self._ENABLE_TX1_variable_check_box_choices[bool(i)])) self.top_layout.addWidget(_ENABLE_TX1_variable_check_box_check_box) self.DataConversion_reint_short_float_0_3 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_2_0 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_2 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_1_0 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_1 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_0_0 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0_0 = DataConversion.reint_short_float( ) self.DataConversion_reint_short_float_0 = DataConversion.reint_short_float( ) self.DataConversion_eaver_resynchronizer_0_0 = DataConversion.eaver_resynchronizer( 1024) self.DataConversion_eaver_resynchronizer_0 = DataConversion.eaver_resynchronizer( decimation) ################################################## # Connections ################################################## self.msg_connect( (self.spectsensing_compute_statistics_0, 'spec_sens_pdus'), (self.spectsensing_ss_edge_plot_0, 'pdus')) self.msg_connect( (self.spectsensing_compute_statistics_0, 'spec_sens_pdus'), (self.spectsensing_ss_subband_plot_0_0, 'pdus')) self.msg_connect((self.spectsensing_ss_pds_plot_0, 'psd_pdu'), (self.spectsensing_xs_plot_1, 'pdus')) self.connect((self.DataConversion_eaver_resynchronizer_0, 1), (self.spectsensing_compute_statistics_0, 1)) self.connect((self.DataConversion_eaver_resynchronizer_0, 0), (self.spectsensing_compute_statistics_0, 0)) self.connect((self.DataConversion_eaver_resynchronizer_0_0, 0), (self.spectsensing_ss_pds_plot_0, 0)) self.connect((self.DataConversion_eaver_resynchronizer_0_0, 1), (self.spectsensing_ss_pds_plot_0, 1)) self.connect((self.DataConversion_reint_short_float_0, 0), (self.DataConversion_eaver_resynchronizer_0, 0)) self.connect((self.DataConversion_reint_short_float_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.DataConversion_reint_short_float_0_0_0, 0), (self.blocks_multiply_const_vxx_0_3, 0)) self.connect((self.DataConversion_reint_short_float_0_1, 0), (self.blocks_multiply_const_vxx_0_1_0, 0)) self.connect((self.DataConversion_reint_short_float_0_1_0, 0), (self.blocks_multiply_const_vxx_0_1_0_0, 0)) self.connect((self.DataConversion_reint_short_float_0_2, 0), (self.blocks_multiply_const_vxx_0_1, 0)) self.connect((self.DataConversion_reint_short_float_0_2_0, 0), (self.blocks_multiply_const_vxx_0_1_1, 0)) self.connect((self.DataConversion_reint_short_float_0_3, 0), (self.DataConversion_eaver_resynchronizer_0_0, 0)) self.connect((self.blks2_packet_decoder_1, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.DataConversion_eaver_resynchronizer_0, 1)) self.connect((self.blocks_add_xx_0_0, 0), (self.DataConversion_eaver_resynchronizer_0_0, 1)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_short_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_float_to_short_0_0_0, 0)) self.connect((self.blocks_deinterleave_0_0, 0), (self.DataConversion_reint_short_float_0, 0)) self.connect((self.blocks_deinterleave_0_0, 1), (self.DataConversion_reint_short_float_0_0, 0)) self.connect((self.blocks_deinterleave_0_0, 3), (self.DataConversion_reint_short_float_0_1, 0)) self.connect((self.blocks_deinterleave_0_0, 2), (self.DataConversion_reint_short_float_0_2, 0)) self.connect((self.blocks_deinterleave_0_0_0, 1), (self.blocks_short_to_float_0_0_0_0, 0)) self.connect((self.blocks_deinterleave_0_0_0, 0), (self.blocks_short_to_float_0_1_0, 0)) self.connect((self.blocks_deinterleave_0_0_1, 1), (self.DataConversion_reint_short_float_0_0_0, 0)) self.connect((self.blocks_deinterleave_0_0_1, 3), (self.DataConversion_reint_short_float_0_1_0, 0)) self.connect((self.blocks_deinterleave_0_0_1, 2), (self.DataConversion_reint_short_float_0_2_0, 0)) self.connect((self.blocks_deinterleave_0_0_1, 0), (self.DataConversion_reint_short_float_0_3, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_float_to_complex_0_0_0, 0), (self.digital_gmsk_demod_0, 0)) self.connect((self.blocks_float_to_complex_0_0_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_float_to_short_0_0, 0), (self.blocks_interleave_0, 0)) self.connect((self.blocks_float_to_short_0_0_0, 0), (self.blocks_interleave_0, 1)) self.connect((self.blocks_interleave_0, 0), (self.nutaq_rtdex_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_1_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_1_0_0, 0), (self.blocks_add_xx_0_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_1_1, 0), (self.blocks_add_xx_0_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_2, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_3, 0), (self.blocks_add_xx_0_0, 0)) self.connect((self.blocks_short_to_float_0_0_0_0, 0), (self.blocks_float_to_complex_0_0_0, 1)) self.connect((self.blocks_short_to_float_0_1_0, 0), (self.blocks_float_to_complex_0_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blks2_packet_encoder_0, 0)) self.connect((self.digital_gmsk_demod_0, 0), (self.blks2_packet_decoder_1, 0)) self.connect((self.digital_gmsk_mod_0, 0), (self.blocks_multiply_const_vxx_0_2, 0)) self.connect((self.nutaq_rtdex_source_0_0_0, 0), (self.blocks_deinterleave_0_0_0, 0)) self.connect((self.nutaq_rtdex_source_S_S, 0), (self.blocks_deinterleave_0_0, 0)) self.connect((self.nutaq_rtdex_source_S_S_0, 0), (self.blocks_deinterleave_0_0_1, 0)) self.connect((self.spectsensing_compute_statistics_0, 0), (self.blocks_null_sink_1, 0)) self.connect((self.spectsensing_compute_statistics_0, 5), (self.blocks_null_sink_1_0, 0)) self.connect((self.spectsensing_compute_statistics_0, 2), (self.blocks_null_sink_1_1, 0)) self.connect((self.spectsensing_compute_statistics_0, 4), (self.blocks_null_sink_1_2, 0)) self.connect((self.spectsensing_compute_statistics_0, 6), (self.blocks_null_sink_1_3, 0)) self.connect((self.spectsensing_compute_statistics_0, 7), (self.spectsensing_subband_selector_0, 0)) self.connect((self.spectsensing_compute_statistics_0, 1), (self.spectsensing_subband_selector_0, 1)) self.connect((self.spectsensing_compute_statistics_0, 3), (self.spectsensing_subband_selector_0, 2)) self.connect((self.spectsensing_subband_selector_0, 0), (self.probe, 0))
def __init__(self, dab_params, rx_params, verbose=False, debug=False): """ Hierarchical block for OFDM demodulation @param dab_params DAB parameter object (grdab.parameters.dab_parameters) @param rx_params RX parameter object (grdab.parameters.receiver_parameters) @param debug enables debug output to files @param verbose whether to produce verbose messages """ self.dp = dp = dab_params self.rp = rp = rx_params self.verbose = verbose if self.rp.softbits: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_float * self.dp.num_carriers * 2)) # output signature else: gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char * self.dp.num_carriers / 4)) # output signature # workaround for a problem that prevents connecting more than one block directly (see trac ticket #161) #self.input = gr.kludge_copy(gr.sizeof_gr_complex) self.input = blocks.multiply_const_cc(1.0) # FIXME self.connect(self, self.input) # input filtering if self.rp.input_fft_filter: if verbose: print("--> RX filter enabled") lowpass_taps = filter.firdes_low_pass( 1.0, # gain dp.sample_rate, # sampling rate rp.filt_bw, # cutoff frequency rp.filt_tb, # width of transition band filter.firdes.WIN_HAMMING) # Hamming window self.fft_filter = filter.fft_filter_ccc(1, lowpass_taps) # correct sample rate offset, if enabled if self.rp.autocorrect_sample_rate: if verbose: print("--> dynamic sample rate correction enabled") self.rate_detect_ns = grdab.detect_null(dp.ns_length, False) self.rate_estimator = grdab.estimate_sample_rate_bf( dp.sample_rate, dp.frame_length) self.rate_prober = blocks.probe_signal_f() self.connect(self.input, self.rate_detect_ns, self.rate_estimator, self.rate_prober) # self.resample = gr.fractional_interpolator_cc(0, 1) self.resample = grdab.fractional_interpolator_triggered_update_cc( 0, 1) self.connect(self.rate_detect_ns, (self.resample, 1)) self.updater = Timer(0.1, self.update_correction) # self.updater = threading.Thread(target=self.update_correction) self.run_interpolater_update_thread = True self.updater.setDaemon(True) self.updater.start() else: self.run_interpolater_update_thread = False if self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: if verbose: print("--> static sample rate correction enabled") self.resample = filter.mmse_resampler_cc( 0, self.rp.sample_rate_correction_factor) # timing and fine frequency synchronisation self.sync = grdab.ofdm_sync_dab2(self.dp, self.rp, debug) # ofdm symbol sampler self.sampler = grdab.ofdm_sampler(dp.fft_length, dp.cp_length, dp.symbols_per_frame, rp.cp_gap) # fft for symbol vectors self.fft = fft.fft_vcc(dp.fft_length, True, [], True) # coarse frequency synchronisation self.cfs = grdab.ofdm_coarse_frequency_correct(dp.fft_length, dp.num_carriers, dp.cp_length) # diff phasor self.phase_diff = grdab.diff_phasor_vcc(dp.num_carriers) # remove pilot symbol self.remove_pilot = grdab.ofdm_remove_first_symbol_vcc(dp.num_carriers) # magnitude equalisation if self.rp.equalize_magnitude: if verbose: print("--> magnitude equalization enabled") self.equalizer = grdab.magnitude_equalizer_vcc( dp.num_carriers, rp.symbols_for_magnitude_equalization) # frequency deinterleaving self.deinterleave = grdab.frequency_interleaver_vcc( dp.frequency_deinterleaving_sequence_array) # symbol demapping self.demapper = grdab.qpsk_demapper_vcb(dp.num_carriers) # # connect everything # if self.rp.autocorrect_sample_rate or self.rp.sample_rate_correction_factor != 1 or self.rp.always_include_resample: self.connect(self.input, self.resample) self.input2 = self.resample else: self.input2 = self.input if self.rp.input_fft_filter: self.connect(self.input2, self.fft_filter, self.sync) else: self.connect(self.input2, self.sync) # data stream self.connect(self.sync, self.sampler, self.fft, self.cfs, self.phase_diff, self.remove_pilot) if self.rp.equalize_magnitude: self.connect(self.remove_pilot, self.equalizer, self.deinterleave) else: self.connect(self.remove_pilot, self.deinterleave) if self.rp.softbits: if verbose: print("--> using soft bits") self.softbit_interleaver = grdab.complex_to_interleaved_float_vcf( self.dp.num_carriers) self.connect(self.deinterleave, self.softbit_interleaver, (self, 0)) else: self.connect(self.deinterleave, self.demapper, (self, 0)) # calculate an estimate of the SNR self.phase_var_decim = blocks.keep_one_in_n( gr.sizeof_gr_complex * self.dp.num_carriers, self.rp.phase_var_estimate_downsample) self.phase_var_arg = blocks.complex_to_arg(dp.num_carriers) self.phase_var_v2s = blocks.vector_to_stream(gr.sizeof_float, dp.num_carriers) self.phase_var_mod = grdab.modulo_ff(pi / 2) self.phase_var_avg_mod = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.phase_var_sub_avg = blocks.sub_ff() self.phase_var_sqr = blocks.multiply_ff() self.phase_var_avg = filter.iir_filter_ffd( [rp.phase_var_estimate_alpha], [0, 1 - rp.phase_var_estimate_alpha]) self.probe_phase_var = blocks.probe_signal_f() self.connect((self.remove_pilot, 0), self.phase_var_decim, self.phase_var_arg, self.phase_var_v2s, self.phase_var_mod, (self.phase_var_sub_avg, 0), (self.phase_var_sqr, 0)) self.connect(self.phase_var_mod, self.phase_var_avg_mod, (self.phase_var_sub_avg, 1)) self.connect(self.phase_var_sub_avg, (self.phase_var_sqr, 1)) self.connect(self.phase_var_sqr, self.phase_var_avg, self.probe_phase_var) # measure processing rate self.measure_rate = grdab.measure_processing_rate( gr.sizeof_gr_complex, 2000000) self.connect(self.input, self.measure_rate) # debugging if debug: self.connect( self.fft, blocks.file_sink(gr.sizeof_gr_complex * dp.fft_length, "debug/ofdm_after_fft.dat")) self.connect( (self.cfs, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_after_cfs.dat")) self.connect( self.phase_diff, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_diff_phasor.dat")) self.connect( (self.remove_pilot, 0), blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_pilot_removed.dat")) self.connect((self.remove_pilot, 1), blocks.file_sink(gr.sizeof_char, "debug/ofdm_after_cfs_trigger.dat")) self.connect( self.deinterleave, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_deinterleaved.dat")) if self.rp.equalize_magnitude: self.connect( self.equalizer, blocks.file_sink(gr.sizeof_gr_complex * dp.num_carriers, "debug/ofdm_equalizer.dat")) if self.rp.softbits: self.connect( self.softbit_interleaver, blocks.file_sink(gr.sizeof_float * dp.num_carriers * 2, "debug/softbits.dat"))
def __init__(self): gr.top_block.__init__(self, "HFS first channel") ################################################## # Variables ################################################## self.snr = snr = 1 self.vol = vol = 1 self.tau_a = tau_a = 1 / 100. self.tau = tau = 0.002 self.snr_out_func = snr_out_func = ([0] * 3) self.samp_rate = samp_rate = 48000 self.out_rms_func = out_rms_func = 0 self.noSpread = noSpread = 1 self.kN = kN = pow(10.0, (-snr / 20.0)) self.freqShift = freqShift = 0.0 self.fd = fd = 1 self.en_noise = en_noise = 0 self.doppler_ir = doppler_ir = [ 0.0016502763167573274, 0.0018854799389366934, 0.002149957633383614, 0.0024466994528029662, 0.002778907461425479, 0.003149998028185868, 0.003563602180973301, 0.00402356375450247, 0.004533935060796761, 0.0050989698117900155, 0.005723113028669535, 0.006410987682800636, 0.007167377828853199, 0.007997208012493867, 0.008905518763040982, 0.00989743801603955, 0.010978148351927763, 0.012152849984840378, 0.013426719489994542, 0.014804864318746317, 0.016292273216847054, 0.01789376273305468, 0.019613920081278834, 0.021457042698902442, 0.023427074925696508, 0.025527542310538734, 0.027761484135525694, 0.030131384827462734, 0.03263910500345486, 0.035285812968654906, 0.03807191754835305, 0.04099700319171279, 0.04405976832879332, 0.04725796799434838, 0.050588361749672524, 0.05404666793605477, 0.057627525278984175, 0.06132446283016882, 0.06512987918400244, 0.0690350318359975, 0.073030037462906, 0.07710388379815894, 0.08124445365265866, 0.08543856149104095, 0.08967200281887802, 0.0939296164688993, 0.09819535969651079, 0.10245239580938088, 0.10668319386560887, 0.1108696397832219, 0.11499315801386097, 0.11903484274903825, 0.12297559745183839, 0.12679628134392928, 0.1304778613306593, 0.13400156771907581, 0.1373490519778611, 0.14050254470705797, 0.14344501193124823, 0.14616030780428022, 0.14863332181791858, 0.15085011864154488, 0.1527980687853246, 0.154465968374505, 0.15584414644656272, 0.15692455833401583, 0.15770086387153975, 0.1581684893637365, 0.15832467246620405, 0.1581684893637365, 0.15770086387153975, 0.15692455833401583, 0.15584414644656272, 0.154465968374505, 0.1527980687853246, 0.15085011864154488, 0.14863332181791858, 0.14616030780428022, 0.14344501193124823, 0.14050254470705797, 0.1373490519778611, 0.13400156771907581, 0.1304778613306593, 0.12679628134392928, 0.12297559745183839, 0.11903484274903825, 0.11499315801386097, 0.1108696397832219, 0.10668319386560887, 0.10245239580938088, 0.09819535969651079, 0.0939296164688993, 0.08967200281887802, 0.08543856149104095, 0.08124445365265866, 0.07710388379815894, 0.073030037462906, 0.0690350318359975, 0.06512987918400244, 0.06132446283016882, 0.057627525278984175, 0.05404666793605477, 0.050588361749672524, 0.04725796799434838, 0.04405976832879332, 0.04099700319171279, 0.03807191754835305, 0.035285812968654906, 0.03263910500345486, 0.030131384827462734, 0.027761484135525694, 0.025527542310538734, 0.023427074925696508, 0.021457042698902442, 0.019613920081278834, 0.01789376273305468, 0.016292273216847054, 0.014804864318746317, 0.013426719489994542, 0.012152849984840378, 0.010978148351927763, 0.00989743801603955, 0.008905518763040982, 0.007997208012493867, 0.007167377828853199, 0.006410987682800636, 0.005723113028669535, 0.0050989698117900155, 0.004533935060796761, 0.00402356375450247, 0.003563602180973301, 0.003149998028185868, 0.002778907461425479, 0.0024466994528029662, 0.002149957633383614, 0.0018854799389366934, 0.0016502763167573274 ] self.ampl = ampl = [[1.0, 0.0], [1.0, 0.0]] ################################################## # Blocks ################################################## self.snr_out = blocks.probe_signal_f() self.out_rms = blocks.probe_signal_f() def _snr_out_func_probe(): while True: val = self.snr_out.level() try: self.set_snr_out_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _snr_out_func_thread = threading.Thread(target=_snr_out_func_probe) _snr_out_func_thread.daemon = True _snr_out_func_thread.start() self.single_pole_iir_filter_xx_0_0 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( 2 * pi * tau_a / samp_rate, 1) def _out_rms_func_probe(): while True: val = self.out_rms.level() try: self.set_out_rms_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _out_rms_func_thread = threading.Thread(target=_out_rms_func_probe) _out_rms_func_thread.daemon = True _out_rms_func_thread.start() self.low_pass_filter_2 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_0 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[0][1] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = filter.interp_fir_filter_ccf( int(samp_rate / 100), firdes.low_pass(ampl[0][0] * (samp_rate / 100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 1750 + 100, 600, firdes.WIN_HAMMING, 6.76)) self.epy_block_0_0 = epy_block_0_0.blk(fd=fd) self.epy_block_0 = epy_block_0.blk(fd=fd) self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0_0.set_enabled(True) self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1, noSpread, 0) self.blocks_selector_0.set_enabled(True) self.blocks_rms_xx_0_0 = blocks.rms_ff(2 * pi * tau_a * 10 / samp_rate) self.blocks_rms_xx_0 = blocks.rms_cf(2 * pi * tau_a * 100 / samp_rate) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_3 = blocks.multiply_const_ff(en_noise) self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_cc(vol) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc(vol) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_ff( 2 * sqrt(ampl[0][0]**2 + ampl[0][1]**2) * 2) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(0.5) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(0.5) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_1 = blocks.divide_ff(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, int(tau * samp_rate)) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_2_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_2 = blocks.complex_to_mag_squared(1) self.blocks_add_xx_1 = blocks.add_vff(1) self.blocks_add_xx_0_0 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.audio_source_0 = audio.source(samp_rate, 'in1', True) self.audio_sink_0_0_0 = audio.sink(samp_rate, 'out3', False) self.audio_sink_0_0 = audio.sink(samp_rate, 'out2', False) self.analog_sig_source_x_2 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0) self.analog_sig_source_x_0_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0) self.analog_noise_source_x_1 = analog.noise_source_c( analog.GR_GAUSSIAN, 1e-0 * kN, 3) self.analog_fastnoise_source_x_2 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, 1, 1, 8192) self.analog_fastnoise_source_x_1 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, 1, 0, 8192) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_f( analog.GR_GAUSSIAN, 0.3, 0, 8192) self.analog_const_source_x_2 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_1_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[0][1]) self.analog_const_source_x_1 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, ampl[0][0]) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.analog_const_source_x_1, 0), (self.blocks_selector_0, 1)) self.connect((self.analog_const_source_x_1_0, 0), (self.blocks_selector_0_0, 1)) self.connect((self.analog_const_source_x_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_multiply_const_vxx_3, 0)) self.connect((self.analog_fastnoise_source_x_1, 0), (self.epy_block_0, 0)) self.connect((self.analog_fastnoise_source_x_2, 0), (self.epy_block_0_0, 0)) self.connect((self.analog_noise_source_x_1, 0), (self.low_pass_filter_2, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.analog_sig_source_x_2, 0), (self.blocks_multiply_xx_0_0_0_0_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_add_xx_1, 0), (self.audio_sink_0_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_rms_xx_0_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2_0, 0), (self.single_pole_iir_filter_xx_0_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0_0_0_0, 0)) self.connect((self.blocks_divide_xx_1, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0_0_0_0_0, 2)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.audio_sink_0_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_multiply_const_vxx_2_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_3, 0), (self.blocks_add_xx_1, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_multiply_xx_0_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0), (self.blocks_add_xx_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0), (self.blocks_complex_to_mag_squared_2_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0), (self.blocks_multiply_const_vxx_2_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_complex_to_mag_squared_2, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.snr_out, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_rms_xx_0_0, 0), (self.out_rms, 0)) self.connect((self.blocks_selector_0, 0), (self.blocks_multiply_xx_0_0_0, 1)) self.connect((self.blocks_selector_0_0, 0), (self.blocks_multiply_xx_0_0_0_0, 1)) self.connect((self.epy_block_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.epy_block_0_0, 0), (self.low_pass_filter_1_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_selector_0, 0)) self.connect((self.low_pass_filter_1_0, 0), (self.blocks_selector_0_0, 0)) self.connect((self.low_pass_filter_2, 0), (self.blocks_multiply_xx_0_0_0_0_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_divide_xx_1, 0)) self.connect((self.single_pole_iir_filter_xx_0_0, 0), (self.blocks_divide_xx_1, 1))
def __init__(self): gr.top_block.__init__(self, "Testvolts") ################################################## # Variables - Some get overridden after block definition before connections. ################################################## self.samp_rate = samp_rate = 48000 # Initial wavelength assumption, which must be calibrated carefully. self.fundamental_wavelength_samples = 800 # self.probed_rms_volts = probed_rms_volts = 0 # Things from config file # self.avg_length = avg_length = 10000 self.probe_interval = probe_interval = float(SETTINGS["display"]["probe_interval"]) self.rms_alpha = rms_alpha = 1 # Calibration (Conversion) parameters, to convert from sample domain to volts/current domain. self.average_rms_slope = float(SETTINGS["calibration"]["average_rms_slope"]) self.average_rms_intercept = float(SETTINGS["calibration"]["average_rms_intercept"]) # RMS Block parameters self.voltage_calculation_rms_alpha = float(SETTINGS["calibration"]["voltage_calculation_rms_alpha"]) # Averaging block parameters self.voltage_rms_average_length = int(SETTINGS["calibration"]["voltage_rms_average_length"]) self.voltage_rms_average_scale = float(SETTINGS["calibration"]["voltage_rms_average_scale"]) self.voltage_rms_max_iter = int(SETTINGS["calibration"]["voltage_rms_max_iter"]) # for averaging block stuff self.last_sampled_wavelength = 1 # Input source parameters. self.audioSource = SETTINGS["input"]["input_type"] # Frequency calculation parameters self.freq_getfreq_alpha = float(SETTINGS["calibration"]["freq_getfreq_alpha"]) self.freq_interpolation = float(SETTINGS["calibration"]["freq_interpolation"]) self.freq_interpolation_multiplier = float(SETTINGS["calibration"]["freq_interpolation_multiplier"]) self.current_readings = self.getDefaultReadings() # AC Volts self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) # self.blocks_rms_volts = blocks.rms_ff(self.voltage_calculation_rms_alpha) # self.blocks_moving_average_volts = blocks.moving_average_ff(self.voltage_rms_average_length, self.voltage_rms_average_scale, self.voltage_rms_max_iter) # self.probe_rms_volts = blocks.probe_signal_f() # AC Frequency # if (setting_acfreq_enabled() is True): self.probe_avgwave = blocks.probe_signal_f() self.upsampler = filter.fractional_resampler_ff(0, self.freq_interpolation) self.getfreq_block = powerquality.getfreqcpp(self.freq_getfreq_alpha) # Streaming support - Permit access to the raw samples to ZeroMQ clients. self.zeromq_pub_sink_0 = zeromq.pub_sink(gr.sizeof_float, 1, SETTINGS["tap_rawsamples"]["zmq_bind_uri"], SETTINGS["tap_rawsamples"]["zmq_timeout"], True, -1) # TODO: Connect the streaming blocks # self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((-1, )) # self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, self.fundamental_wavelength_samples) # self.blocks_add_xx_0 = blocks.add_vff(1) # Bias detection - these parameters are tuned to 48khz samp rate: (1 * samp_rate / 60, .00125, 4000) if ("bias" in SETTINGS and "bias_avg_num_waves" in SETTINGS["bias"]): bias_avg_num_waves = SETTINGS["bias"]["bias_avg_num_waves"] else: bias_avg_num_waves = 1 # Calculate the number of samples associated with n wavelengths specified in settings or the default. avgBiasNumSamples = bias_avg_num_waves * samp_rate / 60 self.blocks_bias_moving_average = blocks.moving_average_ff(avgBiasNumSamples, 1.0/avgBiasNumSamples, 4000) self.probe_bias = blocks.probe_signal_f() ### Calibrate the blocks based on settings from config file # self.set_rms_alpha(asdfasdfasdfasdf from settings) # Instantiate the message consumer that we'll use to get json messages from the getfreq block self.msgConsumer = message_consumer() ################################################## # RMS Volts Connections ################################################## # self.connect((self.blocks_rms_volts, 0), (self.blocks_moving_average_volts, 0)) # self.connect((self.blocks_moving_average_volts, 0), (self.probe_rms_volts, 0)) # Set up a variable with a default value. Below we'll override the value depending on whether we are reading from file or audio device. self.sourceOfSamplesBlock = self.blocks_throttle_0 # Select input source - wav file or sound card. if (self.audioSource == "wav"): # Variable source type: wav file # self.wavfile_input = blocks.wavfile_source('./samples/sample.wav', False) self.input_wav_filename = SETTINGS["input"]["input_wav_filename"] self.wavfile_input = blocks.wavfile_source(self.input_wav_filename, True) # wav input requires throttle block. Then we connect things to the throttle block directly instead of the wav source. self.connect((self.wavfile_input, 0), (self.blocks_throttle_0, 0)) self.sourceOfSamplesBlock = self.blocks_throttle_0 else: # Variable source type: sound device. self.soundcard_device_name = "" if (SETTINGS["input"]["input_sound_device"]): self.soundcard_device_name = SETTINGS["input"]["input_sound_device"] self.soundcard_input = audio.source(samp_rate, self.soundcard_device_name, True) # no throttle block needed in the case of sound card self.sourceOfSamplesBlock = self.soundcard_input # Volts flow print "CONNECTIONS: Defining the voltage calculation flow" # self.connect((self.sourceOfSamplesBlock , 0), (self.blocks_rms_volts, 0)) # Hz flow print "CONNECTIONS: Defining the frequency calculation flow" self.connect((self.sourceOfSamplesBlock , 0), (self.upsampler, 0)) self.connect((self.upsampler, 0), (self.getfreq_block, 0)) self.connect((self.getfreq_block, 0), (self.probe_avgwave, 0)) # Raw Tap port Tap flow print "CONNECTIONS: Connecting raw samples tap (ZMQ)" self.connect((self.sourceOfSamplesBlock , 0), (self.zeromq_pub_sink_0, 0)) # Bias Detection flow self.connect((self.sourceOfSamplesBlock, 0), (self.blocks_bias_moving_average, 0)) self.connect((self.blocks_bias_moving_average, 0), (self.probe_bias, 0)) # Connect our message consumer block to the message output of the getfreq block so we can get messages from it. self.msg_connect((self.getfreq_block, 'out'), (self.msgConsumer, 'in_port'))
def __init__(self, mode='VOR', zero_point=59, **kwargs): self.channel_rate = channel_rate = 40000 internal_audio_rate = 20000 # TODO over spec'd self.zero_point = zero_point transition = 5000 SimpleAudioDemodulator.__init__(self, mode=mode, audio_rate=internal_audio_rate, demod_rate=channel_rate, band_filter=fm_subcarrier * 1.25 + fm_deviation + transition / 2, band_filter_transition=transition, **kwargs) self.dir_rate = dir_rate = 10 if internal_audio_rate % dir_rate != 0: raise ValueError( 'Audio rate %s is not a multiple of direction-finding rate %s' % (internal_audio_rate, dir_rate)) self.dir_scale = dir_scale = internal_audio_rate // dir_rate self.audio_scale = audio_scale = channel_rate // internal_audio_rate self.zeroer = blocks.add_const_vff((zero_point * (math.pi / 180), )) self.dir_vector_filter = grfilter.fir_filter_ccf( 1, firdes.low_pass(1, dir_rate, 1, 2, firdes.WIN_HAMMING, 6.76)) self.am_channel_filter_block = grfilter.fir_filter_ccf( 1, firdes.low_pass(1, channel_rate, 5000, 5000, firdes.WIN_HAMMING, 6.76)) self.goertzel_fm = fft.goertzel_fc(channel_rate, dir_scale * audio_scale, 30) self.goertzel_am = fft.goertzel_fc(internal_audio_rate, dir_scale, 30) self.fm_channel_filter_block = grfilter.freq_xlating_fir_filter_ccc( 1, (firdes.low_pass(1.0, channel_rate, fm_subcarrier / 2, fm_subcarrier / 2, firdes.WIN_HAMMING)), fm_subcarrier, channel_rate) self.multiply_conjugate_block = blocks.multiply_conjugate_cc(1) self.complex_to_arg_block = blocks.complex_to_arg(1) self.am_agc_block = analog.feedforward_agc_cc(1024, 1.0) self.am_demod_block = analog.am_demod_cf( channel_rate=channel_rate, audio_decim=audio_scale, audio_pass=5000, audio_stop=5500, ) self.fm_demod_block = analog.quadrature_demod_cf(1) self.phase_agc_fm = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.phase_agc_am = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.probe = blocks.probe_signal_f() self.audio_filter_block = grfilter.fir_filter_fff( 1, design_lofi_audio_filter(internal_audio_rate, False)) ################################################## # Connections ################################################## # Input self.connect(self, self.band_filter_block) # AM chain self.connect(self.band_filter_block, self.am_channel_filter_block, self.am_agc_block, self.am_demod_block) # AM audio self.connect( self.am_demod_block, blocks.multiply_const_ff(1.0 / audio_modulation_index * 0.5), self.audio_filter_block) self.connect_audio_output(self.audio_filter_block) # AM phase self.connect(self.am_demod_block, self.goertzel_am, self.phase_agc_am, (self.multiply_conjugate_block, 0)) # FM phase self.connect(self.band_filter_block, self.fm_channel_filter_block, self.fm_demod_block, self.goertzel_fm, self.phase_agc_fm, (self.multiply_conjugate_block, 1)) # Phase comparison and output self.connect( self.multiply_conjugate_block, self.dir_vector_filter, self.complex_to_arg_block, blocks.multiply_const_ff(-1), # opposite angle conventions self.zeroer, self.probe)
def __init__(self, mode='VOR', zero_point=59, **kwargs): self.channel_rate = channel_rate = 40000 internal_audio_rate = 20000 # TODO over spec'd self.zero_point = zero_point transition = 5000 SimpleAudioDemodulator.__init__(self, mode=mode, audio_rate=internal_audio_rate, demod_rate=channel_rate, band_filter=fm_subcarrier * 1.25 + fm_deviation + transition / 2, band_filter_transition=transition, **kwargs) self.dir_rate = dir_rate = 10 if internal_audio_rate % dir_rate != 0: raise ValueError('Audio rate %s is not a multiple of direction-finding rate %s' % (internal_audio_rate, dir_rate)) self.dir_scale = dir_scale = internal_audio_rate // dir_rate self.audio_scale = audio_scale = channel_rate // internal_audio_rate self.zeroer = blocks.add_const_vff((zero_point * (math.pi / 180), )) self.dir_vector_filter = grfilter.fir_filter_ccf(1, firdes.low_pass( 1, dir_rate, 1, 2, firdes.WIN_HAMMING, 6.76)) self.am_channel_filter_block = grfilter.fir_filter_ccf(1, firdes.low_pass( 1, channel_rate, 5000, 5000, firdes.WIN_HAMMING, 6.76)) self.goertzel_fm = fft.goertzel_fc(channel_rate, dir_scale * audio_scale, 30) self.goertzel_am = fft.goertzel_fc(internal_audio_rate, dir_scale, 30) self.fm_channel_filter_block = grfilter.freq_xlating_fir_filter_ccc(1, (firdes.low_pass(1.0, channel_rate, fm_subcarrier / 2, fm_subcarrier / 2, firdes.WIN_HAMMING)), fm_subcarrier, channel_rate) self.multiply_conjugate_block = blocks.multiply_conjugate_cc(1) self.complex_to_arg_block = blocks.complex_to_arg(1) self.am_agc_block = analog.feedforward_agc_cc(1024, 1.0) self.am_demod_block = analog.am_demod_cf( channel_rate=channel_rate, audio_decim=audio_scale, audio_pass=5000, audio_stop=5500, ) self.fm_demod_block = analog.quadrature_demod_cf(1) self.phase_agc_fm = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.phase_agc_am = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.probe = blocks.probe_signal_f() self.audio_filter_block = grfilter.fir_filter_fff(1, design_lofi_audio_filter(internal_audio_rate, False)) ################################################## # Connections ################################################## # Input self.connect( self, self.band_filter_block) # AM chain self.connect( self.band_filter_block, self.am_channel_filter_block, self.am_agc_block, self.am_demod_block) # AM audio self.connect( self.am_demod_block, blocks.multiply_const_ff(1.0 / audio_modulation_index * 0.5), self.audio_filter_block) self.connect_audio_output(self.audio_filter_block) # AM phase self.connect( self.am_demod_block, self.goertzel_am, self.phase_agc_am, (self.multiply_conjugate_block, 0)) # FM phase self.connect( self.band_filter_block, self.fm_channel_filter_block, self.fm_demod_block, self.goertzel_fm, self.phase_agc_fm, (self.multiply_conjugate_block, 1)) # Phase comparison and output self.connect( self.multiply_conjugate_block, self.dir_vector_filter, self.complex_to_arg_block, blocks.multiply_const_ff(-1), # opposite angle conventions self.zeroer, self.probe)
def __init__(self): gr.top_block.__init__(self, "Signals") ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.tune_freq = tune_freq = 315000000 self.samp_rate = samp_rate = 1.024e6 ################################################## # Blocks ################################################## self.probe = blocks.probe_signal_f() def _variable_function_probe_0_probe(): sample = [] while True: val = self.probe.level() try: self.set_variable_function_probe_0(val) sample.append(val) if (len(sample) >= 10): mid = np.mean(sample) print(mid) allSignals.append(mid) sample = [] except AttributeError: pass time.sleep(1.0 / (100)) _variable_function_probe_0_thread = threading.Thread( target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(tune_freq, 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(False, 0) self.rtlsdr_source_0.set_gain(5, 0) self.rtlsdr_source_0.set_if_gain(10, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna('', 0) self.rtlsdr_source_0.set_bandwidth(200000, 0) self.low_pass_filter_1 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 20000, 10000, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( 5, firdes.low_pass(1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_0, 0), (self.probe, 0)) self.connect((self.low_pass_filter_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0))
def __init__(self): gr.top_block.__init__(self) options = get_options() bitrate = 8000 channel_bw = options.channel_bandwidth chan0_freq = 358400000 self.rfgain = options.gain self.channels = [ int(ch) for ch in options.channels.split(',') if ch ] self.ch_freqs = [ ch * channel_bw + chan0_freq for ch in self.channels ] self.ch_freqs.extend( [ int(f) for f in options.channels_by_freq.split(',') if f ]) while len(self.channels) < len(self.ch_freqs): self.channels.append(-1) if options.frequency is None: self.ifreq = (max(self.ch_freqs) + min(self.ch_freqs)) / 2 else: self.ifreq = options.frequency self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(options.sample_rate) self.src.set_freq_corr(options.ppm, 0) if self.rfgain is None: self.src.set_gain_mode(True, 0) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(False) self.src.set_gain(self.rfgain) self.src.set_if_gain(37) # may differ from the requested rate sample_rate = int(self.src.get_sample_rate()) sys.stderr.write("sample rate: %d\n" % (sample_rate)) first_decim = int(options.sample_rate / bitrate / 2) sys.stderr.write("decim: %d\n" % (first_decim)) out_sample_rate=sample_rate/first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps=out_sample_rate/bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.tuners = [] self.afc_probes = [] if len(self.channels) != 1: if options.output_file: if options.output_file.find('%%') == -1: raise ValueError('Output name template missing "%%".') elif options.output_pipe: if options.output_pipe.find('%%') == -1: raise ValueError('Output name template missing "%%".') else: raise ValueError('WTF') for ch in range(0,len(self.channels)): bw = (9200 + options.afc_ppm_threshold)/2 taps = filter.firdes.low_pass(1.0, sample_rate, bw, bw*options.transition_width, filter.firdes.WIN_HANN) offset = self.ch_freqs[ch] - self.ifreq sys.stderr.write("channel[%d]: %d frequency=%d, offset=%d Hz\n" % (ch, self.channels[ch], self.ch_freqs[ch], offset)) tuner = filter.freq_xlating_fir_filter_ccc(first_decim, taps, offset, sample_rate) self.tuners.append(tuner) demod = digital.gmsk_demod(samples_per_symbol=sps) fname = self.channels[ch] if fname == -1: fname = self.ch_freqs[ch] if options.output_pipe is None: file = options.output_file.replace('%%', str(fname)) output = blocks.file_sink(gr.sizeof_char, file) else: cmd = options.output_pipe.replace('%%', str(fname)) pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True) fd = pipe.stdin.fileno() output = blocks.file_descriptor_sink(gr.sizeof_char, fd) self.connect((self.src, 0), (tuner, 0)) self.connect((tuner, 0), (demod, 0)) self.connect((demod, 0), (output, 0)) afc_decimation = 32000 afc_demod = analog.quadrature_demod_cf(sample_rate/first_decim/(2*math.pi*afc_decimation)) integrate = blocks.integrate_ff(afc_decimation) afc_probe = blocks.probe_signal_f() self.afc_probes.append(afc_probe) self.connect((tuner, 0), (afc_demod,0)) self.connect((afc_demod, 0), (integrate,0)) self.connect((integrate, 0), (afc_probe, 0)) def _variable_function_probe_0_probe(): while True: time.sleep(options.afc_period) for ch in range(0,len(self.channels)): err = self.afc_probes[ch].level() if abs(err) < options.afc_ppm_threshold: continue freq = self.tuners[ch].center_freq() + err * options.afc_gain self.tuners[ch].set_center_freq(freq) if self.channels[ch] == -1: sys.stderr.write("Freq %d freq err: %5.0f\tfreq: %f\n" % (self.ch_freqs[ch], err, freq)) else: sys.stderr.write("Chan %d freq err: %5.0f\tfreq: %f\n" % (self.channels[ch], err, freq)) sys.stderr.write("\n") _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()
def __init__(self): gr.top_block.__init__(self, "Bpsk Receiverlms") Qt.QWidget.__init__(self) self.setWindowTitle("Bpsk Receiverlms") 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", "BPSK_ReceiverLMS") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 8 self.probe_var_n = probe_var_n = 0 self.probe_var = probe_var = 0 self.nfilts = nfilts = 32 self.eb = eb = 0.35 self.SNR = SNR = 500 self.transistion = transistion = 100 self.timing_loop_bw = timing_loop_bw = 6.28/100.0 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts/16, nfilts/16, 1.0/float(sps), 0.35, 11*sps*nfilts/16) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1] self.phase_bw = phase_bw = 6.28/100.0 self.noise_amp = noise_amp = probe_var/(10**(SNR/20)) self.matched_filter = matched_filter = firdes.root_raised_cosine(nfilts, nfilts, 1, eb, int(11*sps*nfilts)) self.interpolation = interpolation = 2000 self.eq_gain = eq_gain = 0.01 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist(([1,- 1]), ([0,1]), 2, 1).base() self.carrier = carrier = 10000 self.arity = arity = 2 self.Signal_rms = Signal_rms = probe_var self.Signal_Noise_amp = Signal_Noise_amp = probe_var_n ################################################## # Blocks ################################################## self._timing_loop_bw_range = Range(0.0, 0.2, 0.01, 6.28/100.0, 200) self._timing_loop_bw_win = RangeWidget(self._timing_loop_bw_range, self.set_timing_loop_bw, "Time: BW", "counter_slider", float) self.top_grid_layout.addWidget(self._timing_loop_bw_win, 0,0) self.probe_rms = blocks.probe_signal_f() self.probe_avg_n = blocks.probe_signal_f() self._phase_bw_range = Range(0.0, 1.0, 0.001, 6.28/100.0, 200) self._phase_bw_win = RangeWidget(self._phase_bw_range, self.set_phase_bw, "Phase: Bandwidth", "counter_slider", float) self.top_grid_layout.addWidget(self._phase_bw_win, 0,4) self._eq_gain_range = Range(0.0, 0.5, 0.001, 0.01, 200) self._eq_gain_win = RangeWidget(self._eq_gain_range, self.set_eq_gain, "Equalizer: rate", "slider", float) self.top_grid_layout.addWidget(self._eq_gain_win, 1,3) self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=decimation, decimation=interpolation, taps=(rrc_taps), fractional_bw=None, ) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0/10) self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) def _probe_var_n_probe(): while True: val = self.probe_avg_n.level() try: self.set_probe_var_n(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_n_thread = threading.Thread(target=_probe_var_n_probe) _probe_var_n_thread.daemon = True _probe_var_n_thread.start() def _probe_var_probe(): while True: val = self.probe_rms.level() try: self.set_probe_var(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_thread = threading.Thread(target=_probe_var_probe) _probe_var_thread.daemon = True _probe_var_thread.start() self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc(1, (filter.firdes.low_pass(1, samp_rate*10, sideband_rx,1000)), carrier, samp_rate) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 1) self.digital_lms_dd_equalizer_cc_1 = digital.lms_dd_equalizer_cc(8, eq_gain, 1, constel) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, arity, False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constel) self.blocks_wavfile_source_0 = blocks.wavfile_source("/Users/ahmadtrabousli/Desktop/GnuRadioModems/Impulse Responses/5km_20pc/BPSK_Output/goff_random_20pc_5km_E_no3.wav", False) self.blocks_throttle_1_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_rms_xx_1 = blocks.rms_cf(0.01) self.blocks_rms_xx_0 = blocks.rms_cf(0.01) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0_1 = blocks.file_sink(gr.sizeof_char*1, "/Users/ahmadtrabousli/Desktop/GnuRadioModems/PSK/outputText", False) self.blocks_file_sink_0_1.set_unbuffered(False) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/Users/ahmadtrabousli/Desktop/GnuRadioModems/PSK/outputBinary", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_1 = blocks.delay(gr.sizeof_char*1, int(delay)) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, noise_amp, 0) self._Signal_rms_tool_bar = Qt.QToolBar(self) if None: self._Signal_rms_formatter = None else: self._Signal_rms_formatter = lambda x: x self._Signal_rms_tool_bar.addWidget(Qt.QLabel("Signal_rms"+": ")) self._Signal_rms_label = Qt.QLabel(str(self._Signal_rms_formatter(self.Signal_rms))) self._Signal_rms_tool_bar.addWidget(self._Signal_rms_label) self.top_layout.addWidget(self._Signal_rms_tool_bar) self._Signal_Noise_amp_tool_bar = Qt.QToolBar(self) if None: self._Signal_Noise_amp_formatter = None else: self._Signal_Noise_amp_formatter = lambda x: x self._Signal_Noise_amp_tool_bar.addWidget(Qt.QLabel("Signal_Noise_amp"+": ")) self._Signal_Noise_amp_label = Qt.QLabel(str(self._Signal_Noise_amp_formatter(self.Signal_Noise_amp))) self._Signal_Noise_amp_tool_bar.addWidget(self._Signal_Noise_amp_label) self.top_layout.addWidget(self._Signal_Noise_amp_tool_bar) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_rms_xx_1, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_file_sink_0_1, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.probe_rms, 0)) self.connect((self.blocks_rms_xx_1, 0), (self.probe_avg_n, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_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_diff_decoder_bb_0, 0), (self.blocks_delay_1, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_lms_dd_equalizer_cc_1, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_lms_dd_equalizer_cc_1, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_throttle_1_0_0, 0))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() self.src = blocks.file_source(gr.sizeof_gr_complex * 1, "/tmp/myout1.ch", False) ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 15 self.afc_gain = 0.01 self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 10 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) self.channels = 10 ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.blocks_deinterleave_0 = blocks.deinterleave( gr.sizeof_gr_complex * 1, 1) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): mpsk = digital.mpsk_receiver_cc(4, math.pi / 4, math.pi / 100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2. / math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) brmchannels = [ 0, 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 ] #brmchannels = [11,4,3,64,45,47,53,8,68,6,56,49,17,54,65,5,71,22,48,7,50] # itds kancl #brmchannels = [23,13,40,69,59,7,42,54,5,14,4,56,45,46,67,55,66,44,71,49,31,57,0,65,70] # doma - dole #brmchannels = [23,13,59,40,69,7,49,60,42,70,4,50,66,67,3,14,57,33,46,22,68,32,39,24,6,12,43,58,48,17,5,56,65,29,54,30,16,52,53,41,47,2,34,44,8] # doma - strecha #brmchannels = [67, 7, 23, 70] # doma - strecha - SDS #brmchannels = [67, 7, 23, 70,9,71,64,63,62,61,55,51,45,38,37,36,35,31,28,27,26,25,21,20,19,18,15,11,10,1,0] # doma - strecha - komplement if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port) + ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) print "connect %i" % ch if ch in brmchannels: self.connect( (self.blocks_deinterleave_0, ch), #(squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect((self.src, 0), (self.blocks_deinterleave_0, 0)) ################################################## # signal strenght identification ################################################## ''' self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) print "connect %i"%ch self.connect((self.blocks_deinterleave_0, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "power threshold target %f"%pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in []: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ''' ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel / (2 * math.pi)) samp_afc = self.srate_channel * self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1. / samp_afc * self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): rt = 0.0 while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() freq = err * self.afc_gain print "err: %f\tfreq: %f\trt %f" % (err, freq, rt) changed = False if err < -1: rt += 0.1 changed = True elif err > 1: rt -= 0.1 changed = True if changed: os.system("echo \"setrot %f\" | nc localhost 3333" % rt) self.afc_channel = 0 self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): print "connect %i" % ch self.connect((self.blocks_deinterleave_0, ch), (self.afc_selector, ch)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, lo_offset_freq=1e6, threshold_dB=-70, RF=2.49e9, DC_filter_num_elements=4, speed_samp_rate=1, samp_rate=1e6, highpass_cutoff_freq=0, lowpass_cutoff_freq=1700, fft_len=pow(2,20), samp_rate_sink=8000, angle=0, tx_amp=1, rx_gain=30.5): grc_wxgui.top_block_gui.__init__(self, title="CW Radar Single Target") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.lo_offset_freq = lo_offset_freq self.threshold_dB = threshold_dB self.RF = RF self.DC_filter_num_elements = DC_filter_num_elements self.speed_samp_rate = speed_samp_rate self.samp_rate = samp_rate self.highpass_cutoff_freq = highpass_cutoff_freq self.lowpass_cutoff_freq = lowpass_cutoff_freq self.fft_len = fft_len self.samp_rate_sink = samp_rate_sink self.angle = angle self.tx_amp = tx_amp self.rx_gain = rx_gain ################################################## # Variables ################################################## self.target_speed = target_speed = 0 self.target_direction = target_direction = 0 self.tx_amp_tuner = tx_amp_tuner = tx_amp self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB self.speed_textbox = speed_textbox = target_speed self.rx_gain_tuner = rx_gain_tuner = rx_gain self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq self.direction_textbox = direction_textbox = target_direction self.angle_tuner = angle_tuner = angle self.RF_tuner = RF_tuner = RF ################################################## # Blocks ################################################## _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._tx_amp_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, label="TX Signal Amp", converter=forms.float_converter(), proportion=0, ) self._tx_amp_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_tx_amp_tuner_sizer, value=self.tx_amp_tuner, callback=self.set_tx_amp_tuner, minimum=0, maximum=1, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tx_amp_tuner_sizer, 0, 17, 1, 26) _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_dB_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, label="Detected Target Threshold (dB)", converter=forms.float_converter(), proportion=0, ) self._threshold_dB_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_dB_tuner_sizer, value=self.threshold_dB_tuner, callback=self.set_threshold_dB_tuner, minimum=-90, maximum=-30, num_steps=60, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 17) self.speed_probe = blocks.probe_signal_f() _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, label="USRP RX Gain (dB)", converter=forms.float_converter(), proportion=0, ) self._rx_gain_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_tuner_sizer, value=self.rx_gain_tuner, callback=self.set_rx_gain_tuner, minimum=0, maximum=30.5 + 62, num_steps=185, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 17) self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum") self.GridAdd(self.notebook, 5, 0, 13, 75) _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._lowpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, label="Lowpass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._lowpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_lowpass_cutoff_freq_tuner_sizer, value=self.lowpass_cutoff_freq_tuner, callback=self.set_lowpass_cutoff_freq_tuner, minimum=0, maximum=3000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 43, 1, 32) _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._highpass_cutoff_freq_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, label="High-Pass Cutoff Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._highpass_cutoff_freq_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_highpass_cutoff_freq_tuner_sizer, value=self.highpass_cutoff_freq_tuner, callback=self.set_highpass_cutoff_freq_tuner, minimum=0, maximum=1600, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 43, 1, 32) self.direction_probe = blocks.probe_signal_i() _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._angle_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, label="Angle of Approach of the Target (Deg)", converter=forms.float_converter(), proportion=0, ) self._angle_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_angle_tuner_sizer, value=self.angle_tuner, callback=self.set_angle_tuner, minimum=0, maximum=89, num_steps=890, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_angle_tuner_sizer, 1, 17, 1, 26) _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL) self._RF_tuner_text_box = forms.text_box( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, label="Radar Frequency (Hz)", converter=forms.float_converter(), proportion=0, ) self._RF_tuner_slider = forms.slider( parent=self.GetWin(), sizer=_RF_tuner_sizer, value=self.RF_tuner, callback=self.set_RF_tuner, minimum=2.4e9, maximum=2.5e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 17) self.wxgui_waterfallsink = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="Time/Frequency CW Doppler Radar", win=window.blackmanharris, ) self.notebook.GetPage(1).Add(self.wxgui_waterfallsink.win) self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c( self.notebook.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=4096, fft_rate=15, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver Full Spectrum", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win) self.wxgui_fftsink = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate_sink, fft_size=1024, fft_rate=100, average=False, avg_alpha=None, title="FFT CW Doppler Radar Receiver ", peak_hold=False, win=window.blackmanharris, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink.win) self.usrp_transmitter = uhd.usrp_sink( ",".join(('addr=192.168.10.2', "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_transmitter.set_clock_source("internal", 0) self.usrp_transmitter.set_samp_rate(samp_rate) self.usrp_transmitter.set_center_freq(RF_tuner, 0) self.usrp_transmitter.set_gain(0, 0) self.usrp_transmitter.set_antenna('TX/RX', 0) self.usrp_receiver = uhd.usrp_source( ",".join(('addr=192.168.10.3', "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_receiver.set_clock_source("mimo", 0) self.usrp_receiver.set_time_source("mimo", 0) self.usrp_receiver.set_samp_rate(samp_rate) self.usrp_receiver.set_center_freq(uhd.tune_request(RF_tuner, lo_offset_freq), 0) self.usrp_receiver.set_gain(rx_gain_tuner, 0) self.usrp_receiver.set_antenna("J1", 0) self.usrp_receiver.set_bandwidth(15e6, 0) def _target_speed_probe(): while True: val = self.speed_probe.level() try: self.set_target_speed(val) except AttributeError: pass time.sleep(1.0 / (2)) _target_speed_thread = threading.Thread(target=_target_speed_probe) _target_speed_thread.daemon = True _target_speed_thread.start() def _target_direction_probe(): while True: val = self.direction_probe.level() try: self.set_target_direction(val) except AttributeError: pass time.sleep(1.0 / (2)) _target_direction_thread = threading.Thread(target=_target_direction_probe) _target_direction_thread.daemon = True _target_direction_thread.start() self._speed_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.speed_textbox, callback=self.set_speed_textbox, label="Target Speed (Kph)", converter=forms.float_converter(), ) self.GridAdd(self._speed_textbox_text_box, 3, 0, 1, 17) self.rational_resampler = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate/samp_rate_sink), taps=None, fractional_bw=None, ) self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1) self._direction_textbox_text_box = forms.text_box( parent=self.GetWin(), value=self.direction_textbox, callback=self.set_direction_textbox, label="Target Direction", converter=forms.str_converter(), ) self.GridAdd(self._direction_textbox_text_box, 4, 0, 1, 17) self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2) self.cwradar_doppler_velocity_single_target_ff_0 = cwradar.doppler_velocity_single_target_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner) self.complex_to_mag = blocks.complex_to_mag(fft_len) self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len) self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len) self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, tx_amp_tuner, 0) self.DC_filter_0 = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) self.DC_filter = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements))) ################################################## # Connections ################################################## self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0)) self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0)) self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0)) self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink, 0)) self.connect((self.rational_resampler, 0), (self.wxgui_fftsink, 0)) self.connect((self.fft_vxx_0, 0), (self.complex_to_mag, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 1)) self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 0), (self.speed_probe, 0)) self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 1), (self.direction_probe, 0)) self.connect((self.usrp_receiver, 0), (self.wxgui_fftsink2_full_spectrum, 0)) self.connect((self.usrp_receiver, 0), (self.rational_resampler, 0)) self.connect((self.usrp_receiver, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.usrp_transmitter, 0))
def __init__(self): 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()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.center_freq = center_freq = 0 ################################################## # Blocks ################################################## self.freq_sweep_probe = blocks.probe_signal_f() def _center_freq_probe(): while True: val = self.freq_sweep_probe.level() try: self.set_center_freq(val) except AttributeError: pass time.sleep(1.0 / (10)) _center_freq_thread = threading.Thread(target=_center_freq_probe) _center_freq_thread.daemon = True _center_freq_thread.start() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_int * 1, samp_rate, True) self.blocks_int_to_float_1 = blocks.int_to_float(1, 1) self.audio_sink_0 = audio.sink(samp_rate, "", True) self.analog_sig_source_x_1 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, center_freq * 300 + 300, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_i( samp_rate, analog.GR_SAW_WAVE, 0.1, 3, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_int_to_float_1, 0), (self.freq_sweep_probe, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_int_to_float_1, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Vid") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.variable_slider_1 = variable_slider_1 = 500 self.variable_slider_0 = variable_slider_0 = 0 self.snr = snr = 0 self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## _variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_1_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, label="signal", converter=forms.float_converter(), proportion=0, ) self._variable_slider_1_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, minimum=0, maximum=1000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_variable_slider_1_sizer) _variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_0_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, label="noise", converter=forms.float_converter(), proportion=0, ) self._variable_slider_0_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_variable_slider_0_sizer) def _snr_probe(): while True: val = self.my_block_0.get_number() try: self.set_snr(val) except AttributeError: pass time.sleep(1.0 / (10)) _snr_thread = threading.Thread(target=_snr_probe) _snr_thread.daemon = True _snr_thread.start() self.digital_gmsk_mod_0 = digital.gmsk_mod( samples_per_symbol=2, bt=0.35, verbose=False, log=False, ) self.digital_gmsk_demod_0 = digital.gmsk_demod( samples_per_symbol=2, gain_mu=0.175, mu=0.5, omega_relative_limit=0.005, freq_error=0.0, verbose=False, log=False, ) self.blocks_probe_signal_x_0 = blocks.probe_signal_f() self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((500, )) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char * 1, "video1.ts", False) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, "video2.ts", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b( grc_blks2.packet_encoder( samples_per_symbol=2, bits_per_symbol=1, preamble="", access_code="", pad_for_usrp=True, ), payload_length=0, ) self.blks2_packet_decoder_0 = grc_blks2.packet_demod_c( grc_blks2.packet_decoder( access_code="", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0. recv_pkt(ok, payload), ), ) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 0, 0) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 2500) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blks2_packet_decoder_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_gmsk_demod_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blks2_packet_encoder_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_x_0, 0)) self.connect((self.digital_gmsk_demod_0, 0), (self.blks2_packet_decoder_0, 0)) self.connect((self.digital_gmsk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="DVB-T Signal Detector using RTL-SDR") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.threshold = threshold = -70 self.samp_rate = samp_rate = 2048000 self.probe_level = probe_level = 0 self.probe_detection = probe_detection = 0 self.freq = freq = 525200000 self.fft_size = fft_size = 1024 ################################################## # Blocks ################################################## _threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, label="Threshold", converter=forms.float_converter(), proportion=0, ) self._threshold_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, minimum=-100, maximum=0, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_threshold_sizer) self.probe_signal_level = blocks.probe_signal_f() self.probe_signal_detection = blocks.probe_signal_f() self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Waterfall") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Spectrum") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Output") self.Add(self.notebook) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="freq", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=478000000, maximum=862000000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freq_sizer) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=freq, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=fft_size, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", win=window.rectangular, ) self.notebook.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_numbersink2_1 = numbersink2.number_sink_f( self.notebook.GetPage(2).GetWin(), unit="dB", minval=-120, maxval=0, factor=1, decimal_places=0, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=0.03, label="Level", peak_hold=False, show_gauge=True, ) self.notebook.GetPage(2).Add(self.wxgui_numbersink2_1.win) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.notebook.GetPage(2).GetWin(), unit="signal present", minval=0, maxval=1, factor=1.0, decimal_places=0, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=None, label="Signal Detector", peak_hold=False, show_gauge=True, ) self.notebook.GetPage(2).Add(self.wxgui_numbersink2_0.win) self.wxgui_fftsink2_1 = fftsink2.fft_sink_c( self.notebook.GetPage(1).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=fft_size, fft_rate=15, average=False, avg_alpha=None, title="Spectrum", peak_hold=False, win=window.rectangular, ) self.notebook.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(freq, 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(False, 0) self.rtlsdr_source_0.set_gain(20, 0) self.rtlsdr_source_0.set_if_gain(10, 0) self.rtlsdr_source_0.set_bb_gain(5, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) def _probe_level_probe(): while True: val = self.probe_signal_level.level() try: self.set_probe_level(val) except AttributeError, e: pass time.sleep(1.0 / (10))
def __init__(self): gr.top_block.__init__(self, "If Else") Qt.QWidget.__init__(self) self.setWindowTitle("If Else") 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", "if_else") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.variable_function_probe_0 = variable_function_probe_0 = 0 self.samp_rate = samp_rate = 32000 self.freq = freq = 1000 self.ampl = ampl = 1 ################################################## # Blocks ################################################## self.probe = blocks.probe_signal_f() self._freq_tool_bar = Qt.QToolBar(self) self._freq_tool_bar.addWidget(Qt.QLabel("freq"+": ")) self._freq_line_edit = Qt.QLineEdit(str(self.freq)) self._freq_tool_bar.addWidget(self._freq_line_edit) self._freq_line_edit.returnPressed.connect( lambda: self.set_freq(int(self._freq_line_edit.text().toAscii()))) self.top_layout.addWidget(self._freq_tool_bar) self._ampl_tool_bar = Qt.QToolBar(self) self._ampl_tool_bar.addWidget(Qt.QLabel("ampl"+": ")) self._ampl_line_edit = Qt.QLineEdit(str(self.ampl)) self._ampl_tool_bar.addWidget(self._ampl_line_edit) self._ampl_line_edit.returnPressed.connect( lambda: self.set_ampl(int(self._ampl_line_edit.text().toAscii()))) self.top_layout.addWidget(self._ampl_tool_bar) def _variable_function_probe_0_probe(): while True: val = self.probe.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (10)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "QT GUI Plot", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True) self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, freq, ampl, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.probe, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.qtgui_time_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "Adsb Uhd") Qt.QWidget.__init__(self) self.setWindowTitle("Adsb Uhd") qtgui.util.check_set_qss() 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", "adsb_uhd") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.thresh_mult = thresh_mult = 2 self.samp_rate = samp_rate = 2e6 self.low_thresh = low_thresh = 0 self.rx_gain = rx_gain = 40 self.low_thresh_lbl = low_thresh_lbl = low_thresh self.high = high = .4 self.hi_thresh_lbl = hi_thresh_lbl = low_thresh * thresh_mult self.freq = freq = 1090e6 self.filter_taps = filter_taps = firdes.low_pass( 1, samp_rate, samp_rate / 2, 50000, firdes.WIN_FLATTOP, 6.76) self.decim = decim = 1 self.center = center = 0 self.bb_gain = bb_gain = .1e6 ################################################## # Message Queues ################################################## adsb_decoder_0_msgq_out = baz_message_server_0_msgq_in = gr.msg_queue( 2) adsb_decoder_0_msgq_out = blocks_message_source_0_msgq_in = gr.msg_queue( 2) adsb_framer_0_msgq_out = adsb_decoder_0_msgq_in = gr.msg_queue(2) ################################################## # Blocks ################################################## self.probe_power = blocks.probe_signal_f() self._thresh_mult_tool_bar = Qt.QToolBar(self) self._thresh_mult_tool_bar.addWidget(Qt.QLabel("thresh_mult" + ": ")) self._thresh_mult_line_edit = Qt.QLineEdit(str(self.thresh_mult)) self._thresh_mult_tool_bar.addWidget(self._thresh_mult_line_edit) self._thresh_mult_line_edit.returnPressed.connect( lambda: self.set_thresh_mult( eng_notation.str_to_num( str(self._thresh_mult_line_edit.text().toAscii())))) self.top_layout.addWidget(self._thresh_mult_tool_bar) self._rx_gain_tool_bar = Qt.QToolBar(self) self._rx_gain_tool_bar.addWidget(Qt.QLabel("rx_gain" + ": ")) self._rx_gain_line_edit = Qt.QLineEdit(str(self.rx_gain)) self._rx_gain_tool_bar.addWidget(self._rx_gain_line_edit) self._rx_gain_line_edit.returnPressed.connect(lambda: self.set_rx_gain( eng_notation.str_to_num( str(self._rx_gain_line_edit.text().toAscii())))) self.top_layout.addWidget(self._rx_gain_tool_bar) def _low_thresh_probe(): while True: val = self.probe_power.level() try: self.set_low_thresh(val) except AttributeError: pass time.sleep(1.0 / (10)) _low_thresh_thread = threading.Thread(target=_low_thresh_probe) _low_thresh_thread.daemon = True _low_thresh_thread.start() self._center_tool_bar = Qt.QToolBar(self) self._center_tool_bar.addWidget(Qt.QLabel("center" + ": ")) self._center_line_edit = Qt.QLineEdit(str(self.center)) self._center_tool_bar.addWidget(self._center_line_edit) self._center_line_edit.returnPressed.connect(lambda: self.set_center( eng_notation.str_to_num( str(self._center_line_edit.text().toAscii())))) self.top_layout.addWidget(self._center_tool_bar) self._bb_gain_tool_bar = Qt.QToolBar(self) self._bb_gain_tool_bar.addWidget(Qt.QLabel("bb_gain" + ": ")) self._bb_gain_line_edit = Qt.QLineEdit(str(self.bb_gain)) self._bb_gain_tool_bar.addWidget(self._bb_gain_line_edit) self._bb_gain_line_edit.returnPressed.connect(lambda: self.set_bb_gain( eng_notation.str_to_num( str(self._bb_gain_line_edit.text().toAscii())))) self.top_layout.addWidget(self._bb_gain_tool_bar) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq( uhd.tune_request(freq, samp_rate / 2), 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.01) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [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_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-130, -70) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_waterfall_sink_x_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 4096, #size samp_rate, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.010) self.qtgui_time_sink_x_0.set_y_axis(0, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, .3, .0001, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['pre', 'post', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.01) self.qtgui_freq_sink_x_0.set_y_axis(-140, -80) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_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.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self._low_thresh_lbl_tool_bar = Qt.QToolBar(self) if None: self._low_thresh_lbl_formatter = None else: self._low_thresh_lbl_formatter = lambda x: x self._low_thresh_lbl_tool_bar.addWidget( Qt.QLabel("low_thresh_lbl" + ": ")) self._low_thresh_lbl_label = Qt.QLabel( str(self._low_thresh_lbl_formatter(self.low_thresh_lbl))) self._low_thresh_lbl_tool_bar.addWidget(self._low_thresh_lbl_label) self.top_layout.addWidget(self._low_thresh_lbl_tool_bar) self._high_tool_bar = Qt.QToolBar(self) self._high_tool_bar.addWidget(Qt.QLabel("high" + ": ")) self._high_line_edit = Qt.QLineEdit(str(self.high)) self._high_tool_bar.addWidget(self._high_line_edit) self._high_line_edit.returnPressed.connect(lambda: self.set_high( eng_notation.str_to_num(str(self._high_line_edit.text().toAscii())) )) self.top_layout.addWidget(self._high_tool_bar) self._hi_thresh_lbl_tool_bar = Qt.QToolBar(self) if None: self._hi_thresh_lbl_formatter = None else: self._hi_thresh_lbl_formatter = lambda x: x self._hi_thresh_lbl_tool_bar.addWidget( Qt.QLabel("hi_thresh_lbl" + ": ")) self._hi_thresh_lbl_label = Qt.QLabel( str(self._hi_thresh_lbl_formatter(self.hi_thresh_lbl))) self._hi_thresh_lbl_tool_bar.addWidget(self._hi_thresh_lbl_label) self.top_layout.addWidget(self._hi_thresh_lbl_tool_bar) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, (filter_taps), center, samp_rate) self.digital_correlate_access_code_tag_bb_0 = digital.correlate_access_code_tag_bb( '1010000101000000', 0, 'adsb_preamble') self.blocks_threshold_ff_0 = blocks.threshold_ff( low_thresh, low_thresh * thresh_mult, 0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (bb_gain, )) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( 1000, .0001, 4000) self.blocks_message_source_0 = blocks.message_source( gr.sizeof_char * 1, blocks_message_source_0_msgq_in) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, '/dev/stdout', True) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.baz_message_server_0 = message_server.message_server( msgq=baz_message_server_0_msgq_in, port=12345) self.adsb_framer_0 = adsb.framer(tx_msgq=adsb_framer_0_msgq_out) self.adsb_decoder_0 = adsb.decoder(rx_msgq=adsb_decoder_0_msgq_in, tx_msgq=adsb_decoder_0_msgq_out, output_type="csv", check_parity=True) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.digital_correlate_access_code_tag_bb_0, 0)) self.connect((self.blocks_message_source_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.probe_power, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.digital_correlate_access_code_tag_bb_0, 0), (self.adsb_framer_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self, options): gr.top_block.__init__(self, "Superposition coding with MPSK modulation") Qt.QWidget.__init__(self) self.setWindowTitle("Superposition coding with MPSK modulation") qtgui.util.check_set_qss() 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", "SIC_MPSK") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.snr_db = snr_db = options.snr self.const_type = const_type = 1 self.variable_qtgui_label_0 = variable_qtgui_label_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.noisevar = noisevar = 10**(-snr_db / 10) self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.block = block = 1000 self.alpha = alpha = options.alpha self.R = R = 100e3 ################################################## # Blocks ################################################## self._alpha_range = Range(0, 1, .01, options.alpha, 200) self._alpha_win = RangeWidget(self._alpha_range, self.set_alpha, 'Alpha (P1/P)', "counter_slider", float) self.top_layout.addWidget(self._alpha_win) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('Constellation Type' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self._snr_db_range = Range(0, 20, 1, options.snr, 200) self._snr_db_win = RangeWidget(self._snr_db_range, self.set_snr_db, 'P/sigma^2 (dB)', "counter_slider", float) self.top_layout.addWidget(self._snr_db_win) #Add variable to save BER 1 after sic #self.ber_sink_1_after_sic = blocks.vector_sink_f() self.ber_sink_1_after_sic = blocks.probe_signal_f() labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.ber_sink_2_after_sic = blocks.probe_signal_f() labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.ber_sink_2_before = blocks.probe_signal_f() labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.ber_sink_1_before = blocks.probe_signal_f() labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "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(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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.digital_constellation_decoder_cb_0_0_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_chunks_to_symbols_xx_2 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx_1_0 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_char * 1, R, True) self.blocks_sub_xx_2_0 = blocks.sub_cc(1) self.blocks_sub_xx_2 = blocks.sub_cc(1) self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_vcc( ((1 - alpha)**0.5, )) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vcc( (alpha**0.5, )) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc( ((1 - alpha)**0.5, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (alpha**0.5, )) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blks2_error_rate_0_0_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.analog_random_source_x_1 = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), block)), True) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), block)), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, noisevar, -42) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.analog_random_source_x_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blks2_error_rate_0_0_0_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0_1, 0)) self.connect((self.analog_random_source_x_1, 0), (self.blks2_error_rate_0_0, 0)) self.connect((self.analog_random_source_x_1, 0), (self.blks2_error_rate_0_0_0, 0)) self.connect((self.analog_random_source_x_1, 0), (self.digital_chunks_to_symbols_xx_2, 0)) self.connect((self.blks2_error_rate_0, 0), (self.ber_sink_1_before, 0)) self.connect((self.blks2_error_rate_0_0, 0), (self.ber_sink_2_before, 0)) self.connect((self.blks2_error_rate_0_0_0, 0), (self.ber_sink_2_after_sic, 0)) self.connect((self.blks2_error_rate_0_0_0_0, 0), (self.ber_sink_1_after_sic, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_sub_xx_2, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_sub_xx_2_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_sub_xx_2, 1)) self.connect((self.blocks_multiply_const_vxx_2_0, 0), (self.blocks_sub_xx_2_0, 1)) self.connect((self.blocks_sub_xx_2, 0), (self.digital_constellation_decoder_cb_0_0_0, 0)) self.connect((self.blocks_sub_xx_2_0, 0), (self.digital_constellation_decoder_cb_0_0_0_0, 0)) self.connect((self.blocks_throttle_0_1, 0), (self.digital_chunks_to_symbols_xx, 0)) self.connect((self.digital_chunks_to_symbols_xx, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.digital_chunks_to_symbols_xx_1_0, 0), (self.blocks_multiply_const_vxx_2_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_2, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.blks2_error_rate_0_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_chunks_to_symbols_xx_1_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0_0, 0), (self.blks2_error_rate_0_0_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0_0_0, 0), (self.blks2_error_rate_0_0_0_0, 1))
def __init__(self): gr.top_block.__init__(self, "bladeRF_transceiver") ################################################## # Variables ################################################## self.symbole_rate = symbole_rate = 10e3 self.samp_rate = samp_rate = 1e6 self.rat_interop = rat_interop = 8 self.rat_decim = rat_decim = 5 self.firdes_transition_width = firdes_transition_width = 15000 self.firdes_decim = firdes_decim = 4 self.firdes_cuttoff = firdes_cuttoff = 21e3 self.tx_valve_value = tx_valve_value = False self.tx_rf_gain = tx_rf_gain = 10 self.tx_bb_gain = tx_bb_gain = -20 self.samp_per_sym_source = samp_per_sym_source = ( (samp_rate / 2 / firdes_decim) * rat_interop / rat_decim) / symbole_rate self.samp_per_sym = samp_per_sym = int(samp_rate / symbole_rate) self.rx_valve_value = rx_valve_value = False self.rx_rf_gain = rx_rf_gain = 3 self.rx_bb_gain = rx_bb_gain = 20 self.preamble = preamble = '0101010101010101' self.msg_source_msgq_in = msg_source_msgq_in = gr.msg_queue(2) self.msg_sink_msgq_out = msg_sink_msgq_out = gr.msg_queue(2) self.frequency_tx = frequency_tx = 450e6 self.frequency_shift = frequency_shift = 520000 self.frequency_rx = frequency_rx = 450.0e6 self.firdes_filter = firdes_filter = firdes.low_pass( 1, samp_rate / 2, firdes_cuttoff, firdes_transition_width) self.bit_per_sym = bit_per_sym = 1 self.bandwith = bandwith = 6e6 self.access_code = access_code = '11010011100100011101001110010001' ################################################## # Blocks ################################################## self.xlating_fir_filter_1 = filter.freq_xlating_fir_filter_ccc( 2, (1, ), frequency_shift, samp_rate) self.xlating_fir_filter_0 = filter.freq_xlating_fir_filter_ccc( firdes_decim, (firdes_filter), 0, samp_rate / 2) self.tx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex * 1, open=bool(tx_valve_value)) self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate / 2, True) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( 0.05, 1) self.rx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex * 1, open=bool(rx_valve_value)) self.rational_resampler = filter.rational_resampler_ccc( interpolation=rat_interop, decimation=rat_decim, taps=None, fractional_bw=None, ) self.quadrature_demod = analog.quadrature_demod_cf(2) self.probe_signal_2 = blocks.probe_signal_f() self.probe_signal_1 = blocks.probe_signal_f() self.osmosdr_source = osmosdr.source(args="numchan=" + str(1) + " " + "bladerf=0") self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(frequency_rx - frequency_shift, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(2, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(rx_rf_gain, 0) self.osmosdr_source.set_if_gain(0, 0) self.osmosdr_source.set_bb_gain(rx_bb_gain, 0) self.osmosdr_source.set_antenna("", 0) self.osmosdr_source.set_bandwidth(bandwith, 0) self.osmosdr_sink = osmosdr.sink(args="numchan=" + str(1) + " " + "bladerf=0") self.osmosdr_sink.set_sample_rate(samp_rate) self.osmosdr_sink.set_center_freq(frequency_tx, 0) self.osmosdr_sink.set_freq_corr(0, 0) self.osmosdr_sink.set_gain(tx_rf_gain, 0) self.osmosdr_sink.set_if_gain(0, 0) self.osmosdr_sink.set_bb_gain(tx_bb_gain, 0) self.osmosdr_sink.set_antenna("", 0) self.osmosdr_sink.set_bandwidth(bandwith, 0) self.nlog10_ff = blocks.nlog10_ff(10, 1, 0) self.gmsk_mod = digital.gmsk_mod( samples_per_symbol=int(samp_per_sym), bt=0.5, verbose=False, log=False, ) self.correlate_access_code = digital.correlate_access_code_bb( access_code, 4) self.clock_recovery = digital.clock_recovery_mm_ff( samp_per_sym_source * (1 + 0.0), 0.25 * 0.175 * 0.175, 0.5, 0.175, 0.005) self.cc1111_packet_encoder = cc1111.cc1111_packet_mod_base( cc1111.cc1111_packet_encoder(samples_per_symbol=samp_per_sym, bits_per_symbol=bit_per_sym, preamble=preamble, access_code=access_code, pad_for_usrp=True, do_whitening=True, add_crc=True), source_queue=msg_source_msgq_in) self.cc1111_packet_decoder = cc1111.cc1111_packet_decoder( msg_sink_msgq_out, True, True, False, True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_keep_one_in_n = blocks.keep_one_in_n( gr.sizeof_float * 1, int(samp_rate / 30)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1000) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.binary_slicer = digital.binary_slicer_fb() self.avg_mag_sqrd = analog.probe_avg_mag_sqrd_c(0, 1) ################################################## # Connections ################################################## self.connect((self.binary_slicer, 0), (self.correlate_access_code, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.probe_signal_2, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.osmosdr_sink, 0)) self.connect((self.blocks_keep_one_in_n, 0), (self.nlog10_ff, 0)) self.connect((self.cc1111_packet_decoder, 0), (self.blocks_null_sink_0, 0)) self.connect((self.cc1111_packet_encoder, 0), (self.gmsk_mod, 0)) self.connect((self.clock_recovery, 0), (self.binary_slicer, 0)) self.connect((self.correlate_access_code, 0), (self.cc1111_packet_decoder, 0)) self.connect((self.gmsk_mod, 0), (self.tx_valve, 0)) self.connect((self.nlog10_ff, 0), (self.probe_signal_1, 0)) self.connect((self.osmosdr_source, 0), (self.rx_valve, 0)) self.connect((self.quadrature_demod, 0), (self.clock_recovery, 0)) self.connect((self.rational_resampler, 0), (self.quadrature_demod, 0)) self.connect((self.rx_valve, 0), (self.avg_mag_sqrd, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.rx_valve, 0), (self.xlating_fir_filter_1, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n, 0)) self.connect((self.throttle, 0), (self.xlating_fir_filter_0, 0)) self.connect((self.tx_valve, 0), (self.blocks_delay_0, 0)) self.connect((self.xlating_fir_filter_0, 0), (self.rational_resampler, 0)) self.connect((self.xlating_fir_filter_1, 0), (self.throttle, 0))
def __init__(self): gr.top_block.__init__(self, "Bpsk Receiverpoly") ################################################## # Variables ################################################## self.sps = sps = 8 self.probe_var = probe_var = 0 self.nfilts = nfilts = 32 self.eb = eb = 0.35 self.SNR = SNR = 500 self.transistion = transistion = 100 self.timing_loop_bw = timing_loop_bw = 6.28/100.0 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts/16, nfilts/16, 1.0/float(sps), 0.35, 11*sps*nfilts/16) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.probe_var_n = probe_var_n = 0 self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1] self.phase_bw = phase_bw = 6.28/100.0 self.noise_amp = noise_amp = probe_var/(10**(SNR/20)) self.matched_filter = matched_filter = firdes.root_raised_cosine(nfilts, nfilts, 1, eb, int(11*sps*nfilts)) self.interpolation = interpolation = 2000 self.eq_gain = eq_gain = 0.01 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist(([1,- 1]), ([0,1]), 2, 1).base() self.carrier = carrier = 10000 self.arity = arity = 2 ################################################## # Blocks ################################################## self.probe_rms = blocks.probe_signal_f() self.probe_avg_n = blocks.probe_signal_f() self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=decimation, decimation=interpolation, taps=(rrc_taps), fractional_bw=None, ) def _probe_var_n_probe(): while True: val = self.probe_avg_n.level() try: self.set_probe_var_n(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_n_thread = threading.Thread(target=_probe_var_n_probe) _probe_var_n_thread.daemon = True _probe_var_n_thread.start() def _probe_var_probe(): while True: val = self.probe_rms.level() try: self.set_probe_var(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_var_thread = threading.Thread(target=_probe_var_probe) _probe_var_thread.daemon = True _probe_var_thread.start() self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc(1, (filter.firdes.low_pass(1, samp_rate*10, sideband_rx,1000)), carrier, samp_rate) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 1) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constel) script, SNRinput, inputwav, outputBinary, delay= argv self.blocks_wavfile_source_0 = blocks.wavfile_source(inputwav, False) self.blocks_throttle_1_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_rms_xx_1 = blocks.rms_cf(0.01) self.blocks_rms_xx_0 = blocks.rms_cf(0.01) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, outputBinary, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_1 = blocks.delay(gr.sizeof_char*1, int(delay)) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, noise_amp, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_rms_xx_1, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.probe_rms, 0)) self.connect((self.blocks_rms_xx_1, 0), (self.probe_avg_n, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_throttle_1_0_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_delay_1, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_throttle_1_0_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="DVBT Scanner") ################################################## # Variables ################################################## self.threshold = threshold = -60 self.signal_level = signal_level = 0 self.samp_rate = samp_rate = 2048000 self.freq = freq = 525200000 self.fft_size = fft_size = 1024 self.detected = detected = 0 ################################################## # Blocks ################################################## _threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, label="Threshold", converter=forms.float_converter(), proportion=0, ) self._threshold_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, minimum=-100, maximum=0, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_threshold_sizer, 2, 0, 1, 1) self.probe_signal_lvl = blocks.probe_signal_f() self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Spektrum") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Output") self.GridAdd(self.notebook, 0, 0, 1, 1) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="Frequency", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=478000000, maximum=862000000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_sizer, 1, 0, 1, 1) self.wxgui_numbersink2_1 = numbersink2.number_sink_f( self.notebook.GetPage(1).GetWin(), unit="Signal present", minval=0, maxval=1, factor=1.0, decimal_places=0, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=None, label="Signal Detection", peak_hold=False, show_gauge=True, ) self.notebook.GetPage(1).Add(self.wxgui_numbersink2_1.win) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.notebook.GetPage(1).GetWin(), unit="dB", minval=-120, maxval=0, factor=1.0, decimal_places=1, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=0.03, label="Level", peak_hold=False, show_gauge=True, ) self.notebook.GetPage(1).Add(self.wxgui_numbersink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=fft_size, fft_rate=15, average=True, avg_alpha=0.03, title="FFT Plot", peak_hold=False, win=window.flattop, ) self.notebook.GetPage(0).Add(self.wxgui_fftsink2_0.win) def _signal_level_probe(): while True: val = self.probe_signal_lvl.level() try: self.set_signal_level(val) except AttributeError: pass time.sleep(1.0 / (5)) _signal_level_thread = threading.Thread(target=_signal_level_probe) _signal_level_thread.daemon = True _signal_level_thread.start() self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "hackrf=0" ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(freq, 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(False, 0) self.rtlsdr_source_0.set_gain(14, 0) self.rtlsdr_source_0.set_if_gain(24, 0) self.rtlsdr_source_0.set_bb_gain(12, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.probe_detected = blocks.probe_signal_f() self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.rectangular(fft_size)), True, 1) def _detected_probe(): while True: val = self.probe_detected.level() try: self.set_detected(val) except AttributeError: pass time.sleep(1.0 / (5)) _detected_thread = threading.Thread(target=_detected_probe) _detected_thread.daemon = True _detected_thread.start() self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_size) self.blocks_threshold_ff_0 = blocks.threshold_ff(threshold, threshold, threshold) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(1000, 0.001, 4000) self.blocks_divide_xx_0 = blocks.divide_ff(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size) self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 1048580) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.probe_signal_lvl, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.probe_detected, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_numbersink2_1, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="cdma_txrx") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.N0est = N0est = 1.0 self.Esest = Esest = 1e-1 self.EsN0dB_est = EsN0dB_est = 10*numpy.log10( cp.epsilon+ abs(Esest)/ (abs(N0est)+cp.epsilon) ) self.symbol_rate = symbol_rate = 100e3 self.DataEsN0dBthreshold = DataEsN0dBthreshold = 10 self.DataEsN0dB_est = DataEsN0dB_est = EsN0dB_est + 10*numpy.log10( 1.0-cp.training_percent/100.0 ) self.samp_rate = samp_rate = symbol_rate*cp.chips_per_symbol self.onoff_manual = onoff_manual = 1 self.onoff_auto = onoff_auto = 0 if DataEsN0dB_est>DataEsN0dBthreshold else 1 self.manual = manual = 1 self.onoff = onoff = onoff_auto if manual==0 else onoff_manual self.freq_acq_est = freq_acq_est = 0 self.df = df = cp.df*samp_rate self.TrainingEsN0dB_est = TrainingEsN0dB_est = EsN0dB_est + 10*numpy.log10( cp.training_percent/100.0 ) self.EsN0dB = EsN0dB = 20 self.Es = Es = 1 self.variable_static_text = variable_static_text = 'Acquisition' if onoff==1 else 'Tracking' self.n_filt = n_filt = cp.n_filt self.freq_est_acq = freq_est_acq = freq_acq_est self.fmaxt = fmaxt = cp.freqs[-1]*samp_rate self.drift = drift = 0 self.dft = dft = df self.df_Hz = df_Hz = 0 self.delay = delay = 0 self.acq_threshold_dB = acq_threshold_dB = -8.5 self.TrainingEsN0dB = TrainingEsN0dB = TrainingEsN0dB_est self.N0 = N0 = 10**(-EsN0dB/10) * Es self.DataEsN0dB_estimated = DataEsN0dB_estimated = DataEsN0dB_est ################################################## # Blocks ################################################## _drift_sizer = wx.BoxSizer(wx.VERTICAL) self._drift_text_box = forms.text_box( parent=self.GetWin(), sizer=_drift_sizer, value=self.drift, callback=self.set_drift, label="drift (ppm)", converter=forms.float_converter(), proportion=0, ) self._drift_slider = forms.slider( parent=self.GetWin(), sizer=_drift_sizer, value=self.drift, callback=self.set_drift, minimum=0, maximum=2, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_drift_sizer, 3, 0, 1, 1) _df_Hz_sizer = wx.BoxSizer(wx.VERTICAL) self._df_Hz_text_box = forms.text_box( parent=self.GetWin(), sizer=_df_Hz_sizer, value=self.df_Hz, callback=self.set_df_Hz, label="df_Hz", converter=forms.float_converter(), proportion=0, ) self._df_Hz_slider = forms.slider( parent=self.GetWin(), sizer=_df_Hz_sizer, value=self.df_Hz, callback=self.set_df_Hz, minimum=(cp.freqs[0]*samp_rate)-1e-6, maximum=cp.freqs[-1]*samp_rate, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_df_Hz_sizer, 1, 0, 1, 1) _delay_sizer = wx.BoxSizer(wx.VERTICAL) self._delay_text_box = forms.text_box( parent=self.GetWin(), sizer=_delay_sizer, value=self.delay, callback=self.set_delay, label="delay", converter=forms.int_converter(), proportion=0, ) self._delay_slider = forms.slider( parent=self.GetWin(), sizer=_delay_sizer, value=self.delay, callback=self.set_delay, minimum=0, maximum=100-1, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_delay_sizer, 2, 0, 1, 1) self.blocks_probe_signal_n0 = blocks.probe_signal_f() self.blocks_probe_signal_amp = blocks.probe_signal_f() self.blocks_probe_freq = blocks.probe_signal_f() _acq_threshold_dB_sizer = wx.BoxSizer(wx.VERTICAL) self._acq_threshold_dB_text_box = forms.text_box( parent=self.GetWin(), sizer=_acq_threshold_dB_sizer, value=self.acq_threshold_dB, callback=self.set_acq_threshold_dB, label="acq_threshold_dB", converter=forms.float_converter(), proportion=0, ) self._acq_threshold_dB_slider = forms.slider( parent=self.GetWin(), sizer=_acq_threshold_dB_sizer, value=self.acq_threshold_dB, callback=self.set_acq_threshold_dB, minimum=-30, maximum=20, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_acq_threshold_dB_sizer, 7, 0, 1, 1) self._variable_static_text_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text, callback=self.set_variable_static_text, label="Ack/Tra Status", converter=forms.str_converter(), ) self.GridAdd(self._variable_static_text_static_text, 4, 0, 1, 1) self._onoff_manual_chooser = forms.button( parent=self.GetWin(), value=self.onoff_manual, callback=self.set_onoff_manual, label="Manual Acq/Tra", choices=[0,1], labels=['Tracking','Acquisition'], ) self.GridAdd(self._onoff_manual_chooser, 5, 0, 1, 1) self._n_filt_static_text = forms.static_text( parent=self.GetWin(), value=self.n_filt, callback=self.set_n_filt, label="n_filt", converter=forms.int_converter(), ) self.Add(self._n_filt_static_text) self._manual_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.manual, callback=self.set_manual, label="Manual/Auto", choices=[0,1], labels=['Auto','Manual'], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._manual_chooser, 6, 0, 1, 1) self._freq_est_acq_static_text = forms.static_text( parent=self.GetWin(), value=self.freq_est_acq, callback=self.set_freq_est_acq, label='freq_est_acq', converter=forms.float_converter(), ) self.Add(self._freq_est_acq_static_text) def _freq_acq_est_probe(): while True: val = self.blocks_probe_freq.level() try: self.set_freq_acq_est(val) except AttributeError: pass time.sleep(1.0 / (10)) _freq_acq_est_thread = threading.Thread(target=_freq_acq_est_probe) _freq_acq_est_thread.daemon = True _freq_acq_est_thread.start() self._fmaxt_static_text = forms.static_text( parent=self.GetWin(), value=self.fmaxt, callback=self.set_fmaxt, label="f_max (Hz)", converter=forms.float_converter(), ) self.Add(self._fmaxt_static_text) self._dft_static_text = forms.static_text( parent=self.GetWin(), value=self.dft, callback=self.set_dft, label="Deltaf (Hz)", converter=forms.float_converter(), ) self.Add(self._dft_static_text) self.channels_channel_model_0 = channels.channel_model( noise_voltage=(cp.chips_per_symbol*cp.samples_per_chip*N0/2)**0.5, frequency_offset=df_Hz/samp_rate, epsilon=1.0+drift*1e-6, taps=((delay)*(0,)+(1,)+(100-1-delay)*(0,)), noise_seed=0, block_tags=False ) self.cdma_tx_hier_0 = cdma_tx_hier() self.cdma_rx_hier_0 = cdma_rx_hier( acq=onoff, acq_threshold_dB=acq_threshold_dB, ) self.cdma_pac_err_cal_0 = cdma.pac_err_cal(1000, 2**cp.cdma_packet_num_bit, "cdma_packet_num") self.blocks_vector_source_x_0_1 = blocks.vector_source_b(map(int,numpy.random.randint(0,256,cp.payload_bytes_per_frame)), True, 1, tagged_streams.make_lengthtags((cp.payload_bytes_per_frame,), (0,), cp.length_tag_name)) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_char*1, (symbol_rate*cp.bits_per_uncoded_symbol)/8,True) self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char*1) self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((samp_rate, )) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((Es**0.5, )) self._TrainingEsN0dB_static_text = forms.static_text( parent=self.GetWin(), value=self.TrainingEsN0dB, callback=self.set_TrainingEsN0dB, label="TrainingEsN0dB_est", converter=forms.float_converter(), ) self.Add(self._TrainingEsN0dB_static_text) def _N0est_probe(): while True: val = self.blocks_probe_signal_n0.level() try: self.set_N0est(val) except AttributeError: pass time.sleep(1.0 / (10)) _N0est_thread = threading.Thread(target=_N0est_probe) _N0est_thread.daemon = True _N0est_thread.start() def _Esest_probe(): while True: val = self.blocks_probe_signal_amp.level() try: self.set_Esest(val) except AttributeError: pass time.sleep(1.0 / (10)) _Esest_thread = threading.Thread(target=_Esest_probe) _Esest_thread.daemon = True _Esest_thread.start() _EsN0dB_sizer = wx.BoxSizer(wx.VERTICAL) self._EsN0dB_text_box = forms.text_box( parent=self.GetWin(), sizer=_EsN0dB_sizer, value=self.EsN0dB, callback=self.set_EsN0dB, label="EsN0dB", converter=forms.float_converter(), proportion=0, ) self._EsN0dB_slider = forms.slider( parent=self.GetWin(), sizer=_EsN0dB_sizer, value=self.EsN0dB, callback=self.set_EsN0dB, minimum=-20, maximum=80, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_EsN0dB_sizer, 0, 0, 1, 1) _DataEsN0dBthreshold_sizer = wx.BoxSizer(wx.VERTICAL) self._DataEsN0dBthreshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_DataEsN0dBthreshold_sizer, value=self.DataEsN0dBthreshold, callback=self.set_DataEsN0dBthreshold, label="DataEsN0dBthreshold", converter=forms.float_converter(), proportion=0, ) self._DataEsN0dBthreshold_slider = forms.slider( parent=self.GetWin(), sizer=_DataEsN0dBthreshold_sizer, value=self.DataEsN0dBthreshold, callback=self.set_DataEsN0dBthreshold, minimum=0, maximum=20, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_DataEsN0dBthreshold_sizer, 8, 0, 1, 1) self._DataEsN0dB_estimated_static_text = forms.static_text( parent=self.GetWin(), value=self.DataEsN0dB_estimated, callback=self.set_DataEsN0dB_estimated, label="DataEsN0dB_est", converter=forms.float_converter(), ) self.Add(self._DataEsN0dB_estimated_static_text) ################################################## # Connections ################################################## self.msg_connect((self.cdma_rx_hier_0, 'decoded_header'), (self.cdma_pac_err_cal_0, 'errCal')) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_probe_freq, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.blocks_null_sink_0_0, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.cdma_rx_hier_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.cdma_tx_hier_0, 0)) self.connect((self.blocks_vector_source_x_0_1, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.cdma_rx_hier_0, 3), (self.blocks_multiply_const_vxx_1_0, 0)) self.connect((self.cdma_rx_hier_0, 1), (self.blocks_null_sink_0, 0)) self.connect((self.cdma_rx_hier_0, 2), (self.blocks_probe_signal_amp, 0)) self.connect((self.cdma_rx_hier_0, 0), (self.blocks_probe_signal_n0, 0)) self.connect((self.cdma_tx_hier_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_tag_gate_0, 0))
def __init__(self): 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()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 #self.ac1=ac1 ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] 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(2 * 1): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "") self.osmosdr_sink_0.set_sample_rate(1e6) self.osmosdr_sink_0.set_center_freq(100e6, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(20, 0) self.osmosdr_sink_0.set_if_gain(30, 0) self.osmosdr_sink_0.set_bb_gain(30, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(400000, 0) self.file_source = blocks.file_source( gr.sizeof_float * 1, '/home/firas/Downloads/10.1.1.623.6305.pdf', True) self.digital_gmsk_mod_0 = digital.gmsk_mod( samples_per_symbol=2, bt=0.35, verbose=False, log=False, ) self.digital_gfsk_mod_0 = digital.gfsk_mod( samples_per_symbol=2, sensitivity=1.0, bt=0.35, verbose=False, log=False, ) if choice == 1: self.num = 0 self.g = 3 self.p = 5 self.y = 6 if choice == 2: self.num = 0 self.g = 5 self.p = 7 self.y = 9 num = pow(self.g, self.y) % self.p print(num) self.blocks_vector_source_x_0 = blocks.vector_source_f((num, num, num), True, 1, []) self.blocks_vector_source_x_1 = blocks.vector_source_f((1, 2, 3), True, 1, []) self.blks2_packet_encoder_0 = grc_blks2.packet_mod_f( grc_blks2.packet_encoder( samples_per_symbol=2, bits_per_symbol=1, preamble="", access_code="100010001000100010001111", pad_for_usrp=True, ), payload_length=1024, ) self.blks2_packet_encoder_1 = grc_blks2.packet_mod_f( grc_blks2.packet_encoder( samples_per_symbol=2, bits_per_symbol=1, preamble="", access_code="100010001000100010001000", pad_for_usrp=True, ), payload_length=512, ) self.blks2_packet_encoder_2 = grc_blks2.packet_mod_f( grc_blks2.packet_encoder( samples_per_symbol=2, bits_per_symbol=1, preamble="", access_code="100010001000100010101010", pad_for_usrp=True, ), payload_length=256, ) self.probe_sig_0 = blocks.probe_signal_f() ################################################## # Connections ################################################## self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blks2_packet_encoder_0, 0)) self.connect((self.digital_gmsk_mod_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.probe_sig_0, 0))