Exemplo n.º 1
0
    def __init__(self, options):
        gr.top_block.__init__(self, "GPS-SDR-SIM")

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink.set_samp_rate(options.sample_rate)
        self.uhd_usrp_sink.set_center_freq(options.frequency, 0)
        self.uhd_usrp_sink.set_gain(options.gain, 0)

        # a file source for the file generated by the gps-sdr-sim
        self.blocks_file_source = blocks.file_source(gr.sizeof_char*1, options.filename, True)

        # convert from signed bytes to short
        self.blocks_char_to_short = blocks.char_to_short(1)

        # convert from interleaved short to complex values
        self.blocks_interleaved_short_to_complex = blocks.interleaved_short_to_complex(False, False)

        # establish the connections
        self.connect((self.blocks_file_source, 0), (self.blocks_char_to_short, 0))
        self.connect((self.blocks_char_to_short, 0), (self.blocks_interleaved_short_to_complex, 0))
        self.connect((self.blocks_interleaved_short_to_complex, 0), (self.uhd_usrp_sink, 0))
Exemplo n.º 2
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 125e6

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.GetWin(),
        	baseband_freq=500e6,
        	dynamic_range=40,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.Add(self.wxgui_waterfallsink2_0.win)
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
                interpolation=3,
                decimation=125,
                taps=None,
                fractional_bw=None,
        )
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
                interpolation=48,
                decimation=30,
                taps=None,
                fractional_bw=None,
        )
        self.low_pass_filter_0 = filter.fir_filter_ccf(10, firdes.low_pass(
        	1, 3e6, 5e3, 8e3, firdes.WIN_HAMMING, 6.76))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(False, False)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short*1, "/dev/langford", True)
        self.audio_sink_0 = audio.sink(48000, "", True)
        self.analog_nbfm_rx_0 = analog.nbfm_rx(
        	audio_rate=30000,
        	quad_rate=300000,
        	tau=75e-6,
        	max_dev=5e3,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.analog_nbfm_rx_0, 0))
        self.connect((self.analog_nbfm_rx_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_interleaved_short_to_complex_0, 0), (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0), (self.low_pass_filter_0, 0))
Exemplo n.º 3
0
 def test_interleaved_short_to_complex(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
     src = blocks.vector_source_s(src_data)
     op = blocks.interleaved_short_to_complex()
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Exemplo n.º 4
0
    def __init__(self, channel_num=22, decim=50, directory="./", f_offset=0, fc=947.4e6, out_directory="./", samp_rate=25e6):
        gr.top_block.__init__(self, "Get Channel")

        ##################################################
        # Parameters
        ##################################################
        self.channel_num = channel_num
        self.decim = decim
        self.directory = directory
        self.f_offset = f_offset
        self.fc = fc
        self.out_directory = out_directory
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.SDCCH = SDCCH = 6
        self.RACH = RACH = 3
        self.PCH = PCH = 5
        self.CHANNEL_UNKNOWN = CHANNEL_UNKNOWN = 0
        self.CCCH = CCCH = 2
        self.BCCH = BCCH = 1
        self.AGCH = AGCH = 4

        ##################################################
        # Blocks
        ##################################################
        self.pfb_decimator_ccf_0 = pfb.decimator_ccf(
        	  decim,
        	  (),
        	  0,
        	  100,
                  True,
                  True)
        self.pfb_decimator_ccf_0.declare_sample_delay(0)
        	
        self.blocks_rotator_cc_0 = blocks.rotator_cc(-2*math.pi*(arfcn.get_freq_from_arfcn(channel_num,'e')-fc+f_offset)/samp_rate)
        self.blocks_interleaved_short_to_complex_1 = blocks.interleaved_short_to_complex(False, False)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short*1, "/home/piotr/Odbiornik_gsm/Hopping/test_data/nagranie_hopping_4", False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, ""+out_directory+"/fc_"+ str(channel_num) +".cfile", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_interleaved_short_to_complex_1, 0))    
        self.connect((self.blocks_interleaved_short_to_complex_1, 0), (self.blocks_rotator_cc_0, 0))    
        self.connect((self.blocks_rotator_cc_0, 0), (self.pfb_decimator_ccf_0, 0))    
        self.connect((self.pfb_decimator_ccf_0, 0), (self.blocks_file_sink_0, 0))    
Exemplo n.º 5
0
    def __init__(self, channels, resamp_rate, fc, band, samp_rate, input_file, dest_dir, data_type="complex"):
        gr.top_block.__init__(self, "grgsm_channelize")

        ##################################################
        # Parameters
        ##################################################
        self.channels = channels
        self.resamp_rate = resamp_rate
        self.fc = fc
        self.band = band
        self.samp_rate = samp_rate
        self.blocks_resamplers = {}
        self.blocks_rotators = {}
        self.blocks_file_sinks = {}
        
        ##################################################
        # Blocks and connections
        ##################################################
        self.source = None
        if data_type == "ishort":
            self.blocks_file_source = blocks.file_source(gr.sizeof_short, input_file, False)
            self.source = blocks.interleaved_short_to_complex(False, False)
            self.connect((self.blocks_file_source, 0), (self.source, 0))
        elif data_type == "complex":
            self.source = blocks.file_source(gr.sizeof_gr_complex, input_file, False)

        fc_str = eng_notation.num_to_str(fc)
        print("Extracting channels %s, given center frequency at %sHz (ARFCN %d)" % (str(ca), fc_str, center_arfcn))

        for channel in channels:
            channel_freq = arfcn.arfcn2downlink(channel, band)
            if channel_freq is None:
                print("Warning: invalid ARFCN %d for band %s" % (channel, band))
                continue
            freq_diff = channel_freq - fc
            freq_diff_str = "+" if 0 <= freq_diff else ""
            freq_diff_str += eng_notation.num_to_str(freq_diff)
            print("ARFCN %d is at %sHz %sHz" % (channel, fc_str, freq_diff_str))

            self.blocks_resamplers[channel] = pfb.arb_resampler_ccf( resamp_rate, taps=None, flt_size=32)
            self.blocks_rotators[channel] = blocks.rotator_cc(-2*math.pi*(freq_diff)/samp_rate)
            self.connect( (self.source, 0), (self.blocks_rotators[channel], 0) )
            self.connect( (self.blocks_rotators[channel], 0), (self.blocks_resamplers[channel], 0) )

            self.blocks_file_sinks[channel] = blocks.file_sink(gr.sizeof_gr_complex, dest_dir+"/out_" + str(channel) + ".cfile", False)
            self.blocks_file_sinks[channel].set_unbuffered(False)
            self.connect((self.blocks_resamplers[channel], 0), (self.blocks_file_sinks[channel], 0))
Exemplo n.º 6
0
    def __init__(self, filename="0.dat", freq=90.1e6, samp_rate=1e6):
        gr.top_block.__init__(self, "Fm Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.filename = filename
        self.freq = freq
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.gain = gain = 30
        self.audio_rate = audio_rate = 48e3
        self.audio_interp = audio_interp = 4

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
                interpolation=int(audio_rate*audio_interp),
                decimation=int(samp_rate),
                taps=None,
                fractional_bw=None,
        )
        self.low_pass_filter_0 = filter.interp_fir_filter_fff(1, firdes.low_pass(
        	1, int(audio_rate), 800, 100, firdes.WIN_HAMMING, 6.76))
        self.blocks_wavfile_sink_0 = blocks.wavfile_sink("wav_out.wav", 1, int(audio_rate), 8)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(False, False)
        self.blocks_file_source_0_0 = blocks.file_source(gr.sizeof_short*1, filename, False)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
        	quad_rate=int(audio_rate*audio_interp),
        	audio_decimation=int(audio_interp),
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_wfm_rcv_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.blocks_file_source_0_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))    
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.rational_resampler_xxx_0, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.blocks_wavfile_sink_0, 0))    
        self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))    
Exemplo n.º 7
0
 def __init__(self, config):
     gr.top_block.__init__(self)
     ## Vars ##
     ## Interleaved Short input (sc16)
     if config["intype"] == SNAME_TO_ENUM["sc16"]:
         fsrc = blocks.file_source(gr.sizeof_short * 1, config["infile"], False)
         # SEEK_SET is offset from beginning, sample_offset is in samples
         # Factor of 2 because vector of length 2 (since interleaved)
         fsrc.seek(config["sample_offset"] * 2, os.SEEK_SET)
         # sc16->fc32
         if config["outtype"] == SNAME_TO_ENUM["fc32"]:
             ishort_to_cpxfloat = blocks.interleaved_short_to_complex(False, False)
             # Copies sample_len then exits
             head = blocks.head(gr.sizeof_gr_complex * 1, config["sample_len"])
             fsink = blocks.file_sink(gr.sizeof_gr_complex * 1, config["outfile"])
             self.connect(fsrc, ishort_to_cpxfloat, head, fsink)
         # sc16->sc16
         elif config["outtype"] == SNAME_TO_ENUM["sc16"]:
             head = blocks.head(gr.sizeof_short, config["sample_len"])
             fsink = blocks.file_sink(gr.sizeof_short, config["outfile"])
             self.connect(fsrc, head, fsink)
     ## Complex float input (fc32)
     elif config["intype"] == SNAME_TO_ENUM["fc32"]:
         fsrc = blocks.file_source(gr.sizeof_gr_complex * 1, config["infile"], False)
         # SEEK_SET is offset from beginning, sample_offset is in samples
         fsrc.seek(config["sample_offset"], os.SEEK_SET)
         # fc32->fc32
         if config["outtype"] == SNAME_TO_ENUM["fc32"]:
             head = blocks.head(gr.sizeof_gr_complex * 1, config["sample_len"])
             fsink = blocks.file_sink(gr.sizeof_gr_complex * 1, config["outfile"])
             self.connect(fsrc, head, fsink)
         # fc32->sc16
         elif config["outtype"] == SNAME_TO_ENUM["sc16"]:
             cpxfloat_to_ishort = blocks.complex_to_interleaved_short(False)
             head = blocks.head(gr.sizeof_gr_complex * 1, config["sample_len"])
             fsink = blocks.file_sink(gr.sizeof_short, config["outfile"])
             self.connect(fsrc, head, cpxfloat_to_ishort, fsink)
Exemplo n.º 8
0
    def __init__(self,
                 bins=8196,
                 display_integration=2,
                 freq=150e6,
                 gain=20,
                 samp_rate=25e6):
        grc_wxgui.top_block_gui.__init__(self, title="B210 2 Dual")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.bins = bins
        self.display_integration = display_integration
        self.freq = freq
        self.gain = gain
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.timenow = timenow = datetime.now().strftime("%Y%m%d_%H%M%S")
        self.prefix = prefix = "/home/ggancio/obs/gnur/"
        self.raw_b = raw_b = prefix + timenow + "_" + str(bins) + "_raw_b.dat"
        self.raw_a = raw_a = prefix + timenow + "_" + str(bins) + "_raw_a.dat"

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", '')),
            uhd.stream_args(
                cpu_format="sc16",
                otw_format='sc8',
                channels=range(2),
            ),
        )
        self.uhd_usrp_source_0.set_clock_source('external', 0)
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()),
                                            uhd.ALL_MBOARDS)
        self.uhd_usrp_source_0.set_center_freq(freq, 0)
        self.uhd_usrp_source_0.set_gain(gain, 0)
        self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0)
        self.uhd_usrp_source_0.set_center_freq(freq, 1)
        self.uhd_usrp_source_0.set_gain(gain, 1)
        self.fft_vxx_0_0 = fft.fft_vcc(bins, True,
                                       (window.blackmanharris(bins)), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(bins, True, (window.blackmanharris(bins)),
                                     True, 1)
        self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, bins)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, bins)
        self.blocks_nlog10_ff_0_0_0 = blocks.nlog10_ff(10, bins, 0)
        self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, bins, 0)
        self.blocks_multiply_conjugate_cc_0_0 = blocks.multiply_conjugate_cc(
            bins)
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(
            bins)
        self.blocks_interleaved_short_to_complex_0_0 = blocks.interleaved_short_to_complex(
            True, False)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            True, False)
        self.blocks_integrate_xx_0_0 = blocks.integrate_ff(
            int(display_integration * samp_rate / bins), bins)
        self.blocks_integrate_xx_0 = blocks.integrate_ff(
            int(display_integration * samp_rate / bins), bins)
        self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_float * bins,
                                                     raw_b, False)
        self.blocks_file_sink_0_0.set_unbuffered(True)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float * bins,
                                                   raw_a, False)
        self.blocks_file_sink_0.set_unbuffered(True)
        self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(
            bins)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(
            bins)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.blocks_integrate_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0_0, 0),
                     (self.blocks_integrate_xx_0_0, 0))
        self.connect((self.blocks_integrate_xx_0, 0),
                     (self.blocks_nlog10_ff_0_0, 0))
        self.connect((self.blocks_integrate_xx_0_0, 0),
                     (self.blocks_nlog10_ff_0_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0_0, 0),
                     (self.blocks_stream_to_vector_0_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0_0, 0),
                     (self.blocks_complex_to_mag_squared_0_0, 0))
        self.connect((self.blocks_nlog10_ff_0_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_nlog10_ff_0_0_0, 0),
                     (self.blocks_file_sink_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.fft_vxx_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.fft_vxx_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0_0, 0))
        self.connect((self.fft_vxx_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0_0, 1))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.uhd_usrp_source_0, 1),
                     (self.blocks_interleaved_short_to_complex_0_0, 0))
