def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Transmit900")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 320000

		##################################################
		# 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_samp_rate(samp_rate)
		self.uhd_usrp_sink_0.set_center_freq(900000000, 0)
		self.uhd_usrp_sink_0.set_gain(100, 0)
		self.gr_sig_source_x_0 = gr.sig_source_c(samp_rate, gr.GR_SIN_WAVE, 1000, 1, 0)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((16384, ))

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.uhd_usrp_sink_0, 0))
Ejemplo n.º 2
0
 def test_003_channel_no_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j,  1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     sink_chanest = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
     self.assertEqual(sink_chanest.data(), channel)
Ejemplo n.º 3
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan= gr.multiply_const_vcc(channel)
     noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude)
     add = gr.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = gr.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.pmt_c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
Ejemplo n.º 4
0
 def test_006_channel_and_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0,  1,  0, 1,  0,  -1, 0, 1,   0, -1,   0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0,  1, -1, 1,  -1,  1, 0, 1,  -1, -1,  -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp  = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.pmt_c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(sink.data(), tuple(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
Ejemplo n.º 5
0
 def test_001 (self):
   vlen = 128
   syms = 4
   
   freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0/vlen)
   
   fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2
   ifft = gr.fft_vcc(vlen, False, [], True)
   fft_scale = gr.multiply_const_vcc([1.0/vlen]*vlen)
       
   vec = numpy.array(numpy.zeros(vlen), numpy.complex)
   vec[vlen/2-vlen/4] = 1.0
   vec = concatenate([vec]*syms)
   
   src = gr.vector_source_c(vec)
   dst = gr.vector_sink_c()
   s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
   v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)
   
   eps = gr.vector_source_f([0.0]*syms)
   trig = gr.vector_source_b([1]*syms)
   
   self.fg.connect(src, s2v, ifft, (freq_shift,0))
   self.fg.connect(eps, (freq_shift,1))
   self.fg.connect(trig, (freq_shift,2))
   self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
   self.fg.run()
   
   self.assertComplexTuplesAlmostEqual(vec, numpy.array(dst.data()))
Ejemplo n.º 6
0
  def test_007 (self):
    vlen = 128
    syms = 4
    bin1 = vlen/2 + 2
    bin1_val = 1.0
        
    expec = numpy.array(numpy.zeros(vlen), numpy.complex)
    expec[bin1] = bin1_val
    expec = concatenate([expec]*syms)
    
    epsilon = [0.5]
    frame_trigger = numpy.concatenate([[1],[0]*(syms-1)])
    
    freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0/vlen)
    
    fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2
    fft_scale = gr.multiply_const_vcc([1.0/vlen]*vlen)    
    
    src = gr.sig_source_c(vlen, gr.GR_COS_WAVE, 1.5, 1.0, 0.0) 
    # bin vlen/2 + 1.5
    dst = gr.vector_sink_c()
    s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)
    
    eps = gr.vector_source_f(epsilon)
    trig = gr.vector_source_b(frame_trigger.tolist())
    
    self.fg.connect(src, s2v, (freq_shift,0))
    self.fg.connect(eps, (freq_shift,1))
    self.fg.connect(trig, (freq_shift,2))
    self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
    self.fg.run()

    self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5, 1e-5)  
Ejemplo n.º 7
0
    def __init__(self, serverip, serverport, clientname, packetsize,
                 simulation, samp_rate, center_freq, net_id,
                 device_addr, stream_args):
        gr.hier_block2.__init__(self, "sim_source_c",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        uhd_gate.__init__(self)
        self.simulation = simulation
        self.samp_rate = samp_rate
        self.typ = 'tx'
        if not self.simulation:
            self.usrp = uhd.usrp_sink(device_addr, stream_args)
                # TODO: Parameters
            self.connect(self, self.usrp)
        else:
            self.simsnk = sim_sink_cc(self, serverip, serverport, clientname,
                                      packetsize, samp_rate, center_freq,
                                      net_id)
#            self.tcp_sink = grc_blks2.tcp_sink(itemsize=gr.sizeof_gr_complex,
#                                               addr=serverip,
#                                               port=self.simsnk.get_dataport(),
#                                               server=False)
            self.tcp_sink = gr.udp_sink(itemsize=gr.sizeof_gr_complex,
                                        host=str(serverip),
                                        port=self.simsnk.get_dataport(),
                                        payload_size=1472,
                                        eof=False)
            self.gain_blk = gr.multiply_const_vcc((1, ))
            self.heartbeat = heart_beat(0.1, "", "")
            self.connect(self.heartbeat, (self.simsnk, 1))
            #self.connect(self, (simsnk, 0), self.tcp_sink)
            self.connect(self, self.gain_blk, (self.simsnk, 0))
            self.connect((self.simsnk, 0), self.tcp_sink)
Ejemplo n.º 8
0
	def __init__(self, infile="data", samp_rate=1000000, outfile="data.wav", amp=70):
		gr.top_block.__init__(self, "Analyze")

		##################################################
		# Parameters
		##################################################
		self.infile = infile
		self.samp_rate = samp_rate
		self.outfile = outfile
		self.amp = amp

		##################################################
		# Blocks
		##################################################
		self.gr_wavfile_sink_0 = gr.wavfile_sink(outfile, 3, samp_rate, 16)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((amp, ))
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, infile, False)
		self.gr_complex_to_mag_0 = gr.complex_to_mag(1)
		self.gr_complex_to_float_0 = gr.complex_to_float(1)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_float_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_mag_0, 0))
		self.connect((self.gr_complex_to_mag_0, 0), (self.gr_wavfile_sink_0, 2))
		self.connect((self.gr_complex_to_float_0, 1), (self.gr_wavfile_sink_0, 1))
		self.connect((self.gr_complex_to_float_0, 0), (self.gr_wavfile_sink_0, 0))
Ejemplo n.º 9
0
    def __init__(self):
        gr.top_block.__init__(self)
        print("=================="+str(gsm.__file__))
        (options, args) = self._process_options()
                
        self.tuner_callback = tuner(self)
        self.synchronizer_callback = synchronizer(self)
        self.options    = options
        
        self.args       = args
        if(self.options.arf>0):
            self.freq = 935000000 + self.options.arf*200000
        else:
            self.freq = 890000000 + (-1)*self.options.arf*200000	
        
        self.multiply_const = gr.multiply_const_vcc((self.options.multiply, ))
        self._set_rates()
        self.source = self._set_source_uhd()
        self.filtr = self._set_filter()
        self.interpolator = self._set_interpolator()
        self.receiver = self._set_receiver()
        self.converter = self._set_converter()
        self.sink = self._set_sink()
        

        
        #	self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, self.input_rate/10)
    	#self.usrp_simple_source_x_0 = grc_usrp.simple_source_c(which=0, side="A", rx_ant="RXA")
	    #self.usrp_simple_source_x_0.set_decim_rate(self.options.decim)
	    #self.usrp_simple_source_x_0.set_frequency(self.freq, verbose=True)
	    #self.usrp_simple_source_x_0.set_gain(self.options.gain)


        self.connect(self.source, self.multiply_const, self.filtr,  self.interpolator, self.receiver, self.converter, self.sink)
Ejemplo n.º 10
0
 def postProcessing(self, inSampRate, dxcFreq, sampRate):
     
     # xlating
     if dxcFreq != 0:
         xlateFilterTaps = firdes.low_pass(1, sampRate, sampRate / 2, sampRate / 10, firdes.WIN_HAMMING, 6.76)
         self.xlatingFilter = gr.freq_xlating_fir_filter_ccc(1, (xlateFilterTaps), 
             dxcFreq, 
             sampRate)
         print "i: xlating filter fixed to " + str(dxcFreq)
     else:
         self.xlatingFilter = gr.multiply_const_vcc((1, ))
         print "i: xlating filter not needed"
         
     # pfb resampler
     self.resamplerFactor = sampRate / inSampRate
     nphases = 32
     frac_bw = 0.45
     rs_taps = firdes.low_pass(nphases, nphases, frac_bw, 0.5 - frac_bw)
     self.resampler = blks2.pfb_arb_resampler_ccf(self.resamplerFactor, 
         (rs_taps), 
         nphases)
     print "i: re-sampler relation new_freq/old_freq = " + str(self.resamplerFactor)
     #EO instance variables
     
     self.isRTEnable = gr.enable_realtime_scheduling()
     if self.isRTEnable == gr.RT_OK:
         print "i: realtime enable: True"
     else:
         print "i: realtime enable: False"
     
     # Connections
     self.connect((self, 0), (self.resampler, 0), (self.xlatingFilter, 0), (self.tx, 0))
Ejemplo n.º 11
0
	def __init__(self, decim=16, N_id_1=134, N_id_2=0):
		grc_wxgui.top_block_gui.__init__(self, title="Sss Corr Gui")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.N_id_1 = N_id_1
		self.N_id_2 = N_id_2

		##################################################
		# Variables
		##################################################
		self.sss_start_ts = sss_start_ts = 10608 - 2048 - 144
		self.samp_rate = samp_rate = 30720e3/decim

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=200,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, 2048/decim)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate*decim)
		self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, 2048/decim)
		self.gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex*1, sss_start_ts)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((gen_sss_fd(N_id_1, N_id_2, 2048/decim).get_sss_conj_rev()))
		self.gr_integrate_xx_0 = gr.integrate_cc(2048/decim)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/traces/lte_02_796m_30720k_frame.cfile", True)
		self.gr_fft_vxx_0 = gr.fft_vcc(2048/decim, True, (window.blackmanharris(1024)), True, 1)
		self.gr_complex_to_mag_0 = gr.complex_to_mag(1)
		self.fir_filter_xxx_0 = filter.fir_filter_ccc(decim, (firdes.low_pass(1, decim*samp_rate, 550e3, 100e3)))

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0))
		self.connect((self.gr_fft_vxx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_vector_to_stream_0, 0))
		self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0))
		self.connect((self.gr_integrate_xx_0, 0), (self.gr_complex_to_mag_0, 0))
		self.connect((self.gr_complex_to_mag_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_skiphead_0, 0))
		self.connect((self.gr_skiphead_0, 0), (self.fir_filter_xxx_0, 0))
		self.connect((self.fir_filter_xxx_0, 0), (self.gr_stream_to_vector_0, 0))
Ejemplo n.º 12
0
    def __init__(self, samp_rate, small_buffers):
        gr.top_block.__init__(self, "Test1")


        ##################################################
        # Variables
        ##################################################
#        self.samp_rate = samp_rate = 32000
        self.lspace = lspace = 512

        ##################################################
        # Blocks
        ##################################################
        self.latency_tagger_0 = latency.tagger(gr.sizeof_gr_complex, lspace, "latency0")
        self.latency_probe_0 = latency.probe(gr.sizeof_gr_complex, ["latency0"])
        self.gr_vector_source_x_0 = gr.vector_source_c((0,1,2,3,4,5,6,7), True, 1)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
        self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((0, ))
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0, ))
        self.gr_head_0 = gr.head(gr.sizeof_gr_complex*1, nsamp)


        if small_buffers:
            for b in [self.gr_vector_source_x_0, self.gr_head_0, self.latency_tagger_0, self.gr_multiply_const_vxx_0, self.gr_multiply_const_vxx_1]:
                b.set_max_output_buffer(1*1024);
#            b.set_min_output_buffer(100*1024);
#            b.set_max_noutput_items(256);

        ##################################################
        # Connections
        ##################################################

        self.connect((self.gr_head_0, 0), (self.latency_tagger_0, 0))

        self.connect((self.gr_vector_source_x_0, 0), (self.gr_head_0, 0))

        self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_multiply_const_vxx_1, 0))

        self.connect((self.latency_tagger_0, 0), (self.gr_multiply_const_vxx_0, 0))

        self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_throttle_0, 0))

        self.connect((self.gr_throttle_0, 0), (self.latency_probe_0, 0))
Ejemplo n.º 13
0
  def __init__( self, vlen ):

    gr.hier_block2.__init__( self,
        "scaled_fft",
        gr.io_signature( 1, 1, gr.sizeof_gr_complex * vlen ),
        gr.io_signature( 1, 1, gr.sizeof_gr_complex * vlen ) )

    fft = gr.fft_vcc( vlen, True, [], True )
    fft_scale = gr.multiply_const_vcc( [1.0/vlen]*vlen )

    self.connect( self, fft, fft_scale, self )
Ejemplo n.º 14
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")
		_icon_path = "/home/pfb/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 16000000

		##################################################
		# Blocks
		##################################################
		self.M_Sequence = gr.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,   1,   1,   1,   1,  -1,   1,  -1,  -1,   1,  -1,   1,  -1,   1,  -1,  -1,  1,  -1,  -1,  -1,  -1,  -1,   1,  -1,  -1,  -1,  -1,   1,   1,   1,  -1,   1,   1,   1,   1,   1,  1,  -1,   1,   1,  -1,  -1,  -1,  -1,   1,   1,  -1,  -1,  -1,   1,  -1,  -1,   1,   1,  -1,  -1,  -1,  -1,  -1,   1,   1,  -1,   1,  -1,  -1,  -1,   1,  -1,   1,  -1,  -1,   1,   1,  -1,   1,  -1,  1,  -1,  -1,  -1,  -1,   1,  -1,   1,   1,   1,  -1,  -1,   1,   1,   1,   1,  -1,   1,  -1,   1,  1,   1,   1,   1,  -1,  -1,  -1,   1,   1,   1,  -1,  -1,   1,  -1,   1,  -1,  -1,  -1,   1,   1,  1,   1,  -1,  -1,  -1,  -1,   1,  -1,  -1,   1,  -1,  -1,   1,  -1,   1,   1,   1,   1,  -1,  -1,  1,  -1,  -1,  -1,   1,  -1,  -1,  -1,   1,   1,  -1,   1,   1,  -1,   1,   1,   1,  -1,  -1,  -1,  1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,  -1,   1,  -1,   1,   1,  -1,   1,   1,  -1,  -1,   1,  -1,  -1,   1,   1,   1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,   1,   1,  -1,   1,   1,  -1,   1,  -1,   1,   1,  -1,   1,  -1,  -1,   1,   1,   1,   1,   1,   1,   1,   1), True, 1)
		self.M_Sequence_Baseband_Modulator = blks2.dbpsk_mod(
			samples_per_symbol=2,
			excess_bw=0.35,
			gray_code=False,
			verbose=False,
			log=False,
		)
		self.blks2_dxpsk_mod_0 = blks2.dbpsk_mod(
			samples_per_symbol=2,
			excess_bw=0.35,
			gray_code=True,
			verbose=False,
			log=False,
		)
		self.gr_add_xx_0 = gr.add_vcc(1)
		self.gr_delay_0 = gr.delay(gr.sizeof_char*1, 16)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_gr_complex*1, "../M_Sequence_Baseband.cmplx")
		self.gr_float_to_char_0 = gr.float_to_char()
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0, ))
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_delay_0, 0), (self.blks2_dxpsk_mod_0, 0))
		self.connect((self.blks2_dxpsk_mod_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.M_Sequence_Baseband_Modulator, 0), (self.gr_add_xx_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.M_Sequence, 0), (self.gr_float_to_char_0, 0))
		self.connect((self.gr_float_to_char_0, 0), (self.M_Sequence_Baseband_Modulator, 0))
		self.connect((self.gr_float_to_char_0, 0), (self.gr_delay_0, 0))
Ejemplo n.º 15
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset / 2, max_offset / 2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [
         rand_range(min_chan_ampl, max_chan_ampl) *
         numpy.exp(1j * rand_range(0, 2 * numpy.pi))
         for x in range(fft_len)
     ]
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude)
     add = gr.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = gr.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(
         noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
         (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [
         0,
     ] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(
                 tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(
                 pmt.pmt_c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i],
                                    channel_est[i],
                                    places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est,
                                           -carr_offset_hat)))
Ejemplo n.º 16
0
	def __init__(self, input_path, sample_rate, output_path):
		gr.top_block.__init__(self)

		self.source = gr.file_source(
			gr.sizeof_gr_complex, input_path, False)
		self.lowpass_and_decimate = gr.fir_filter_ccf(
			8, firdes.low_pass(1, sample_rate, FREQ_SPACE, 100))
		self.lsb_tune = gr.freq_xlating_fir_filter_ccc(
			1, (1,), -FREQ_SPACE, sample_rate/8)
		self.boost_volume = gr.multiply_const_vcc((10, ))
		self.complex_to_real = gr.complex_to_real(1)
		self.sink = gr.wavfile_sink(output_path, 1, sample_rate/8, 16)

		self.connect((self.source, 0), (self.lowpass_and_decimate, 0))
		self.connect((self.lowpass_and_decimate, 0), (self.lsb_tune, 0))
		self.connect((self.lsb_tune, 0), (self.boost_volume, 0))
		self.connect((self.boost_volume, 0), (self.complex_to_real, 0))
		self.connect((self.complex_to_real, 0), (self.sink, 0))
Ejemplo n.º 17
0
    def __init__(self, app, samp_rate, inter, dec, filename):
        '''
        in:
            - app = object of type RXApp
            - samp_rate = sample rate in Hertz
            - inter = interpolation factor
            - dec = decimation factor
            - filename
            
        output
            - port 0 = MF
        '''
        gr.hier_block2.__init__(self, "RXData",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        
        # instance variables
        self.filename = filename
        self.isRecording = False
        self.app = app
        
        #  "bandpass" to new sample rate
        # cleaning the out-of-band interferences, low pass filter around the shape 
        lowPassTaps = firdes.low_pass(1, samp_rate, samp_rate/2, samp_rate/20, firdes.WIN_HAMMING, 6.76)
        self.lowPass = gr.multiply_const_vcc([1, ]) #gr.fir_filter_ccc(1, lowPassTaps)
        
        #Matched Filter
#        self.matched = gr.multiply_const_cc(1)   #RXMatchedFilter(1, 20, 1, 0.8, 10)
        
        # resampler after Matched-filter
        self.resampler = blks2.rational_resampler_ccc(
                interpolation=inter,
                decimation=dec,
                taps=None,
                fractional_bw=None,
        )
        
        # saving the IQ samples
        self.fileSink = gr.file_sink(gr.sizeof_gr_complex*1, self.filename) if(self.filename <> None and len(self.filename) > 0) else None
        
        #EO instance variables
        
        self.__makeConnections()
Ejemplo n.º 18
0
    def test_006(self):
        vlen = 128
        syms = 4
        bin1 = vlen / 2 - vlen / 4
        bin2 = vlen / 2 + vlen / 3
        bin1_val = 1.0j
        bin2_val = -1.0

        vec = numpy.array(numpy.zeros(vlen), numpy.complex)
        vec[bin1] = bin1_val
        vec[bin2] = bin2_val
        vec = concatenate([vec] * syms)

        epsilon = [1, -4, 5, 2]
        frame_trigger = [1] * syms

        expec = numpy.array(numpy.zeros(vlen * syms), numpy.complex)
        for i in range(syms):
            expec[bin1 + i * vlen + epsilon[i]] = bin1_val
            expec[bin2 + i * vlen + epsilon[i]] = bin2_val

        freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen)

        fft = gr.fft_vcc(vlen, True, [], True)  # natural order, dc = vlen / 2
        ifft = gr.fft_vcc(vlen, False, [], True)
        fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen)

        src = gr.vector_source_c(vec)
        dst = gr.vector_sink_c()
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        eps = gr.vector_source_f(epsilon)
        trig = gr.vector_source_b(frame_trigger)

        self.fg.connect(src, s2v, ifft, (freq_shift, 0))
        self.fg.connect(eps, (freq_shift, 1))
        self.fg.connect(trig, (freq_shift, 2))
        self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
        self.fg.run()

        self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5)
