def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit='Units',
        	minval=-100,
        	maxval=100,
        	factor=1.0,
        	decimal_places=10,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=False,
        	avg_alpha=None,
        	label='Number Plot',
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_float_to_char_1 = blocks.float_to_char(1, 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=1000,
        	bits_per_symbol=8,
        )
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 10000, 1, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.125, 0)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_float_to_char_1, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blks2_error_rate_0, 0))
        self.connect((self.blocks_float_to_char_1, 0), (self.blks2_error_rate_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_float_to_char_0, 0))
Esempio n. 2
0
    def test_001_t (self):

        # Setup parameters of the System
        fsm = fsm_args["awgn1o2_16"]
        os = numpy.array(fsm[4], dtype=int) 
        data = numpy.array([-5,-5,-5,-5,5,5,-5,5,5,-5])
        expected_data = numpy.array([0,0,0,0,1,1,0,1,1,0])
        print data

        data_src = blocks.vector_source_f(map(float, data))

        # Set up TX
        src_head = blocks.head(gr.sizeof_float*1, 10)
        
        shuffle = numpy.array([0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,], dtype=int)
        # Setup RX
        max_log_map_cel = celec.max_log_map_f(2, 4, 10, 0, -1, shuffle, os)
        conv = blocks.float_to_char()
        rx_sink = blocks.vector_sink_f(1)


        self.tb.connect(data_src, src_head, max_log_map_cel, rx_sink)

        # set up fg
        self.tb.run ()

        print rx_sink.data()
Esempio n. 3
0
    def __init__(self):
        gr.top_block.__init__(self, "METEOR-M2 receiver")

        ##################################################
        # Variables
        ##################################################
        self.symb_rate = symb_rate = 72e3
        self.samp_rate = samp_rate = 960e3
        self.decimation = decimation = 4
        self.samp_per_sym = samp_per_sym = samp_rate/decimation/symb_rate
        self.clock_alpha = clock_alpha = 30e-3
        self.bitstream_name = bitstream_name = os.getcwd() + "/Data/meteor_LRPT_" + datetime.now().strftime("%d%m%Y_%H%M") + ".s"
        self.Tuning_offset = Tuning_offset = 300e3
        self.LO_freq = LO_freq = 137.903e6
        self.BPF_width = BPF_width = 140e3

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(LO_freq-Tuning_offset, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(2, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(2, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(42, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(10, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine(
        	1, samp_rate/decimation, symb_rate, 0.3, 361))
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(decimation, (firdes.low_pass(1,samp_rate,BPF_width/2,20e3)), Tuning_offset, samp_rate)
        (self.freq_xlating_fir_filter_xxx_0).set_processor_affinity([0])
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(1e-3, 4)
        (self.digital_costas_loop_cc_0).set_processor_affinity([1])
        self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf(digital.constellation_calcdist(([-1-1j, -1+1j, 1+1j, 1-1j]), ([0, 1, 3, 2]), 4, 1).base())
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(samp_per_sym*(1+0.0), clock_alpha**2/4.0, 0.5, clock_alpha, 0.005)
        (self.digital_clock_recovery_mm_xx_0).set_processor_affinity([2])
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, bitstream_name, False)
        self.blocks_file_sink_0_0.set_unbuffered(False)
        self.analog_rail_ff_0 = analog.rail_ff(-1, 1)
        self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0)
        self.analog_agc_xx_0.set_max_gain(4000)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0))
        self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_constellation_soft_decoder_cf_1, 0))
        self.connect((self.digital_constellation_soft_decoder_cf_1, 0), (self.analog_rail_ff_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_costas_loop_cc_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
    def __init__(self):
        gr.top_block.__init__(self, "Many Rate Changing")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.random_source_x_0 = gr.vector_source_b(
            map(int, numpy.random.randint(0, 256, 1000)), True)
        self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(
            2, gr.GR_LSB_FIRST)
        self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(
            2, gr.GR_MSB_FIRST)
        self.gr_null_sink_0_2 = gr.null_sink(gr.sizeof_char * 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_char_to_float_0 = blocks.char_to_float(1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_char_to_float_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_unpacked_to_packed_xx_0, 0),
                     (self.blocks_char_to_float_0, 0))
        self.connect((self.random_source_x_0, 0),
                     (self.gr_unpacked_to_packed_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.gr_null_sink_0_2, 0))
Esempio n. 5
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Wav To Raw Iq")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Blocks
        ##################################################
        self.test_wav = blocks.wavfile_source("original.wav", False)
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
                interpolation=2000000,
                decimation=44100,
                taps=None,
                fractional_bw=None,
        )
        self.blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_float*1, 2)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "sample.raw", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.test_wav, 1), (self.blocks_streams_to_stream_0, 1))
        self.connect((self.blocks_streams_to_stream_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.test_wav, 0), (self.blocks_streams_to_stream_0, 0))
Esempio n. 6
0
    def __init__(self,samp_per_sym=1):
        valid_mod_block.__init__(self)

        # Blocks
        self.b_to_f = blocks.char_to_float(1, 1)
        self.interp_filter = filter.interp_fir_filter_fff(samp_per_sym, (np.ones(samp_per_sym)))
        self.f_to_c = blocks.float_to_complex(1)
        
        self.c_to_r = blocks.complex_to_real(1)
        self.decim_filter = filter.fir_filter_fff(samp_per_sym, (np.ones(samp_per_sym)))
        self.divide_f = blocks.multiply_const_vff((1.0/samp_per_sym, ))
        self.f_to_b = blocks.float_to_char(1,1)
        
        # Connections
        self.connect((self,0),self.b_to_f)
        self.connect(self.b_to_f,(self,2))
        self.connect(self.b_to_f,self.interp_filter)
        self.connect(self.interp_filter,self.f_to_c)
        self.connect(self.f_to_c,(self,1))

        self.connect((self,1),self.c_to_r)
        self.connect(self.c_to_r,self.decim_filter)
        self.connect(self.decim_filter,self.divide_f)
        self.connect(self.divide_f,(self,3))
        self.connect(self.divide_f,self.f_to_b)        
        self.connect(self.f_to_b,(self,0))
Esempio n. 7
0
    def __init__(self, freq_sample_delay_samps, freq_samps_to_avg,
                 mag_samps_to_avg, thresh):
        gr.hier_block2.__init__(
            self, "Sample and Hold Detector",
            gr.io_signaturev(2, 2, [gr.sizeof_float * 1, gr.sizeof_float * 1]),
            gr.io_signaturev(4, 4, [
                gr.sizeof_float * 1, gr.sizeof_float * 1, gr.sizeof_float * 1,
                gr.sizeof_float * 1
            ]))
        '''
        Constructor
        
        @param freq_sample_delay_samps - 
        @param freq_samps_to_avg - 
        @param mag_samps_to_avg - 
        @param thresh - 
        
        '''

        ##################################################
        # Parameters
        ##################################################
        self.freq_sample_delay_samps = freq_sample_delay_samps
        self.freq_samps_to_avg = freq_samps_to_avg
        self.mag_samps_to_avg = mag_samps_to_avg
        self.thresh = thresh

        ##################################################
        # Blocks
        ##################################################
        self.edge_detector = timing_utils.edge_detector_bb(
            timing_utils.RISING_EDGE)
        self.threshold = blocks.threshold_ff(thresh / 4.0, thresh, 0)
        self.samp_hold = blocks.sample_and_hold_ff()
        self.mag_avg = blocks.moving_average_ff(int(mag_samps_to_avg),
                                                1.0 / (mag_samps_to_avg), 4000)
        self.freq_avg = blocks.moving_average_ff(int(freq_samps_to_avg),
                                                 1.0 / (freq_samps_to_avg),
                                                 4000)
        self.f2c = blocks.float_to_char(1, 1)
        self.delay = blocks.delay(
            gr.sizeof_float * 1,
            int(freq_samps_to_avg - mag_samps_to_avg +
                freq_sample_delay_samps))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.delay, 0), (self.mag_avg, 0))
        self.connect((self.f2c, 0), (self.edge_detector, 0))
        self.connect((self.freq_avg, 0), (self.samp_hold, 0))
        self.connect((self.freq_avg, 0), (self, 1))
        self.connect((self.mag_avg, 0), (self.threshold, 0))
        self.connect((self.mag_avg, 0), (self, 3))
        self.connect((self.samp_hold, 0), (self, 0))
        self.connect((self.threshold, 0), (self.f2c, 0))
        self.connect((self.threshold, 0), (self, 2))
        self.connect((self, 0), (self.delay, 0))
        self.connect((self, 1), (self.freq_avg, 0))
        self.connect((self.edge_detector, 0), (self.samp_hold, 1))
Esempio n. 8
0
	def __init__(self):
		gr.top_block.__init__(self, "Many Rate Changing")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.random_source_x_0 = gr.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True)
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(2, gr.GR_LSB_FIRST)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST)
		self.gr_null_sink_0_2 = gr.null_sink(gr.sizeof_char*1)
		self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, 3, 20, 0)
		self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
		self.blocks_char_to_float_0 = blocks.char_to_float(1, 1)

		##################################################
		# Connections
		##################################################
		self.connect((self.blocks_char_to_float_0, 0), (self.blocks_keep_m_in_n_0, 0))
		self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_float_to_char_0, 0))
		self.connect((self.blocks_float_to_char_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.blocks_char_to_float_0, 0))
		self.connect((self.random_source_x_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_null_sink_0_2, 0))
Esempio n. 9
0
	def __init__(self, esno=0, samp_rate=3200000):
		gr.hier_block2.__init__(
			self, "FECTEST",
			gr.io_signature(1, 1, gr.sizeof_char*1),
			gr.io_signature(2, 2, gr.sizeof_char*1))
                
		##################################################
		# Parameters
		##################################################
		self.esno = esno
		self.samp_rate = samp_rate
		
		##################################################
		# Blocks
		##################################################
		self.gr_unpacked_to_packed_xx_0_0 = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
		self.gr_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
                self.char_to_float = blocks.char_to_float()
                self.float_to_char = blocks.float_to_char()
		self.gr_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate)
		self.gaussnoise_ff_0 = fec.gaussnoise_ff(esno)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_unpacked_to_packed_xx_0_0, 0), (self, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self, 1))
		self.connect((self.gr_throttle_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gaussnoise_ff_0, 0), (self.float_to_char, 0))
                self.connect((self.float_to_char, 0), (self.gr_unpacked_to_packed_xx_0_0, 0))
		self.connect(self, (self.gr_throttle_0, 0))
                self.connect((self.gr_throttle_0, 0), (self.char_to_float, 0))
                self.connect((self.char_to_float, 0), (self.gaussnoise_ff_0, 0))
Esempio n. 10
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")
        self.restoreGeometry(
            self.settings.value("geometry", type=QtCore.QByteArray))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_float * 1,
            '/home/bencarlisle15/UMDCTF-2020-Challenges/Misc/CarrierCrisis/prod/message',
            False)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_char * 1,
            '/home/bencarlisle15/UMDCTF-2020-Challenges/Misc/CarrierCrisis/dev/flag2.txt',
            False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_divide_xx_0 = blocks.divide_ff(1)
        self.analog_sig_source_x_0 = analog.sig_source_f(
            samp_rate, analog.GR_COS_WAVE, 751000000, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_divide_xx_0, 1))
        self.connect((self.blocks_divide_xx_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_divide_xx_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_file_sink_0, 0))
Esempio n. 11
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Transmisor")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 44100
        self.fcmod = fcmod = 0
        self.fc = fc = 0

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        	device_addr="",
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0.set_time_source("gpsdo", 0)
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(fc, 0)
        self.uhd_usrp_sink_0.set_gain(0, 0)
        self.digital_psk_mod_0 = digital.psk.psk_mod(
          constellation_points=4,
          mod_code="gray",
          differential=True,
          samples_per_symbol=2,
          excess_bw=0.35,
          verbose=False,
          log=False,
          )
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((127, ))
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder(
        		samples_per_symbol=2,
        		bits_per_symbol=1,
        		access_code="",
        		pad_for_usrp=False,
        	),
        	payload_length=0,
        )
        self.audio_source_0 = audio.source(samp_rate, "", True)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, fcmod, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blks2_packet_encoder_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blks2_packet_encoder_0, 0), (self.digital_psk_mod_0, 0))
        self.connect((self.digital_psk_mod_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.audio_source_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.uhd_usrp_sink_0, 0))
Esempio n. 12
0
 def test_float_to_char_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Esempio n. 13
0
 def test_float_to_char_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char(1, 5)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Esempio n. 14
0
 def test_float_to_char_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char(1, 5)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Esempio n. 15
0
 def test_float_to_char_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Esempio n. 16
0
    def __rebuild(self):
        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(
                itemsize=output_length * gr.sizeof_float, nstreams=2)

        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(
            math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)

        self.__gate = blocks.copy(gr.sizeof_gr_complex)
        self.__gate.set_enabled(not self.__paused)

        self.__fft_sink = MessageDistributorSink(
            itemsize=output_length * gr.sizeof_char,
            context=self.__context,
            migrate=self.__fft_sink,
            notify=self.__update_interested)
        self.__overlapper = _OverlapGimmick(size=input_length,
                                            factor=overlap_factor,
                                            itemsize=self.__itemsize)

        # Adjusts units so displayed level is independent of resolution and sample rate. Also throw in the packing offset
        compensation = to_dB(input_length / sample_rate) + self.__power_offset
        # TODO: Consider not using the logpwrfft block

        self.__logpwrfft = logpwrfft.logpwrfft_c(
            sample_rate=sample_rate * overlap_factor,
            fft_size=input_length,
            ref_scale=10.0**(-compensation / 20.0) *
            2,  # not actually using this as a reference scale value but avoiding needing to use a separate add operation to apply the unit change -- this expression is the inverse of what logpwrfft does internally
            frame_rate=self.__frame_rate,
            avg_alpha=1.0,
            average=False)
        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(
            vlen=self.__freq_resolution, scale=1.0)

        self.__scope_sink = MessageDistributorSink(
            itemsize=self.__time_length * gr.sizeof_gr_complex,
            context=self.__context,
            migrate=self.__scope_sink,
            notify=self.__update_interested)
        self.__scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)
Esempio n. 17
0
    def __init__(self,
                 fft_size=256,
                 power_max=0.0,
                 power_min=-100.0,
                 port=6663,
                 frame_rate=5,
                 sample_rate=1e4,
                 ip_address="srvwww.cortexlab.fr"):
        gr.hier_block2.__init__(
            self,
            "fft web",
            gr.io_signature(1, 1, gr.sizeof_float * fft_size),
            gr.io_signature(0, 0, 0),
        )

        ##################################################
        # Parameters
        ##################################################
        self.fft_size = fft_size
        self.power_max = power_max
        self.power_min = power_min
        self.port = port
        self.frame_rate = frame_rate
        self.sample_rate = sample_rate
        self.ip_address = ip_address

        ##################################################
        # Blocks
        ##################################################
        self.digital_simple_framer_0 = digital.simple_framer(fft_size)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(
            gr.sizeof_float * 1, fft_size)
        self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_char * 1,
                                                 ip_address, port, 1472, True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (-255.0 / (power_min - power_max), ))
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff(
            ((128.0 * power_max + 127.0 * power_min) /
             (power_min - power_max), ))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.digital_simple_framer_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.digital_simple_framer_0, 0),
                     (self.blocks_udp_sink_0, 0))
        self.connect((self, 0), (self.blocks_vector_to_stream_0, 0))
Esempio n. 18
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.4e6

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                              "")
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(891e6, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(1, 0)
        self.rtlsdr_source_0.set_gain_mode(0, 0)
        self.rtlsdr_source_0.set_gain(50, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        try:
            self.rtlsdr_source_0.get_sample_rates().start()
        except RuntimeError:
            print "Source has no sample rates (wrong device arguments?)."
            sys.exit(1)

        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
            sample_rate=samp_rate,
            fft_size=1024,
            ref_scale=2,
            frame_rate=60,
            avg_alpha=1.0,
            average=True,
        )
        self.blocks_float_to_char_0 = blocks.float_to_char(1024, 1)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1024,
                                                   "gsm_power.txt", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rtlsdr_source_0, 0), (self.logpwrfft_x_0, 0))
        self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_file_sink_0, 0))
Esempio n. 19
0
 def __rebuild(self):
     if self.__signal_type.is_analytic():
         input_length = self.__freq_resolution
         output_length = self.__freq_resolution
         self.__after_fft = None
     else:
         # use vector_to_streams to cut the output in half and discard the redundant part
         input_length = self.__freq_resolution * 2
         output_length = self.__freq_resolution
         self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
     
     sample_rate = self.__signal_type.get_sample_rate()
     overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
     # sanity limit -- OverlapGimmick is not free
     overlap_factor = min(16, overlap_factor)
     
     self.__gate = blocks.copy(gr.sizeof_gr_complex)
     self.__gate.set_enabled(not self.__paused)
     
     self.__fft_sink = MessageDistributorSink(
         itemsize=output_length * gr.sizeof_char,
         context=self.__context,
         migrate=self.__fft_sink,
         notify=self.__update_interested)
     self.__overlapper = _OverlapGimmick(
         size=input_length,
         factor=overlap_factor,
         itemsize=self.__itemsize)
     
     # Adjusts units so displayed level is independent of resolution and sample rate. Also throw in the packing offset
     compensation = to_dB(input_length / sample_rate) + self.__power_offset
     # TODO: Consider not using the logpwrfft block
     
     self.__logpwrfft = logpwrfft.logpwrfft_c(
         sample_rate=sample_rate * overlap_factor,
         fft_size=input_length,
         ref_scale=10.0 ** (-compensation / 20.0) * 2,  # not actually using this as a reference scale value but avoiding needing to use a separate add operation to apply the unit change -- this expression is the inverse of what logpwrfft does internally
         frame_rate=self.__frame_rate,
         avg_alpha=1.0,
         average=False)
     # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
     self.__fft_converter = blocks.float_to_char(vlen=self.__freq_resolution, scale=1.0)
 
     self.__scope_sink = MessageDistributorSink(
         itemsize=self.__time_length * gr.sizeof_gr_complex,
         context=self.__context,
         migrate=self.__scope_sink,
         notify=self.__update_interested)
     self.__scope_chunker = blocks.stream_to_vector_decimator(
         item_size=gr.sizeof_gr_complex,
         sample_rate=sample_rate,
         vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
         vec_len=self.__time_length)
