Пример #1
0
    def test_convolutional_encoder(self):
        """
		Tests convolutional encoder
		"""
        src_data = make_transport_stream()
        constellation = [.7, .7, .7, -.7, -.7, .7, -.7, -.7]

        src = gr.vector_source_b(src_data)
        unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        enc = dvb_convolutional_encoder_bb.convolutional_encoder_bb()
        repack1 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        repack2 = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST)
        mapper = gr.chunks_to_symbols_bf(constellation,
                                         dvb_swig.dimensionality)
        viterbi = trellis.viterbi_combined_fb(
            trellis.fsm(dvb_swig.k, dvb_swig.n,
                        dvb_convolutional_encoder_bb.G), dvb_swig.K, -1, -1,
            dvb_swig.dimensionality, constellation, digital.TRELLIS_EUCLIDEAN)
        pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        dst = gr.vector_sink_b()

        self.tb.connect(src, unpack, enc, repack1, repack2, mapper)
        self.tb.connect(mapper, viterbi, pack, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(tuple(src_data[:len(result_data)]), result_data)
Пример #2
0
	def __init__(self):
		gr.top_block.__init__(self, "Many Rate Changing")

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

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

		##################################################
		# Connections
		##################################################
		self.connect((self.blocks_char_to_float_0, 0), (self.blocks_keep_m_in_n_0, 0))
		self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_float_to_char_0, 0))
		self.connect((self.blocks_float_to_char_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.blocks_char_to_float_0, 0))
		self.connect((self.random_source_x_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_null_sink_0_2, 0))
Пример #3
0
    def __init__(self, randstring, fill=None, width=None, lrs_len=None):
        gr.hier_block2.__init__(
            self, "generalized_randomizer", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_char)
        )

        if lrs_len == None:
            lrs_len = width

        self.randstring = randstring

        myrand = stringtorand(self.randstring)

        if randstring.startswith("F"):
            self._randomizer = fsblks.randomizer_feedthrough_bb(myrand[1])
            self.connect(self, (self._randomizer, 0))
            self.connect((self._randomizer, 0), self)

        elif randstring.startswith("A"):
            self._pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
            self._randomizer = fsblks.randomizer_additive_bb(myrand[1], lrs_len, width, fill)
            self._unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
            self.connect(self, self._pack, self._randomizer)
            self.connect(self._randomizer, self._unpack, self)

        else:
            assert False, "Check randomizer string input: only additive or feedthrough allowed."
Пример #4
0
    def __init__(self, sample_rate, symbol_rate):
        gr.hier_block2.__init__(
            self,
            "dvb_s_modulator_bc",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        samples_per_symbol = sample_rate / symbol_rate
        if samples_per_symbol < 2:
            raise TypeError, "Samples per symbol must be >= 2"

        # Form symbols with 2 bits per symbol
        self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.reunpack = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST)

        self.mapper = gr.chunks_to_symbols_bc(mod_constellation)

        # Design FIR filter taps for square root raised cosine filter
        ntaps = 11 * int(samples_per_symbol * nfilts)
        rrc_taps = gr.firdes.root_raised_cosine(nfilts, nfilts, 1.0,
                                                dvb_swig.RRC_ROLLOFF_FACTOR,
                                                ntaps)
        # Baseband pulse shaping filter
        self.rrc_filter = gr.pfb_arb_resampler_ccf(samples_per_symbol,
                                                   rrc_taps)

        self.connect(self, self.pack, self.reunpack, self.mapper,
                     self.rrc_filter, self)
 def __init__(self,
              constellation,
              differential,
              data_length=None,
              src_data=None):
     """
     constellation -- a constellation object
     differential -- whether differential encoding is used
     data_length -- the number of bits of data to use
     src_data -- a list of the bits to use
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple(
             [random.randint(0, 1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = gr.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET,
                                TIMING_OFFSET)
     # Receiver Blocks
     demod = generic_demod(constellation,
                           differential=differential,
                           freq_bw=FREQ_BW,
                           phase_bw=PHASE_BW)
     self.dst = gr.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
Пример #6
0
    def __init__(self, randstring, fill=None, width=None, lrs_len=None):
        gr.hier_block2.__init__(self, "generalized_randomizer",
                                gr.io_signature(1, 1, gr.sizeof_char),
                                gr.io_signature(1, 1, gr.sizeof_char))

        if (lrs_len == None):
            lrs_len = width

        self.randstring = randstring

        myrand = stringtorand(self.randstring)

        if randstring.startswith("F"):
            self._randomizer = fsblks.randomizer_feedthrough_bb(myrand[1])
            self.connect(self, (self._randomizer, 0))
            self.connect((self._randomizer, 0), self)

        elif randstring.startswith("A"):
            self._pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
            self._randomizer = fsblks.randomizer_additive_bb(
                myrand[1], lrs_len, width, fill)
            self._unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
            self.connect(self, self._pack, self._randomizer)
            self.connect(self._randomizer, self._unpack, self)

        else:
            assert (
                False
            ), 'Check randomizer string input: only additive or feedthrough allowed.'
Пример #7
0
 def __init__(self, constellation, differential,
              data_length=None, src_data=None):
     """
     constellation -- a constellation object
     differential -- whether differential encoding is used
     data_length -- the number of bits of data to use
     src_data -- a list of the bits to use
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple([rndm.randint(0,1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = gr.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
     # Receiver Blocks
     demod = generic_demod(constellation, differential=differential,
                           freq_bw=FREQ_BW,
                           phase_bw=PHASE_BW)
     self.dst = gr.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
    def __init__(self):
        gr.top_block.__init__(self, "Many Rate Changing")

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

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

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_char_to_float_0, 0),
                     (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_float_to_char_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_unpacked_to_packed_xx_0, 0),
                     (self.blocks_char_to_float_0, 0))
        self.connect((self.random_source_x_0, 0),
                     (self.gr_unpacked_to_packed_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.gr_null_sink_0_2, 0))
Пример #9
0
	def __init__(self):
		gr.top_block.__init__(self, "Wmbus Phy2")

		##################################################
		# Variables
		##################################################
		self.frame = frame = [1,1]

		##################################################
		# Blocks
		##################################################
		self.gr_vector_source_x_0 = gr.vector_source_b((frame), False, 1)
		self.gr_vector_sink_x_1 = gr.vector_sink_b(1)
		self.gr_vector_sink_x_0 = gr.vector_sink_b(1)
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(4, gr.GR_MSB_FIRST)
		self.gr_pack_k_bits_bb_0 = gr.pack_k_bits_bb(6)
		self.digital_map_bb_1 = digital.map_bb(([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]))
		self.digital_map_bb_0 = digital.map_bb(([16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 3, 16, 1, 2, 16, 16, 16, 16, 7, 16, 16, 0, 16, 16, 5, 6, 16, 4, 16, 16, 16, 16, 16, 16, 11, 16, 9, 10, 16, 16, 15, 16, 16, 8, 16, 16, 16, 16, 13, 14, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]))

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_pack_k_bits_bb_0, 0))
		self.connect((self.gr_pack_k_bits_bb_0, 0), (self.digital_map_bb_0, 0))
		self.connect((self.digital_map_bb_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_vector_sink_x_0, 0))
		self.connect((self.digital_map_bb_0, 0), (self.digital_map_bb_1, 0))
		self.connect((self.digital_map_bb_1, 0), (self.gr_vector_sink_x_1, 0))
