def reset(self):
    self.ch_est.reset()
    self.sampler_trigsrc.rewind()

    cir_len = self.cir_len
    vlen = self.vlen

    self.disconnect( self.padded_sccir, self.conv )
    self.disconnect( self.conv, self.search_window )

    self.disconnect( self.null_source, ( self.padded_sccir, 0 ) )
    self.disconnect( self.serial_ccir, ( self.padded_sccir, 1 ) )
    self.disconnect( self.null_source, ( self.padded_sccir, 2 ) )


    # rebuild
    self.padded_sccir = gr.stream_mux( gr.sizeof_float,
                                       [ cir_len-1, 2*vlen, cir_len-1 ] )

    if cir_len > 1:
      self.conv = gr.fir_filter_fff( 1, [ 1 ] * cir_len )


    self.connect( self.padded_sccir, self.conv )

    self.connect( self.null_source, ( self.padded_sccir, 0 ) )
    self.connect( self.serial_ccir, ( self.padded_sccir, 1 ) )
    self.connect( self.null_source, ( self.padded_sccir, 2 ) )

    self.connect( self.conv, self.search_window )
    def help_stream_2ff(self, N, stream_sizes):
        v0 = gr.vector_source_f(N*[1,], False)
        v1 = gr.vector_source_f(N*[2,], False)
        
        mux = gr.stream_mux(gr.sizeof_float, stream_sizes)

        dst = gr.vector_sink_f ()

        self.tb.connect (v0, (mux,0))
        self.tb.connect (v1, (mux,1))
        self.tb.connect (mux, dst)
        self.tb.run ()

        return dst.data ()
