Example #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)
Example #2
0
    def __init__(self, bt=0.3, samples_per_symbol=2):
        gr.hier_block2.__init__(
            self, "msk_demod", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_gr_complex)
        )

        ntaps = 4 * samples_per_symbol  # up to 3 bits in filter at once
        sensitivity = (pi / 2) / samples_per_symbol  # phase change per bit = pi / 2

        # Turn it into NRZ data.
        self.unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.nrz = digital.chunks_to_symbols_bf([-1, 1], 1)  # note could also invert bits here

        # Form Gaussian filter
        # Generate Gaussian response (Needs to be convolved with window below).
        self.gaussian_taps = gr.firdes.gaussian(1, samples_per_symbol, bt, ntaps)

        self.sqwave = (1,) * samples_per_symbol  # rectangular window
        self.taps = numpy.convolve(numpy.array(self.gaussian_taps), numpy.array(self.sqwave))
        self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)

        # FM modulation
        self.fmmod = gr.frequency_modulator_fc(sensitivity)

        # TODO: this is hardcoded, how to figure out this value?
        self.offset = gr.add_const_vff((-0.5,))

        # CC430 RF core is inverted with respect to USRP for some reason
        self.invert = gr.multiply_const_vff((-1,))

        # Connect & Initialize base class
        self.connect(self, self.unpack, self.nrz, self.invert, self.offset, self.gaussian_filter, self.fmmod, self)
    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)
    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."
    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))
Example #6
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)
Example #7
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.'
Example #8
0
	def __init__(self):
		gr.top_block.__init__(self, "Many Rate Changing")

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

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

		##################################################
		# Connections
		##################################################
		self.connect((self.blocks_char_to_float_0, 0), (self.blocks_keep_m_in_n_0, 0))
		self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_float_to_char_0, 0))
		self.connect((self.blocks_float_to_char_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.blocks_char_to_float_0, 0))
		self.connect((self.random_source_x_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_null_sink_0_2, 0))
Example #9
0
    def test_00(self):
        expected_result = (
            0x00, 0x11, 0x22, 0x33,
            0x44, 0x55, 0x66, 0x77,
            0x88, 0x99, 0xaa, 0xbb,
            0xcc, 0xdd, 0xee, 0xff)

        # Filter taps to expand the data to oversample by 8
        # Just using a RRC for some basic filter shape
        taps = gr.firdes.root_raised_cosine(8, 8, 1.0, 0.5, 21)
        
        src = gr.vector_source_b(expected_result)
        frame = digital.simple_framer(4)
        unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        expand = gr.interp_fir_filter_fff(8, taps)
        b2f = gr.char_to_float()
        mult2 = gr.multiply_const_ff(2)
        sub1 = gr.add_const_ff(-1)
        op = digital.simple_correlator(4)
        dst = gr.vector_sink_b()
        self.tb.connect(src, frame, unpack, b2f, mult2, sub1, expand)
        self.tb.connect(expand, op, dst)
        self.tb.run()
        result_data = dst.data()

        self.assertEqual(expected_result, result_data)
Example #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
        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)
Example #11
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__(self)

        # data sink and sink rate
        u = usrp.sink_c()

        # important vars (to be calculated from USRP when available
        dac_rate = u.dac_rate()
        usrp_rate = 320e3
        usrp_interp = int(dac_rate // usrp_rate)
        channel_rate = 32e3
        interp_factor = int(usrp_rate // channel_rate)

        # open the pcap source
        pcap = op25.pcap_source_b(filename, delay)
        #        pcap = gr.glfsr_source_b(16)

        # convert octets into dibits
        bits_per_symbol = 2
        unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

        # setup low pass filter + interpolator
        low_pass = 2.88e3
        interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass,
                                         low_pass * 0.1, gr.firdes.WIN_HANN)
        interpolator = gr.interp_fir_filter_fff(int(interp_factor),
                                                interp_taps)

        # frequency modulator
        max_dev = 12.5e3
        k = 2 * math.pi * max_dev / usrp_rate
        adjustment = 1.5  # adjust for proper c4fm deviation level
        fm = gr.frequency_modulator_fc(k * adjustment)

        # signal gain
        gain = gr.multiply_const_cc(4000)

        # configure USRP
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(u)
        u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec))
        self.db = usrp.selected_subdev(u, subdev_spec)
        print "Using TX d'board %s" % (self.db.side_and_name(), )
        u.set_interp_rate(usrp_interp)

        if gain is None:
            g = self.db.gain_range()
            gain = float(g[0] + g[1]) / 2
        self.db.set_gain(self.db.gain_range()[0])
        u.tune(self.db.which(), self.db, freq)
        self.db.set_enable(True)

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Example #12
0
def unpack_array(arr):
    src = blocks.vector_source_b(arr)
    data_p2u = gr.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
    dst = blocks.vector_sink_b()
    fg = gr.top_block()
    fg.connect(src, data_p2u, dst)
    fg.run()
    unpacked_array = dst.data()
    assert (len(unpacked_array) == 8 * len(arr))
    return unpacked_array
Example #13
0
def unpack_array(arr):
  src = blocks.vector_source_b(arr)
  data_p2u = gr.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
  dst = blocks.vector_sink_b()
  fg = gr.top_block()
  fg.connect(src, data_p2u,dst)
  fg.run()
  unpacked_array = dst.data()
  assert(len(unpacked_array) == 8*len(arr))
  return unpacked_array
Example #14
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__ (self)

        # data sink and sink rate
        u = usrp.sink_c()

        # important vars (to be calculated from USRP when available
        dac_rate = u.dac_rate()
        usrp_rate = 320e3
        usrp_interp = int(dac_rate // usrp_rate)
        channel_rate = 32e3
        interp_factor = int(usrp_rate // channel_rate)

        # open the pcap source
        pcap = op25.pcap_source_b(filename, delay)
#        pcap = gr.glfsr_source_b(16)

        # convert octets into dibits
        bits_per_symbol = 2
        unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

        # setup low pass filter + interpolator
        low_pass = 2.88e3
        interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass, low_pass * 0.1, gr.firdes.WIN_HANN)
        interpolator = gr.interp_fir_filter_fff (int(interp_factor), interp_taps)

        # frequency modulator
        max_dev = 12.5e3
        k = 2 * math.pi * max_dev / usrp_rate
        adjustment = 1.5   # adjust for proper c4fm deviation level
        fm = gr.frequency_modulator_fc(k * adjustment)

        # signal gain
        gain = gr.multiply_const_cc(4000)

        # configure USRP
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(u)
        u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec))
        self.db = usrp.selected_subdev(u, subdev_spec)
        print "Using TX d'board %s" % (self.db.side_and_name(),)
        u.set_interp_rate(usrp_interp)

        if gain is None:
            g = self.db.gain_range()
            gain = float(g[0] + g[1]) / 2
        self.db.set_gain(self.db.gain_range()[0])
        u.tune(self.db.which(), self.db, freq)
        self.db.set_enable(True)

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Example #15
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))
Example #16
0
 def test_001_t (self):
     packets = ((1, 2, 3), (4, 5, 6, 7, 8), (9, 10))
     tagname = "packet_length"
     data, tags = ofdm.utils.packets_to_vectors(packets, tagname)
     tb = gr.top_block()
     src = gr.vector_source_b(data, tags, False, 1)
     tag_scaler = ofdm.scale_tags(1, tagname, 2)
     unpacker = gr.packed_to_unpacked_bb(4, gr.GR_MSB_FIRST)
     snk = gr.vector_sink_b()
     tb.connect(src, unpacker, tag_scaler, snk)
     tb.run()
     packets = ofdm.utils.vectors_to_packets(snk.data(), snk.tags(), tagname)