Exemplo n.º 9
0
    def __init__(self):
        gr.top_block.__init__(self, "Shipping Passing App")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Shipping Passing App")
        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", "audioTxRx")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
        self.msg_str = msg_str = "CSQ305438"

        self.QPSK = QPSK = digital.constellation_calcdist(
            ([1 + 1j, -1 + 1j, 1 - 1j, -1 - 1j]), ([0, 1, 3, 2]), 4, 1).base()

        ##################################################
        # Blocks
        ##################################################
        self._msg_str_tool_bar = Qt.QToolBar(self)
        self._msg_str_tool_bar.addWidget(Qt.QLabel("msg_str" + ": "))
        self._msg_str_line_edit = Qt.QLineEdit(str(self.msg_str))
        self._msg_str_tool_bar.addWidget(self._msg_str_line_edit)
        self._msg_str_line_edit.returnPressed.connect(lambda: self.set_msg_str(
            str(str(self._msg_str_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._msg_str_tool_bar)
        self.tutorial_my_qpsk_demod_cb_0 = tutorial.my_qpsk_demod_cb(True)
        self.tutorial_chat_sanitizer_0 = tutorial.chat_sanitizer('', '')
        self.gnuShipping_shippingReciever_0 = gnuShipping.shippingReciever(
            msg_str)
        self.digital_crc32_async_bb_1 = digital.crc32_async_bb(False)
        self.digital_crc32_async_bb_0 = digital.crc32_async_bb(True)
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(
            1, 0.25 * 0.175 * 0.175, 0.5, 0.175, 0.005)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(
            (QPSK.points()), 1)
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_char * 1,
                                                   samp_rate, True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate,
                                                 True)
        self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu(
            blocks.byte_t, 'pdu_length')
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char * 1, '', "")
        self.blocks_tag_debug_0.set_display(True)
        self.blocks_short_to_float_0 = blocks.short_to_float(1, 1)
        self.blocks_repack_bits_bb_1 = blocks.repack_bits_bb(
            2, 8, 'pdu_length', True, gr.GR_LSB_FIRST)
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(
            8, 2, 'pdu_length', False, gr.GR_LSB_FIRST)
        self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(
            blocks.byte_t, 'pdu_length')
        self.blocks_message_debug_0 = blocks.message_debug()
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_float_to_short_0 = blocks.float_to_short(1, 1)
        self.blocks_complex_to_interleaved_short_0 = blocks.complex_to_interleaved_short(
            False)
        self.audio_source_0 = audio.source(samp_rate, '', True)
        self.audio_sink_0 = audio.sink(samp_rate, '', True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'),
                         (self.digital_crc32_async_bb_0, 'in'))
        self.msg_connect((self.digital_crc32_async_bb_0, 'out'),
                         (self.gnuShipping_shippingReciever_0, 'in'))
        self.msg_connect((self.digital_crc32_async_bb_1, 'out'),
                         (self.blocks_message_debug_0, 'print_pdu'))
        self.msg_connect((self.digital_crc32_async_bb_1, 'out'),
                         (self.blocks_pdu_to_tagged_stream_0, 'pdus'))
        self.msg_connect((self.tutorial_chat_sanitizer_0, 'out'),
                         (self.digital_crc32_async_bb_1, 'in'))
        self.connect((self.audio_source_0, 0),
                     (self.blocks_float_to_short_0, 0))
        self.connect((self.blocks_complex_to_interleaved_short_0, 0),
                     (self.blocks_short_to_float_0, 0))
        self.connect((self.blocks_float_to_short_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_0, 0),
                     (self.blocks_tag_debug_0, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.blocks_repack_bits_bb_1, 0),
                     (self.blocks_tagged_stream_to_pdu_0, 0))
        self.connect((self.blocks_short_to_float_0, 0), (self.audio_sink_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.blocks_throttle_0_0, 0),
                     (self.blocks_repack_bits_bb_1, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.blocks_complex_to_interleaved_short_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.tutorial_my_qpsk_demod_cb_0, 0))
        self.connect((self.tutorial_my_qpsk_demod_cb_0, 0),
                     (self.blocks_throttle_0_0, 0))
Exemplo n.º 10
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage=("%prog: [options] output_filename.\nSpecial output_filename" + \
            "\"sdl\" will use video_sink_sdl as realtime output window. " + \
            "You then need to have gr-video-sdl installed.\n" +\
            "Make sure your input capture file containes interleaved " + \
            "shorts not complex floats")
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
                          help="set sample rate")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be " + \
                            "interleaved shorts \n Use usrp_rx_file.py or " + \
                            "usrp_rx_cfile.py --output-shorts.\n Special " + \
                            "name \"usrp\" results in realtime capturing " + \
                            "and processing using usrp.\n" + \
                            "You then probably need a decimation factor of 64 or higher.")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-N", "--nframes", type="eng_float", default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("", "--freq-min", type="eng_float", default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("", "--freq-max", type="eng_float", default=900.25e6,
                          help="Set a maximum frequency [default=%default]")
        (options, args) = parser.parse_args ()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n');
            sys.exit(1)

        filename = args[0]

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n');
            raise SystemExit, 1

        if not (filename=="sdl"):
          options.repeat=False

        input_rate = options.samp_rate
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        if not (options.in_filename=="usrp"):
          # file is data source, capture with usr_rx_csfile.py
          self.filesource = blocks.file_source(gr.sizeof_short,
                                               options.in_filename,
                                               options.repeat)
          self.istoc = blocks.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.src=self.istoc
        else:
          if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1

          # build the graph
          self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))

          # Set the subdevice spec
          if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

          # Set the antenna
          if(options.antenna):
            self.u.set_antenna(options.antenna, 0)

          self.u.set_samp_rate(input_rate)
          dev_rate = self.u.get_samp_rate()

          self.src=self.u

          if options.gain is None:
              # if no gain was specified, use the mid-point in dB
              g = self.u.get_gain_range()
              options.gain = float(g.start()+g.stop())/2.0
          self.u.set_gain(options.gain)

          r = self.u.set_center_freq(options.freq)
          if not r:
              sys.stderr.write('Failed to set frequency\n')
              raise SystemExit, 1


        self.agc = analog.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = blocks.complex_to_mag ()
        self.set_blacklevel = blocks.add_const_ff(options.brightness +255.0)
        self.invert_and_scale = blocks.multiply_const_ff(-options.contrast *128.0*255.0/(200.0))
        self.f2uc = blocks.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL
        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768
        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640
        width=int(input_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if filename=="sdl":
          #Here comes the tv screen, you have to build and install
          #gr-video-sdl for this (subproject of gnuradio)
          try:
            video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0,
                                           show_width,height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename
          print "(Use the spacebar to advance to next frames)"
          file_sink = blocks.file_sink(gr.sizeof_char, filename)
          self.dst =file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
            self.connect(self.src, self.head, self.agc)

        self.connect (self.agc, self.am_demod, self.invert_and_scale,
                      self.set_blacklevel, self.f2uc, self.dst)
Exemplo n.º 11
0
    def __init__(self, fifo='/tmp/rx_samples.bin', frequency=1e9, sample_rate=2000000):
        gr.top_block.__init__(self, "bladeRF FIFO RX")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("bladeRF FIFO RX")
        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", "bladeRF_fifo_rx")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.fifo = fifo
        self.frequency = frequency
        self.sample_rate = sample_rate

        ##################################################
        # Variables
        ##################################################
        self.sample_rate_range = sample_rate_range = sample_rate
        self.frequency_range = frequency_range = frequency

        ##################################################
        # Blocks
        ##################################################
        self._sample_rate_range_range = Range(160e3, 40e6, 1e6, sample_rate, 200)
        self._sample_rate_range_win = RangeWidget(self._sample_rate_range_range, self.set_sample_rate_range, 'Sample Rate', "counter", float)
        self.top_grid_layout.addWidget(self._sample_rate_range_win, 0, 0, 1, 1)
        self._frequency_range_range = Range(300e6, 3.8e9, 1e6, frequency, 200)
        self._frequency_range_win = RangeWidget(self._frequency_range_range, self.set_frequency_range, 'Frequency', "counter", float)
        self.top_grid_layout.addWidget(self._frequency_range_win, 0, 1, 1, 1)
        self.qtgui_sink_x_0 = qtgui.sink_c(
        	1024, #fftsize
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	frequency_range, #fc
        	sample_rate_range, #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_grid_layout.addWidget(self._qtgui_sink_x_0_win, 1, 0, 1, 8)

        self.qtgui_sink_x_0.enable_rf_freq(False)



        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, sample_rate,True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(((1.0 / 2048.0), ))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(True, False)
        self.blocks_file_source_0_0 = blocks.file_source(gr.sizeof_short*2, '/home/mg/prefix/src/mg/sigs/rf-929611400.sc16q11', False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_sink_x_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_const_vxx_0, 0))
Exemplo n.º 12
0
    def __init__(self):
        gr.top_block.__init__(self, "RSU Transmitter")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("RSU Transmitter")
        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", "rsu_transmitter")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.pulse_shaper_interpolation = pulse_shaper_interpolation = 32
        self.bit_per_second = bit_per_second = 500e3
        self.v_min = v_min = 1000
        self.v_max = v_max = 25000
        self.usrp_samples_per_second = usrp_samples_per_second = 400e6
        self.sample_rate = sample_rate = pulse_shaper_interpolation * bit_per_second
        self.phase = phase = 1
        self.output_file = output_file = 'output_samples.dat'
        self.input_file = input_file = 'binary_nrz_data.dat'
        self.gain = gain = 1.0
        self.frequency = frequency = 5.8e9

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0.set_samp_rate(sample_rate)
        self.uhd_usrp_sink_0.set_center_freq(frequency, 0)
        self.uhd_usrp_sink_0.set_gain(gain, 0)
        self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
        self.qtgui_time_sink_x_1 = qtgui.time_sink_c(
        	256, #size
        	sample_rate, #samp_rate
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_1.set_update_time(0.10)
        self.qtgui_time_sink_x_1.set_y_axis(0, 26000)

        self.qtgui_time_sink_x_1.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_1.enable_tags(-1, True)
        self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_1.enable_autoscale(True)
        self.qtgui_time_sink_x_1.enable_grid(False)
        self.qtgui_time_sink_x_1.enable_axis_labels(True)
        self.qtgui_time_sink_x_1.enable_control_panel(False)

        if not True:
          self.qtgui_time_sink_x_1.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):
            if len(labels[i]) == 0:
                if(i % 2 == 0):
                    self.qtgui_time_sink_x_1.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                else:
                    self.qtgui_time_sink_x_1.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                self.qtgui_time_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_1_win)
        self._output_file_tool_bar = Qt.QToolBar(self)
        self._output_file_tool_bar.addWidget(Qt.QLabel('Output file'+": "))
        self._output_file_line_edit = Qt.QLineEdit(str(self.output_file))
        self._output_file_tool_bar.addWidget(self._output_file_line_edit)
        self._output_file_line_edit.returnPressed.connect(
        	lambda: self.set_output_file(str(str(self._output_file_line_edit.text().toAscii()))))
        self.top_layout.addWidget(self._output_file_tool_bar)
        self._input_file_tool_bar = Qt.QToolBar(self)
        self._input_file_tool_bar.addWidget(Qt.QLabel('Input file'+": "))
        self._input_file_line_edit = Qt.QLineEdit(str(self.input_file))
        self._input_file_tool_bar.addWidget(self._input_file_line_edit)
        self._input_file_line_edit.returnPressed.connect(
        	lambda: self.set_input_file(str(str(self._input_file_line_edit.text().toAscii()))))
        self.top_layout.addWidget(self._input_file_tool_bar)
        self.dsrcmod_pulse_shaper_bs_0 = dsrcmod.pulse_shaper_bs(v_min, v_max, phase, pulse_shaper_interpolation)
        self.blocks_vector_source_b_0 = blocks.vector_source_b((1, 0,1, 1,1,0), True, 1, [])
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(False, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.qtgui_time_sink_x_1, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.blocks_vector_source_b_0, 0), (self.dsrcmod_pulse_shaper_bs_0, 0))
        self.connect((self.dsrcmod_pulse_shaper_bs_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
    def __init__(
        self,
        radioParam={
            "type": "ndr804-ptt",
            "host": "ndr308",
            "port": 8617,
            "obj": None
        },
        index=1,
        enable=True,
        idString="USER",
        rate=0,
        ddcFreq=0,
        tunerIndex=1,
        radioInterface=1,
        dipIndex=-1,
        localInterface="eth6",
        udpPort=11000,
        testFilename="",
        otherDdcArgs={},
    ):
        gr.hier_block2.__init__(
            self,
            "NDR804-PTT Narrowband IQ Source",
            gr.io_signature(0, 0, 0),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )
        self.message_port_register_hier_out("control")
        self.message_port_register_hier_in("control")

        ##################################################
        # Parameters
        ##################################################
        self.ddcFreq = ddcFreq
        self.dipIndex = dipIndex
        self.index = index
        self.localInterface = localInterface
        self.otherDdcArgs = otherDdcArgs
        self.radioInterface = radioInterface
        self.radioParam = radioParam
        self.rate = rate
        self.tunerIndex = tunerIndex
        self.udpPort = udpPort
        self.enable = enable
        self.idString = idString
        self.testFilename = testFilename

        ##################################################
        # Blocks
        ##################################################
        self.vitaIqSource = CyberRadio.vita_iq_source_2(
            3,
            1024 * 4 / 4,
            9 * 4,
            1 * 4,
            False,
            True,
            "0.0.0.0",
            udpPort,
            False,
            False,
            False,
        )
        self.vecToStream = blocks.vector_to_stream(gr.sizeof_gr_complex * 1,
                                                   1024 / 4)
        self.nullSink = blocks.null_sink(gr.sizeof_int * (9 + 1024 / 4 + 1))
        self.ddcControl = generic_ddc_control_block(
            radioParam,
            index,
            self.idString,
            enable,  # enable
            False,  # wideband
            rate,
            0,
            ddcFreq,
            tunerIndex,
            0,
            radioInterface,
            dipIndex,
            localInterface,
            udpPort,
            dict(otherDdcArgs),
            False)

        if self.testFilename != "":
            self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                     31250, True)
            self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
                False, False)
            self.blocks_file_source_0 = blocks.file_source(
                gr.sizeof_short * 1, self.testFilename, True)
            self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(
                (1.0 / 32767, ))

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.ddcControl, 'control'), (self, 'control'))
        self.msg_connect((self, 'control'), (self.ddcControl, 'control'))

        if self.testFilename != "":
            self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0))
            self.connect((self.blocks_throttle_0, 0),
                         (self.blocks_multiply_const_vxx_0, 0))
            self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                         (self.blocks_throttle_0, 0))
            self.connect((self.blocks_file_source_0, 0),
                         (self.blocks_interleaved_short_to_complex_0, 0))
        else:
            self.connect((self.vecToStream, 0), (self, 0))
            self.connect((self.vitaIqSource, 0), (self.nullSink, 0))
            self.connect((self.vitaIqSource, 1), (self.vecToStream, 0))
    def __init__(self, samp_rate=80e6):
        gr.top_block.__init__(
            self, "INMARSAT BGAN Service, C-Band Return, Transponder 2")
        Qt.QWidget.__init__(self)
        self.setWindowTitle(
            "INMARSAT BGAN Service, C-Band Return, Transponder 2")
        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", "inmarsat_cband_playback_3")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.xpndr_offset = xpndr_offset = [-23e6, -7.5e6, 8e6, 23e6]
        self.xpndr_id = xpndr_id = 1
        self.rf_freq = rf_freq = 3627.5e6
        self.offset = offset = 0
        self.rf_center = rf_center = (rf_freq + xpndr_offset[xpndr_id] +
                                      offset)
        self.hs_lo = hs_lo = 5150e6
        self.xpndr_lbl = xpndr_lbl = "{:s}, Center [MHz]: {:4.3f}, BW [MHz]: 1.0".format(
            str(xpndr_id + 1), rf_center / 1e6)
        self.if_freq = if_freq = hs_lo - rf_freq
        self.xpndr_lbll = xpndr_lbll = xpndr_lbl
        self.xpndr_4_offset = xpndr_4_offset = xpndr_offset[3]
        self.xpndr_3_offset = xpndr_3_offset = xpndr_offset[2]
        self.xpndr_2_offset = xpndr_2_offset = xpndr_offset[1]
        self.xpndr_1_offset = xpndr_1_offset = xpndr_offset[0]
        self.rf_freq_lbl = rf_freq_lbl = rf_freq
        self.resamp_rate = resamp_rate = 0.175
        self.if_freq_lbl = if_freq_lbl = if_freq
        self.fg_title = fg_title = "INMARSAT BGAN Service, C-Band Return, Transponder {:s}".format(
            str(xpndr_id + 1))

        ##################################################
        # Blocks
        ##################################################
        self.tab = Qt.QTabWidget()
        self.tab_widget_0 = Qt.QWidget()
        self.tab_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_0)
        self.tab_grid_layout_0 = Qt.QGridLayout()
        self.tab_layout_0.addLayout(self.tab_grid_layout_0)
        self.tab.addTab(self.tab_widget_0, 'Transponder 1')
        self.tab_widget_1 = Qt.QWidget()
        self.tab_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_1)
        self.tab_grid_layout_1 = Qt.QGridLayout()
        self.tab_layout_1.addLayout(self.tab_grid_layout_1)
        self.tab.addTab(self.tab_widget_1, 'Transponder 2')
        self.tab_widget_2 = Qt.QWidget()
        self.tab_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_2)
        self.tab_grid_layout_2 = Qt.QGridLayout()
        self.tab_layout_2.addLayout(self.tab_grid_layout_2)
        self.tab.addTab(self.tab_widget_2, 'Transponder 3')
        self.tab_widget_3 = Qt.QWidget()
        self.tab_layout_3 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_3)
        self.tab_grid_layout_3 = Qt.QGridLayout()
        self.tab_layout_3.addLayout(self.tab_grid_layout_3)
        self.tab.addTab(self.tab_widget_3, 'Transponder 4')
        self.top_grid_layout.addWidget(self.tab, 2, 0, 4, 2)
        for r in range(2, 6):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._offset_tool_bar = Qt.QToolBar(self)
        self._offset_tool_bar.addWidget(Qt.QLabel("offset" + ": "))
        self._offset_line_edit = Qt.QLineEdit(str(self.offset))
        self._offset_tool_bar.addWidget(self._offset_line_edit)
        self._offset_line_edit.returnPressed.connect(lambda: self.set_offset(
            eng_notation.str_to_num(
                str(self._offset_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._offset_tool_bar, 8, 2, 1, 2)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._xpndr_lbll_tool_bar = Qt.QToolBar(self)

        if None:
            self._xpndr_lbll_formatter = None
        else:
            self._xpndr_lbll_formatter = lambda x: str(x)

        self._xpndr_lbll_tool_bar.addWidget(Qt.QLabel('Transponder' + ": "))
        self._xpndr_lbll_label = Qt.QLabel(
            str(self._xpndr_lbll_formatter(self.xpndr_lbll)))
        self._xpndr_lbll_tool_bar.addWidget(self._xpndr_lbll_label)
        self.top_grid_layout.addWidget(self._xpndr_lbll_tool_bar, 9, 2, 1, 2)
        for r in range(9, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._rf_freq_lbl_tool_bar = Qt.QToolBar(self)

        if None:
            self._rf_freq_lbl_formatter = None
        else:
            self._rf_freq_lbl_formatter = lambda x: eng_notation.num_to_str(x)

        self._rf_freq_lbl_tool_bar.addWidget(Qt.QLabel('RF' + ": "))
        self._rf_freq_lbl_label = Qt.QLabel(
            str(self._rf_freq_lbl_formatter(self.rf_freq_lbl)))
        self._rf_freq_lbl_tool_bar.addWidget(self._rf_freq_lbl_label)
        self.top_grid_layout.addWidget(self._rf_freq_lbl_tool_bar, 8, 0, 1, 1)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate * resamp_rate * 0.071428571,  #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(False)

        if not False:
            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(-100, -20)

        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, 3,
                                       2, 3, 2)
        for r in range(3, 6):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            rf_freq + xpndr_offset[xpndr_id] + offset,  #fc
            samp_rate * resamp_rate * 0.071428571,  #bw
            "",  #name
            1  #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.0010)
        self.qtgui_freq_sink_x_0.set_y_axis(-100, -20)
        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(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(False)
        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, 2, 2, 1,
                                       2)
        for r in range(2, 3):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.pfb_arb_resampler_xxx_0_1 = pfb.arb_resampler_ccf(resamp_rate,
                                                               taps=None,
                                                               flt_size=32)
        self.pfb_arb_resampler_xxx_0_1.declare_sample_delay(0)

        self.pfb_arb_resampler_xxx_0_0_0_0 = pfb.arb_resampler_ccf(0.071428571,
                                                                   taps=None,
                                                                   flt_size=32)
        self.pfb_arb_resampler_xxx_0_0_0_0.declare_sample_delay(0)

        self.pfb_arb_resampler_xxx_0_0_0 = pfb.arb_resampler_ccf(resamp_rate,
                                                                 taps=None,
                                                                 flt_size=32)
        self.pfb_arb_resampler_xxx_0_0_0.declare_sample_delay(0)

        self.pfb_arb_resampler_xxx_0_0 = pfb.arb_resampler_ccf(resamp_rate,
                                                               taps=None,
                                                               flt_size=32)
        self.pfb_arb_resampler_xxx_0_0.declare_sample_delay(0)

        self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(resamp_rate,
                                                             taps=None,
                                                             flt_size=32)
        self.pfb_arb_resampler_xxx_0.declare_sample_delay(0)

        self._if_freq_lbl_tool_bar = Qt.QToolBar(self)

        if None:
            self._if_freq_lbl_formatter = None
        else:
            self._if_freq_lbl_formatter = lambda x: eng_notation.num_to_str(x)

        self._if_freq_lbl_tool_bar.addWidget(Qt.QLabel('IF' + ": "))
        self._if_freq_lbl_label = Qt.QLabel(
            str(self._if_freq_lbl_formatter(self.if_freq_lbl)))
        self._if_freq_lbl_tool_bar.addWidget(self._if_freq_lbl_label)
        self.top_grid_layout.addWidget(self._if_freq_lbl_tool_bar, 8, 1, 1, 1)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.fosphor_qt_sink_c_0_2 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0_2.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0_2.set_frequency_range(rf_freq, samp_rate)
        self._fosphor_qt_sink_c_0_2_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_0_2.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._fosphor_qt_sink_c_0_2_win, 0, 0,
                                       2, 4)
        for r in range(0, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.fosphor_qt_sink_c_0_1 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0_1.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0_1.set_frequency_range(
            rf_freq + xpndr_3_offset, samp_rate * resamp_rate)
        self._fosphor_qt_sink_c_0_1_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_0_1.pyqwidget(), Qt.QWidget)
        self.tab_grid_layout_2.addWidget(self._fosphor_qt_sink_c_0_1_win, 0, 0,
                                         4, 4)
        for r in range(0, 4):
            self.tab_grid_layout_2.setRowStretch(r, 1)
        for c in range(0, 4):
            self.tab_grid_layout_2.setColumnStretch(c, 1)
        self.fosphor_qt_sink_c_0_0_0 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0_0_0.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0_0_0.set_frequency_range(
            rf_freq + xpndr_4_offset, samp_rate * resamp_rate)
        self._fosphor_qt_sink_c_0_0_0_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_0_0_0.pyqwidget(), Qt.QWidget)
        self.tab_grid_layout_3.addWidget(self._fosphor_qt_sink_c_0_0_0_win, 0,
                                         0, 4, 4)
        for r in range(0, 4):
            self.tab_grid_layout_3.setRowStretch(r, 1)
        for c in range(0, 4):
            self.tab_grid_layout_3.setColumnStretch(c, 1)
        self.fosphor_qt_sink_c_0_0 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0_0.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0_0.set_frequency_range(
            rf_freq + xpndr_2_offset, samp_rate * resamp_rate)
        self._fosphor_qt_sink_c_0_0_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_0_0.pyqwidget(), Qt.QWidget)
        self.tab_grid_layout_1.addWidget(self._fosphor_qt_sink_c_0_0_win, 0, 0,
                                         4, 4)
        for r in range(0, 4):
            self.tab_grid_layout_1.setRowStretch(r, 1)
        for c in range(0, 4):
            self.tab_grid_layout_1.setColumnStretch(c, 1)
        self.fosphor_qt_sink_c_0 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0.set_frequency_range(rf_freq + xpndr_1_offset,
                                                     samp_rate * resamp_rate)
        self._fosphor_qt_sink_c_0_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_0.pyqwidget(), Qt.QWidget)
        self.tab_grid_layout_0.addWidget(self._fosphor_qt_sink_c_0_win, 0, 0,
                                         4, 4)
        for r in range(0, 4):
            self.tab_grid_layout_0.setRowStretch(r, 1)
        for c in range(0, 4):
            self.tab_grid_layout_0.setColumnStretch(c, 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_1 = 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_0 = blocks.multiply_const_vff((-1, ))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_file_source_1 = blocks.file_source(
            gr.sizeof_short * 1,
            '/data1/captures/inmarsat_c/4F3_F5BE35_20180903_043333.872099_UTC_80M.short',
            True)
        self.blocks_file_source_1.set_begin_tag(pmt.PMT_NIL)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
        self.analog_sig_source_x_0_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1 * xpndr_3_offset, 1, 0)
        self.analog_sig_source_x_0_0_1 = analog.sig_source_c(
            samp_rate * resamp_rate, analog.GR_COS_WAVE, -1 * (offset), 1, 0)
        self.analog_sig_source_x_0_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1 * xpndr_4_offset, 1, 0)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1 * xpndr_2_offset, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1 * xpndr_1_offset, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.analog_sig_source_x_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 1))
        self.connect((self.analog_sig_source_x_0_0_1, 0),
                     (self.blocks_multiply_xx_0_0_1, 1))
        self.connect((self.analog_sig_source_x_0_1, 0),
                     (self.blocks_multiply_xx_0_1, 1))
        self.connect((self.blocks_complex_to_float_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_complex_to_float_0, 1),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_file_source_1, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0_1, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.fosphor_qt_sink_c_0_2, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.pfb_arb_resampler_xxx_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.pfb_arb_resampler_xxx_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0, 0),
                     (self.pfb_arb_resampler_xxx_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_1, 0),
                     (self.pfb_arb_resampler_xxx_0_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_1, 0),
                     (self.pfb_arb_resampler_xxx_0_1, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_complex_to_float_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0, 0),
                     (self.fosphor_qt_sink_c_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_0, 0),
                     (self.blocks_multiply_xx_0_0_1, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_0, 0),
                     (self.fosphor_qt_sink_c_0_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_0_0, 0),
                     (self.fosphor_qt_sink_c_0_0_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_0_0_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_0_0_0, 0),
                     (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0_1, 0),
                     (self.fosphor_qt_sink_c_0_1, 0))
Exemplo n.º 15
0
    def __init__(self):
        gr.top_block.__init__(self, "Not titled yet")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Not titled yet")
        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", "fir_analysis")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 64000

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
            33, #size
            samp_rate, #samp_rate
            "", #name
            1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.0010)
        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(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)
        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)


        labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
        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]
        styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]


        for i in range(2):
            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_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(False, False)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short*1, '/Users/iracigt/Developer/DVB_hat/hdl/fir_out_s16.bin', True, 0, 66)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.qtgui_time_sink_x_0, 0))