Exemple #3
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True

        SNR = 10.0**(options.snr / 10.0)
        frequency_offset = options.frequency_offset

        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal / SNR
        noise_voltage = math.sqrt(noise_power)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if (options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                            1.01)

            if options.discontinuous:
                z = 20000 * [
                    0,
                ]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5 * ((4 + 8 + 4 + 1500 + 4) * 8)
                self.mux = gr.stream_mux(
                    gr.sizeof_gr_complex,
                    [packet_size - 0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux, 0))
                self.connect(self.zeros, (self.mux, 1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
    def help_stream_ramp_2ff(self, N, stream_sizes):
        r1 = range(N)
        r2 = range(N)
        r2.reverse()

        v0 = gr.vector_source_f(r1, False)
        v1 = gr.vector_source_f(r2, False)
        
        mux = gr.stream_mux(gr.sizeof_float, stream_sizes)

        dst = gr.vector_sink_f ()

        self.tb.connect (v0, (mux,0))
        self.tb.connect (v1, (mux,1))
        self.tb.connect (mux, dst)
        self.tb.run ()

        return dst.data ()
    def help_stream_2ff(self, N, stream_sizes):
        v0 = gr.vector_source_f(N * [
            1,
        ], False)
        v1 = gr.vector_source_f(N * [
            2,
        ], False)

        mux = gr.stream_mux(gr.sizeof_float, stream_sizes)

        dst = gr.vector_sink_f()

        self.tb.connect(v0, (mux, 0))
        self.tb.connect(v1, (mux, 1))
        self.tb.connect(mux, dst)
        self.tb.run()

        return dst.data()
    def help_stream_ramp_2ff(self, N, stream_sizes):
        r1 = range(N)
        r2 = range(N)
        r2.reverse()

        v0 = gr.vector_source_f(r1, False)
        v1 = gr.vector_source_f(r2, False)

        mux = gr.stream_mux(gr.sizeof_float, stream_sizes)

        dst = gr.vector_sink_f()

        self.tb.connect(v0, (mux, 0))
        self.tb.connect(v1, (mux, 1))
        self.tb.connect(mux, dst)
        self.tb.run()

        return dst.data()
Exemple #7
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True;

        SNR = 10.0**(options.snr/10.0)
        frequency_offset = options.frequency_offset
        
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal/SNR
        noise_voltage = math.sqrt(noise_power)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if(options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = gr.channel_model(noise_voltage, frequency_offset, 1.01)

            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True;

        SNR = 10.0**(options.snr/10.0)
        frequency_offset = options.frequency_offset
        
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal/SNR
        noise_voltage = math.sqrt(noise_power)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = awgn_channel(options.sample_rate, noise_voltage,
                                        frequency_offset, options.seed)

            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        if(options.samples_per_symbol is None):
            options.samples_per_symbol = 2

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._timing_gain_alpha = self.rxpath.packet_receiver._demodulator._mm_gain_mu
        self._alpha = self.rxpath.packet_receiver._demodulator._costas_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, self._sample_rate,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, self._sample_rate,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)
            
                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.receiver = self.rxpath.packet_receiver._demodulator.receiver
                self.receiver.set_alpha(2)
                self.receiver.set_beta(0.02)
                self.connect(self.channel, self.snk_tx)
                self.connect(self.receiver, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                 
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Exemple #10
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        if not options.channel_off:
            SNR = 10.0**(options.snr/10.0)
            power_in_signal = abs(options.tx_amplitude)**2.0
            noise_power_in_channel = power_in_signal/SNR
            noise_voltage = math.sqrt(noise_power_in_channel/2.0)
            #noise_voltage = 0
            
            frequency_offset = options.frequency_offset / options.fft_length

            if options.multipath_on:
                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
                #taps = [0.5,0.5]
            else:
                taps = [1.0, 0.0]

            if options.verbose:
                print "Targeted SNR(dB): ",options.snr
                print "Noise Amplitude: ", noise_voltage
                print "Frequency offset: ", frequency_offset
                print "Taps: ",taps
        else:
            noise_voltage = 0.0
            frequency_offset = 0.0
            taps = [1.0, 0.0]

        z = [0,]
        self.zeros = gr.vector_source_c(z, True)
        self.txpath = transmit_path(options)

        self.subcarrier_size = self.txpath._pkt_input.subcarrier_size() 
        #self.subcarrier_size = options.occupied_tones-2
        
        # 4 bytes of Packet Length
        # 1 byte of whitener offset
        # 4 bytes of CRC
        symbols_per_packet = math.ceil(((4+1+options.size+4) * 8) / math.log(self.txpath.arity,2) / self.subcarrier_size)
        
        # 1 set of Preamble
        samples_per_packet = (symbols_per_packet + 3 + 0) * (options.fft_length+options.cp_length)



        print "Symbols per Packet: ", symbols_per_packet
        print "Samples per Packet: ", samples_per_packet


        if options.discontinuous:
            stream_size = [1000, int(options.discontinuous*samples_per_packet) + 512]
        else:
            stream_size = [0, 100000]

        print 'Stream Size=',stream_size

        self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                        options.clockrate_ratio, taps)
        self.rxpath = receive_path(callback, options)
                
        self.connect(self.zeros, (self.mux,0))
        self.connect(self.txpath, (self.mux,1))
        self.connect(self.mux, self.throttle, self.channel, self.rxpath)
        
        #self.connect(self.mux, self.throttle, self.rxpath)
        
        #self.connect(self.txpath, self.throttle, self.channel, self.rxpath)
        #self.connect(self.txpath, self.rxpath)
        
        if options.log:
            self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, "txpath.dat"))
            self.connect(self.mux, gr.file_sink(gr.sizeof_gr_complex, "mux.dat"))