Пример #10
0
    def __init__(self, constellation, differential, rotation):
        if constellation.arity() > 256:
            # If this becomes limiting some of the blocks should be generalised so
            # that they can work with shorts and ints as well as chars.
            raise ValueError("Constellation cannot contain more than 256 points.")

	gr.hier_block2.__init__(self, "mod_demod",
				gr.io_signature(1, 1, gr.sizeof_char),       # Input signature
				gr.io_signature(1, 1, gr.sizeof_char))       # Output signature

        arity = constellation.arity()

        # TX
        self.constellation = constellation
        self.differential = differential
        import weakref
        self.blocks = [weakref.proxy(self)]
        # We expect a stream of unpacked bits.
        # First step is to pack them.
        self.blocks.append(
            gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST))
        # Second step we unpack them such that we have k bits in each byte where
        # each constellation symbol hold k bits.
        self.blocks.append(
            gr.packed_to_unpacked_bb(self.constellation.bits_per_symbol(),
                                     gr.GR_MSB_FIRST))
        # Apply any pre-differential coding
        # Gray-coding is done here if we're also using differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(gr.map_bb(self.constellation.pre_diff_code()))
        # Differential encoding.
        if self.differential:
            self.blocks.append(gr.diff_encoder_bb(arity))
        # Convert to constellation symbols.
        self.blocks.append(gr.chunks_to_symbols_bc(self.constellation.points(),
                                                   self.constellation.dimensionality()))
        # CHANNEL
        # Channel just consists of a rotation to check differential coding.
        if rotation is not None:
            self.blocks.append(gr.multiply_const_cc(rotation))

        # RX
        # Convert the constellation symbols back to binary values.
        self.blocks.append(digital_swig.constellation_decoder_cb(self.constellation.base()))
        # Differential decoding.
        if self.differential:
            self.blocks.append(gr.diff_decoder_bb(arity))
        # Decode any pre-differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(gr.map_bb(
                mod_codes.invert_code(self.constellation.pre_diff_code())))
        # unpack the k bit vector into a stream of bits            
        self.blocks.append(gr.unpack_k_bits_bb(
                self.constellation.bits_per_symbol()))
        # connect to block output
        check_index = len(self.blocks)
        self.blocks = self.blocks[:check_index]
        self.blocks.append(weakref.proxy(self))

        self.connect(*self.blocks)
Пример #11
0
    def __init__(self, constellation, differential, rotation):
        if constellation.arity() > 256:
            # If this becomes limiting some of the blocks should be generalised so
            # that they can work with shorts and ints as well as chars.
            raise ValueError("Constellation cannot contain more than 256 points.")

	gr.hier_block2.__init__(self, "mod_demod",
				gr.io_signature(1, 1, gr.sizeof_char),       # Input signature
				gr.io_signature(1, 1, gr.sizeof_char))       # Output signature

        arity = constellation.arity()

        # TX
        self.constellation = constellation
        self.differential = differential
        self.blocks = [self]
        # We expect a stream of unpacked bits.
        # First step is to pack them.
        self.blocks.append(
            gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST))
        # Second step we unpack them such that we have k bits in each byte where
        # each constellation symbol hold k bits.
        self.blocks.append(
            gr.packed_to_unpacked_bb(self.constellation.bits_per_symbol(),
                                     gr.GR_MSB_FIRST))
        # Apply any pre-differential coding
        # Gray-coding is done here if we're also using differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(gr.map_bb(self.constellation.pre_diff_code()))
        # Differential encoding.
        if self.differential:
            self.blocks.append(gr.diff_encoder_bb(arity))
        # Convert to constellation symbols.
        self.blocks.append(gr.chunks_to_symbols_bc(self.constellation.points(),
                                                   self.constellation.dimensionality()))
        # CHANNEL
        # Channel just consists of a rotation to check differential coding.
        if rotation is not None:
            self.blocks.append(gr.multiply_const_cc(rotation))

        # RX
        # Convert the constellation symbols back to binary values.
        self.blocks.append(digital_swig.constellation_decoder_cb(self.constellation.base()))
        # Differential decoding.
        if self.differential:
            self.blocks.append(gr.diff_decoder_bb(arity))
        # Decode any pre-differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(gr.map_bb(
                mod_codes.invert_code(self.constellation.pre_diff_code())))
        # unpack the k bit vector into a stream of bits            
        self.blocks.append(gr.unpack_k_bits_bb(
                self.constellation.bits_per_symbol()))
        # connect to block output
        check_index = len(self.blocks)
        self.blocks = self.blocks[:check_index]
        self.blocks.append(self)

        self.connect(*self.blocks)
Пример #12
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 25000000
		self.dec_rate = dec_rate = 25

		##################################################
		# Blocks
		##################################################
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.GetWin(),
			baseband_freq=0,
			y_per_div=10,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=samp_rate/dec_rate,
			fft_size=1024,
			fft_rate=15,
			average=False,
			avg_alpha=None,
			title="FFT Plot",
			peak_hold=False,
		)
		self.Add(self.wxgui_fftsink2_0.win)
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(dec_rate, (firdes.low_pass(1,samp_rate,1000000,100000)), -1000000, samp_rate)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/shampoo/sdr/capture/j9Pro-capture/2400000000-25M-1.cap", False)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_char*1, "/shampoo/sdr/projects/gr-nineeagles/gmsk-packed.out")
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/shampoo/sdr/projects/gr-nineeagles/gmsk-unpacked.out")
		self.gr_file_sink_0.set_unbuffered(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,
		)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.digital_gmsk_demod_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.digital_gmsk_demod_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.digital_gmsk_demod_0, 0))
Пример #13
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 1000

		##################################################
		# Blocks
		##################################################
		self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0)
		self.gr_descrambler_bb_0 = gr.descrambler_bb(0x8A, 0x7F, 7)
		self.gr_float_to_complex_0 = gr.float_to_complex(1)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.gr_scrambler_bb_0 = gr.scrambler_bb(0x8A, 0x7F, 7)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.gr_throttle_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate)
		self.gr_throttle_0_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate*8)
		self.gr_throttle_0_0_0_0 = gr.throttle(gr.sizeof_char*1, samp_rate*8*8)
		self.gr_uchar_to_float_0 = gr.uchar_to_float()
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		self.gr_vector_source_x_0 = gr.vector_source_b((0, 1, 3,7,255,3,1,0), True, 1)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate*32,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
		)
		self.Add(self.wxgui_scopesink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_float_to_complex_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1))
		self.connect((self.gr_throttle_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_throttle_0_0, 0))
		self.connect((self.gr_throttle_0_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_descrambler_bb_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_throttle_0_0_0, 0))
		self.connect((self.gr_throttle_0_0_0, 0), (self.gr_scrambler_bb_0, 0))
		self.connect((self.gr_scrambler_bb_0, 0), (self.gr_throttle_0_0_0_0, 0))
		self.connect((self.gr_throttle_0_0_0_0, 0), (self.gr_descrambler_bb_0, 0))
		self.connect((self.gr_uchar_to_float_0, 0), (self.gr_float_to_complex_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_uchar_to_float_0, 0))