Exemplo n.º 16
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        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", "top_block")

        if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
            self.restoreGeometry(self.settings.value("geometry").toByteArray())
        else:
            self.restoreGeometry(
                self.settings.value("geometry", type=QtCore.QByteArray))

        ##################################################
        # Variables
        ##################################################
        self.vec_length = vec_length = 400
        self.sinc_sample_locations = sinc_sample_locations = np.arange(
            -np.pi * 4 / 2.0, np.pi * 4 / 2.0, np.pi / vec_length)
        self.timenow = timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S")
        self.sinc = sinc = np.sinc(sinc_sample_locations / np.pi)
        self.prefix = prefix = "/home/dspradio/grc_data/"
        self.samp_rate = samp_rate = 10e6
        self.recfile = recfile = prefix + timenow + "rtl_drift.h5"
        self.integration_time = integration_time = .0002
        self.freq = freq = 1420.5e6
        self.display_integration = display_integration = 0.0002
        self.delay1 = delay1 = 0
        self.custom_window = custom_window = sinc * np.hamming(4 * vec_length)

        ##################################################
        # Blocks
        ##################################################
        self._delay1_range = Range(0, 100, 1, 0, 200)
        self._delay1_win = RangeWidget(self._delay1_range, self.set_delay1,
                                       "delay1", "counter_slider", int)
        self.top_layout.addWidget(self._delay1_win)
        self.qtgui_vector_sink_f_0_1 = qtgui.vector_sink_f(
            vec_length,
            0,
            1,
            "x-Axis",
            "y-Axis",
            "one",
            2  # Number of inputs
        )
        self.qtgui_vector_sink_f_0_1.set_update_time(.1)
        self.qtgui_vector_sink_f_0_1.set_y_axis(-140, 10)
        self.qtgui_vector_sink_f_0_1.enable_autoscale(True)
        self.qtgui_vector_sink_f_0_1.enable_grid(False)
        self.qtgui_vector_sink_f_0_1.set_x_axis_units("")
        self.qtgui_vector_sink_f_0_1.set_y_axis_units("")
        self.qtgui_vector_sink_f_0_1.set_ref_level(0)

        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_vector_sink_f_0_1.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_vector_sink_f_0_1.set_line_label(i, labels[i])
            self.qtgui_vector_sink_f_0_1.set_line_width(i, widths[i])
            self.qtgui_vector_sink_f_0_1.set_line_color(i, colors[i])
            self.qtgui_vector_sink_f_0_1.set_line_alpha(i, alphas[i])

        self._qtgui_vector_sink_f_0_1_win = sip.wrapinstance(
            self.qtgui_vector_sink_f_0_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_vector_sink_f_0_1_win)
        self.qtgui_time_sink_x_0_2 = qtgui.time_sink_f(
            750,  #size
            samp_rate / 10,  #samp_rate
            "",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0_2.set_update_time(0.10)
        self.qtgui_time_sink_x_0_2.set_y_axis(-1, 1)

        self.qtgui_time_sink_x_0_2.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_0_2.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_2.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                    qtgui.TRIG_SLOPE_POS, 0.0,
                                                    0, 0, "")
        self.qtgui_time_sink_x_0_2.enable_autoscale(True)
        self.qtgui_time_sink_x_0_2.enable_grid(False)
        self.qtgui_time_sink_x_0_2.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_2.enable_control_panel(False)
        self.qtgui_time_sink_x_0_2.enable_stem_plot(False)

        if not True:
            self.qtgui_time_sink_x_0_2.disable_legend()

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "red", "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_2.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_2.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_2.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_2.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_2.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_2.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_2.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_2_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_2.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_2_win)
        self.qtgui_time_sink_x_0_1 = qtgui.time_sink_f(
            750,  #size
            1e6,  #samp_rate
            "",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0_1.set_update_time(0.010)
        self.qtgui_time_sink_x_0_1.set_y_axis(-1, 1)

        self.qtgui_time_sink_x_0_1.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_0_1.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                    qtgui.TRIG_SLOPE_POS, 0.0,
                                                    0, 0, "")
        self.qtgui_time_sink_x_0_1.enable_autoscale(True)
        self.qtgui_time_sink_x_0_1.enable_grid(False)
        self.qtgui_time_sink_x_0_1.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_1.enable_control_panel(False)
        self.qtgui_time_sink_x_0_1.enable_stem_plot(False)

        if not True:
            self.qtgui_time_sink_x_0_1.disable_legend()

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "green", "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_1.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_1.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_1_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_1_win)
        self.fft_vxx_0_0 = fft.fft_vcc(400, True,
                                       (window.rectangular(vec_length)), True,
                                       1)
        self.fft_vxx_0 = fft.fft_vcc(400, True,
                                     (window.rectangular(vec_length)), True, 1)
        self.dedispersion_oot_dedisperse_roll_0_0 = dedispersion_oot.dedisperse_roll(
            400, ([600, 601, 602, 603, 604]), 1400.000, 10.000, 750, .15)
        self.dedispersion_oot_dedisperse_roll_0 = dedispersion_oot.dedisperse_roll(
            400, ([600, 601, 602, 603, 604]), 1400.000, 10.000, 750, .15)
        self.dedispersion_oot_Pulse_Detection_0 = dedispersion_oot.Pulse_Detection(
            25, 2.0, 750, ([600, 601, 602, 603, 604]))
        self.blocks_vector_to_stream_1_0_0 = blocks.vector_to_stream(
            gr.sizeof_float * 1, 750)
        self.blocks_vector_to_stream_0_1 = blocks.vector_to_stream(
            gr.sizeof_float * 1, 400)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(
            gr.sizeof_float * 1, 400)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, 1e6 / 2,
                                                 True)
        self.blocks_stream_to_vector_2_0 = blocks.stream_to_vector(
            gr.sizeof_float * 400, 750)
        self.blocks_stream_to_vector_2 = blocks.stream_to_vector(
            gr.sizeof_float * 400, 750)
        self.blocks_stream_to_vector_1_1 = blocks.stream_to_vector(
            gr.sizeof_float * 1, 400)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(
            gr.sizeof_float * 1, 400)
        self.blocks_stream_to_vector_0_3 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_2_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_1_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_0_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, vec_length)
        self.blocks_multiply_const_vxx_0_3 = blocks.multiply_const_vcc(
            (custom_window[0:vec_length]))
        self.blocks_multiply_const_vxx_0_2_0 = blocks.multiply_const_vcc(
            (custom_window[-vec_length:]))
        self.blocks_multiply_const_vxx_0_2 = blocks.multiply_const_vcc(
            (custom_window[-vec_length:]))
        self.blocks_multiply_const_vxx_0_1_0 = blocks.multiply_const_vcc(
            (custom_window[2 * vec_length:3 * vec_length]))
        self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vcc(
            (custom_window[2 * vec_length:3 * vec_length]))
        self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_vcc(
            (custom_window[vec_length:2 * vec_length]))
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc(
            (custom_window[vec_length:2 * vec_length]))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(
            (custom_window[0:vec_length]))
        self.blocks_multiply_conjugate_cc_0_0 = blocks.multiply_conjugate_cc(
            vec_length)
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(
            vec_length)
        self.blocks_interleaved_short_to_complex_0_0 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_integrate_xx_0_0_0 = blocks.integrate_cc(
            int(display_integration * samp_rate / vec_length), vec_length)
        self.blocks_integrate_xx_0_0 = blocks.integrate_cc(
            int(display_integration * samp_rate / vec_length), vec_length)
        self.blocks_file_source_0_1 = blocks.file_source(
            gr.sizeof_short * 1,
            '/home/andy/FRB_Pipeline_and_Contributions/gr-transient/jupyter/pulse_sim_10mhz_int16_5ms_period_60dm_1400MHz_center_150ms_long_noise.bin',
            True)
        self.blocks_file_source_0_0 = blocks.file_source(
            gr.sizeof_float * 1,
            '/home/andy/FRB_Pipeline_and_Contributions/gr-transient/jupyter/pulse_sim_10mhz_int16_5ms_period_60dm_1400MHz_center_150ms_long_corr.bin',
            True)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_short * 1,
            '/home/andy/FRB_Pipeline_and_Contributions/gr-transient/jupyter/pulse_sim_10mhz_int16_5ms_period_60dm_1400MHz_center_150ms_long.bin',
            True)
        self.blocks_delay_0_0_1 = blocks.delay(gr.sizeof_gr_complex * 1,
                                               vec_length)
        self.blocks_delay_0_0_0_1 = blocks.delay(gr.sizeof_gr_complex * 1,
                                                 2 * vec_length)
        self.blocks_delay_0_0_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                                   3 * vec_length)
        self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                                 3 * vec_length)
        self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                               2 * vec_length)
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                             vec_length)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, delay1)
        self.blocks_complex_to_real_0_0 = blocks.complex_to_real(vec_length)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(vec_length)
        self.blocks_add_xx_0_0 = blocks.add_vcc(vec_length)
        self.blocks_add_xx_0 = blocks.add_vcc(vec_length)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.blocks_add_xx_0_0, 0), (self.fft_vxx_0_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.blocks_vector_to_stream_0, 0))
        self.connect((self.blocks_complex_to_real_0_0, 0),
                     (self.blocks_vector_to_stream_0_1, 0))
        self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0_2, 0))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.blocks_stream_to_vector_0_0, 0))
        self.connect((self.blocks_delay_0_0_0, 0),
                     (self.blocks_stream_to_vector_0_2, 0))
        self.connect((self.blocks_delay_0_0_0_0, 0),
                     (self.blocks_stream_to_vector_0_1, 0))
        self.connect((self.blocks_delay_0_0_0_0_0, 0),
                     (self.blocks_stream_to_vector_0_1_0, 0))
        self.connect((self.blocks_delay_0_0_0_1, 0),
                     (self.blocks_stream_to_vector_0_2_0, 0))
        self.connect((self.blocks_delay_0_0_1, 0),
                     (self.blocks_stream_to_vector_0_0_0, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_file_source_0_0, 0),
                     (self.blocks_delay_0, 0))
        self.connect((self.blocks_file_source_0_1, 0),
                     (self.blocks_interleaved_short_to_complex_0_0, 0))
        self.connect((self.blocks_integrate_xx_0_0, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_integrate_xx_0_0_0, 0),
                     (self.blocks_complex_to_real_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_delay_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_delay_0_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_delay_0_0_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0_0, 0),
                     (self.blocks_delay_0_0_0_0_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0_0, 0),
                     (self.blocks_delay_0_0_0_1, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0_0, 0),
                     (self.blocks_delay_0_0_1, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0_0, 0),
                     (self.blocks_stream_to_vector_0_3, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.blocks_integrate_xx_0_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0_0, 0),
                     (self.blocks_integrate_xx_0_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_add_xx_0, 3))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.blocks_multiply_const_vxx_0_0_0, 0),
                     (self.blocks_add_xx_0_0, 2))
        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_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0_2, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_2_0, 0),
                     (self.blocks_add_xx_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_3, 0),
                     (self.blocks_add_xx_0_0, 3))
        self.connect((self.blocks_stream_to_vector_0, 0),
                     (self.blocks_multiply_const_vxx_0_2, 0))
        self.connect((self.blocks_stream_to_vector_0_0, 0),
                     (self.blocks_multiply_const_vxx_0_1, 0))
        self.connect((self.blocks_stream_to_vector_0_0_0, 0),
                     (self.blocks_multiply_const_vxx_0_1_0, 0))
        self.connect((self.blocks_stream_to_vector_0_1, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_stream_to_vector_0_1_0, 0),
                     (self.blocks_multiply_const_vxx_0_3, 0))
        self.connect((self.blocks_stream_to_vector_0_2, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_stream_to_vector_0_2_0, 0),
                     (self.blocks_multiply_const_vxx_0_0_0, 0))
        self.connect((self.blocks_stream_to_vector_0_3, 0),
                     (self.blocks_multiply_const_vxx_0_2_0, 0))
        self.connect((self.blocks_stream_to_vector_1, 0),
                     (self.blocks_stream_to_vector_2, 0))
        self.connect((self.blocks_stream_to_vector_1, 0),
                     (self.qtgui_vector_sink_f_0_1, 0))
        self.connect((self.blocks_stream_to_vector_1_1, 0),
                     (self.blocks_stream_to_vector_2_0, 0))
        self.connect((self.blocks_stream_to_vector_1_1, 0),
                     (self.qtgui_vector_sink_f_0_1, 1))
        self.connect((self.blocks_stream_to_vector_2, 0),
                     (self.dedispersion_oot_dedisperse_roll_0, 0))
        self.connect((self.blocks_stream_to_vector_2_0, 0),
                     (self.dedispersion_oot_dedisperse_roll_0_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_stream_to_vector_1, 0))
        self.connect((self.blocks_vector_to_stream_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_vector_to_stream_0_1, 0),
                     (self.blocks_stream_to_vector_1_1, 0))
        self.connect((self.blocks_vector_to_stream_1_0_0, 0),
                     (self.qtgui_time_sink_x_0_1, 0))
        self.connect((self.dedispersion_oot_Pulse_Detection_0, 0),
                     (self.blocks_vector_to_stream_1_0_0, 0))
        self.connect((self.dedispersion_oot_dedisperse_roll_0, 0),
                     (self.dedispersion_oot_Pulse_Detection_0, 0))
        self.connect((self.dedispersion_oot_dedisperse_roll_0_0, 0),
                     (self.dedispersion_oot_Pulse_Detection_0, 1))
        self.connect((self.fft_vxx_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.fft_vxx_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0_0, 0))
        self.connect((self.fft_vxx_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0_0, 1))