Exemple #11
0
    def __init__(self, options):
        '''
        See below for what options should hold
        '''

	gr.hier_block2.__init__(self, "transmit_path",
				gr.io_signature(0, 0, 0),
				gr.io_signature(1, 1, gr.sizeof_gr_complex))

        options = copy.copy(options)    # make a copy so we can destructively modify

        self._verbose      = options.verbose      # turn verbose mode on/off
        self._tx_amplitude = options.tx_amplitude # digital amp sent to radio
        self._pad_for_usrp = False
        self._modulation = options.modulation
        self._fft_length = options.fft_length
        self._occupied_tones = options.occupied_tones
        self._cp_length = options.cp_length

        msgq_limit = 4

        win = [] #[1 for i in range(self._fft_length)]

        # Use freq domain to get doubled-up known symbol for correlation in time domain
        zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0))


        # STBC Initialization
        self._block_length = 2
        
        print "Length of predetermined known symbols =",len(known_symbols_4512_3)

        # Preamble Sequence
        preamble_sequence = known_symbols_4512_3[0:self._occupied_tones]
        training_sequence = ( known_symbols_4512_3[self._occupied_tones:self._occupied_tones*2], \
                            known_symbols_4512_3[self._occupied_tones*2:self._occupied_tones*3] )
               
        # Generating consecutive two symbols in time domain
        for i in range(len(preamble_sequence)):
            if((zeros_on_left + i) & 1):
                preamble_sequence[i] = 0

        
        for i in range(len(training_sequence[0])):
                #training_sequence[0][i] = 0
                training_sequence[1][i] = 0

        # hard-coded known symbols
        # preambles = (preamble_sequence,)
        preambles = (preamble_sequence, training_sequence[0], training_sequence[1])
                
        padded_preambles = list()
        for pre in preambles:
            padded = self._fft_length*[0,]
            padded[zeros_on_left : zeros_on_left + self._occupied_tones] = pre
            padded_preambles.append(padded)
            
        symbol_length = options.fft_length + options.cp_length
        
        mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
        self.arity = mods[self._modulation]
        
        rot = 1
        if self._modulation == "qpsk":
            rot = (0.707+0.707j)

        print "Padded Preambles (l=%d,%d):"%(len(padded_preambles),len(padded_preambles[0])), padded_preambles
            
        # FIXME: pass the constellation objects instead of just the points
        if(self._modulation.find("psk") >= 0):
            constel = psk.psk_constellation(self.arity)
            rotated_const = map(lambda pt: pt * rot, constel.points())
        elif(self._modulation.find("qam") >= 0):
            constel = qam.qam_constellation(self.arity)
            rotated_const = map(lambda pt: pt * rot, constel.points())
        #print rotated_const
        self._pkt_input = gtlib.ofdm_mapper_bcv(rotated_const,
                                                       msgq_limit,
                                                       options.occupied_tones,
                                                       options.fft_length)
        
        self.preambles = gtlib.ofdm_insert_preamble(self._fft_length,
                                                           padded_preambles)
        self.ifft = gr.fft_vcc(self._fft_length, False, win, True)
        self.cp_adder = gtlib.ofdm_cyclic_prefixer(self._fft_length,
                                                          symbol_length)
        self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length))

        self.amp = gr.multiply_const_cc(1)
        self.set_tx_amplitude(self._tx_amplitude)

        """        
        Transformation Matrix
        
        Alamouti
        
         1  0  0  0
         0  1  0  0
         0  0  0  1
         0  0 -1  0
        
        """ 
        
        code_matrix = [ [1,0,0,0], [0,1,0,0], [0,0,0,-1], [0,0,1,0] ];
        
        self.stbc_encoder = gtlib.ofdm_stbc_encoder(options.fft_length,code_matrix, 1.0)
        
        # Create and setup transmit path flow graph
        
        self.subcarrier_size = self._pkt_input.subcarrier_size() 
        symbols_per_packet = math.ceil(((4+1+options.size+4) * 8) / math.log(self.arity,2) / self.subcarrier_size)
        samples_per_packet = (symbols_per_packet + 3 + 0) * (options.fft_length+options.cp_length)

        stream_size = [int(options.discontinuous*samples_per_packet), 0]

        z = [0.000001,]
        self.zeros = gr.vector_source_c(z, True)
        self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
        
        
        #self.connect((self._pkt_input, 0), (self.preambles, 0))
        #self.connect((self._pkt_input, 1), (self.preambles, 1))
        
        self.connect((self._pkt_input, 0), (self.stbc_encoder, 0))
        self.connect((self._pkt_input, 1), (self.stbc_encoder, 1))
        
        self.connect( (self.stbc_encoder,0) , (self.preambles, 0))
        self.connect( (self.stbc_encoder,1), gr.null_sink ( 8*self._fft_length) )

        self.connect((self._pkt_input, 1), (self.preambles, 1))
        
        if options.dummy_zero:
            self.connect(self.preambles, self.ifft, self.cp_adder, self.scale, self.amp, (self.mux,0))
            self.connect(self.zeros , (self.mux,1))
            self.connect(self.mux, self)
        else:        
            self.connect(self.preambles, self.ifft, self.cp_adder, self.scale, self.amp, self)
        
        
     
        if options.verbose:
            self._print_verbage()

        if options.log:
            self.connect(self._pkt_input, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                       "ofdm_mapper_c.dat"))
            self.connect((self.stbc_encoder,0), gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                       "ofdm_stbc_encoder_c.dat"))
            self.connect(self.preambles, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                      "ofdm_preambles.dat"))
            self.connect(self.ifft, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                 "ofdm_ifft_c.dat"))
            self.connect(self.cp_adder, gr.file_sink(gr.sizeof_gr_complex,
                                                     "ofdm_cp_adder_c.dat"))