Пример #14
0
	def test_convolutional_encoder(self):
		"""
		Tests convolutional encoder
		"""
		src_data = make_transport_stream()
		constellation = [.7, .7,.7,-.7,-.7,.7,-.7,-.7]

		src = gr.vector_source_b(src_data)
		unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		enc = dvb_convolutional_encoder_bb.convolutional_encoder_bb()
		repack1 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		repack2 = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST)
		mapper = gr.chunks_to_symbols_bf(constellation, dvb_swig.dimensionality)
		viterbi = trellis.viterbi_combined_fb(trellis.fsm(dvb_swig.k, dvb_swig.n, dvb_convolutional_encoder_bb.G),
				dvb_swig.K, -1, -1, dvb_swig.dimensionality, constellation, trellis.TRELLIS_EUCLIDEAN)
		pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		dst = gr.vector_sink_b()

		self.tb.connect(src, unpack, enc, repack1, repack2, mapper)
		self.tb.connect(mapper, viterbi, pack, dst)
		self.tb.run()
		result_data = dst.data()
		self.assertEqual(tuple(src_data[:len(result_data)]), result_data)
    def test_006(self):
        """
        Test stream_to_streams.
        """
        src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0)
        expected_results =  (0x82,0x5a)
        src = gr.vector_source_b(src_data,False)
        op = gr.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        self.fg.connect(src, op)
        
        dst = gr.vector_sink_b()
        self.fg.connect(op, dst)

        self.fg.run()

        self.assertEqual(expected_results, dst.data())
Пример #16
0
    def test_008(self):
        """
        Test stream_to_streams.
        """
        src_data = (0, 4, 2, 0, 0)
        expected_results = (0x11,)
        src = gr.vector_source_b(src_data, False)
        op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
        self.tb.connect(src, op)

        dst = gr.vector_sink_b()
        self.tb.connect(op, dst)

        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Пример #17
0
    def test_008(self):
        """
        Test stream_to_streams.
        """
        src_data = (0, 4, 2,0,0)
        expected_results = (0x11,)
        src = gr.vector_source_b(src_data,False)
        op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
        self.tb.connect(src, op)
        
        dst = gr.vector_sink_b()
        self.tb.connect(op, dst)

        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Пример #18
0
 def test_two(self):
     tb = gr.top_block()
     MTU = 4000
     tagname = "length"
     packets = (
         (0, 0, 0, 0)*32,
         #(0, 0, 1, 0)*16,
         #(1, 1, 1, 0)*4,
         )
     data, tags = ofdm.utils.packets_to_vectors(packets, tagname)
     constellation = digital.bpsk_constellation()
     src = gr.vector_source_b(data, tags, False, 1)
     tag_scaler1 = ofdm.scale_tags(1, tagname, 0.125)
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     crc = ofdm.crc32_bb(False, MTU, tagname)
     tag_scaler2 = ofdm.scale_tags(1, tagname, 8)
     unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
     mod1 = digital.chunks_to_symbols_bc(constellation.points())
     mod2 = digital.chunks_to_symbols_bc(constellation.points())
     occupied_carriers = ((1, 2, 4, 5),)
     fft_len = 16
     header = ofdm.ofdm_header_bb(len(occupied_carriers[0]))
     mux1 = ofdm.tagged_stream_mux(gr.sizeof_gr_complex, 2, tagname, MTU)
     mux2 = ofdm.tagged_stream_mux(gr.sizeof_gr_complex*fft_len, 2, tagname, MTU)
     ifft = fft.fft_vcc(fft_len, forward=False, window=[1]*fft_len)
     cp_len = 4
     rolloff_len = 2
     cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len+cp_len, rolloff_len, tagname, MTU)
     pilot_symbols = ((1j,),)
     pilot_carriers = ((3,),)
     alloc = ofdm.carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tagname)
     snk = gr.vector_sink_c()
     sync_packet = [0, 1, 0, 1, 0, 1] + [0]*10
     sync_data, sync_tags = ofdm.utils.packets_to_vectors([sync_packet], tagname, vlen=fft_len)
     sync_header = gr.vector_source_c(sync_data, sync_tags, True, fft_len)
     tb.connect(src, tag_scaler1, packer, crc, tag_scaler2, unpacker, mod1, (mux1, 1))
     tb.connect(crc, header, mod2, (mux1, 0))
     tb.connect(mux1, alloc, (mux2, 1))
     tb.connect(sync_header, (mux2, 0))
     tb.connect(mux2, ifft, cp, snk)
     #tb.connect(src, tag_scaler1, packer, crc, tag_scaler2, unpacker, mod1, alloc, snk)
     
     tb.run()