Exemplo n.º 17
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1920000
        self.freq = freq = 1440000
        self.audio_gain = audio_gain = 0.025

        ##################################################
        # Blocks
        ##################################################
        self._freq_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.freq,
        	callback=self.set_freq,
        	label="Frequency (Hz)",
        	converter=forms.int_converter(),
        )
        self.Add(self._freq_text_box)
        _audio_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._audio_gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_audio_gain_sizer,
        	value=self.audio_gain,
        	callback=self.set_audio_gain,
        	label="Audio gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._audio_gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_audio_gain_sizer,
        	value=self.audio_gain,
        	callback=self.set_audio_gain,
        	minimum=0,
        	maximum=.05,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_audio_gain_sizer)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=freq,
        	y_per_div=20,
        	y_divs=8,
        	ref_level=100,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=2048,
        	fft_rate=10,
        	average=True,
        	avg_alpha=1,
        	title="FFT Plot",
        	peak_hold=False,
        	win=window.blackmanharris,
        	size=(1200,400),
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.ss = sdrstick.sdrstick_source_s(gr.sizeof_short*1, "192.168.1.200", "192.168.1.26", 8001, 1 - int(samp_rate/1920000))
        self.ss.set_freq(freq)
            
        self.low_pass_filter_0 = filter.fir_filter_ccf(samp_rate/48000, firdes.low_pass(
        	1, samp_rate, 5000, 3000, firdes.WIN_BLACKMAN, 6.76))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((audio_gain, ))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(False, False)
        self.audio_sink_0 = audio.sink(48000, "", True)
        self.analog_am_demod_cf_0 = analog.am_demod_cf(
        	channel_rate=48000,
        	audio_decim=1,
        	audio_pass=5000,
        	audio_stop=5500,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.analog_am_demod_cf_0, 0))
        self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.ss, 0), (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
Exemplo n.º 18
0
    def __init__(self,
                 center_frequency,
                 sample_rate,
                 decimation,
                 filename,
                 sample_format=None,
                 threshold=7.0,
                 signal_width=40e3,
                 offline=False,
                 max_queue_len=500,
                 handle_multiple_frames_per_burst=False,
                 max_bursts=0,
                 verbose=False):
        gr.top_block.__init__(self, "Top Block")
        self._center_frequency = center_frequency
        self._burst_width = 40e3
        self._input_sample_rate = sample_rate
        self._verbose = verbose
        self._threshold = threshold
        self._filename = filename
        self._offline = offline
        self._max_queue_len = max_queue_len
        self._handle_multiple_frames_per_burst = handle_multiple_frames_per_burst

        self._fft_size = int(
            math.pow(2, 1 + int(math.log(self._input_sample_rate / 1000,
                                         2))))  # fft is approx 1ms long
        self._burst_pre_len = 2 * self._fft_size
        self._burst_post_len = 8 * self._fft_size

        if decimation > 1:
            self._use_pfb = True

            # We will set up a filter bank with an odd number of outputs and
            # and an over sampling ratio to still get the desired decimation.

            # The goal is to still catch signal which (due to doppler shift) end up
            # on the border of two channels.

            # For this to work the desired decimation must be even.
            if decimation % 2:
                raise RuntimeError(
                    "The desired decimation must be 1 or an even number")

            self._channels = decimation + 1
            self._pfb_over_sample_ratio = self._channels / (self._channels -
                                                            1.)
            pfb_output_sample_rate = int(
                round(
                    float(self._input_sample_rate) / self._channels *
                    self._pfb_over_sample_ratio))
            assert pfb_output_sample_rate == self._input_sample_rate / decimation

            # The over sampled region of the FIR filter contains half of the signal width and
            # the transition region of the FIR filter.
            # The bandwidth is simply increased by the signal width.
            # A signal which has its center frequency directly on the border of
            # two channels will reconstruct correclty on both channels.
            self._fir_bw = (self._input_sample_rate / self._channels +
                            self._burst_width) / 2

            # The remaining bandwidth inside the over samples region is used to
            # contain the transistion region of the filter.
            # It can be multiplied by two as it is allowed to continue into the
            # transition region of the neighboring channel.
            # TODO: Draw a nice graphic how this works.
            self._fir_tw = (pfb_output_sample_rate / 2 - self._fir_bw) * 2

            # If the over sampling ratio is not large enough, there is not
            # enough room to construct a transition region.
            if self._fir_tw < 0:
                raise RuntimeError(
                    "PFB over sampling ratio not enough to create a working FIR filter"
                )

            self._pfb_fir_filter = gnuradio.filter.firdes.low_pass_2(
                1, self._input_sample_rate, self._fir_bw, self._fir_tw, 60)

            # If the transition width approaches 0, the filter size goes up significantly.
            if len(self._pfb_fir_filter) > 200:
                print >> sys.stderr, "Warning: The PFB FIR filter has an abnormal large number of taps:", len(
                    self._pfb_fir_filter)
                print >> sys.stderr, "Consider reducing the decimation factor or increase the over sampling ratio"

            self._burst_sample_rate = pfb_output_sample_rate
            if self._verbose:
                print >> sys.stderr, "self._channels", self._channels
                print >> sys.stderr, "len(self._pfb_fir_filter)", len(
                    self._pfb_fir_filter)
                print >> sys.stderr, "self._pfb_over_sample_ratio", self._pfb_over_sample_ratio
                print >> sys.stderr, "self._fir_bw", self._fir_bw
                print >> sys.stderr, "self._fir_tw", self._fir_tw
                print >> sys.stderr, "self._burst_sample_rate", self._burst_sample_rate
        else:
            self._use_pfb = False
            self._burst_sample_rate = self._input_sample_rate

        # After 90 ms there needs to be a pause in the frame sturcture.
        # Let's make that the limit for a detected burst
        self._max_burst_len = int(self._burst_sample_rate * 0.09)

        if self._verbose:
            print >> sys.stderr, "require %.1f dB" % self._threshold
            print >> sys.stderr, "burst_width: %d Hz" % self._burst_width

        if self._filename.endswith(".conf"):
            import ConfigParser
            config = ConfigParser.ConfigParser()
            config.read(self._filename)
            items = config.items("osmosdr-source")
            d = {key: value for key, value in items}

            if 'device_args' in d:
                source = osmosdr.source(args=d['device_args'])
            else:
                source = osmosdr.source()

            source.set_sample_rate(self._input_sample_rate)
            source.set_center_freq(self._center_frequency, 0)

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain(gain, 0)
                print >> sys.stderr, "(RF) Gain:", source.get_gain(
                    0), '(Requested %d)' % gain

            for key, value in d.iteritems():
                if key.endswith("_gain"):
                    gain_option_name = key.split('_')[0]
                    gain_value = int(value)

                    def match_gain(gain, gain_names):
                        for gain_name in gain_names:
                            if gain.lower() == gain_name.lower():
                                return gain_name
                        return None

                    gain_name = match_gain(gain_option_name,
                                           source.get_gain_names())

                    if gain_name is not None:
                        source.set_gain(gain_value, gain_name, 0)
                        print >> sys.stderr, gain_name, "Gain:", source.get_gain(
                            gain_name, 0), '(Requested %d)' % gain_value
                    else:
                        print >> sys.stderr, "WARNING: Gain", gain_option_name, "not supported by source!"
                        print >> sys.stderr, "Supported gains:", source.get_gain_names(
                        )

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(bandwidth, 0)
                print >> sys.stderr, "Bandwidth:", source.get_bandwidth(
                    0), '(Requested %d)' % bandwidth
            else:
                source.set_bandwidth(0, 0)
                print >> sys.stderr, "Warning: Setting bandwidth to", source.get_bandwidth(
                    0)

            if 'antenna' in d:
                antenna = d['antenna']
                source.set_antenna(antenna, 0)
                print >> sys.stderr, "Antenna:", source.get_antenna(
                    0), '(Requested %s)' % antenna
            else:
                print >> sys.stderr, "Warning: Setting antenna to", source.get_antenna(
                    0)

            #source.set_freq_corr($corr0, 0)
            #source.set_dc_offset_mode($dc_offset_mode0, 0)
            #source.set_iq_balance_mode($iq_balance_mode0, 0)
            #source.set_gain_mode($gain_mode0, 0)
            #source.set_antenna($ant0, 0)

            converter = None
        else:
            if sample_format == "rtl":
                converter = iridium.iuchar_to_complex()
                itemsize = gr.sizeof_char
            elif sample_format == "hackrf":
                converter = blocks.interleaved_char_to_complex()
                itemsize = gr.sizeof_char
            elif sample_format == "sc16":
                converter = blocks.interleaved_short_to_complex()
                itemsize = gr.sizeof_short
            elif sample_format == "float":
                converter = None
                itemsize = gr.sizeof_gr_complex
            else:
                raise RuntimeError(
                    "Unknown sample format for offline mode given")
            source = blocks.file_source(itemsize=itemsize,
                                        filename=self._filename,
                                        repeat=False)

        # Just to keep the code below a bit more portable
        tb = self

        #fft_burst_tagger::make(float center_frequency, int fft_size, int sample_rate,
        #                    int burst_pre_len, int burst_post_len, int burst_width,
        #                    int max_bursts, float threshold, int history_size, bool debug)

        self._fft_burst_tagger = iridium.fft_burst_tagger(
            center_frequency=self._center_frequency,
            fft_size=self._fft_size,
            sample_rate=self._input_sample_rate,
            burst_pre_len=self._burst_pre_len,
            burst_post_len=self._burst_post_len,
            burst_width=int(self._burst_width),
            max_bursts=max_bursts,
            threshold=self._threshold,
            history_size=512,
            debug=self._verbose)

        # Initial filter to filter the detected bursts. Runs at burst_sample_rate. Used to decimate the signal.
        # TODO: Should probably be set to self._burst_width
        input_filter = gnuradio.filter.firdes.low_pass_2(
            1, self._burst_sample_rate, 40e3 / 2, 40e3, 40)
        #input_filter = gnuradio.filter.firdes.low_pass_2(1, self._burst_sample_rate, 42e3/2, 24e3, 40)
        #print len(input_filter)

        # Filter to find the start of the signal. Should be fairly narrow.
        # TODO: 250000 appears as magic number here
        start_finder_filter = gnuradio.filter.firdes.low_pass_2(
            1, 250000, 5e3 / 2, 10e3 / 2, 60)
        #print len(start_finder_filter)

        self._iridium_qpsk_demod = iridium.iridium_qpsk_demod_cpp()
        self._frame_sorter = iridium.frame_sorter()
        self._iridium_frame_printer = iridium.iridium_frame_printer()

        #self._iridium_qpsk_demod = iridium.iridium_qpsk_demod(250000)

        if self._use_pfb:
            self._burst_to_pdu_converters = []
            self._burst_downmixers = []
            sinks = []

            for channel in range(self._channels):
                center = channel if channel <= self._channels / 2 else (
                    channel - self._channels)

                # Second and third parameters tell the block where after the PFB it sits.
                relative_center = center / float(self._channels)
                relative_span = 1. / self._channels
                relative_sample_rate = relative_span * self._pfb_over_sample_ratio
                burst_to_pdu_converter = iridium.tagged_burst_to_pdu(
                    self._max_burst_len, relative_center, relative_span,
                    relative_sample_rate, self._max_queue_len,
                    not self._offline)
                burst_downmixer = iridium.burst_downmix(
                    self._burst_sample_rate, int(0.007 * 250000), 0,
                    (input_filter), (start_finder_filter),
                    self._handle_multiple_frames_per_burst)

                self._burst_downmixers.append(burst_downmixer)
                self._burst_to_pdu_converters.append(burst_to_pdu_converter)

            #pfb_debug_sinks = [blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename="/tmp/channel-%d.f32"%i) for i in range(self._channels)]
            pfb_debug_sinks = None

            pfb = gnuradio.filter.pfb.channelizer_ccf(
                numchans=self._channels,
                taps=self._pfb_fir_filter,
                oversample_rate=self._pfb_over_sample_ratio)

            if converter:
                tb.connect(source, converter, self._fft_burst_tagger, pfb)
            else:
                tb.connect(source, self._fft_burst_tagger, pfb)

            for i in range(self._channels):
                tb.connect((pfb, i), self._burst_to_pdu_converters[i])
                if pfb_debug_sinks:
                    tb.connect((pfb, i), pfb_debug_sinks[i])

                tb.msg_connect((self._burst_to_pdu_converters[i], 'cpdus'),
                               (self._burst_downmixers[i], 'cpdus'))
                tb.msg_connect(
                    (self._burst_downmixers[i], 'burst_handled'),
                    (self._burst_to_pdu_converters[i], 'burst_handled'))

                tb.msg_connect((self._burst_downmixers[i], 'cpdus'),
                               (self._iridium_qpsk_demod, 'cpdus'))
        else:
            burst_downmix = iridium.burst_downmix(
                self._burst_sample_rate, int(0.007 * 250000), 0,
                (input_filter), (start_finder_filter),
                self._handle_multiple_frames_per_burst)
            burst_to_pdu = iridium.tagged_burst_to_pdu(self._max_burst_len,
                                                       0.0, 1.0, 1.0,
                                                       self._max_queue_len,
                                                       not self._offline)

            if converter:
                #multi = blocks.multiply_const_cc(1/128.)
                #tb.connect(source, converter, multi, self._fft_burst_tagger, burst_to_pdu)
                tb.connect(source, converter, self._fft_burst_tagger,
                           burst_to_pdu)
            else:
                tb.connect(source, self._fft_burst_tagger, burst_to_pdu)

            tb.msg_connect((burst_to_pdu, 'cpdus'), (burst_downmix, 'cpdus'))
            tb.msg_connect((burst_downmix, 'burst_handled'),
                           (burst_to_pdu, 'burst_handled'))

            # Final connection to the demodulator. It prints the output to stdout
            tb.msg_connect((burst_downmix, 'cpdus'),
                           (self._iridium_qpsk_demod, 'cpdus'))

            self._burst_downmixers = [burst_downmix]
            self._burst_to_pdu_converters = [burst_to_pdu]

        tb.msg_connect((self._iridium_qpsk_demod, 'pdus'),
                       (self._frame_sorter, 'pdus'))
        tb.msg_connect((self._frame_sorter, 'pdus'),
                       (self._iridium_frame_printer, 'pdus'))
Exemplo n.º 19
0
    def __init__(self):
        gr.top_block.__init__(self, "2020-08-13T05:06:25.664651Z")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("2020-08-13T05:06:25.664651Z")
        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", "n210_record_ci16")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 12.5e6
        self.ts_str = ts_str = dt.strftime(dt.utcnow(),
                                           "%Y-%m-%dT%H:%M:%S.%fZ")
        self.signal_type = signal_type = "HF"
        self.samp_str = samp_str = "{:3.1f}MSPS".format(samp_rate / 1e6)
        self.path = path = "/tmp"
        self.fn = fn = "{:s}_{:s}_{:s}.ci16".format(signal_type, samp_str,
                                                    ts_str)
        self.rx_freq = rx_freq = samp_rate / 2
        self.fp = fp = "{:s}/{:s}".format(path, fn)

        ##################################################
        # Blocks
        ##################################################
        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, 8, 2, 1, 2)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._rx_freq_tool_bar = Qt.QToolBar(self)
        self._rx_freq_tool_bar.addWidget(Qt.QLabel('Frequency [Hz]' + ": "))
        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, 8, 0, 1, 2)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(('addr=192.168.10.2', "")),
            uhd.stream_args(
                cpu_format="sc16",
                otw_format='sc16',
                channels=range(1),
            ),
        )
        self.uhd_usrp_source_0.set_clock_source('gpsdo', 0)
        self.uhd_usrp_source_0.set_time_source('gpsdo', 0)
        self.uhd_usrp_source_0.set_subdev_spec('A:AB', 0)
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_time_unknown_pps(uhd.time_spec())
        self.uhd_usrp_source_0.set_center_freq(rx_freq, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.uhd_usrp_source_0.set_antenna('A', 0)
        self.uhd_usrp_source_0.set_auto_dc_offset(True, 0)
        self.uhd_usrp_source_0.set_auto_iq_balance(True, 0)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
            4096,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            rx_freq,  #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(True)
        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(-140, 10)

        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(
            4096,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            rx_freq,  #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, -40)
        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(1.0)
        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)
        self.blocks_multiply_const_xx_0 = blocks.multiply_const_cc(1.0 /
                                                                   65536.0)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            True, False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_short * 2, fp,
                                                   False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_multiply_const_xx_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0),
                     (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
Exemplo n.º 20
0
    def __init__(self,
                 center_frequency,
                 sample_rate,
                 decimation,
                 filename,
                 sample_format=None,
                 threshold=7.0,
                 burst_width=40e3,
                 offline=False,
                 max_queue_len=500,
                 handle_multiple_frames_per_burst=False,
                 raw_capture_filename=None,
                 debug_id=None,
                 max_bursts=0,
                 verbose=False,
                 file_info=None,
                 samples_per_symbol=10):
        gr.top_block.__init__(self, "Top Block")
        self.handle_sigint = False
        self._center_frequency = center_frequency
        self._burst_width = burst_width
        self._input_sample_rate = sample_rate
        self._verbose = verbose
        self._threshold = threshold
        self._filename = filename
        self._offline = offline
        self._max_queue_len = max_queue_len
        self._handle_multiple_frames_per_burst = handle_multiple_frames_per_burst

        # Sample rate of the bursts exiting the burst downmix block
        self._burst_sample_rate = 25000 * samples_per_symbol
        assert (self._input_sample_rate /
                decimation) % self._burst_sample_rate == 0

        self._fft_size = 2**round(math.log(self._input_sample_rate / 1000,
                                           2))  # FFT is approx. 1 ms long
        self._burst_pre_len = 2 * self._fft_size

        # Keep 16 ms of signal after the FFT loses track
        self._burst_post_len = int(self._input_sample_rate * 16e-3)

        # Just to keep the code below a bit more portable
        tb = self

        if decimation > 1:
            self._use_pfb = True

            # We will set up a filter bank with an odd number of outputs and
            # and an over sampling ratio to still get the desired decimation.

            # The goal is to reconstruct signals which (due to Doppler shift) end up
            # on the border of two channels.

            # For this to work the desired decimation must be even.
            if decimation % 2:
                raise RuntimeError(
                    "The desired decimation must be 1 or an even number")

            self._channels = decimation + 1
            self._pfb_over_sample_ratio = self._channels / (self._channels -
                                                            1.)
            pfb_output_sample_rate = int(
                round(
                    float(self._input_sample_rate) / self._channels *
                    self._pfb_over_sample_ratio))
            assert pfb_output_sample_rate == self._input_sample_rate / decimation
            assert pfb_output_sample_rate % self._burst_sample_rate == 0

            # The over sampled region of the FIR filter contains half of the signal width and
            # the transition region of the FIR filter.
            # The bandwidth is simply increased by the signal width.
            # A signal which has its center frequency directly on the border of
            # two channels will reconstruct correctly on both channels.
            self._fir_bw = (self._input_sample_rate / self._channels +
                            self._burst_width) / 2

            # The remaining bandwidth inside the over sampled region is used to
            # contain the transition region of the filter.
            # It can be multiplied by two as it is allowed to continue into the
            # transition region of the neighboring channel.
            # Some details can be found here: https://youtu.be/6ngYp8W-AX0?t=2289
            self._fir_tw = (pfb_output_sample_rate / 2 - self._fir_bw) * 2

            # Real world data shows only a minor degradation in performance when
            # doubling the transition width.
            self._fir_tw *= 2

            # If the over sampling ratio is not large enough, there is not
            # enough room to construct a transition region.
            if self._fir_tw < 0:
                raise RuntimeError(
                    "PFB over sampling ratio not enough to create a working FIR filter"
                )

            self._pfb_fir_filter = gnuradio.filter.firdes.low_pass_2(
                1, self._input_sample_rate, self._fir_bw, self._fir_tw, 60)

            # If the transition width approaches 0, the filter size goes up significantly.
            if len(self._pfb_fir_filter) > 300:
                print(
                    "Warning: The PFB FIR filter has an abnormal large number of taps:",
                    len(self._pfb_fir_filter),
                    file=sys.stderr)
                print("Consider reducing the decimation factor",
                      file=sys.stderr)

            pfb_input_delay = (
                len(self._pfb_fir_filter) +
                1) // 2 - self._channels / self._pfb_over_sample_ratio
            self._pfb_delay = pfb_input_delay / decimation
            self._channel_sample_rate = pfb_output_sample_rate
            if self._verbose:
                print("self._channels", self._channels, file=sys.stderr)
                print("len(self._pfb_fir_filter)",
                      len(self._pfb_fir_filter),
                      file=sys.stderr)
                print("self._pfb_over_sample_ratio",
                      self._pfb_over_sample_ratio,
                      file=sys.stderr)
                print("self._fir_bw", self._fir_bw, file=sys.stderr)
                print("self._fir_tw", self._fir_tw, file=sys.stderr)
                print("self._channel_sample_rate",
                      self._channel_sample_rate,
                      file=sys.stderr)
        else:
            self._use_pfb = False
            self._channel_sample_rate = self._input_sample_rate
            self._channels = 1

        # After 90 ms there needs to be a pause in the frame sturcture.
        # Let's make that the limit for a detected burst
        self._max_burst_len = int(self._channel_sample_rate * 0.09)

        if self._verbose:
            print("require %.1f dB" % self._threshold, file=sys.stderr)
            print("burst_width: %d Hz" % self._burst_width, file=sys.stderr)

        if self._filename.endswith(".conf"):
            import configparser
            config = configparser.ConfigParser()
            config.read(self._filename)
            items = config.items("osmosdr-source")
            d = {key: value for key, value in items}

            import osmosdr
            if 'device_args' in d:
                source = osmosdr.source(args=d['device_args'])
            else:
                source = osmosdr.source()

            source.set_time_now(osmosdr.time_spec_t.get_system_time())

            source.set_sample_rate(self._input_sample_rate)
            source.set_center_freq(self._center_frequency, 0)

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain(gain, 0)
                print("(RF) Gain:",
                      source.get_gain(0),
                      '(Requested %d)' % gain,
                      file=sys.stderr)

            for key, value in d.items():
                if key.endswith("_gain"):
                    gain_option_name = key.split('_')[0]
                    gain_value = int(value)

                    def match_gain(gain, gain_names):
                        for gain_name in gain_names:
                            if gain.lower() == gain_name.lower():
                                return gain_name
                        return None

                    gain_name = match_gain(gain_option_name,
                                           source.get_gain_names())

                    if gain_name is not None:
                        source.set_gain(gain_value, gain_name, 0)
                        print(gain_name,
                              "Gain:",
                              source.get_gain(gain_name, 0),
                              '(Requested %d)' % gain_value,
                              file=sys.stderr)
                    else:
                        print("WARNING: Gain",
                              gain_option_name,
                              "not supported by source!",
                              file=sys.stderr)
                        print("Supported gains:",
                              source.get_gain_names(),
                              file=sys.stderr)

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(bandwidth, 0)
                print("Bandwidth:",
                      source.get_bandwidth(0),
                      '(Requested %d)' % bandwidth,
                      file=sys.stderr)
            else:
                source.set_bandwidth(0, 0)
                print("Warning: Setting bandwidth to",
                      source.get_bandwidth(0),
                      file=sys.stderr)

            if 'antenna' in d:
                antenna = d['antenna']
                source.set_antenna(antenna, 0)
                print("Antenna:",
                      source.get_antenna(0),
                      '(Requested %s)' % antenna,
                      file=sys.stderr)
            else:
                print("Warning: Setting antenna to",
                      source.get_antenna(0),
                      file=sys.stderr)

            #source.set_freq_corr($corr0, 0)
            #source.set_dc_offset_mode($dc_offset_mode0, 0)
            #source.set_iq_balance_mode($iq_balance_mode0, 0)
            #source.set_gain_mode($gain_mode0, 0)
            #source.set_antenna($ant0, 0)

        else:
            if sample_format == "rtl":
                converter = iridium.iuchar_to_complex()
                itemsize = gr.sizeof_char
                scale = 1
            elif sample_format == "hackrf":
                converter = blocks.interleaved_char_to_complex()
                itemsize = gr.sizeof_char
                scale = 1 / 128.
            elif sample_format == "sc16":
                converter = blocks.interleaved_short_to_complex()
                itemsize = gr.sizeof_short
                scale = 1 / 32768.
            elif sample_format == "float":
                converter = None
                itemsize = gr.sizeof_gr_complex
            else:
                raise RuntimeError(
                    "Unknown sample format for offline mode given")

            if self._filename == '/dev/stdin':
                file_source = blocks.file_descriptor_source(itemsize=itemsize,
                                                            fd=0,
                                                            repeat=False)
            else:
                file_source = blocks.file_source(itemsize=itemsize,
                                                 filename=self._filename,
                                                 repeat=False)

            if converter:
                multi = blocks.multiply_const_cc(scale)
                tb.connect(file_source, converter, multi)
                source = multi
            else:
                source = file_source

        self._fft_burst_tagger = iridium.fft_burst_tagger(
            center_frequency=self._center_frequency,
            fft_size=self._fft_size,
            sample_rate=self._input_sample_rate,
            burst_pre_len=self._burst_pre_len,
            burst_post_len=self._burst_post_len,
            burst_width=int(self._burst_width),
            max_bursts=max_bursts,
            threshold=self._threshold,
            history_size=512,
            offline=self._offline,
            debug=self._verbose)

        # Initial filter to filter the detected bursts. Runs at burst_sample_rate. Used to decimate the signal.
        input_filter = gnuradio.filter.firdes.low_pass_2(
            1, self._channel_sample_rate, self._burst_width / 2,
            self._burst_width, 40)
        #input_filter = gnuradio.filter.firdes.low_pass_2(1, self._channel_sample_rate, 42e3/2, 24e3, 40)
        #print len(input_filter)

        # Filter to find the start of the signal. Should be fairly narrow.
        start_finder_filter = gnuradio.filter.firdes.low_pass_2(
            1, self._burst_sample_rate, 5e3 / 2, 10e3 / 2, 60)
        #print len(start_finder_filter)

        self._iridium_qpsk_demod = iridium.iridium_qpsk_demod_cpp(
            self._channels)
        self._frame_sorter = iridium.frame_sorter()
        self._iridium_frame_printer = iridium.iridium_frame_printer(file_info)

        if raw_capture_filename:
            multi = blocks.multiply_const_cc(32768)
            converter = blocks.complex_to_interleaved_short()
            raw_sink = blocks.file_sink(itemsize=gr.sizeof_short,
                                        filename=raw_capture_filename)
            tb.connect(source, multi, converter, raw_sink)

            # Enable the following if not fast enough
            #self._burst_to_pdu_converters = []
            #self._burst_downmixers = []
            #return

        tb.connect(source, self._fft_burst_tagger)

        if self._use_pfb:
            self._burst_to_pdu_converters = []
            self._burst_downmixers = []
            sinks = []

            for channel in range(self._channels):
                center = channel if channel <= self._channels / 2 else (
                    channel - self._channels)

                # Second and third parameters tell the block where after the PFB it sits.
                relative_center = center / float(self._channels)
                relative_span = 1. / self._channels
                relative_sample_rate = relative_span * self._pfb_over_sample_ratio
                burst_to_pdu_converter = iridium.tagged_burst_to_pdu(
                    self._max_burst_len, relative_center, relative_span,
                    relative_sample_rate, -self._pfb_delay,
                    self._max_queue_len, not self._offline)
                burst_downmixer = iridium.burst_downmix(
                    self._burst_sample_rate,
                    int(0.007 * self._burst_sample_rate), 0, (input_filter),
                    (start_finder_filter),
                    self._handle_multiple_frames_per_burst)

                if debug_id is not None: burst_downmixer.debug_id(debug_id)

                self._burst_downmixers.append(burst_downmixer)
                self._burst_to_pdu_converters.append(burst_to_pdu_converter)

            #pfb_debug_sinks = [blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename="/tmp/channel-%d.f32"%i) for i in range(self._channels)]
            pfb_debug_sinks = None

            pfb = gnuradio.filter.pfb.channelizer_ccf(
                numchans=self._channels,
                taps=self._pfb_fir_filter,
                oversample_rate=self._pfb_over_sample_ratio)

            tb.connect(self._fft_burst_tagger, pfb)

            for i in range(self._channels):
                tb.connect((pfb, i), self._burst_to_pdu_converters[i])
                if pfb_debug_sinks:
                    tb.connect((pfb, i), pfb_debug_sinks[i])

                tb.msg_connect((self._burst_to_pdu_converters[i], 'cpdus'),
                               (self._burst_downmixers[i], 'cpdus'))
                tb.msg_connect(
                    (self._burst_downmixers[i], 'burst_handled'),
                    (self._burst_to_pdu_converters[i], 'burst_handled'))

                tb.msg_connect((self._burst_downmixers[i], 'cpdus'),
                               (self._iridium_qpsk_demod, 'cpdus%d' % i))
        else:
            burst_downmix = iridium.burst_downmix(
                self._burst_sample_rate, int(0.007 * self._burst_sample_rate),
                0, (input_filter), (start_finder_filter),
                self._handle_multiple_frames_per_burst)
            if debug_id is not None: burst_downmix.debug_id(debug_id)

            burst_to_pdu = iridium.tagged_burst_to_pdu(self._max_burst_len,
                                                       0.0, 1.0, 1.0, 0,
                                                       self._max_queue_len,
                                                       not self._offline)

            tb.connect(self._fft_burst_tagger, burst_to_pdu)

            tb.msg_connect((burst_to_pdu, 'cpdus'), (burst_downmix, 'cpdus'))
            tb.msg_connect((burst_downmix, 'burst_handled'),
                           (burst_to_pdu, 'burst_handled'))

            # Final connection to the demodulator. It prints the output to stdout
            tb.msg_connect((burst_downmix, 'cpdus'),
                           (self._iridium_qpsk_demod, 'cpdus'))

            self._burst_downmixers = [burst_downmix]
            self._burst_to_pdu_converters = [burst_to_pdu]

        tb.msg_connect((self._iridium_qpsk_demod, 'pdus'),
                       (self._frame_sorter, 'pdus'))
        tb.msg_connect((self._frame_sorter, 'pdus'),
                       (self._iridium_frame_printer, 'pdus'))
    def __init__(self, center_frequency, sample_rate, decimation, filename, sample_format=None, threshold=7.0,
                 burst_width=40e3, offline=False, max_queue_len=500, handle_multiple_frames_per_burst=False,
                 raw_capture_filename=None, debug_id=None, max_bursts=0, verbose=False, file_info="",
                 samples_per_symbol=10, config={}):
        gr.top_block.__init__(self, "Top Block")
        self.handle_sigint = False
        self._center_frequency = center_frequency
        self._burst_width = burst_width
        self._input_sample_rate = sample_rate
        self._verbose = verbose
        self._threshold = threshold
        self._filename = filename
        self._offline = offline
        self._max_queue_len = max_queue_len
        self._handle_multiple_frames_per_burst = handle_multiple_frames_per_burst
        self._decimation = decimation

        # Sample rate of the bursts exiting the burst downmix block
        self._burst_sample_rate = 25000 * samples_per_symbol
        if (self._input_sample_rate / self._decimation) % self._burst_sample_rate != 0:
            raise RuntimeError("Selected sample rate and decimation can not be matched. Please try a different combination. Sample rate divided by decimation must be a multiple of %d." % self._burst_sample_rate)

        self._fft_size = 2**round(math.log(self._input_sample_rate / 1000, 2))  # FFT is approx. 1 ms long
        self._burst_pre_len = 2 * self._fft_size

        # Keep 16 ms of signal after the FFT loses track
        self._burst_post_len = int(self._input_sample_rate * 16e-3)

        # Just to keep the code below a bit more portable
        tb = self

        if self._decimation > 1:
            self._use_channelizer = True

            # We will set up a filter bank with an odd number of outputs and
            # and an over sampling ratio to still get the desired decimation.

            # The goal is to reconstruct signals which (due to Doppler shift) end up
            # on the border of two channels.

            # For this to work the desired decimation must be even.
            if self._decimation % 2:
                raise RuntimeError("The desired decimation must be 1 or an even number.")

            self._channels = self._decimation + 1

            if self._decimation >= 8:
                self._use_fft_channelizer = True

                if 2**int(math.log(self._decimation, 2)) != self._decimation:
                    raise RuntimeError("Decimations >= 8 must be a power of two.")
                self._channel_sample_rate = self._input_sample_rate // self._decimation

                # On low end ARM machines we only create a single burst downmixer to not
                # overload the CPU. Rather drop bursts than samples.
                if platform.machine() == 'aarch64' and multiprocessing.cpu_count() == 4:
                    self._n_burst_downmixers = 1
                else:
                    self._n_burst_downmixers = 2
            else:
                self._use_fft_channelizer = False

                self._n_burst_downmixers = self._channels
                self._channelizer_over_sample_ratio = self._channels / (self._channels - 1.)
                channelizer_output_sample_rate = int(round(float(self._input_sample_rate) / self._channels * self._channelizer_over_sample_ratio))
                self._channel_sample_rate = channelizer_output_sample_rate
                assert channelizer_output_sample_rate == self._input_sample_rate / self._decimation
                assert channelizer_output_sample_rate % self._burst_sample_rate == 0

                # The over sampled region of the FIR filter contains half of the signal width and
                # the transition region of the FIR filter.
                # The bandwidth is simply increased by the signal width.
                # A signal which has its center frequency directly on the border of
                # two channels will reconstruct correctly on both channels.
                self._fir_bw = (self._input_sample_rate / self._channels + self._burst_width) / 2

                # The remaining bandwidth inside the over sampled region is used to
                # contain the transition region of the filter.
                # It can be multiplied by two as it is allowed to continue into the
                # transition region of the neighboring channel.
                # Some details can be found here: https://youtu.be/6ngYp8W-AX0?t=2289
                self._fir_tw = (channelizer_output_sample_rate / 2 - self._fir_bw) * 2

                # Real world data shows only a minor degradation in performance when
                # doubling the transition width.
                self._fir_tw *= 2

                # If the over sampling ratio is not large enough, there is not
                # enough room to construct a transition region.
                if self._fir_tw < 0:
                    raise RuntimeError("PFB over sampling ratio not enough to create a working FIR filter. Please try a different decimation.")

                self._pfb_fir_filter = gnuradio.filter.firdes.low_pass_2(1, self._input_sample_rate, self._fir_bw, self._fir_tw, 60)

                # If the transition width approaches 0, the filter size goes up significantly.
                if len(self._pfb_fir_filter) > 300:
                    print("Warning: The PFB FIR filter has an abnormal large number of taps:", len(self._pfb_fir_filter), file=sys.stderr)
                    print("Consider reducing the decimation factor or use a decimation >= 8.", file=sys.stderr)

                pfb_input_delay = (len(self._pfb_fir_filter) + 1) // 2 - self._channels / self._channelizer_over_sample_ratio
                self._channelizer_delay = pfb_input_delay / self._decimation

                if self._verbose:
                    print("self._channels", self._channels, file=sys.stderr)
                    print("len(self._pfb_fir_filter)", len(self._pfb_fir_filter), file=sys.stderr)
                    print("self._channelizer_over_sample_ratio", self._channelizer_over_sample_ratio, file=sys.stderr)
                    print("self._fir_bw", self._fir_bw, file=sys.stderr)
                    print("self._fir_tw", self._fir_tw, file=sys.stderr)
                    print("self._channel_sample_rate", self._channel_sample_rate, file=sys.stderr)
        else:
            self._use_channelizer = False
            self._channel_sample_rate = self._input_sample_rate
            self._channels = 1

        # After 90 ms there needs to be a pause in the frame sturcture.
        # Let's make that the limit for a detected burst
        self._max_burst_len = int(self._channel_sample_rate * 0.09)

        if self._verbose:
            print("require %.1f dB" % self._threshold, file=sys.stderr)
            print("burst_width: %d Hz" % self._burst_width, file=sys.stderr)
            print("source:", config['source'], file=sys.stderr)

        if config['source'] == 'osmosdr':
            d = config["osmosdr-source"]

            # work around https://github.com/gnuradio/gnuradio/issues/5121
            sys.path.append('/usr/local/lib/python3/dist-packages')
            import osmosdr
            if 'device_args' in d:
                source = osmosdr.source(args=d['device_args'])
            else:
                source = osmosdr.source()

            source.set_sample_rate(self._input_sample_rate)
            source.set_center_freq(self._center_frequency, 0)

            # Set a rough time estimate for potential rx_time tags from USRP devices
            # This prevents the output from having bogous time stamps if no GPSDO is available
            source.set_time_now(osmosdr.time_spec_t(time.time()))

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain(gain, 0)
                print("(RF) Gain:", source.get_gain(0), '(Requested %d)' % gain, file=sys.stderr)

            for key, value in d.items():
                if key.endswith("_gain"):
                    gain_option_name = key.split('_')[0]
                    gain_value = int(value)

                    def match_gain(gain, gain_names):
                        for gain_name in gain_names:
                            if gain.lower() == gain_name.lower():
                                return gain_name
                        return None

                    gain_name = match_gain(gain_option_name, source.get_gain_names())

                    if gain_name is not None:
                        source.set_gain(gain_value, gain_name, 0)
                        print(gain_name, "Gain:", source.get_gain(gain_name, 0), '(Requested %d)' % gain_value, file=sys.stderr)
                    else:
                        print("WARNING: Gain", gain_option_name, "not supported by source!", file=sys.stderr)
                        print("Supported gains:", source.get_gain_names(), file=sys.stderr)

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(bandwidth, 0)
                print("Bandwidth:", source.get_bandwidth(0), '(Requested %d)' % bandwidth, file=sys.stderr)
            else:
                source.set_bandwidth(0, 0)
                print("Warning: Setting bandwidth to", source.get_bandwidth(0), file=sys.stderr)

            if 'antenna' in d:
                antenna = d['antenna']
                source.set_antenna(antenna, 0)
                print("Antenna:", source.get_antenna(0), '(Requested %s)' % antenna, file=sys.stderr)
            else:
                print("Warning: Setting antenna to", source.get_antenna(0), file=sys.stderr)

            if 'clock_source' in d:
                print("Setting clock source to:", d['clock_source'], file=sys.stderr)
                source.set_clock_source(d['clock_source'], 0)

            if 'time_source' in d:
                print("Setting time source to:", d['time_source'], file=sys.stderr)
                source.set_time_source(d['time_source'], 0)
                while (time.time() % 1) < 0.4 or (time.time() % 1) > 0.6:
                    pass
                t = time.time()
                source.set_time_next_pps(osmosdr.time_spec_t(int(t) + 1))
                time.sleep(1)

            #source.set_freq_corr($corr0, 0)
            #source.set_dc_offset_mode($dc_offset_mode0, 0)
            #source.set_iq_balance_mode($iq_balance_mode0, 0)
            #source.set_gain_mode($gain_mode0, 0)

        elif config['source'] == 'soapy':
            d = config["soapy-source"]

            try:
                from gnuradio import soapy
            except ImportError:
                raise ImportError("gr-soapy not found. Make sure you are running GNURadio >= 3.9.2.0")

            if 'driver' not in d:
                print("No driver specified for soapy", file=sys.stderr)
                print("Run 'SoapySDRUtil -i' to see available drivers(factories)", file=sys.stderr)
                exit(1)
            dev = 'driver=' + d['driver']

            # Strip quotes
            def sanitize(s):
                if s.startswith('"') and s.endswith('"'):
                    return s.strip('""')
                if s.startswith("'") and s.endswith("'"):
                    return s.strip("''")
                return s

            # Remove all outer quotes from the args if they are present in the config
            if 'device_args' in d:
                dev_args = sanitize(d['device_args'])
            elif 'dev_args' in d:
                dev_args = sanitize(d['dev_args'])
            else:
                dev_args = ''

            stream_args = sanitize(d['stream_args']) if 'stream_args' in d else ''
            tune_args = sanitize(d['tune_args']) if 'tune_args' in d else ''
            other_settings = sanitize(d['other_settings']) if 'other_settings' in d else ''

            # We only support a single channel. Apply tune_args and other_settings to that channel.
            source = soapy.source(dev, "fc32", 1, dev_args, stream_args, [tune_args], [other_settings])

            source.set_sample_rate(0, self._input_sample_rate)
            source.set_frequency(0, self._center_frequency)

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain_mode(0, False)  # AGC: OFF
                source.set_gain(0, gain)
                print("Gain:", source.get_gain(0), '(Requested %d)' % gain, file=sys.stderr)

            for key, value in d.items():
                if key.endswith("_gain"):
                    gain_option_name = key.split('_')[0]
                    gain_value = int(value)

                    def match_gain(gain, gain_names):
                        for gain_name in gain_names:
                            if gain.lower() == gain_name.lower():
                                return gain_name
                        return None

                    gain_name = match_gain(gain_option_name, source.list_gains(0))

                    if gain_name is not None:
                        source.set_gain(0, gain_name, gain_value)
                        print(gain_name, "Gain:", source.get_gain(0, gain_name), '(Requested %d)' % gain_value, source.get_gain_range(0, gain_name), file=sys.stderr)
                    else:
                        print("WARNING: Gain", gain_option_name, "not supported by source!", file=sys.stderr)
                        print("Supported gains:", source.list_gains(0), file=sys.stderr)

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(0, bandwidth)
                print("Bandwidth:", source.get_bandwidth(0), '(Requested %d)' % bandwidth, file=sys.stderr)
            else:
                source.set_bandwidth(0, 0)
                print("Warning: Setting bandwidth to", source.get_bandwidth(0), file=sys.stderr)

            if 'antenna' in d:
                antenna = d['antenna']
                source.set_antenna(0, antenna)
                print("Antenna:", source.get_antenna(0), '(Requested %s)' % antenna, file=sys.stderr)
            else:
                print("Warning: Setting antenna to", source.get_antenna(0), file=sys.stderr)

            #source.set_frequency_correction(0, f_corr)
            #source.set_dc_offset_mode(0, True)
            #source.set_dc_offset(0, dc_off)
            #source.set_iq_balance(0, iq_bal)
        elif config['source'] == 'zeromq-sub':
            d = config["zeromq-sub-source"]

            from gnuradio import zeromq

            if 'address' not in d:
                print("No address specified for zeromq sub", file=sys.stderr)
                exit(1)

            pass_tags = False
            if 'pass_tags' in d:
                pass_tags = bool(distutils.util.strtobool(d['pass_tags']))

            timeout = 100
            if 'timeout' in d:
                timeout = int(d['timeout'])

            high_water_mark = -1
            if 'high_water_mark' in d:
                high_water_mark = int(d['high_water_mark'])

            source = zeromq.sub_source(gr.sizeof_gr_complex, 1, d['address'], timeout, pass_tags, high_water_mark, '')

        elif config['source'] == 'uhd':
            d = config["uhd-source"]

            from gnuradio import uhd

            dev_addr = ""
            if "device_addr" in d:
                dev_addr = d['device_addr']
            dev_args = d['device_args']

            cpu_format = 'fc32'
            wire_format = 'sc16'
            stream_args = ""

            stream_args = uhd.stream_args(cpu_format, wire_format, args=stream_args)
            source = uhd.usrp_source(dev_addr + "," + dev_args, stream_args)

            source.set_samp_rate(self._input_sample_rate)
            source.set_center_freq(self._center_frequency)

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain(gain, 0)
                print("Gain:", source.get_gain(0), '(Requested %d)' % gain, file=sys.stderr)

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(bandwidth, 0)
                print("Bandwidth:", source.get_bandwidth(0), '(Requested %d)' % bandwidth, file=sys.stderr)
            else:
                source.set_bandwidth(0)
                print("Warning: Setting bandwidth to", source.get_bandwidth(0), file=sys.stderr)

            if 'antenna' in d:
                antenna = d['antenna']
                source.set_antenna(antenna, 0)
                print("Antenna:", source.get_antenna(0), '(Requested %s)' % antenna, file=sys.stderr)
            else:
                print("Warning: Setting antenna to", source.get_antenna(0), file=sys.stderr)

            print("mboard sensors:", source.get_mboard_sensor_names(0), file=sys.stderr)
            #for sensor in source.get_mboard_sensor_names(0):
            #    print(sensor, source.get_mboard_sensor(sensor, 0))

            gpsdo_sources = ('gpsdo', 'jacksonlabs')

            time_source = None
            if 'time_source' in d:
                time_source = d['time_source']
                if time_source in gpsdo_sources:
                    source.set_time_source("gpsdo", 0)
                else:
                    source.set_time_source(time_source, 0)

            clock_source = None
            if 'clock_source' in d:
                clock_source = d['time_source']
                if clock_source in gpsdo_sources:
                    source.set_clock_source("gpsdo", 0)
                else:
                    source.set_clock_source(clock_source, 0)

            if time_source in gpsdo_sources or clock_source in gpsdo_sources:
                print("Waiting for gps_locked...", file=sys.stderr)
                while True:
                    try:
                        if d['time_source'] == "jacksonlabs":
                            servo = source.get_mboard_sensor("gps_servo", 0)
                            # See https://lists.ettus.com/empathy/thread/6ZOCFQSKLHSG2IH3ID7XPWVKHVHZXPBP
                            gps_locked = str(servo).split()[8] == "6"
                        else:
                            gps_locked = source.get_mboard_sensor("gps_locked", 0).to_bool()

                        if gps_locked:
                            break
                    except ValueError as e:
                        print(e, file=sys.stderr)
                        pass
                    time.sleep(1)

                print("gps_locked!", file=sys.stderr)

            if clock_source:
                print("Waiting for ref_locked...", file=sys.stderr)
                while True:
                    try:
                        ref_locked = source.get_mboard_sensor("ref_locked", 0)
                        if ref_locked.to_bool():
                            break
                    except ValueError as e:
                        print(e, file=sys.stderr)
                        pass
                    time.sleep(1)
                print("ref_locked!", file=sys.stderr)

            if time_source:
                if time_source in gpsdo_sources:
                    while True:
                        try:
                            gps_time = uhd.time_spec_t(source.get_mboard_sensor("gps_time").to_int())
                            break
                        except ValueError as e:
                            print(e, file=sys.stderr)
                            pass
                        time.sleep(1)

                    next_pps_time = gps_time + 1
                else:
                    system_time = uhd.time_spec_t(int(time.time()))
                    next_pps_time = system_time + 1

                source.set_time_next_pps(next_pps_time)
                print("Next PPS at", next_pps_time.get_real_secs(), file=sys.stderr)

                print("Sleeping 2 seconds...", file=sys.stderr)
                time.sleep(2)

                # TODO: Check result for plausibility
                print("USRP  time:", source.get_time_last_pps(0).get_real_secs(), file=sys.stderr)
            else:
                # Set a rough time estimate for rx_time tags from the USRP.
                # This prevents the output from having bogous time stamps if no GPSDO is available.
                source.set_time_now(uhd.time_spec_t(time.time()))

            self.source = source

        else:
            if sample_format == "cu8":
                converter = iridium.iuchar_to_complex()
                itemsize = gr.sizeof_char
                scale = 1
                itemtype = np.uint8
            elif sample_format == "ci8":
                converter = blocks.interleaved_char_to_complex()
                itemsize = gr.sizeof_char
                scale = 1 / 128.
                itemtype = np.int8
            elif sample_format == "ci16_le":
                converter = blocks.interleaved_short_to_complex()
                itemsize = gr.sizeof_short
                scale = 1 / 32768.
                itemtype = np.int16
            elif sample_format == "cf32_le":
                converter = None
                itemsize = gr.sizeof_gr_complex
                itemtype = np.complex64
            else:
                raise RuntimeError("Unknown sample format for offline mode given")

            if config['source'] == 'stdin':
                file_source = blocks.file_descriptor_source(itemsize=itemsize, fd=0, repeat=False)
            elif config['source'] == 'object':
                from iridium.file_object_source import file_object_source
                file_source = file_object_source(fileobject=config['object'], itemtype=itemtype)
            else:
                file_source = blocks.file_source(itemsize=itemsize, filename=config['file'], repeat=False)

            self.source = file_source  # XXX: keep reference

            if converter:
                multi = blocks.multiply_const_cc(scale)
                tb.connect(file_source, converter, multi)
                source = multi
            else:
                source = file_source

        self._fft_burst_tagger = iridium.fft_burst_tagger(center_frequency=self._center_frequency,
                                                          fft_size=self._fft_size,
                                                          sample_rate=self._input_sample_rate,
                                                          burst_pre_len=self._burst_pre_len,
                                                          burst_post_len=self._burst_post_len,
                                                          burst_width=int(self._burst_width),
                                                          max_bursts=max_bursts,
                                                          max_burst_len=int(self._input_sample_rate * 0.09),
                                                          threshold=self._threshold,
                                                          history_size=512,
                                                          offline=self._offline,
                                                          debug=self._verbose)
        self._fft_burst_tagger.set_min_output_buffer(1024 * 64)

        # Initial filter to filter the detected bursts. Runs at burst_sample_rate. Used to decimate the signal.
        input_filter = gnuradio.filter.firdes.low_pass_2(1, self._channel_sample_rate, self._burst_width / 2, self._burst_width, 40)
        #input_filter = gnuradio.filter.firdes.low_pass_2(1, self._channel_sample_rate, 42e3/2, 24e3, 40)
        #print len(input_filter)

        # Filter to find the start of the signal. Should be fairly narrow.
        start_finder_filter = gnuradio.filter.firdes.low_pass_2(1, self._burst_sample_rate, 5e3 / 2, 10e3 / 2, 60)
        #print len(start_finder_filter)

        self._iridium_qpsk_demod = iridium.iridium_qpsk_demod(self._channels)
        self._frame_sorter = iridium.frame_sorter()
        self._iridium_frame_printer = iridium.iridium_frame_printer(file_info)

        if raw_capture_filename:
            multi = blocks.multiply_const_cc(32768)
            converter = blocks.complex_to_interleaved_short()
            raw_sink = blocks.file_sink(itemsize=gr.sizeof_short, filename=raw_capture_filename + '.sigmf-data')
            tb.connect(source, multi, converter, raw_sink)

            # Enable the following if not fast enough
            #self._burst_to_pdu_converters = []
            #self._burst_downmixers = []
            #return

        tb.connect(source, self._fft_burst_tagger)

        if self._use_channelizer:
            self._burst_to_pdu_converters = []
            self._burst_downmixers = []
            sinks = []

            for channel in range(self._channels):
                if not self._use_fft_channelizer:
                    center = channel if channel <= self._channels / 2 else (channel - self._channels)
                    relative_center = center / float(self._channels)
                    relative_span = 1. / self._channels
                    relative_sample_rate = relative_span * self._channelizer_over_sample_ratio

                    # Second and third parameters tell the block where after the PFB it sits.
                    burst_to_pdu_converter = iridium.tagged_burst_to_pdu(self._max_burst_len,
                                                                         relative_center,
                                                                         relative_span,
                                                                         relative_sample_rate,
                                                                         -self._channelizer_delay,
                                                                         self._max_queue_len,
                                                                         not self._offline)
                    self._burst_to_pdu_converters.append(burst_to_pdu_converter)

                burst_downmixer = iridium.burst_downmix(self._burst_sample_rate,
                                                        int(0.007 * self._burst_sample_rate),
                                                        0,
                                                        (input_filter),
                                                        (start_finder_filter),
                                                        self._handle_multiple_frames_per_burst)

                if debug_id is not None:
                    burst_downmixer.debug_id(debug_id)

                self._burst_downmixers.append(burst_downmixer)

            channelizer_debug_sinks = []
            #channelizer_debug_sinks = [blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename="/tmp/channel-%d.f32"%i) for i in range(self._channels)]

            if self._use_fft_channelizer:
                if not channelizer_debug_sinks and self._offline:
                    # HACK: if there are no stream outputs active GNURadio has issues terminating the
                    # flowgraph on completion. Connect some dummy sinks to them.
                    channelizer_debug_sinks = [blocks.null_sink(gr.sizeof_gr_complex) for i in range(self._channels)]

                activate_streams = len(channelizer_debug_sinks) > 0
                self._channelizer = iridium.fft_channelizer(1024, self._channels - 1, activate_streams, self._n_burst_downmixers, self._max_burst_len,
                                                            self._max_queue_len * self._n_burst_downmixers, not self._offline)
            else:
                self._channelizer = gnuradio.filter.pfb.channelizer_ccf(numchans=self._channels, taps=self._pfb_fir_filter, oversample_rate=self._channelizer_over_sample_ratio)

            tb.connect(self._fft_burst_tagger, self._channelizer)

            for i in range(self._channels):
                if channelizer_debug_sinks:
                    tb.connect((self._channelizer, i), channelizer_debug_sinks[i])

            for i in range(self._n_burst_downmixers):
                if self._burst_to_pdu_converters:
                    tb.connect((self._channelizer, i), self._burst_to_pdu_converters[i])
                    tb.msg_connect((self._burst_to_pdu_converters[i], 'cpdus'), (self._burst_downmixers[i], 'cpdus'))
                    tb.msg_connect((self._burst_downmixers[i], 'burst_handled'), (self._burst_to_pdu_converters[i], 'burst_handled'))
                else:
                    tb.msg_connect((self._channelizer, 'cpdus%d' % i), (self._burst_downmixers[i], 'cpdus'))
                    tb.msg_connect((self._burst_downmixers[i], 'burst_handled'), (self._channelizer, 'burst_handled'))

                tb.msg_connect((self._burst_downmixers[i], 'cpdus'), (self._iridium_qpsk_demod, 'cpdus%d' % i))
        else:
            burst_downmix = iridium.burst_downmix(self._burst_sample_rate, int(0.007 * self._burst_sample_rate), 0, (input_filter), (start_finder_filter), self._handle_multiple_frames_per_burst)
            if debug_id is not None:
                burst_downmix.debug_id(debug_id)

            burst_to_pdu = iridium.tagged_burst_to_pdu(self._max_burst_len,
                                                       0.0, 1.0, 1.0,
                                                       0,
                                                       self._max_queue_len, not self._offline)

            tb.connect(self._fft_burst_tagger, burst_to_pdu)

            tb.msg_connect((burst_to_pdu, 'cpdus'), (burst_downmix, 'cpdus'))
            tb.msg_connect((burst_downmix, 'burst_handled'), (burst_to_pdu, 'burst_handled'))

            # Final connection to the demodulator. It prints the output to stdout
            tb.msg_connect((burst_downmix, 'cpdus'), (self._iridium_qpsk_demod, 'cpdus'))

            self._burst_downmixers = [burst_downmix]
            self._burst_to_pdu_converters = [burst_to_pdu]

        tb.msg_connect((self._iridium_qpsk_demod, 'pdus'), (self._frame_sorter, 'pdus'))
        tb.msg_connect((self._frame_sorter, 'pdus'), (self._iridium_frame_printer, 'pdus'))
Exemplo n.º 22
0
    def __init__(
            self,
            fifo='/home/dionisiocar/sdr/receiver_generator/rx_samples.bin',
            frequency=100e6,
            sample_rate=8000000):
        gr.top_block.__init__(self, "bladeRF FIFO RX")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("bladeRF FIFO RX")
        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", "bladeRF_fifo_rx")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Parameters
        ##################################################
        self.fifo = fifo
        self.frequency = frequency
        self.sample_rate = sample_rate

        ##################################################
        # Variables
        ##################################################
        self.sample_rate_range = sample_rate_range = sample_rate
        self.frequency_range = frequency_range = frequency

        ##################################################
        # Blocks
        ##################################################
        self._sample_rate_range_range = Range(160e3, 40e6, 1e6, sample_rate,
                                              200)
        self._sample_rate_range_win = RangeWidget(
            self._sample_rate_range_range, self.set_sample_rate_range,
            'Sample Rate', "counter", float)
        self.top_grid_layout.addWidget(self._sample_rate_range_win, 0, 0, 1, 1)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._frequency_range_range = Range(100e6, 500e6, 1e6, frequency, 200)
        self._frequency_range_win = RangeWidget(self._frequency_range_range,
                                                self.set_frequency_range,
                                                'Frequency', "counter", float)
        self.top_grid_layout.addWidget(self._frequency_range_win, 0, 1, 1, 1)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_sink_x_0 = qtgui.sink_c(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            frequency_range,  #fc
            sample_rate_range,  #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.qtgui_sink_x_0.enable_rf_freq(False)

        self.top_grid_layout.addWidget(self._qtgui_sink_x_0_win, 1, 0, 1, 8)
        for r in range(1, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(
            (1.0 / 2048.0))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            True, False)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short * 2,
                                                       fifo, False, 0, 0)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.qtgui_sink_x_0, 0))