Ejemplo n.º 19
0
    def test_008(self):
        vlen = 128
        syms = 4
        bin1 = vlen / 2 + 4
        bin1_val = 1.0
        cp_length = vlen / 4

        expec = numpy.array(numpy.zeros(vlen), numpy.complex)
        expec[bin1] = bin1_val
        expec = concatenate([expec] * syms)

        epsilon = [-0.5]
        frame_trigger = numpy.concatenate([[1], [0] * (syms - 1)])

        freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen, cp_length)

        fft = gr.fft_vcc(vlen, True, [], True)  # natural order, dc = vlen / 2
        fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen)

        sampler = ofdm.vector_sampler(gr.sizeof_gr_complex, vlen)

        trigger_vec = concatenate([[0] * (vlen + cp_length - 1), [1]])
        trigger_vec = concatenate([trigger_vec] * syms)
        trigger = gr.vector_source_b(trigger_vec.tolist())

        src = gr.sig_source_c(vlen, gr.GR_COS_WAVE, 4.5, 1.0,
                              0.0)  # bin vlen/2 + 4.5
        dst = gr.vector_sink_c()
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        eps = gr.vector_source_f(epsilon)
        trig = gr.vector_source_b(frame_trigger.tolist())

        self.fg.connect(src, (sampler, 0))
        self.fg.connect(trigger, (sampler, 1))
        self.fg.connect(sampler, (freq_shift, 0))
        self.fg.connect(eps, (freq_shift, 1))
        self.fg.connect(trig, (freq_shift, 2))
        self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
        self.fg.run()

        self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5, 1e-5)
Ejemplo n.º 20
0
  def test_006 (self):
    vlen = 128
    syms = 4
    bin1 = vlen/2-vlen/4
    bin2 = vlen/2+vlen/3
    bin1_val = 1.0j
    bin2_val = -1.0
        
    vec = numpy.array(numpy.zeros(vlen), numpy.complex)
    vec[bin1] = bin1_val
    vec[bin2] = bin2_val
    vec = concatenate([vec]*syms)
    
    epsilon = [1,-4,5,2]
    frame_trigger = [1]*syms
    
    expec = numpy.array(numpy.zeros(vlen*syms), numpy.complex)
    for i in range(syms):
      expec[bin1+i*vlen+epsilon[i]] =  bin1_val
      expec[bin2+i*vlen+epsilon[i]] = bin2_val
    
    freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0/vlen)
    
    fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2
    ifft = gr.fft_vcc(vlen, False, [], True)
    fft_scale = gr.multiply_const_vcc([1.0/vlen]*vlen)    
    
    src = gr.vector_source_c(vec)
    dst = gr.vector_sink_c()
    s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)
    
    eps = gr.vector_source_f(epsilon)
    trig = gr.vector_source_b(frame_trigger)
    
    self.fg.connect(src, s2v, ifft, (freq_shift,0))
    self.fg.connect(eps, (freq_shift,1))
    self.fg.connect(trig, (freq_shift,2))
    self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
    self.fg.run()

    self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5)
Ejemplo n.º 21
0
 def test_004_channel_no_carroffset_1sym (self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2.5, 3, 2.5, 2, 2.5, 3, 2, 1, 1, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
Ejemplo n.º 22
0
    def __init__(self,
                 infile="data",
                 samp_rate=1000000,
                 outfile="data.wav",
                 amp=70):
        gr.top_block.__init__(self, "Analyze")

        ##################################################
        # Parameters
        ##################################################
        self.infile = infile
        self.samp_rate = samp_rate
        self.outfile = outfile
        self.amp = amp

        ##################################################
        # Blocks
        ##################################################
        self.gr_wavfile_sink_0 = gr.wavfile_sink(outfile, 3, samp_rate, 16)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((amp, ))
        self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex * 1,
                                               infile, False)
        self.gr_complex_to_mag_0 = gr.complex_to_mag(1)
        self.gr_complex_to_float_0 = gr.complex_to_float(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_float_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_mag_0, 0))
        self.connect((self.gr_complex_to_mag_0, 0),
                     (self.gr_wavfile_sink_0, 2))
        self.connect((self.gr_complex_to_float_0, 1),
                     (self.gr_wavfile_sink_0, 1))
        self.connect((self.gr_complex_to_float_0, 0),
                     (self.gr_wavfile_sink_0, 0))
Ejemplo n.º 23
0
 def test_005_both_1sym_force(self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     ref_symbol = (0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2.5, 3, 2.5, 2, 2.5, 3, 2, 1, 1, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, ref_symbol, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value),
                              channel)
Ejemplo n.º 24
0
  def test_002 (self):
    vlen = 128
    syms = 4
        
    vec = numpy.array(numpy.zeros(vlen), numpy.complex)
    vec[vlen/2-vlen/4] = 1.0
    vec = concatenate([vec]*syms)
    
    epsilon = [-1]
    frame_trigger = numpy.concatenate([[1],[0]*(syms-1)])    
    
    expec = numpy.array(numpy.zeros(vlen*syms), numpy.complex)
    for i in range(syms):
      expec[vlen/2-vlen/4+i*vlen+epsilon[0]] = 1.0
    
    freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0/vlen)
    
    fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2
    ifft = gr.fft_vcc(vlen, False, [], True)
    fft_scale = gr.multiply_const_vcc([1.0/vlen]*vlen)    
    
    src = gr.vector_source_c(vec)
    dst = gr.vector_sink_c()
    s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)
    
    eps = gr.vector_source_f(epsilon)
    trig = gr.vector_source_b(frame_trigger.tolist())
    
    self.fg.connect(src, s2v, ifft, (freq_shift,0))
    self.fg.connect(eps, (freq_shift,1))
    self.fg.connect(trig, (freq_shift,2))
    self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
    self.fg.run()

    self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-6)  
Ejemplo n.º 25
0
    def test_002(self):
        vlen = 128
        syms = 4

        vec = numpy.array(numpy.zeros(vlen), numpy.complex)
        vec[vlen / 2 - vlen / 4] = 1.0
        vec = concatenate([vec] * syms)

        epsilon = [-1]
        frame_trigger = numpy.concatenate([[1], [0] * (syms - 1)])

        expec = numpy.array(numpy.zeros(vlen * syms), numpy.complex)
        for i in range(syms):
            expec[vlen / 2 - vlen / 4 + i * vlen + epsilon[0]] = 1.0

        freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen)

        fft = gr.fft_vcc(vlen, True, [], True)  # natural order, dc = vlen / 2
        ifft = gr.fft_vcc(vlen, False, [], True)
        fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen)

        src = gr.vector_source_c(vec)
        dst = gr.vector_sink_c()
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        eps = gr.vector_source_f(epsilon)
        trig = gr.vector_source_b(frame_trigger.tolist())

        self.fg.connect(src, s2v, ifft, (freq_shift, 0))
        self.fg.connect(eps, (freq_shift, 1))
        self.fg.connect(trig, (freq_shift, 2))
        self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
        self.fg.run()

        self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-6)
Ejemplo n.º 26
0
	def __init__(self,
		sample_rate,
		ber_threshold=0,	# Above which to do search
		ber_smoothing=0,	# Alpha of BER smoother (0.01)
		ber_duration=0,		# Length before trying next combo
		ber_sample_decimation=1,
		settling_period=0,
		pre_lock_duration=0,
		#ber_sample_skip=0
		**kwargs):
		
		use_throttle = False
		base_duration = 1024
		if sample_rate > 0:
			use_throttle = True
			base_duration *= 4	# Has to be high enough for block-delay
		
		if ber_threshold == 0:
			ber_threshold = 512 * 4
		if ber_smoothing == 0:
			ber_smoothing = 0.01
		if ber_duration == 0:
			ber_duration = base_duration * 2 # 1000ms
		if settling_period == 0:
			settling_period = base_duration * 1 # 500ms
		if pre_lock_duration == 0:
			pre_lock_duration = base_duration * 2 #1000ms
		
		print "Creating Auto-FEC:"
		print "\tsample_rate:\t\t", sample_rate
		print "\tber_threshold:\t\t", ber_threshold
		print "\tber_smoothing:\t\t", ber_smoothing
		print "\tber_duration:\t\t", ber_duration
		print "\tber_sample_decimation:\t", ber_sample_decimation
		print "\tsettling_period:\t", settling_period
		print "\tpre_lock_duration:\t", pre_lock_duration
		print ""
		
		self.sample_rate = sample_rate
		self.ber_threshold = ber_threshold
		#self.ber_smoothing = ber_smoothing
		self.ber_duration = ber_duration
		self.settling_period = settling_period
		self.pre_lock_duration = pre_lock_duration
		#self.ber_sample_skip = ber_sample_skip
		
		self.data_lock = threading.Lock()

		gr.hier_block2.__init__(self, "auto_fec",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),			# Post MPSK-receiver complex input
			gr.io_signature3(3, 3, gr.sizeof_char, gr.sizeof_float, gr.sizeof_float))	# Decoded packed bytes, BER metric, lock
		
		self.input_watcher = auto_fec_input_watcher(self)
		default_xform = self.input_watcher.xform_lock
		
		self.gr_conjugate_cc_0 = gr.conjugate_cc()
		self.connect((self, 0), (self.gr_conjugate_cc_0, 0))	# Input
		
		self.blks2_selector_0 = grc_blks2.selector(
			item_size=gr.sizeof_gr_complex*1,
			num_inputs=2,
			num_outputs=1,
			input_index=default_xform.get_conjugation_index(),
			output_index=0,
		)
		self.connect((self.gr_conjugate_cc_0, 0), (self.blks2_selector_0, 0))
		self.connect((self, 0), (self.blks2_selector_0, 1))		# Input
		
		self.gr_multiply_const_vxx_3 = gr.multiply_const_vcc((0.707*(1+1j), ))
		self.connect((self.blks2_selector_0, 0), (self.gr_multiply_const_vxx_3, 0))
		
		self.gr_multiply_const_vxx_2 = gr.multiply_const_vcc((default_xform.get_rotation(), ))	# phase_mult
		self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_multiply_const_vxx_2, 0))
		
		self.gr_complex_to_float_0_0 = gr.complex_to_float(1)
		self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_complex_to_float_0_0, 0))
		
		self.gr_interleave_1 = gr.interleave(gr.sizeof_float*1)
		self.connect((self.gr_complex_to_float_0_0, 1), (self.gr_interleave_1, 1))
		self.connect((self.gr_complex_to_float_0_0, 0), (self.gr_interleave_1, 0))
		
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((1, ))	# invert
		self.connect((self.gr_interleave_1, 0), (self.gr_multiply_const_vxx_0, 0))
		
		self.baz_delay_2 = baz.delay(gr.sizeof_float*1, default_xform.get_puncture_delay())	# delay_puncture
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.baz_delay_2, 0))
		
		self.depuncture_ff_0 = baz.depuncture_ff((_puncture_matrices[self.input_watcher.puncture_matrix][1]))	# puncture_matrix
		self.connect((self.baz_delay_2, 0), (self.depuncture_ff_0, 0))
		
		self.baz_delay_1 = baz.delay(gr.sizeof_float*1, default_xform.get_viterbi_delay())	# delay_viterbi
		self.connect((self.depuncture_ff_0, 0), (self.baz_delay_1, 0))
		
		self.swap_ff_0 = baz.swap_ff(default_xform.get_viterbi_swap())	# swap_viterbi
		self.connect((self.baz_delay_1, 0), (self.swap_ff_0, 0))
		
		self.gr_decode_ccsds_27_fb_0 = gr.decode_ccsds_27_fb()
		
		if use_throttle:
			print "==> Using throttle at sample rate:", self.sample_rate
			self.gr_throttle_0 = gr.throttle(gr.sizeof_float, self.sample_rate)
			self.connect((self.swap_ff_0, 0), (self.gr_throttle_0, 0))
			self.connect((self.gr_throttle_0, 0), (self.gr_decode_ccsds_27_fb_0, 0))
		else:
			self.connect((self.swap_ff_0, 0), (self.gr_decode_ccsds_27_fb_0, 0))
		
		self.connect((self.gr_decode_ccsds_27_fb_0, 0), (self, 0))	# Output bytes
		
		self.gr_add_const_vxx_1 = gr.add_const_vff((-4096, ))
		self.connect((self.gr_decode_ccsds_27_fb_0, 1), (self.gr_add_const_vxx_1, 0))
		
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((-1, ))
		self.connect((self.gr_add_const_vxx_1, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self, 1))	# Output BER
		
		self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(ber_smoothing, 1)
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_single_pole_iir_filter_xx_0, 0))
		
		self.gr_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float, ber_sample_decimation)
		self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_keep_one_in_n_0, 0))
		
		self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0)	# Last param is const value
		if use_throttle:
			lock_throttle_rate = self.sample_rate // 16
			print "==> Using lock throttle rate:", lock_throttle_rate
			self.gr_throttle_1 = gr.throttle(gr.sizeof_float, lock_throttle_rate)
			self.connect((self.const_source_x_0, 0), (self.gr_throttle_1, 0))
			self.connect((self.gr_throttle_1, 0), (self, 2))
		else:
			self.connect((self.const_source_x_0, 0), (self, 2))
		
		self.msg_q = gr.msg_queue(2*256)	# message queue that holds at most 2 messages, increase to speed up process
		self.msg_sink = gr.message_sink(gr.sizeof_float, self.msg_q, dont_block=0)	# Block to speed up process
		self.connect((self.gr_keep_one_in_n_0, 0), self.msg_sink)
		
		self.input_watcher.start()
Ejemplo n.º 27
0
    def __init__(self,
                 freq_corr=0,
                 N_id_1=134,
                 avg_frames=1,
                 N_id_2=0,
                 decim=16):
        grc_wxgui.top_block_gui.__init__(self, title="Sss Corr2 Gui")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.freq_corr = freq_corr
        self.N_id_1 = N_id_1
        self.avg_frames = avg_frames
        self.N_id_2 = N_id_2
        self.decim = decim

        ##################################################
        # Variables
        ##################################################
        self.vec_half_frame = vec_half_frame = 30720 * 5 / decim
        self.samp_rate = samp_rate = 30720e3 / decim
        self.rot = rot = 0
        self.noise_level = noise_level = 0
        self.fft_size = fft_size = 2048 / decim

        ##################################################
        # Blocks
        ##################################################
        _rot_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rot_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            label='rot',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._rot_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_rot_sizer)
        _noise_level_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_level_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            label='noise_level',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_level_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            minimum=0,
            maximum=10,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_level_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
            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=2,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.gr_vector_to_stream_1 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_to_stream_0_2 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_to_stream_0_1 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_to_stream_0_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_to_stream_0 = gr.vector_to_stream(
            gr.sizeof_float * 1, fft_size)
        self.gr_vector_source_x_0_0_0 = gr.vector_source_c(
            (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size)
        self.gr_vector_source_x_0_0 = gr.vector_source_c(
            (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size)
        self.gr_vector_source_x_0 = gr.vector_source_c(
            (gen_sss_fd(N_id_1, N_id_2, fft_size).get_sss(True)), True,
            fft_size)
        self.gr_stream_to_vector_0_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_stream_to_vector_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_repeat_0 = gr.repeat(gr.sizeof_float * 1, fft_size)
        self.gr_null_sink_0_0 = gr.null_sink(gr.sizeof_gr_complex * 1)
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN,
                                                     noise_level, 0)
        self.gr_multiply_xx_1 = gr.multiply_vcc(1)
        self.gr_multiply_xx_0 = gr.multiply_vcc(fft_size)
        self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((1 / 1500., ))
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(
            (exp(rot * 2 * numpy.pi * 1j), ))
        self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex * fft_size)
        self.gr_integrate_xx_0 = gr.integrate_ff(fft_size)
        self.gr_float_to_complex_0_0 = gr.float_to_complex(1)
        self.gr_float_to_complex_0 = gr.float_to_complex(1)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True)
        self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False,
                                       (window.blackmanharris(1024)), True, 1)
        self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True,
                                       (window.blackmanharris(1024)), True, 1)
        self.gr_divide_xx_0_1 = gr.divide_cc(1)
        self.gr_divide_xx_0_0 = gr.divide_ff(1)
        self.gr_divide_xx_0 = gr.divide_cc(1)
        self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex *
                                                 fft_size)
        self.gr_conjugate_cc_1 = gr.conjugate_cc()
        self.gr_conjugate_cc_0 = gr.conjugate_cc()
        self.gr_complex_to_mag_squared_0_0 = gr.complex_to_mag_squared(1)
        self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(fft_size)
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.gr_add_const_vxx_0 = gr.add_const_vff((1, ))
        self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0)
        self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0),
                     (self.gr_stream_to_vector_0, 0))
        self.connect((self.gr_conjugate_cc_0, 0),
                     (self.gr_stream_to_vector_0_0, 0))
        self.connect((self.gr_stream_to_vector_0_0, 0),
                     (self.gr_multiply_xx_0, 1))
        self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_0, 0))
        self.connect((self.gr_multiply_xx_0, 0),
                     (self.gr_complex_to_mag_squared_0, 0))
        self.connect((self.gr_complex_to_mag_squared_0, 0),
                     (self.gr_vector_to_stream_0, 0))
        self.connect((self.gr_vector_to_stream_0, 0),
                     (self.gr_integrate_xx_0, 0))
        self.connect((self.gr_integrate_xx_0, 0), (self.gr_repeat_0, 0))
        self.connect((self.gr_multiply_xx_0, 0),
                     (self.gr_vector_to_stream_0_0, 0))
        self.connect((self.gr_vector_to_stream_0_1, 0),
                     (self.gr_multiply_xx_1, 1))
        self.connect((self.gr_divide_xx_0, 0), (self.gr_multiply_xx_1, 0))
        self.connect((self.gr_float_to_complex_0, 0), (self.gr_divide_xx_0, 1))
        self.connect((self.gr_conjugate_cc_1, 0), (self.gr_divide_xx_0, 0))
        self.connect((self.gr_deinterleave_0, 1),
                     (self.gr_vector_to_stream_0_1, 0))
        self.connect((self.gr_repeat_0, 0), (self.gr_float_to_complex_0, 0))
        self.connect((self.const_source_x_0, 0),
                     (self.gr_float_to_complex_0, 1))
        self.connect((self.gr_vector_to_stream_0_0, 0),
                     (self.gr_conjugate_cc_1, 0))
        self.connect((self.gr_vector_to_stream_0_0, 0),
                     (self.gr_complex_to_mag_squared_0_0, 0))
        self.connect((self.gr_complex_to_mag_squared_0_0, 0),
                     (self.gr_divide_xx_0_0, 0))
        self.connect((self.gr_repeat_0, 0), (self.gr_divide_xx_0_0, 1))
        self.connect((self.gr_divide_xx_0_0, 0), (self.gr_add_const_vxx_0, 0))
        self.connect((self.gr_add_const_vxx_0, 0),
                     (self.gr_float_to_complex_0_0, 0))
        self.connect((self.const_source_x_0_0, 0),
                     (self.gr_float_to_complex_0_0, 1))
        self.connect((self.gr_float_to_complex_0_0, 0),
                     (self.gr_divide_xx_0_1, 1))
        self.connect((self.gr_multiply_xx_1, 0), (self.gr_divide_xx_0_1, 0))
        self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0))
        self.connect((self.gr_fft_vxx_0, 0), (self.gr_deinterleave_0, 0))
        self.connect((self.gr_vector_to_stream_0_2, 0),
                     (self.gr_conjugate_cc_0, 0))
        self.connect((self.gr_divide_xx_0_1, 0), (self.gr_null_sink_0, 0))
        self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1))
        self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0))
        self.connect((self.gr_fft_vxx_1, 0), (self.gr_vector_to_stream_1, 0))
        self.connect((self.gr_vector_source_x_0_0, 0),
                     (self.gr_interleave_0, 0))
        self.connect((self.gr_vector_source_x_0_0_0, 0),
                     (self.gr_vector_to_stream_0_2, 0))
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.gr_vector_to_stream_1, 0), (self.gr_add_xx_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_vector_to_stream_0_1, 0),
                     (self.gr_multiply_const_vxx_1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_null_sink_0_0, 0))
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self.wxgui_scopesink2_0, 1))
        self.connect((self.gr_divide_xx_0_1, 0), (self.wxgui_scopesink2_0, 0))