Пример #19
0
	def __init__(self):
		gr.top_block.__init__(self, "Create Vector")

		##################################################
		# Blocks
		##################################################
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/utils/rds_vector.dat")
		self.gr_head_0 = gr.head(gr.sizeof_char*1, 13)
		self.gr_rds_data_encoder_0 = rds.data_encoder("/media/dimitris/mywork/gr/dimitris/rds/trunk/src/utils/rds_data.xml")
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_head_0, 0))
		self.connect((self.gr_head_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_rds_data_encoder_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
Пример #20
0
    def __init__(self, constellation, samples_per_symbol,
                 differential, excess_bw, gray_coded,
                 verbose, log):

        gr.hier_block2.__init__(self, "bert_transmit",
                                gr.io_signature(0, 0, 0),                    # Output signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Input signature
        
        # Create BERT data bit stream	
	self._bits = gr.vector_source_b([1,], True)      # Infinite stream of ones
        self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit scrambler

        self._mod = digital.generic_mod(constellation, samples_per_symbol,
                                        differential, excess_bw, gray_coded,
                                        verbose, log)

        self._pack = gr.unpacked_to_packed_bb(self._mod.bits_per_symbol(), gr.GR_MSB_FIRST)

        self.connect(self._bits, self._scrambler, self._pack, self._mod, self)
    def __init__(self, constellation, samples_per_symbol,
                 differential, excess_bw, gray_coded,
                 verbose, log):

        gr.hier_block2.__init__(self, "bert_transmit",
                                gr.io_signature(0, 0, 0),                    # Output signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Input signature
        
        # Create BERT data bit stream	
	self._bits = gr.vector_source_b([1,], True)      # Infinite stream of ones
        self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit scrambler

        self._mod = digital.generic_mod(constellation, samples_per_symbol,
                                        differential, excess_bw, gray_coded,
                                        verbose, log)

        self._pack = gr.unpacked_to_packed_bb(self._mod.bits_per_symbol(), gr.GR_MSB_FIRST)

        self.connect(self._bits, self._scrambler, self._pack, self._mod, self)
Пример #22
0
    def test_003_bsc_packed (self):
        """ Test on packed data """
        src = gr.glfsr_source_b(32)  # Create some pseudo-random bits
        packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        head = gr.head(1, 8 * 1000)
        bsc = chancoding.bsc_bb(0.5, 8)
        unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        sink1 = gr.vector_sink_b()
        sink2 = gr.vector_sink_b()

        self.tb.connect(src, head, packer, bsc, unpacker, sink1)
        self.tb.connect(head, sink2)
        self.tb.run()

        bits1 = sink1.data()
        bits2 = sink2.data()
        bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2)))
        self.assert_(bit_errors > 3500 and bit_errors < 4500,
                 "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
Пример #23
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 2000000
		self.dec_rate = dec_rate = 4

		##################################################
		# Blocks
		##################################################
		self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		self.gr_throttle_1 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate/dec_rate)
		self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(dec_rate, (firdes.low_pass(1,samp_rate,500000,100000)), -535000, samp_rate)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/shampoo/sdr/capture/nrf-capture/2410500000-2M-1.cap", False)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_char*1, "/shampoo/sdr/projects/gr-nordic/qam-packed.out")
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/shampoo/sdr/projects/gr-nordic/qam-unpacked.out")
		self.gr_file_sink_0.set_unbuffered(False)
		self.digital_qam_demod_0 = digital.qam.qam_demod(
		  constellation_points=4,
		  differential=False,
		  samples_per_symbol=2,
		  excess_bw=.035,
		  freq_bw=6.28/100.0,
		  timing_bw=6.28/100.0,
		  phase_bw=6.28/100.0,
		  gray_coded=False,
		  verbose=False,
		  log=False,
		  )

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.gr_throttle_1, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.digital_qam_demod_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.digital_qam_demod_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_throttle_1, 0), (self.digital_qam_demod_0, 0))
Пример #24
0
    def test_011(self):
        """
        Test stream_to_streams.
        """

        random.seed(0)
        src_data = []
        for i in xrange(56):
            src_data.append((random.randint(0, 255)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = gr.vector_source_b(tuple(src_data), False)
        op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
        op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
        self.tb.connect(src, op1, op2)
        dst = gr.vector_sink_b()
        self.tb.connect(op2, dst)

        self.tb.run()
        self.assertEqual(expected_results[0:201], dst.data())
Пример #25
0
    def test_011(self):
        """
        Test stream_to_streams.
        """

        random.seed(0)
        src_data = []
        for i in xrange(56):
            src_data.append((random.randint(0,255)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = gr.vector_source_b(tuple(src_data),False)
        op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
        op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
        self.tb.connect(src, op1, op2)
        dst = gr.vector_sink_b()
        self.tb.connect(op2, dst)

        self.tb.run()
        self.assertEqual(expected_results[0:201], dst.data())
Пример #26
0
    def test_003_bsc_packed(self):
        """ Test on packed data """
        src = gr.glfsr_source_b(32)  # Create some pseudo-random bits
        packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        head = gr.head(1, 8 * 1000)
        bsc = chancoding.bsc_bb(0.5, 8)
        unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        sink1 = gr.vector_sink_b()
        sink2 = gr.vector_sink_b()

        self.tb.connect(src, head, packer, bsc, unpacker, sink1)
        self.tb.connect(head, sink2)
        self.tb.run()

        bits1 = sink1.data()
        bits2 = sink2.data()
        bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2)))
        self.assert_(
            bit_errors > 3500 and bit_errors < 4500,
            "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again."
        )
Пример #27
0
	def __init__(self, sample_rate, symbol_rate):
		gr.hier_block2.__init__(self, "dvb_s_modulator_bc",
				gr.io_signature(1, 1, gr.sizeof_char),			# Input signature
				gr.io_signature(1, 1, gr.sizeof_gr_complex))	# Output signature

		samples_per_symbol = sample_rate / symbol_rate
		if samples_per_symbol < 2:
			raise TypeError, "Samples per symbol must be >= 2"

		# Form symbols with 2 bits per symbol
		self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		self.reunpack = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST)

		self.mapper = gr.chunks_to_symbols_bc(mod_constellation)

		# Design FIR filter taps for square root raised cosine filter
		ntaps = 11 * int(samples_per_symbol * nfilts)
		rrc_taps = gr.firdes.root_raised_cosine(nfilts, nfilts, 1.0, dvb_swig.RRC_ROLLOFF_FACTOR, ntaps)
		# Baseband pulse shaping filter
		self.rrc_filter = gr.pfb_arb_resampler_ccf(samples_per_symbol, rrc_taps)

		self.connect(self, self.pack, self.reunpack, self.mapper, self.rrc_filter, self)
Пример #28
0
 def atest_one(self):
     tb = gr.top_block()
     MTU = 4000
     tagname = "_length"
     packets = (
         (0, 0, 0, 0)*32,
         (0, 0, 1, 0)*16,
         (1, 1, 1, 0)*4,
         )
     data, tags = ofdm.utils.packets_to_vectors(packets, tagname)
     constellation = digital.bpsk_constellation()
     src = gr.vector_source_b(data, tags, False, 1)
     tag_scaler1 = ofdm.scale_tags(1, tagname, 0.125)
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     crc1 = ofdm.crc32_bb(False, MTU, tagname)
     crc2 = ofdm.crc32_bb(True, MTU, tagname)
     tag_scaler2 = ofdm.scale_tags(1, tagname, 8)
     unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
     chunks2symbols = digital.chunks_to_symbols_bc(constellation.points())
     snk = gr.vector_sink_b()
     #tb.connect(src, packer, crc, tag_scaler, unpacker, chunks2symbols, snk)
     tb.connect(src, tag_scaler1, packer, crc1, crc2, tag_scaler2, unpacker, snk)
     tb.run()
Пример #29
0
    def __init__(self):
        gr.top_block.__init__(self, "Create Vector")

        ##################################################
        # Blocks
        ##################################################
        self.gr_file_sink_0 = gr.file_sink(
            gr.sizeof_char * 1,
            "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/utils/rds_vector.dat"
        )
        self.gr_head_0 = gr.head(gr.sizeof_char * 1, 13)
        self.gr_rds_data_encoder_0 = rds.data_encoder(
            "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/utils/rds_data.xml"
        )
        self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_head_0, 0))
        self.connect((self.gr_head_0, 0), (self.gr_file_sink_0, 0))
        self.connect((self.gr_rds_data_encoder_0, 0),
                     (self.gr_unpacked_to_packed_xx_0, 0))