Exemplo n.º 23
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage=("%prog: [options] output_filename.\nSpecial output_filename" + \
            "\"sdl\" will use video_sink_sdl as realtime output window. " + \
            "You then need to have gr-video-sdl installed.\n" +\
            "Make sure your input capture file contains interleaved " + \
            "shorts not complex floats")
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default=None,
                          help="Subdevice of UHD device where appropriate")
        parser.add_option("-A",
                          "--antenna",
                          type="string",
                          default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s",
                          "--samp-rate",
                          type="eng_float",
                          default=1e6,
                          help="set sample rate")
        parser.add_option("-c",
                          "--contrast",
                          type="eng_float",
                          default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b",
                          "--brightness",
                          type="eng_float",
                          default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be " + \
                            "interleaved shorts \n Use usrp_rx_file.py or " + \
                            "usrp_rx_cfile.py --output-shorts.\n Special " + \
                            "name \"usrp\" results in realtime capturing " + \
                            "and processing using usrp.\n" + \
                            "You then probably need a decimation factor of 64 or higher.")
        parser.add_option(
            "-f",
            "--freq",
            type="eng_float",
            default=519.25e6,
            help=
            "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel",
            metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p",
                          "--pal",
                          action="store_true",
                          default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n",
                          "--ntsc",
                          action="store_true",
                          default=False,
                          help="NTSC video format")
        parser.add_option("-r",
                          "--repeat",
                          action="store_false",
                          default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-N",
                          "--nframes",
                          type="eng_float",
                          default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("",
                          "--freq-min",
                          type="eng_float",
                          default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("",
                          "--freq-max",
                          type="eng_float",
                          default=900.25e6,
                          help="Set a maximum frequency [default=%default]")
        (options, args) = parser.parse_args()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n')
            sys.exit(1)

        filename = args[0]

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write(
                'You must specify the input -i FILENAME or -i usrp\n')
            raise SystemExit, 1

        if not (filename == "sdl"):
            options.repeat = False

        input_rate = options.samp_rate
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        if not (options.in_filename == "usrp"):
            # file is data source, capture with usr_rx_csfile.py
            self.filesource = blocks.file_source(gr.sizeof_short,
                                                 options.in_filename,
                                                 options.repeat)
            self.istoc = blocks.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.src = self.istoc
        else:
            if options.freq is None:
                parser.print_help()
                sys.stderr.write(
                    'You must specify the frequency with -f FREQ\n')
                raise SystemExit, 1

            # build the graph
            self.u = uhd.usrp_source(device_addr=options.args,
                                     stream_args=uhd.stream_args('fc32'))

            # Set the subdevice spec
            if (options.spec):
                self.u.set_subdev_spec(options.spec, 0)

            # Set the antenna
            if (options.antenna):
                self.u.set_antenna(options.antenna, 0)

            self.u.set_samp_rate(input_rate)
            dev_rate = self.u.get_samp_rate()

            self.src = self.u

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.u.get_gain_range()
                options.gain = float(g.start() + g.stop()) / 2.0
            self.u.set_gain(options.gain)

            r = self.u.set_center_freq(options.freq)
            if not r:
                sys.stderr.write('Failed to set frequency\n')
                raise SystemExit, 1

        self.agc = analog.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = blocks.complex_to_mag()
        self.set_blacklevel = blocks.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = blocks.multiply_const_ff(
            -options.contrast * 128.0 * 255.0 / (200.0))
        self.f2uc = blocks.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
            options.pal = True  #set default to PAL
        if options.pal:
            lines_per_frame = 625.0
            frames_per_sec = 25.0
            show_width = 768
        elif options.ntsc:
            lines_per_frame = 525.0
            frames_per_sec = 29.97002997
            show_width = 640
        width = int(input_rate / (lines_per_frame * frames_per_sec))
        height = int(lines_per_frame)

        if filename == "sdl":
            #Here comes the tv screen, you have to build and install
            #gr-video-sdl for this (subproject of gnuradio)
            try:
                video_sink = video_sdl.sink_uc(frames_per_sec, width, height,
                                               0, show_width, height)
            except:
                print "gr-video-sdl is not installed"
                print "realtime \"sdl\" video output window is not available"
                raise SystemExit, 1
            self.dst = video_sink
        else:
            print "You can use the imagemagick display tool to show the resulting imagesequence"
            print "use the following line to show the demodulated TV-signal:"
            print "display -depth 8 -size " + str(width) + "x" + str(
                height) + " gray:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = blocks.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = blocks.head(gr.sizeof_gr_complex,
                                    int(options.nframes * width * height))
            self.connect(self.src, self.head, self.agc)

        self.connect(self.agc, self.am_demod, self.invert_and_scale,
                     self.set_blacklevel, self.f2uc, self.dst)
Exemplo n.º 24
0
			if sample_rate is not None:
				self._send_and_wait_for_ok("RATE", sample_rate)
			else:
				#sample_rate = self.adc_freq() / decim_rate
				if self.set_decim_rate(decim_rate) == False:
					raise Exception, "Invalid decimation: %s (sample rate: %s)" % (decim_rate, sample_rate)
		
		if self.udp_source is None:
			assert self.vec2stream is None and self.ishort2complex is None
			udp_interface = "0.0.0.0"	# MAGIC
			self.udp_source = baz.udp_source(gr.sizeof_short * 2, udp_interface, udp_port, self._packet_size, True, True, True)
			#print "--> UDP Source listening on port:", udp_port, "interface:", udp_interface, "MTU:", self._packet_size
			if self._format == "fc32":
				try: self.vec2stream = blocks.vector_to_stream(gr.sizeof_short * 1, 2)
				except: self.vec2stream = gr.vector_to_stream(gr.sizeof_short * 1, 2)
				try: self.ishort2complex = blocks.interleaved_short_to_complex()	# FIXME: Use vector mode and skip 'vector_to_stream'
				except: self.ishort2complex = gr.interleaved_short_to_complex()
				mul_factor = 1./2**15
				try: self.multiply_const = blocks.multiply_const_cc(mul_factor)
				except: self.multiply_const = gr.multiply_const_cc(mul_factor)
			
				self.connect(self.udp_source, self.vec2stream, self.ishort2complex, self.multiply_const, self)
			elif self._format == "sc16":
				self.connect(self.udp_source, self)
		else:
			assert self.vec2stream is not None and self.ishort2complex is not None
		
		if self._listen_only == False:
			if self._last_antenna is not None:
				self.select_rx_antenna(self._last_antenna)
			if self._last_freq is not None:
Exemplo n.º 25
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \
              "Make sure your input capture file contains interleaved shorts not complex floats"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default=None,
                          help="Subdevice of UHD device where appropriate")
        parser.add_option("-A",
                          "--antenna",
                          type="string",
                          default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s",
                          "--samp-rate",
                          type="eng_float",
                          default=1e6,
                          help="set sample rate")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=519.25e6,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-c",
                          "--contrast",
                          type="eng_float",
                          default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b",
                          "--brightness",
                          type="eng_float",
                          default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-p",
                          "--pal",
                          action="store_true",
                          default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n",
                          "--ntsc",
                          action="store_true",
                          default=False,
                          help="NTSC video format")
        parser.add_option(
            "-o",
            "--out-filename",
            type="string",
            default="sdl",
            help=
            "For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)"
        )
        parser.add_option("-r",
                          "--repeat",
                          action="store_false",
                          default=True,
                          help="repeat file in a loop")
        parser.add_option("",
                          "--freq-min",
                          type="eng_float",
                          default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("",
                          "--freq-max",
                          type="eng_float",
                          default=900.25e6,
                          help="Set a maximum frequency [default=%default]")

        (options, args) = parser.parse_args()
        if not ((len(args) == 1) or (len(args) == 0)):
            parser.print_help()
            sys.exit(1)

        if len(args) == 1:
            filename = args[0]
        else:
            filename = None

        self.frame = frame
        self.panel = panel

        self.contrast = options.contrast
        self.brightness = options.brightness
        self.state = "FREQ"
        self.freq = 0

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        # build graph
        self.u = None

        if not (options.out_filename == "sdl"):
            options.repeat = False

        usrp_rate = options.samp_rate

        if not ((filename is None) or (filename == "usrp")):
            # file is data source
            self.filesource = blocks.file_source(gr.sizeof_short, filename,
                                                 options.repeat)
            self.istoc = blocks.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.src = self.istoc

            options.gain = 0.0
            self.gain = 0.0

        else:  # use a UHD device
            self.u = uhd.usrp_source(device_addr=options.args,
                                     stream_args=uhd.stream_args('fc32'))

            # Set the subdevice spec
            if (options.spec):
                self.u.set_subdev_spec(options.spec, 0)

            # Set the antenna
            if (options.antenna):
                self.u.set_antenna(options.antenna, 0)

            self.u.set_samp_rate(usrp_rate)
            dev_rate = self.u.get_samp_rate()

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.u.get_gain_range()
                options.gain = float(g.start() + g.stop()) / 2.0

            self.src = self.u

        self.gain = options.gain

        f2uc = blocks.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
            options.pal = True  #set default to PAL

        if options.pal:
            lines_per_frame = 625.0
            frames_per_sec = 25.0
            show_width = 768

        elif options.ntsc:
            lines_per_frame = 525.0
            frames_per_sec = 29.97002997
            show_width = 640

        width = int(usrp_rate / (lines_per_frame * frames_per_sec))
        height = int(lines_per_frame)

        if (options.out_filename == "sdl"):
            #Here comes the tv screen, you have to build and install
            #gr-video-sdl for this (subproject of gnuradio, only in cvs
            #for now)
            try:
                video_sink = video_sdl.sink_uc(frames_per_sec, width, height,
                                               0, show_width, height)
            except:
                print "gr-video-sdl is not installed"
                print "realtime \"sdl\" video output window is not available"
                raise SystemExit, 1
            self.dst = video_sink
        else:
            print "You can use the imagemagick display tool to show the resulting imagesequence"
            print "use the following line to show the demodulated TV-signal:"
            print "display -depth 8 -size " +str(width)+ "x" + str(height) \
                + " gray:" + options.out_filename
            print "(Use the spacebar to advance to next frames)"
            options.repeat = False
            file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename)
            self.dst = file_sink

        self.agc = analog.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = blocks.complex_to_mag()
        self.set_blacklevel = blocks.add_const_ff(0.0)
        self.invert_and_scale = blocks.multiply_const_ff(
            0.0)  #-self.contrast *128.0*255.0/(200.0)

        # now wire it all together
        #sample_rate=options.width*options.height*options.framerate

        process_type = 'do_no_sync'
        if process_type == 'do_no_sync':
            self.connect(self.src, self.agc, self.am_demod,
                         self.invert_and_scale, self.set_blacklevel, f2uc,
                         self.dst)
        elif process_type == 'do_tv_sync_adv':
            #defaults: gr.tv_sync_adv (double sampling_freq, unsigned
            #int tv_format,bool output_active_video_only=false, bool
            #do_invert=false, double wanted_black_level=0.0, double
            #wanted_white_level=255.0, double avg_alpha=0.1, double
            #initial_gain=1.0, double initial_offset=0.0,bool
            #debug=false)

            #note, this block is not yet in cvs
            self.tv_sync_adv = gr.tv_sync_adv(usrp_rate, 0, False, False, 0.0,
                                              255.0, 0.01, 1.0, 0.0, False)
            self.connect(self.src, self.am_demod, self.invert_and_scale,
                         self.tv_sync_adv, s2f, f2uc, self.dst)

        elif process_type == 'do_nullsink':
            #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
            c2r = blocks.complex_to_real()
            nullsink = blocks.null_sink(gr.sizeof_float)
            self.connect(self.src, c2r, nullsink)  #video_sink)
        elif process_type == 'do_tv_sync_corr':
            frame_size = width * height  #int(usrp_rate/25.0)
            nframes = 10  # 32
            search_window = 20 * nframes
            debug = False
            video_alpha = 0.3  #0.1
            corr_alpha = 0.3

            #Note: this block is not yet in cvs
            tv_corr = gr.tv_correlator_ff(frame_size, nframes, search_window,
                                          video_alpha, corr_alpha, debug)
            shift = blocks.add_const_ff(-0.7)

            self.connect(self.src, self.agc, self.am_demod, tv_corr,
                         self.invert_and_scale, self.set_blacklevel, f2uc,
                         self.dst)
        else:  # process_type=='do_test_image':
            src_vertical_bars = analog.sig_source_f(usrp_rate,
                                                    analog.GR_SIN_WAVE,
                                                    10.0 * usrp_rate / 320,
                                                    255, 128)
            self.connect(src_vertical_bars, f2uc, self.dst)

        self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate)

        frange = self.u.get_freq_range()
        if (frange.start() > self.tv_freq_max
                or frange.stop() < self.tv_freq_min):
            sys.stderr.write(
                "Radio does not support required frequency range.\n")
            sys.exit(1)
        if (options.freq < self.tv_freq_min
                or options.freq > self.tv_freq_max):
            sys.stderr.write(
                "Requested frequency is outside of required frequency range.\n"
            )
            sys.exit(1)

        # set initial values
        self.set_gain(options.gain)
        self.set_contrast(self.contrast)
        self.set_brightness(options.brightness)
        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
    def __init__(self, center_frequency, sample_rate, decimation, filename, sample_format=None, threshold=7.0, signal_width=40e3, offline=False, max_queue_len=500, verbose=False):
        gr.top_block.__init__(self, "Top Block")
        self._center_frequency = center_frequency
        self._signal_width = 40e3
        self._input_sample_rate = sample_rate
        self._verbose = verbose
        self._threshold = threshold
        self._filename = filename
        self._offline = offline
        self._max_queue_len = max_queue_len

        self._fft_size = int(math.pow(2, 1 + int(math.log(self._input_sample_rate / 1000, 2)))) # fft is approx 1ms long
        self._burst_pre_len = 2 * self._fft_size
        self._burst_post_len = 8 * self._fft_size
        self._burst_width= int(self._signal_width / (self._input_sample_rate / self._fft_size)) # Area to ignore around an already found signal in FFT bins
        if decimation > 1:
            self._use_pfb = True

            # We will set up a filter bank with an odd number of outputs and
            # and an over sampling ratio to still get the desired decimation.

            # The goal is to still catch signal which (due to doppler shift) end up
            # on the border of two channels.

            # For this to work the desired decimation must be even.
            if decimation % 2:
                raise RuntimeError("The desired decimation must be 1 or an even number")

            self._channels = decimation + 1
            self._pfb_over_sample_ratio = self._channels / (self._channels - 1.)
            pfb_output_sample_rate = int(round(float(self._input_sample_rate) / self._channels * self._pfb_over_sample_ratio))
            assert pfb_output_sample_rate == self._input_sample_rate / decimation


            # The over sampled region of the FIR filter contains half of the signal width and
            # the transition region of the FIR filter.
            # The bandwidth is simply increased by the signal width.
            # A signal which has its center frequency directly on the border of
            # two channels will reconstruct correclty on both channels.
            self._fir_bw = (self._input_sample_rate / self._channels + self._signal_width) / 2

            # The remaining bandwidth inside the over samples region is used to
            # contain the transistion region of the filter.
            # It can be multiplied by two as it is allowed to continue into the
            # transition region of the neighboring channel.
            # TODO: Draw a nice graphic how this works.
            self._fir_tw = (pfb_output_sample_rate / 2 - self._fir_bw) * 2

            # If the over sampling ratio is not large enough, there is not
            # enough room to construct a transition region.
            if self._fir_tw < 0:
                raise RuntimeError("PFB over sampling ratio not enough to create a working FIR filter")

            self._pfb_fir_filter = gnuradio.filter.firdes.low_pass_2(1, self._input_sample_rate, self._fir_bw, self._fir_tw, 60)

            # If the transition width approaches 0, the filter size goes up significantly.
            if len(self._pfb_fir_filter) > 200:
                print >> sys.stderr, "Warning: The PFB FIR filter has an abnormal large number of taps:", len(self._pfb_fir_filter)
                print >> sys.stderr, "Consider reducing the decimation factor or increase the over sampling ratio"


            self._burst_sample_rate = pfb_output_sample_rate
            if self._verbose:
                print >> sys.stderr, "self._channels", self._channels
                print >> sys.stderr, "len(self._pfb_fir_filter)", len(self._pfb_fir_filter)
                print >> sys.stderr, "self._pfb_over_sample_ratio", self._pfb_over_sample_ratio
                print >> sys.stderr, "self._fir_bw", self._fir_bw
                print >> sys.stderr, "self._fir_tw", self._fir_tw
                print >> sys.stderr, "self._burst_sample_rate", self._burst_sample_rate
        else:
            self._use_pfb = False
            self._burst_sample_rate = self._input_sample_rate

        # After 90 ms there needs to be a pause in the frame sturcture.
        # Let's make that the limit for a detected burst
        self._max_burst_len = int(self._burst_sample_rate * 0.09)

        if self._verbose:
            print >> sys.stderr, "require %.1f dB" % self._threshold
            print >> sys.stderr, "burst_width: %d (= %.1f Hz)" % (self._burst_width, self._burst_width*self._input_sample_rate/self._fft_size)


        if self._filename.endswith(".conf"):
            import ConfigParser
            config = ConfigParser.ConfigParser()
            config.read(self._filename)
            items = config.items("osmosdr-source")
            d = {key: value for key, value in items}

            if 'device_args' in d:
                source = osmosdr.source(args=d['device_args'])
            else:
                source = osmosdr.source()

            source.set_sample_rate(self._input_sample_rate)
            source.set_center_freq(self._center_frequency, 0)

            if 'gain' in d:
                gain = int(d['gain'])
                source.set_gain(gain, 0)
                print >> sys.stderr, "(RF) Gain:", source.get_gain(0), '(Requested %d)' % gain

            if 'if_gain' in d:
                if_gain = int(d['if_gain'])
                source.set_if_gain(if_gain, 0)
                print >> sys.stderr, "IF Gain:", source.get_gain("IF", 0), '(Requested %d)' % if_gain

            if 'mix_gain' in d:
                mix_gain = int(d['mix_gain'])
                source.set_mix_gain(mix_gain, 0)
                print >> sys.stderr, "MIX Gain:", source.get_gain("MIX", 0), '(Requested %d)' % mix_gain

            if 'bb_gain' in d:
                bb_gain = int(d['bb_gain'])
                source.set_bb_gain(bb_gain, 0)
                print >> sys.stderr, "BB Gain:", source.get_gain("BB", 0), '(Requested %d)' % bb_gain

            if 'bandwidth' in d:
                bandwidth = int(d['bandwidth'])
                source.set_bandwidth(bandwidth, 0)
                print >> sys.stderr, "Bandwidth:", source.get_bandwidth(0), '(Requested %d)' % bandwidth
            else:
                source.set_bandwidth(0, 0)
                print >> sys.stderr, "Warning: Setting bandwidth to", source.get_bandwidth(0)

            #source.set_freq_corr($corr0, 0)
            #source.set_dc_offset_mode($dc_offset_mode0, 0)
            #source.set_iq_balance_mode($iq_balance_mode0, 0)
            #source.set_gain_mode($gain_mode0, 0)
            #source.set_antenna($ant0, 0)

            converter = None
        else:
            if sample_format == "rtl":
                converter = iridium.iuchar_to_complex()
                itemsize = gr.sizeof_char
            elif sample_format == "hackrf":
                converter = blocks.interleaved_char_to_complex()
                itemsize = gr.sizeof_char
            elif sample_format == "sc16":
                converter = blocks.interleaved_short_to_complex()
                itemsize = gr.sizeof_short
            elif sample_format == "float":
                converter = None
                itemsize = gr.sizeof_gr_complex
            else:
                raise RuntimeError("Unknown sample format for offline mode given")
            source = blocks.file_source(itemsize=itemsize, filename=self._filename, repeat=False)

        # Just to keep the code below a bit more portable
        tb = self

        #fft_burst_tagger::make(float center_frequency, int fft_size, int sample_rate,
        #                    int burst_pre_len, int burst_post_len, int burst_width,
        #                    int max_bursts, float threshold, int history_size, bool debug)

        self._fft_burst_tagger = iridium.fft_burst_tagger(center_frequency=self._center_frequency,
                                fft_size=self._fft_size,
                                sample_rate=self._input_sample_rate,
                                burst_pre_len=self._burst_pre_len, burst_post_len=self._burst_post_len,
                                burst_width=self._burst_width,
                                max_bursts=100,
                                threshold=self._threshold,
                                history_size=512,
                                debug=self._verbose)

        # Initial filter to filter the detected bursts. Runs at burst_sample_rate. Used to decimate the signal.
        # TODO: Should probably be set to self._signal_width
        input_filter = gnuradio.filter.firdes.low_pass_2(1, self._burst_sample_rate, 40e3/2, 40e3, 40)
        #input_filter = gnuradio.filter.firdes.low_pass_2(1, self._burst_sample_rate, 42e3/2, 24e3, 40)
        #print len(input_filter)

        # Filter to find the start of the signal. Should be fairly narrow.
        # TODO: 250000 appears as magic number here
        start_finder_filter = gnuradio.filter.firdes.low_pass_2(1, 250000, 5e3/2, 10e3/2, 60)
        #print len(start_finder_filter)

        self._iridium_qpsk_demod = iridium.iridium_qpsk_demod_cpp()
        #self._iridium_qpsk_demod = iridium.iridium_qpsk_demod(250000)

        if self._use_pfb:
            self._burst_to_pdu_converters = []
            self._burst_downmixers = []
            sinks = []

            for channel in range(self._channels):
                center = channel if channel <= self._channels / 2 else (channel - self._channels)

                # Second and third parameters tell the block where after the PFB it sits.
                relative_center = center / float(self._channels)
                relative_span = 1. / self._channels
                relative_sample_rate = relative_span * self._pfb_over_sample_ratio
                burst_to_pdu_converter = iridium.tagged_burst_to_pdu(self._max_burst_len, relative_center,
                                            relative_span, relative_sample_rate, self._max_queue_len, not self._offline)
                burst_downmixer = iridium.burst_downmix(self._burst_sample_rate,
                                    int(0.007 * 250000), 0, (input_filter), (start_finder_filter))

                self._burst_downmixers.append(burst_downmixer)
                self._burst_to_pdu_converters.append(burst_to_pdu_converter)

            #pfb_debug_sinks = [blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename="/tmp/channel-%d.f32"%i) for i in range(self._channels)]
            pfb_debug_sinks = None

            pfb = gnuradio.filter.pfb.channelizer_ccf(numchans=self._channels, taps=self._pfb_fir_filter, oversample_rate=self._pfb_over_sample_ratio)

            if converter:
                tb.connect(source, converter, self._fft_burst_tagger, pfb)
            else:
                tb.connect(source, self._fft_burst_tagger, pfb)

            for i in range(self._channels):
                tb.connect((pfb, i), self._burst_to_pdu_converters[i])
                if pfb_debug_sinks:
                    tb.connect((pfb, i), pfb_debug_sinks[i])

                tb.msg_connect((self._burst_to_pdu_converters[i], 'cpdus'), (self._burst_downmixers[i], 'cpdus'))
                tb.msg_connect((self._burst_downmixers[i], 'burst_handled'), (self._burst_to_pdu_converters[i], 'burst_handled'))

                tb.msg_connect((self._burst_downmixers[i], 'cpdus'), (self._iridium_qpsk_demod, 'cpdus'))
        else:
            burst_downmix = iridium.burst_downmix(self._burst_sample_rate, int(0.007 * 250000), 0, (input_filter), (start_finder_filter))
            burst_to_pdu = iridium.tagged_burst_to_pdu(self._max_burst_len, 0.0, 1.0, 1.0, self._max_queue_len, not self._offline)

            if converter:
                #multi = blocks.multiply_const_cc(1/128.)
                #tb.connect(source, converter, multi, self._fft_burst_tagger, burst_to_pdu)
                tb.connect(source, converter, self._fft_burst_tagger, burst_to_pdu)
            else:
                tb.connect(source, self._fft_burst_tagger, burst_to_pdu)


            tb.msg_connect((burst_to_pdu, 'cpdus'), (burst_downmix, 'cpdus'))
            tb.msg_connect((burst_downmix, 'burst_handled'), (burst_to_pdu, 'burst_handled'))

            # Final connection to the demodulator. It prints the output to stdout
            tb.msg_connect((burst_downmix, 'cpdus'), (self._iridium_qpsk_demod, 'cpdus'))

            self._burst_downmixers = [burst_downmix]
            self._burst_to_pdu_converters = [burst_to_pdu]