Exemple #12
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))
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if(options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._gain_clock = self.rxpath.packet_receiver._demodulator._timing_alpha
        self._gain_phase = self.rxpath.packet_receiver._demodulator._phase_alpha
        self._gain_freq  = self.rxpath.packet_receiver._demodulator._freq_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)

                self.freq_recov = self.rxpath.packet_receiver._demodulator.freq_recov
                self.phase_recov = self.rxpath.packet_receiver._demodulator.phase_recov
                self.time_recov = self.rxpath.packet_receiver._demodulator.time_recov
                self.freq_recov.set_alpha(self._gain_freq)
                self.freq_recov.set_beta(self._gain_freq/10.0)
                self.phase_recov.set_alpha(self._gain_phase)
                self.phase_recov.set_beta(0.25*self._gain_phase*self._gain_phase)
                self.time_recov.set_alpha(self._gain_clock)
                self.time_recov.set_beta(0.25*self._gain_clock*self._gain_clock)

                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.connect(self.channel, self.snk_tx)
                self.connect(self.phase_recov, self.snk_rx)
                #self.connect(self.freq_recov, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                 
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
  def __init__( self, vlen, cp_len ):

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

    self.ch_est = channel_estimator_001( vlen )
    self.connect( self, self.ch_est )

    cir_len = cp_len + 1
    self.cir_len = cir_len
    self.vlen = vlen

    self.preamble_td = self.ch_est.td
    self.preamble_fd = self.ch_est.fd

    # CTF -> CIR
    self.cir_est = gr.fft_vcc( vlen, False, [], False ) # IFFT
    self.connect( self.ch_est, self.cir_est )

    # CIR -> energy per sample
    self.cir_energy = gr.complex_to_mag_squared( vlen )
    self.connect( self.cir_est, self.cir_energy )

    # prepare cyclic convolution of CIR vector
    self.cyclic_cir = gr.streams_to_vector( gr.sizeof_float * vlen, 2 )
    self.connect( self.cir_energy, ( self.cyclic_cir, 0 ) )
    self.connect( self.cir_energy, ( self.cyclic_cir, 1 ) )

    # Cyclic convolution of CIR vector
    # Pad CIR vector: 0 x cp_len, CIR, CIR, 0 x cp_len
    self.serial_ccir = gr.vector_to_stream( gr.sizeof_float, vlen * 2 )
    self.padded_sccir = gr.stream_mux( gr.sizeof_float,
                                       [ cir_len-1, 2*vlen, cir_len-1 ] )

    if cir_len > 1:
      self.conv = gr.fir_filter_fff( 1, [ 1 ] * cir_len )
    else:
      self.conv = gr.kludge_copy( gr.sizeof_float )


    self.connect( self.padded_sccir, self.conv )

    self.null_source = gr.null_source( gr.sizeof_float )
    self.connect( self.cyclic_cir, self.serial_ccir )
    self.connect( self.null_source, ( self.padded_sccir, 0 ) )
    self.connect( self.serial_ccir, ( self.padded_sccir, 1 ) )
    self.connect( self.null_source, ( self.padded_sccir, 2 ) )


    # Extract search window
    self.search_window = ofdm.vector_sampler( gr.sizeof_float, vlen )
    periodic_trigger_seq = [ 0 ] * ( ( vlen + cir_len-1 ) * 2 )
    periodic_trigger_seq[ cir_len-1 + cir_len-1 + vlen-1 ] = 1
    self.sampler_trigsrc = gr.vector_source_b( periodic_trigger_seq, True )
    self.connect( self.conv, self.search_window )
    self.connect( self.sampler_trigsrc, ( self.search_window, 1 ) )

    # Find point of maximum energy
    self.cir_start = gr.argmax_fs( vlen )
    self.connect( self.search_window, self.cir_start )
    self.connect( ( self.cir_start, 1 ), gr.null_sink( gr.sizeof_short ) )

    # Set to zero all samples that do not belong to the CIR
    self.filtered_cir = ofdm.interp_cir_set_noncir_to_zero( vlen, cir_len )
    #self.filtered_cir = gr.kludge_copy( gr.sizeof_gr_complex * vlen )
    self.connect( self.cir_est, self.filtered_cir )
    self.connect( self.cir_start, ( self.filtered_cir, 1 ) )
    #self.connect( self.cir_start, gr.null_sink( gr.sizeof_short ) )

    # CIR -> CTF
    self.filtered_ctf = gr.fft_vcc( vlen, True, [], False ) # FFT
    self.scaled_fctf = gr.multiply_const_vcc( [1./vlen]*vlen )
    self.connect( self.filtered_cir, self.filtered_ctf )
    self.connect( self.filtered_ctf, self.scaled_fctf )

    # Output connection
    self.connect( self.scaled_fctf, self )
    def __init__(
        self,
        decim=16,
        fft_size=2048 / 16,
        N_re=62,
        avg_frames=8,
        dump=None,
        N_id_1s=range(0, 168),
        slot_0_10s=range(0, 2),
    ):
        self.logger = logging.getLogger("sss_corr2")

        # store parameters
        self.decim = decim
        self.fft_size = fft_size
        self.N_re = N_re
        self.avg_frames = avg_frames
        self.dump = dump
        self.N_id_1s = N_id_1s
        self.slot_0_10s = slot_0_10s

        # calculate statics
        self.symbol_mask = numpy.zeros(20 * 7)
        self.symbol_mask[5:7] = 1
        self.symbol_mask[75:77] = 1

        # generate PSS sequences
        self.pss_fd_vec = []
        for N_id_2 in range(0, 3):
            self.pss_fd_vec.append(gen_pss_fd(N_id_2, self.N_re, False).get_data())

        # generate SSS sequences
        self.sss_fd_vec = []
        for N_id_2 in range(0, 3):
            self.sss_fd_vec.append([])
            for N_id_1 in range(0, 168):
                self.sss_fd_vec[N_id_2].append([])
                for slot_0_10 in range(0, 2):
                    self.sss_fd_vec[N_id_2][N_id_1].append(
                        gen_sss_fd(N_id_1, N_id_2, N_re).get_sss_conj(slot_0_10 != 0)
                    )
        self.pss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re)
        self.sss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re)

        # SSS equalization flow graph
        self.equ_source = symbol_source(decim=self.decim, vlen=self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, (window.blackmanharris(1024)), True, 1)
        vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex * 1, self.fft_size)
        keep_m_in_n_0 = gr.keep_m_in_n(
            gr.sizeof_gr_complex, self.N_re / 2, self.fft_size, (self.fft_size - self.N_re) / 2 - 1
        )
        keep_m_in_n_1 = gr.keep_m_in_n(gr.sizeof_gr_complex, self.N_re / 2, self.fft_size, (self.fft_size) / 2)
        stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex, 2 * [self.N_re / 2])
        stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex * 1, self.N_re)
        deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * self.N_re)
        self.equ = sss_equ2()
        self.equ_sink = gr.vector_sink_c(self.N_re)

        self.equ_top = gr.top_block("sss equ graph")
        self.equ_top.connect(self.equ_source, fft, vector_to_stream_0)
        self.equ_top.connect(vector_to_stream_0, keep_m_in_n_0, (stream_mux_0, 0))
        self.equ_top.connect(vector_to_stream_0, keep_m_in_n_1, (stream_mux_0, 1))
        self.equ_top.connect(stream_mux_0, stream_to_vector_0_0, deinterleave_0)
        self.equ_top.connect((deinterleave_0, 0), (self.equ, 0))
        self.equ_top.connect((deinterleave_0, 1), (self.equ, 1))
        self.equ_top.connect(self.pss_ref_src, (self.equ, 2))
        self.equ_top.connect((self.equ, 0), self.equ_sink)
        self.equ_top.connect((self.equ, 1), gr.null_sink(self.N_re * gr.sizeof_gr_complex))

        if self.dump != None:
            self.equ_top.connect(
                self.equ_source, gr.file_sink(gr.sizeof_gr_complex * self.fft_size, self.dump + "_sss_td_in.cfile")
            )
            self.equ_top.connect(
                (deinterleave_0, 0), gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_in.cfile")
            )
            self.equ_top.connect(
                (deinterleave_0, 1), gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_pss_fd_in.cfile")
            )
            self.equ_top.connect(
                self.equ, gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_equ.cfile")
            )

        # SSS maximum likelihood estimation
        self.ml_src = gr.vector_source_c(zeros(0), False, self.N_re)
        self.ml_derot = sss_derot()
        self.ml_sss = sss_ml_fd2(avg_frames=self.avg_frames)
        self.ml_sink = gr.vector_sink_f()

        self.ml_top = gr.top_block("sss ml graph")
        self.ml_top.connect(self.ml_src, self.ml_derot, self.ml_sss, self.ml_sink)
        self.ml_top.connect(self.sss_ref_src, (self.ml_derot, 1))
        self.ml_top.connect(self.sss_ref_src, (self.ml_sss, 1))

        if self.dump != None:
            self.ml_top.connect(
                self.ml_derot, gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_derot.cfile")
            )
            self.ml_top.connect(self.ml_sss, gr.file_sink(gr.sizeof_float, self.dump + "_sss_corr.cfile"))