Example #17
0
def mod_bits_qpsk(strbits, syms=[0, 1, 3, 2], pts=[-1, 1j, 1, -1j]):
    src = gr.vector_source_b(es.string_to_vector(strbits))
    unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
    pack = gr.pack_k_bits_bb(2)
    bts = gr.map_bb((syms))
    mapper = gr.chunks_to_symbols_bc(pts, 1)
    rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91)
    interp = gr.interp_fir_filter_ccc(2, (rrc_taps))
    sink = gr.vector_sink_c()
    tb = gr.top_block()
    tb.connect(src, unpack, pack, bts, mapper, interp, sink)
    tb.run()
    return sink.data()
Example #18
0
def mod_bits_qpsk(strbits, syms=[0,1,3,2], pts=[-1,1j,1,-1j]):
    src = gr.vector_source_b(es.string_to_vector(strbits));
    unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST);
    pack = gr.pack_k_bits_bb(2);
    bts = gr.map_bb((syms));
    mapper =  gr.chunks_to_symbols_bc(pts, 1);
    rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91);
    interp = gr.interp_fir_filter_ccc(2, (rrc_taps))
    sink = gr.vector_sink_c();
    tb=gr.top_block();
    tb.connect(src,unpack,pack,bts,mapper,interp,sink);
    tb.run();
    return sink.data();
Example #19
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 bt=_def_bt,
                 verbose=_def_verbose,
                 log=_def_log):

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

        samples_per_symbol = int(samples_per_symbol)
        self._samples_per_symbol = samples_per_symbol
        self._bt = bt
        self._differential = False

        if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
            raise TypeError, ("samples_per_symbol must be an integer >= 2, is %r" % (samples_per_symbol,))

	ntaps = 4 * samples_per_symbol			# up to 3 bits in filter at once
	sensitivity = (pi / 2) / samples_per_symbol	# phase change per bit = pi / 2

	# Turn it into NRZ data.
	#self.nrz = digital.bytes_to_syms()
        self.unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.nrz = digital.chunks_to_symbols_bf([-1, 1], 1)

	# Form Gaussian filter
        # Generate Gaussian response (Needs to be convolved with window below).
	self.gaussian_taps = gr.firdes.gaussian(
		1,		       # gain
		samples_per_symbol,    # symbol_rate
		bt,		       # bandwidth * symbol time
		ntaps	               # number of taps
		)

	self.sqwave = (1,) * samples_per_symbol       # rectangular window
	self.taps = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
	self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)

	# FM modulation
	self.fmmod = gr.frequency_modulator_fc(sensitivity)
		
        if verbose:
            self._print_verbage()
         
        if log:
            self._setup_logging()

	# Connect & Initialize base class
	self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self)
Example #20
0
File: qa_dvb.py Project: EQ4/gr-dvb
	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)
Example #21
0
    def __init__(self, bt = 0.3, samples_per_symbol = 2, ti_adj=False):
        gr.hier_block2.__init__(self, "msk_demod",
                gr.io_signature(1, 1, gr.sizeof_char),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.sps = 2
        self.bt = 0.35
        self.mu = 0.5
        self.gain_mu = 0.175
        self.freq_error = 0.0
        self.omega_relative_limit = 0.005

        self.omega = self.sps * (1 + self.freq_error)
        self.gain_omega = .25 * self.gain_mu * self.gain_mu        # critically damped

        ntaps = 4 * samples_per_symbol              # up to 3 bits in filter at once
        sensitivity = (pi / 2) / samples_per_symbol # phase change per bit = pi / 2

        # Turn it into NRZ data.
        self.unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.nrz = digital.chunks_to_symbols_bf([-1, 1], 1) # note could also invert bits here

        # Form Gaussian filter
        # Generate Gaussian response (Needs to be convolved with window below).
        self.gaussian_taps = gr.firdes.gaussian(1, samples_per_symbol, bt, ntaps)

        self.sqwave = (1,) * samples_per_symbol       # rectangular window
        self.taps = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
        self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)

        # 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 = digital.clock_recovery_mm_ff(self.omega, self.gain_omega,
                                                               self.mu, self.gain_mu,
                                                               self.omega_relative_limit)

        # FM modulation
        self.fmmod = gr.frequency_modulator_fc(sensitivity)

        # TODO: this is hardcoded, how to figure out this value?
        self.offset = gr.add_const_vff((-.5, ))

        # CC430 RF core is inverted with respect to USRP for some reason
        self.invert = gr.multiply_const_vff((-1, ))

        # Connect & Initialize base class
        if ti_adj:
            self.connect(self, self.unpack, self.nrz, self.invert, self.offset, self.gaussian_filter, self.fmmod, self)
        else:
            self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self)
Example #22
0
    def test_004(self):
        """
        Test stream_to_streams.
        """
        src_data = (0x11,)
        expected_results = (0, 4)
        src = gr.vector_source_b(src_data, False)
        op = gr.packed_to_unpacked_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())
    def test_004(self):
        """
        Test stream_to_streams.
        """
        src_data = (0x11,)
        expected_results = (0, 4)
        src = gr.vector_source_b(src_data,False)
        op = gr.packed_to_unpacked_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())