Esempio n. 20
0
    def __init__(self, payload_len=96, sync_seq=[complex(1,0),complex(-1,0)], threshold=.8):
        gr.hier_block2.__init__(self,
            "generic_rx_path",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signaturev(3, 3, [gr.sizeof_gr_complex*1, gr.sizeof_gr_complex*1, gr.sizeof_float*1]),
            )

        ##################################################
        # Parameters
        ##################################################
        self.threshold = threshold
        self.sync_seq = sync_seq
        self.sync_header_len = len(sync_seq)
        self.items_per_header_symbol = 1
        self.payload_len = payload_len

        ##################################################
        # Variables
        ##################################################
        self.tag_len_name = tag_len_name = "packet_len"

        ##################################################
        # Blocks
        ##################################################
        self.frame_sync_0 = dctk.frame_sync (self.sync_seq, self.threshold)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(self.sync_header_len, self.items_per_header_symbol, 0, tag_len_name, "", False, gr.sizeof_gr_complex)
        self.dctk_header_tag_generator_0 = dctk.header_tag_generator(self.sync_header_len, payload_len, tag_len_name)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, self.sync_header_len)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.blocks_delay_0, 0))
        self.connect((self, 0), (self.frame_sync_0, 0)) 
               
        self.connect((self.blocks_delay_0, 0), (self.digital_header_payload_demux_0, 0))
        self.connect((self.frame_sync_0, 1), (self.digital_header_payload_demux_0, 1))
        
        self.connect((self.digital_header_payload_demux_0, 0), (self.blocks_complex_to_float_0, 0))
        self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.dctk_header_tag_generator_0, 0))
        
        self.connect((self.frame_sync_0, 0), (self, 2))
        self.connect((self.digital_header_payload_demux_0, 1), (self, 1))
        self.connect((self.digital_header_payload_demux_0, 0), (self, 0))
        
        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.dctk_header_tag_generator_0, "header_data", self.digital_header_payload_demux_0, "header_data")
Esempio n. 21
0
 def test_002_t(self):
     # set up fg
     src_data = (0, 0, 1, 0, 0, 1.0, 1, 2, 1, 1, 0, 0, 1, 0, 0, 0, 0, 3, 0,
                 0, 0, 0, 1, 0, 0)
     src = blocks.vector_source_f(src_data)
     f2c = blocks.float_to_char()
     s2v = blocks.stream_to_vector(gr.sizeof_char, 5)
     f = open('/tmp/threshold_timestamp_test002.out', 'w')
     tts = msod_sensor.threshold_timestamp(5, gr.sizeof_char, 1, 1.5,
                                           f.fileno())
     ns = blocks.null_sink(5 * gr.sizeof_float)
     self.tb.connect(src, f2c, s2v, tts, ns)
     self.tb.run()
     f.close()
Esempio n. 22
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.4e6

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(891e6, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(1, 0)
        self.rtlsdr_source_0.set_gain_mode(0, 0)
        self.rtlsdr_source_0.set_gain(50, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        try:
            self.rtlsdr_source_0.get_sample_rates().start()
        except RuntimeError:
            print "Source has no sample rates (wrong device arguments?)."
            sys.exit(1)
          
        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
        	sample_rate=samp_rate,
        	fft_size=1024,
        	ref_scale=2,
        	frame_rate=30,
        	avg_alpha=1.0,
        	average=False,
        )
        self.blocks_float_to_char_0 = blocks.float_to_char(1024, 1)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1024, "gsm_power.txt", False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rtlsdr_source_0, 0), (self.logpwrfft_x_0, 0))
        self.connect((self.logpwrfft_x_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0))
Esempio n. 23
0
    def __init__(self):
        gr.top_block.__init__(self, "Ask Rx Top Raspi")

        ##################################################
        # Variables
        ##################################################
        self.sound_card_sample_rate = sound_card_sample_rate = 44000
        self.samples_per_symbol = samples_per_symbol = 19
        self.symbol_rate = symbol_rate = sound_card_sample_rate / samples_per_symbol
        self.bits_per_symbol = bits_per_symbol = 1

        self.variable_rrc_filter_taps = variable_rrc_filter_taps = firdes.root_raised_cosine(
            1, sound_card_sample_rate, symbol_rate, 0.5, 70)

        self.bit_rate = bit_rate = symbol_rate / bits_per_symbol

        ##################################################
        # Blocks
        ##################################################
        self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_fff(
            samples_per_symbol, 0.5, (variable_rrc_filter_taps), 32, 0, 1.5, 1)
        self.digital_hdlc_deframer_bp_0 = digital.hdlc_deframer_bp(32, 500)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 sound_card_sample_rate, True)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(-0.01, 0.01, 0)
        self.blocks_tagged_file_sink_0 = blocks.tagged_file_sink(
            gr.sizeof_char * 1, bit_rate)
        self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(
            blocks.byte_t, 'burst')
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.audio_source_0 = audio.source(sound_card_sample_rate, '', True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.digital_hdlc_deframer_bp_0, 'out'),
                         (self.blocks_pdu_to_tagged_stream_0, 'pdus'))
        self.connect((self.audio_source_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.digital_hdlc_deframer_bp_0, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_0, 0),
                     (self.blocks_tagged_file_sink_0, 0))
        self.connect((self.blocks_threshold_ff_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.digital_pfb_clock_sync_xxx_0, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0),
                     (self.blocks_threshold_ff_0, 0))
Esempio n. 24
0
    def __init__(self, f_in, f_out, base_freq, freq_offset, samp_rate, bit_rate):
        gr.top_block.__init__(self, "Demod Fsk Gen")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate
        self.bit_rate = bit_rate
        self.samp_per_sym = samp_per_sym = int(samp_rate/bit_rate)
        self.fxff_decimation = fxff_decimation = 1
        self.fsk_deviation_hz = fsk_deviation_hz = 160000
        self.freq_offset = freq_offset
        self.base_freq = base_freq
        if not f_out:
            f_out = f_in + '.demod'

        ##################################################
        # Blocks
        ##################################################
        self.low_pass_filter_0 = filter.fir_filter_fff(1, firdes.low_pass(
        	1, samp_rate/fxff_decimation, bit_rate*0.8, bit_rate*.2, firdes.WIN_BLACKMAN, 6.76))
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(fxff_decimation, (firdes.low_pass(1, samp_rate, bit_rate*1.1, bit_rate*.4,  firdes.WIN_BLACKMAN, 6.76)), freq_offset, samp_rate)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate/32,True)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, f_in, False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, f_out, False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_float*1)
        self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(samp_rate/(2*math.pi*fsk_deviation_hz/8.0)/fxff_decimation)
        self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(30, 0.3, 0, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_deinterleave_0, 0))
        self.connect((self.blocks_deinterleave_0, 0), (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_deinterleave_0, 1), (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_pwr_squelch_xx_0, 0))
        self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_quadrature_demod_cf_0, 0))
Esempio n. 25
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.5e+06
        self.decim = decim = 3
        self.baud = baud = 40000
        self.samp_per_sym = samp_per_sym = float(samp_rate/decim)/baud
        self.clock_alpha = clock_alpha = 0.0037

        ##################################################
        # Blocks
        ##################################################
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(decim, (firdes.complex_band_pass(1, samp_rate, -samp_rate/(2*decim), samp_rate/(2*decim), 10000)), 1.4e6, samp_rate)
        self.digital_pfb_clock_sync_xxx_0_0 = digital.pfb_clock_sync_ccf(samp_per_sym, 0.1, (firdes.root_raised_cosine(32, 32, 1.0/float(samp_per_sym), 0.35, 11*int(samp_per_sym)*32)), 32, 16, 0.1, 1)
        self.digital_costas_loop_cc_0_0 = digital.costas_loop_cc(50e-3, 4, False)
        self.blocks_wavfile_source_0 = blocks.wavfile_source('/Volumes/My Passport/Basebands/Satellites/GOES-16/gqrx_20170124_060211_1694100000_2500000_fc.wav', False)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_char*1, 16)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_char*16,
        	addr='127.0.0.1',
        	port=5000,
        	server=False,
        )
        self.analog_feedforward_agc_cc_0_0 = analog.feedforward_agc_cc(1024, 2.0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_feedforward_agc_cc_0_0, 0), (self.digital_pfb_clock_sync_xxx_0_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.blks2_tcp_sink_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_wavfile_source_0, 1), (self.blocks_float_to_complex_0, 1))
        self.connect((self.digital_costas_loop_cc_0_0, 0), (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0_0, 0), (self.digital_costas_loop_cc_0_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_feedforward_agc_cc_0_0, 0))
Esempio n. 26
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32e3

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.GetWin(),
        	title="Scope Plot",
        	sample_rate=samp_rate,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.digital_map_bb_0 = digital.map_bb(([1, -1]))
        self.blocks_vector_source_x_0 = blocks.vector_source_i((1, 1, 1, 0), True, 1, [])
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_int*1, samp_rate,True)
        self.blocks_int_to_float_0 = blocks.int_to_float(1, 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_ctrlport_monitor_performance_0 = not True or monitor("gr-perf-monitorx")
        self.blocks_char_to_float_0 = blocks.char_to_float(1, 1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_char_to_float_0, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.digital_map_bb_0, 0))    
        self.connect((self.blocks_int_to_float_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_int_to_float_0, 0))    
        self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.digital_map_bb_0, 0), (self.blocks_char_to_float_0, 0))    
Esempio n. 27
0
    def test_001_t(self):

        # Setup parameters of the System
        fsm = fsm_args["awgn1o2_16"]
        os = numpy.array(fsm[4], dtype=int)
        data = numpy.array([-5, -5, -5, -5, 5, 5, -5, 5, 5, -5])
        expected_data = numpy.array([0, 0, 0, 0, 1, 1, 0, 1, 1, 0])
        print data

        data_src = blocks.vector_source_f(map(float, data))

        # Set up TX
        src_head = blocks.head(gr.sizeof_float * 1, 10)

        shuffle = numpy.array([
            0,
            1,
            0,
            1,
            0,
            1,
            0,
            1,
            0,
            1,
            0,
            1,
            0,
            1,
            0,
            1,
        ],
                              dtype=int)
        # Setup RX
        max_log_map_cel = celec.max_log_map_f(2, 4, 10, 0, -1, shuffle, os)
        conv = blocks.float_to_char()
        rx_sink = blocks.vector_sink_f(1)

        self.tb.connect(data_src, src_head, max_log_map_cel, rx_sink)

        # set up fg
        self.tb.run()

        print rx_sink.data()
Esempio n. 28
0
    def __init__(self, item_size_in, item_size_out, onoff,ts,factor,alpha):
        gr.hier_block2.__init__(self,
            "myselector",
            gr.io_signature(1,1, item_size_in),  # Input signature
            gr.io_signature(1,1, item_size_out), # Output signature
        )

        self.item_size_in = item_size_in
        self.item_size_out = item_size_out
        self.onoff=onoff

        #print self.item_size_in, self.item_size_out, self.onoff
     
        # Define blocks and connect them

        # This is the BIG block
        self.A=cdma.timing_estimator_hier(ts,factor,alpha)
        #self.Ab=blocks.multiply_const_cc(2.0+0j)
        #self.Ab=filter.interp_fir_filter_ccc(1,ts)
        #self.A1=blocks.complex_to_mag_squared()
        #self.Ae=blocks.float_to_char()
        #self.Ae=blocks.complex_to_mag_squared()
        #self.connect(self.Ab, self.A1, self.Ae)
        #self.connect(self.Ab, self.Ae)

        # This is the SMALL block
        self.Ob=blocks.multiply_const_cc(0.0)
        self.O1=blocks.complex_to_mag_squared()
        self.Oe=blocks.float_to_char()
        #self.Oe=blocks.complex_to_mag_squared()
        self.connect(self.Ob, self.O1, self.Oe)
        #self.connect(self.Ob, self.Oe)

        # null sources/sinks for connecting inactive block
        self.nso=blocks.null_source(item_size_in)
        self.h=blocks.head(item_size_in, 0)
        self.connect(self.nso, self.h)

        self.nsi=blocks.null_sink(item_size_out)

        if self.onoff==0:
          self._connect_off()
        else:
          self._connect_on()
Esempio n. 29
0
    def make_file(self, filename, type, amplitude):

        filename = os.path.join(self.test_dir, filename)

        tb = gr.top_block()

        if type == "rf32":
            head = blocks.head(gr.sizeof_float * 1, self.samp_rate)
            source = analog.sig_source_f(self.samp_rate, analog.GR_COS_WAVE,
                                         1000, amplitude, 0)
            tb.connect(source, head)
        elif type == "ri32":
            head = blocks.head(gr.sizeof_int * 1, self.samp_rate)
            source = analog.sig_source_i(self.samp_rate, analog.GR_COS_WAVE,
                                         1000, amplitude, 0)
            tb.connect(source, head)
        elif type == "ri16":
            head = blocks.head(gr.sizeof_short * 1, self.samp_rate)
            source = analog.sig_source_s(self.samp_rate, analog.GR_COS_WAVE,
                                         1000, amplitude, 0)
            tb.connect(source, head)
        elif type == "ri8":
            head = blocks.head(gr.sizeof_char * 1, self.samp_rate)
            source = analog.sig_source_f(self.samp_rate, analog.GR_COS_WAVE,
                                         1000, amplitude, 0)
            convert = blocks.float_to_char(1, 1)
            tb.connect(source, convert)
            tb.connect(convert, head)

        else:
            head = blocks.head(gr.sizeof_gr_complex * 1, self.samp_rate)
            source = analog.sig_source_c(self.samp_rate, analog.GR_COS_WAVE,
                                         1000, amplitude, 0)
            tb.connect(source, head)

        sigmf_sink = sigmf.sink(type, filename)

        tb.connect(head, sigmf_sink)
        tb.run()
        tb.wait()

        return filename
Esempio n. 30
0
    def __init__(self,delay=0,amplitude=1):
        """Simple Modulation Block Fixture
        
        Keyword Arguments:
            delay {int} -- Delay to introduce (default: {0})
            amplitude {int} -- Amplitude Change (default: {1})
        """ 
        valid_mod_block.__init__(self)

        # Blocks
        self.b_to_f = blocks.char_to_float(1, 1)
        self.symbol_map_mult = blocks.multiply_const_vff((2.0, ))
        self.symbol_map_subtract = blocks.add_const_vff((-1.0,))
        self.delay_f = blocks.delay(gr.sizeof_float,delay=delay)
        self.f_to_c = blocks.float_to_complex(1)
        self.mult_f = blocks.multiply_const_vff((amplitude, ))
        
        self.c_to_r = blocks.complex_to_real(1)
        self.divide_f = blocks.multiply_const_vff((1.0/amplitude, ))
        self.symbol_map_add = blocks.add_const_vff((1.0,))
        self.symbol_map_divide = blocks.multiply_const_vff((1/2.0,))
        self.f_to_b = blocks.float_to_char(1,1)
        
        # Connections
        self.connect((self,0),self.b_to_f)
        self.connect(self.b_to_f,self.symbol_map_mult)
        self.connect(self.symbol_map_mult,self.symbol_map_subtract)
        self.connect(self.symbol_map_subtract,self.mult_f)
        self.connect(self.mult_f,(self,2))
        self.connect(self.mult_f,self.delay_f)
        self.connect(self.delay_f,self.f_to_c)
        self.connect(self.f_to_c,(self,1))

        self.connect((self,1),self.c_to_r)
        self.connect(self.c_to_r,self.divide_f)
        self.connect(self.divide_f,self.symbol_map_add)
        self.connect(self.symbol_map_add,self.symbol_map_divide)
        self.connect(self.symbol_map_divide,(self,3))
        self.connect(self.symbol_map_divide,self.f_to_b)        
        self.connect(self.f_to_b,(self,0))