Exemplo n.º 27
0
    def __init__(self, filename, loop, decimation, samp_rate, f0, short,
                 start_time):
        gr.hier_block2.__init__(self, "uhd_timed_cordic_emulator",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # setup logger
        logger_name = 'gr_log.' + self.to_basic_block().alias()
        if logger_name in gr.logger_get_names():
            self.log = gr.logger(logger_name)
        else:
            self.log = gr.logger('log')

        # variables
        taps = filter.firdes.low_pass_2(1, samp_rate,
                                        (samp_rate * 0.4) / decimation,
                                        (samp_rate * 0.4) / decimation, 60)
        self.log.debug("freq xlating filter created with " + repr(len(taps)) +
                       " taps")
        fc_start = f0

        # message inputs / outputs
        self.message_port_register_hier_in("command")

        # blocks
        if short:
            self.file = blocks.file_source(gr.sizeof_short * 1, filename, loop)
        else:
            self.file = blocks.file_source(gr.sizeof_gr_complex * 1, filename,
                                           loop)
        self.deint = blocks.interleaved_short_to_complex(
            False, False, 1.0 / pow(2, 15))
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate,
                                        True)
        self.tagger = timing_utils.add_usrp_tags_c(
            fc_start, samp_rate, int(start_time),
            (start_time - int(start_time)))
        self.tuner = timing_utils.retune_uhd_to_timed_tag(
            int(samp_rate), timing_utils.PMTCONSTSTR__dsp_freq(),
            int(start_time), (start_time - int(start_time)))
        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                decimation, (taps), fc_start, samp_rate)
        else:
            self.filt = timing_utils.timed_freq_xlating_fir_ccf(
                1, [1], fc_start, samp_rate)
            self.fir = filter.fir_filter_ccf(decimation, (taps))
            self.fir.declare_sample_delay(0)

        # connections
        if short:
            self.connect(self.file, self.deint)
            self.connect(self.deint, self.throttle)
            self.connect(self.throttle, self.tagger)
        else:
            self.connect(self.file, self.throttle)
            self.connect(self.throttle, self.tagger)

        self.connect(self.tagger, self.tuner)
        self.connect(self.tuner, self.filt)

        if DECIMATE_IN_FREQ_XLATING_FILTER:
            self.connect(self.filt, self)
        else:
            self.connect(self.filt, self.fir)
            self.connect(self.fir, self)

        self.msg_connect(self, "command", self.tuner, "command")