Example #24
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()
Example #25
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "mhp")

        sample_rate = options.sample_rate

        arity = 2
        IN = gr.file_source(gr.sizeof_char, options.input_file, options.repeat)
        B2C = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
        mod_map = [1.0, 3.0, -1.0, -3.0]
        C2S = gr.chunks_to_symbols_bf(mod_map)
        if options.reverse:
            polarity = gr.multiply_const_ff(-1)
        else:
            polarity = gr.multiply_const_ff( 1)

        symbol_rate = 4800
        samples_per_symbol = sample_rate // symbol_rate
        excess_bw = 0.1
        ntaps = 11 * samples_per_symbol
        rrc_taps = gr.firdes.root_raised_cosine(
            samples_per_symbol, # gain  (sps since we're interpolating by sps
            samples_per_symbol, # sampling rate
            1.0,                # symbol rate
            excess_bw,          # excess bandwidth (roll-off factor)
            ntaps)
        rrc_filter = gr.interp_fir_filter_fff(samples_per_symbol, rrc_taps)

        rrc_coeffs = [0, -0.003, -0.006, -0.009, -0.012, -0.014, -0.014, -0.013, -0.01, -0.006, 0, 0.007, 0.014, 0.02, 0.026, 0.029, 0.029, 0.027, 0.021, 0.012, 0, -0.013, -0.027, -0.039, -0.049, -0.054, -0.055, -0.049, -0.038, -0.021, 0, 0.024, 0.048, 0.071, 0.088, 0.098, 0.099, 0.09, 0.07, 0.039, 0, -0.045, -0.091, -0.134, -0.17, -0.193, -0.199, -0.184, -0.147, -0.085, 0, 0.105, 0.227, 0.36, 0.496, 0.629, 0.751, 0.854, 0.933, 0.983, 1, 0.983, 0.933, 0.854, 0.751, 0.629, 0.496, 0.36, 0.227, 0.105, 0, -0.085, -0.147, -0.184, -0.199, -0.193, -0.17, -0.134, -0.091, -0.045, 0, 0.039, 0.07, 0.09, 0.099, 0.098, 0.088, 0.071, 0.048, 0.024, 0, -0.021, -0.038, -0.049, -0.055, -0.054, -0.049, -0.039, -0.027, -0.013, 0, 0.012, 0.021, 0.027, 0.029, 0.029, 0.026, 0.02, 0.014, 0.007, 0, -0.006, -0.01, -0.013, -0.014, -0.014, -0.012, -0.009, -0.006, -0.003, 0]

        # rrc_coeffs work slightly differently: each input sample
        # (from mod_map above) at 4800 rate, then 9 zeros are inserted
        # to bring to a 48000 rate, then this filter is applied:
        # rrc_filter = gr.fir_filter_fff(1, rrc_coeffs)
        # FIXME: how to insert the 9 zero samples using gr ?

        # FM pre-emphasis filter
        shaping_coeffs = [-0.018, 0.0347, 0.0164, -0.0064, -0.0344, -0.0522, -0.0398, 0.0099, 0.0798, 0.1311, 0.121, 0.0322, -0.113, -0.2499, -0.3007, -0.2137, -0.0043, 0.2825, 0.514, 0.604, 0.514, 0.2825, -0.0043, -0.2137, -0.3007, -0.2499, -0.113, 0.0322, 0.121, 0.1311, 0.0798, 0.0099, -0.0398, -0.0522, -0.0344, -0.0064, 0.0164, 0.0347, -0.018]
        shaping_filter = gr.fir_filter_fff(1, shaping_coeffs)

        OUT = audio.sink(sample_rate, options.audio_output)
        amp = gr.multiply_const_ff(options.factor)

        self.connect(IN, B2C, C2S, polarity, rrc_filter, shaping_filter, amp)
        # output to both L and R channels
        self.connect(amp, (OUT,0) )
        self.connect(amp, (OUT,1) )
Example #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.")
Example #27
0
    def __init__(self, rx_callback, options):
        gr.top_block.__init__(self)

        if (options.from_file is not None):
            sys.stderr.write(
                ("Reading samples from '%s'.\n\n" % (options.from_file)))
            self.source = gr.file_source(gr.sizeof_char, options.from_file,
                                         options.repeat_file)
        else:
            sys.stderr.write(
                "No source defined, pulling samples from null source.\n\n")
            self.source = gr.null_source(gr.sizeof_gr_byte)

        # Set up receive path
        self.rxpath = receive_path(rx_callback, options)
        self.unpacker_bb = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.connect(self.source, self.unpacker_bb)
        self.connect(self.unpacker_bb, (self.rxpath, 0))
        self.connect(self.unpacker_bb, (self.rxpath, 1))
Example #28
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())
    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())
Example #30
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."
        )
Example #31
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)
Example #32
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()
Example #33
0
    def __init__(self, fg, spb, alpha, gain, use_barker=0):
        if not isinstance(spb, int) or spb < 2:
            raise TypeError, "sbp must be an integer >= 2"
        self.spb = spb
        self.bits_per_chunk = 1

	ntaps = 2 * spb - 1
        alpha = 0.5

        self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk,
                                                     gr.GR_MSB_FIRST)

        constellation = ( (), ( -1-0j,1+0j ), ( 0.707+0.707j,-0.707-0.707j ),
                          ( 0.707+0j,-0.707-0.707j ), ( -1+0j,-1j, 1j, 1+0j ),
                          ( 1+0j,0+1j,-1+0j,0-1j ), ( 0+0j,1+0j ) )

        self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2])
        self.scrambler = bbn.scrambler_bb(True)
        self.diff_encode = gr.diff_encoder_bb(2);

        self.barker_taps = bbn.firdes_barker(spb)

	self.rrc_taps = gr.firdes.root_raised_cosine(4 * gain, spb,
		1.0, alpha, ntaps)

        if use_barker:
            self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps)
        else:
            self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps)

        fg.connect(self.scrambler, self.bytes2chunks)
        fg.connect(self.bytes2chunks, self.diff_encode)
        fg.connect(self.diff_encode, self.chunks2symbols)
	fg.connect(self.chunks2symbols,self.tx_filter)

        gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter)
        bbn.crc16_init()
Example #34
0
    def __init__(self, bt=0.3, samples_per_symbol=2):
        gr.hier_block2.__init__(self, "msk_demod",
                                gr.io_signature(1, 1, gr.sizeof_char),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        ntaps = 4 * samples_per_symbol  # up to 3 bits in filter at once
        sensitivity = (pi /
                       2) / samples_per_symbol  # phase change per bit = pi / 2

        # Turn it into NRZ data.
        self.unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.nrz = digital.chunks_to_symbols_bf(
            [-1, 1], 1)  # note could also invert bits here

        # Form Gaussian filter
        # Generate Gaussian response (Needs to be convolved with window below).
        self.gaussian_taps = gr.firdes.gaussian(1, samples_per_symbol, bt,
                                                ntaps)

        self.sqwave = (1, ) * samples_per_symbol  # rectangular window
        self.taps = numpy.convolve(numpy.array(self.gaussian_taps),
                                   numpy.array(self.sqwave))
        self.gaussian_filter = filter.interp_fir_filter_fff(
            samples_per_symbol, self.taps)

        # FM modulation
        self.fmmod = gr.frequency_modulator_fc(sensitivity)

        # TODO: this is hardcoded, how to figure out this value?
        self.offset = gr.add_const_vff((-.5, ))

        # CC430 RF core is inverted with respect to USRP for some reason
        self.invert = gr.multiply_const_vff((-1, ))

        # Connect & Initialize base class
        self.connect(self, self.unpack, self.nrz, self.invert, self.offset,
                     self.gaussian_filter, self.fmmod, self)
Example #35
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered QPSK modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: integer
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param gray_code: Tell modulator to Gray code the bits
        @type gray_code: bool
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modualtion data to files?
        @type debug: bool
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._gray_code = gray_code

        if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
            raise TypeError, ("sbp must be an integer >= 2, is %d" %
                              samples_per_symbol)

        ntaps = 11 * samples_per_symbol

        arity = pow(2, self.bits_per_symbol())

        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity])
        else:
            self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity])

        self.diffenc = gr.diff_encoder_bb(arity)

        rot = 1.0
        print "constellation with %d arity" % arity
        rotated_const = map(lambda pt: pt * rot, qam.constellation[arity])
        self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const)

        # pulse shaping filter
        self.rrc_taps = gr.firdes.root_raised_cosine(
            self.
            _samples_per_symbol,  # gain  (sps since we're interpolating by sps)
            self._samples_per_symbol,  # sampling rate
            1.0,  # symbol rate
            self._excess_bw,  # excess bandwidth (roll-off factor)
            ntaps)

        self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol,
                                                   self.rrc_taps)

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

# Connect
        self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc,
                     self.chunks2symbols, self.rrc_filter, self)