Esempio n. 31
0
    def __init__(self, BT=4, pulse_duration=4, sps=4):
        gr.hier_block2.__init__(
            self,
            "GMSK Modulator for GSM",
            gr.io_signature(1, 1, gr.sizeof_char * 1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.BT = BT
        self.pulse_duration = pulse_duration
        self.sps = sps

        ##################################################
        # Blocks
        ##################################################
        self.digital_gmskmod_bc_0 = digital.gmskmod_bc(sps, pulse_duration, BT)
        self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(
            ([1, -1]), 1)
        self.blocks_tagged_stream_multiply_length_0 = blocks.tagged_stream_multiply_length(
            gr.sizeof_gr_complex * 1, "packet_len", sps)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.digital_gmskmod_bc_0, 0))
        self.connect((self.blocks_tagged_stream_multiply_length_0, 0),
                     (self, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.digital_diff_decoder_bb_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_gmskmod_bc_0, 0),
                     (self.blocks_tagged_stream_multiply_length_0, 0))
        self.connect((self, 0), (self.digital_diff_decoder_bb_0, 0))
    def __init__(self):
        gr.top_block.__init__(self, "Meteor QPSK LRPT")

        # get some variables in place for inputs
        #
        # Arguments:
        #   1. Full path and name of stream file (including file extension)
        #   2. Gain to be used
        #   3. Frequency offset (PPM)
        #   4. SDR Device ID from settings.yml (for RTL-SDR source block)
        #   5. Bias-T (0/1 for RTL-SDR)

        stream_name = sys.argv[1]
        gain = float(sys.argv[2])
        freq_offset = int(sys.argv[3])
        sdr_dev_id = sys.argv[4]
        bias_t_string = sys.argv[5]
        bias_t = "1"
        if not bias_t_string:
            bias_t = "0"

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_airspy = samp_rate_airspy = 1250000
        self.decim = decim = 8
        self.symb_rate = symb_rate = 72000
        self.samp_rate = samp_rate = samp_rate_airspy / decim
        self.sps = sps = (samp_rate * 1.0) / (symb_rate * 1.0)
        self.pll_alpha = pll_alpha = 0.006
        self.freq = freq = 137100000
        self.clock_alpha = clock_alpha = 0.002
        self.bitstream_name = bitstream_name = stream_name

        ##############################################################################################################################################
        # Blocks -- *** NOTE HOW THE VARIABLES ARE CARRIED IN FROM settings.yml - this has to be re-done every time you export the .py from gnuradio
        ###############################################################################################################################################

        self.rtlsdr_source_0 = osmosdr.source(args='numchan=' + str(1) + ' ' +
                                              'rtl=' + str(sdr_dev_id) +
                                              ',bias=' + bias_t + '')
        self.rtlsdr_source_0.set_sample_rate(samp_rate_airspy)
        self.rtlsdr_source_0.set_center_freq(freq, 0)
        self.rtlsdr_source_0.set_freq_corr(freq_offset, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        # determine if gain is specified or if auto-gain should be used
        if (gain == 0):
            self.rtlsdr_source_0.set_gain_mode(True, 0)
        else:
            self.rtlsdr_source_0.set_gain_mode(False, 0)
            self.rtlsdr_source_0.set_gain(gain, 0)
        self.rtlsdr_source_0.set_if_gain(0, 0)
        self.rtlsdr_source_0.set_bb_gain(0, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(1500000, 0)

        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(
            1, firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.6, 361))
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
            interpolation=1,
            decimation=decim,
            taps=None,
            fractional_bw=None,
        )
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(
            pll_alpha, 4, False)
        self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf(
            digital.constellation_calcdist(
                ([-1 - 1j, -1 + 1j, 1 + 1j, 1 - 1j]), ([0, 1, 3, 2]), 4,
                1).base())
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(
            sps, clock_alpha**2 / 4.0, 0.5, clock_alpha, 0.005)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                   bitstream_name, False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.analog_rail_ff_0 = analog.rail_ff(-1, 1)
        self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0)
        self.analog_agc_xx_0.set_max_gain(4000)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.analog_rail_ff_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_constellation_soft_decoder_cf_1, 0))
        self.connect((self.digital_constellation_soft_decoder_cf_1, 0),
                     (self.analog_rail_ff_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.analog_agc_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.digital_costas_loop_cc_0, 0))
        self.connect((self.rtlsdr_source_0, 0),
                     (self.rational_resampler_xxx_0, 0))
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "usage: %prog [options] center_freq band_width"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device 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 [default=%default]")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("", "--meas-interval", type="eng_float",
                          default=0.1, metavar="SECS",
                          help="interval over which to measure statistic (in seconds) [default=%default]")
        parser.add_option("-c", "--number-channels", type="int", default=100, 
                          help="number of uniform channels for which to report power measurements [default=%default]")
        parser.add_option("-l", "--lo-offset", type="eng_float",
                          default=0, metavar="Hz",
                          help="lo_offset in Hz [default=half the sample rate]")
        parser.add_option("-F", "--fft-size", type="int", default=1024,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("", "--real-time", action="store_true", default=False,
                          help="Attempt to enable real-time scheduling")
    	parser.add_option("-d", "--dest-host", type="string", default="",
                          help="set destination host for sending data")
        parser.add_option("", "--skip-DC", action="store_true", default=False,
                          help="skip the DC bin when mapping channels")

        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.print_help()
            sys.exit(1)

	self.center_freq = eng_notation.str_to_num(args[0])
	self.bandwidth = eng_notation.str_to_num(args[1])

        if not options.real_time:
            realtime = False
        else:
            # Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        # build 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(options.samp_rate)
        usrp_rate = self.u.get_samp_rate()

	if usrp_rate != options.samp_rate:
	    if usrp_rate < options.samp_rate:
	        # create list of allowable rates
	        samp_rates = self.u.get_samp_rates()
	        rate_list = [0.0]*len(samp_rates)
	        for i in range(len(rate_list)):
		    last_rate = samp_rates.pop()
		    rate_list[len(rate_list) - 1 - i] = last_rate.start()
		# choose next higher rate
		rate_ind = rate_list.index(usrp_rate) + 1
		if rate_ind < len(rate_list):
		    self.u.set_samp_rate(rate_list[rate_ind])
		    usrp_rate = self.u.get_samp_rate()
		print "New actual sample rate =", usrp_rate/1e6, "MHz"
	    resamp = filter.fractional_resampler_cc(0.0, usrp_rate / options.samp_rate)

	self.samp_rate = options.samp_rate
        
	if(options.lo_offset):
            self.lo_offset = options.lo_offset
	else:
	    self.lo_offset = usrp_rate / 2.0
	    print "LO offset set to", self.lo_offset/1e6, "MHz"

        self.fft_size = options.fft_size
        self.num_ch = options.number_channels
        
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        mywindow = filter.window.blackmanharris(self.fft_size)
        ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)
        window_power = sum(map(lambda x: x*x, mywindow))

        c2mag = blocks.complex_to_mag_squared(self.fft_size)

	self.bin2ch_map = [0] * self.fft_size
        hz_per_bin = self.samp_rate / self.fft_size
	channel_bw = hz_per_bin * round(self.bandwidth / self.num_ch / hz_per_bin)
	self.bandwidth = channel_bw * self.num_ch
	print "Actual width of band is", self.bandwidth/1e6, "MHz."
	start_freq = self.center_freq - self.bandwidth/2.0
	stop_freq = start_freq + self.bandwidth
	for j in range(self.fft_size):
	    fj = self.bin_freq(j, self.center_freq)
	    if (fj >= start_freq) and (fj < stop_freq):
	        channel_num = int(math.floor((fj - start_freq) / channel_bw)) + 1
	        self.bin2ch_map[j] = channel_num
	if options.skip_DC:
	    self.bin2ch_map[(self.fft_size + 1) / 2 + 1:] = self.bin2ch_map[(self.fft_size + 1) / 2 : -1]
	    self.bin2ch_map[(self.fft_size + 1) / 2] = 0
	if self.bandwidth > self.samp_rate:
	    print "Warning: Width of band (" + str(self.bandwidth/1e6), "MHz) is greater than the sample rate (" + str(self.samp_rate/1e6), "MHz)."

	self.aggr = myblocks.bin_aggregator_ff(self.fft_size, self.num_ch, self.bin2ch_map)

        meas_frames = max(1, int(round(options.meas_interval * self.samp_rate / self.fft_size))) # in fft_frames
	self.meas_duration = meas_frames * self.fft_size / self.samp_rate
	print "Actual measurement duration =", self.meas_duration, "s"

        self.stats = myblocks.bin_statistics_ff(self.num_ch, meas_frames)

	# Divide magnitude-square by a constant to obtain power
	# in Watts.  Assumes unit of USRP source is volts.
	impedance = 50.0   # ohms
	Vsq2W_dB = -10.0 * math.log10(self.fft_size * window_power * impedance)

	# Convert from Watts to dBm.
	W2dBm = blocks.nlog10_ff(10.0, self.num_ch, 30.0 + Vsq2W_dB)

	f2c = blocks.float_to_char(self.num_ch, 1.0)

	self.dest_host = options.dest_host

	# file descriptor is set in main loop; use dummy value for now
	self.srvr = myblocks.file_descriptor_sink(self.num_ch * gr.sizeof_char, 0)

	if usrp_rate > self.samp_rate:
	    # insert resampler
	    self.connect(self.u, resamp, s2v)
	else:
	    self.connect(self.u, s2v)
	self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, f2c, self.srvr)
	#self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, self.srvr)

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

        self.set_gain(options.gain)
        print "gain =", options.gain, "dB in range (%0.1f dB, %0.1f dB)" % (float(g.start()), float(g.stop()))
	self.atten = float(g.stop()) - options.gain
Esempio n. 34
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.symbol_rate = symbol_rate = 60000
        self.symbol_period = symbol_period = pow(symbol_rate,-1)
        self.samp_rate = samp_rate = 300e3
        self.samp_per_sym = samp_per_sym = 5
        self.packet_len = packet_len = 256
        self.decimation = decimation = 1
        self.bits_per_sym = bits_per_sym = 1
        self.Sq_Thresh = Sq_Thresh = -30
        self.RF_Gain = RF_Gain = 20
        self.Fc = Fc = 175e6

        ##################################################
        # Blocks
        ##################################################
        _Sq_Thresh_sizer = wx.BoxSizer(wx.VERTICAL)
        self._Sq_Thresh_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_Sq_Thresh_sizer,
        	value=self.Sq_Thresh,
        	callback=self.set_Sq_Thresh,
        	label="Squelch Threshold",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._Sq_Thresh_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_Sq_Thresh_sizer,
        	value=self.Sq_Thresh,
        	callback=self.set_Sq_Thresh,
        	minimum=-50,
        	maximum=20,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_Sq_Thresh_sizer, 0, 2, 1, 1)
        _RF_Gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_Gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_RF_Gain_sizer,
        	value=self.RF_Gain,
        	callback=self.set_RF_Gain,
        	label="RF Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._RF_Gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_RF_Gain_sizer,
        	value=self.RF_Gain,
        	callback=self.set_RF_Gain,
        	minimum=0,
        	maximum=50,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_RF_Gain_sizer, 0, 0, 1, 1)
        _Fc_sizer = wx.BoxSizer(wx.VERTICAL)
        self._Fc_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_Fc_sizer,
        	value=self.Fc,
        	callback=self.set_Fc,
        	label="Center Frequency",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._Fc_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_Fc_sizer,
        	value=self.Fc,
        	callback=self.set_Fc,
        	minimum=50e6,
        	maximum=1700e6,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_Fc_sizer, 0, 1, 1, 1)
        self.osmosdr_source_0_0 = osmosdr.source( args="numchan=" + str(1) + " " + 'rtl_tcp=10.0.0.13:1234' )
        self.osmosdr_source_0_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0_0.set_center_freq(Fc+10e6, 0)
        self.osmosdr_source_0_0.set_freq_corr(0, 0)
        self.osmosdr_source_0_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0_0.set_gain_mode(False, 0)
        self.osmosdr_source_0_0.set_gain(RF_Gain, 0)
        self.osmosdr_source_0_0.set_if_gain(0, 0)
        self.osmosdr_source_0_0.set_bb_gain(0, 0)
        self.osmosdr_source_0_0.set_antenna("", 0)
        self.osmosdr_source_0_0.set_bandwidth(0, 0)
          
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + 'rtl_tcp=10.0.0.12:1234' )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(Fc, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(0, 0)
        self.osmosdr_source_0.set_bb_gain(0, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
          
        self.blocks_skiphead_0_0 = blocks.skiphead(gr.sizeof_gr_complex*1, int(samp_rate)*5)
        self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, int(samp_rate)*5)
        self.blocks_pack_k_bits_bb_0_0 = blocks.pack_k_bits_bb(8)
        self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8)
        self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_float*1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*1)
        self.blocks_float_to_char_0_0 = blocks.float_to_char(1, 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blks2_tcp_sink_0_0_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_char*1,
        	addr="127.0.0.1",
        	port=3493,
        	server=True,
        )
        self.blks2_tcp_sink_0_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_char*1,
        	addr="127.0.0.1",
        	port=3491,
        	server=True,
        )
        self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_cc(Sq_Thresh, 0.01, 5, True)
        self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(-10, 0.01, 5, True)
        self.analog_fm_demod_cf_0_0 = analog.fm_demod_cf(
        	channel_rate=samp_rate,
        	audio_decim=decimation,
        	deviation=75e3,
        	audio_pass=120e3,
        	audio_stop=140e3,
        	gain=1.0,
        	tau=75e-6,
        )
        self.analog_fm_demod_cf_0 = analog.fm_demod_cf(
        	channel_rate=samp_rate,
        	audio_decim=decimation,
        	deviation=75e3,
        	audio_pass=120e3,
        	audio_stop=140e3,
        	gain=1.0,
        	tau=75e-6,
        )
        self.RPi_Rx_RPi_Rx_0_0 = RPi_Rx.RPi_Rx(bits_per_sym, samp_per_sym, packet_len, 65)
        self.RPi_Rx_RPi_Rx_0 = RPi_Rx.RPi_Rx(bits_per_sym, samp_per_sym, packet_len, 65)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_fm_demod_cf_0, 0), (self.RPi_Rx_RPi_Rx_0, 0))
        self.connect((self.RPi_Rx_RPi_Rx_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.RPi_Rx_RPi_Rx_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_fm_demod_cf_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.analog_pwr_squelch_xx_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.blocks_skiphead_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_pack_k_bits_bb_0, 0))
        self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blks2_tcp_sink_0_0, 0))
        self.connect((self.blocks_float_to_char_0_0, 0), (self.blocks_pack_k_bits_bb_0_0, 0))
        self.connect((self.blocks_pack_k_bits_bb_0_0, 0), (self.blks2_tcp_sink_0_0_0, 0))
        self.connect((self.analog_fm_demod_cf_0_0, 0), (self.RPi_Rx_RPi_Rx_0_0, 0))
        self.connect((self.RPi_Rx_RPi_Rx_0_0, 0), (self.blocks_null_sink_0_0, 0))
        self.connect((self.RPi_Rx_RPi_Rx_0_0, 0), (self.blocks_float_to_char_0_0, 0))
        self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.analog_fm_demod_cf_0_0, 0))
        self.connect((self.blocks_skiphead_0_0, 0), (self.analog_pwr_squelch_xx_0_0, 0))
        self.connect((self.osmosdr_source_0_0, 0), (self.blocks_skiphead_0_0, 0))
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor Hackrf")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor Hackrf")
        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", "MSOD_SSLSensor_HackRF")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10e6
        self.fft_size = fft_size = 1000
        self.num_ch = num_ch = 50
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 9e6
        self.window_power = window_power = sum(map(lambda x: x*x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "pwct5.ctl.nist.gov"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (10e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6, )
        self._samp_rate_labels = ("10e6", "15.36e6", "7.68e6", "3.84e6", "1.92e6", )
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._samp_rate_box.addWidget(radio_button)
        	self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
        	lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._num_ch_options = (56, 50, 25, 15, 8, )
        self._num_ch_labels = ("56", "50", "25", "15", "8", )
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._num_ch_box.addWidget(radio_button)
        	self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
        	lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (1000, 1024, 512, 256, 128, )
        self._fft_size_labels = ("1000", "1024", "512", "256", "128", )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size"+": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels: self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.230.12", "pwc8.ctl.nist.gov", "pwct5.ctl.nist.gov", )
        self._dest_host_labels = ("pwct1", "Naceur Laptop", "pwct5Desktop", "Pwct5", )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host+": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels: self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6, 729e6, )
        self._center_freq_labels = ("AT&T", "Verizon", "ChannelEmulator", "HackRF Shifted Freq", )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq"+": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels: self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "hackrf=0" )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(1, 0)
        self.osmosdr_source_0.set_iq_balance_mode(2, 0)
        self.osmosdr_source_0.set_gain_mode(True, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(32, 0)
        self.osmosdr_source_0.set_bb_gain(40, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(20e6, 0)
          
        self.msod_sensor_sslsocket_sink_0 = msod_sensor.sslsocket_sink(num_ch, dest_host, "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.loc", "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.sys", "HackRF", "NaN", center_freq, ActualBW, meas_interval, 0, samp_rate, False)
        self.msod_sensor_bin_statistics_0 = msod_sensor.bin_statistics(num_ch, meas_period)
        self.msod_sensor_bin_aggregator_0 = msod_sensor.bin_aggregator(fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size, False)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6, )
        self._bandwidth_labels = ("10.08e6", "9e6", "4.5e6", "2.7e6", "1.08e6", )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth"+": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.msod_sensor_bin_aggregator_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.msod_sensor_sslsocket_sink_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.msod_sensor_bin_aggregator_0, 0), (self.msod_sensor_bin_statistics_0, 0))    
        self.connect((self.msod_sensor_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))    