Exemple #16
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))
Exemple #17
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._gain_mu = self.rxpath.packet_receiver._demodulator._mm_gain_mu
        self._alpha = self.rxpath.packet_receiver._demodulator._costas_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)
            
                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.receiver = self.rxpath.packet_receiver._demodulator.receiver
                self.connect(self.channel, self.snk_tx)
                self.connect(self.receiver, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)
                
                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Exemple #18
0
    def __init__(self,
                 decim=16,
                 fft_size=2048 / 16,
                 N_re=62,
                 avg_frames=8,
                 dump=None,
                 N_id_1s=range(0, 168),
                 slot_0_10s=range(0, 2)):
        self.logger = logging.getLogger('sss_corr2')

        # store parameters
        self.decim = decim
        self.fft_size = fft_size
        self.N_re = N_re
        self.avg_frames = avg_frames
        self.dump = dump
        self.N_id_1s = N_id_1s
        self.slot_0_10s = slot_0_10s

        # calculate statics
        self.symbol_mask = numpy.zeros(20 * 7)
        self.symbol_mask[5:7] = 1
        self.symbol_mask[75:77] = 1

        # generate PSS sequences
        self.pss_fd_vec = []
        for N_id_2 in range(0, 3):
            self.pss_fd_vec.append(
                gen_pss_fd(N_id_2, self.N_re, False).get_data())

        # generate SSS sequences
        self.sss_fd_vec = []
        for N_id_2 in range(0, 3):
            self.sss_fd_vec.append([])
            for N_id_1 in range(0, 168):
                self.sss_fd_vec[N_id_2].append([])
                for slot_0_10 in range(0, 2):
                    self.sss_fd_vec[N_id_2][N_id_1].append(
                        gen_sss_fd(N_id_1, N_id_2,
                                   N_re).get_sss_conj(slot_0_10 != 0))
        self.pss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re)
        self.sss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re)

        # SSS equalization flow graph
        self.equ_source = symbol_source(decim=self.decim, vlen=self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, (window.blackmanharris(1024)),
                         True, 1)
        vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex * 1,
                                                 self.fft_size)
        keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, self.N_re / 2,
                                       self.fft_size,
                                       (self.fft_size - self.N_re) / 2 - 1)
        keep_m_in_n_1 = gr.keep_m_in_n(gr.sizeof_gr_complex, self.N_re / 2,
                                       self.fft_size, (self.fft_size) / 2)
        stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex, 2 * [self.N_re / 2])
        stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex * 1,
                                                   self.N_re)
        deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * self.N_re)
        self.equ = sss_equ2()
        self.equ_sink = gr.vector_sink_c(self.N_re)

        self.equ_top = gr.top_block("sss equ graph")
        self.equ_top.connect(self.equ_source, fft, vector_to_stream_0)
        self.equ_top.connect(vector_to_stream_0, keep_m_in_n_0,
                             (stream_mux_0, 0))
        self.equ_top.connect(vector_to_stream_0, keep_m_in_n_1,
                             (stream_mux_0, 1))
        self.equ_top.connect(stream_mux_0, stream_to_vector_0_0,
                             deinterleave_0)
        self.equ_top.connect((deinterleave_0, 0), (self.equ, 0))
        self.equ_top.connect((deinterleave_0, 1), (self.equ, 1))
        self.equ_top.connect(self.pss_ref_src, (self.equ, 2))
        self.equ_top.connect((self.equ, 0), self.equ_sink)
        self.equ_top.connect((self.equ, 1),
                             gr.null_sink(self.N_re * gr.sizeof_gr_complex))

        if self.dump != None:
            self.equ_top.connect(
                self.equ_source,
                gr.file_sink(gr.sizeof_gr_complex * self.fft_size,
                             self.dump + "_sss_td_in.cfile"))
            self.equ_top.connect((deinterleave_0, 0),
                                 gr.file_sink(gr.sizeof_gr_complex * self.N_re,
                                              self.dump + "_sss_fd_in.cfile"))
            self.equ_top.connect((deinterleave_0, 1),
                                 gr.file_sink(gr.sizeof_gr_complex * self.N_re,
                                              self.dump + "_pss_fd_in.cfile"))
            self.equ_top.connect(
                self.equ,
                gr.file_sink(gr.sizeof_gr_complex * self.N_re,
                             self.dump + "_sss_fd_equ.cfile"))

        # SSS maximum likelihood estimation
        self.ml_src = gr.vector_source_c(zeros(0), False, self.N_re)
        self.ml_derot = sss_derot()
        self.ml_sss = sss_ml_fd2(avg_frames=self.avg_frames)
        self.ml_sink = gr.vector_sink_f()

        self.ml_top = gr.top_block("sss ml graph")
        self.ml_top.connect(self.ml_src, self.ml_derot, self.ml_sss,
                            self.ml_sink)
        self.ml_top.connect(self.sss_ref_src, (self.ml_derot, 1))
        self.ml_top.connect(self.sss_ref_src, (self.ml_sss, 1))

        if self.dump != None:
            self.ml_top.connect(
                self.ml_derot,
                gr.file_sink(gr.sizeof_gr_complex * self.N_re,
                             self.dump + "_sss_fd_derot.cfile"))
            self.ml_top.connect(
                self.ml_sss,
                gr.file_sink(gr.sizeof_float, self.dump + "_sss_corr.cfile"))