Example #36
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "mhp")

        sample_rate = options.sample_rate

        arity = 2
        IN = gr.file_source(gr.sizeof_char, options.input_file, options.repeat)
        B2C = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
        mod_map = [1.0, 3.0, -1.0, -3.0]
        C2S = gr.chunks_to_symbols_bf(mod_map)
        if options.reverse:
            polarity = gr.multiply_const_ff(-1)
        else:
            polarity = gr.multiply_const_ff(1)

        symbol_rate = 4800
        samples_per_symbol = sample_rate // symbol_rate
        excess_bw = 0.1
        ntaps = 11 * samples_per_symbol
        rrc_taps = gr.firdes.root_raised_cosine(
            samples_per_symbol,  # gain  (sps since we're interpolating by sps
            samples_per_symbol,  # sampling rate
            1.0,  # symbol rate
            excess_bw,  # excess bandwidth (roll-off factor)
            ntaps)
        rrc_filter = gr.interp_fir_filter_fff(samples_per_symbol, rrc_taps)

        rrc_coeffs = [
            0, -0.003, -0.006, -0.009, -0.012, -0.014, -0.014, -0.013, -0.01,
            -0.006, 0, 0.007, 0.014, 0.02, 0.026, 0.029, 0.029, 0.027, 0.021,
            0.012, 0, -0.013, -0.027, -0.039, -0.049, -0.054, -0.055, -0.049,
            -0.038, -0.021, 0, 0.024, 0.048, 0.071, 0.088, 0.098, 0.099, 0.09,
            0.07, 0.039, 0, -0.045, -0.091, -0.134, -0.17, -0.193, -0.199,
            -0.184, -0.147, -0.085, 0, 0.105, 0.227, 0.36, 0.496, 0.629, 0.751,
            0.854, 0.933, 0.983, 1, 0.983, 0.933, 0.854, 0.751, 0.629, 0.496,
            0.36, 0.227, 0.105, 0, -0.085, -0.147, -0.184, -0.199, -0.193,
            -0.17, -0.134, -0.091, -0.045, 0, 0.039, 0.07, 0.09, 0.099, 0.098,
            0.088, 0.071, 0.048, 0.024, 0, -0.021, -0.038, -0.049, -0.055,
            -0.054, -0.049, -0.039, -0.027, -0.013, 0, 0.012, 0.021, 0.027,
            0.029, 0.029, 0.026, 0.02, 0.014, 0.007, 0, -0.006, -0.01, -0.013,
            -0.014, -0.014, -0.012, -0.009, -0.006, -0.003, 0
        ]

        # rrc_coeffs work slightly differently: each input sample
        # (from mod_map above) at 4800 rate, then 9 zeros are inserted
        # to bring to a 48000 rate, then this filter is applied:
        # rrc_filter = gr.fir_filter_fff(1, rrc_coeffs)
        # FIXME: how to insert the 9 zero samples using gr ?

        # FM pre-emphasis filter
        shaping_coeffs = [
            -0.018, 0.0347, 0.0164, -0.0064, -0.0344, -0.0522, -0.0398, 0.0099,
            0.0798, 0.1311, 0.121, 0.0322, -0.113, -0.2499, -0.3007, -0.2137,
            -0.0043, 0.2825, 0.514, 0.604, 0.514, 0.2825, -0.0043, -0.2137,
            -0.3007, -0.2499, -0.113, 0.0322, 0.121, 0.1311, 0.0798, 0.0099,
            -0.0398, -0.0522, -0.0344, -0.0064, 0.0164, 0.0347, -0.018
        ]
        shaping_filter = gr.fir_filter_fff(1, shaping_coeffs)

        OUT = audio.sink(sample_rate, options.audio_output)
        amp = gr.multiply_const_ff(options.factor)

        self.connect(IN, B2C, C2S, polarity, rrc_filter, shaping_filter, amp)
        # output to both L and R channels
        self.connect(amp, (OUT, 0))
        self.connect(amp, (OUT, 1))