Пример #30
0
	def __init__(self, dab_params, verbose=True, debug=False):
		"""
		Hierarchical block for FIC decoding
		
		@param dab_params DAB parameter object (dab.parameters.dab_parameters)
		"""
		gr.hier_block2.__init__(self,"fic",
					gr.io_signature2(2, 2, gr.sizeof_float*dab_params.num_carriers*2, gr.sizeof_char), # input
					gr.io_signature(0, 0, 0)) # output signature

		self.dp = dab_params
		self.verbose = verbose
		self.debug = debug
		
		
		# FIB selection and block partitioning
		self.select_fic_syms = dab_swig.select_vectors(gr.sizeof_float, self.dp.num_carriers*2, self.dp.num_fic_syms, 0)
		self.repartition_fic = dab_swig.repartition_vectors(gr.sizeof_float, self.dp.num_carriers*2, self.dp.fic_punctured_codeword_length, self.dp.num_fic_syms, self.dp.num_cifs)

		# unpuncturing
		self.unpuncture = dab_swig.unpuncture_vff(self.dp.assembled_fic_puncturing_sequence)

		# convolutional coding
		# self.fsm = trellis.fsm(self.dp.conv_code_in_bits, self.dp.conv_code_out_bits, self.dp.conv_code_generator_polynomials)
		self.fsm = trellis.fsm(1, 4, [0133, 0171, 0145, 0133]) # OK (dumped to text and verified partially)
		self.conv_v2s = gr.vector_to_stream(gr.sizeof_float, self.dp.fic_conv_codeword_length)
		# self.conv_decode = trellis.viterbi_combined_fb(self.fsm, 20, 0, 0, 1, [1./sqrt(2),-1/sqrt(2)] , trellis.TRELLIS_EUCLIDEAN)
		table = [ 
			  0,0,0,0,
			  0,0,0,1,
			  0,0,1,0,
			  0,0,1,1,
			  0,1,0,0,
			  0,1,0,1,
			  0,1,1,0,
			  0,1,1,1,
			  1,0,0,0,
			  1,0,0,1,
			  1,0,1,0,
			  1,0,1,1,
			  1,1,0,0,
			  1,1,0,1,
			  1,1,1,0,
			  1,1,1,1
			]
		assert(len(table)/4==self.fsm.O())
		table = [(1-2*x)/sqrt(2) for x in table]
		self.conv_decode = trellis.viterbi_combined_fb(self.fsm, 774, 0, 0, 4, table, trellis.TRELLIS_EUCLIDEAN)
		self.conv_s2v = gr.stream_to_vector(gr.sizeof_char, 774)
		self.conv_prune = dab_swig.prune_vectors(gr.sizeof_char, self.dp.fic_conv_codeword_length/4, 0, self.dp.conv_code_add_bits_input)

		# energy dispersal
		self.prbs_src   = gr.vector_source_b(self.dp.prbs(self.dp.energy_dispersal_fic_vector_length), True)
		self.energy_v2s = gr.vector_to_stream(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length)
		self.add_mod_2  = gr.xor_bb()
		self.energy_s2v = gr.stream_to_vector(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length)
		self.cut_into_fibs = dab_swig.repartition_vectors(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length, self.dp.fib_bits, 1, self.dp.energy_dispersal_fic_fibs_per_vector)
		
		# connect all
		self.nullsink = gr.null_sink(gr.sizeof_char)
		# self.filesink = gr.file_sink(gr.sizeof_char, "debug/fic.dat")
		self.fibsink = dab_swig.fib_sink_vb()
		
		# self.connect((self,0), (self.select_fic_syms,0), (self.repartition_fic,0), self.unpuncture, self.conv_v2s, self.conv_decode, self.conv_s2v, self.conv_prune, self.energy_v2s, self.add_mod_2, self.energy_s2v, (self.cut_into_fibs,0), gr.vector_to_stream(1,256), gr.unpacked_to_packed_bb(1,gr.GR_MSB_FIRST), self.filesink)
		self.connect((self,0), (self.select_fic_syms,0), (self.repartition_fic,0), self.unpuncture, self.conv_v2s, self.conv_decode, self.conv_s2v, self.conv_prune, self.energy_v2s, self.add_mod_2, self.energy_s2v, (self.cut_into_fibs,0), gr.vector_to_stream(1,256), gr.unpacked_to_packed_bb(1,gr.GR_MSB_FIRST), gr.stream_to_vector(1,32), self.fibsink)
		self.connect(self.prbs_src, (self.add_mod_2,1))
		self.connect((self,1), (self.select_fic_syms,1), (self.repartition_fic,1), (self.cut_into_fibs,1), self.nullsink)

		if self.debug:
			self.connect(self.select_fic_syms, gr.file_sink(gr.sizeof_float*self.dp.num_carriers*2, "debug/fic_select_syms.dat"))
			self.connect(self.repartition_fic, gr.file_sink(gr.sizeof_float*self.dp.fic_punctured_codeword_length, "debug/fic_repartitioned.dat"))
			self.connect(self.unpuncture, gr.file_sink(gr.sizeof_float*self.dp.fic_conv_codeword_length, "debug/fic_unpunctured.dat"))
			self.connect(self.conv_decode, gr.file_sink(gr.sizeof_char, "debug/fic_decoded.dat"))
			self.connect(self.energy_s2v, gr.file_sink(gr.sizeof_char*self.dp.energy_dispersal_fic_vector_length, "debug/fic_energy_dispersal_undone.dat"))