Esempio n. 36
0
    def __init__(self):
        gr.top_block.__init__(self, "OOK Receiver")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("OOK Receiver")
        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", "ook_receiver")

        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 = 10e6
        self.baseband_freq = baseband_freq = 500
        self.threshold = threshold = 0.03
        self.samples_per_symbol = samples_per_symbol = int(samp_rate /
                                                           baseband_freq)
        self.carrier_freq = carrier_freq = 432.867e6
        self.alpha = alpha = 0.00328

        ##################################################
        # Blocks
        ##################################################
        self._threshold_range = Range(0, 1, 0.01, 0.03, 200)
        self._threshold_win = RangeWidget(self._threshold_range,
                                          self.set_threshold, 'Threshold',
                                          "counter_slider", float)
        self.top_grid_layout.addWidget(self._threshold_win)
        self._alpha_range = Range(0.00001, 0.01, 0.00001, 0.00328, 200)
        self._alpha_win = RangeWidget(self._alpha_range, self.set_alpha,
                                      'alpha', "counter_slider", float)
        self.top_grid_layout.addWidget(self._alpha_win)
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
            interpolation=1,
            decimation=int(samples_per_symbol / 4),
            taps=[1],
            fractional_bw=None)
        self.qtgui_time_sink_x_1 = qtgui.time_sink_f(
            1024,  #size
            samp_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(-1, 1)

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

        self.qtgui_time_sink_x_1.enable_tags(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(False)
        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(True)
        self.qtgui_time_sink_x_1.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 = [0, -1, -1, -1, -1, -1, -1, -1, -1, -1]

        for i in range(1):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_1.set_line_label(
                    i, "Data {0}".format(i))
            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_grid_layout.addWidget(self._qtgui_time_sink_x_1_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            600000,  #size
            samp_rate,  #samp_rate
            "",  #name
            3  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(0, 0.15)

        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_NORM,
                                                  qtgui.TRIG_SLOPE_POS, 0.07,
                                                  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(True)
        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(3):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            carrier_freq,  #fc
            samp_rate,  #bw
            "",  #name
            1)
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0,
                                                  "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)

        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 range(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)
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               "soapy=0,driver=lime")
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(carrier_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(0, 0)
        self.osmosdr_source_0.set_bb_gain(0, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
        self.blocks_threshold_ff_0_0 = blocks.threshold_ff(
            threshold, threshold, 0)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(0.04, 0.06, 0)
        self.blocks_rms_xx_0 = blocks.rms_ff(alpha)
        self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(4)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(0.1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_char * 1,
            '/run/media/gpellaeon/ubuntu20_04/home/pellaeon/Development/SDR/GRFlowgraphs/ook/digital_output.txt',
            False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_rms_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_threshold_ff_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_pack_k_bits_bb_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_pack_k_bits_bb_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_rms_xx_0, 0),
                     (self.blocks_threshold_ff_0_0, 0))
        self.connect((self.blocks_threshold_ff_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_threshold_ff_0_0, 0),
                     (self.qtgui_time_sink_x_0, 2))
        self.connect((self.blocks_threshold_ff_0_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.blocks_complex_to_mag_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.qtgui_time_sink_x_1, 0))
Esempio n. 37
0
def float_to_char(N):
    op = blocks.float_to_char()
    tb = helper(N, op, gr.sizeof_float, gr.sizeof_char, 1, 1)
    return tb
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor X310 Rfnoc")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor X310 Rfnoc")
        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", "MSOD_SSLSensor_X310_RFNoC")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10e6
        self.fft_size = fft_size = 256
        self.num_ch = num_ch = 50
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 9e6
        self.meas_interval = meas_interval = 1e-3
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.device3 = variable_uhd_device3_0 = ettus.device3(uhd.device_addr_t( ",".join(("type=x300", "addr=usrp0")) ))
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.impedance = impedance = 50.0
        self.dest_host = dest_host = "129.6.142.138"
        self.center_freq = center_freq = 724e6
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (10e6, 25e6, 12.5e6, 3.84e6, 5e5, )
        self._samp_rate_labels = ("10e6", "25e6", "12.5e6", "3.84e6", "5e5", )
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._samp_rate_box.addWidget(radio_button)
        	self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
        	lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (56, 50, 25, 15, 8, )
        self._num_ch_labels = ("56", "50", "25", "15", "8", )
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._num_ch_box.addWidget(radio_button)
        	self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
        	lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (2048, 1024, 512, 256, 128, )
        self._fft_size_labels = ("2048", "1024", "512", "256", "128", )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size"+": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels: self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6, )
        self._center_freq_labels = ("AT&T", "Verizon", "ChannelEmulator", )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq"+": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels: self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self.uhd_rfnoc_streamer_vector_iir_0 = ettus.rfnoc_generic(
              self.device3,
              uhd.stream_args( # TX Stream Args
                  cpu_format="fc32",
                  otw_format="sc16",
                  args="spp={},alpha={},beta={}".format(fft_size, 0.984375, 0.015625),
              ),
              uhd.stream_args( # TX Stream Args
                  cpu_format="fc32",
                  otw_format="sc16",
                  args="spp={},alpha={},beta={}".format(fft_size, 0.984375, 0.015625),
              ),
              "VectorIIR", -1, -1,
        )
        self.uhd_rfnoc_streamer_vector_iir_0.set_arg("alpha", 0.984375)
        self.uhd_rfnoc_streamer_vector_iir_0.set_arg("beta",  0.015625)
          
        self.uhd_rfnoc_streamer_radio_0 = ettus.rfnoc_radio(
            self.device3,
            uhd.stream_args( # Tx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="", # empty
            ),
            uhd.stream_args( # Rx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
        	args="spp=256",
            ),
            0, -1
        )
        self.uhd_rfnoc_streamer_radio_0.set_rx_freq(center_freq)
        self.uhd_rfnoc_streamer_radio_0.set_rx_rate(samp_rate)
        self.uhd_rfnoc_streamer_radio_0.set_rx_gain(rx_gain)
        self.uhd_rfnoc_streamer_radio_0.set_rx_antenna("TX/RX")
        self.uhd_rfnoc_streamer_radio_0.set_rx_dc_offset(True)
        self.uhd_rfnoc_streamer_logpwr_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args( # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(num_ch, "" if num_ch == 1 else "spp={0}".format(num_ch)),
            ),
            uhd.stream_args( # RX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(num_ch, "" if num_ch == 1 else "spp={0}".format(num_ch)),
            ),
            "LogPwr", -1, -1,
        )
        self.uhd_rfnoc_streamer_fifo_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args( # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(fft_size, "" if fft_size == 1 else "spp={0}".format(fft_size)),
            ),
            uhd.stream_args( # RX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(fft_size, "" if fft_size == 1 else "spp={0}".format(fft_size)),
            ),
            "FIFO", -1, -1,
        )
        self.uhd_rfnoc_streamer_fft_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args( # TX Stream Args
                cpu_format="fc32", # TODO: This must be made an option
                otw_format="sc16",
                args="spp={},magnitude_out={}".format(256, "COMPLEX"),
            ),
            uhd.stream_args( # RX Stream Args
                cpu_format="fc32", # TODO: This must be made an option
                otw_format="sc16",
                args="",
            ),
            "FFT", -1, -1,
        )
        self.uhd_rfnoc_streamer_bin_aggr_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(
                cpu_format="fc32", # TODO: This must be made an option
                otw_format="sc16",
                args=""
            ),
            uhd.stream_args(
                cpu_format="fc32", # TODO: This must be made an option
                otw_format="sc16",
                args="",
            ),
            "BinAggr", -1, -1,
        )
        self.msod_sensor_jsonfile_sink_0 = msod_sensor.jsonfile_sink(num_ch, "/home/nae/capture/capture_X310/03_25_2016-002.dat", "/raid/nae/pybombs_RFNoC/src/gr-msod_latency/examples/sensor_X310.loc", "/raid/nae/pybombs_RFNoC/src/gr-msod_latency/examples/sensor_X310.sys", "X310", "NaN", center_freq, ActualBW, meas_interval, 0, samp_rate, False)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.230.12", "129.6.142.181", "129.6.142.138", )
        self._dest_host_labels = ("pwct1", "Naceur Laptop", "pwct5Desktop", "Pwct5", )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host+": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels: self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(num_ch)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6, )
        self._bandwidth_labels = ("10.08e6", "9e6", "4.5e6", "2.7e6", "1.08e6", )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth"+": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.msod_sensor_jsonfile_sink_0, 0))    
        self.connect((self.uhd_rfnoc_streamer_logpwr_0, 0), (self.blocks_complex_to_mag_0, 0))    
        self.device3.connect(self.uhd_rfnoc_streamer_bin_aggr_0.get_block_id(), 0, self.uhd_rfnoc_streamer_logpwr_0.get_block_id(), 0)    
        self.device3.connect(self.uhd_rfnoc_streamer_fft_0.get_block_id(), 0, self.uhd_rfnoc_streamer_vector_iir_0.get_block_id(), 0)    
        self.device3.connect(self.uhd_rfnoc_streamer_fifo_0.get_block_id(), 0, self.uhd_rfnoc_streamer_fft_0.get_block_id(), 0)    
        self.device3.connect(self.uhd_rfnoc_streamer_radio_0.get_block_id(), 0, self.uhd_rfnoc_streamer_fifo_0.get_block_id(), 0)    
        self.device3.connect(self.uhd_rfnoc_streamer_vector_iir_0.get_block_id(), 0, self.uhd_rfnoc_streamer_bin_aggr_0.get_block_id(), 0)    
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor N210")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor N210")
        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", "MSOD_SSLSensor_N210")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 12.5e6
        self.fft_size = fft_size = 625
        self.num_ch = num_ch = 56
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 10.08e6
        self.window_power = window_power = sum(map(lambda x: x*x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.device3 = variable_uhd_device3_0 = ettus.device3(uhd.device_addr_t( ",".join(('type=x300, addr=usrp02', "")) ))
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "129.6.142.103"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (12.5e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6, )
        self._samp_rate_labels = ('12.5e6', '15.36e6', '7.68e6', '3.84e6', '1.92e6', )
        self._samp_rate_group_box = Qt.QGroupBox('samp_rate')
        self._samp_rate_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._samp_rate_box.addWidget(radio_button)
        	self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
        	lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, 'rx_gain', "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (56, 50, 25, 15, 8, )
        self._num_ch_labels = ('56', '50', '25', '15', '8', )
        self._num_ch_group_box = Qt.QGroupBox('num_ch')
        self._num_ch_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._num_ch_box.addWidget(radio_button)
        	self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
        	lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (625, 1024, 512, 256, 128, )
        self._fft_size_labels = ('625', '1024', '512', '256', '128', )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel('fft_size'+": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels: self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6, )
        self._center_freq_labels = ('AT&T', 'Verizon', 'ChannelEmulator', )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel('center_freq'+": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels: self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6, )
        self._bandwidth_labels = ('10.08e6', '9e6', '4.5e6', '2.7e6', '1.08e6', )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel('bandwidth'+": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)
        self.uhd_rfnoc_streamer_radio_0 = ettus.rfnoc_radio(
            self.device3,
            uhd.stream_args( # Tx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="", # empty
            ),
            uhd.stream_args( # Rx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
        	args='',
            ),
            1, -1
        )
        self.uhd_rfnoc_streamer_radio_0.set_rate(samp_rate)
        for i in xrange(1):
            self.uhd_rfnoc_streamer_radio_0.set_rx_freq(center_freq, i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_gain(rx_gain, i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_antenna("RX2", i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_dc_offset(True, i)
        self.spectrum_latency_jsonfile_sink_0 = spectrum_latency.jsonfile_sink(num_ch, "/home/nae/Spectrum-Sensors/N210/Capture.N210/10-25-2016", "/raid/nae/gnuradio/src/gr-spectrum_latency/examples/utils/sensor.loc", "/raid/nae/gnuradio/src/gr-spectrum_latency/examples/utils/sensor.sys", "F37258", "12345", center_freq, bandwidth, meas_interval, 0, samp_rate, False)
        self.spectrum_latency_bin_statistics_0 = spectrum_latency.bin_statistics(num_ch, meas_period)
        self.spectrum_latency_bin_aggregator_0 = spectrum_latency.bin_aggregator(fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.142.103", "129.6.142.181", "pwct5.ctl.nist.gov", )
        self._dest_host_labels = ('pwct1', 'NEO_VM', 'pwct5Desktop', 'Pwct5', )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host+": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels: self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.spectrum_latency_bin_aggregator_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.spectrum_latency_jsonfile_sink_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.spectrum_latency_bin_aggregator_0, 0), (self.spectrum_latency_bin_statistics_0, 0))    
        self.connect((self.spectrum_latency_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.uhd_rfnoc_streamer_radio_0, 0), (self.blocks_stream_to_vector_0, 0))    
Esempio n. 40
0
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor X310 Rfnoc")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor X310 Rfnoc")
        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", "MSOD_SSLSensor_X310_RFNoC")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10e6
        self.fft_size = fft_size = 256
        self.num_ch = num_ch = 50
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 9e6
        self.meas_interval = meas_interval = 1e-3
        self.channel_bw = channel_bw = hz_per_bin * round(
            bandwidth / num_ch / hz_per_bin)
        self.device3 = variable_uhd_device3_0 = ettus.device3(
            uhd.device_addr_t(",".join(("type=x300", "addr=usrp0"))))
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(
            1, int(round(meas_interval * samp_rate / fft_size)))
        self.impedance = impedance = 50.0
        self.dest_host = dest_host = "129.6.142.138"
        self.center_freq = center_freq = 724e6
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (
            10e6,
            25e6,
            12.5e6,
            3.84e6,
            5e5,
        )
        self._samp_rate_labels = (
            "10e6",
            "25e6",
            "12.5e6",
            "3.84e6",
            "5e5",
        )
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
            radio_button = Qt.QRadioButton(label)
            self._samp_rate_box.addWidget(radio_button)
            self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain,
                                        "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (
            56,
            50,
            25,
            15,
            8,
        )
        self._num_ch_labels = (
            "56",
            "50",
            "25",
            "15",
            "8",
        )
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
            radio_button = Qt.QRadioButton(label)
            self._num_ch_box.addWidget(radio_button)
            self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._num_ch_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
            lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (
            2048,
            1024,
            512,
            256,
            128,
        )
        self._fft_size_labels = (
            "2048",
            "1024",
            "512",
            "256",
            "128",
        )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size" + ": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels:
            self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._fft_size_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
            lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._center_freq_options = (
            709.01e6,
            782e6,
            724e6,
        )
        self._center_freq_labels = (
            "AT&T",
            "Verizon",
            "ChannelEmulator",
        )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq" + ": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels:
            self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._center_freq_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self.uhd_rfnoc_streamer_vector_iir_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(  # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="spp={},alpha={},beta={}".format(fft_size, 0.984375,
                                                      0.015625),
            ),
            uhd.stream_args(  # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="spp={},alpha={},beta={}".format(fft_size, 0.984375,
                                                      0.015625),
            ),
            "VectorIIR",
            -1,
            -1,
        )
        self.uhd_rfnoc_streamer_vector_iir_0.set_arg("alpha", 0.984375)
        self.uhd_rfnoc_streamer_vector_iir_0.set_arg("beta", 0.015625)

        self.uhd_rfnoc_streamer_radio_0 = ettus.rfnoc_radio(
            self.device3,
            uhd.stream_args(  # Tx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="",  # empty
            ),
            uhd.stream_args(  # Rx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="spp=256",
            ),
            0,
            -1)
        self.uhd_rfnoc_streamer_radio_0.set_rx_freq(center_freq)
        self.uhd_rfnoc_streamer_radio_0.set_rx_rate(samp_rate)
        self.uhd_rfnoc_streamer_radio_0.set_rx_gain(rx_gain)
        self.uhd_rfnoc_streamer_radio_0.set_rx_antenna("TX/RX")
        self.uhd_rfnoc_streamer_radio_0.set_rx_dc_offset(True)
        self.uhd_rfnoc_streamer_logpwr_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(  # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(
                    num_ch, "" if num_ch == 1 else "spp={0}".format(num_ch)),
            ),
            uhd.stream_args(  # RX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(
                    num_ch, "" if num_ch == 1 else "spp={0}".format(num_ch)),
            ),
            "LogPwr",
            -1,
            -1,
        )
        self.uhd_rfnoc_streamer_fifo_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(  # TX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(
                    fft_size,
                    "" if fft_size == 1 else "spp={0}".format(fft_size)),
            ),
            uhd.stream_args(  # RX Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="gr_vlen={0},{1}".format(
                    fft_size,
                    "" if fft_size == 1 else "spp={0}".format(fft_size)),
            ),
            "FIFO",
            -1,
            -1,
        )
        self.uhd_rfnoc_streamer_fft_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(  # TX Stream Args
                cpu_format="fc32",  # TODO: This must be made an option
                otw_format="sc16",
                args="spp={},magnitude_out={}".format(256, "COMPLEX"),
            ),
            uhd.stream_args(  # RX Stream Args
                cpu_format="fc32",  # TODO: This must be made an option
                otw_format="sc16",
                args="",
            ),
            "FFT",
            -1,
            -1,
        )
        self.uhd_rfnoc_streamer_bin_aggr_0 = ettus.rfnoc_generic(
            self.device3,
            uhd.stream_args(
                cpu_format="fc32",  # TODO: This must be made an option
                otw_format="sc16",
                args=""),
            uhd.stream_args(
                cpu_format="fc32",  # TODO: This must be made an option
                otw_format="sc16",
                args="",
            ),
            "BinAggr",
            -1,
            -1,
        )
        self.msod_sensor_jsonfile_sink_0 = msod_sensor.jsonfile_sink(
            num_ch, "/home/nae/capture/capture_X310/03_25_2016-002.dat",
            "/raid/nae/pybombs_RFNoC/src/gr-msod_latency/examples/sensor_X310.loc",
            "/raid/nae/pybombs_RFNoC/src/gr-msod_latency/examples/sensor_X310.sys",
            "X310", "NaN", center_freq, ActualBW, meas_interval, 0, samp_rate,
            False)
        self._dest_host_options = (
            "pwct1.ctl.nist.gov",
            "129.6.230.12",
            "129.6.142.181",
            "129.6.142.138",
        )
        self._dest_host_labels = (
            "pwct1",
            "Naceur Laptop",
            "pwct5Desktop",
            "Pwct5",
        )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host + ": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels:
            self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._dest_host_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
            lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(num_ch)
        self._bandwidth_options = (
            10.08e6,
            9e6,
            4.5e6,
            2.7e6,
            1.08e6,
        )
        self._bandwidth_labels = (
            "10.08e6",
            "9e6",
            "4.5e6",
            "2.7e6",
            "1.08e6",
        )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth" + ": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels:
            self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._bandwidth_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
            lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.msod_sensor_jsonfile_sink_0, 0))
        self.connect((self.uhd_rfnoc_streamer_logpwr_0, 0),
                     (self.blocks_complex_to_mag_0, 0))
        self.device3.connect(self.uhd_rfnoc_streamer_bin_aggr_0.get_block_id(),
                             0,
                             self.uhd_rfnoc_streamer_logpwr_0.get_block_id(),
                             0)
        self.device3.connect(
            self.uhd_rfnoc_streamer_fft_0.get_block_id(), 0,
            self.uhd_rfnoc_streamer_vector_iir_0.get_block_id(), 0)
        self.device3.connect(self.uhd_rfnoc_streamer_fifo_0.get_block_id(), 0,
                             self.uhd_rfnoc_streamer_fft_0.get_block_id(), 0)
        self.device3.connect(self.uhd_rfnoc_streamer_radio_0.get_block_id(), 0,
                             self.uhd_rfnoc_streamer_fifo_0.get_block_id(), 0)
        self.device3.connect(
            self.uhd_rfnoc_streamer_vector_iir_0.get_block_id(), 0,
            self.uhd_rfnoc_streamer_bin_aggr_0.get_block_id(), 0)