Example #37
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):

        """
	Hierarchical block for RRC-filtered QPSK modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: integer
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param gray_code: Tell modulator to Gray code the bits
        @type gray_code: bool
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modualtion data to files?
        @type debug: bool
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._gray_code = gray_code

        if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
            raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol)

	ntaps = 11 * samples_per_symbol
 
        arity = pow(2, self.bits_per_symbol())

        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity])
        else:
            self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity])
            
        self.diffenc = gr.diff_encoder_bb(arity)

        rot = 1.0
        print "constellation with %d arity" % arity
        rotated_const = map(lambda pt: pt * rot, qam.constellation[arity])
        self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const)

        # pulse shaping filter
	self.rrc_taps = gr.firdes.root_raised_cosine(
	    self._samples_per_symbol, # gain  (sps since we're interpolating by sps)
            self._samples_per_symbol, # sampling rate
            1.0,		      # symbol rate
            self._excess_bw,          # excess bandwidth (roll-off factor)
            ntaps)

	self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps)

        if verbose:
            self._print_verbage()
        
        if log:
            self._setup_logging()
            
	# Connect
        self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc,
                     self.chunks2symbols, self.rrc_filter, self)
    def __init__(self, gui, options):
        gr.hier_block2.__init__(self, "bpsk_mod",
                                gr.io_signature(1, 1, gr.sizeof_char),       # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
        
        self._samples_per_symbol = options.sps
        self.amplitude = options.amplitude
        self.verbose = options.verbose
        
        self._excess_bw = _def_excess_bw
        self._gray_code = _def_gray_code

        if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2:
            raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol)
    

        arity = pow(2,self.bits_per_symbol())
        
        # turn bytes into k-bit vectors
        self.packed_to_unpacked_bb = \
            gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity])
        else:
            self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity])
        self.diff_encoder_bb = gr.diff_encoder_bb(arity)
            
        #This bloc allow to decode the stream
        #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7)
        
        #Transform symbols to chips
        self.symbols_to_chips = ieee.symbols_to_chips_bs()

        #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity])
        self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j])
        self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j])
        
        # transform chips to symbols
        print "bits_per_symbol", self.bits_per_symbol()
        self.packed_to_unpacked_ss = \
          gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        ntaps = 11 * self._samples_per_symbol
        # pulse shaping filter
        self.rrc_taps = gr.firdes.root_raised_cosine(
                                                     self._samples_per_symbol * self.amplitude,   # gain (samples_per_symbol since we're
                                                                                # interpolating by samples_per_symbol)
                                                     self._samples_per_symbol,   # sampling rate
                                                     1.0,                # symbol rate
                                                     self._excess_bw,            # excess bandwidth (roll-off factor)
                                                     ntaps)
        self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol,
                                                   self.rrc_taps)

        # Connect
        #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self)
        
#        self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c(
#            gui.GetWin(),
#            title="Constellation Plot",
#            sample_rate=self._samples_per_symbol,
#            frame_rate=5,
#            const_size=2048,
#            M=2,
#            theta=0,
#            alpha=0.005,
#            fmax=0.06,
#            mu=0.5,
#            gain_mu=0.005,
#            symbol_rate=self._samples_per_symbol/2,
#            omega_limit=0.005,
#        )
#        gui.Add(self.wxgui_constellationsink2_0.win)
        
        #Modefied for IEEE 802.15.4
        #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss,  self.chunks2symbols, self.rrc_filter, self)
        
        self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss,  self.chunks2symbols, self.rrc_filter, self)
        #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss,  self.chunks2symbols, self.rrc_filter, self)
        
        #self.connect(self, self.packed_to_unpacked_ss,  self.chunks2symbols, self.rrc_filter, self)

        #self.connect(self, self._scrambler, self.chunks2symbols_b, self.rrc_filter, self)
        
        #self.connect(self.rrc_filter, self.wxgui_constellationsink2_0)


        if self.verbose:
            self._print_verbage()
Example #39
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered QPSK modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: integer
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modualtion data to files?
        @type debug: bool
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw

        if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
            raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol)

	ntaps = 11 * samples_per_symbol
 
        arity = 8

        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        #	0	+45	1	[+1]
        #	1	+135	3	[+3]
        #	2	-45	7	[-1]
        #	3	-135	5	[-3]
        self.pi4map = [1, 3, 7, 5]
        self.symbol_mapper = gr.map_bb(self.pi4map)
        self.diffenc = gr.diff_encoder_bb(arity)
        self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity])

        # pulse shaping filter
	self.rrc_taps = firdes.root_raised_cosine(
	    self._samples_per_symbol, # gain  (sps since we're interpolating by sps)
            self._samples_per_symbol, # sampling rate
            1.0,		      # symbol rate
            self._excess_bw,          # excess bandwidth (roll-off factor)
            ntaps)

	self.rrc_filter = filter.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps)

        if verbose:
            self._print_verbage()
        
        if log:
            self._setup_logging()
            
	# Connect & Initialize base class
        self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc,
                     self.chunks2symbols, self.rrc_filter, self)
Example #40
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=1,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("--args", type="string", default="",
                           help="device args")
        parser.add_option("--gains", type="string", default="",
                           help="gains")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = osmosdr.sink (options.args)       # the USRP sink (consumes samples)
        gain_names = self.u.get_gain_names()
        for name in gain_names:
            gain_range = self.u.get_gain_range(name)
            print "gain: name: %s range: start %d stop %d step %d" % (name, gain_range[0].start(), gain_range[0].stop(), gain_range[0].step())
        if options.gains:
            for tuple in options.gains.split(","):
                name, gain = tuple.split(":")
                gain = int(gain)
                print "setting gain %s to %d" % (name, gain)
                self.u.set_gain(gain, name)

        self.usrp_rate = 320000
        print 'setting sample rate'
        self.u.set_sample_rate(self.usrp_rate)
        self.u.set_center_freq(int(options.freq))
        #self.u.set_bandwidth(self.usrp_rate)

        #self.u = blocks.file_sink(gr.sizeof_gr_complex, 'usrp-samp.dat')

        #self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        #self.usrp_interp = 400
        #self.u.set_interp_rate(self.usrp_interp)
        #self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        #self.sw_interp = 10
        #self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s
        self.audio_rate = 32000

#       if not self.set_freq(options.freq):
#           freq_range = self.subdev.freq_range()
#           print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
#               eng_notation.num_to_str(options.freq),
#               eng_notation.num_to_str(freq_range[0]),
#               eng_notation.num_to_str(freq_range[1]))
#           raise SystemExit
#       self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
            i = 0
            t = blocks.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        if 1: # else:
          input_audio_rate = 8000
          #self.audio_input = audio.source(input_audio_rate, options.audio_input)
          af = 1333
          audio_input = analog.sig_source_s( input_audio_rate, analog.GR_SIN_WAVE, af, 15000)
          t = op25_repeater.vocoder(True,		# 0=Decode,True=Encode
                                  options.verbose,	# Verbose flag
                                  options.stretch,	# flex amount
                                  "",			# udp ip address
                                  0,			# udp port
                                  False) 		# dump raw u vectors
          self.connect(audio_input, t)
          self.vocoders.append(t)

        sum = blocks.add_cc ()

        # Instantiate N NBFM channels
        step = 100e3
        offset = (0 * step, -1 * step, +1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        t = file_pipeline(offset[2], self.usrp_rate, '2013-320k-filt.dat')
        self.connect(t, (sum, options.nchannels))

        gain = blocks.multiply_const_cc (0.75 / (options.nchannels+1))

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Example #41
0
File: op25_tx.py Project: wiml/op25
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=1,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("--args", type="string", default="",
                           help="device args")
        parser.add_option("--gains", type="string", default="",
                           help="gains")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = osmosdr.sink (options.args)       # the USRP sink (consumes samples)
        gain_names = self.u.get_gain_names()
        for name in gain_names:
            gain_range = self.u.get_gain_range(name)
            print("gain: name: %s range: start %d stop %d step %d" % (name, gain_range[0].start(), gain_range[0].stop(), gain_range[0].step()))
        if options.gains:
            for tuple in options.gains.split(","):
                name, gain = tuple.split(":")
                gain = int(gain)
                print("setting gain %s to %d" % (name, gain))
                self.u.set_gain(gain, name)

        self.usrp_rate = 320000
        print('setting sample rate')
        self.u.set_sample_rate(self.usrp_rate)
        self.u.set_center_freq(int(options.freq))
        #self.u.set_bandwidth(self.usrp_rate)

        #self.u = blocks.file_sink(gr.sizeof_gr_complex, 'usrp-samp.dat')

        #self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        #self.usrp_interp = 400
        #self.u.set_interp_rate(self.usrp_interp)
        #self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        #self.sw_interp = 10
        #self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s
        self.audio_rate = 32000

#       if not self.set_freq(options.freq):
#           freq_range = self.subdev.freq_range()
#           print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
#               eng_notation.num_to_str(options.freq),
#               eng_notation.num_to_str(freq_range[0]),
#               eng_notation.num_to_str(freq_range[1]))
#           raise SystemExit
#       self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
            i = 0
            t = blocks.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        if 1: # else:
          input_audio_rate = 8000
          #self.audio_input = audio.source(input_audio_rate, options.audio_input)
          af = 1333
          audio_input = analog.sig_source_s( input_audio_rate, analog.GR_SIN_WAVE, af, 15000)
          t = op25_repeater.vocoder(True,          # 0=Decode,True=Encode
                                  options.verbose, # Verbose flag
                                  options.stretch, # flex amount
                                  "",              # udp ip address
                                  0,               # udp port
                                  False)           # dump raw u vectors
          self.connect(audio_input, t)
          self.vocoders.append(t)

        sum = blocks.add_cc ()

        # Instantiate N NBFM channels
        step = 100e3
        offset = (0 * step, -1 * step, +1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        t = file_pipeline(offset[2], self.usrp_rate, '2013-320k-filt.dat')
        self.connect(t, (sum, options.nchannels))

        gain = blocks.multiply_const_cc (0.75 / (options.nchannels+1))

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Example #42
0
    def __init__(self, 
                 samples_per_symbol=_def_samples_per_symbol,
                 bits_per_symbol=_def_bits_per_symbol,
                 h_numerator=_def_h_numerator,
                 h_denominator=_def_h_denominator,
                 cpm_type=_def_cpm_type,
		 bt=_def_bt,
		 symbols_per_pulse=_def_symbols_per_pulse,
                 generic_taps=_def_generic_taps,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for Continuous Phase
	modulation.

	The input is a byte stream (unsigned char) 
        representing packed bits and the
	output is the complex modulated signal at baseband.

        See Proakis for definition of generic CPM signals:
        s(t)=exp(j phi(t))
        phi(t)= 2 pi h int_0^t f(t') dt'
        f(t)=sum_k a_k g(t-kT)
        (normalizing assumption: int_0^infty g(t) dt = 1/2)

	@param samples_per_symbol: samples per baud >= 2
	@type samples_per_symbol: integer
	@param bits_per_symbol: bits per symbol
	@type bits_per_symbol: integer
	@param h_numerator: numerator of modulation index
	@type h_numerator: integer
	@param h_denominator: denominator of modulation index (numerator and denominator must be relative primes)
	@type h_denominator: integer
	@param cpm_type: supported types are: 0=CPFSK, 1=GMSK, 2=RC, 3=GENERAL
	@type cpm_type: integer
        @param bt: bandwidth symbol time product for GMSK
        @type bt: float
	@param symbols_per_pulse: shaping pulse duration in symbols
	@type symbols_per_pulse: integer
	@param generic_taps: define a generic CPM pulse shape (sum = samples_per_symbol/2)
	@type generic_taps: array of floats

        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modulation data to files?
        @type debug: bool       
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._bits_per_symbol = bits_per_symbol
        self._h_numerator = h_numerator
        self._h_denominator = h_denominator
        self._cpm_type = cpm_type
        self._bt=bt
        if cpm_type == 0 or cpm_type == 2 or cpm_type == 3: # CPFSK, RC, Generic
	    self._symbols_per_pulse = symbols_per_pulse
        elif cpm_type == 1: # GMSK
	    self._symbols_per_pulse = 4
        else:
            raise TypeError, ("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))

        self._generic_taps=numpy.array(generic_taps)

        if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
            raise TypeError, ("samples_per_symbol must be an integer >= 2, is %r" % (samples_per_symbol,))

        self.nsymbols = 2**bits_per_symbol
        self.sym_alphabet=numpy.arange(-(self.nsymbols-1),self.nsymbols,2)


	self.ntaps = self._symbols_per_pulse * samples_per_symbol
	sensitivity = 2 * pi * h_numerator / h_denominator / samples_per_symbol

        # Unpack Bytes into bits_per_symbol groups
        self.B2s = gr.packed_to_unpacked_bb(bits_per_symbol,gr.GR_MSB_FIRST)
 
 
	# Turn it into symmetric PAM data.
        self.pam = gr.chunks_to_symbols_bf(self.sym_alphabet,1)

        # Generate pulse (sum of taps = samples_per_symbol/2)
        if cpm_type == 0: # CPFSK
            self.taps= (1.0/self._symbols_per_pulse/2,) * self.ntaps
        elif cpm_type == 1: # GMSK
            gaussian_taps = gr.firdes.gaussian(
                1.0/2,                     # gain
                samples_per_symbol,    # symbol_rate
                bt,                    # bandwidth * symbol time
                self.ntaps                  # number of taps
                )
	    sqwave = (1,) * samples_per_symbol       # rectangular window
	    self.taps = numpy.convolve(numpy.array(gaussian_taps),numpy.array(sqwave))
        elif cpm_type == 2: # Raised Cosine
            # generalize it for arbitrary roll-off factor
            self.taps = (1-numpy.cos(2*pi*numpy.arange(0,self.ntaps)/samples_per_symbol/self._symbols_per_pulse))/(2*self._symbols_per_pulse)
        elif cpm_type == 3: # Generic CPM
            self.taps = generic_taps
        else:
            raise TypeError, ("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))

	self.filter = gr.interp_fir_filter_fff(samples_per_symbol, self.taps)

	# FM modulation
	self.fmmod = gr.frequency_modulator_fc(sensitivity)
		
        if verbose:
            self._print_verbage()
         
        if log:
            self._setup_logging()

	# Connect
	self.connect(self, self.B2s, self.pam, self.filter, self.fmmod, self)
Example #43
0
	def __init__(self, deframer_insync_frames=2, deframer_outsync_frames=5, deframer_sync_check=True, pll_alpha=0.005, baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam', satellite='MetOp', viterbi_sync_threshold=0.1, viterbi_outsync_frames=20, viterbi_insync_frames=5, frames_file=os.environ['HOME'] + '/MetOp-cadu_frames.cadu', clock_alpha=0.05, symb_rate=(3500e3/3+3500e3)/2, symb_rate_0=3*3500/4, viterbi_sync_check=True, decim=24):
		grc_wxgui.top_block_gui.__init__(self, title="MetOp AHRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

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

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

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

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_file_source_0_0_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.fec_decode_viterbi_ahrpt_metop_cb_0, 0))
		self.connect((self.fec_decode_viterbi_ahrpt_metop_cb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
Example #44
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e",
                          "--enable-fft",
                          action="store_true",
                          default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("-i",
                          "--file-input",
                          action="store_true",
                          default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g",
                          "--audio-gain",
                          type="eng_float",
                          default=1.0,
                          help="input audio gain multiplier")
        parser.add_option("-n",
                          "--nchannels",
                          type="int",
                          default=2,
                          help="number of Tx channels [1,4]")
        parser.add_option("-a",
                          "--udp-addr",
                          type="string",
                          default="127.0.0.1",
                          help="UDP host IP address")
        parser.add_option("-p",
                          "--udp-port",
                          type="int",
                          default=0,
                          help="UDP port number")
        parser.add_option("-r",
                          "--repeat",
                          action="store_true",
                          default=False,
                          help="continuously replay input file")
        parser.add_option("-S",
                          "--stretch",
                          type="int",
                          default=0,
                          help="elastic buffer trigger value")
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          help="print out stats")
        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write(
                "op25_tx: nchannels out of range.  Must be in [1,%d]\n" %
                MAX_CHANNELS)
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c()  # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp  # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.subdev.set_gain(self.subdev.gain_range()[0])  # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(
                    options.freq), eng_notation.num_to_str(
                        freq_range[0]), eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)  # enable transmitter

        # instantiate vocoders
        self.vocoders = []
        if options.file_input:
            for i in range(options.nchannels):
                t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i,
                                   options.repeat)
                self.vocoders.append(t)

        elif options.udp_port > 0:
            self.udp_sources = []
            for i in range(options.nchannels):
                t = gr.udp_source(1, options.udp_addr, options.udp_port + i,
                                  216)
                self.udp_sources.append(t)
                arity = 2
                t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
                self.vocoders.append(t)
                self.connect(self.udp_sources[i], self.vocoders[i])

        else:
            self.audio_amps = []
            self.converters = []
            input_audio_rate = 8000
            self.audio_input = audio.source(input_audio_rate,
                                            options.audio_input)
            for i in range(options.nchannels):
                t = gr.multiply_const_ff(32767 * options.audio_gain)
                self.audio_amps.append(t)
                t = gr.float_to_short()
                self.converters.append(t)
                t = repeater.vocoder(
                    True,  # 0=Decode,True=Encode
                    options.verbose,  # Verbose flag
                    options.stretch,  # flex amount
                    "",  # udp ip address
                    0,  # udp port
                    False)  # dump raw u vectors
                self.vocoders.append(t)
                self.connect((self.audio_input, i), self.audio_amps[i],
                             self.converters[i], self.vocoders[i])

        sum = gr.add_cc()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step,
                  -3 * step)
        for i in range(options.nchannels):
            t = pipeline(self.vocoders[i], offset[i], self.audio_rate,
                         self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc(4000.0 / options.nchannels)

        # connect it all
        self.connect(sum, gain)
        self.connect(gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel,
                                           title="Post Modulation",
                                           fft_size=512,
                                           sample_rate=self.usrp_rate,
                                           y_per_div=20,
                                           ref_level=40)
            self.connect(sum, post_mod)
            vbox.Add(post_mod.win, 1, wx.EXPAND)
Example #45
0
    def __init__(self,
                 constellation,
                 samples_per_symbol=_def_samples_per_symbol,
                 differential=_def_differential,
                 excess_bw=_def_excess_bw,
                 gray_coded=True,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered differential generic modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.
        
	@param constellation: determines the modulation type
	@type constellation: gnuradio.digital.gr_constellation
	@param samples_per_symbol: samples per baud >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param gray_coded: turn gray coding on/off
        @type gray_coded: bool
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param log: Log modulation data to files?
        @type log: bool
	"""

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

        self._constellation = constellation.base()
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._differential = differential

        if self._samples_per_symbol < 2:
            raise TypeError, ("sbp must be >= 2, is %f" %
                              self._samples_per_symbol)

        arity = pow(2, self.bits_per_symbol())

        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if gray_coded == True:
            self.symbol_mapper = digital.map_bb(
                self._constellation.pre_diff_code())

        if differential:
            self.diffenc = digital.diff_encoder_bb(arity)

        self.chunks2symbols = digital.chunks_to_symbols_bc(
            self._constellation.points())

        # pulse shaping filter
        nfilts = 32
        ntaps = nfilts * 11 * int(
            self._samples_per_symbol)  # make nfilts filters of ntaps each
        self.rrc_taps = gr.firdes.root_raised_cosine(
            nfilts,  # gain
            nfilts,  # sampling rate based on 32 filters in resampler
            1.0,  # symbol rate
            self._excess_bw,  # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol,
                                                   self.rrc_taps)

        # Connect
        blocks = [self, self.bytes2chunks]
        if gray_coded == True:
            blocks.append(self.symbol_mapper)
        if differential:
            blocks.append(self.diffenc)
        blocks += [self.chunks2symbols, self.rrc_filter, self]
        self.connect(*blocks)

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()
Example #46
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered QPSK modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: integer
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param gray_code: Tell modulator to Gray code the bits
        @type gray_code: bool
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modualtion data to files?
        @type debug: bool
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._gray_code = gray_code

        if samples_per_symbol < 2:
            raise TypeError, ("sbp must be >= 2, is %f" % samples_per_symbol)

        ntaps = 11 * samples_per_symbol

        arity = pow(2, self.bits_per_symbol())

        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity])
        else:
            self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity])

        self.diffenc = gr.diff_encoder_bb(arity)

        rot = .707 + .707j
        rotated_const = map(lambda pt: pt * rot, psk.constellation[arity])
        self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const)

        # pulse shaping filter
        nfilts = 32
        ntaps = 11 * int(
            nfilts *
            self._samples_per_symbol)  # make nfilts filters of ntaps each
        self.rrc_taps = gr.firdes.root_raised_cosine(
            nfilts,  # gain
            nfilts,  # sampling rate based on 32 filters in resampler
            1.0,  # symbol rate
            self._excess_bw,  # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol,
                                                   self.rrc_taps)

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