Пример #31
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(
            self, title="Communication System Graphical Analyzer (LAPS/UFCG)")

        ##################################################
        # Default Variables
        ##################################################
        self.sps = 2
        self.snr = 20
        self.symbol_rate = 140000
        self.mod_type = "DBPSK"
        self.view = 1
        self.band = 200
        self.excess_bw = 0.35
        self.fading_flag = False
        self.fdts = -8
        self.fading_state_rx = False

        ##################################################
        # Blocks Definition
        ##################################################

        #A bit stream of 1's is generated at the source, scrambled,
        #modulated and sent to the input of an AWGN channel.
        #random.seed(42)
        #self.source = gr.vector_source_b([random.randint(0, 2) for i in range(0,10^8)], True)
        self.source = gr.vector_source_b((1, ), True, 1)
        self.thottle = gr.throttle(gr.sizeof_char, 10e5)
        self.scrambler = gr.scrambler_bb(0x40801, 0x92F72,
                                         20)  #Taxa de simbolos constante
        self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.modulator = utils.mods[self.mod_type](self.sps,
                                                   excess_bw=self.excess_bw)
        self.channel = utils.channel(1 / 10.0**(self.snr / 10.0), self.band,
                                     self.symbol_rate, self.sps)

        #The noisy signal is demodulated, descrambled and the BER
        #is estimated by the ber_estim block using the receiver
        #density of 0 bits.
        self.demodulator = utils.demods[self.mod_type](
            self.sps, excess_bw=self.excess_bw)
        self.descrambler = gr.descrambler_bb(0x40801, 0x92F72, 20)
        self.char2float = gr.char_to_float()
        self.mov_average = gr.moving_average_ff(524288, 1 / 524288., 10000)
        self.ber = utils.ber_estim()
        #self.ber = utils.ber_estim_simple(3)

        ##################################################
        # GUI Elements Definition
        ##################################################

        #Defines an adds FFT Window to GUI
        self.fft = fftsink.fft_sink_c(self.GetWin(),
                                      sample_rate=self.symbol_rate * self.sps,
                                      baseband_freq=5e6)
        self.GridAdd(self.fft.win, 0, 3, 4, 3)
        self.ctr = gr.complex_to_real(1)

        #Defines and adds SNR slider to GUI
        _snr_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self._snr_text_box = forms.text_box(parent=self.GetWin(),
                                            sizer=_snr_sizer,
                                            value=self.snr,
                                            callback=self.callback_snr,
                                            label=" SNR (dB)",
                                            converter=forms.float_converter(),
                                            proportion=0)
        self._snr_slider = forms.slider(parent=self.GetWin(),
                                        sizer=_snr_sizer,
                                        value=self.snr,
                                        callback=self.callback_snr,
                                        minimum=0,
                                        maximum=20,
                                        style=wx.RA_HORIZONTAL,
                                        proportion=1)
        self.GridAdd(_snr_sizer, 4, 3, 1, 3)

        #Defines and adds bandwidth slider to GUI
        band_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.band_text_box = forms.text_box(parent=self.GetWin(),
                                            sizer=band_sizer,
                                            value=self.band,
                                            callback=self.callback_band,
                                            label="Bandwidth (kHz)",
                                            converter=forms.float_converter(),
                                            proportion=0)
        self.band_slider = forms.slider(parent=self.GetWin(),
                                        sizer=band_sizer,
                                        value=self.band,
                                        callback=self.callback_band,
                                        minimum=30,
                                        maximum=200,
                                        style=wx.RA_HORIZONTAL,
                                        proportion=1)
        self.GridAdd(band_sizer, 5, 3, 1, 3)

        #Defines and adds Rayleigh GUI elements

        fading_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.fading_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=fading_sizer,
            value=self.fdts,
            callback=self.callback_fading,
            label='Fading/log(FdTs)',
            converter=forms.float_converter(),
            proportion=0)
        self.fading_slider = forms.slider(parent=self.GetWin(),
                                          sizer=fading_sizer,
                                          value=self.fdts,
                                          callback=self.callback_fading,
                                          minimum=-8,
                                          maximum=-2,
                                          style=wx.RA_HORIZONTAL,
                                          proportion=1)
        self.GridAdd(fading_sizer, 6, 3, 1, 3)

        #Defines and adds modulation type chooser to GUI
        self._mod_type_chooser = forms.radio_buttons(
            parent=self.GetWin(),
            value=self.mod_type,
            callback=self.set_mod_type,
            label="Modulation",
            choices=["DBPSK", "DQPSK", "D8PSK"],
            labels=["DBPSK", "DQPSK", "D8PSK"],
            style=wx.RA_HORIZONTAL)
        self.GridAdd(self._mod_type_chooser, 7, 4, 1, 2)

        #Defines and adds signal source chooser
        self.sig_src_chooser = forms.radio_buttons(
            parent=self.GetWin(),
            value=self.view,
            callback=self.callback_view,
            label="Signal Source",
            choices=[0, 1],
            labels=["Transmitter", "Receiver"],
            style=wx.RA_VERTICAL)
        self.GridAdd(self.sig_src_chooser, 7, 3, 1, 1)

        #Definition of the of constellation window and attachment to the GUI
        self.constel = constsink.const_sink_c(self.GetWin(),
                                              title="RX Constellation Plot",
                                              sample_rate=self.symbol_rate,
                                              const_size=256,
                                              mod=self.mod_type)
        self.GridAdd(self.constel.win, 0, 0, 8, 3)

        #Definition of the constellation sink window and attachment to the GUI
        self.number_sink = bersink.number_sink_f(self.GetWin(),
                                                 sample_rate=self.symbol_rate)
        self.GridAdd(self.number_sink.win, 8, 0, 1, 6)

        ##################################################
        # Blocks Connections
        ##################################################

        #The necessary block connections to the system work as described above.
        self.connect(self.source, self.scrambler, self.thottle, self.pack)
        #self.connect(self.source , self.thottle, self.pack)
        self.connect(self.pack, self.modulator, self.channel, self.demodulator)
        self.connect(self.channel, self.fft)
        self.connect(self.demodulator.diffdec, self.constel)
        self.connect(self.demodulator, self.descrambler, self.char2float,
                     self.mov_average)
        self.connect(self.mov_average, self.ber, self.number_sink)