Exemplo n.º 28
0
    def __init__(self,frame,panel,vbox,argv):
        stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)

        usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \
              "Make sure your input capture file contains interleaved shorts not complex floats"
        parser=OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
                          help="set sample rate")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-o", "--out-filename", type="string", default="sdl",
                          help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat file in a loop")
        parser.add_option("", "--freq-min", type="eng_float", default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("", "--freq-max", type="eng_float", default=900.25e6,
                          help="Set a maximum frequency [default=%default]")

        (options, args) = parser.parse_args()
        if not ((len(args) == 1) or (len(args) == 0)):
            parser.print_help()
            sys.exit(1)

        if len(args) == 1:
          filename = args[0]
        else:
          filename = None

        self.frame = frame
        self.panel = panel

        self.contrast = options.contrast
        self.brightness = options.brightness
        self.state = "FREQ"
        self.freq = 0

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        # build graph
        self.u=None

        if not (options.out_filename=="sdl"):
          options.repeat=False

        usrp_rate = options.samp_rate

        if not ((filename is None) or (filename=="usrp")):
          # file is data source
          self.filesource = blocks.file_source(gr.sizeof_short,filename,options.repeat)
          self.istoc = blocks.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.src=self.istoc

          options.gain=0.0
          self.gain=0.0

        else: # use a UHD device
          self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))

          # Set the subdevice spec
          if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

          # Set the antenna
          if(options.antenna):
            self.u.set_antenna(options.antenna, 0)

          self.u.set_samp_rate(usrp_rate)
          dev_rate = self.u.get_samp_rate()

          if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            options.gain = float(g.start()+g.stop())/2.0

          self.src=self.u

        self.gain = options.gain

        f2uc = blocks.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL

        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768

        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640

        width=int(usrp_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if (options.out_filename=="sdl"):
          #Here comes the tv screen, you have to build and install
          #gr-video-sdl for this (subproject of gnuradio, only in cvs
          #for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height, 0,
                                             show_width, height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) \
              + " gray:" + options.out_filename
          print "(Use the spacebar to advance to next frames)"
          options.repeat=False
          file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink

        self.agc = analog.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = blocks.complex_to_mag ()
        self.set_blacklevel = blocks.add_const_ff(0.0)
        self.invert_and_scale = blocks.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0)

        # now wire it all together
        #sample_rate=options.width*options.height*options.framerate

        process_type='do_no_sync'
        if process_type=='do_no_sync':
          self.connect (self.src, self.agc,self.am_demod,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc,self.dst)
        elif process_type=='do_tv_sync_adv':
          #defaults: gr.tv_sync_adv (double sampling_freq, unsigned
          #int tv_format,bool output_active_video_only=false, bool
          #do_invert=false, double wanted_black_level=0.0, double
          #wanted_white_level=255.0, double avg_alpha=0.1, double
          #initial_gain=1.0, double initial_offset=0.0,bool
          #debug=false)

          #note, this block is not yet in cvs
          self.tv_sync_adv=gr.tv_sync_adv(usrp_rate, 0, False, False,
                                          0.0, 255.0, 0.01, 1.0, 0.0, False)
          self.connect (self.src, self.am_demod, self.invert_and_scale,
                        self.tv_sync_adv, s2f, f2uc, self.dst)

        elif process_type=='do_nullsink':
          #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
          c2r=blocks.complex_to_real()
          nullsink=blocks.null_sink(gr.sizeof_float)
          self.connect (self.src, c2r,nullsink) #video_sink)
        elif process_type=='do_tv_sync_corr':
          frame_size=width*height #int(usrp_rate/25.0)
          nframes=10# 32
          search_window=20*nframes
          debug=False
          video_alpha=0.3 #0.1
          corr_alpha=0.3

          #Note: this block is not yet in cvs
          tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window,
                                      video_alpha, corr_alpha,debug)
          shift = blocks.add_const_ff(-0.7)

          self.connect (self.src, self.agc, self.am_demod, tv_corr,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc, self.dst)
        else: # process_type=='do_test_image':
          src_vertical_bars = analog.sig_source_f(usrp_rate, analog.GR_SIN_WAVE,
                                                  10.0 *usrp_rate/320, 255,128)
          self.connect(src_vertical_bars, f2uc, self.dst)

        self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate)


        frange = self.u.get_freq_range()
        if(frange.start() > self.tv_freq_max or frange.stop() <  self.tv_freq_min):
            sys.stderr.write("Radio does not support required frequency range.\n")
            sys.exit(1)
        if(options.freq < self.tv_freq_min or options.freq > self.tv_freq_max):
            sys.stderr.write("Requested frequency is outside of required frequency range.\n")
            sys.exit(1)

        # set initial values
        self.set_gain(options.gain)
        self.set_contrast(self.contrast)
        self.set_brightness(options.brightness)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 29
0
    def __init__(self,
                 channel_num=22,
                 decim=50,
                 directory="./",
                 f_offset=0,
                 fc=947.4e6,
                 out_directory="./",
                 samp_rate=25e6):
        gr.top_block.__init__(self, "Get Channel")

        ##################################################
        # Parameters
        ##################################################
        self.channel_num = channel_num
        self.decim = decim
        self.directory = directory
        self.f_offset = f_offset
        self.fc = fc
        self.out_directory = out_directory
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.SDCCH = SDCCH = 6
        self.RACH = RACH = 3
        self.PCH = PCH = 5
        self.CHANNEL_UNKNOWN = CHANNEL_UNKNOWN = 0
        self.CCCH = CCCH = 2
        self.BCCH = BCCH = 1
        self.AGCH = AGCH = 4

        ##################################################
        # Blocks
        ##################################################
        self.pfb_decimator_ccf_0 = pfb.decimator_ccf(decim, (), 0, 100, True,
                                                     True)
        self.pfb_decimator_ccf_0.declare_sample_delay(0)

        self.blocks_rotator_cc_0 = blocks.rotator_cc(
            -2 * math.pi *
            (arfcn.get_freq_from_arfcn(channel_num, 'e') - fc + f_offset) /
            samp_rate)
        self.blocks_interleaved_short_to_complex_1 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_short * 1,
            "/home/piotr/Odbiornik_gsm/Hopping/test_data/nagranie_hopping_4",
            False)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_gr_complex * 1,
            "" + out_directory + "/fc_" + str(channel_num) + ".cfile", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_1, 0))
        self.connect((self.blocks_interleaved_short_to_complex_1, 0),
                     (self.blocks_rotator_cc_0, 0))
        self.connect((self.blocks_rotator_cc_0, 0),
                     (self.pfb_decimator_ccf_0, 0))
        self.connect((self.pfb_decimator_ccf_0, 0),
                     (self.blocks_file_sink_0, 0))