Ejemplo n.º 28
0
	def __init__(self, N_id_1=134, N_id_2=0, decim=16, frames=1, gain=.08):
		grc_wxgui.top_block_gui.__init__(self, title="LTE DL synchronization signal")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.N_id_1 = N_id_1
		self.N_id_2 = N_id_2
		self.decim = decim
		self.frames = frames
		self.gain = gain

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 30720e3/decim
		self.fft_size = fft_size = 2048/decim
		self.N_re = N_re = 2048/decim

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0_2 = scopesink2.scope_sink_c(
			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=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0_2.win)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
			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=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.gr_vector_to_stream_1_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size+9)
		self.gr_vector_source_x_0_0_2_0_0 = gr.vector_source_c((gen_pss_td(N_id_2, N_re, 144).get_data()), True, fft_size+9)
		self.gr_vector_source_x_0_0_2_0 = gr.vector_source_c((gen_sss_td(N_id_1, N_id_2, True, N_re).get_data()), True, fft_size+9)
		self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size)
		self.gr_vector_source_x_0 = gr.vector_source_c((gen_sss_fd( N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size)
		self.gr_throttle_0_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.gr_null_sink_1 = gr.null_sink(gr.sizeof_gr_complex*1)
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1)
		self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vcc((1, ))
		self.gr_interleave_0_0 = gr.interleave(gr.sizeof_gr_complex*137)
		self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex*fft_size)
		self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1)
		self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(fft_size, fft_size+144/decim)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0))
		self.connect((self.gr_fft_vxx_1, 0), (self.digital_ofdm_cyclic_prefixer_0, 0))
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1))
		self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_interleave_0, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_null_sink_0, 0))
		self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.gr_null_sink_1, 0))
		self.connect((self.gr_vector_source_x_0_0_2_0, 0), (self.gr_interleave_0_0, 0))
		self.connect((self.gr_vector_source_x_0_0_2_0_0, 0), (self.gr_interleave_0_0, 1))
		self.connect((self.gr_interleave_0_0, 0), (self.gr_vector_to_stream_1_0_0, 0))
		self.connect((self.gr_vector_to_stream_1_0_0, 0), (self.gr_multiply_const_vxx_0_0, 0))
		self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.gr_throttle_0_0, 0))
		self.connect((self.gr_throttle_0_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.wxgui_scopesink2_0_2, 0))
Ejemplo n.º 29
0
 def setup_multiply_consts(self):
     print 'setup_multiply_consts'
     self.mlts = []
     for i in range(self.n_devices):
         self.mlts.append(gr.multiply_const_vcc((0.7, )))
Ejemplo n.º 30
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Fm Stereo Tx")

        ##################################################
        # Variables
        ##################################################
        self.st_gain = st_gain = 10
        self.samp_rate = samp_rate = 195.312e3
        self.pilot_gain = pilot_gain = 80e-3
        self.mpx_rate = mpx_rate = 160e3
        self.Mono_gain = Mono_gain = 300e-3
        self.FM_freq = FM_freq = 96.5e6

        ##################################################
        # Blocks
        ##################################################
        _st_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._st_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_st_gain_sizer,
            value=self.st_gain,
            callback=self.set_st_gain,
            label='st_gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._st_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_st_gain_sizer,
            value=self.st_gain,
            callback=self.set_st_gain,
            minimum=0,
            maximum=100,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_st_gain_sizer)
        _pilot_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pilot_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_pilot_gain_sizer,
            value=self.pilot_gain,
            callback=self.set_pilot_gain,
            label='pilot_gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pilot_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_pilot_gain_sizer,
            value=self.pilot_gain,
            callback=self.set_pilot_gain,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_pilot_gain_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), "FM")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "audio")
        self.Add(self.notebook_0)
        _Mono_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._Mono_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_Mono_gain_sizer,
            value=self.Mono_gain,
            callback=self.set_Mono_gain,
            label='Mono_gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._Mono_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_Mono_gain_sizer,
            value=self.Mono_gain,
            callback=self.set_Mono_gain,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_Mono_gain_sizer)
        _FM_freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._FM_freq_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_FM_freq_sizer,
            value=self.FM_freq,
            callback=self.set_FM_freq,
            label='FM_freq',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._FM_freq_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_FM_freq_sizer,
            value=self.FM_freq,
            callback=self.set_FM_freq,
            minimum=88e6,
            maximum=108e6,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_FM_freq_sizer)
        self.wxgui_fftsink2_1 = fftsink2.fft_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=FM_freq,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            device_addr="addr=192.168.10.2",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(FM_freq, 0)
        self.uhd_usrp_sink_0.set_gain(0, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.low_pass_filter_0 = gr.fir_filter_fff(
            1,
            firdes.low_pass(Mono_gain, mpx_rate, 15000, 2000,
                            firdes.WIN_HAMMING, 6.76))
        self.gr_vector_to_streams_0 = gr.vector_to_streams(
            gr.sizeof_short * 1, 2)
        self.gr_sub_xx_0 = gr.sub_ff(1)
        self.gr_sig_source_x_1 = gr.sig_source_f(160000, gr.GR_SIN_WAVE, 19000,
                                                 pilot_gain, 0)
        self.gr_sig_source_x_0 = gr.sig_source_f(160000, gr.GR_SIN_WAVE, 38000,
                                                 30e-3, 0)
        self.gr_short_to_float_1 = gr.short_to_float(1, 1)
        self.gr_short_to_float_0 = gr.short_to_float(1, 1)
        self.gr_multiply_xx_0 = gr.multiply_vff(1)
        self.gr_multiply_const_vxx_2 = gr.multiply_const_vcc((32.768e3, ))
        self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((30e-6, ))
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((30e-6, ))
        self.gr_frequency_modulator_fc_0 = gr.frequency_modulator_fc(980e-3)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_short * 2,
            "/home/kranthi/Documents/project/FM Transceiver/FM Transmitter/test.raw",
            True)
        self.gr_add_xx_1 = gr.add_vff(1)
        self.gr_add_xx_0 = gr.add_vff(1)
        self.blks2_rational_resampler_xxx_2 = blks2.rational_resampler_fff(
            interpolation=4,
            decimation=1,
            taps=None,
            fractional_bw=None,
        )
        self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_fff(
            interpolation=5,
            decimation=1,
            taps=None,
            fractional_bw=None,
        )
        self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
            interpolation=5,
            decimation=1,
            taps=None,
            fractional_bw=None,
        )
        self.blks2_fm_preemph_0 = blks2.fm_preemph(fs=mpx_rate, tau=50e-6)
        self.band_pass_filter_0 = gr.fir_filter_fff(
            1,
            firdes.band_pass(st_gain, mpx_rate, 23000, 53000, 2000,
                             firdes.WIN_HAMMING, 6.76))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0),
                     (self.gr_vector_to_streams_0, 0))
        self.connect((self.gr_vector_to_streams_0, 0),
                     (self.gr_short_to_float_0, 0))
        self.connect((self.gr_vector_to_streams_0, 1),
                     (self.gr_short_to_float_1, 0))
        self.connect((self.gr_short_to_float_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_short_to_float_1, 0),
                     (self.gr_multiply_const_vxx_1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.blks2_rational_resampler_xxx_0, 0))
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self.blks2_rational_resampler_xxx_1, 0))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.gr_add_xx_0, 1))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.gr_sub_xx_0, 1))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.gr_sub_xx_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.gr_add_xx_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 0))
        self.connect((self.gr_sub_xx_0, 0), (self.gr_multiply_xx_0, 1))
        self.connect((self.gr_multiply_xx_0, 0), (self.band_pass_filter_0, 0))
        self.connect((self.gr_sig_source_x_1, 0), (self.gr_add_xx_1, 0))
        self.connect((self.band_pass_filter_0, 0), (self.gr_add_xx_1, 1))
        self.connect((self.low_pass_filter_0, 0), (self.gr_add_xx_1, 2))
        self.connect((self.gr_add_xx_1, 0), (self.blks2_fm_preemph_0, 0))
        self.connect((self.blks2_fm_preemph_0, 0),
                     (self.blks2_rational_resampler_xxx_2, 0))
        self.connect((self.blks2_rational_resampler_xxx_2, 0),
                     (self.gr_frequency_modulator_fc_0, 0))
        self.connect((self.gr_frequency_modulator_fc_0, 0),
                     (self.gr_multiply_const_vxx_2, 0))
        self.connect((self.gr_multiply_const_vxx_2, 0),
                     (self.uhd_usrp_sink_0, 0))
        self.connect((self.gr_multiply_const_vxx_2, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self.wxgui_fftsink2_1, 0))
Ejemplo n.º 31
0
	def __init__(self, ahw="default", freq=150.0e6, ppm=0.0, vol=1.0, ftune=0.0, xftune=0.0, srate=1.0e6, upclo=0.0, devinfo="rtl=0", agc=0, arate=48.0e3, upce=0, mthresh=-10.0, offs=50.e3, flist="", dfifo="multimode_fifo", mbw=2.0e3, deemph=75.0e-6, dmode="NFM1"):
		grc_wxgui.top_block_gui.__init__(self, title="Multimode Radio Receiver")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.ahw = ahw
		self.freq = freq
		self.ppm = ppm
		self.vol = vol
		self.ftune = ftune
		self.xftune = xftune
		self.srate = srate
		self.upclo = upclo
		self.devinfo = devinfo
		self.agc = agc
		self.arate = arate
		self.upce = upce
		self.mthresh = mthresh
		self.offs = offs
		self.flist = flist
		self.dfifo = dfifo
		self.mbw = mbw
		self.deemph = deemph
		self.dmode = dmode

		##################################################
		# Variables
		##################################################
		self.sc_list_str = sc_list_str = flist
		self.zoom = zoom = 1
		self.thresh = thresh = mthresh
		self.scan_rate = scan_rate = 15
		self.scan_power = scan_power = 0
		self.sc_low = sc_low = 150e6
		self.sc_listm = sc_listm = False
		self.sc_list = sc_list = eval("["+sc_list_str+"]")
		self.sc_incr = sc_incr = 12.5e3
		self.sc_high = sc_high = 300e6
		self.sc_ena = sc_ena = False
		self.samp_rate = samp_rate = int(mh.get_good_rate(devinfo,srate))
		self.rf_power = rf_power = 0
		self.ifreq = ifreq = freq
		self.zoomed_lp = zoomed_lp = (samp_rate/2.1)/zoom
		self.wbfm = wbfm = 200e3
		self.rf_d_power = rf_d_power = 0
		self.mode = mode = dmode
		self.logpower = logpower = math.log10(rf_power+1.0e-14)*10.0
		self.cur_freq = cur_freq = mh.scan_freq_out(sc_ena,sc_low,sc_high,freq,ifreq,scan_power+1.0e-14,thresh,sc_incr,scan_rate,sc_listm,sc_list)
		self.bw = bw = mbw
		self.audio_int_rate = audio_int_rate = 40e3
		self.zoom_taps = zoom_taps = firdes.low_pass(1.0,samp_rate,zoomed_lp,zoomed_lp/3,firdes.WIN_HAMMING,6.76)
		self.xfine = xfine = xftune
		self.volume = volume = vol
		self.variable_static_text_1 = variable_static_text_1 = cur_freq
		self.variable_static_text_0_0 = variable_static_text_0_0 = samp_rate
		self.variable_static_text_0 = variable_static_text_0 = float(int(math.log10(rf_d_power+1.0e-14)*100.0)/10.0)
		self.upc_offset = upc_offset = upclo
		self.upc = upc = upce
		self.ssbo = ssbo = -bw/2 if mode == "LSB" else 0.0
		self.sc_list_len = sc_list_len = len(sc_list)
		self.rfgain = rfgain = 25
		self.record_file = record_file = "recording.wav"
		self.record = record = False
		self.offset = offset = offs
		self.muted = muted = 0.0 if logpower >= thresh else 1
		self.main_taps = main_taps = firdes.low_pass(1.0,wbfm,mh.get_mode_deviation(mode,bw)*1.05,mh.get_mode_deviation(mode,bw)/2.0,firdes.WIN_HAMMING,6.76)
		self.k = k = wbfm/(2*math.pi*mh.get_mode_deviation(mode,bw))
		self.iagc = iagc = agc
		self.freq_update = freq_update = 0
		self.fine = fine = ftune
		self.digi_rate = digi_rate = 50e3
		self.aratio = aratio = int(wbfm/audio_int_rate)

		##################################################
		# Blocks
		##################################################
		self.rf_probe = gr.probe_avg_mag_sqrd_c(0, 0.015)
		self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.Main.AddPage(grc_wxgui.Panel(self.Main), "Main Controls")
		self.Main.AddPage(grc_wxgui.Panel(self.Main), "Scan/Upconv Controls")
		self.Add(self.Main)
		self._zoom_chooser = forms.drop_down(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.zoom,
			callback=self.set_zoom,
			label="Spectral Zoom Ratio",
			choices=[1, 2, 5, 10, 20, 50, 100],
			labels=[],
		)
		self.Main.GetPage(0).GridAdd(self._zoom_chooser, 1, 4, 1, 1)
		_xfine_sizer = wx.BoxSizer(wx.VERTICAL)
		self._xfine_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_xfine_sizer,
			value=self.xfine,
			callback=self.set_xfine,
			label="Extra Fine Tuning",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._xfine_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_xfine_sizer,
			value=self.xfine,
			callback=self.set_xfine,
			minimum=-1.0e3,
			maximum=1.0e3,
			num_steps=200,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_xfine_sizer, 0, 3, 1, 1)
		_volume_sizer = wx.BoxSizer(wx.VERTICAL)
		self._volume_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_volume_sizer,
			value=self.volume,
			callback=self.set_volume,
			label="Volume",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._volume_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_volume_sizer,
			value=self.volume,
			callback=self.set_volume,
			minimum=1.0,
			maximum=10.0,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_volume_sizer, 0, 0, 1, 1)
		self._upc_offset_text_box = forms.text_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.upc_offset,
			callback=self.set_upc_offset,
			label="Upconv. LO Freq",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(1).GridAdd(self._upc_offset_text_box, 3, 2, 1, 2)
		self._upc_check_box = forms.check_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.upc,
			callback=self.set_upc,
			label="Ext. Upconv.",
			true=1,
			false=0,
		)
		self.Main.GetPage(1).GridAdd(self._upc_check_box, 3, 0, 1, 1)
		_rfgain_sizer = wx.BoxSizer(wx.VERTICAL)
		self._rfgain_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_rfgain_sizer,
			value=self.rfgain,
			callback=self.set_rfgain,
			label="RF Gain",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._rfgain_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_rfgain_sizer,
			value=self.rfgain,
			callback=self.set_rfgain,
			minimum=0,
			maximum=50,
			num_steps=200,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_rfgain_sizer, 2, 1, 1, 1)
		self._record_file_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.record_file,
			callback=self.set_record_file,
			label="Recording Filename",
			converter=forms.str_converter(),
		)
		self.Main.GetPage(0).GridAdd(self._record_file_text_box, 2, 3, 1, 3)
		self._record_check_box = forms.check_box(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.record,
			callback=self.set_record,
			label="Record",
			true=True,
			false=False,
		)
		self.Main.GetPage(0).GridAdd(self._record_check_box, 2, 2, 1, 1)
		_offset_sizer = wx.BoxSizer(wx.VERTICAL)
		self._offset_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_offset_sizer,
			value=self.offset,
			callback=self.set_offset,
			label="LO Offset",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._offset_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_offset_sizer,
			value=self.offset,
			callback=self.set_offset,
			minimum=25e3,
			maximum=500e3,
			num_steps=200,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_offset_sizer, 1, 3, 1, 1)
		self._mode_chooser = forms.drop_down(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.mode,
			callback=self.set_mode,
			label="Mode",
			choices=mh.get_modes_values(),
			labels=mh.get_modes_names(),
		)
		self.Main.GetPage(0).GridAdd(self._mode_chooser, 0, 4, 1, 1)
		self._iagc_check_box = forms.check_box(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.iagc,
			callback=self.set_iagc,
			label="AGC",
			true=1,
			false=0,
		)
		self.Main.GetPage(0).GridAdd(self._iagc_check_box, 2, 0, 1, 1)
		def _freq_update_probe():
			while True:
				val = self.rf_probe.level()
				try: self.set_freq_update(val)
				except AttributeError, e: pass
				time.sleep(1.0/(1.0/(2.5)))
		_freq_update_thread = threading.Thread(target=_freq_update_probe)
		_freq_update_thread.daemon = True
		_freq_update_thread.start()
		_fine_sizer = wx.BoxSizer(wx.VERTICAL)
		self._fine_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_fine_sizer,
			value=self.fine,
			callback=self.set_fine,
			label="Fine Tuning",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._fine_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_fine_sizer,
			value=self.fine,
			callback=self.set_fine,
			minimum=-35e3,
			maximum=35e3,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_fine_sizer, 0, 2, 1, 1)
		self.display_probe = gr.probe_avg_mag_sqrd_c(0, 0.002)
		_bw_sizer = wx.BoxSizer(wx.VERTICAL)
		self._bw_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_bw_sizer,
			value=self.bw,
			callback=self.set_bw,
			label="AM/SSB Bandwidth",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._bw_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_bw_sizer,
			value=self.bw,
			callback=self.set_bw,
			minimum=1.0e3,
			maximum=audio_int_rate/2,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_bw_sizer, 1, 2, 1, 1)
		self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
			self.Main.GetPage(0).GetWin(),
			baseband_freq=mh.get_last_returned(freq_update),
			dynamic_range=40,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=samp_rate/zoom,
			fft_size=1024,
			fft_rate=4,
			average=True,
			avg_alpha=None,
			title="Spectrogram",
			win=window.hamming,
		)
		self.Main.GetPage(0).Add(self.wxgui_waterfallsink2_0.win)
		def wxgui_waterfallsink2_0_callback(x, y):
			self.set_freq(x)
		
		self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.Main.GetPage(0).GetWin(),
			baseband_freq=mh.get_last_returned(freq_update),
			y_per_div=10,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=samp_rate/zoom,
			fft_size=1024,
			fft_rate=4,
			average=True,
			avg_alpha=0.1,
			title="Panorama",
			peak_hold=False,
			win=window.hamming,
		)
		self.Main.GetPage(0).Add(self.wxgui_fftsink2_0.win)
		def wxgui_fftsink2_0_callback(x, y):
			self.set_freq(x)
		
		self.wxgui_fftsink2_0.set_callback(wxgui_fftsink2_0_callback)
		self._variable_static_text_1_static_text = forms.static_text(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.variable_static_text_1,
			callback=self.set_variable_static_text_1,
			label="Current Scan Freq",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(1).GridAdd(self._variable_static_text_1_static_text, 0, 5, 1, 2)
		self._variable_static_text_0_0_static_text = forms.static_text(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.variable_static_text_0_0,
			callback=self.set_variable_static_text_0_0,
			label="Actual srate",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(0).GridAdd(self._variable_static_text_0_0_static_text, 1, 5, 1, 1)
		self._variable_static_text_0_static_text = forms.static_text(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.variable_static_text_0,
			callback=self.set_variable_static_text_0,
			label="RF Level",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(0).GridAdd(self._variable_static_text_0_static_text, 1, 0, 1, 1)
		_thresh_sizer = wx.BoxSizer(wx.VERTICAL)
		self._thresh_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_thresh_sizer,
			value=self.thresh,
			callback=self.set_thresh,
			label="Mute Threshold",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._thresh_slider = forms.slider(
			parent=self.Main.GetPage(0).GetWin(),
			sizer=_thresh_sizer,
			value=self.thresh,
			callback=self.set_thresh,
			minimum=-50,
			maximum=10,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Main.GetPage(0).GridAdd(_thresh_sizer, 1, 1, 1, 1)
		def _scan_power_probe():
			while True:
				val = self.rf_probe.level()
				try: self.set_scan_power(val)
				except AttributeError, e: pass
				time.sleep(1.0/(scan_rate))
		_scan_power_thread = threading.Thread(target=_scan_power_probe)
		_scan_power_thread.daemon = True
		_scan_power_thread.start()
		self._sc_low_text_box = forms.text_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_low,
			callback=self.set_sc_low,
			label="Scan Low",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(1).GridAdd(self._sc_low_text_box, 0, 1, 1, 1)
		self._sc_listm_check_box = forms.check_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_listm,
			callback=self.set_sc_listm,
			label="Scan List Mode",
			true=True,
			false=False,
		)
		self.Main.GetPage(1).GridAdd(self._sc_listm_check_box, 2, 0, 1, 1)
		self._sc_list_str_text_box = forms.text_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_list_str,
			callback=self.set_sc_list_str,
			label="Scan List",
			converter=forms.str_converter(),
		)
		self.Main.GetPage(1).GridAdd(self._sc_list_str_text_box, 2, 1, 1, 5)
		self._sc_incr_chooser = forms.drop_down(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_incr,
			callback=self.set_sc_incr,
			label="Scan Increment (Hz)",
			choices=[5.0e3,6.25e3,10.0e3,12.5e3,15e3,25e3],
			labels=[],
		)
		self.Main.GetPage(1).GridAdd(self._sc_incr_chooser, 0, 0, 1, 1)
		self._sc_high_text_box = forms.text_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_high,
			callback=self.set_sc_high,
			label="Scan High",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(1).GridAdd(self._sc_high_text_box, 0, 2, 1, 1)
		self._sc_ena_check_box = forms.check_box(
			parent=self.Main.GetPage(1).GetWin(),
			value=self.sc_ena,
			callback=self.set_sc_ena,
			label="Scan Enable",
			true=True,
			false=False,
		)
		self.Main.GetPage(1).GridAdd(self._sc_ena_check_box, 0, 3, 1, 1)
		def _rf_power_probe():
			while True:
				val = self.rf_probe.level()
				try: self.set_rf_power(val)
				except AttributeError, e: pass
				time.sleep(1.0/(10))
		_rf_power_thread = threading.Thread(target=_rf_power_probe)
		_rf_power_thread.daemon = True
		_rf_power_thread.start()
		def _rf_d_power_probe():
			while True:
				val = self.display_probe.level()
				try: self.set_rf_d_power(val)
				except AttributeError, e: pass
				time.sleep(1.0/(5))
		_rf_d_power_thread = threading.Thread(target=_rf_d_power_probe)
		_rf_d_power_thread.daemon = True
		_rf_d_power_thread.start()
		self.osmosdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + devinfo )
		self.osmosdr_source_c_0.set_sample_rate(samp_rate)
		self.osmosdr_source_c_0.set_center_freq(cur_freq+offset+(upc_offset*float(upc)), 0)
		self.osmosdr_source_c_0.set_freq_corr(ppm, 0)
		self.osmosdr_source_c_0.set_gain_mode(iagc, 0)
		self.osmosdr_source_c_0.set_gain(25 if iagc == 1 else rfgain, 0)
		self.osmosdr_source_c_0.set_if_gain(20, 0)
			
		self._ifreq_text_box = forms.text_box(
			parent=self.Main.GetPage(0).GetWin(),
			value=self.ifreq,
			callback=self.set_ifreq,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.Main.GetPage(0).GridAdd(self._ifreq_text_box, 0, 1, 1, 1)
		self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else record_file, 1, int(audio_int_rate), 8)
		self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(k)
		self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if mh.get_mode_type(mode) == "FM" else 0.0, ))
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0.0 if muted else volume/4.5, ))
		self.gr_multiply_const_vxx_0_0_0 = gr.multiply_const_vff((0.85 if mh.get_mode_type(mode) == "AM" else 0.0, ))
		self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((0.85 if mh.get_mode_type(mode) == "SSB" else 0.0, ))
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(((1.0/math.sqrt(mh.get_mode_deviation(mode,bw))*250), ))
		self.gr_keep_one_in_n_1 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, aratio)
		self.gr_keep_one_in_n_0_0 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, zoom)
		self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, int(wbfm/digi_rate))
		self.gr_freq_xlating_fir_filter_xxx_0_1 = gr.freq_xlating_fir_filter_ccc(1, (1.0, ), (offset+fine+xfine)/(samp_rate/1.0e6), samp_rate)
		self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, audio_int_rate/arate)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_gr_complex*1, "/dev/null" if mh.get_mode_type(mode) != "DIG" else dfifo)
		self.gr_file_sink_0.set_unbuffered(True)
		self.gr_fft_filter_xxx_3 = gr.fft_filter_ccc(1, (zoom_taps), 1)
		self.gr_fft_filter_xxx_2_0 = gr.fft_filter_fff(5, (firdes.low_pass(1.0,wbfm,14.5e3,8.5e3,firdes.WIN_HAMMING,6.76)), 1)
		self.gr_fft_filter_xxx_2 = gr.fft_filter_ccc(1, (main_taps), 1)
		self.gr_fft_filter_xxx_0 = gr.fft_filter_ccc(int(samp_rate/wbfm), (firdes.low_pass(1.0,samp_rate,98.5e3,66e3,firdes.WIN_HAMMING,6.76)), 1)
		self.gr_feedforward_agc_cc_0 = gr.feedforward_agc_cc(1024, 0.75)
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(1)
		self.gr_add_xx_0 = gr.add_vff(1)
		self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=audio_int_rate, tau=deemph)
		self.audio_sink_0 = audio.sink(int(arate), ahw, True)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink_0, 1))
		self.connect((self.gr_feedforward_agc_cc_0, 0), (self.gr_complex_to_mag_squared_0, 0))
		self.connect((self.osmosdr_source_c_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0_1, 0))
		self.connect((self.gr_multiply_const_vxx_0_0_0, 0), (self.gr_add_xx_0, 2))
		self.connect((self.gr_feedforward_agc_cc_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_multiply_const_vxx_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_0, 0))
		self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_multiply_const_vxx_0_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.display_probe, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.rf_probe, 0))
		self.connect((self.gr_add_xx_0, 0), (self.gr_fractional_interpolator_xx_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0_1, 0), (self.gr_fft_filter_xxx_0, 0))
		self.connect((self.gr_keep_one_in_n_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0_1, 0), (self.gr_fft_filter_xxx_3, 0))
		self.connect((self.gr_fft_filter_xxx_3, 0), (self.gr_keep_one_in_n_0_0, 0))
		self.connect((self.gr_keep_one_in_n_0_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_keep_one_in_n_0_0, 0), (self.wxgui_waterfallsink2_0, 0))
		self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_2, 0))
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_fft_filter_xxx_2_0, 0))
		self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_keep_one_in_n_0, 0))
		self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_fft_filter_xxx_2, 0))
		self.connect((self.gr_keep_one_in_n_1, 0), (self.gr_feedforward_agc_cc_0, 0))
		self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_keep_one_in_n_1, 0))
		self.connect((self.gr_fft_filter_xxx_2, 0), (self.gr_quadrature_demod_cf_0, 0))
		self.connect((self.gr_fft_filter_xxx_2_0, 0), (self.blks2_fm_deemph_0, 0))