Esempio n. 41
0
    def __init__(self, large_sig_len=0.0015, signal_mult=2, freq=433866000):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.large_sig_len = large_sig_len
        self.signal_mult = signal_mult
        self.freq = freq

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 240000

        ##################################################
        # Blocks
        ##################################################
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(
            0.2, 1)
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                              "")
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(freq, 0)
        self.rtlsdr_source_0.set_freq_corr(-24, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(1, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(50, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        self.low_pass_filter_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 10000, 10000, firdes.WIN_HAMMING,
                            6.76))
        self.blocks_threshold_ff_2 = blocks.threshold_ff(0, 0, 0)
        self.blocks_threshold_ff_1 = blocks.threshold_ff(0, 0, 0)
        self.blocks_sub_xx_2 = blocks.sub_ff(1)
        self.blocks_sub_xx_1 = blocks.sub_ff(1)
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_CLIENT", "localhost",
                                                     "52001", 10000, False)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff(
            (signal_mult, ))
        self.blocks_moving_average_xx_1 = blocks.moving_average_ff(
            int(samp_rate * large_sig_len), 0.8 / samp_rate / large_sig_len,
            4000)
        self.blocks_float_to_char_1 = blocks.float_to_char(1, 1)
        self.blocks_float_to_char_0_0 = blocks.float_to_char(1, 1)
        self.blocks_delay_1 = blocks.delay(gr.sizeof_float * 1,
                                           int(samp_rate * 0.00005))
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, 1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.bitgate_triggered_bits_0 = bitgate.triggered_bits(
            int(samp_rate * large_sig_len * 5), False)
        self.analog_rail_ff_1 = analog.rail_ff(0.001, 1)
        self.analog_rail_ff_0 = analog.rail_ff(0, 1)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.bitgate_triggered_bits_0, 'pdus'),
                         (self.blocks_socket_pdu_0, 'pdus'))
        self.connect((self.analog_rail_ff_0, 0),
                     (self.blocks_float_to_char_0_0, 0))
        self.connect((self.analog_rail_ff_1, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.analog_rail_ff_1, 0))
        self.connect((self.blocks_delay_0, 0), (self.blocks_sub_xx_0, 0))
        self.connect((self.blocks_delay_1, 0),
                     (self.blocks_float_to_char_1, 0))
        self.connect((self.blocks_float_to_char_0_0, 0),
                     (self.bitgate_triggered_bits_0, 1))
        self.connect((self.blocks_float_to_char_1, 0),
                     (self.bitgate_triggered_bits_0, 0))
        self.connect((self.blocks_moving_average_xx_1, 0),
                     (self.blocks_sub_xx_1, 1))
        self.connect((self.blocks_moving_average_xx_1, 0),
                     (self.blocks_sub_xx_2, 1))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_moving_average_xx_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.single_pole_iir_filter_xx_0, 0))
        self.connect((self.blocks_sub_xx_0, 0), (self.analog_rail_ff_0, 0))
        self.connect((self.blocks_sub_xx_1, 0), (self.blocks_sub_xx_2, 0))
        self.connect((self.blocks_sub_xx_1, 0),
                     (self.blocks_threshold_ff_1, 0))
        self.connect((self.blocks_sub_xx_2, 0),
                     (self.blocks_threshold_ff_2, 0))
        self.connect((self.blocks_threshold_ff_1, 0), (self.blocks_delay_0, 0))
        self.connect((self.blocks_threshold_ff_1, 0),
                     (self.blocks_sub_xx_0, 1))
        self.connect((self.blocks_threshold_ff_2, 0), (self.blocks_delay_1, 0))
        self.connect((self.low_pass_filter_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0),
                     (self.blocks_sub_xx_1, 0))
Esempio n. 42
0
    def __init__(self, fft_length, cp_length, kstime, logging=False):
        """
        OFDM synchronization using PN Correlation and initial cross-correlation:
        F. Tufvesson, O. Edfors, and M. Faulkner, "Time and Frequency Synchronization for OFDM using
        PN-Sequency Preambles," IEEE Proc. VTC, 1999, pp. 2203-2207.

        This implementation is meant to be a more robust version of the Schmidl and Cox receiver design.
        By correlating against the preamble and using that as the input to the time-delayed correlation,
        this circuit produces a very clean timing signal at the end of the preamble. The timing is
        more accurate and does not have the problem associated with determining the timing from the
        plateau structure in the Schmidl and Cox.

        This implementation appears to require that the signal is received with a normalized power or signal
        scaling factor to reduce ambiguities introduced from partial correlation of the cyclic prefix and
        the peak detection. A better peak detection block might fix this.

        Also, the cross-correlation falls apart as the frequency offset gets larger and completely fails
        when an integer offset is introduced. Another thing to look at.
        """

        gr.hier_block2.__init__(self, "ofdm_sync_pnac",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature

        self.input = blocks.add_const_cc(0)

        symbol_length = fft_length + cp_length

        # PN Sync with cross-correlation input

        # cross-correlate with the known symbol
        kstime = [k.conjugate() for k in kstime[0:fft_length//2]]
        kstime.reverse()
        self.crosscorr_filter = filter.fir_filter_ccc(1, kstime)
        
        # Create a delay line
        self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2)

        # Correlation from ML Sync
        self.conjg = blocks.conjugate_cc();
        self.corr = blocks.multiply_cc();

        # Create a moving sum filter for the input
        self.mag = blocks.complex_to_mag_squared()
        self.power = filter.fir_filter_fff(1, [1.0] * int(fft_length))

        # Get magnitude (peaks) and angle (phase/freq error)
        self.c2mag = blocks.complex_to_mag_squared()
        self.angle = blocks.complex_to_arg()
        self.compare = blocks.sub_ff()

        self.sample_and_hold = blocks.sample_and_hold_ff()

        #ML measurements input to sampler block and detect
        self.threshold = blocks.threshold_ff(0,0,0)      # threshold detection might need to be tweaked
        self.peaks = blocks.float_to_char()

        self.connect(self, self.input)

        # Cross-correlate input signal with known preamble
        self.connect(self.input, self.crosscorr_filter)

        # use the output of the cross-correlation as input time-shifted correlation
        self.connect(self.crosscorr_filter, self.delay)
        self.connect(self.crosscorr_filter, (self.corr,0))
        self.connect(self.delay, self.conjg)
        self.connect(self.conjg, (self.corr,1))
        self.connect(self.corr, self.c2mag)
        self.connect(self.corr, self.angle)
        self.connect(self.angle, (self.sample_and_hold,0))
        
        # Get the power of the input signal to compare against the correlation
        self.connect(self.crosscorr_filter, self.mag, self.power)

        # Compare the power to the correlator output to determine timing peak
        # When the peak occurs, it peaks above zero, so the thresholder detects this
        self.connect(self.c2mag, (self.compare,0))
        self.connect(self.power, (self.compare,1))
        self.connect(self.compare, self.threshold)
        self.connect(self.threshold, self.peaks, (self.sample_and_hold,1))

        # Set output signals
        #    Output 0: fine frequency correction value
        #    Output 1: timing signal
        self.connect(self.sample_and_hold, (self,0))
        self.connect(self.peaks, (self,1))

        if logging:
            self.connect(self.compare, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-compare_f.dat"))
            self.connect(self.c2mag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-theta_f.dat"))
            self.connect(self.power, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-inputpower_f.dat"))
            self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-epsilon_f.dat"))
            self.connect(self.threshold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-threshold_f.dat"))
            self.connect(self.peaks, blocks.file_sink(gr.sizeof_char, "ofdm_sync_pnac-peaks_b.dat"))
            self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pnac-sample_and_hold_f.dat"))
            self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pnac-input_c.dat"))
Esempio n. 43
0
    def __init__(self, address="addr=192.168.10.2"):
        gr.top_block.__init__(self, "OFDM 256QAM")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("OFDM 256QAM")
        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", "GSM_OFDM_LTE_E300")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Parameters
        ##################################################
        self.address = address

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1e6
        self.samp_0 = samp_0 = 6.5e6
        self.CENTRAL_FREQEUNCY_USRP_Ch1 = CENTRAL_FREQEUNCY_USRP_Ch1 = 2145e6
        self.BW_USRP = BW_USRP = 50e6

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		args="scalar=1024",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0.set_subdev_spec("B:0", 0)
        self.uhd_usrp_sink_0.set_samp_rate(5e6)
        self.uhd_usrp_sink_0.set_center_freq(CENTRAL_FREQEUNCY_USRP_Ch1, 0)
        self.uhd_usrp_sink_0.set_gain(27, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.uhd_usrp_sink_0.set_bandwidth(BW_USRP, 0)
        self.digital_ofdm_mod_1 = grc_blks2.packet_mod_f(digital.ofdm_mod(
        		options=grc_blks2.options(
        			modulation="bpsk",
        			fft_length=1024,
        			occupied_tones=1000,
        			cp_length=0,
        			pad_for_usrp=True,
        			log=None,
        			verbose=None,
        		),
        	),
        	payload_length=0,
        )
        self.digital_cpmmod_bc_1 = digital.cpmmod_bc(analog.cpm.LREC, 2, 2, 2, 2)
        self.blocks_vector_source_x_1 = blocks.vector_source_f((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,0,1, 1,0, 0, 1,0,1, 1, 1,0, 0, 1,0,1), True, 1, [])
        self.blocks_vector_source_x_0_0_0 = blocks.vector_source_f((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,0,1, 1,0, 0, 1,0,1, 1, 1,0, 0, 1,0,1), True, 1, [])
        self.blocks_vector_source_x_0_0 = blocks.vector_source_f((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,0,1, 1,0, 0, 1,0,1, 1, 1,0, 0, 1,0,1), True, 1, [])
        self.blocks_vector_source_x_0 = blocks.vector_source_f((1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,0,1, 1,0, 0, 1,0,1, 0, 1,0, 0, 1,0,1), True, 1, [])
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_complex_to_real_0, 0), (self.digital_ofdm_mod_1, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.digital_cpmmod_bc_1, 0))    
        self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_add_xx_0, 2))    
        self.connect((self.blocks_vector_source_x_0_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.blocks_vector_source_x_0_0_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.blocks_vector_source_x_1, 0), (self.blocks_add_xx_0, 3))    
        self.connect((self.digital_cpmmod_bc_1, 0), (self.blocks_complex_to_real_0, 0))    
        self.connect((self.digital_ofdm_mod_1, 0), (self.uhd_usrp_sink_0, 0))    
Esempio n. 44
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Am Xmit Multi Carrier Fl2K")
        _icon_path = "/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.rf_sample_rate = rf_sample_rate = 8192e3
        self.fir_interp = fir_interp = 512
        self.fgain = fgain = 128
        self.af_sample_rate = af_sample_rate = 16e3

        ##################################################
        # Blocks
        ##################################################
#        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
#        	self.GetWin(),
#        	title="Scope Plot",
#        	sample_rate=rf_sample_rate,
#        	v_scale=0,
#        	v_offset=0,
#        	t_scale=0,
#        	ac_couple=False,
#        	xy_mode=False,
#        	num_inputs=1,
#        	trig_mode=wxgui.TRIG_MODE_AUTO,
#        	y_axis_label="Counts",
#        )
#        self.Add(self.wxgui_scopesink2_0.win)
#        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
#        	self.GetWin(),
#        	baseband_freq=0,
#        	y_per_div=10,
#        	y_divs=10,
#        	ref_level=0,
#        	ref_scale=2.0,
#        	sample_rate=rf_sample_rate,
#        	fft_size=1024,
#        	fft_rate=15,
#        	average=False,
#        	avg_alpha=None,
#        	title="FFT Plot",
#        	peak_hold=False,
#        )
#        self.Add(self.wxgui_fftsink2_0.win)
        self.low_pass_filter_5 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_4 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_3 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_2 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0 = filter.interp_fir_filter_fff(fir_interp, firdes.low_pass(
        	fgain, rf_sample_rate, 8e3, 4e3, firdes.WIN_HAMMING, 6.76))
        self.blocks_wavfile_source_5 = blocks.wavfile_source("Jackbenny-390101Goodbye1938Hello1939.wav", True)
        self.blocks_wavfile_source_4 = blocks.wavfile_source("Jackbenny-390115JacksScreenGuildTheatrePerformance.wav", True)
        self.blocks_wavfile_source_3 = blocks.wavfile_source("Jackbenny-390122EncyclopediaBritannica.wav", True)
        self.blocks_wavfile_source_2 = blocks.wavfile_source("Jackbenny-390129BennyVsAllenFight.wav", True)
        self.blocks_wavfile_source_1 = blocks.wavfile_source("Jackbenny-390129JackChallengesFredToFight.wav", True)
        self.blocks_wavfile_source_0 = blocks.wavfile_source("Jackbenny-390205JackChallengesFredAllenToABoxingMatch.wav", True)
        self.blocks_multiply_xx_5 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_4 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_3 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_2 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_1 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_6 = blocks.multiply_const_vff((.2, ))
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 128)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "am_xmit_fl2k.dat", False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.blocks_add_const_vxx_5 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_4 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_3 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_2 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_1 = blocks.add_const_vff((1, ))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((1, ))
        self.analog_sig_source_x_5 = analog.sig_source_f(rf_sample_rate, analog.GR_SIN_WAVE, 850.006e3, 1, 0)
        self.analog_sig_source_x_4 = analog.sig_source_f(rf_sample_rate, analog.GR_COS_WAVE, 830.005e3, 1, 0)
        self.analog_sig_source_x_3 = analog.sig_source_f(rf_sample_rate, analog.GR_SIN_WAVE, 810.004e3, 1, 0)
        self.analog_sig_source_x_2 = analog.sig_source_f(rf_sample_rate, analog.GR_COS_WAVE, 790.003e3, 1, 0)
        self.analog_sig_source_x_1 = analog.sig_source_f(rf_sample_rate, analog.GR_SIN_WAVE, 770.002e3, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(rf_sample_rate, analog.GR_COS_WAVE, 750.001e3, 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_1, 0), (self.blocks_multiply_xx_1, 1))    
        self.connect((self.analog_sig_source_x_2, 0), (self.blocks_multiply_xx_2, 1))    
        self.connect((self.analog_sig_source_x_3, 0), (self.blocks_multiply_xx_3, 1))    
        self.connect((self.analog_sig_source_x_4, 0), (self.blocks_multiply_xx_4, 1))    
        self.connect((self.analog_sig_source_x_5, 0), (self.blocks_multiply_xx_5, 1))    
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.blocks_add_const_vxx_1, 0), (self.blocks_multiply_xx_1, 0))    
        self.connect((self.blocks_add_const_vxx_2, 0), (self.blocks_multiply_xx_2, 0))    
        self.connect((self.blocks_add_const_vxx_3, 0), (self.blocks_multiply_xx_3, 0))    
        self.connect((self.blocks_add_const_vxx_4, 0), (self.blocks_multiply_xx_4, 0))    
        self.connect((self.blocks_add_const_vxx_5, 0), (self.blocks_multiply_xx_5, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_6, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_6, 0), (self.blocks_float_to_char_0, 0))    
#        self.connect((self.blocks_multiply_const_vxx_6, 0), (self.wxgui_fftsink2_0, 0))    
#        self.connect((self.blocks_multiply_const_vxx_6, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.blocks_multiply_xx_2, 0), (self.blocks_add_xx_0, 2))    
        self.connect((self.blocks_multiply_xx_3, 0), (self.blocks_add_xx_0, 3))    
        self.connect((self.blocks_multiply_xx_4, 0), (self.blocks_add_xx_0, 4))    
        self.connect((self.blocks_multiply_xx_5, 0), (self.blocks_add_xx_0, 5))    
        self.connect((self.blocks_wavfile_source_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.blocks_wavfile_source_1, 0), (self.low_pass_filter_1, 0))    
        self.connect((self.blocks_wavfile_source_2, 0), (self.low_pass_filter_2, 0))    
        self.connect((self.blocks_wavfile_source_3, 0), (self.low_pass_filter_3, 0))    
        self.connect((self.blocks_wavfile_source_4, 0), (self.low_pass_filter_4, 0))    
        self.connect((self.blocks_wavfile_source_5, 0), (self.low_pass_filter_5, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.blocks_add_const_vxx_0, 0))    
        self.connect((self.low_pass_filter_1, 0), (self.blocks_add_const_vxx_1, 0))    
        self.connect((self.low_pass_filter_2, 0), (self.blocks_add_const_vxx_2, 0))    
        self.connect((self.low_pass_filter_3, 0), (self.blocks_add_const_vxx_3, 0))    
        self.connect((self.low_pass_filter_4, 0), (self.blocks_add_const_vxx_4, 0))    
        self.connect((self.low_pass_filter_5, 0), (self.blocks_add_const_vxx_5, 0))    