Пример #32
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Communication System Graphical Analyzer (LAPS/UFCG)")
        
        ##################################################
        # Default Variables
        ##################################################
        self.sps = 2
        self.snr = 20
        self.symbol_rate = 140000
        self.mod_type = "DBPSK"
        self.view = 1
        self.band= 200
        self.excess_bw=0.35
        self.fading_flag = False 
        self.fdts = -8
        self.fading_state_rx = False
        
        ##################################################
        # Blocks Definition
        ##################################################
        
        #A bit stream of 1's is generated at the source, scrambled,
        #modulated and sent to the input of an AWGN channel.
        #random.seed(42)
        #self.source = gr.vector_source_b([random.randint(0, 2) for i in range(0,10^8)], True)
        self.source = gr.vector_source_b((1,), True, 1)
        self.thottle = gr.throttle(gr.sizeof_char,10e5)
        self.scrambler = gr.scrambler_bb(0x40801, 0x92F72, 20) #Taxa de simbolos constante
        self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.modulator = utils.mods[self.mod_type](self.sps,excess_bw=self.excess_bw)
        self.channel = utils.channel(1/10.0**(self.snr/10.0),self.band,self.symbol_rate,self.sps)
        
        #The noisy signal is demodulated, descrambled and the BER
        #is estimated by the ber_estim block using the receiver
        #density of 0 bits.
        self.demodulator = utils.demods[self.mod_type](self.sps,excess_bw=self.excess_bw)     
        self.descrambler = gr.descrambler_bb(0x40801, 0x92F72, 20)
        self.char2float = gr.char_to_float()
        self.mov_average = gr.moving_average_ff(524288, 1/524288., 10000)
        self.ber = utils.ber_estim()
        #self.ber = utils.ber_estim_simple(3)

        
        ##################################################
        # GUI Elements Definition
        ##################################################
        
        #Defines an adds FFT Window to GUI
        self.fft = fftsink.fft_sink_c(self.GetWin(), sample_rate=self.symbol_rate*self.sps, baseband_freq=5e6)
        self.GridAdd(self.fft.win, 0,3,4,3)
        self.ctr= gr.complex_to_real(1)
        
        #Defines and adds SNR slider to GUI
        _snr_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self._snr_text_box = forms.text_box(parent=self.GetWin(),
            sizer=_snr_sizer, value=self.snr, callback=self.callback_snr,
            label=" SNR (dB)", converter=forms.float_converter(),
            proportion=0)
        self._snr_slider = forms.slider(parent=self.GetWin(),
            sizer=_snr_sizer, value=self.snr, callback=self.callback_snr,
            minimum=0, maximum=20, style=wx.RA_HORIZONTAL, proportion=1)
        self.GridAdd(_snr_sizer, 4, 3, 1, 3)
        
        #Defines and adds bandwidth slider to GUI
        band_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.band_text_box = forms.text_box(parent=self.GetWin(),
            sizer=band_sizer, value=self.band, callback=self.callback_band,
            label="Bandwidth (kHz)", converter=forms.float_converter(),
            proportion=0)
        self.band_slider = forms.slider(parent=self.GetWin(),
            sizer=band_sizer, value=self.band, callback=self.callback_band,
            minimum=30, maximum=200, style=wx.RA_HORIZONTAL, proportion=1)
        self.GridAdd(band_sizer, 5, 3, 1, 3)
        
        #Defines and adds Rayleigh GUI elements
        
        fading_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.fading_text_box = forms.text_box(parent=self.GetWin(),
            sizer=fading_sizer, value=self.fdts, callback=self.callback_fading,
            label='Fading/log(FdTs)', converter=forms.float_converter(),
            proportion=0)
        self.fading_slider = forms.slider(parent=self.GetWin(),
            sizer=fading_sizer, value=self.fdts, callback=self.callback_fading,
            minimum=-8, maximum=-2, style=wx.RA_HORIZONTAL, proportion=1)
        self.GridAdd(fading_sizer, 6, 3, 1, 3)
        
        #Defines and adds modulation type chooser to GUI
        self._mod_type_chooser = forms.radio_buttons(parent=self.GetWin(),
            value=self.mod_type, callback=self.set_mod_type,
            label="Modulation", choices=["DBPSK", "DQPSK", "D8PSK"],
            labels=["DBPSK", "DQPSK", "D8PSK"], style=wx.RA_HORIZONTAL)
        self.GridAdd(self._mod_type_chooser, 7, 4, 1, 2)

        
        #Defines and adds signal source chooser
        self.sig_src_chooser = forms.radio_buttons(parent=self.GetWin(),
            value=self.view, callback=self.callback_view,
            label="Signal Source", choices=[0,1],
            labels=["Transmitter","Receiver"], style=wx.RA_VERTICAL)
        self.GridAdd(self.sig_src_chooser, 7,3,1,1)
        
        
        #Definition of the of constellation window and attachment to the GUI
        self.constel = constsink.const_sink_c(self.GetWin(),
            title="RX Constellation Plot",  sample_rate=self.symbol_rate,
            const_size=256, mod=self.mod_type)
        self.GridAdd(self.constel.win,0,0,8,3)
        
        
        #Definition of the constellation sink window and attachment to the GUI
        self.number_sink = bersink.number_sink_f(self.GetWin(),
            sample_rate=self.symbol_rate)
        self.GridAdd(self.number_sink.win,8,0,1,6)
        
        ##################################################
        # Blocks Connections
        ##################################################
        
        #The necessary block connections to the system work as described above.
        self.connect(self.source, self.scrambler , self.thottle, self.pack)
        #self.connect(self.source , self.thottle, self.pack)
        self.connect(self.pack, self.modulator, self.channel, self.demodulator)
        self.connect(self.channel, self.fft)
        self.connect(self.demodulator.diffdec, self.constel)
        self.connect(self.demodulator, self.descrambler, self.char2float, self.mov_average)
        self.connect(self.mov_average, self.ber, self.number_sink)
Пример #33
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 25000000
        self.dec_rate = dec_rate = 25

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate / dec_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(
            dec_rate, (firdes.low_pass(1, samp_rate, 1000000, 100000)),
            -1000000, samp_rate)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/shampoo/sdr/capture/j9Pro-capture/2400000000-25M-1.cap", False)
        self.gr_file_sink_0_0 = gr.file_sink(
            gr.sizeof_char * 1,
            "/shampoo/sdr/projects/gr-nineeagles/gmsk-packed.out")
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_file_sink_0 = gr.file_sink(
            gr.sizeof_char * 1,
            "/shampoo/sdr/projects/gr-nineeagles/gmsk-unpacked.out")
        self.gr_file_sink_0.set_unbuffered(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,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_unpacked_to_packed_xx_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0), (self.gr_file_sink_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0),
                     (self.gr_unpacked_to_packed_xx_0, 0))
        self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_throttle_0, 0),
                     (self.gr_freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0),
                     (self.digital_gmsk_demod_0, 0))