Ejemplo n.º 32
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="DVB Simulator (GMSK)")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.signal = signal = 1
        self.samp_rate = samp_rate = 32000
        self.noise = noise = 10

        ##################################################
        # Blocks
        ##################################################
        _signal_sizer = wx.BoxSizer(wx.VERTICAL)
        self._signal_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_signal_sizer,
            value=self.signal,
            callback=self.set_signal,
            label="Signal",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._signal_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_signal_sizer,
            value=self.signal,
            callback=self.set_signal,
            minimum=0,
            maximum=1000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_signal_sizer)
        _noise_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_sizer,
            value=self.noise,
            callback=self.set_noise,
            label="Noise",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_sizer,
            value=self.noise,
            callback=self.set_noise,
            minimum=0,
            maximum=1000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_sizer)
        self.gr_wavfile_source_0 = gr.wavfile_source(
            "/home/traviscollins/GNURADIO/tfc_models/test.wav", False)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_float * 1, samp_rate)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise, 42)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((signal, ))
        self.gr_file_sink_1_0 = gr.file_sink(
            gr.sizeof_float * 1,
            "/home/traviscollins/GNURADIO/tfc_models/output_txt.wav")
        self.gr_file_sink_1_0.set_unbuffered(False)
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=20,
            frequency_offset=0.0,
            epsilon=1.0,
            taps=(1.0 + 1.0j, ),
            noise_seed=42,
        )
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
            samples_per_symbol=2,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.digital_gmsk_demod_0 = digital.gmsk_demod(
            samples_per_symbol=2,
            gain_mu=0.175,
            mu=0.5,
            omega_relative_limit=0.005,
            freq_error=0.0,
            verbose=False,
            log=False,
        )
        self.blks2_packet_encoder_0 = grc_blks2.packet_mod_f(
            grc_blks2.packet_encoder(
                samples_per_symbol=2,
                bits_per_symbol=1,
                access_code="",
                pad_for_usrp=True,
            ),
            payload_length=0,
        )
        self.blks2_packet_decoder_0 = grc_blks2.packet_demod_f(
            grc_blks2.packet_decoder(
                access_code="",
                threshold=-1,
                callback=lambda ok, payload: self.blks2_packet_decoder_0.
                recv_pkt(ok, payload),
            ), )
        self.audio_sink_0 = audio.sink(samp_rate, "", True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.gr_add_xx_0, 0), (self.digital_gmsk_demod_0, 0))
        self.connect((self.blks2_packet_encoder_0, 0),
                     (self.digital_gmsk_mod_0, 0))
        self.connect((self.digital_gmsk_mod_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.blks2_packet_encoder_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_1_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0),
                     (self.blks2_packet_decoder_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_channel_model_0, 0))
        self.connect((self.gr_channel_model_0, 0), (self.gr_add_xx_0, 0))
        self.connect((self.gr_wavfile_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.blks2_packet_decoder_0, 0), (self.audio_sink_0, 0))
Ejemplo n.º 33
0
    def __init__(self, modulator, demodulator, options, ll_logging, dev_log, start_tb_time, time_cal_timeout, start_controller_time):
        gr.top_block.__init__(self)
        
        # Get the modulation's bits_per_symbol
        args = modulator.extract_kwargs_from_options(options)
        symbol_rate = options.modulation_bitrate / modulator(**args).bits_per_symbol()
        
        # all subsequent code expects list of ints, so convert from 
        # comma separated string
        sink_addresses = options.sink_mac_addresses
        options.sink_mac_addresses = [int(x) for x in sink_addresses.split(',')]

        # Direct asynchronous notifications to callback function
        if True:#self.options.show_async_msg:
            self.async_msgq = gr.msg_queue(0)
            self.async_src = uhd.amsg_source("", self.async_msgq)
            self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)

        self.dev_log = dev_log
        
        # how much time should be spent calibrating time sync?
        self.cal_time = time_cal_timeout
      
        self.rx_channelizer = channelizer.rx_channelizer(options, dev_log)
        self.tx_channelizer = channelizer.tx_channelizer(options, dev_log)
        self.rx_channelizer.set_beacon_channel(options.gpsbug_cal_channel)
        upsampled_symbol_rate = symbol_rate*options.digital_freq_hop_num_channels
        upsample_factor_usrp = options.digital_freq_hop_num_channels

        #setting up USRP RX
        self.source = uhd_receiver(options.usrp_args, upsampled_symbol_rate,
                                       options.modulation_samples_per_symbol,
                                       options.rf_rx_freq, options.rf_rx_gain,
                                       options.usrp_spec, "RX2",
                                       options.verbose)
            
        #setting up USRP TX
        self.sink = uhd_transmitter(options.usrp_args, upsampled_symbol_rate,
                                        options.modulation_samples_per_symbol,
                                        options.rf_tx_freq, options.rf_tx_gain,
                                        options.usrp_spec, "TX/RX",
                                        options.verbose)

        if self.source._sps != options.modulation_samples_per_symbol:
            self.dev_log.warning("The USRP does not support the requested sample rate of %f. Using %f instead",
                                    options.modulation_samples_per_symbol*upsampled_symbol_rate,
                                    self.source._sps*upsampled_symbol_rate)

        options.modulation_samples_per_symbol = self.source._sps
        
        self.digital_scaling = gr.multiply_const_vcc((options.digital_scale_factor,))
        
        # moved down here (after reassignment of self.source._sps so we can use
        # the actual sample rate the UHD is using
        self.fs = options.modulation_samples_per_symbol*upsampled_symbol_rate/upsample_factor_usrp
        
        self.pmt_rpc = digital_ll.pmt_rpc(obj=self,result_msg=False)
        
        self.start_tb_time = start_tb_time
        self.start_controller_time = start_controller_time
        
        # this helps control dc tone problem (Use to be burst_gate now eob_shifter)
        # TODO: Only programmed for GMSK. Other modulations will need additional work.
        upsample_factor = 8*options.modulation_samples_per_symbol*options.digital_freq_hop_num_channels
        self.eob        = digital_ll.eob_shifter(upsample_factor)

        num_d_chans = options.digital_freq_hop_num_channels
      
        if  options.tx_access_code == '0':
            tx_access_code = None
        elif options.tx_access_code == '1':
            tx_access_code = '0000010000110001010011110100011100100101101110110011010101111110'
        elif options.tx_access_code == '2':
            tx_access_code = '1110001100101100010110110001110101100000110001011101000100001110'   
        else:
            tx_access_code = options.tx_access_code
            
        print 'tx access code: %s' % tx_access_code   
   
        self.packet_framer = digital_ll.packet_framer(
            fs=self.fs,
            samples_per_symbol=options.modulation_samples_per_symbol,
            bits_per_symbol=1,
            access_code=tx_access_code,
            number_digital_channels=num_d_chans
        )
        
        if options.node_role == "tdma_base":
            self.tdma_mac_sm = tdma_base_sm(options, self.sink, self.source, 
                                            self.packet_framer.num_bytes_to_num_samples)
            
            self.frame_sched = parse_frame_file(options.frame_file,start_controller_time, self.fs)
            
            for k, slot in enumerate(self.frame_sched["slots"]):
                self.frame_sched["slots"][k] = slot._replace()
                
                # replace the rf_freq field with the value of tx_freq from the ini or 
                # command line for the slots transmitted by the base
                if (slot.type == "downlink") or (slot.type == "beacon"):
                    self.frame_sched["slots"][k] = slot._replace(rf_freq=options.rf_tx_freq,
                                                                 tx_gain=options.rf_tx_gain,
                                                                 bw=self.fs)
                    
                # replace the rf_freq field with the value of rx_freq from the ini or 
                # command line for the slots received by the base
                elif slot.type == "uplink":
                    self.frame_sched["slots"][k] = slot._replace(rf_freq=options.rf_rx_freq,
                                                                 tx_gain=options.rf_tx_gain,
                                                                 bw=self.fs)
                    

                
                
        else:
            self.tdma_mac_sm = tdma_mobile_sm(options, self.sink, self.source,
                                              self.packet_framer.num_bytes_to_num_samples)
            self.frame_sched = None
        
                
        if self.tdma_mac_sm.is_base():
                
            manage_slots = base_slot_manager_ber_feedback(tdma_types_to_ints, 
                                                          initial_schedule=self.frame_sched,
                                                          options=options,
                                                          tdma_mac = self.tdma_mac_sm,)
            
            
        else:
                
            manage_slots = mobile_slot_manager_ber_feedback(tdma_types_to_ints, 
                                                            options=options,
                                                            tdma_mac = self.tdma_mac_sm,)

            
        self.dev_log.info("starting at time %s", start_tb_time)
        self.tdma_controller = tdma_controller(options=options, 
                                               mac_sm=self.tdma_mac_sm,
                                               manage_slots=manage_slots, 
                                               fs=self.fs, 
                                               mux_name="scheduled_mux",
                                               rx_channelizer_name="rx_channelizer",
                                               fhss_flag=1, 
                                               start_time=start_controller_time,
                                               )
        
        
        if options.traffic_generation == "infinite": 
            self.traffic = Infinite_Backlog_PDU_Streamer( options, 
                                                 self.tdma_controller.app_queue_size )
            self.msg_connect(self.traffic, "out_pkt_port", self.tdma_controller,'from_app')
        
        elif options.traffic_generation == "tunnel":
            self.traffic = Tunnel_Handler_PDU_Streamer(options)
            self.msg_connect(self.traffic, "out_pkt_port", self.tdma_controller,'from_app')
            self.msg_connect(self.tdma_controller,'to_app', self.traffic, "in_pkt_port")

        else:
            self.traffic = None

        
        self.tdma_logger = tdma_logger(ll_logging, upsample_factor_usrp)
        
        # set up receive path
        packet_rx_callback = self.tdma_controller.incoming_packet_callback
        self.rx_path = receive_path_gmsk(demodulator, packet_rx_callback, options, 
                                               log_index=-2, use_new_pkt=True)
   

   
        self.gmsk_mod = digital_ll.gmsk_mod(
            samples_per_symbol=options.modulation_samples_per_symbol,
            bt=options.bt,
            verbose=False,
            log=False,
        )
   
        # declare time tag shifters
        is_receive = True
        self.rx_time_tag_shifter = time_tag_shifter(is_receive, gr.sizeof_gr_complex)
        self.tx_time_tag_shifter = time_tag_shifter(not is_receive, gr.sizeof_gr_complex)
   
   
        # handle base node specific setup
        if self.tdma_mac_sm.is_base():
            t0 = time.time()
            t0_int = int(t0)-10
            t0_frac = t0-t0_int
            beacon_sched = (1,1,0,(t0_int, t0_frac),(t0_int, t0_frac))
            
            self.scheduled_mux = digital_ll.scheduled_mux(gr.sizeof_gr_complex,1,
                                                          self.fs, [beacon_sched])
 
            self.connect(self.source, self.rx_time_tag_shifter, self.rx_channelizer,self.scheduled_mux,self.rx_path) 
            
        # handle mobile node specific setup    
        else:
            t0 = time.time()
            t0_int = int(t0)-10
            t0_frac = t0-t0_int
            beacon_sched = (2.0,2.0,0,(t0_int, t0_frac),(t0_int, t0_frac))

            self.scheduled_mux = digital_ll.scheduled_mux(gr.sizeof_gr_complex,2,self.fs)
            self.rx_channelizer.switch_channels(options.gpsbug_cal_channel)
            # Set up receive path for beacon
            
            # set up beacon consumer
            self.beacon_consumer = beacon_consumer(options, overwrite_metadata=True)
            
            beacon_rx_callback = self.beacon_consumer.beacon_callback
            self.beacon_rx_path = receive_path_gmsk(demodulator, beacon_rx_callback, options,log_index=-1,use_new_pkt=True)
         
            self.connect(self.source, self.rx_time_tag_shifter,self.rx_channelizer,self.scheduled_mux,self.beacon_consumer)
            self.connect(self.scheduled_mux,self.beacon_rx_path)
            self.connect((self.scheduled_mux,1),self.rx_path)

            
            self.msg_connect(self.beacon_consumer, "sched_out", self.tdma_controller, "sched_in")
                    
                    
            # add in time tag shifter block message connections
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.rx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.tx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.tdma_mac_sm.cq_manager, 'time_tag_shift')
            

        self.connect(self.rx_channelizer,self.tdma_controller)
        self.connect(self.packet_framer, self.gmsk_mod, self.digital_scaling,
                     self.tx_channelizer, self.tx_time_tag_shifter, self.eob, self.sink)
            
            

            
        #self.connect(self.gmsk_mod, self.tdma_logger)
        self.connect(self.eob, self.tdma_logger)


        self.msg_connect(self.tdma_controller, "command_out", self.pmt_rpc, "in")
        self.msg_connect(self.tdma_controller, "outgoing_pkt", self.packet_framer, "in")   
        
        # store off params for logging 
        self.get_usrp_params(options)