Esempio n. 45
0
    def __do_connect(self):
        itemsize = self.__itemsize

        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(
                itemsize=output_length * gr.sizeof_float, nstreams=2)

        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(
            math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)

        self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length

        self.__gate = blocks.copy(itemsize)
        self.__gate.set_enabled(not self.__paused)

        overlapper = _OverlappedStreamToVector(size=input_length,
                                               factor=overlap_factor,
                                               itemsize=itemsize)

        self.__frame_dec = blocks.keep_one_in_n(
            itemsize=itemsize * input_length,
            n=max(
                1,
                int(
                    round(self.__frame_rate_to_decimation_conversion /
                          self.__frame_rate))))

        # the actual FFT logic, which is similar to GR's logpwrfft_c
        window = windows.build(self.__window_type, input_length, 6.76)
        window_power = sum(x * x for x in window)
        # TODO: use fft_vfc when applicable
        fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
            fft_size=input_length, forward=True, window=window)
        mag_squared = blocks.complex_to_mag_squared(input_length)
        logarithmizer = blocks.nlog10_ff(
            n=10,  # the "deci" in "decibel"
            vlen=input_length,
            k=(
                -to_dB(window_power) +  # compensate for window
                -to_dB(sample_rate)
                +  # convert from power-per-sample to power-per-Hz
                self.__power_offset  # offset for packing into bytes
            ))

        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(
            vlen=self.__freq_resolution, scale=1.0)

        fft_sink = self.__fft_cell.create_sink_internal(
            numpy.dtype((numpy.int8, output_length)))
        scope_sink = self.__scope_cell.create_sink_internal(
            numpy.dtype(('c8', self.__time_length)))
        scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)

        # connect everything
        self.__context.lock()
        try:
            self.disconnect_all()
            self.connect(self, self.__gate, overlapper, self.__frame_dec,
                         fft_block, mag_squared, logarithmizer)
            if self.__after_fft is not None:
                self.connect(logarithmizer, self.__after_fft)
                self.connect(self.__after_fft, self.__fft_converter, fft_sink)
                self.connect(
                    (self.__after_fft, 1),
                    blocks.null_sink(gr.sizeof_float * self.__freq_resolution))
            else:
                self.connect(logarithmizer, self.__fft_converter, fft_sink)
            if self.__enable_scope:
                self.connect(self.__gate, scope_chunker, scope_sink)
        finally:
            self.__context.unlock()
Esempio n. 46
0
    def __init__(self, rxPort=52002, txPort=52001):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Parameters
        ##################################################
        self.rxPort = rxPort
        self.txPort = txPort

        ##################################################
        # Variables
        ##################################################
        self.localOscillator = localOscillator = 14070000
        self.threshold = threshold = -200
        self.samp_rate = samp_rate = 48000
        self.rxPhase = rxPhase = .84
        self.rxMagnitude = rxMagnitude = 0.854
        self.freqFine = freqFine = 0
        self.freq = freq = localOscillator
        self.bandwidth = bandwidth = 50

        ##################################################
        # Blocks
        ##################################################
        _threshold_sizer = wx.BoxSizer(wx.VERTICAL)
        self._threshold_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_threshold_sizer,
        	value=self.threshold,
        	callback=self.set_threshold,
        	label="threshold",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._threshold_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_threshold_sizer,
        	value=self.threshold,
        	callback=self.set_threshold,
        	minimum=-500,
        	maximum=500,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_threshold_sizer)
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tuning")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "scope")
        self.Add(self.notebook_0)
        _freqFine_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freqFine_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_freqFine_sizer,
        	value=self.freqFine,
        	callback=self.set_freqFine,
        	label="Tuning",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._freqFine_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_freqFine_sizer,
        	value=self.freqFine,
        	callback=self.set_freqFine,
        	minimum=-500,
        	maximum=500,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_freqFine_sizer)
        _freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	label="Frequency",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._freq_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	minimum=localOscillator-samp_rate,
        	maximum=localOscillator+samp_rate,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_freq_sizer)
        _bandwidth_sizer = wx.BoxSizer(wx.VERTICAL)
        self._bandwidth_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_bandwidth_sizer,
        	value=self.bandwidth,
        	callback=self.set_bandwidth,
        	label="Signal Bandwidth",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._bandwidth_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_bandwidth_sizer,
        	value=self.bandwidth,
        	callback=self.set_bandwidth,
        	minimum=30,
        	maximum=5000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_bandwidth_sizer)
        self.wxgui_waterfallsink2_0_0_0 = waterfallsink2.waterfall_sink_c(
        	self.notebook_0.GetPage(1).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=125*8,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_waterfallsink2_0_0_0.win)
        self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c(
        	self.notebook_0.GetPage(0).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=125*8,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0_0.win)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.notebook_0.GetPage(0).GetWin(),
        	baseband_freq=localOscillator,
        	dynamic_range=100,
        	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.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0.win)
        self.low_pass_filter_0_1 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass(
        	1, samp_rate, 500, 500, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_0 = filter.interp_fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate, 30, 30, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass(
        	1, samp_rate, bandwidth, bandwidth, firdes.WIN_HAMMING, 6.76))
        self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(2, 0, cmath.pi/100.0, -0.5, 0.5, 0.25, 0.01, 125*8/31.25, 0.001, 0.001)
        self.blocks_transcendental_1 = blocks.transcendental("sin", "float")
        self.blocks_transcendental_0 = blocks.transcendental("cos", "float")
        self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_float*1, samp_rate)
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, 31.25)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(1e-12, 1e-12, 0)
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, int(samp_rate/31.25))
        self.blocks_null_source_1 = blocks.null_source(gr.sizeof_float*1)
        self.blocks_null_source_0_0 = blocks.null_source(gr.sizeof_float*1)
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float*1)
        self.blocks_multiply_xx_0_2 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_1 = 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_2 = blocks.multiply_const_vff((rxMagnitude, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((2, ))
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_1 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_0_1 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
        self.blocks_char_to_float_0 = blocks.char_to_float(1, 1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, ))
        self.blks2_tcp_source_0 = grc_blks2.tcp_source(
        	itemsize=gr.sizeof_char*1,
        	addr="127.0.0.1",
        	port=txPort,
        	server=False,
        )
        self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_char*1,
        	addr="127.0.0.1",
        	port=rxPort,
        	server=False,
        )
        self.audio_source_0 = audio.source(samp_rate, "", True)
        self.audio_sink_0 = audio.sink(samp_rate, "", True)
        self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(threshold, 1)
        self.analog_sig_source_x_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -freqFine, 1, 0)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq+freqFine-localOscillator, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, -(freq-localOscillator), 1, 0)
        self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, rxPhase*3.14159/180.0)
        self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
        self.analog_agc_xx_0.set_max_gain(65536)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blks2_tcp_source_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_char_to_float_0, 0))
        self.connect((self.blocks_char_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0), (self.low_pass_filter_0_0, 0))
        self.connect((self.blocks_throttle_0_1, 0), (self.blocks_float_to_complex_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.blocks_float_to_complex_0_1, 0), (self.blocks_multiply_xx_0_1, 1))
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_1, 0))
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_0, 0))
        self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_1, 0))
        self.connect((self.blocks_transcendental_1, 0), (self.blocks_float_to_complex_0_1, 1))
        self.connect((self.blocks_null_source_0, 0), (self.blocks_float_to_complex_1, 0))
        self.connect((self.audio_source_0, 0), (self.blocks_multiply_const_vxx_2, 0))
        self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_float_to_complex_1, 1))
        self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0_1, 0))
        self.connect((self.blocks_null_source_0_0, 0), (self.blocks_float_to_complex_1_0, 1))
        self.connect((self.audio_source_0, 1), (self.blocks_float_to_complex_1_0, 0))
        self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0_1, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0_0, 0))
        self.connect((self.blocks_null_source_1, 0), (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_throttle_0_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blks2_tcp_sink_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_threshold_ff_0, 0))
        self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.analog_simple_squelch_cc_0, 0), (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.analog_simple_squelch_cc_0, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.blocks_repeat_0, 0), (self.blocks_throttle_0_1, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_repeat_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_complex_to_float_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_xx_0_2, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0_2, 1))
        self.connect((self.blocks_multiply_xx_0_2, 0), (self.low_pass_filter_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_1, 0))
        self.connect((self.low_pass_filter_0_1, 0), (self.wxgui_waterfallsink2_0_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.analog_agc_xx_0, 0), (self.digital_mpsk_receiver_cc_0, 0))
        self.connect((self.analog_agc_xx_0, 0), (self.wxgui_waterfallsink2_0_0_0, 0))
        self.connect((self.blocks_complex_to_float_0, 0), (self.audio_sink_0, 1))
        self.connect((self.blocks_complex_to_float_0, 1), (self.audio_sink_0, 0))
        self.connect((self.blocks_throttle_0_0, 0), (self.wxgui_waterfallsink2_0, 0))
Esempio n. 47
0
    def __init__(self):
        gr.top_block.__init__(self, "rrc_filtering_comparison_test")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("rrc_filtering_comparison_test")
        qtgui.util.check_set_qss()
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio",
                                     "rrc_filtering_comparison_test")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.symbol_rate = symbol_rate = 4800
        self.orig_bit_delay = orig_bit_delay = 110
        self.channel_rate = channel_rate = 48000
        self.chan_delay = chan_delay = 55

        ##################################################
        # Blocks
        ##################################################
        self._orig_bit_delay_range = Range(0, 300, 1, 110, 200)
        self._orig_bit_delay_win = RangeWidget(self._orig_bit_delay_range,
                                               self.set_orig_bit_delay,
                                               'Original Bit Delay',
                                               "counter_slider", float)
        self.top_layout.addWidget(self._orig_bit_delay_win)
        self._chan_delay_range = Range(0, 200, 1, 55, 200)
        self._chan_delay_win = RangeWidget(self._chan_delay_range,
                                           self.set_chan_delay,
                                           'Channel Delay', "counter_slider",
                                           float)
        self.top_layout.addWidget(self._chan_delay_win)
        self.root_raised_cosine_filter_0_0_0 = filter.fir_filter_fff(
            1,
            firdes.root_raised_cosine(1, channel_rate, symbol_rate, 0.35,
                                      11 * int(channel_rate / symbol_rate)))
        self.root_raised_cosine_filter_0_0 = filter.fir_filter_fff(
            int(channel_rate / symbol_rate),
            firdes.root_raised_cosine(1, channel_rate, symbol_rate, 0.35,
                                      11 * int(channel_rate / symbol_rate)))
        self.root_raised_cosine_filter_0 = filter.interp_fir_filter_fff(
            int(channel_rate / symbol_rate),
            firdes.root_raised_cosine(int(channel_rate / symbol_rate),
                                      channel_rate, symbol_rate, 0.35,
                                      11 * int(channel_rate / symbol_rate)))
        self.qtgui_time_sink_x_0_1_0 = qtgui.time_sink_f(
            512,  #size
            48000,  #samp_rate
            'Nyquist Filter Test',  #name
            4  #number of inputs
        )
        self.qtgui_time_sink_x_0_1_0.set_update_time(0.5)
        self.qtgui_time_sink_x_0_1_0.set_y_axis(-4, 4)

        self.qtgui_time_sink_x_0_1_0.set_y_label('Level', "")

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

        if not True:
            self.qtgui_time_sink_x_0_1_0.disable_legend()

        labels = [
            'Original Bits', 'RC Channel Waveform',
            'RRC Recovered Filtered Waveform', 'Post Bits', '', '', '', '', '',
            ''
        ]
        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(4):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_1_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_1_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_1_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_1_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_1_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_1_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_1_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_1_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_1_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_1_0_win)
        self.p25_dibit_mapper_bf_0 = p25.dibit_mapper_bf(
            dibit_map=([1, 3, -1, -3]), log_level=logging.NOTSET, filename='')
        self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_fff(
            10, ((1, )))
        self.interp_fir_filter_xxx_0_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff(
            10, ((1, )))
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_int * 1,
                                                 symbol_rate, True)
        self.blocks_int_to_float_0 = blocks.int_to_float(1, 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_delay_0_1 = blocks.delay(gr.sizeof_float * 1,
                                             int(orig_bit_delay))
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_float * 1,
                                             int(chan_delay))
        self.analog_random_uniform_source_x_0 = analog.random_uniform_source_i(
            0, 4, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_uniform_source_x_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.qtgui_time_sink_x_0_1_0, 1))
        self.connect((self.blocks_delay_0_1, 0),
                     (self.qtgui_time_sink_x_0_1_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.p25_dibit_mapper_bf_0, 0))
        self.connect((self.blocks_int_to_float_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_int_to_float_0, 0))
        self.connect((self.interp_fir_filter_xxx_0, 0),
                     (self.qtgui_time_sink_x_0_1_0, 3))
        self.connect((self.interp_fir_filter_xxx_0_0, 0),
                     (self.blocks_delay_0_1, 0))
        self.connect((self.p25_dibit_mapper_bf_0, 0),
                     (self.interp_fir_filter_xxx_0_0, 0))
        self.connect((self.p25_dibit_mapper_bf_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.blocks_delay_0_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.root_raised_cosine_filter_0_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.root_raised_cosine_filter_0_0_0, 0))
        self.connect((self.root_raised_cosine_filter_0_0, 0),
                     (self.interp_fir_filter_xxx_0, 0))
        self.connect((self.root_raised_cosine_filter_0_0_0, 0),
                     (self.qtgui_time_sink_x_0_1_0, 2))
Esempio n. 48
0
def float_to_char(N):
    op = blocks.float_to_char()
    tb = helper(N, op, gr.sizeof_float, gr.sizeof_char, 1, 1)
    return tb
    def __init__(self):
        gr.top_block.__init__(self,
                              "Symbol Mapping Demo",
                              catch_exceptions=True)
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Symbol Mapping Demo")
        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", "symbol_mapping_demo")

        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 = 32000
        self.constellation_order = constellation_order = 6

        ##################################################
        # Blocks
        ##################################################
        self.symbolmapping_symbol_mapper_bc_0 = symbolmapping.symbol_mapper_bc(
            constellation_order, 'GRAY', True)
        self.symbolmapping_symbol_demapper_cf_0 = symbolmapping.symbol_demapper_cf(
            constellation_order, 'GRAY', 'snr')
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #samp_rate
            "",  #name
            2,  #number of inputs
            None  # parent
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 260)

        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(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)

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

        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            1024,  #size
            "",  #name
            1,  #number of inputs
            None  # parent
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                   qtgui.TRIG_SLOPE_POS, 0.0,
                                                   0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(False)
        self.qtgui_const_sink_x_0.enable_grid(False)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "red", "red", "red", "red", "red", "red", "red",
            "red"
        ]
        styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in range(1):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_const_sink_x_0_win = sip.wrapinstance(
            self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)
        self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate,
                                                 True)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_char_to_float_0_0 = blocks.char_to_float(1, -1)
        self.blocks_add_const_vxx_0 = blocks.add_const_ff(1)
        self.analog_random_uniform_source_x_0 = analog.random_uniform_source_b(
            0, 256, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_uniform_source_x_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_char_to_float_0_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.symbolmapping_symbol_mapper_bc_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_uchar_to_float_0_0, 0),
                     (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0),
                     (self.blocks_uchar_to_float_0_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.blocks_char_to_float_0_0, 0))
        self.connect((self.symbolmapping_symbol_demapper_cf_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.symbolmapping_symbol_mapper_bc_0, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.symbolmapping_symbol_mapper_bc_0, 0),
                     (self.symbolmapping_symbol_demapper_cf_0, 0))