Exemplo n.º 30
0
def graph (args):

	print os.getpid()

	nargs = len(args)
    	if nargs == 2:
		infile = args[0]
        	outfile = args[1]
    	else:
        	raise ValueError('usage: interp.py input_file output_file.ts\n')

	input_rate = 19.2e6
	IF_freq = 5.75e6

	tb = gr.top_block()

	# Read from input file
	srcf = blocks.file_source(gr.sizeof_short, infile)

	# Convert interleaved shorts (I,Q,I,Q) to complex
	is2c = blocks.interleaved_short_to_complex()

	# 1/2 as wide because we're designing lp filter
	symbol_rate = atsc.ATSC_SYMBOL_RATE/2.
	NTAPS = 279
	tt = filter.firdes.root_raised_cosine (1.0, input_rate / 3, symbol_rate, .1152, NTAPS)
	rrc = filter.fir_filter_ccf(1, tt)

	# Interpolate Filter our 6MHz wide signal centered at 0
	ilp_coeffs = filter.firdes.low_pass(1, input_rate, 3.2e6, .5e6, filter.firdes.WIN_HAMMING)
	ilp = filter.interp_fir_filter_ccf(3, ilp_coeffs)

	# Move the center frequency to 5.75MHz ( this wont be needed soon )
	duc_coeffs = filter.firdes.low_pass ( 1, 19.2e6, 9e6, 1e6, filter.firdes.WIN_HAMMING )
    	duc = filter.freq_xlating_fir_filter_ccf ( 1, duc_coeffs, -5.75e6, 19.2e6 )

	# fpll input is float
	c2f = blocks.complex_to_float()

	# Phase locked loop
	fpll = atsc.fpll()

	# Clean fpll output
	lp_coeffs2 = filter.firdes.low_pass (1.0,
			   input_rate,
			   5.75e6,
                           120e3,
                           filter.firdes.WIN_HAMMING);
	lp_filter = filter.fir_filter_fff (1, lp_coeffs2)

	# Remove pilot ( at DC now )
	iir = filter.single_pole_iir_filter_ff(1e-5)
	remove_dc = blocks.sub_ff()

	# Bit Timing Loop, Field Sync Checker and Equalizer
	btl = atsc.bit_timing_loop()
	fsc = atsc.fs_checker()
	eq = atsc.equalizer()
	fsd = atsc.field_sync_demux()

	# Viterbi
	viterbi = atsc.viterbi_decoder()
        deinter = atsc.deinterleaver()
        rs_dec = atsc.rs_decoder()
        derand = atsc.derandomizer()
	depad = atsc.depad()

	# Write to output file
	outf = blocks.file_sink(gr.sizeof_char,outfile)

	# Connect it all together
	tb.connect( srcf, is2c, rrc, ilp, duc, c2f, fpll, lp_filter)
	tb.connect( lp_filter, iir )
	tb.connect( lp_filter, (remove_dc, 0) )
	tb.connect( iir, (remove_dc, 1) )
	tb.connect( remove_dc, btl )
	tb.connect( (btl, 0), (fsc, 0), (eq, 0), (fsd,0) )
	tb.connect( (btl, 1), (fsc, 1), (eq, 1), (fsd,1) )
	tb.connect( fsd, viterbi, deinter, rs_dec, derand, depad, outf )

	tb.run()
Exemplo n.º 31
0
    def __init__(self,
                 baudrate=1200.0,
                 raw_file='',
                 udp_dest_audio='127.0.0.1',
                 udp_dest_iq='127.0.0.1',
                 udp_port_audio=7355,
                 udp_port_iq=7356):
        gr.top_block.__init__(self, "satnogs raw to udp")

        ##################################################
        # Parameters
        ##################################################
        self.baudrate = baudrate
        self.raw_file = raw_file
        self.udp_dest_audio = udp_dest_audio
        self.udp_dest_iq = udp_dest_iq
        self.udp_port_audio = udp_port_audio
        self.udp_port_iq = udp_port_iq

        ##################################################
        # Variables
        ##################################################
        self.sps = sps = 4
        self.audio_samp_rate = audio_samp_rate = 48000
        self.if_freq = if_freq = 12000
        self.decimation = decimation = satnogs.find_decimation(
            baudrate, 2, audio_samp_rate, sps)

        ##################################################
        # Blocks
        ##################################################
        self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(
            audio_samp_rate / (baudrate * decimation), taps=None, flt_size=32)
        self.pfb_arb_resampler_xxx_0.declare_sample_delay(0)
        self.low_pass_filter_0_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, audio_samp_rate, 0.42 * audio_samp_rate / 2.0,
                            0.05 * audio_samp_rate, firdes.WIN_HAMMING, 6.76))
        self.blocks_udp_sink_0_0 = blocks.udp_sink(gr.sizeof_short * 1,
                                                   udp_dest_iq, udp_port_iq,
                                                   1472, True)
        self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short * 1,
                                                 udp_dest_audio,
                                                 udp_port_audio, 1472, True)
        self.blocks_throttle_1 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 baudrate * decimation, True)
        self.blocks_rotator_cc_0_0 = blocks.rotator_cc(
            2.0 * math.pi * (if_freq / audio_samp_rate))
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(16383)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(1 / 16768)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            False, False)
        self.blocks_float_to_short_0 = blocks.float_to_short(1, 16383.0)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short * 1,
                                                       raw_file, False, 0, 0)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_interleaved_short_0 = blocks.complex_to_interleaved_short(
            False)
        self.analog_agc2_xx_0_1 = analog.agc2_cc(1e-3, 1e-3, 0.5, 1.0)
        self.analog_agc2_xx_0_1.set_max_gain(65536)
        self.analog_agc2_xx_0_0 = analog.agc2_cc(0.01, 0.001, 0.015, 1.0)
        self.analog_agc2_xx_0_0.set_max_gain(65536)
        self.analog_agc2_xx_0 = analog.agc2_cc(1e-2, 1e-3, 1.5e-2, 1.0)
        self.analog_agc2_xx_0.set_max_gain(65536)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc2_xx_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.analog_agc2_xx_0_0, 0),
                     (self.low_pass_filter_0_0, 0))
        self.connect((self.analog_agc2_xx_0_1, 0),
                     (self.pfb_arb_resampler_xxx_0, 0))
        self.connect((self.blocks_complex_to_interleaved_short_0, 0),
                     (self.blocks_udp_sink_0_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.blocks_float_to_short_0, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))
        self.connect((self.blocks_float_to_short_0, 0),
                     (self.blocks_udp_sink_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_throttle_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_complex_to_interleaved_short_0, 0))
        self.connect((self.blocks_rotator_cc_0_0, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_throttle_1, 0), (self.analog_agc2_xx_0, 0))
        self.connect((self.blocks_throttle_1, 0), (self.analog_agc2_xx_0_1, 0))
        self.connect((self.low_pass_filter_0_0, 0),
                     (self.blocks_rotator_cc_0_0, 0))
        self.connect((self.pfb_arb_resampler_xxx_0, 0),
                     (self.analog_agc2_xx_0_0, 0))
Exemplo n.º 32
0
def graph(args):

    print os.getpid()

    nargs = len(args)
    if nargs == 2:
        infile = args[0]
        outfile = args[1]
    else:
        raise ValueError('usage: interp.py input_file output_file.ts\n')

    input_rate = 19.2e6
    IF_freq = 5.75e6

    tb = gr.top_block()

    # Read from input file
    srcf = blocks.file_source(gr.sizeof_short, infile)

    # Convert interleaved shorts (I,Q,I,Q) to complex
    is2c = blocks.interleaved_short_to_complex()

    # 1/2 as wide because we're designing lp filter
    symbol_rate = atsc.ATSC_SYMBOL_RATE / 2.
    NTAPS = 279
    tt = filter.firdes.root_raised_cosine(1.0, input_rate / 3, symbol_rate,
                                          .1152, NTAPS)
    rrc = filter.fir_filter_ccf(1, tt)

    # Interpolate Filter our 6MHz wide signal centered at 0
    ilp_coeffs = filter.firdes.low_pass(1, input_rate, 3.2e6, .5e6,
                                        filter.firdes.WIN_HAMMING)
    ilp = filter.interp_fir_filter_ccf(3, ilp_coeffs)

    # Move the center frequency to 5.75MHz ( this won't be needed soon )
    duc_coeffs = filter.firdes.low_pass(1, 19.2e6, 9e6, 1e6,
                                        filter.firdes.WIN_HAMMING)
    duc = filter.freq_xlating_fir_filter_ccf(1, duc_coeffs, -5.75e6, 19.2e6)

    # fpll input is float
    c2f = blocks.complex_to_float()

    # Phase locked loop
    fpll = atsc.fpll()

    # Clean fpll output
    lp_coeffs2 = filter.firdes.low_pass(1.0, input_rate, 5.75e6, 120e3,
                                        filter.firdes.WIN_HAMMING)
    lp_filter = filter.fir_filter_fff(1, lp_coeffs2)

    # Remove pilot ( at DC now )
    iir = filter.single_pole_iir_filter_ff(1e-5)
    remove_dc = blocks.sub_ff()

    # Bit Timing Loop, Field Sync Checker and Equalizer
    btl = atsc.bit_timing_loop()
    fsc = atsc.fs_checker()
    eq = atsc.equalizer()
    fsd = atsc.field_sync_demux()

    # Viterbi
    viterbi = atsc.viterbi_decoder()
    deinter = atsc.deinterleaver()
    rs_dec = atsc.rs_decoder()
    derand = atsc.derandomizer()
    depad = atsc.depad()

    # Write to output file
    outf = blocks.file_sink(gr.sizeof_char, outfile)

    # Connect it all together
    tb.connect(srcf, is2c, rrc, ilp, duc, c2f, fpll, lp_filter)
    tb.connect(lp_filter, iir)
    tb.connect(lp_filter, (remove_dc, 0))
    tb.connect(iir, (remove_dc, 1))
    tb.connect(remove_dc, btl)
    tb.connect((btl, 0), (fsc, 0), (eq, 0), (fsd, 0))
    tb.connect((btl, 1), (fsc, 1), (eq, 1), (fsd, 1))
    tb.connect(fsd, viterbi, deinter, rs_dec, derand, depad, outf)

    tb.run()
    def __init__(self):
        gr.top_block.__init__(self, "rothr_playback_sigmf")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("rothr_playback_sigmf")
        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", "rothr_playback_sigmf")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.target_freq = target_freq = 4.575e6
        self.rec_center = rec_center = 9.25e6
        self.tune_offset = tune_offset = target_freq - rec_center
        self.trig_lvl = trig_lvl = 0
        self.throttle_rate = throttle_rate = 1.0
        self.samp_rate = samp_rate = 12.5e6
        self.decim = decim = 10
        self.cutoff = cutoff = 25e3

        ##################################################
        # Blocks
        ##################################################
        self._trig_lvl_tool_bar = Qt.QToolBar(self)
        self._trig_lvl_tool_bar.addWidget(Qt.QLabel("trig_lvl"+": "))
        self._trig_lvl_line_edit = Qt.QLineEdit(str(self.trig_lvl))
        self._trig_lvl_tool_bar.addWidget(self._trig_lvl_line_edit)
        self._trig_lvl_line_edit.returnPressed.connect(
        	lambda: self.set_trig_lvl(eng_notation.str_to_num(str(self._trig_lvl_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._trig_lvl_tool_bar, 7, 6, 1, 2)
        for r in range(7, 8):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(6, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._throttle_rate_tool_bar = Qt.QToolBar(self)
        self._throttle_rate_tool_bar.addWidget(Qt.QLabel("throttle_rate"+": "))
        self._throttle_rate_line_edit = Qt.QLineEdit(str(self.throttle_rate))
        self._throttle_rate_tool_bar.addWidget(self._throttle_rate_line_edit)
        self._throttle_rate_line_edit.returnPressed.connect(
        	lambda: self.set_throttle_rate(eng_notation.str_to_num(str(self._throttle_rate_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._throttle_rate_tool_bar, 4, 6, 1, 2)
        for r in range(4, 5):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(6, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._target_freq_tool_bar = Qt.QToolBar(self)
        self._target_freq_tool_bar.addWidget(Qt.QLabel("target_freq"+": "))
        self._target_freq_line_edit = Qt.QLineEdit(str(self.target_freq))
        self._target_freq_tool_bar.addWidget(self._target_freq_line_edit)
        self._target_freq_line_edit.returnPressed.connect(
        	lambda: self.set_target_freq(eng_notation.str_to_num(str(self._target_freq_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._target_freq_tool_bar, 5, 4, 1, 2)
        for r in range(5, 6):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 6):
            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, 4, 4, 1, 2)
        for r in range(4, 5):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 6):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._cutoff_tool_bar = Qt.QToolBar(self)
        self._cutoff_tool_bar.addWidget(Qt.QLabel("cutoff"+": "))
        self._cutoff_line_edit = Qt.QLineEdit(str(self.cutoff))
        self._cutoff_tool_bar.addWidget(self._cutoff_line_edit)
        self._cutoff_line_edit.returnPressed.connect(
        	lambda: self.set_cutoff(eng_notation.str_to_num(str(self._cutoff_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._cutoff_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.sigmf_source_0 = gr_sigmf.source('/captures/20210516/HF-FULL_2021-05-17T00:43:31Z.sigmf-data', "ci16" + ("_le" if sys.byteorder == "little" else "_be"), True)
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
                interpolation=1,
                decimation=decim,
                taps=None,
                fractional_bw=None,
        )
        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(
        	1024, #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.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(-140, 10)

        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, 8, 0, 4, 4)
        for r in range(8, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	1024, #size
        	samp_rate/decim/decim, #samp_rate
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.010)
        self.qtgui_time_sink_x_0.set_y_axis(-30, 20)

        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, trig_lvl, 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 False:
          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, 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_freq_sink_x_0_0 = qtgui.freq_sink_c(
        	2048, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate/decim, #bw
        	"", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_0_0.set_update_time(0.010)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-80, 10)
        self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)

        if not False:
          self.qtgui_freq_sink_x_0_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
          self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True)

        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(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, 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.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate/decim, cutoff, 1e3, firdes.WIN_HAMMING, 6.76))
        self.fosphor_qt_sink_c_0 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_0.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_0.set_frequency_range(target_freq, samp_rate / decim)
        self._fosphor_qt_sink_c_0_win = sip.wrapinstance(self.fosphor_qt_sink_c_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._fosphor_qt_sink_c_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.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate*throttle_rate,True)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_xx_0 = blocks.multiply_const_cc(1.0 / 65536.0)
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(True, False)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -1*tune_offset, 1, 0)
        self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-1, 1.0, 1.0)
        self.analog_agc2_xx_0.set_max_gain(65536)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc2_xx_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.analog_agc2_xx_0, 0), (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.analog_agc2_xx_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_nlog10_ff_0, 0))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_multiply_const_xx_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.low_pass_filter_0, 0), (self.qtgui_freq_sink_x_0_0, 1))
        self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc2_xx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.fosphor_qt_sink_c_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.sigmf_source_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
Exemplo n.º 34
0
    def __init__(self, filenames, dev_addrs,
                 onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps):
        gr.top_block.__init__(self)

        if mix:
            raise NotImplementedError("TODO: Hilbert remix mode not implemented.")

        uhd_sinks = [
            uhd.usrp_sink(",".join(
                [addr, "send_frame_size=32768,num_send_frames=128"]),
                          uhd.stream_args(
                              cpu_format="fc32",
                              otwformat="sc8",
                              channels=[0]))
            for addr in dev_addrs]

        for sink in uhd_sinks:
            sink.set_clock_rate(fs*2, uhd.ALL_MBOARDS)
            sink.set_samp_rate(fs)
            sink.set_center_freq(fc, 0)
            sink.set_gain(gain, 0)
            # TODO Use offset tuning?
            if sync_pps:
                sink.set_clock_source("external") # 10 MHz
                sink.set_time_source("external") # PPS

        if unint:
            if noise or onebit or not iq:
                raise NotImplementedError("TODO: RX channel-interleaved mode only "
                                          "supported for noiseless 8-bit complex.")
            
            BLOCK_N=16*1024*1024
            demux = blocks.vector_to_streams(2, len(uhd_sinks))
            self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False),
                         blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N),
                         demux)
            for ix, sink in enumerate(uhd_sinks):
                self.connect((demux, ix),
                             blocks.vector_to_stream(1, 2),
                             blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
                             blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125)
#                             blocks.vector_to_stream(8, 16*1024),
                             sink)

        else:
            file_srcs = [blocks.file_source(gr.sizeof_char*1, f, False)
                         for f in filenames]

            for src, sink in zip(file_srcs, uhd_sinks):

                if iq:
                    node = blocks.multiply_const_cc(1.0/1024)
                    if onebit:
                        self.connect(src,
                                     blocks.unpack_k_bits_bb(8), 
                                     blocks.char_to_short(), # [0, 1] -> [0, 256]
                                     blocks.add_const_ss(-128), # [-128, +128],
                                     blocks.interleaved_short_to_complex(), # [ -128.0, +128.0]
                                     node) # [-0.125, +0.125]
                    else:
                        self.connect(src, # [-128..127]
                                     blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
                                     node) # [-0.125, +0.125)
                    
                else:
                    node = blocks.float_to_complex(1)
                    if onebit:
                        self.connect(src,
                                     blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125]
                                     blocks.char_to_float(vlen=1, scale=4),
                                     blocks.add_const_vff((-0.125, )),
                                     node)
                    else:
                        self.connect(src, # [-128..127] -> [-0.125, +0.125)
                                     blocks.char_to_float(vlen=1, scale=1024),
                                     node)
                        
                if noise:
                    combiner = blocks.add_vcc(1)
                    self.connect(node,
                                 combiner,
                                 sink)
                    self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192),
                                 (combiner, 1))
                else:
                    self.connect(node,
                                 sink)

        print "Setting clocks..."
        if sync_pps:
            time.sleep(1.1) # Ensure there's been an edge.  TODO: necessary?
            last_pps_time = uhd_sinks[0].get_time_last_pps()
            while last_pps_time == uhd_sinks[0].get_time_last_pps():
                time.sleep(0.1)
            print "Got edge"
            [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks]
            time.sleep(1.0) # Wait for edge to set the clocks
        else:
            # No external PPS/10 MHz.  Just set each clock and accept some skew.
            t = time.time()
            [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks]
            if len(uhd_sinks) > 1:
                print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % (
                    (time.time()-t) * 1000)

        t_start = uhd.time_spec(time.time() + 1.5)
        [sink.set_start_time(t_start) for sink in uhd_sinks]
        print "ready"
Exemplo n.º 35
0
    def __init__(self):
        gr.top_block.__init__(self, "Hf Spectrum Simple")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Hf Spectrum Simple")
        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", "hf_spectrum_simple")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 25e6
        self.rx_freq = rx_freq = 12.5e6
        self.offset = offset = 0

        ##################################################
        # Blocks
        ##################################################
        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, 8, 0, 1, 1)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        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, 8, 1, 1, 1)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._offset_tool_bar = Qt.QToolBar(self)
        self._offset_tool_bar.addWidget(Qt.QLabel('offset' + ": "))
        self._offset_line_edit = Qt.QLineEdit(str(self.offset))
        self._offset_tool_bar.addWidget(self._offset_line_edit)
        self._offset_line_edit.returnPressed.connect(lambda: self.set_offset(
            eng_notation.str_to_num(
                str(self._offset_line_edit.text().toAscii()))))
        self.top_grid_layout.addWidget(self._offset_tool_bar, 8, 2, 1, 1)
        for r in range(8, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(2, 3):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.uhd_usrp_source_1 = uhd.usrp_source(
            ",".join(("addr=192.168.10.2", "")),
            uhd.stream_args(
                cpu_format="sc16",
                otw_format='sc16',
                channels=range(1),
            ),
        )
        self.uhd_usrp_source_1.set_samp_rate(samp_rate)
        self.uhd_usrp_source_1.set_time_now(uhd.time_spec(time.time()),
                                            uhd.ALL_MBOARDS)
        self.uhd_usrp_source_1.set_center_freq(
            uhd.tune_request(rx_freq, samp_rate / 2), 0)
        self.uhd_usrp_source_1.set_gain(0, 0)
        self.uhd_usrp_source_1.set_antenna('RX2', 0)
        self.uhd_usrp_source_1.set_auto_dc_offset(True, 0)
        self.uhd_usrp_source_1.set_auto_iq_balance(True, 0)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
            2048,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            rx_freq,  #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(-140, 10)

        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
            rx_freq,  #fc
            samp_rate,  #bw
            "",  #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(-140, 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(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_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.fosphor_qt_sink_c_1 = fosphor.qt_sink_c()
        self.fosphor_qt_sink_c_1.set_fft_window(window.WIN_BLACKMAN_hARRIS)
        self.fosphor_qt_sink_c_1.set_frequency_range(0, samp_rate)
        self._fosphor_qt_sink_c_1_win = sip.wrapinstance(
            self.fosphor_qt_sink_c_1.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._fosphor_qt_sink_c_1_win, 0, 4, 9,
                                       4)
        for r in range(0, 9):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(
            (1 / 65536.0, ))
        self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex(
            True, False)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1 * offset, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_interleaved_short_to_complex_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.fosphor_qt_sink_c_1, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.uhd_usrp_source_1, 0),
                     (self.blocks_interleaved_short_to_complex_0, 0))