Ejemplo n.º 34
0
    def __init__(self,
                 freq_corr=0,
                 avg_frames=1,
                 decim=16,
                 N_id_2=0,
                 N_id_1=134):
        grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.freq_corr = freq_corr
        self.avg_frames = avg_frames
        self.decim = decim
        self.N_id_2 = N_id_2
        self.N_id_1 = N_id_1

        ##################################################
        # Variables
        ##################################################
        self.vec_half_frame = vec_half_frame = 30720 * 5 / decim
        self.symbol_start = symbol_start = 144 / decim
        self.slot_0_10 = slot_0_10 = 1
        self.samp_rate = samp_rate = 30720e3 / decim
        self.rot = rot = 0
        self.noise_level = noise_level = 0
        self.fft_size = fft_size = 2048 / decim
        self.N_re = N_re = 62

        ##################################################
        # Blocks
        ##################################################
        _rot_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rot_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            label='rot',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._rot_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_rot_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), "SSS ML")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo")
        self.Add(self.notebook_0)
        _noise_level_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_level_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            label='noise_level',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_level_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            minimum=0,
            maximum=10,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_level_sizer)
        self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(3).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=2,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win)
        self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(2).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=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win)
        self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(1).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=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win)
        self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f(
            self.notebook_0.GetPage(0).GetWin(),
            title="Scope Plot",
            sample_rate=100 / avg_frames,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win)
        _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL)
        self._symbol_start_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_symbol_start_sizer,
            value=self.symbol_start,
            callback=self.set_symbol_start,
            label='symbol_start',
            converter=forms.int_converter(),
            proportion=0,
        )
        self._symbol_start_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_symbol_start_sizer,
            value=self.symbol_start,
            callback=self.set_symbol_start,
            minimum=0,
            maximum=144 / decim,
            num_steps=144 / decim,
            style=wx.SL_HORIZONTAL,
            cast=int,
            proportion=1,
        )
        self.Add(_symbol_start_sizer)
        self.sss_ml_fd_0 = sss_ml_fd(
            decim=decim,
            avg_frames=avg_frames,
            N_id_1=N_id_1,
            N_id_2=N_id_2,
            slot_0_10=slot_0_10,
        )
        self.pss_chan_est2_0 = pss_chan_est2(N_id_2=N_id_2, )
        self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_source_x_0_0_0 = gr.vector_source_c(
            (gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.gr_stream_to_vector_0_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_stream_to_vector_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex * 1,
                                             (N_re / 2, N_re / 2))
        self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex * 1)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN,
                                                     noise_level, 0)
        self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re)
        self.gr_multiply_xx_1 = gr.multiply_vcc(N_re)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(
            (0.005 * exp(rot * 2 * numpy.pi * 1j), ))
        self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex,
                                                 N_re / 2, fft_size,
                                                 (fft_size - N_re) / 2 - 1)
        self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2,
                                               fft_size, (fft_size) / 2)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile",
            True)
        self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True,
                                       (window.blackmanharris(1024)), True, 1)
        self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * N_re)
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=0.005 * noise_level,
            frequency_offset=0.0,
            epsilon=1,
            taps=(0.005 * exp(rot * 2 * numpy.pi * 1j), ),
            noise_seed=0,
        )
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.blks2_selector_0_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=2,
            num_outputs=1,
            input_index=0,
            output_index=0,
        )
        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=3,
            num_outputs=2,
            input_index=0,
            output_index=0,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0))
        self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0))
        self.connect((self.gr_channel_model_0, 0),
                     (self.blks2_selector_0_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.blks2_selector_0_0, 1))
        self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0))
        self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_deinterleave_0, 0),
                     (self.gr_vector_to_stream_0_0_0, 0))
        self.connect((self.gr_vector_to_stream_0_0_0, 0),
                     (self.wxgui_scopesink2_0_1_0_0, 0))
        self.connect((self.gr_vector_to_stream_0_0, 0),
                     (self.wxgui_scopesink2_0_1_0, 0))
        self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0))
        self.connect((self.gr_vector_to_stream_0, 0),
                     (self.gr_keep_m_in_n_0, 0))
        self.connect((self.gr_stream_to_vector_0_0, 0),
                     (self.gr_deinterleave_0, 0))
        self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0))
        self.connect((self.gr_vector_to_stream_0_0_1, 0),
                     (self.wxgui_scopesink2_0_1_0_1, 0))
        self.connect((self.gr_vector_to_stream_0_0_1_0, 0),
                     (self.wxgui_scopesink2_0_1_0_1, 1))
        self.connect((self.gr_vector_source_x_0_0_0, 0),
                     (self.gr_vector_to_stream_0_0_1_0, 0))
        self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1))
        self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0))
        self.connect((self.gr_multiply_xx_1, 0),
                     (self.gr_vector_to_stream_0_0, 0))
        self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0))
        self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1))
        self.connect((self.gr_multiply_xx_1_0, 0),
                     (self.gr_vector_to_stream_0_0_1, 0))
        self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0))
        self.connect((self.gr_vector_to_stream_0, 0),
                     (self.gr_keep_m_in_n_0_0, 0))
        self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0))
        self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1))
        self.connect((self.gr_stream_mux_0, 0),
                     (self.gr_stream_to_vector_0_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0))
        self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1))
        self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2))
        self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0))
        self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
Ejemplo n.º 35
0
 def test_multiply_const_vcc_one(self):
     src_data = (1.0 + 2.0j, )
     op = gr.multiply_const_vcc((2.0 + 3.0j, ))
     exp_data = (-4.0 + 7.0j, )
     self.help_const_cc(src_data, exp_data, op)
Ejemplo n.º 36
0
    def __init__(
            self,
            sample_rate,
            ber_threshold=0,  # Above which to do search
            ber_smoothing=0,  # Alpha of BER smoother (0.01)
            ber_duration=0,  # Length before trying next combo
            ber_sample_decimation=1,
            settling_period=0,
            pre_lock_duration=0,
            #ber_sample_skip=0
            **kwargs):

        use_throttle = False
        base_duration = 1024
        if sample_rate > 0:
            use_throttle = True
            base_duration *= 4  # Has to be high enough for block-delay

        if ber_threshold == 0:
            ber_threshold = 512 * 4
        if ber_smoothing == 0:
            ber_smoothing = 0.01
        if ber_duration == 0:
            ber_duration = base_duration * 2  # 1000ms
        if settling_period == 0:
            settling_period = base_duration * 1  # 500ms
        if pre_lock_duration == 0:
            pre_lock_duration = base_duration * 2  #1000ms

        print "Creating Auto-FEC:"
        print "\tsample_rate:\t\t", sample_rate
        print "\tber_threshold:\t\t", ber_threshold
        print "\tber_smoothing:\t\t", ber_smoothing
        print "\tber_duration:\t\t", ber_duration
        print "\tber_sample_decimation:\t", ber_sample_decimation
        print "\tsettling_period:\t", settling_period
        print "\tpre_lock_duration:\t", pre_lock_duration
        print ""

        self.sample_rate = sample_rate
        self.ber_threshold = ber_threshold
        #self.ber_smoothing = ber_smoothing
        self.ber_duration = ber_duration
        self.settling_period = settling_period
        self.pre_lock_duration = pre_lock_duration
        #self.ber_sample_skip = ber_sample_skip

        self.data_lock = threading.Lock()

        gr.hier_block2.__init__(
            self,
            "auto_fec",
            gr.io_signature(
                1, 1,
                gr.sizeof_gr_complex),  # Post MPSK-receiver complex input
            gr.io_signature3(
                3, 3, gr.sizeof_char, gr.sizeof_float,
                gr.sizeof_float))  # Decoded packed bytes, BER metric, lock

        self.input_watcher = auto_fec_input_watcher(self)
        default_xform = self.input_watcher.xform_lock

        self.gr_conjugate_cc_0 = gr.conjugate_cc()
        self.connect((self, 0), (self.gr_conjugate_cc_0, 0))  # Input

        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=2,
            num_outputs=1,
            input_index=default_xform.get_conjugation_index(),
            output_index=0,
        )
        self.connect((self.gr_conjugate_cc_0, 0), (self.blks2_selector_0, 0))
        self.connect((self, 0), (self.blks2_selector_0, 1))  # Input

        self.gr_multiply_const_vxx_3 = gr.multiply_const_vcc(
            (0.707 * (1 + 1j), ))
        self.connect((self.blks2_selector_0, 0),
                     (self.gr_multiply_const_vxx_3, 0))

        self.gr_multiply_const_vxx_2 = gr.multiply_const_vcc(
            (default_xform.get_rotation(), ))  # phase_mult
        self.connect((self.gr_multiply_const_vxx_3, 0),
                     (self.gr_multiply_const_vxx_2, 0))

        self.gr_complex_to_float_0_0 = gr.complex_to_float(1)
        self.connect((self.gr_multiply_const_vxx_2, 0),
                     (self.gr_complex_to_float_0_0, 0))

        self.gr_interleave_1 = gr.interleave(gr.sizeof_float * 1)
        self.connect((self.gr_complex_to_float_0_0, 1),
                     (self.gr_interleave_1, 1))
        self.connect((self.gr_complex_to_float_0_0, 0),
                     (self.gr_interleave_1, 0))

        self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((1, ))  # invert
        self.connect((self.gr_interleave_1, 0),
                     (self.gr_multiply_const_vxx_0, 0))

        self.baz_delay_2 = baz.delay(
            gr.sizeof_float * 1,
            default_xform.get_puncture_delay())  # delay_puncture
        self.connect((self.gr_multiply_const_vxx_0, 0), (self.baz_delay_2, 0))

        self.depuncture_ff_0 = baz.depuncture_ff(
            (_puncture_matrices[self.input_watcher.puncture_matrix][1]
             ))  # puncture_matrix
        self.connect((self.baz_delay_2, 0), (self.depuncture_ff_0, 0))

        self.baz_delay_1 = baz.delay(
            gr.sizeof_float * 1,
            default_xform.get_viterbi_delay())  # delay_viterbi
        self.connect((self.depuncture_ff_0, 0), (self.baz_delay_1, 0))

        self.swap_ff_0 = baz.swap_ff(
            default_xform.get_viterbi_swap())  # swap_viterbi
        self.connect((self.baz_delay_1, 0), (self.swap_ff_0, 0))

        self.gr_decode_ccsds_27_fb_0 = gr.decode_ccsds_27_fb()

        if use_throttle:
            print "==> Using throttle at sample rate:", self.sample_rate
            self.gr_throttle_0 = gr.throttle(gr.sizeof_float, self.sample_rate)
            self.connect((self.swap_ff_0, 0), (self.gr_throttle_0, 0))
            self.connect((self.gr_throttle_0, 0),
                         (self.gr_decode_ccsds_27_fb_0, 0))
        else:
            self.connect((self.swap_ff_0, 0),
                         (self.gr_decode_ccsds_27_fb_0, 0))

        self.connect((self.gr_decode_ccsds_27_fb_0, 0),
                     (self, 0))  # Output bytes

        self.gr_add_const_vxx_1 = gr.add_const_vff((-4096, ))
        self.connect((self.gr_decode_ccsds_27_fb_0, 1),
                     (self.gr_add_const_vxx_1, 0))

        self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((-1, ))
        self.connect((self.gr_add_const_vxx_1, 0),
                     (self.gr_multiply_const_vxx_1, 0))
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self, 1))  # Output BER

        self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(
            ber_smoothing, 1)
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self.gr_single_pole_iir_filter_xx_0, 0))

        self.gr_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float,
                                                       ber_sample_decimation)
        self.connect((self.gr_single_pole_iir_filter_xx_0, 0),
                     (self.gr_keep_one_in_n_0, 0))

        self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0,
                                                0)  # Last param is const value
        if use_throttle:
            lock_throttle_rate = self.sample_rate // 16
            print "==> Using lock throttle rate:", lock_throttle_rate
            self.gr_throttle_1 = gr.throttle(gr.sizeof_float,
                                             lock_throttle_rate)
            self.connect((self.const_source_x_0, 0), (self.gr_throttle_1, 0))
            self.connect((self.gr_throttle_1, 0), (self, 2))
        else:
            self.connect((self.const_source_x_0, 0), (self, 2))

        self.msg_q = gr.msg_queue(
            2 * 256
        )  # message queue that holds at most 2 messages, increase to speed up process
        self.msg_sink = gr.message_sink(
            gr.sizeof_float, self.msg_q,
            dont_block=0)  # Block to speed up process
        self.connect((self.gr_keep_one_in_n_0, 0), self.msg_sink)

        self.input_watcher.start()
Ejemplo n.º 37
0
    def test_multiply_const_vcc_five(self):
	src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j)
	op = gr.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j))
	exp_data = (-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j)
	self.help_const_cc(src_data, exp_data, op)
Ejemplo n.º 38
0
    def __init__(self, modulator, demodulator, options, ll_logging, dev_log,
                 start_tb_time, time_cal_timeout, start_controller_time):
        gr.top_block.__init__(self)

        # Get the modulation's bits_per_symbol
        args = modulator.extract_kwargs_from_options(options)
        symbol_rate = options.modulation_bitrate / modulator(
            **args).bits_per_symbol()

        # all subsequent code expects list of ints, so convert from
        # comma separated string
        sink_addresses = options.sink_mac_addresses
        options.sink_mac_addresses = [
            int(x) for x in sink_addresses.split(',')
        ]

        # Direct asynchronous notifications to callback function
        if True:  #self.options.show_async_msg:
            self.async_msgq = gr.msg_queue(0)
            self.async_src = uhd.amsg_source("", self.async_msgq)
            self.async_rcv = gru.msgq_runner(self.async_msgq,
                                             self.async_callback)

        self.dev_log = dev_log

        # how much time should be spent calibrating time sync?
        self.cal_time = time_cal_timeout

        #setting up USRP RX
        self.source = uhd_receiver(options.usrp_args, symbol_rate,
                                   options.modulation_samples_per_symbol,
                                   options.rf_rx_freq, options.rf_rx_gain,
                                   options.usrp_spec, "RX2", options.verbose)

        #setting up USRP TX
        self.sink = uhd_transmitter(options.usrp_args, symbol_rate,
                                    options.modulation_samples_per_symbol,
                                    options.rf_tx_freq, options.rf_tx_gain,
                                    options.usrp_spec, "TX/RX",
                                    options.verbose)

        if self.source._sps != options.modulation_samples_per_symbol:
            self.dev_log.warning(
                "The USRP does not support the requested sample rate of %f. Using %f instead",
                options.modulation_samples_per_symbol * symbol_rate,
                self.source._sps * symbol_rate)

        options.modulation_samples_per_symbol = self.source._sps

        self.digital_scaling = gr.multiply_const_vcc(
            (options.digital_scale_factor, ))

        # moved down here (after reassignment of self.source._sps so we can use
        # the actual sample rate the UHD is using
        self.fs = options.modulation_samples_per_symbol * symbol_rate

        self.pmt_rpc = digital_ll.pmt_rpc(obj=self, result_msg=False)

        self.start_tb_time = start_tb_time
        self.start_controller_time = start_controller_time

        upsample_factor = 8 * options.modulation_samples_per_symbol
        self.eob = digital_ll.eob_shifter(upsample_factor)
        options.digital_freq_hop_num_channels = 1

        if options.tx_access_code == '0':
            tx_access_code = None
        elif options.tx_access_code == '1':
            tx_access_code = '0000010000110001010011110100011100100101101110110011010101111110'
        elif options.tx_access_code == '2':
            tx_access_code = '1110001100101100010110110001110101100000110001011101000100001110'
        else:
            tx_access_code = options.tx_access_code

        print 'tx access code: %s' % tx_access_code

        self.packet_framer = digital_ll.packet_framer(
            fs=self.fs,
            samples_per_symbol=options.modulation_samples_per_symbol,
            bits_per_symbol=1,
            access_code=tx_access_code,
            number_digital_channels=1)

        if options.node_role == "tdma_base":
            self.tdma_mac_sm = tdma_base_sm(
                options, self.sink, self.source,
                self.packet_framer.num_bytes_to_num_samples)

            self.frame_sched = parse_frame_file(options.frame_file,
                                                start_controller_time, self.fs)

            for k, slot in enumerate(self.frame_sched["slots"]):
                self.frame_sched["slots"][k] = slot._replace()

                # replace the rf_freq field with the value of tx_freq from the ini or
                # command line for the slots transmitted by the base
                if (slot.type == "downlink") or (slot.type == "beacon"):
                    self.frame_sched["slots"][k] = slot._replace(
                        rf_freq=options.rf_tx_freq,
                        tx_gain=options.rf_tx_gain,
                        bw=self.fs)

                # replace the rf_freq field with the value of rx_freq from the ini or
                # command line for the slots received by the base
                elif slot.type == "uplink":
                    self.frame_sched["slots"][k] = slot._replace(
                        rf_freq=options.rf_rx_freq,
                        tx_gain=options.rf_tx_gain,
                        bw=self.fs)

            # for simple case, force all slot baseband frequencies to 0
            for k, slot in enumerate(self.frame_sched["slots"]):
                self.frame_sched["slots"][k] = slot._replace(bb_freq=0)

        else:
            self.tdma_mac_sm = tdma_mobile_sm(
                options, self.sink, self.source,
                self.packet_framer.num_bytes_to_num_samples)
            self.frame_sched = None

        if self.tdma_mac_sm.is_base():

            manage_slots = base_slot_manager_static(
                types_to_ints=tdma_types_to_ints,
                options=options,
                tdma_mac=self.tdma_mac_sm,
                initial_schedule=self.frame_sched)

        else:

            manage_slots = mobile_slot_manager_static(
                types_to_ints=tdma_types_to_ints,
                options=options,
                tdma_mac=self.tdma_mac_sm,
            )

        self.dev_log.info("starting at time %s", start_tb_time)
        self.tdma_controller = tdma_controller(
            options=options,
            mac_sm=self.tdma_mac_sm,
            manage_slots=manage_slots,
            fs=self.fs,
            mux_name="scheduled_mux",
            rx_channelizer_name="rx_channelizer",
            fhss_flag=0,  # No hopping
            start_time=start_controller_time,
        )

        if options.traffic_generation == "infinite":
            self.traffic = Infinite_Backlog_PDU_Streamer(
                options, self.tdma_controller.app_queue_size)
            self.msg_connect(self.traffic, "out_pkt_port",
                             self.tdma_controller, 'from_app')

        elif options.traffic_generation == "tunnel":
            self.traffic = Tunnel_Handler_PDU_Streamer(options)
            self.msg_connect(self.traffic, "out_pkt_port",
                             self.tdma_controller, 'from_app')
            self.msg_connect(self.tdma_controller, 'to_app', self.traffic,
                             "in_pkt_port")

        else:
            self.traffic = None

        self.tdma_logger = tdma_logger(ll_logging, 1)

        # set up receive path
        packet_rx_callback = self.tdma_controller.incoming_packet_callback
        self.rx_path = receive_path_gmsk(demodulator,
                                         packet_rx_callback,
                                         options,
                                         log_index=-2,
                                         use_new_pkt=True)

        self.gmsk_mod = digital_ll.gmsk_mod(
            samples_per_symbol=options.modulation_samples_per_symbol,
            bt=options.bt,
            verbose=False,
            log=False,
        )

        # declare time tag shifters
        is_receive = True
        self.rx_time_tag_shifter = time_tag_shifter(is_receive,
                                                    gr.sizeof_gr_complex)
        self.tx_time_tag_shifter = time_tag_shifter(not is_receive,
                                                    gr.sizeof_gr_complex)

        # handle base node specific setup
        if self.tdma_mac_sm.is_base():
            t0 = time.time()
            t0_int = int(t0) - 10
            t0_frac = t0 - t0_int
            beacon_sched = (1, 1, 0, (t0_int, t0_frac), (t0_int, t0_frac))

            self.scheduled_mux = digital_ll.scheduled_mux(
                gr.sizeof_gr_complex, 1, self.fs, [beacon_sched])

            self.connect(self.source, self.rx_time_tag_shifter,
                         self.scheduled_mux, self.rx_path)

        # handle mobile node specific setup
        else:
            t0 = time.time()
            t0_int = int(t0) - 10
            t0_frac = t0 - t0_int
            beacon_sched = (options.beacon_sense_block_size,
                            options.beacon_sense_block_size, 0,
                            (t0_int, t0_frac), (t0_int, t0_frac))

            self.scheduled_mux = digital_ll.scheduled_mux(
                gr.sizeof_gr_complex, 2, self.fs)

            # Set up receive path for beacon

            # set up beacon consumer
            self.beacon_consumer = beacon_consumer(options,
                                                   overwrite_metadata=True)

            beacon_rx_callback = self.beacon_consumer.beacon_callback
            self.beacon_rx_path = receive_path_gmsk(demodulator,
                                                    beacon_rx_callback,
                                                    options,
                                                    log_index=-1,
                                                    use_new_pkt=True)

            self.connect(self.source, self.rx_time_tag_shifter,
                         self.scheduled_mux, self.beacon_consumer)
            self.connect(self.scheduled_mux, self.beacon_rx_path)
            self.connect((self.scheduled_mux, 1), self.rx_path)

            self.msg_connect(self.beacon_consumer, "sched_out",
                             self.tdma_controller, "sched_in")

            # add in time tag shifter block message connections
            self.msg_connect(self.beacon_consumer, 'time_cal_out',
                             self.rx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out',
                             self.tx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out',
                             self.tdma_mac_sm.cq_manager, 'time_tag_shift')

        self.connect(self.rx_time_tag_shifter, self.tdma_controller)
        self.connect(self.packet_framer, self.gmsk_mod, self.digital_scaling,
                     self.tx_time_tag_shifter, self.eob, self.sink)

        #self.connect(self.gmsk_mod, self.tdma_logger)
        self.connect(self.eob, self.tdma_logger)

        self.msg_connect(self.tdma_controller, "command_out", self.pmt_rpc,
                         "in")
        self.msg_connect(self.tdma_controller, "outgoing_pkt",
                         self.packet_framer, "in")

        # store off params for logging
        self.get_usrp_params(options)