Пример #34
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 gain_mu=_def_gain_mu,
                 mu=_def_mu,
                 costas_alpha=_def_costas_alpha,
                 omega_relative_limit=_def_omega_relative_limit,
                 freq_error=_def_freq_error,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for Gaussian Minimum Shift Key (GMSK)
	demodulation.

	The input is the complex modulated signal at baseband.
	The output is a stream of bits packed 1 bit per byte (the LSB)

	@param samples_per_symbol: samples per baud
	@type samples_per_symbol: integer
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param log: Print modualtion data to files?
        @type log: bool 

        Clock recovery parameters.  These all have reasonble defaults.
        
        @param gain_mu: controls rate of mu adjustment
        @type gain_mu: float
        @param mu: fractional delay [0.0, 1.0]
        @type mu: float
        @param omega_relative_limit: sets max variation in omega
        @type omega_relative_limit: float, typically 0.000200 (200 ppm)
        @param freq_error: bit rate error as a fraction
        @param float
	"""

        gr.hier_block2.__init__(
            self,
            "gmsk_demod",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))  # Output signature

        self._samples_per_symbol = samples_per_symbol
        self._gain_mu = gain_mu
        self._mu = mu
        self._omega_relative_limit = omega_relative_limit
        self._freq_error = freq_error
        self._costas_alpha = costas_alpha

        if samples_per_symbol < 2:
            raise TypeError, "samples_per_symbol >= 2, is %f" % samples_per_symbol

        self._omega = samples_per_symbol * (1 + self._freq_error)

        if not self._gain_mu:
            self._gain_mu = 0.175

        self._gain_omega = .25 * self._gain_mu * self._gain_mu  # critically damped

        # Demodulate FM
        sensitivity = (pi / 2) / samples_per_symbol
        self.fmdemod = gr.quadrature_demod_cf(1.0 / sensitivity)

        # the clock recovery block tracks the symbol clock and resamples as needed.
        # the output of the block is a stream of soft symbols (float)
        self.clock_recovery = gr.clock_recovery_mm_ff(
            self._omega, self._gain_omega, self._mu, self._gain_mu,
            self._omega_relative_limit)

        # slice the floats at 0, outputting 1 bit (the LSB of the output byte) per sample
        self.slicer = gr.binary_slicer_fb()

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

        # Costas loop (carrier tracking)
        # FIXME: need to decide how to handle this more generally; do we pull it from higher layer?
        costas_order = 2
        beta = .25 * self._costas_alpha * self._costas_alpha
        self.costas_loop = gr.costas_loop_cc(self._costas_alpha, beta, 0.002,
                                             -0.002, costas_order)

        # Connect & Initialize base class
        self.unpack = gr.unpacked_to_packed_bb(self.bits_per_symbol(),
                                               gr.GR_MSB_FIRST)
        #self.connect(self, self.fmdemod, self.clock_recovery, self.slicer,self.unpack, self)
        self.connect(self, self.fmdemod, self.slicer, self.unpack, self)
Пример #35
0
	def __init__(self, system, site_uuid, overseer_uuid):
		gr.top_block.__init__(self, "edacs receiver")
                self.log = logging.getLogger('overseer.edacs_control_demod')

		self.system = system
		self.instance_uuid = '%s' % uuid.uuid4()
                self.log = logging.getLogger('overseer.edacs_control_demod.%s' % self.instance_uuid)
		self.protocol_log = logging.getLogger('protocol.%s' % self.instance_uuid)
                self.log.info('Initializing instance: %s site: %s overseer: %s' % (self.instance_uuid, site_uuid, overseer_uuid))

		self.overseer_uuid = overseer_uuid
		self.site_uuid = site_uuid

		self.audio_rate = audio_rate = 12500
		self.symbol_rate = symbol_rate = system['symbol_rate']
		self.channels = channels = system['channels']
		self.channels_list = self.channels.keys()
		self.control_channel_key = 8
                self.control_channel = control_channel = self.channels[self.channels_list[0]]
		self.control_source = 0

		self.thread_id = '%s-%s' % (self.system['type'], self.system['id'])

		self.control_lcn = control_lcn = 1
		self.bad_messages = 0
		self.total_messages = 0
		self.quality = []
		self.site_detail = {}

		self.is_locked = False

		self.enable_capture = True
		self.keep_running = True

		self.freq_offset = 0

		self.connector = frontend_connector()
		self.client_redis = client_redis()

		################################################
		# Blocks
		################################################
	

		self.channel_rate = 12500
		self.receive_rate = self.channel_rate*2 #Decimation adds 50% on either side

		self.source = None


		try:
			self.control_quad_demod = gr.quadrature_demod_cf(5)
		except:
			self.control_quad_demod = analog.quadrature_demod_cf(5)
		self.control_clock_recovery = digital.clock_recovery_mm_ff(self.receive_rate/symbol_rate, 1.4395919, 0.5, 0.05, 0.005)
                self.control_binary_slicer = digital.binary_slicer_fb()
		try:
			self.control_unpacked_to_packed = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		except:
			self.control_unpacked_to_packed = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
		self.control_msg_queue = gr.msg_queue(1024000)
		try:
			self.control_msg_sink = gr.message_sink(gr.sizeof_char, self.control_msg_queue,True)
		except:
			self.control_msg_sink = blocks.message_sink(gr.sizeof_char, self.control_msg_queue,True)

		#offset measurement
                moving_sum = blocks.moving_average_ff(10000, 1, 40000)
                subtract = blocks.sub_ff(1)
                divide_const = blocks.multiply_const_vff((0.0001, ))
                self.probe = blocks.probe_signal_f()


		################################################
		# Connections
		################################################
	
		self.connect(   self.control_quad_demod,
                                self.control_clock_recovery,
                                self.control_binary_slicer,
                                self.control_unpacked_to_packed,
				self.control_msg_sink)

		self.connect(self.control_quad_demod, moving_sum, divide_const, self.probe)
		

		###############################################
		self.patches = {}
		self.patch_timeout = 3 #seconds
		self.redis_demod_publisher = redis_demod_publisher(parent_demod=self)

		control_decode_0 = threading.Thread(target=self.control_decode)
		control_decode_0.daemon = True
		control_decode_0.start()

                quality_check_0 = threading.Thread(target=self.quality_check)
                quality_check_0.daemon = True
                quality_check_0.start()

		self.tune_next_control_channel()
Пример #36
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 gain_mu=_def_gain_mu,
                 mu=_def_mu,
                 costas_alpha=_def_costas_alpha,
                 omega_relative_limit=_def_omega_relative_limit,
                 freq_error=_def_freq_error,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for Gaussian Minimum Shift Key (GMSK)
	demodulation.

	The input is the complex modulated signal at baseband.
	The output is a stream of bits packed 1 bit per byte (the LSB)

	@param samples_per_symbol: samples per baud
	@type samples_per_symbol: integer
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param log: Print modualtion data to files?
        @type log: bool 

        Clock recovery parameters.  These all have reasonble defaults.
        
        @param gain_mu: controls rate of mu adjustment
        @type gain_mu: float
        @param mu: fractional delay [0.0, 1.0]
        @type mu: float
        @param omega_relative_limit: sets max variation in omega
        @type omega_relative_limit: float, typically 0.000200 (200 ppm)
        @param freq_error: bit rate error as a fraction
        @param float
	"""

	gr.hier_block2.__init__(self, "gmsk_demod",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(1, 1, gr.sizeof_char))       # Output signature

        self._samples_per_symbol = samples_per_symbol
        self._gain_mu = gain_mu
        self._mu = mu
        self._omega_relative_limit = omega_relative_limit
        self._freq_error = freq_error
	self._costas_alpha = costas_alpha
        
        if samples_per_symbol < 2:
            raise TypeError, "samples_per_symbol >= 2, is %f" % samples_per_symbol

        self._omega = samples_per_symbol*(1+self._freq_error)

        if not self._gain_mu:
            self._gain_mu = 0.175
            
	self._gain_omega = .25 * self._gain_mu * self._gain_mu        # critically damped

	# Demodulate FM
	sensitivity = (pi / 2) / samples_per_symbol
	self.fmdemod = gr.quadrature_demod_cf(1.0 / sensitivity)

	# the clock recovery block tracks the symbol clock and resamples as needed.
	# the output of the block is a stream of soft symbols (float)
	self.clock_recovery = gr.clock_recovery_mm_ff(self._omega, self._gain_omega,
                                                      self._mu, self._gain_mu,
                                                      self._omega_relative_limit)

        # slice the floats at 0, outputting 1 bit (the LSB of the output byte) per sample
        self.slicer = gr.binary_slicer_fb()

        if verbose:
            self._print_verbage()
         
        if log:
            self._setup_logging()

        # Costas loop (carrier tracking)
        # FIXME: need to decide how to handle this more generally; do we pull it from higher layer?
        costas_order = 2
        beta = .25 * self._costas_alpha * self._costas_alpha
        self.costas_loop = gr.costas_loop_cc(self._costas_alpha, beta, 0.002, -0.002, costas_order)	    
	    
	    
	# Connect & Initialize base class
        self.unpack = gr.unpacked_to_packed_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)
	#self.connect(self, self.fmdemod, self.clock_recovery, self.slicer,self.unpack, self)
	self.connect(self, self.fmdemod, self.slicer,self.unpack, self)