Esempio n. 50
0
    def __init__(self):
        gr.top_block.__init__(self, "Rfile Non Rfnoc")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Rfile Non Rfnoc")
        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", "rfile_non_RFNoC")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 12.5e6
        self.fft_size = fft_size = 625
        self.num_ch = num_ch = 56
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 10.08e6
        self.window_power = window_power = sum(map(lambda x: x * x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "129.6.142.138"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (12.5e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6)
        self._samp_rate_labels = ("12.5e6", "15.36e6", "7.68e6", "3.84e6", "1.92e6")
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
            radio_button = Qt.QRadioButton(label)
            self._samp_rate_box.addWidget(radio_button)
            self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i))
        )
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i])
        )
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (56, 50, 25, 15, 8)
        self._num_ch_labels = ("56", "50", "25", "15", "8")
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
            radio_button = Qt.QRadioButton(label)
            self._num_ch_box.addWidget(radio_button)
            self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i))
        )
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (625, 1024, 512, 256, 128)
        self._fft_size_labels = ("625", "1024", "512", "256", "128")
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size" + ": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels:
            self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i))
        )
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.230.12", "129.6.142.181", "129.6.142.138")
        self._dest_host_labels = ("pwct1", "Naceur Laptop", "pwct5Desktop", "Pwct5")
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host + ": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels:
            self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i))
        )
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6)
        self._center_freq_labels = ("AT&T", "Verizon", "ChannelEmulator")
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq" + ": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels:
            self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i))
        )
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_center_freq(self._center_freq_options[i])
        )
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("addr=172.16.20.2", "")), uhd.stream_args(cpu_format="fc32", channels=range(1))
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(center_freq, 0)
        self.uhd_usrp_source_0.set_gain(rx_gain, 0)
        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)
        self.myblocks_sslsocket_sink_0 = myblocks.sslsocket_sink(
            num_ch,
            dest_host,
            "/home/naceur/Documents/spectrum_monitor_sensors/gr-myblocks/examples/utils/sensor.loc",
            "/home/naceur/Documents/spectrum_monitor_sensors/gr-myblocks/examples/utils/sensor.sys",
            "E6R16W5XS",
            "NaN",
            center_freq,
            ActualBW,
            meas_interval,
            0,
        )
        self.myblocks_bin_statistics_0 = myblocks.bin_statistics(num_ch, meas_period)
        self.myblocks_bin_aggregator_0 = myblocks.bin_aggregator(
            fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size
        )
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6)
        self._bandwidth_labels = ("10.08e6", "9e6", "4.5e6", "2.7e6", "1.08e6")
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth" + ": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels:
            self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i))
        )
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_float_to_char_0, 0), (self.myblocks_sslsocket_sink_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.myblocks_bin_aggregator_0, 0), (self.myblocks_bin_statistics_0, 0))
        self.connect((self.myblocks_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.myblocks_bin_aggregator_0, 0))
Esempio n. 51
0
    def __init__(self, fft_length, cp_length, snr, kstime, logging):
        ''' Maximum Likelihood OFDM synchronizer:
        J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation
        of Time and Frequency Offset in OFDM Systems," IEEE Trans.
        Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997.
        '''

        gr.hier_block2.__init__(self, "ofdm_sync_ml",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature

        self.input = blocks.add_const_cc(0)

        SNR = 10.0**(snr / 10.0)
        rho = SNR / (SNR + 1.0)
        symbol_length = fft_length + cp_length

        # ML Sync

        # Energy Detection from ML Sync

        self.connect(self, self.input)

        # Create a delay line
        self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length)
        self.connect(self.input, self.delay)

        # magnitude squared blocks
        self.magsqrd1 = blocks.complex_to_mag_squared()
        self.magsqrd2 = blocks.complex_to_mag_squared()
        self.adder = blocks.add_ff()

        moving_sum_taps = [rho / 2 for i in range(cp_length)]
        self.moving_sum_filter = filter.fir_filter_fff(1,moving_sum_taps)

        self.connect(self.input,self.magsqrd1)
        self.connect(self.delay,self.magsqrd2)
        self.connect(self.magsqrd1,(self.adder,0))
        self.connect(self.magsqrd2,(self.adder,1))
        self.connect(self.adder,self.moving_sum_filter)


        # Correlation from ML Sync
        self.conjg = blocks.conjugate_cc();
        self.mixer = blocks.multiply_cc();

        movingsum2_taps = [1.0 for i in range(cp_length)]
        self.movingsum2 = filter.fir_filter_ccf(1,movingsum2_taps)

        # Correlator data handler
        self.c2mag = blocks.complex_to_mag()
        self.angle = blocks.complex_to_arg()
        self.connect(self.input,(self.mixer,1))
        self.connect(self.delay,self.conjg,(self.mixer,0))
        self.connect(self.mixer,self.movingsum2,self.c2mag)
        self.connect(self.movingsum2,self.angle)

        # ML Sync output arg, need to find maximum point of this
        self.diff = blocks.sub_ff()
        self.connect(self.c2mag,(self.diff,0))
        self.connect(self.moving_sum_filter,(self.diff,1))

        #ML measurements input to sampler block and detect
        self.f2c = blocks.float_to_complex()
        self.pk_detect = blocks.peak_detector_fb(0.2, 0.25, 30, 0.0005)
        self.sample_and_hold = blocks.sample_and_hold_ff()

        # use the sync loop values to set the sampler and the NCO
        #     self.diff = theta
        #     self.angle = epsilon

        self.connect(self.diff, self.pk_detect)

        # The DPLL corrects for timing differences between CP correlations
        use_dpll = 0
        if use_dpll:
            self.dpll = gr.dpll_bb(float(symbol_length),0.01)
            self.connect(self.pk_detect, self.dpll)
            self.connect(self.dpll, (self.sample_and_hold,1))
        else:
            self.connect(self.pk_detect, (self.sample_and_hold,1))

        self.connect(self.angle, (self.sample_and_hold,0))

        ################################
        # correlate against known symbol
        # This gives us the same timing signal as the PN sync block only on the preamble
        # we don't use the signal generated from the CP correlation because we don't want
        # to readjust the timing in the middle of the packet or we ruin the equalizer settings.
        kstime = [k.conjugate() for k in kstime]
        kstime.reverse()
        self.kscorr = filter.fir_filter_ccc(1, kstime)
        self.corrmag = blocks.complex_to_mag_squared()
        self.div = blocks.divide_ff()

        # The output signature of the correlation has a few spikes because the rest of the
        # system uses the repeated preamble symbol. It needs to work that generically if
        # anyone wants to use this against a WiMAX-like signal since it, too, repeats.
        # The output theta of the correlator above is multiplied with this correlation to
        # identify the proper peak and remove other products in this cross-correlation
        self.threshold_factor = 0.1
        self.slice = blocks.threshold_ff(self.threshold_factor, self.threshold_factor, 0)
        self.f2b = blocks.float_to_char()
        self.b2f = blocks.char_to_float()
        self.mul = blocks.multiply_ff()

        # Normalize the power of the corr output by the energy. This is not really needed
        # and could be removed for performance, but it makes for a cleaner signal.
        # if this is removed, the threshold value needs adjustment.
        self.connect(self.input, self.kscorr, self.corrmag, (self.div,0))
        self.connect(self.moving_sum_filter, (self.div,1))

        self.connect(self.div, (self.mul,0))
        self.connect(self.pk_detect, self.b2f, (self.mul,1))
        self.connect(self.mul, self.slice)

        # Set output signals
        #    Output 0: fine frequency correction value
        #    Output 1: timing signal
        self.connect(self.sample_and_hold, (self,0))
        self.connect(self.slice, self.f2b, (self,1))


        if logging:
            self.connect(self.moving_sum_filter, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat"))
            self.connect(self.diff, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat"))
            self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat"))
            self.connect(self.corrmag, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat"))
            self.connect(self.kscorr, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat"))
            self.connect(self.div, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat"))
            self.connect(self.mul, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat"))
            self.connect(self.slice, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat"))
            self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat"))
            if use_dpll:
                self.connect(self.dpll, blocks.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat"))

            self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat"))
            self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor Bladerf")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor Bladerf")
        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", "MSOD_SSLSensor_BladeRF")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10e6
        self.fft_size = fft_size = 1000
        self.num_ch = num_ch = 50
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 9e6
        self.window_power = window_power = sum(map(lambda x: x * x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(
            bandwidth / num_ch / hz_per_bin)
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(
            1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "pwct5.ctl.nist.gov"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(
            fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (
            10e6,
            15.36e6,
            7.68e6,
            3.84e6,
            1.92e6,
        )
        self._samp_rate_labels = (
            "10e6",
            "15.36e6",
            "7.68e6",
            "3.84e6",
            "1.92e6",
        )
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
            radio_button = Qt.QRadioButton(label)
            self._samp_rate_box.addWidget(radio_button)
            self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._num_ch_options = (
            56,
            50,
            25,
            15,
            8,
        )
        self._num_ch_labels = (
            "56",
            "50",
            "25",
            "15",
            "8",
        )
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
            radio_button = Qt.QRadioButton(label)
            self._num_ch_box.addWidget(radio_button)
            self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._num_ch_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
            lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (
            1000,
            1024,
            512,
            256,
            128,
        )
        self._fft_size_labels = (
            "1000",
            "1024",
            "512",
            "256",
            "128",
        )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size" + ": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels:
            self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._fft_size_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
            lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._dest_host_options = (
            "pwct1.ctl.nist.gov",
            "129.6.230.12",
            "pwc8.ctl.nist.gov",
            "pwct5.ctl.nist.gov",
        )
        self._dest_host_labels = (
            "pwct1",
            "Naceur Laptop",
            "pwct5Desktop",
            "Pwct5",
        )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host + ": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels:
            self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._dest_host_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
            lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self._center_freq_options = (
            709.01e6,
            782e6,
            724e6,
            729e6,
        )
        self._center_freq_labels = (
            "AT&T",
            "Verizon",
            "ChannelEmulator",
            "HackRF Shifted Freq",
        )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq" + ": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels:
            self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._center_freq_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain,
                                        "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               "bladerf=0")
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(1, 0)
        self.osmosdr_source_0.set_iq_balance_mode(2, 0)
        self.osmosdr_source_0.set_gain_mode(True, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(32, 0)
        self.osmosdr_source_0.set_bb_gain(40, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(20e6, 0)

        self.msod_sensor_sslsocket_sink_0 = msod_sensor.sslsocket_sink(
            num_ch, dest_host,
            "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.loc",
            "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.sys",
            "HackRF", "NaN", center_freq, ActualBW, meas_interval, 0,
            samp_rate, False)
        self.msod_sensor_bin_statistics_0 = msod_sensor.bin_statistics(
            num_ch, meas_period)
        self.msod_sensor_bin_aggregator_0 = msod_sensor.bin_aggregator(
            fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW,
            channel_bw, [0] * fft_size, False)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(
            fft_size)
        self._bandwidth_options = (
            10.08e6,
            9e6,
            4.5e6,
            2.7e6,
            1.08e6,
        )
        self._bandwidth_labels = (
            "10.08e6",
            "9e6",
            "4.5e6",
            "2.7e6",
            "1.08e6",
        )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth" + ": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels:
            self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._bandwidth_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
            lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.msod_sensor_bin_aggregator_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.msod_sensor_sslsocket_sink_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.msod_sensor_bin_aggregator_0, 0),
                     (self.msod_sensor_bin_statistics_0, 0))
        self.connect((self.msod_sensor_bin_statistics_0, 0),
                     (self.blocks_nlog10_ff_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
Esempio n. 53
0
    def __init__(self):
        gr.top_block.__init__(self, "Meteor QPSK LRPT")

        ##################################################
        # Variables
        ##################################################
        self.freq = freq = 137900000
        self.symb_rate = symb_rate = 72000
        self.samp_rate = samp_rate = 128000
        self.doppler_freq = doppler_freq = freq
        self.sps = sps = (samp_rate * 1.0) / (symb_rate * 1.0)
        self.samp_rate_rtlsdr = samp_rate_rtlsdr = 1536000
        self.pll_alpha = pll_alpha = float(sys.argv[2])
        self.doppler_shift = doppler_shift = doppler_freq - freq
        self.decim = decim = 8
        self.clock_alpha = clock_alpha = .001
        self.bitstream_name = bitstream_name = sys.argv[1] + '.s'

        ##################################################
        # Blocks
        ##################################################
        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(
            1, firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.6, 361))
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
            interpolation=1,
            decimation=int(samp_rate_rtlsdr / samp_rate),
            taps=None,
            fractional_bw=None,
        )
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               '')
        self.osmosdr_source_0.set_sample_rate(samp_rate_rtlsdr)
        self.osmosdr_source_0.set_center_freq(freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(2, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(True, 0)
        self.osmosdr_source_0.set_gain(44, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)

        self.gpredict_doppler_0 = gpredict.doppler(self.set_doppler_freq,
                                                   "localhost", 4532, True)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(
            pll_alpha, 4, False)
        self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf(
            digital.constellation_calcdist(
                ([-1 - 1j, -1 + 1j, 1 + 1j, 1 - 1j]), ([0, 1, 3, 2]), 4,
                1).base())
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(
            sps, clock_alpha**2 / 4.0, 0.5, clock_alpha, 0.005)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 127)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                   bitstream_name, False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.analog_sig_source_x_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, doppler_shift, 1, 0)
        self.analog_rail_ff_0 = analog.rail_ff(-1, 1)
        self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0)
        self.analog_agc_xx_0.set_max_gain(4000)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.analog_rail_ff_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_constellation_soft_decoder_cf_1, 0))
        self.connect((self.digital_constellation_soft_decoder_cf_1, 0),
                     (self.analog_rail_ff_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.digital_costas_loop_cc_0, 0))
Esempio n. 54
0
    def __init__(self, large_sig_len=0.0015, signal_mult=2, freq=433866000):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.large_sig_len = large_sig_len
        self.signal_mult = signal_mult
        self.freq = freq

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 240000

        ##################################################
        # Blocks
        ##################################################
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(0.2, 1)
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(freq, 0)
        self.rtlsdr_source_0.set_freq_corr(-24, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(1, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(50, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate, 10000, 10000, firdes.WIN_HAMMING, 6.76))
        self.blocks_threshold_ff_2 = blocks.threshold_ff(0, 0, 0)
        self.blocks_threshold_ff_1 = blocks.threshold_ff(0, 0, 0)
        self.blocks_sub_xx_2 = blocks.sub_ff(1)
        self.blocks_sub_xx_1 = blocks.sub_ff(1)
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_socket_pdu_0 = blocks.socket_pdu("UDP_CLIENT", "localhost", "52001", 10000, False)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((signal_mult, ))
        self.blocks_moving_average_xx_1 = blocks.moving_average_ff(int(samp_rate*large_sig_len), 0.8/samp_rate/large_sig_len, 4000)
        self.blocks_float_to_char_1 = blocks.float_to_char(1, 1)
        self.blocks_float_to_char_0_0 = blocks.float_to_char(1, 1)
        self.blocks_delay_1 = blocks.delay(gr.sizeof_float*1, int(samp_rate*0.00005))
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, 1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.bitgate_triggered_bits_0 = bitgate.triggered_bits(int(samp_rate*large_sig_len*5), False)
        self.analog_rail_ff_1 = analog.rail_ff(0.001, 1)
        self.analog_rail_ff_0 = analog.rail_ff(0, 1)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.bitgate_triggered_bits_0, 'pdus'), (self.blocks_socket_pdu_0, 'pdus'))    
        self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0_0, 0))    
        self.connect((self.analog_rail_ff_1, 0), (self.blocks_multiply_const_vxx_1, 0))    
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.analog_rail_ff_1, 0))    
        self.connect((self.blocks_delay_0, 0), (self.blocks_sub_xx_0, 0))    
        self.connect((self.blocks_delay_1, 0), (self.blocks_float_to_char_1, 0))    
        self.connect((self.blocks_float_to_char_0_0, 0), (self.bitgate_triggered_bits_0, 1))    
        self.connect((self.blocks_float_to_char_1, 0), (self.bitgate_triggered_bits_0, 0))    
        self.connect((self.blocks_moving_average_xx_1, 0), (self.blocks_sub_xx_1, 1))    
        self.connect((self.blocks_moving_average_xx_1, 0), (self.blocks_sub_xx_2, 1))    
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_moving_average_xx_1, 0))    
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.single_pole_iir_filter_xx_0, 0))    
        self.connect((self.blocks_sub_xx_0, 0), (self.analog_rail_ff_0, 0))    
        self.connect((self.blocks_sub_xx_1, 0), (self.blocks_sub_xx_2, 0))    
        self.connect((self.blocks_sub_xx_1, 0), (self.blocks_threshold_ff_1, 0))    
        self.connect((self.blocks_sub_xx_2, 0), (self.blocks_threshold_ff_2, 0))    
        self.connect((self.blocks_threshold_ff_1, 0), (self.blocks_delay_0, 0))    
        self.connect((self.blocks_threshold_ff_1, 0), (self.blocks_sub_xx_0, 1))    
        self.connect((self.blocks_threshold_ff_2, 0), (self.blocks_delay_1, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_sub_xx_1, 0))    
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "usage: %prog [options] center_freq1 band_width1 [center_freq2 band_width2 ...]"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option(
            "-a",
            "--args",
            type="string",
            default="",
            help="UHD device 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 [default=%default]")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option(
            "",
            "--acquisition-period",
            type="eng_float",
            default=3,
            metavar="SECS",
            help=
            "time to delay (in seconds) after changing frequency [default=%default]"
        )
        parser.add_option(
            "",
            "--dwell-delay",
            type="eng_float",
            default=3,
            metavar="SECS",
            help=
            "time to dwell (in seconds) at a given frequency [default=%default]"
        )
        parser.add_option(
            "",
            "--meas-interval",
            type="eng_float",
            default=0.1,
            metavar="SECS",
            help=
            "interval over which to measure statistic (in seconds) [default=%default]"
        )
        parser.add_option(
            "-c",
            "--number-channels",
            type="int",
            default=100,
            help=
            "number of uniform channels for which to report power measurements [default=%default]"
        )
        parser.add_option(
            "-l",
            "--lo-offset",
            type="eng_float",
            default=0,
            metavar="Hz",
            help="lo_offset in Hz [default=half the sample rate]")
        parser.add_option("-F",
                          "--fft-size",
                          type="int",
                          default=1024,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("",
                          "--real-time",
                          action="store_true",
                          default=False,
                          help="Attempt to enable real-time scheduling")
        parser.add_option("-d",
                          "--dest-url",
                          type="string",
                          default="",
                          help="set destination url for posting data")
        parser.add_option("",
                          "--skip-DC",
                          action="store_true",
                          default=False,
                          help="skip the DC bin when mapping channels")

        (options, args) = parser.parse_args()
        if (len(args) < 2) or (len(args) % 2 == 1):
            parser.print_help()
            sys.exit(1)

        self.center_freq = []
        self.bandwidth = []
        for i in range(len(args) / 2):
            self.center_freq.append(eng_notation.str_to_num(args[2 * i]))
            self.bandwidth.append(eng_notation.str_to_num(args[2 * i + 1]))
        self.band_ind = len(self.center_freq) - 1

        if not options.real_time:
            realtime = False
        else:
            # Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        # build 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(options.samp_rate)
        usrp_rate = self.u.get_samp_rate()

        if usrp_rate != options.samp_rate:
            if usrp_rate < options.samp_rate:
                # create list of allowable rates
                samp_rates = self.u.get_samp_rates()
                rate_list = [0.0] * len(samp_rates)
                for i in range(len(rate_list)):
                    last_rate = samp_rates.pop()
                    rate_list[len(rate_list) - 1 - i] = last_rate.start()

# choose next higher rate
                rate_ind = rate_list.index(usrp_rate) + 1
                if rate_ind < len(rate_list):
                    self.u.set_samp_rate(rate_list[rate_ind])
                    usrp_rate = self.u.get_samp_rate()
                print "New actual sample rate =", usrp_rate / 1e6, "MHz"
            resamp = filter.fractional_resampler_cc(
                0.0, usrp_rate / options.samp_rate)

        self.samp_rate = options.samp_rate

        if (options.lo_offset):
            self.lo_offset = options.lo_offset
        else:
            self.lo_offset = usrp_rate / 2.0
            print "LO offset set to", self.lo_offset / 1e6, "MHz"

        self.fft_size = options.fft_size
        self.num_ch = options.number_channels
        self.acq_period = options.acquisition_period
        self.dwell_delay = options.dwell_delay

        self.head = blocks.head(gr.sizeof_gr_complex,
                                int(self.dwell_delay * usrp_rate))

        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        mywindow = filter.window.blackmanharris(self.fft_size)
        ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)
        window_power = sum(map(lambda x: x * x, mywindow))

        c2mag = blocks.complex_to_mag_squared(self.fft_size)

        self.bin2ch_map = [[0] * self.fft_size
                           for i in range(len(self.center_freq))]
        hz_per_bin = self.samp_rate / self.fft_size
        for i in range(len(self.center_freq)):
            channel_bw = hz_per_bin * round(
                self.bandwidth[i] / self.num_ch / hz_per_bin)
            self.bandwidth[i] = channel_bw * self.num_ch
            print "Actual width of band", i + 1, "is", self.bandwidth[
                i] / 1e6, "MHz."
            start_freq = self.center_freq[i] - self.bandwidth[i] / 2.0
            stop_freq = start_freq + self.bandwidth[i]
            for j in range(self.fft_size):
                fj = self.bin_freq(j, self.center_freq[i])
                if (fj >= start_freq) and (fj < stop_freq):
                    channel_num = int(
                        math.floor((fj - start_freq) / channel_bw)) + 1
                    self.bin2ch_map[i][j] = channel_num
            if options.skip_DC:
                self.bin2ch_map[i][(self.fft_size + 1) / 2 +
                                   1:] = self.bin2ch_map[i][(self.fft_size +
                                                             1) / 2:-1]
                self.bin2ch_map[i][(self.fft_size + 1) / 2] = 0
            if self.bandwidth[i] > self.samp_rate:
                print "Warning: Width of band", i + 1, "(" + str(
                    self.bandwidth[i] /
                    1e6), "MHz) is greater than the sample rate (" + str(
                        self.samp_rate / 1e6), "MHz)."

        self.aggr = myblocks.bin_aggregator_ff(self.fft_size, self.num_ch,
                                               self.bin2ch_map[0])

        meas_frames = max(1,
                          int(
                              round(options.meas_interval * self.samp_rate /
                                    self.fft_size)))  # in fft_frames
        self.meas_duration = meas_frames * self.fft_size / self.samp_rate
        print "Actual measurement duration =", self.meas_duration, "s"

        self.stats = myblocks.bin_statistics_ff(self.num_ch, meas_frames)

        # Divide magnitude-square by a constant to obtain power
        # in Watts.  Assumes unit of USRP source is volts.
        impedance = 50.0  # ohms
        Vsq2W_dB = -10.0 * math.log10(self.fft_size * window_power * impedance)

        # Convert from Watts to dBm.
        W2dBm = blocks.nlog10_ff(10.0, self.num_ch, 30.0 + Vsq2W_dB)

        f2c = blocks.float_to_char(self.num_ch, 1.0)

        self.dest_url = options.dest_url

        # file descriptor is set in main loop; use dummy value for now
        self.srvr = myblocks.file_descriptor_sink(self.num_ch * gr.sizeof_char,
                                                  0)

        self.connect(self.u, self.head)

        if usrp_rate > self.samp_rate:
            # insert resampler
            self.connect(self.head, resamp, s2v)
        else:
            self.connect(self.head, s2v)
        self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, f2c,
                     self.srvr)
        #self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, self.srvr)

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

        self.set_gain(options.gain)
        print "gain =", options.gain, "dB in range (%0.1f dB, %0.1f dB)" % (
            float(g.start()), float(g.stop()))
        self.atten = float(g.stop()) - options.gain