Ejemplo n.º 39
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="DVB Simulator (GMSK)")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.signal = signal = 1
		self.samp_rate = samp_rate = 32000
		self.noise = noise = 10

		##################################################
		# Blocks
		##################################################
		_signal_sizer = wx.BoxSizer(wx.VERTICAL)
		self._signal_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_signal_sizer,
			value=self.signal,
			callback=self.set_signal,
			label="Signal",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._signal_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_signal_sizer,
			value=self.signal,
			callback=self.set_signal,
			minimum=0,
			maximum=1000,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_signal_sizer)
		_noise_sizer = wx.BoxSizer(wx.VERTICAL)
		self._noise_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			label="Noise",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._noise_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			minimum=0,
			maximum=1000,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_noise_sizer)
		self.gr_wavfile_source_0 = gr.wavfile_source("/home/traviscollins/GNURADIO/tfc_models/test.wav", False)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_float*1, samp_rate)
		self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise, 42)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((signal, ))
		self.gr_file_sink_1_0 = gr.file_sink(gr.sizeof_float*1, "/home/traviscollins/GNURADIO/tfc_models/output_txt.wav")
		self.gr_file_sink_1_0.set_unbuffered(False)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=20,
			frequency_offset=0.0,
			epsilon=1.0,
			taps=(1.0 + 1.0j, ),
			noise_seed=42,
		)
		self.gr_add_xx_0 = gr.add_vcc(1)
		self.digital_gmsk_mod_0 = digital.gmsk_mod(
			samples_per_symbol=2,
			bt=0.35,
			verbose=False,
			log=False,
		)
		self.digital_gmsk_demod_0 = digital.gmsk_demod(
			samples_per_symbol=2,
			gain_mu=0.175,
			mu=0.5,
			omega_relative_limit=0.005,
			freq_error=0.0,
			verbose=False,
			log=False,
		)
		self.blks2_packet_encoder_0 = grc_blks2.packet_mod_f(grc_blks2.packet_encoder(
				samples_per_symbol=2,
				bits_per_symbol=1,
				access_code="",
				pad_for_usrp=True,
			),
			payload_length=0,
		)
		self.blks2_packet_decoder_0 = grc_blks2.packet_demod_f(grc_blks2.packet_decoder(
				access_code="",
				threshold=-1,
				callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload),
			),
		)
		self.audio_sink_0 = audio.sink(samp_rate, "", True)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.gr_add_xx_0, 0), (self.digital_gmsk_demod_0, 0))
		self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0))
		self.connect((self.digital_gmsk_mod_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.blks2_packet_encoder_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_1_0, 0))
		self.connect((self.digital_gmsk_demod_0, 0), (self.blks2_packet_decoder_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.gr_add_xx_0, 0))
		self.connect((self.gr_wavfile_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.blks2_packet_decoder_0, 0), (self.audio_sink_0, 0))
Ejemplo n.º 40
0
    def __init__(self, modulator, demodulator, options, ll_logging, dev_log, start_tb_time, time_cal_timeout, start_controller_time):
        gr.top_block.__init__(self)
        
        # Get the modulation's bits_per_symbol
        args = modulator.extract_kwargs_from_options(options)
        symbol_rate = options.modulation_bitrate / modulator(**args).bits_per_symbol()
        
        # all subsequent code expects list of ints, so convert from 
        # comma separated string
        sink_addresses = options.sink_mac_addresses
        options.sink_mac_addresses = [int(x) for x in sink_addresses.split(',')]        

        # Direct asynchronous notifications to callback function
        if True:#self.options.show_async_msg:
            self.async_msgq = gr.msg_queue(0)
            self.async_src = uhd.amsg_source("", self.async_msgq)
            self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)

        self.dev_log = dev_log
        
        # how much time should be spent calibrating time sync?
        self.cal_time = time_cal_timeout      

        self.rx_channelizer = channelizer.rx_channelizer(options, dev_log)
        self.tx_channelizer = channelizer.tx_channelizer(options, dev_log)
        self.rx_channelizer.set_beacon_channel(options.gpsbug_cal_channel)
        upsampled_symbol_rate = symbol_rate*options.digital_freq_hop_num_channels
        upsample_factor_usrp = options.digital_freq_hop_num_channels

        #setting up USRP RX
        self.source = uhd_receiver(options.usrp_args, upsampled_symbol_rate,
                                       options.modulation_samples_per_symbol,
                                       options.rf_rx_freq, options.rf_rx_gain,
                                       options.usrp_spec, "RX2",
                                       options.verbose)
            
        #setting up USRP TX
        self.sink = uhd_transmitter(options.usrp_args, upsampled_symbol_rate,
                                        options.modulation_samples_per_symbol,
                                        options.rf_tx_freq, options.rf_tx_gain,
                                        options.usrp_spec, "TX/RX",
                                        options.verbose)

        if self.source._sps != options.modulation_samples_per_symbol:
            self.dev_log.warning("The USRP does not support the requested sample rate of %f. Using %f instead",
                                    options.modulation_samples_per_symbol*upsampled_symbol_rate,
                                    self.source._sps*upsampled_symbol_rate)

        options.modulation_samples_per_symbol = self.source._sps
        
        self.digital_scaling = gr.multiply_const_vcc((options.digital_scale_factor,))
        
        # moved down here (after reassignment of self.source._sps so we can use
        # the actual sample rate the UHD is using
        self.fs = options.modulation_samples_per_symbol*upsampled_symbol_rate/upsample_factor_usrp
        
        self.pmt_rpc = digital_ll.pmt_rpc(obj=self,result_msg=False)
        
        self.start_tb_time = start_tb_time
        self.start_controller_time = start_controller_time
        
        # this helps control dc tone problem (Use to be burst_gate now eob_shifter)
        # TODO: Only programmed for GMSK. Other modulations will need additional work.
        upsample_factor = 8*options.modulation_samples_per_symbol*options.digital_freq_hop_num_channels
        self.eob        = digital_ll.eob_shifter(upsample_factor)

        num_d_chans = options.digital_freq_hop_num_channels
      
        if  options.tx_access_code == '0':
            tx_access_code = None
        elif options.tx_access_code == '1':
            tx_access_code = '0000010000110001010011110100011100100101101110110011010101111110'
        elif options.tx_access_code == '2':
            tx_access_code = '1110001100101100010110110001110101100000110001011101000100001110'   
        else:
            tx_access_code = options.tx_access_code
            
        print 'tx access code: %s' % tx_access_code   
   
        self.packet_framer = digital_ll.packet_framer(
            fs=self.fs,
            samples_per_symbol=options.modulation_samples_per_symbol,
            bits_per_symbol=1,
            access_code=tx_access_code,
            number_digital_channels=num_d_chans
        )
        
        if options.node_role == "tdma_base":
            self.tdma_mac_sm = tdma_base_sm(options, self.sink, self.source, 
                                            self.packet_framer.num_bytes_to_num_samples)
                
                
        else:
            self.tdma_mac_sm = tdma_mobile_sm(options, self.sink, self.source,
                                              self.packet_framer.num_bytes_to_num_samples)
        


        base_rl_agent_protocol_manager.configure_action_space(options, self.fs)

        num_mobiles = len(options.sink_mac_addresses)
        pfs = PatternFrameSchedule()
        num_actions = pfs.num_actions
        num_stochastic_states = num_mobiles + 1
        num_action_states = num_actions
        num_states = num_stochastic_states*num_action_states
        
        
        if self.tdma_mac_sm.is_base():
            
            epoch_len = options.agent_epoch_duration
            discount_factor = options.discount_factor
            learning_rate = options.learning_rate
            greedy_epsilon = options.greedy_epsilon
            use_dynamic_alpha = bool(options.agent_use_adaptive_alpha)
            use_dynamic_epsilon = bool(options.agent_use_adaptive_greedy_epsilon)

            use_change_detection = bool(options.agent_use_reward_change_detection)            
            reward_history_len = (options.agent_reward_oldbuffer_size,
                                  options.agent_reward_guardbuffer_size,
                                  options.agent_reward_newbuffer_size )
            
            change_delay = options.slot_assignment_leadtime
            mobile_ids = options.sink_mac_addresses
            
            if options.agent_type == "q_learner":
            
                agent = Q_Learner(num_states, num_actions, learning_rate, 
                     discount_factor, greedy_epsilon, q_mask=None, q_seed=None, 
                     dynamic_alpha=use_dynamic_alpha, dynamic_epsilon=use_dynamic_epsilon,
                     reward_history_len=reward_history_len,
                     use_change_detection=use_change_detection,
                     min_visit_count=options.agent_epsilon_adaptation_threshold)
                
            elif options.agent_type == "sarsa":
                
                agent = Sarsa_Learner(num_states, num_actions, learning_rate, 
                     discount_factor, greedy_epsilon, q_mask=None, q_seed=None, 
                     dynamic_alpha=use_dynamic_alpha, dynamic_epsilon=use_dynamic_epsilon,)
            
            
            agent_wrapper = RL_Agent_Wrapper(agent, 
                                               epoch_len, 
                                               num_stochastic_states,
                                               num_action_states, 
                                               change_delay, 
                                               mobile_ids,
                                               tdma_types_to_ints,
                                               reward_lookup_states=options.agent_reward_states, 
                                               reward_lookup_vals=options.agent_reward_vals,
                                               num_channels=options.digital_freq_hop_num_channels,
                                               do_episodic_learning=False,
                                               lock_buffer_len=options.agent_lock_buffer_len,
                                               lock_policy=options.agent_lock_policy)
                
            manage_slots = base_rl_agent_protocol_manager(tdma_types_to_ints, 
                                                         options=options,
                                                         tdma_mac=self.tdma_mac_sm,
                                                         initial_time_ref=start_controller_time,
                                                         agent_wrapper=agent_wrapper)

        else:
            manage_slots = mobile_rl_agent_protocol_manager(tdma_types_to_ints, 
                                                           options=options,
                                                           tdma_mac = self.tdma_mac_sm,)


            
        self.dev_log.info("starting at time %s", start_tb_time)
        self.tdma_controller = tdma_controller(options=options, 
                                               mac_sm=self.tdma_mac_sm,
                                               manage_slots=manage_slots, 
                                               fs=self.fs, 
                                               mux_name="scheduled_mux",
                                               rx_channelizer_name="rx_channelizer",
                                               fhss_flag=1, 
                                               start_time=start_controller_time,
                                               )
        
        
        if options.traffic_generation == "infinite": 
            self.traffic = Infinite_Backlog_PDU_Streamer( options, 
                                                 self.tdma_controller.app_queue_size )
            self.msg_connect(self.traffic, "out_pkt_port", self.tdma_controller,'from_app')
        
        elif options.traffic_generation == "tunnel":
            self.traffic = Tunnel_Handler_PDU_Streamer(options)
            self.msg_connect(self.traffic, "out_pkt_port", self.tdma_controller,'from_app')
            self.msg_connect(self.tdma_controller,'to_app', self.traffic, "in_pkt_port")

        else:
            self.traffic = None

        
        self.tdma_logger = tdma_logger(ll_logging, upsample_factor_usrp)
        
        # set up receive path
        packet_rx_callback = self.tdma_controller.incoming_packet_callback
        self.rx_path = receive_path_gmsk(demodulator, packet_rx_callback, options, 
                                               log_index=-2, use_new_pkt=True)
   

   
        self.gmsk_mod = digital_ll.gmsk_mod(
            samples_per_symbol=options.modulation_samples_per_symbol,
            bt=options.bt, 
            verbose=False,
            log=False,
        )
   
        # declare time tag shifters
        is_receive = True
        self.rx_time_tag_shifter = time_tag_shifter(is_receive, gr.sizeof_gr_complex)
        self.tx_time_tag_shifter = time_tag_shifter(not is_receive, gr.sizeof_gr_complex)
   
   
        # handle base node specific setup
        if self.tdma_mac_sm.is_base():
            t0 = time.time()
            t0_int = int(t0)-10
            t0_frac = t0-t0_int
            beacon_sched = (1,1,0,(t0_int, t0_frac),(t0_int, t0_frac))
            
            self.scheduled_mux = digital_ll.scheduled_mux(gr.sizeof_gr_complex,1,
                                                          self.fs, [beacon_sched])
 
            self.connect(self.source, self.rx_time_tag_shifter, self.rx_channelizer,self.scheduled_mux,self.rx_path)
              
            
        # handle mobile node specific setup    
        else:
            t0 = time.time()
            t0_int = int(t0)-10
            t0_frac = t0-t0_int
            beacon_sched = (options.beacon_sense_block_size,
                            options.beacon_sense_block_size,
                            0,(t0_int, t0_frac),(t0_int, t0_frac))

            self.scheduled_mux = digital_ll.scheduled_mux(gr.sizeof_gr_complex,2,self.fs)
            
            self.rx_channelizer.switch_channels(options.gpsbug_cal_channel)
            # Set up receive path for beacon
            
            # set up beacon consumer
            self.beacon_consumer = beacon_consumer(options, overwrite_metadata=True)
            
            beacon_rx_callback = self.beacon_consumer.beacon_callback
            self.beacon_rx_path = receive_path_gmsk(demodulator, beacon_rx_callback, options,log_index=-1,use_new_pkt=True)
         
            self.connect(self.source, self.rx_time_tag_shifter,self.rx_channelizer,self.scheduled_mux,self.beacon_consumer)
            self.connect(self.scheduled_mux,self.beacon_rx_path)
            self.connect((self.scheduled_mux,1),self.rx_path)

            
            self.msg_connect(self.beacon_consumer, "sched_out", self.tdma_controller, "sched_in")
                    
                    
            # add in time tag shifter block message connections
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.rx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.tx_time_tag_shifter, 'time_tag_shift')
            self.msg_connect(self.beacon_consumer, 'time_cal_out', self.tdma_mac_sm.cq_manager, 'time_tag_shift')
            

        self.connect(self.rx_channelizer,self.tdma_controller)
        self.connect(self.packet_framer, self.gmsk_mod, self.digital_scaling, 
                     self.tx_channelizer, self.tx_time_tag_shifter, self.eob, self.sink)
            
            

            
        #self.connect(self.gmsk_mod, self.tdma_logger)
        self.connect(self.eob, self.tdma_logger)


        self.msg_connect(self.tdma_controller, "command_out", self.pmt_rpc, "in")
        self.msg_connect(self.tdma_controller, "outgoing_pkt", self.packet_framer, "in")   
        
        # store off params for logging 
        self.get_usrp_params(options)
Ejemplo n.º 41
0
	def __init__(self,device_addr="",samp_rate=int(1000e3),
		tx_A="TX/RX",rx_A="RX2",tx_gain=15,rx_gain=0,centre_freq=int(990e6),
		sps=2,bps=1,access_code=""):
		gras.HierBlock.__init__(self,"cog_phy")
		#
		self.device_addr=device_addr
		self.samp_rate=samp_rate
		self.tx_A=tx_A
		self.rx_A=rx_A
		self.tx_gain=tx_gain
		self.rx_gain=rx_gain
		self.centre_freq=centre_freq
		self.sps=sps
		self.bps=bps
		self.access_code=access_code
		# usrp source/sinks

		self.uhd_usrp_source = uhd.usrp_source(
			device_addr=self.device_addr,
			stream_args=uhd.stream_args(
				cpu_format="fc32",
				channels=range(1),
			),
		)
		self.uhd_usrp_source.set_samp_rate(samp_rate)
		self.uhd_usrp_source.set_center_freq(centre_freq, 0)
		self.uhd_usrp_source.set_gain(rx_gain, 0)
		self.uhd_usrp_source.set_antenna(rx_A, 0)
		self.uhd_usrp_sink = uhd.usrp_sink(
			device_addr,
			stream_args=uhd.stream_args(
				cpu_format="fc32",
				channels=range(1),
			),
		)
		self.uhd_usrp_sink.set_samp_rate(samp_rate)
		self.uhd_usrp_sink.set_center_freq(centre_freq, 0)
		self.uhd_usrp_sink.set_gain(tx_gain, 0)
		self.uhd_usrp_sink.set_antenna(tx_A, 0)

		# packet framer/deframer

		self.extras_packet_framer = grextras.PacketFramer(
		    samples_per_symbol=1,
		    bits_per_symbol=1,
		    access_code=self.access_code,
		)
		self.extras_packet_deframer = grextras.PacketDeframer(
		    access_code=self.access_code,
		    threshold=-1,
		)

		# Modulator/Demodulator

		self.digital_gmsk_mod = digital.gmsk_mod(
			samples_per_symbol=self.sps,
			bt=0.35,
			verbose=False,
			log=False,
		)
		self.digital_gmsk_demod = digital.gmsk_demod(
			samples_per_symbol=self.sps,
			gain_mu=0.175,
			mu=0.5,
			omega_relative_limit=0.005,
			freq_error=0.0,
			verbose=False,
			log=False,
		)

		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.3, ))
		self.extras_burst_tagger_0 = grextras.BurstTagger(self.sps)
		##################################################
		# Connections
		##################################################
		#RX chain
		self.connect((self.uhd_usrp_source, 0), (self.digital_gmsk_demod, 0))
		self.connect((self.digital_gmsk_demod, 0), (self.extras_packet_deframer, 0))
		self.connect((self.extras_packet_deframer, 0), (self,0))
		#TX chain		
		self.connect((self,0),((self.extras_packet_framer, 0)))
		self.connect((self.extras_packet_framer, 0), (self.digital_gmsk_mod, 0))
		self.connect((self.digital_gmsk_mod, 0), (self.gr_multiply_const_vxx_0,0))
		self.connect((self.gr_multiply_const_vxx_0,0),(self.extras_burst_tagger_0,0))
		self.connect((self.extras_burst_tagger_0,0),(self.uhd_usrp_sink, 0))
		#probe to usrp_source for testing fft of received signal
		self.connect((self.uhd_usrp_source,0),(self,1))