# Connect & Initialize base class
        self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc,
                     self.chunks2symbols, self.rrc_filter, self)
Example #47
0
    def __init__(self,
                 deframer_insync_frames=2,
                 viterbi_insync_frames=5,
                 deframer_outsync_frames=5,
                 viterbi_outsync_frames=20,
                 viterbi_sync_check=True,
                 viterbi_sync_threshold=0.1,
                 deframer_sync_check=True,
                 clock_alpha=0.005,
                 symb_rate=293883,
                 pll_alpha=0.005,
                 satellite='GOES-LRIT',
                 freq=1691.02e6,
                 gain=23,
                 decim=108,
                 side="A",
                 frames_file=os.environ['HOME'] +
                 '/GOES-LRIT_cadu_frames.cadu',
                 baseband_file=os.environ['HOME'] + '/GOES-LRIT_baseband.dat'):
        grc_wxgui.top_block_gui.__init__(
            self, title="LRIT Receiver from baseband file")

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

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

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

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

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

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.poesweather_metop_cadu_deframer_0, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.fec_decode_viterbi_bpsk_fb_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.wxgui_fftsink2, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.poesweather_metop_cadu_deframer_0, 0),
                     (self.gr_null_sink_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
Example #48
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 bits_per_symbol=_def_bits_per_symbol,
                 h_numerator=_def_h_numerator,
                 h_denominator=_def_h_denominator,
                 cpm_type=_def_cpm_type,
                 bt=_def_bt,
                 symbols_per_pulse=_def_symbols_per_pulse,
                 generic_taps=_def_generic_taps,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for Continuous Phase
	modulation.

	The input is a byte stream (unsigned char) 
        representing packed bits and the
	output is the complex modulated signal at baseband.

        See Proakis for definition of generic CPM signals:
        s(t)=exp(j phi(t))
        phi(t)= 2 pi h int_0^t f(t') dt'
        f(t)=sum_k a_k g(t-kT)
        (normalizing assumption: int_0^infty g(t) dt = 1/2)

	@param samples_per_symbol: samples per baud >= 2
	@type samples_per_symbol: integer
	@param bits_per_symbol: bits per symbol
	@type bits_per_symbol: integer
	@param h_numerator: numerator of modulation index
	@type h_numerator: integer
	@param h_denominator: denominator of modulation index (numerator and denominator must be relative primes)
	@type h_denominator: integer
	@param cpm_type: supported types are: 0=CPFSK, 1=GMSK, 2=RC, 3=GENERAL
	@type cpm_type: integer
        @param bt: bandwidth symbol time product for GMSK
        @type bt: float
	@param symbols_per_pulse: shaping pulse duration in symbols
	@type symbols_per_pulse: integer
	@param generic_taps: define a generic CPM pulse shape (sum = samples_per_symbol/2)
	@type generic_taps: array of floats

        @param verbose: Print information about modulator?
        @type verbose: bool
        @param debug: Print modulation data to files?
        @type debug: bool       
	"""

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

        self._samples_per_symbol = samples_per_symbol
        self._bits_per_symbol = bits_per_symbol
        self._h_numerator = h_numerator
        self._h_denominator = h_denominator
        self._cpm_type = cpm_type
        self._bt = bt
        if cpm_type == 0 or cpm_type == 2 or cpm_type == 3:  # CPFSK, RC, Generic
            self._symbols_per_pulse = symbols_per_pulse
        elif cpm_type == 1:  # GMSK
            self._symbols_per_pulse = 4
        else:
            raise TypeError, (
                "cpm_type must be an integer in {0,1,2,3}, is %r" %
                (cpm_type, ))

        self._generic_taps = numpy.array(generic_taps)

        if samples_per_symbol < 2:
            raise TypeError, ("samples_per_symbol must be >= 2, is %r" %
                              (samples_per_symbol, ))

        self.nsymbols = 2**bits_per_symbol
        self.sym_alphabet = numpy.arange(-(self.nsymbols - 1), self.nsymbols,
                                         2).tolist()

        self.ntaps = int(self._symbols_per_pulse * samples_per_symbol)
        sensitivity = 2 * pi * h_numerator / h_denominator / samples_per_symbol

        # Unpack Bytes into bits_per_symbol groups
        self.B2s = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)

        # Turn it into symmetric PAM data.
        self.pam = gr.chunks_to_symbols_bf(self.sym_alphabet, 1)

        # Generate pulse (sum of taps = samples_per_symbol/2)
        if cpm_type == 0:  # CPFSK
            self.taps = (1.0 / self._symbols_per_pulse / 2, ) * self.ntaps
        elif cpm_type == 1:  # GMSK
            gaussian_taps = gr.firdes.gaussian(
                1.0 / 2,  # gain
                samples_per_symbol,  # symbol_rate
                bt,  # bandwidth * symbol time
                self.ntaps  # number of taps
            )
            sqwave = (1, ) * samples_per_symbol  # rectangular window
            self.taps = numpy.convolve(numpy.array(gaussian_taps),
                                       numpy.array(sqwave))
        elif cpm_type == 2:  # Raised Cosine
            # generalize it for arbitrary roll-off factor
            self.taps = (1 - numpy.cos(
                2 * pi * numpy.arange(0, self.ntaps) / samples_per_symbol /
                self._symbols_per_pulse)) / (2 * self._symbols_per_pulse)
        elif cpm_type == 3:  # Generic CPM
            self.taps = generic_taps
        else:
            raise TypeError, (
                "cpm_type must be an integer in {0,1,2,3}, is %r" %
                (cpm_type, ))

        self.filter = blks2.pfb_arb_resampler_fff(samples_per_symbol,
                                                  self.taps)

        # FM modulation
        self.fmmod = gr.frequency_modulator_fc(sensitivity)

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

# Connect
        self.connect(self, self.B2s, self.pam, self.filter, self.fmmod, self)
    def __init__(self, constellation,
                 samples_per_symbol=_def_samples_per_symbol,
                 differential=_def_differential,
                 excess_bw=_def_excess_bw,
                 gray_coded=True,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered differential generic modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.
        
	@param constellation: determines the modulation type
	@type constellation: gnuradio.digital.gr_constellation
	@param samples_per_symbol: samples per baud >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param gray_coded: turn gray coding on/off
        @type gray_coded: bool
        @param verbose: Print information about modulator?
        @type verbose: bool
        @param log: Log modulation data to files?
        @type log: bool
	"""

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

        self._constellation = constellation.base()
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._differential = differential

        if self._samples_per_symbol < 2:
            raise TypeError, ("sbp must be >= 2, is %f" % self._samples_per_symbol)
        
        arity = pow(2,self.bits_per_symbol())
        
        # turn bytes into k-bit vectors
        self.bytes2chunks = \
          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)

        if gray_coded == True:
            self.symbol_mapper = gr.map_bb(self._constellation.pre_diff_code())

        if differential:
            self.diffenc = gr.diff_encoder_bb(arity)

        self.chunks2symbols = gr.chunks_to_symbols_bc(self._constellation.points())

        # pulse shaping filter
        nfilts = 32
        ntaps = nfilts * 11 * int(self._samples_per_symbol)    # make nfilts filters of ntaps each
        self.rrc_taps = gr.firdes.root_raised_cosine(
            nfilts,          # gain
            nfilts,          # sampling rate based on 32 filters in resampler
            1.0,             # symbol rate
            self._excess_bw, # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol,
                                                   self.rrc_taps)

	# Connect
        blocks = [self, self.bytes2chunks]
        if gray_coded == True:
            blocks.append(self.symbol_mapper)
        if differential:
            blocks.append(self.diffenc)
        blocks += [self.chunks2symbols, self.rrc_filter, self]
        self.connect(*blocks)

        if verbose:
            self._print_verbage()
            
        if log:
            self._setup_logging()
	def __init__(self, deframer_insync_frames=2, deframer_sync_check=True, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, satellite='GOES-LRIT', freq=1691.02e6, gain=23, decim=108, side="A", pll_alpha=0.005, symb_rate=293883, clock_alpha=0.005):
		grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver - check signal quality")

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

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

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

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

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

		##################################################
		# Connections
		##################################################
		self.connect((self.usrp_simple_source, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.fec_decode_viterbi_bpsk_fb_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_null_sink_0, 0))
Example #51
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=2,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.subdev.set_gain(self.subdev.gain_range()[0])    # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
          for i in range (options.nchannels):
            t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        else:
          self.audio_amps = []
          self.converters = []
          input_audio_rate = 8000
          self.audio_input = audio.source(input_audio_rate, options.audio_input)
          for i in range (options.nchannels):
            t = gr.multiply_const_ff(32767 * options.audio_gain)
            self.audio_amps.append(t)
            t = gr.float_to_short()
            self.converters.append(t)
            t = repeater.vocoder(True,			# 0=Decode,True=Encode
                                  options.verbose,	# Verbose flag
                                  options.stretch,	# flex amount
                                  "",			# udp ip address
                                  0,			# udp port
                                  False) 		# dump raw u vectors
            self.vocoders.append(t)
            self.connect((self.audio_input, i), self.audio_amps[i], self.converters[i], self.vocoders[i])

        sum = gr.add_cc ()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc (4000.0 / options.nchannels)

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Example #52
0
    def __init__(self, fg, spb, alpha, gain, use_barker=0):
        """
	Hierarchical block for RRC-filtered PSK modulation
	modulation.

	The input is a byte stream (unsigned char) and the
	output is the complex modulated signal at baseband.

	@param fg: flow graph
	@type fg: flow graph
	@param spb: samples per baud >= 2
	@type spb: integer
	@param alpha: Root-raised cosine filter excess bandwidth
	@type alpha: float
	"""
        if not isinstance(spb, int) or spb < 2:
            raise TypeError, "sbp must be an integer >= 2"
        self.spb = spb
        self.bits_per_chunk = 1

	ntaps = 2 * spb - 1
        alpha = 0.5

        # turn bytes into symbols
        self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk,
                                                     gr.GR_MSB_FIRST)

        constellation = ( (),
                          ( -1-0j,1+0j ),
                          ( 0.707+0.707j,-0.707-0.707j ),
                          ( 0.707+0j,-0.707-0.707j ),
                          ( -1+0j,-1j, 1j, 1+0j),
                          ( 1+0j,0+1j,-1+0j,0-1j ),
                          ( 0+0j,1+0j ),
                          )

        self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2])
        self.scrambler = bbn.scrambler_bb(True)
        self.diff_encode = gr.diff_encoder_bb(2);

        self.barker_taps = bbn.firdes_barker(spb)

	# Form Raised Cosine filter
	self.rrc_taps = gr.firdes.root_raised_cosine(
		4 * gain,     	# gain  FIXME may need to be spb
		spb,            # sampling freq
		1.0,		# symbol_rate
		alpha,
                ntaps)

        if use_barker:
            self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps)
        else:
            self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps)

	# Connect
        fg.connect(self.scrambler, self.bytes2chunks)
        fg.connect(self.bytes2chunks, self.diff_encode)
        fg.connect(self.diff_encode, self.chunks2symbols)
	fg.connect(self.chunks2symbols,self.tx_filter)

	# Initialize base class
        gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter)
        bbn.crc16_init()