Esempio n. 56
0
    def __do_connect(self):
        itemsize = self.__itemsize
        
        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
        
        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)
        
        self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length
        
        self.__gate = blocks.copy(itemsize)
        self.__gate.set_enabled(not self.__paused)
        
        overlapper = _OverlappedStreamToVector(
            size=input_length,
            factor=overlap_factor,
            itemsize=itemsize)
        
        self.__frame_dec = blocks.keep_one_in_n(
            itemsize=itemsize * input_length,
            n=int(round(self.__frame_rate_to_decimation_conversion / self.__frame_rate)))
        
        # the actual FFT logic, which is similar to GR's logpwrfft_c
        window = windows.blackmanharris(input_length)
        window_power = sum(x * x for x in window)
        # TODO: use fft_vfc when applicable
        fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
            fft_size=input_length,
            forward=True,
            window=window)
        mag_squared = blocks.complex_to_mag_squared(input_length)
        logarithmizer = blocks.nlog10_ff(
            n=10,  # the "deci" in "decibel"
            vlen=input_length,
            k=(
                -to_dB(window_power) +  # compensate for window
                -to_dB(sample_rate) +  # convert from power-per-sample to power-per-Hz
                self.__power_offset  # offset for packing into bytes
            ))
        
        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(vlen=self.__freq_resolution, scale=1.0)
        
        self.__fft_sink = MessageDistributorSink(
            itemsize=output_length * gr.sizeof_char,
            context=self.__context,
            migrate=self.__fft_sink,
            notify=self.__update_interested)
    
        self.__scope_sink = MessageDistributorSink(
            itemsize=self.__time_length * gr.sizeof_gr_complex,
            context=self.__context,
            migrate=self.__scope_sink,
            notify=self.__update_interested)
        scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)

        # connect everything
        self.__context.lock()
        try:
            self.disconnect_all()
            self.connect(
                self,
                self.__gate,
                overlapper,
                self.__frame_dec,
                fft_block,
                mag_squared,
                logarithmizer)
            if self.__after_fft is not None:
                self.connect(logarithmizer, self.__after_fft)
                self.connect(self.__after_fft, self.__fft_converter, self.__fft_sink)
                self.connect((self.__after_fft, 1), blocks.null_sink(gr.sizeof_float * self.__freq_resolution))
            else:
                self.connect(logarithmizer, self.__fft_converter, self.__fft_sink)
            if self.__enable_scope:
                self.connect(
                    self.__gate,
                    scope_chunker,
                    self.__scope_sink)
        finally:
            self.__context.unlock()
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "usage: %prog [options] center_freq band_width"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-s", "--samp-rate", type="eng_float", default=10e6,
                          help="set sample rate: 8/10/12.5/16/20 MHz [default=%default]")
        parser.add_option("-g", "--rf-gain", type="eng_float", default=0,
                          help="set the overall gain in dB (default is midpoint)") #FIXME range?
        parser.add_option("", "--lna-gain", type="eng_float", default=24,
                          help="set RX IF gain in dB (default is midpoint): 0-40dB, 8dB steps")
        parser.add_option("", "--vga-gain", type="eng_float", default=32,
                          help="set BB gain in dB (default is midpoint): 0-62dB, 2dB steps")
        parser.add_option("", "--antenna", action="store_false", default=True,
                          help="Disable Antenna Port Power [default=%default]")
        parser.add_option("", "--bandwidth", type="eng_float", default=10e6,
                          help="Set the BB Filter Bandwidth in MHz: 1.75-28 MHz[default=%default]")
        parser.add_option("", "--g-mode", action="store_false", default=True,
                          help="set the gain mode[default=%default]")
        parser.add_option("", "--iq-balance", type="eng_float", default=2,
                          help="set the iq_balance_mode [default=%default]")
	parser.add_option("", "--dc-off", type="eng_float", default=1,
                          help="set the dc offset mode [default=%default]")

        parser.add_option("", "--meas-interval", type="eng_float",
                          default=0.1, metavar="SECS",
                          help="interval over which to measure statistic (in seconds) [default=%default]")
        parser.add_option("-c", "--number-channels", type="int", default=56,
                          help="number of uniform channels for which to report power measurements [default=%default]") 
        parser.add_option("-F", "--fft-size", type="int", default=1024,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("", "--real-time", action="store_true", default=False,
                          help="Attempt to enable real-time scheduling")
        parser.add_option("-d", "--dest-host", type="string", default="",
                          help="set destination host for sending data")
        parser.add_option("", "--skip-DC", action="store_true", default=False,
                          help="skip the DC bin when mapping channels")
        parser.add_option("", "--avoid-LO", action="store_true", default=False,
                          help="Avoid LO by sampling at higher rate, shift frequency and take only a desired chunk")

#        parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", 
#                          help="lo_offset in Hz [default=half the sample rate]")
#        parser.add_option("", "--tx-VGA-gain", type="eng_float", default=None,
#                          help="set TX IF gain in dB (default is midpoint): 0-47dB, 1dB steps")
        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.print_help()
            sys.exit(1)

	self.center_freq = eng_notation.str_to_num(args[0])
        if options.avoid_LO:
                self.center_freq = self.center_freq + options.samp_rate/4.0
		print "Avoiding LO...\nShifting center Frequency to", self.center_freq
	self.bandwidth = eng_notation.str_to_num(args[1])

        if not options.real_time:
            realtime = False
        else:
            # Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        # build graph
        self.u = osmosdr.source( args="numchan=" + str(1) + " " + "hackrf=0" )
        self.u.set_sample_rate(options.samp_rate)
        self.u.set_freq_corr(0, 0)
        self.u.set_dc_offset_mode(int(options.dc_off), 0)
        self.u.set_iq_balance_mode(int(options.iq_balance), 0)
	print "options.g_mode: ", options.g_mode
        self.u.set_gain_mode(options.g_mode, 0)
        self.u.set_gain(options.rf_gain, 0)
        self.u.set_if_gain(options.lna_gain, 0)
        self.u.set_bb_gain(options.vga_gain, 0)
        self.u.set_antenna("", 0)
        self.u.set_bandwidth(options.bandwidth, 0)

        #if hackrf_rate != options.samp_rate: #FIXME How to read back hackrf_rate
        #    if hackrf_rate < options.samp_rate:
        #        # create list of allowable rates
        #        samp_rates = self.u.get_samp_rates()
        #        rate_list = [0.0]*len(samp_rates)
        #        for i in range(len(rate_list)):
        #           last_rate = samp_rates.pop()
        #           rate_list[len(rate_list) - 1 - i] = last_rate.start()
        #       # choose next higher rate
        #       rate_ind = rate_list.index(hackrf_rate) + 1
        #       if rate_ind < len(rate_list):
        #           self.u.set_samp_rate(rate_list[rate_ind])
        #           hackrf_rate = self.u.get_samp_rate()
        #       print "New actual sample rate =", hackrf_rate/1e6, "MHz"
        #    resamp = filter.fractional_resampler_cc(0.0, hackrf_rate / options.samp_rate)
	
	self.samp_rate = options.samp_rate
        self.fft_size = options.fft_size
        self.num_ch = options.number_channels
        self.avoid_LO = options.avoid_LO 

        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        mywindow = filter.window.blackmanharris(self.fft_size)
        ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)
        window_power = sum(map(lambda x: x*x, mywindow))

        c2mag = blocks.complex_to_mag_squared(self.fft_size)
	self.bin2ch_map = [0] * self.fft_size
        hz_per_bin = self.samp_rate / self.fft_size
	print "\nhz_per_bin: ", hz_per_bin/1e3, "kHz"
	channel_bw = hz_per_bin * round(self.bandwidth / self.num_ch / hz_per_bin)
	print "RB Bandwidth: ", channel_bw/1e3, "kHz"
	self.bandwidth = channel_bw * self.num_ch
	print "Actual width of band is", self.bandwidth/1e6, "MHz."
        start_freq = self.center_freq - self.bandwidth/2.0
        #print "Initiallay set frequency range to: [",start_freq/1e6, "MHz-",stop_freq/1e6,"MHz ]"
        if options.avoid_LO:
                start_freq = (self.center_freq - options.samp_rate/4) - self.bandwidth/2.0
        stop_freq = start_freq + self.bandwidth
        if options.avoid_LO:
                print "Avoiding LO, frequencies are shifted to: [",start_freq/1e6, "MHz-",stop_freq/1e6,"MHz ]"

	for j in range(self.fft_size):
	    fj = self.bin_freq(j, self.center_freq)
	    if (fj >= start_freq) and (fj < stop_freq):
	        channel_num = int(math.floor((fj - start_freq) / channel_bw)) + 1
	        self.bin2ch_map[j] = channel_num
	if options.skip_DC:
	    self.bin2ch_map[(self.fft_size + 1) / 2 + 1:] = self.bin2ch_map[(self.fft_size + 1) / 2 : -1]
	    self.bin2ch_map[(self.fft_size + 1) / 2] = 0
	if self.bandwidth > self.samp_rate:
	    print "Warning: Width of band (" + str(self.bandwidth/1e6), "MHz) is greater than the sample rate (" + str(self.samp_rate/1e6), "MHz)."

	self.aggr = myblocks.bin_aggregator_ff(self.fft_size, self.num_ch, self.bin2ch_map)

        meas_frames = max(1, int(round(options.meas_interval * self.samp_rate / self.fft_size))) # in fft_frames
	self.meas_duration = meas_frames * self.fft_size / self.samp_rate
	print "Actual measurement duration =", self.meas_duration, "s"

        self.stats = myblocks.bin_statistics_ff(self.num_ch, meas_frames)

	# Divide magnitude-square by a constant to obtain power
	# in Watts.  Assumes unit of HackRF source is volts.
	impedance = 50.0   # ohms
	Vsq2W_dB = -10.0 * math.log10(self.fft_size * window_power * impedance)

	# Convert from Watts to dBm.
	W2dBm = blocks.nlog10_ff(10.0, self.num_ch, 30.0 + Vsq2W_dB)

	f2c = blocks.float_to_char(self.num_ch, 1.0)

	self.dest_host = options.dest_host

	# ssl socket is set in main loop; use dummy value for now
	self.srvr = myblocks.sslsocket_sink(numpy.int8, self.num_ch, 0)

	if options.samp_rate > self.samp_rate:
	    # insert resampler
	    self.connect(self.u, resamp, s2v)
	else:
	    self.connect(self.u, s2v)
	self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, f2c, self.srvr)
	#self.connect(s2v, ffter, c2mag, self.aggr, self.stats, W2dBm, self.srvr)

        g_start = 0
        g_stop  = 20
        # FIXME Find out the Gain range of HACK_RF
        if options.rf_gain is None:
            # if no gain was specified, use the mid-point in dB
            options.rf_gain = float(g_start+g_stop)/2.0
        self.set_gain(options.rf_gain)

        print "gain =", options.rf_gain, "dB in range (%0.1f dB, %0.1f dB)" % (float(g_start), float(g_stop))
	self.atten = float(g_stop) - options.rf_gain
Esempio n. 58
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.thresh = thresh = 900*10**-3
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        _thresh_sizer = wx.BoxSizer(wx.VERTICAL)
        self._thresh_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_thresh_sizer,
        	value=self.thresh,
        	callback=self.set_thresh,
        	label='thresh',
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._thresh_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_thresh_sizer,
        	value=self.thresh,
        	callback=self.set_thresh,
        	minimum=0,
        	maximum=1,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_thresh_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.GetWin(),
        	title="Scope Plot",
        	sample_rate=samp_rate,
        	v_scale=200*10**-3,
        	v_offset=0,
        	t_scale=100*10**-3,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=2,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit="Units",
        	minval=0,
        	maxval=1,
        	factor=1.0,
        	decimal_places=6,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=False,
        	avg_alpha=None,
        	label="Number Plot",
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.digital_glfsr_source_x_0 = digital.glfsr_source_b(6, True, 0, 1)
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(thresh, thresh, 0)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((0.5, ))
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=1280,
        	bits_per_symbol=1,
        )
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_UNIFORM, 0.5, 32)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_const_vxx_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_numbersink2_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_threshold_ff_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_xor_xx_0, 1))    
        self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_scopesink2_0, 1))    
        self.connect((self.blocks_throttle_0, 0), (self.blks2_error_rate_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_xor_xx_0, 0))    
        self.connect((self.blocks_xor_xx_0, 0), (self.blks2_error_rate_0, 1))    
        self.connect((self.digital_glfsr_source_x_0, 0), (self.blocks_throttle_0, 0))