Ejemplo n.º 42
0
    def __init__(self,
                 gain=25,
                 clock_alpha=0.005,
                 freq=1707e6,
                 decim=25,
                 satellite='MetOp',
                 symb_rate=(3500e3 / 3 + 3500e3) / 2,
                 pll_alpha=0.005,
                 deframer_sync_check=True,
                 deframer_insync_frames=2,
                 deframer_outsync_frames=5,
                 frames_file=os.environ['HOME'] + '/metop_ahrpt_frames.cadu',
                 baseband_file=os.environ['HOME'] +
                 '/metop_ahrpt_baseband.dat',
                 viterbi_sync_threshold=0.1,
                 viterbi_sync_check=True,
                 viterbi_insync_frames=5,
                 viterbi_outsync_frames=20):
        grc_wxgui.top_block_gui.__init__(self,
                                         title="USRP2 MetOp AHRPT Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.gain = gain
        self.clock_alpha = clock_alpha
        self.freq = freq
        self.decim = decim
        self.satellite = satellite
        self.symb_rate = symb_rate
        self.pll_alpha = pll_alpha
        self.deframer_sync_check = deframer_sync_check
        self.deframer_insync_frames = deframer_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.frames_file = frames_file
        self.baseband_file = baseband_file
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_insync_frames = viterbi_insync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.max_clock_offset = max_clock_offset = 0.1
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).Add(self._baseband_file_text_inf_static_text)

        ##################################################
        # Blocks
        ##################################################
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 4)
        self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short * 2,
                                             baseband_file)
        self.gr_float_to_complex_0 = gr.float_to_complex(1)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_short_to_float_0 = gr.short_to_float()
        self.gr_short_to_float_0_0 = gr.short_to_float()
        self.gr_vector_to_streams_0 = gr.vector_to_streams(
            gr.sizeof_short * 1, 2)
        self.usrp2_source_xxxx2_0 = usrp2.source_16sc()
        self.usrp2_source_xxxx2_0.set_decim(decim_tb)
        self.usrp2_source_xxxx2_0.set_center_freq(freq_tb)
        self.usrp2_source_xxxx2_0.set_gain(gain_tb)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_fftsink2 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="RRC filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="QPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink2, 0))
        self.connect((self.gr_short_to_float_0, 0),
                     (self.gr_float_to_complex_0, 0))
        self.connect((self.gr_short_to_float_0_0, 0),
                     (self.gr_float_to_complex_0, 1))
        self.connect((self.usrp2_source_xxxx2_0, 0),
                     (self.gr_file_sink_0_1, 0))
        self.connect((self.usrp2_source_xxxx2_0, 0),
                     (self.gr_vector_to_streams_0, 0))
        self.connect((self.gr_vector_to_streams_0, 1),
                     (self.gr_short_to_float_0_0, 0))
        self.connect((self.gr_vector_to_streams_0, 0),
                     (self.gr_short_to_float_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_float_to_complex_0, 0),
                     (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
Ejemplo n.º 43
0
    def create(self,
               address=None,
               decim_rate=0,
               which=None,
               subdev_spec="",
               sample_rate=None):
        if self._uhd_device is not None:  # Not supporting re-creation
            return True

        if address is None:
            address = self._address
        if (address is
                None):  # or (isinstance(address, str) and address == "")
            address = _default_address

        if isinstance(address, int):
            # FIXME: Check 'which'
            which = address
            address = ""

        if decim_rate == 0:
            decim_rate = self._decim_rate
        if decim_rate == 0:
            #raise Exception, "Decimation rate required"
            decim_rate = 256

        if which is None:
            which = self._which

        self._last_address = address
        self._last_which = which
        self._last_subdev_spec = subdev_spec

        self.destroy()

        # FIXME: 'which'

        stream_args = uhd.stream_args(
            cpu_format=self._args[1],
            channels=range(1),
        )

        if self._args[0]:
            self._uhd_device = uhd.usrp_sink(
                device_addr=address,
                stream_args=stream_args,
            )
        else:
            self._uhd_device = uhd.usrp_source(
                device_addr=address,
                stream_args=stream_args,
            )

        if ((subdev_spec is not None) and
            (not isinstance(subdev_spec, str))) or (isinstance(
                subdev_spec, str) and (subdev_spec != "")):
            if isinstance(subdev_spec, str) == False:
                if isinstance(subdev_spec, tuple):
                    if len(subdev_spec) > 1:
                        default_subdev_spec = self._uhd_device.get_subdev_spec(
                        )
                        idx = default_subdev_spec.find(':')
                        if idx > -1:
                            try:
                                int(default_subdev_spec[idx + 1:])
                            except:
                                subdev_spec = "%s:%s" % (
                                    chr(ord('A') + subdev_spec[0]),
                                    chr(ord('A') + subdev_spec[1]))
                        if isinstance(subdev_spec, str) == False:
                            subdev_spec = "%s:%s" % (
                                chr(ord('A') + subdev_spec[0]), subdev_spec[1])
                    else:
                        subdev_spec = chr(ord('A') + subdev_spec[0])
                else:
                    raise Exception, "Unknown sub-device specification: " + str(
                        subdev_spec)

        if subdev_spec is not None:
            self._uhd_device.set_subdev_spec(subdev_spec, 0)

        try:
            info = self._uhd_device.get_usrp_info(0)
            self._name = info.get("mboard_id")
            self._serial = info.get("mboard_serial")
            if self._serial != "":
                self._name += (" (%s)" % (self._serial))
        except:
            pass

        _gr = self._uhd_device.get_gain_range(0)
        self._gain_range = (_gr.start(), _gr.stop(), _gr.step())
        self._gain_step = _gr.step()

        external_port = self
        self._multiplier = None
        if self._args[1] != "sc16" and self._scale != 1.0:
            scale = self._scale
            if self._args[0]:
                scale = 1.0 / scale
            #print "Scaling by", self._scale
            try:
                self._multiplier = external_port = blocks.multiply_const_vcc(
                    (scale, ))
            except:
                self._multiplier = external_port = gr.multiply_const_vcc(
                    (scale, ))
            if self._args[0]:
                self.connect(self, self._multiplier)
            else:
                self.connect(self._multiplier, self)

        _fr = self._uhd_device.get_freq_range(0)
        self._freq_range = (_fr.start(), _fr.stop(), _fr.step())

        if self._args[0]:
            if self._args[1] == "sc16":
                try:
                    self._s2v = blocks.stream_to_vector(gr.sizeof_short, 2)
                except:
                    self._s2v = gr.stream_to_vector(gr.sizeof_short, 2)
                self.connect(external_port, self._s2v, self._uhd_device)
            else:
                self.connect(external_port, self._uhd_device)
        else:
            if self._args[1] == "sc16":
                try:
                    self._v2s = blocks.vector_to_stream(gr.sizeof_short, 2)
                except:
                    self._v2s = gr.vector_to_stream(gr.sizeof_short, 2)
                self.connect(self._uhd_device, self._v2s, external_port)
            else:
                self.connect(self._uhd_device, external_port)

        self._created = True

        if sample_rate is not None:
            self._uhd_device.set_samp_rate(sample_rate)
        else:
            if self.set_decim_rate(decim_rate) == False:
                raise Exception, "Invalid decimation: %s (sample rate: %s)" % (
                    decim_rate, sample_rate)
    def __init__(
            self,
            deframer_insync_frames=2,
            viterbi_insync_frames=5,
            deframer_outsync_frames=5,
            viterbi_outsync_frames=20,
            viterbi_sync_check=True,
            viterbi_sync_threshold=0.1,
            deframer_sync_check=True,
            pll_alpha=0.005,
            freq=1691.02e6,
            gain=23,
            side="A",
            decim=25,
            symb_rate=(3500e3 / 3 + 3500e3) / 2,
            frames_file=os.environ['HOME'] + '/MetOp-AHRPT_cadu_frames.cadu',
            clock_alpha=0.05,
            baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam',
            satellite='MetOp'):
        grc_wxgui.top_block_gui.__init__(
            self, title="MetOp AHRPT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.pll_alpha = pll_alpha
        self.freq = freq
        self.gain = gain
        self.side = side
        self.decim = decim
        self.symb_rate = symb_rate
        self.frames_file = frames_file
        self.clock_alpha = clock_alpha
        self.baseband_file = baseband_file
        self.satellite = satellite

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.cs2cf = gr.interleaved_short_to_complex()
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 4)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               baseband_file, True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="QPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_null_sink_0, 0))
Ejemplo n.º 45
0
    def __init__(self):
        gr.top_block.__init__(self, "Simple QAM Simulation")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Simple QAM Simulation")
        self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        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)

        ##################################################
        # Variables
        ##################################################
        self.constellation_cardinality = constellation_cardinality = 16
        self.const_object = const_object = constellations()['qam'](
            constellation_cardinality)
        self.snr_db = snr_db = 20
        self.constellation = constellation = const_object.points()
        self.sps = sps = 8
        self.samp_rate = samp_rate = 250000
        self.noise_amp = noise_amp = sqrt((10**(-snr_db / 10.)) / 2.)
        self.constellation_power = constellation_power = sqrt(
            sum([abs(i)**2
                 for i in constellation]) / constellation_cardinality)

        ##################################################
        # Blocks
        ##################################################
        self.tabid_0 = Qt.QTabWidget()
        self.tabid_0_widget_0 = Qt.QWidget()
        self.tabid_0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_0_widget_0)
        self.tabid_0_grid_layout_0 = Qt.QGridLayout()
        self.tabid_0_layout_0.addLayout(self.tabid_0_grid_layout_0)
        self.tabid_0.addTab(self.tabid_0_widget_0, "TX")
        self.tabid_0_widget_1 = Qt.QWidget()
        self.tabid_0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_0_widget_1)
        self.tabid_0_grid_layout_1 = Qt.QGridLayout()
        self.tabid_0_layout_1.addLayout(self.tabid_0_grid_layout_1)
        self.tabid_0.addTab(self.tabid_0_widget_1, "CHANNEL")
        self.tabid_0_widget_2 = Qt.QWidget()
        self.tabid_0_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_0_widget_2)
        self.tabid_0_grid_layout_2 = Qt.QGridLayout()
        self.tabid_0_layout_2.addLayout(self.tabid_0_grid_layout_2)
        self.tabid_0.addTab(self.tabid_0_widget_2, "RX")
        self.top_grid_layout.addWidget(self.tabid_0, 30, 0, 10, 100)
        self.tabid_2 = Qt.QTabWidget()
        self.tabid_2_widget_0 = Qt.QWidget()
        self.tabid_2_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_2_widget_0)
        self.tabid_2_grid_layout_0 = Qt.QGridLayout()
        self.tabid_2_layout_0.addLayout(self.tabid_2_grid_layout_0)
        self.tabid_2.addTab(self.tabid_2_widget_0, "symbol-based")
        self.tabid_2_widget_1 = Qt.QWidget()
        self.tabid_2_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_2_widget_1)
        self.tabid_2_grid_layout_1 = Qt.QGridLayout()
        self.tabid_2_layout_1.addLayout(self.tabid_2_grid_layout_1)
        self.tabid_2.addTab(self.tabid_2_widget_1, "bit-based")
        self.tabid_2_widget_2 = Qt.QWidget()
        self.tabid_2_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_2_widget_2)
        self.tabid_2_grid_layout_2 = Qt.QGridLayout()
        self.tabid_2_layout_2.addLayout(self.tabid_2_grid_layout_2)
        self.tabid_2.addTab(self.tabid_2_widget_2, "BER")
        self.tabid_0_layout_2.addWidget(self.tabid_2)
        self.tabid_1 = Qt.QTabWidget()
        self.tabid_1_widget_0 = Qt.QWidget()
        self.tabid_1_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_1_widget_0)
        self.tabid_1_grid_layout_0 = Qt.QGridLayout()
        self.tabid_1_layout_0.addLayout(self.tabid_1_grid_layout_0)
        self.tabid_1.addTab(self.tabid_1_widget_0, "bit-based")
        self.tabid_1_widget_1 = Qt.QWidget()
        self.tabid_1_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_1_widget_1)
        self.tabid_1_grid_layout_1 = Qt.QGridLayout()
        self.tabid_1_layout_1.addLayout(self.tabid_1_grid_layout_1)
        self.tabid_1.addTab(self.tabid_1_widget_1, "scrambled")
        self.tabid_1_widget_2 = Qt.QWidget()
        self.tabid_1_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                              self.tabid_1_widget_2)
        self.tabid_1_grid_layout_2 = Qt.QGridLayout()
        self.tabid_1_layout_2.addLayout(self.tabid_1_grid_layout_2)
        self.tabid_1.addTab(self.tabid_1_widget_2, "symbol-based")
        self.tabid_0_grid_layout_0.addWidget(self.tabid_1, 0, 0, 10, 10)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #bw
            "QT GUI Plot",  #name
            1  #number of inputs
        )
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tabid_2_layout_2.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_sink_x_0_1_0_0 = qtgui.sink_f(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            False,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            True,  #plotconst
        )
        self._qtgui_sink_x_0_1_0_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0_1_0_0.pyqwidget(), Qt.QWidget)
        self.tabid_1_layout_0.addWidget(self._qtgui_sink_x_0_1_0_0_win)
        self.qtgui_sink_x_0_1_0 = qtgui.sink_f(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            True,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            True,  #plotconst
        )
        self._qtgui_sink_x_0_1_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0_1_0.pyqwidget(), Qt.QWidget)
        self.tabid_1_layout_1.addWidget(self._qtgui_sink_x_0_1_0_win)
        self.qtgui_sink_x_0_1 = qtgui.sink_c(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            False,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            True,  #plotconst
        )
        self._qtgui_sink_x_0_1_win = sip.wrapinstance(
            self.qtgui_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.tabid_1_layout_2.addWidget(self._qtgui_sink_x_0_1_win)
        self.qtgui_sink_x_0_0_0_0 = qtgui.sink_c(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            True,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            True,  #plotconst
        )
        self._qtgui_sink_x_0_0_0_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0_0_0_0.pyqwidget(), Qt.QWidget)
        self.tabid_2_layout_0.addWidget(self._qtgui_sink_x_0_0_0_0_win)
        self.qtgui_sink_x_0_0_0 = qtgui.sink_f(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            False,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            True,  #plotconst
        )
        self._qtgui_sink_x_0_0_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0_0_0.pyqwidget(), Qt.QWidget)
        self.tabid_2_layout_1.addWidget(self._qtgui_sink_x_0_0_0_win)
        self.qtgui_sink_x_0_0 = qtgui.sink_c(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "QT GUI Plot",  #name
            True,  #plotfreq
            False,  #plotwaterfall
            True,  #plottime
            False,  #plotconst
        )
        self._qtgui_sink_x_0_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.tabid_0_layout_1.addWidget(self._qtgui_sink_x_0_0_win)
        self.gr_vector_source_x_0_0 = gr.vector_source_b(([1, 0]), True, 1)
        self.gr_vector_source_x_0 = gr.vector_source_b(([1, 0]), True, 1)
        self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(
            int(log2(constellation_cardinality)))
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.gr_pack_k_bits_bb_0 = gr.pack_k_bits_bb(
            int(log2(constellation_cardinality)))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_amp,
                                                     0)
        self.gr_nlog10_ff_0 = gr.nlog10_ff(1, 1, 0)
        self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vcc(
            (1. / constellation_power, ))
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(
            (constellation_power, ))
        self.gr_file_sink_0_1_0 = gr.file_sink(gr.sizeof_gr_complex * 1,
                                               "rx_sym.32fc")
        self.gr_file_sink_0_1_0.set_unbuffered(False)
        self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_gr_complex * 1,
                                             "tx_sym.32fc")
        self.gr_file_sink_0_1.set_unbuffered(False)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_char * 1, "rx.8b")
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char * 1, "tx.8b")
        self.gr_file_sink_0.set_unbuffered(False)
        self.gr_descrambler_bb_0 = gr.descrambler_bb(0xe4001, 0x7ffff, 19)
        self.gr_char_to_float_1_0 = gr.char_to_float(1, 1)
        self.gr_char_to_float_1 = gr.char_to_float(1, 1)
        self.gr_char_to_float_0 = gr.char_to_float(1, 1)
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.digital_scrambler_bb_0 = digital.scrambler_bb(
            0xe4001, 0x7fffF, 19)
        self.digital_constellation_receiver_cb_0 = digital.constellation_receiver_cb(
            const_object.base(), 6.28 / 100, -0.25, +0.25)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(
            (constellation), 1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
            type='BER',
            win_size=samp_rate,
            bits_per_symbol=1,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_vector_source_x_0, 0),
                     (self.digital_scrambler_bb_0, 0))
        self.connect((self.digital_scrambler_bb_0, 0),
                     (self.gr_pack_k_bits_bb_0, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_constellation_receiver_cb_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.digital_constellation_receiver_cb_0, 0),
                     (self.gr_unpack_k_bits_bb_0, 0))
        self.connect((self.gr_unpack_k_bits_bb_0, 0),
                     (self.gr_descrambler_bb_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0), (self.gr_null_sink_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.digital_constellation_receiver_cb_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0),
                     (self.gr_char_to_float_0, 0))
        self.connect((self.gr_char_to_float_0, 0),
                     (self.qtgui_sink_x_0_0_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.gr_multiply_const_vxx_0_0, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.gr_file_sink_0_1, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.qtgui_sink_x_0_1, 0))
        self.connect((self.gr_char_to_float_1, 0),
                     (self.qtgui_sink_x_0_1_0, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0),
                     (self.gr_char_to_float_1, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_file_sink_0, 0))
        self.connect((self.gr_char_to_float_1_0, 0),
                     (self.qtgui_sink_x_0_1_0_0, 0))
        self.connect((self.gr_vector_source_x_0, 0),
                     (self.gr_char_to_float_1_0, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.gr_add_xx_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.qtgui_sink_x_0_0, 0))
        self.connect((self.gr_throttle_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_0_1_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.qtgui_sink_x_0_0_0_0, 0))
        self.connect((self.gr_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blks2_error_rate_0, 0), (self.gr_nlog10_ff_0, 0))
        self.connect((self.gr_vector_source_x_0_0, 0),
                     (self.blks2_error_rate_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0),
                     (self.blks2_error_rate_0, 1))
Ejemplo n.º 46
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Simulated Sender GUI")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
        self.noise_voltage = noise_voltage = 0.01
        self.mult_const = mult_const = 1

        ##################################################
        # Controls
        ##################################################
        _noise_voltage_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_voltage_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_voltage_sizer,
            value=self.noise_voltage,
            callback=self.set_noise_voltage,
            label="Noise Voltage",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_voltage_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_voltage_sizer,
            value=self.noise_voltage,
            callback=self.set_noise_voltage,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_voltage_sizer)
        self._mult_const_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.mult_const,
            callback=self.set_mult_const,
            label="Multiplication Const",
            converter=forms.float_converter(),
        )
        self.Add(self._mult_const_text_box)

        ##################################################
        # Blocks
        ##################################################
        self.blks2_ofdm_mod_0 = grc_blks2.packet_mod_b(
            blks2.ofdm_mod(options=grc_blks2.options(
                modulation="bpsk",
                fft_length=512,
                occupied_tones=200,
                cp_length=128,
                pad_for_usrp=True,
                log=None,
                verbose=None,
            ), ),
            payload_length=512,
        )
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=noise_voltage,
            frequency_offset=0.0,
            epsilon=1.0,
            taps=(1.0 + 1.0j, ),
            noise_seed=42,
        )
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((mult_const, ))
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.random_source_x_0 = gr.vector_source_b(
            map(int, numpy.random.randint(0, 256, 512)), True)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=50,
            sample_rate=samp_rate,
            fft_size=256,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="FFT Plot",
            peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_throttle_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_channel_model_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_channel_model_0, 0))
        self.connect((self.random_source_x_0, 0), (self.blks2_ofdm_mod_0, 0))
        self.connect((self.blks2_ofdm_mod_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
Ejemplo n.º 47
0
    def __init__(self,
                 lead_limit=0.001,
                 tx_gain=0,
                 samp_per_sym=4,
                 link_speed=200,
                 pre_guard=0.003,
                 rate=1e6,
                 hop_interval=0.02,
                 rx_gain=15,
                 ampl=0.7,
                 freq=425e6,
                 args="",
                 freq_list="4251e5,4261e5,4271e5",
                 post_guard=0.001,
                 dev_addr=1):
        gr.hier_block2.__init__(
            self,
            "FHAH TRANSCEIVER",
            gr.io_signature(1, 1, gr.sizeof_char * 1),
            gr.io_signature(1, 1, gr.sizeof_char * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.lead_limit = lead_limit
        self.tx_gain = tx_gain
        self.samp_per_sym = samp_per_sym
        self.link_speed = link_speed
        self.pre_guard = pre_guard
        self.rate = rate
        self.hop_interval = hop_interval
        self.rx_gain = rx_gain
        self.ampl = ampl
        self.freq = freq
        self.args = args
        self.freq_list = freq_list
        self.post_guard = post_guard
        self.dev_addr = dev_addr

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_0 = samp_rate_0 = rate
        self.samp_rate = samp_rate = rate

        ##################################################
        # Blocks
        ##################################################
        self.uhd_source = uhd.usrp_source(
            device_addr=args,
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_source.set_clock_source("mimo", 0)
        self.uhd_source.set_time_source("mimo", 0)
        self.uhd_source.set_samp_rate(samp_rate)
        #self.uhd_source.set_auto_dc_offset(False)
        self.uhd_source.set_center_freq(freq, 0)
        self.uhd_source.set_gain(rx_gain, 0)
        self.uhd_source.set_antenna("RX2", 0)
        self.uhd_sink = uhd.usrp_sink(
            device_addr=args,
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_sink.set_clock_source("mimo", 0)
        self.uhd_sink.set_time_source("mimo", 0)
        self.uhd_sink.set_samp_rate(samp_rate)
        self.uhd_sink.set_center_freq(freq, 0)
        self.uhd_sink.set_gain(tx_gain, 0)
        self.uhd_sink.set_antenna("TX/RX", 0)
        self.precog_packet_framer_0 = fhah.packet_framer(
            samples_per_symbol=samp_per_sym,
            bits_per_symbol=1,
            access_code="",
        )
        self.precog_packet_deframer_0 = fhah.packet_deframer(
            access_code="",
            threshold=2,
        )
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((ampl, ))
        self.gmsk_mod = digital.gmsk_mod(
            samples_per_symbol=samp_per_sym,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.gmsk_demod = digital.gmsk_demod(
            samples_per_symbol=samp_per_sym,
            gain_mu=0,
            mu=0.5,
            omega_relative_limit=0.005,
            freq_error=0.0,
            verbose=False,
            log=False,
        )
        self.fhah_fhah_engine_tx_0 = fhah.fhah_engine_tx(
            hop_interval, pre_guard, post_guard, dev_addr,
            samp_rate / samp_per_sym, freq_list)
        self.extras_pmt_rpc_0 = gr_extras.pmt_rpc(obj=self, result_msg=True)
        self.burst_gate_0 = fhah.burst_gate()

        ##################################################
        # Connections
        ##################################################
        self.connect((self.uhd_source, 0), (self.gmsk_demod, 0))
        self.connect((self.uhd_source, 0), (self.fhah_fhah_engine_tx_0, 0))
        self.connect((self, 0), (self.fhah_fhah_engine_tx_0, 1))
        self.connect((self.burst_gate_0, 0), (self.uhd_sink, 0))
        self.connect((self.gmsk_mod, 0), (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.fhah_fhah_engine_tx_0, 0),
                     (self.precog_packet_framer_0, 0))
        self.connect((self.fhah_fhah_engine_tx_0, 1),
                     (self.extras_pmt_rpc_0, 0))
        self.connect((self.precog_packet_framer_0, 0), (self.gmsk_mod, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0), (self.burst_gate_0, 0))
        self.connect((self.precog_packet_deframer_0, 0),
                     (self.fhah_fhah_engine_tx_0, 2))
        self.connect((self.fhah_fhah_engine_tx_0, 2), (self, 0))
        self.connect((self.gmsk_demod, 0), (self.precog_packet_deframer_0, 0))
Ejemplo n.º 48
0
	def __init__(self, deframer_insync_frames=2, deframer_outsync_frames=5, deframer_sync_check=True, pll_alpha=0.005, baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam', satellite='MetOp', viterbi_sync_threshold=0.1, viterbi_outsync_frames=20, viterbi_insync_frames=5, frames_file=os.environ['HOME'] + '/MetOp-cadu_frames.cadu', clock_alpha=0.05, symb_rate=(3500e3/3+3500e3)/2, symb_rate_0=3*3500/4, viterbi_sync_check=True, decim=24):
		grc_wxgui.top_block_gui.__init__(self, title="MetOp AHRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_sync_check = deframer_sync_check
		self.pll_alpha = pll_alpha
		self.baseband_file = baseband_file
		self.satellite = satellite
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_insync_frames = viterbi_insync_frames
		self.frames_file = frames_file
		self.clock_alpha = clock_alpha
		self.symb_rate = symb_rate
		self.symb_rate_0 = symb_rate_0
		self.viterbi_sync_check = viterbi_sync_check
		self.decim = decim

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Blocks
		##################################################
		self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			title="QPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_scopesink2_1.win)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=-15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(False, 1024, 5, 25)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*10)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.6, ))
		self.gr_file_source_0_0_0_0 = gr.file_source(gr.sizeof_short*1, "/home/martin/hrpt/baseband/METOP-A/2011/07/24/METOP-A_2011-07-24_122614-U2d24.sam", False)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/home/martin/MetOp-cadu_frames.cadu")
		self.gr_file_sink_0.set_unbuffered(False)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 4)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self.fec_decode_viterbi_ahrpt_metop_cb_0 = fec.decode_viterbi_ahrpt_metop_cb(True, 0.2, 5, 50, 50)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		self.cs2cf = gr.interleaved_short_to_complex()
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).Add(self._baseband_file_text_inf_static_text)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_file_source_0_0_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.fec_decode_viterbi_ahrpt_metop_cb_0, 0))
		self.connect((self.fec_decode_viterbi_ahrpt_metop_cb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
	def __init__(self, deframer_insync_frames=2, deframer_sync_check=True, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, satellite='GOES-LRIT', freq=1691.02e6, gain=23, decim=108, side="A", pll_alpha=0.005, symb_rate=293883, clock_alpha=0.005):
		grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver - check signal quality")

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_sync_check = deframer_sync_check
		self.viterbi_insync_frames = viterbi_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_sync_check = viterbi_sync_check
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.satellite = satellite
		self.freq = freq
		self.gain = gain
		self.decim = decim
		self.side = side
		self.pll_alpha = pll_alpha
		self.symb_rate = symb_rate
		self.clock_alpha = clock_alpha

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 64e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.gain_tb = gain_tb = gain
		self.freq_tb = freq_tb = freq
		self.frames_file_text_inf = frames_file_text_inf = 'no output file'
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self._gain_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.gain_tb,
			callback=self.set_gain_tb,
			label="RX gain [dB]",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames, viterbi_outsync_frames, viterbi_outsync_frames*3)
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 2)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char*1)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(True, 1024, deframer_insync_frames, deframer_outsync_frames)
		self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(1, firdes.root_raised_cosine(
			1, samp_rate, symb_rate, 0.25, int(11*samp_rate/symb_rate)))
		self.usrp_simple_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source.set_decim_rate(decim_tb)
		self.usrp_simple_source.set_frequency(freq_tb, verbose=True)
		self.usrp_simple_source.set_gain(gain_tb)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=2,
			y_divs=10,
			ref_level=12,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_fftsink2 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=2,
			y_divs=10,
			ref_level=12,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="RRC filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="BPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.usrp_simple_source, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.fec_decode_viterbi_bpsk_fb_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_null_sink_0, 0))
Ejemplo n.º 50
0
    def test_multiply_const_vcc_one(self):
	src_data = (1.0+2.0j,)
	op = gr.multiply_const_vcc((2.0+3.0j,))
	exp_data = (-4.0+7.0j,)
	self.help_const_cc(src_data, exp_data, op)
Ejemplo n.º 51
0
    def __init__(self,
                 deframer_insync_frames=2,
                 viterbi_insync_frames=5,
                 deframer_outsync_frames=5,
                 viterbi_outsync_frames=20,
                 viterbi_sync_check=True,
                 viterbi_sync_threshold=0.1,
                 deframer_sync_check=True,
                 clock_alpha=0.005,
                 symb_rate=293883,
                 pll_alpha=0.005,
                 satellite='GOES-LRIT',
                 freq=1691.02e6,
                 gain=23,
                 decim=108,
                 side="A",
                 frames_file=os.environ['HOME'] +
                 '/GOES-LRIT_cadu_frames.cadu',
                 baseband_file=os.environ['HOME'] + '/GOES-LRIT_baseband.dat'):
        grc_wxgui.top_block_gui.__init__(
            self, title="LRIT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.clock_alpha = clock_alpha
        self.symb_rate = symb_rate
        self.pll_alpha = pll_alpha
        self.satellite = satellite
        self.freq = freq
        self.gain = gain
        self.decim = decim
        self.side = side
        self.frames_file = frames_file
        self.baseband_file = baseband_file

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 64e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(
            viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames,
            viterbi_outsync_frames, viterbi_outsync_frames * 3)
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_complex_to_real_0 = gr.complex_to_real(1)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 2)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/martin/GNURadioData/lrit/goes_lrit_D108AD64MHz.sam", True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1)
        self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(
            1, gr.GR_MSB_FIRST)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(
            True, 1024, deframer_insync_frames, deframer_outsync_frames)
        self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.25,
                                      int(11 * samp_rate / symb_rate)))
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_fftsink2 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="RRC filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="BPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.poesweather_metop_cadu_deframer_0, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.fec_decode_viterbi_bpsk_fb_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.wxgui_fftsink2, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.poesweather_metop_cadu_deframer_0, 0),
                     (self.gr_null_sink_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
Ejemplo n.º 52
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.variable_slider_0 = variable_slider_0 = 0
		self.samp_rate = samp_rate = 500e3

		##################################################
		# Controls
		##################################################
		_variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL)
		self._variable_slider_0_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_variable_slider_0_sizer,
			value=self.variable_slider_0,
			callback=self.set_variable_slider_0,
			label="Volume",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._variable_slider_0_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_variable_slider_0_sizer,
			value=self.variable_slider_0,
			callback=self.set_variable_slider_0,
			minimum=0,
			maximum=100,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_variable_slider_0_sizer)

		##################################################
		# Blocks
		##################################################
		self.audio_sink_0 = audio.sink(48000, "", True)
		self.blks2_nbfm_rx_0 = blks2.nbfm_rx(
			audio_rate=25000,
			quad_rate=100000,
			tau=75e-6,
			max_dev=15e3,
		)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc(
			interpolation=1,
			decimation=5,
			taps=None,
			fractional_bw=None,
		)
		self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_fff(
			interpolation=48,
			decimation=25,
			taps=None,
			fractional_bw=None,
		)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((variable_slider_0, ))
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((100e3, ))
		self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass(
			10, samp_rate, 5e3, 10e3, firdes.WIN_HAMMING, 6.76))
		self.uhd_single_usrp_source_0 = uhd.single_usrp_source(
			device_addr="addr=192.168.10.3",
			io_type=uhd.io_type.COMPLEX_FLOAT32,
			num_channels=1,
		)
		self.uhd_single_usrp_source_0.set_samp_rate(samp_rate)
		self.uhd_single_usrp_source_0.set_center_freq(462.5625e6, 0)
		self.uhd_single_usrp_source_0.set_gain(45, 0)
		self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
			self.GetWin(),
			baseband_freq=0,
			dynamic_range=100,
			ref_level=50,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=512,
			fft_rate=15,
			average=False,
			avg_alpha=None,
			title="Waterfall Plot",
		)
		self.Add(self.wxgui_waterfallsink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.blks2_nbfm_rx_0, 0), (self.blks2_rational_resampler_xxx_1, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.blks2_nbfm_rx_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.blks2_rational_resampler_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.uhd_single_usrp_source_0, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.low_pass_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.wxgui_waterfallsink2_0, 0))
Ejemplo n.º 53
0
 def __init__(self, app, samp_rate, inter, dec):
     '''
     in:
         - app = object of type TXApp
         - samp_rate = sample rate in Herz
         - inter = interpolation factor
         - dec = decimation factor
     '''
     gr.hier_block2.__init__(self, "TXGui",
                             gr.io_signature(1, 1, gr.sizeof_gr_complex),
                             gr.io_signature(0, 0, 0))
       
     # instance variables
     self.app = app
     self.gui = wxgui.top_block_gui("BPSK TX", size=default_gui_size) 
     self.nb = self.__createNoteBook()
     
     self.throttle = gr.throttle(gr.sizeof_gr_complex, samp_rate)
     
     # resampler
     if inter == 1 and dec == 1:
         self.resampler = gr.multiply_const_vcc((1,))
         print("i: resampler not need")
     else:
         self.resampler = blks2.rational_resampler_ccc(
             interpolation=inter,
             decimation=dec,
             taps=None,
             fractional_bw=None,
         )
     # samples
     self.fft = fftsink2.fft_sink_c(
             self.nb.GetPage(0).GetWin(),
             baseband_freq=0,
             y_per_div=5,
             y_divs=10,
             ref_level=-40,
             sample_rate= inter*samp_rate/dec,
             fft_size=512,
             fft_rate=10,
             average=True,
             avg_alpha=0.1,
             title="FFT Plot",
             peak_hold=False,
     )
     self.scope_IQ = scopesink2.scope_sink_c(
             self.nb.GetPage(1).GetWin(),
             title="Scope IQ",
             sample_rate = inter*samp_rate/dec,
             v_scale=0.001,
             t_scale=0.001,
             ac_couple=False,
             xy_mode=False,
             num_inputs=1,
     )
     
     # adding the visual components to the notebook
     self.nb.GetPage(0).Add(self.fft.win)
     self.nb.GetPage(1).Add(self.scope_IQ.win)
     
     # phase
     self.cmp2arg = gr.complex_to_arg()
     
     self.fftPhase = fftsink2.fft_sink_f(
             self.nb.GetPage(2).GetWin(),
             baseband_freq=0,
             y_per_div=5,
             y_divs=10,
             ref_level=-40,
             sample_rate= inter*samp_rate/dec,
             fft_size=512,
             fft_rate=10,
             average=True,
             avg_alpha=0.1,
             title="FFT phase Plot",
             peak_hold=False,
     )
     self.scopePhase = scopesink2.scope_sink_f(
             self.nb.GetPage(3).GetWin(),
             title="Scope phase",
             sample_rate = inter*samp_rate/dec,
             v_scale=0.001,
             t_scale=0.001,
             ac_couple=False,
             xy_mode=False,
             num_inputs=1,
     )
     # adding the visual components to the notebook
     self.nb.GetPage(2).Add(self.fftPhase.win)
     self.nb.GetPage(3).Add(self.scopePhase.win)
     
     self.__makeConnections()
Ejemplo n.º 54
0
    def __init__(self,
                 rx_gain=15,
                 rate=1e6,
                 samp_per_sym=4,
                 args="",
                 freq=915e6,
                 ampl=0.7,
                 tx_gain=15,
                 number_of_slots=10,
                 lead_limit=0.025,
                 initial_slot=15,
                 link_speed=15,
                 slot_interval=0.010,
                 guard_interval=15):
        gr.hier_block2.__init__(
            self,
            "TDMA_HIER",
            gr.io_signaturev(2, 2, [gr.sizeof_char * 1, gr.sizeof_char * 1]),
            gr.io_signaturev(2, 2, [gr.sizeof_char * 1, gr.sizeof_char * 1]),
        )

        ##################################################
        # Parameters
        ##################################################
        self.rx_gain = rx_gain
        self.rate = rate
        self.samp_per_sym = samp_per_sym
        self.args = args
        self.freq = freq
        self.ampl = ampl
        self.tx_gain = tx_gain
        self.number_of_slots = number_of_slots
        self.lead_limit = lead_limit
        self.initial_slot = initial_slot
        self.link_speed = link_speed
        self.slot_interval = slot_interval
        self.guard_interval = guard_interval

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = rate

        ##################################################
        # Blocks
        ##################################################
        self.usrp_source = uhd.usrp_source(
            device_addr=args,
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.usrp_source.set_time_source("external", 0)
        self.usrp_source.set_time_unknown_pps(uhd.time_spec())
        self.usrp_source.set_samp_rate(samp_rate)
        self.usrp_source.set_center_freq(freq, 0)
        self.usrp_source.set_gain(rx_gain, 0)
        self.usrp_source.set_antenna("TX/RX", 0)
        self.usrp_sink = uhd.usrp_sink(
            device_addr=args,
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.usrp_sink.set_time_source("external", 0)
        self.usrp_sink.set_time_unknown_pps(uhd.time_spec())
        self.usrp_sink.set_samp_rate(samp_rate)
        self.usrp_sink.set_center_freq(freq, 0)
        self.usrp_sink.set_gain(tx_gain, 0)
        self.usrp_sink.set_antenna("TX/RX", 0)
        self.tdma_engine = precog.tdma_engine(initial_slot, slot_interval,
                                              guard_interval, number_of_slots,
                                              lead_limit, link_speed)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((ampl, ))
        self.gmsk_mod = digital.gmsk_mod(
            samples_per_symbol=samp_per_sym,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.gmsk_demod = digital.gmsk_demod(
            samples_per_symbol=samp_per_sym,
            gain_mu=0.175,
            mu=0.5,
            omega_relative_limit=0.005,
            freq_error=0.0,
            verbose=False,
            log=False,
        )
        self.extras_pmt_rpc_0 = gr_extras.pmt_rpc(obj=self, result_msg=False)
        self.extras_packet_framer_0 = gr_extras.packet_framer(
            samples_per_symbol=1,
            bits_per_symbol=1,
            access_code="",
        )
        self.extras_packet_deframer_0 = gr_extras.packet_deframer(
            access_code="",
            threshold=-1,
        )
        self.burst_gate_0 = precog.burst_gate()

        ##################################################
        # Connections
        ##################################################
        self.connect((self.usrp_source, 0), (self.tdma_engine, 0))
        self.connect((self.tdma_engine, 0), (self.extras_packet_framer_0, 0))
        self.connect((self.usrp_source, 0), (self.gmsk_demod, 0))
        self.connect((self.gmsk_demod, 0), (self.extras_packet_deframer_0, 0))
        self.connect((self.extras_packet_framer_0, 0), (self.gmsk_mod, 0))
        self.connect((self, 1), (self.tdma_engine, 1))
        self.connect((self, 0), (self.tdma_engine, 3))
        self.connect((self.extras_packet_deframer_0, 0), (self, 1))
        self.connect((self.gmsk_mod, 0), (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0), (self.burst_gate_0, 0))
        self.connect((self.burst_gate_0, 0), (self.usrp_sink, 0))
        self.connect((self.extras_packet_deframer_0, 0), (self.tdma_engine, 2))
        self.connect((self, 0), (self.extras_pmt_rpc_0, 0))
        self.connect((self.tdma_engine, 1), (self, 0))