示例#1
0
    def qamtest(self, nbits):
        data = tuple(range(2**nbits))

        src = gr.vector_source_b(data)
        unpack = gr.unpack_k_bits_bb(nbits)
        enc = raw.qam_enc(nbits)
        dec = raw.qam_dec(nbits)
        tofloat = gr.uchar_to_float()
        slicer = gr.binary_slicer_fb()

        unpacked = gr.vector_sink_b()
        encoded = gr.vector_sink_c()
        decoded = gr.vector_sink_b()
        dst = gr.vector_sink_b()
        self.tb.connect(src, unpack, enc, dec, tofloat,
                        gr.add_const_ff(-128.0), slicer, dst)
        self.tb.connect(unpack, unpacked)
        self.tb.connect(enc, encoded)
        self.tb.connect(dec, decoded)
        self.tb.run()
        #print "data = ", data
        #print "unpacked = ", unpacked.data()
        #print "encoded = ", encoded.data()
        #print "decoded = ", decoded.data()
        #print "dst = ", dst.data()
        self.assertEqual(unpacked.data(), dst.data())
        pwr = sum([abs(x)**2 for x in encoded.data()]) / len(encoded.data())
        #print pwr
        self.assertAlmostEqual(1.0, pwr, 6)
    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)
示例#3
0
文件: qa_qam.py 项目: UpYou/ofdm
    def qamtest (self, nbits):
        data = tuple(range(2**nbits))

        src = gr.vector_source_b(data)
        unpack = gr.unpack_k_bits_bb(nbits)
        enc = raw.qam_enc(nbits)
        dec = raw.qam_dec(nbits)
        tofloat = gr.uchar_to_float()
        slicer = gr.binary_slicer_fb()

        unpacked = gr.vector_sink_b()
        encoded = gr.vector_sink_c()
        decoded = gr.vector_sink_b()
        dst = gr.vector_sink_b()
        self.tb.connect(src,
                        unpack,
                        enc,
                        dec,
                        tofloat,
                        gr.add_const_ff(-128.0),
                        slicer,
                        dst)
        self.tb.connect(unpack, unpacked)
        self.tb.connect(enc, encoded)
        self.tb.connect(dec, decoded)
        self.tb.run()
        #print "data = ", data
        #print "unpacked = ", unpacked.data()
        #print "encoded = ", encoded.data()
        #print "decoded = ", decoded.data()
        #print "dst = ", dst.data()
        self.assertEqual(unpacked.data(), dst.data())
        pwr = sum([abs(x)**2 for x in encoded.data()]) / len(encoded.data())
        #print pwr
        self.assertAlmostEqual(1.0, pwr, 6)
示例#4
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)
示例#5
0
 def test_003(self):
     src_data = expected_results = map(lambda x: random.randint(0,3), range(10));
     src = gr.vector_source_b( src_data );
     pack = gr.pack_k_bits_bb(2);
     unpack = gr.unpack_k_bits_bb(2);
     snk = gr.vector_sink_b();
     self.tb.connect(src,unpack,pack,snk);
     self.tb.run()
     self.assertEqual(list(expected_results), list(snk.data()));
示例#6
0
 def test_002(self):
     src_data =         (  2,  3,  0,  1)
     expected_results = (1,0,1,1,0,0,0,1)
     src = gr.vector_source_b(src_data,False)
     op = gr.unpack_k_bits_bb(2)
     dst = gr.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_results, dst.data())
示例#7
0
 def test_002(self):
     src_data = (2, 3, 0, 1)
     expected_results = (1, 0, 1, 1, 0, 0, 0, 1)
     src = gr.vector_source_b(src_data, False)
     op = gr.unpack_k_bits_bb(2)
     dst = gr.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_results, dst.data())
	def __init__(self):
		gr.hier_block2.__init__(self, "dvb_convolutional_encoder_bb",
				gr.io_signature(1, 1, gr.sizeof_char),	# Input signature
				gr.io_signature(1, 1, gr.sizeof_char))	# Output signature

		self.encoder = trellis.encoder_bb(trellis.fsm(dvb_swig.k, dvb_swig.n, G), dvb_swig.dimensionality)
		self.unpack = gr.unpack_k_bits_bb(dvb_swig.dimensionality)

		self.connect(self, self.encoder, self.unpack, self)
示例#9
0
 def test_003(self):
     src_data = expected_results = map(lambda x: random.randint(0, 3),
                                       range(10))
     src = gr.vector_source_b(src_data)
     pack = gr.pack_k_bits_bb(2)
     unpack = gr.unpack_k_bits_bb(2)
     snk = gr.vector_sink_b()
     self.tb.connect(src, unpack, pack, snk)
     self.tb.run()
     self.assertEqual(list(expected_results), list(snk.data()))
示例#10
0
    def __init__(self):
        gr.hier_block2.__init__(
            self,
            "dvb_convolutional_encoder_bb",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))  # Output signature

        self.encoder = trellis.encoder_bb(
            trellis.fsm(dvb_swig.k, dvb_swig.n, G), dvb_swig.dimensionality)
        self.unpack = gr.unpack_k_bits_bb(dvb_swig.dimensionality)

        self.connect(self, self.encoder, self.unpack, self)
示例#11
0
    def __init__(self, bits_per_byte):
        gr.hier_block2.__init__(self, "BitErrors",
                                gr.io_signature(2, 2, gr.sizeof_char),
                                gr.io_signature(1, 1, gr.sizeof_int))

        # Bit comparison
        comp = gr.xor_bb()
        intdump_decim = 100000
        if N_BITS < intdump_decim:
            intdump_decim = int(N_BITS)
        self.connect(self, comp, gr.unpack_k_bits_bb(bits_per_byte),
                     gr.uchar_to_float(), gr.integrate_ff(intdump_decim),
                     gr.multiply_const_ff(1.0 / N_BITS), self)
        self.connect((self, 1), (comp, 1))
示例#12
0
	def __init__(self, vlen_in=1, vlen_out=1, n_tailbits=6, denom_mother_code_rate=6, gen_poly=(91, 121, 101, 91, 121, 101), N=1, bits_per_symbol=0, pp=0, pp_tail=0, interl_seq=range(2), map_tab=0):
		gr.hier_block2.__init__(
			self, "DRM MLC 4-QAM",
			gr.io_signature(1, 1, gr.sizeof_char*vlen_in),
			gr.io_signature(1, 1, gr.sizeof_gr_complex*vlen_out),
		)

		##################################################
		# Parameters
		##################################################
		self.vlen_in = vlen_in
		self.vlen_out = vlen_out
		self.n_tailbits = n_tailbits
		self.denom_mother_code_rate = denom_mother_code_rate
		self.gen_poly = gen_poly
		self.N = N
		self.bits_per_symbol = bits_per_symbol
		self.pp = pp
		self.pp_tail = pp_tail
		self.interl_seq = interl_seq
		self.map_tab = map_tab

		##################################################
		# Blocks
		##################################################
		self.trellis_encoder_xx_0 = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0)
		self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_char*1, vlen_in + n_tailbits)
		self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(denom_mother_code_rate)
		self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_char*1, (vlen_in + n_tailbits) * denom_mother_code_rate)
		self.drm_qam_map_vbvc_0 = drm.qam_map_vbvc(map_tab, bits_per_symbol, vlen_out, 1)
		self.drm_punct_vbvb_0 = drm.punct_vbvb(pp, pp_tail, (vlen_in + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate)
		self.drm_interleaver_vbvb_0 = drm.interleaver_vbvb((interl_seq))
		self.add_tailbits_vbvb_0 = drm.add_tailbits_vbvb(vlen_in, n_tailbits)

		##################################################
		# Connections
		##################################################
		self.connect((self, 0), (self.add_tailbits_vbvb_0, 0))
		self.connect((self.add_tailbits_vbvb_0, 0), (self.gr_vector_to_stream_0, 0))
		self.connect((self.gr_vector_to_stream_0, 0), (self.trellis_encoder_xx_0, 0))
		self.connect((self.trellis_encoder_xx_0, 0), (self.gr_unpack_k_bits_bb_0, 0))
		self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_stream_to_vector_0, 0))
		self.connect((self.gr_stream_to_vector_0, 0), (self.drm_punct_vbvb_0, 0))
		self.connect((self.drm_punct_vbvb_0, 0), (self.drm_interleaver_vbvb_0, 0))
		self.connect((self.drm_interleaver_vbvb_0, 0), (self.drm_qam_map_vbvc_0, 0))
		self.connect((self.drm_qam_map_vbvc_0, 0), (self, 0))
示例#13
0
    def __init__(self, bits_per_byte):
        gr.hier_block2.__init__(self, "BitErrors",
                gr.io_signature(2, 2, gr.sizeof_char),
                gr.io_signature(1, 1, gr.sizeof_int))

        # Bit comparison
        comp = gr.xor_bb()
        intdump_decim = 100000
        if N_BITS < intdump_decim:
            intdump_decim = int(N_BITS)
        self.connect(self,
                     comp,
                     gr.unpack_k_bits_bb(bits_per_byte),
                     gr.uchar_to_float(),
                     gr.integrate_ff(intdump_decim),
                     gr.multiply_const_ff(1.0/N_BITS),
                     self)
        self.connect((self, 1), (comp, 1))
示例#14
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 freq_alpha=_def_freq_alpha,
                 phase_alpha=_def_phase_alpha,
                 timing_alpha=_def_timing_alpha,
                 timing_max_dev=_def_timing_max_dev,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log,
                 sync_out=False):
        """
	Hierarchical block for RRC-filtered DQPSK demodulation

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

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param freq_alpha: loop filter gain for frequency recovery
        @type freq_alpha: float
        @param phase_alpha: loop filter gain
        @type phase_alphas: float
        @param timing_alpha: timing loop alpha gain
        @type timing_alpha: float
        @param timing_max: timing loop maximum rate deviations
        @type timing_max: 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 log: Print modualtion data to files?
        @type log: bool
        @param sync_out: Output a sync signal on :1?
        @type sync_out: bool
	"""
        if sync_out:
            io_sig_out = gr.io_signaturev(
                2, 2, (gr.sizeof_char, gr.sizeof_gr_complex))
        else:
            io_sig_out = gr.io_signature(1, 1, gr.sizeof_char)

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

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._freq_alpha = freq_alpha
        self._freq_beta = 0.25 * self._freq_alpha**2
        self._phase_alpha = phase_alpha
        self._timing_alpha = timing_alpha
        self._timing_beta = _def_timing_beta
        self._timing_max_dev = timing_max_dev
        self._gray_code = gray_code

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

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

        # Automatic gain control
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        #self.agc = gr.feedforward_agc_cc(16, 2.0)

        # Frequency correction
        self.freq_recov = gr.fll_band_edge_cc(
            self._samples_per_symbol, self._excess_bw,
            11 * int(self._samples_per_symbol), self._freq_alpha,
            self._freq_beta)

        # symbol timing recovery with RRC data filter
        nfilts = 32
        ntaps = 11 * int(samples_per_symbol * nfilts)
        taps = gr.firdes.root_raised_cosine(
            nfilts, nfilts, 1.0 / float(self._samples_per_symbol),
            self._excess_bw, ntaps)
        self.time_recov = gr.pfb_clock_sync_ccf(self._samples_per_symbol,
                                                self._timing_alpha, taps,
                                                nfilts, nfilts / 2,
                                                self._timing_max_dev)
        self.time_recov.set_beta(self._timing_beta)

        # Perform phase / fine frequency correction
        self._phase_beta = 0.25 * self._phase_alpha * self._phase_alpha
        # Allow a frequency swing of +/- half of the sample rate
        fmin = -0.5
        fmax = 0.5

        self.phase_recov = gr.costas_loop_cc(self._phase_alpha,
                                             self._phase_beta, fmax, fmin,
                                             arity)

        # Perform Differential decoding on the constellation
        self.diffdec = gr.diff_phasor_cc()

        # find closest constellation point
        rot = 1
        rotated_const = map(lambda pt: pt * rot, psk.constellation[arity])
        self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity))

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

        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

        # Connect
        self.connect(self, self.agc, self.freq_recov, self.time_recov,
                     self.phase_recov, self.diffdec, self.slicer,
                     self.symbol_mapper, self.unpack, self)
        if sync_out: self.connect(self.time_recov, (self, 1))
    def __init__(self, constellation,
                 differential=_def_differential,
                 samples_per_symbol=_def_samples_per_symbol,
                 pre_diff_code=True,
                 excess_bw=_def_excess_bw,
                 freq_bw=_def_freq_bw,
                 timing_bw=_def_timing_bw,
                 phase_bw=_def_phase_bw,
                 verbose=_def_verbose,
                 log=_def_log):
        
	gr.hier_block2.__init__(self, "generic_demod",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(1, 1, gr.sizeof_char))       # Output signature
				
        self._constellation = constellation
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._phase_bw = phase_bw
        self._freq_bw = freq_bw
        self._timing_bw = timing_bw
        self._timing_max_dev= _def_timing_max_dev
        self._differential = differential

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

        # Only apply a predifferential coding if the constellation also supports it.
        self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()

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

        nfilts = 32
        ntaps = 11 * int(self._samples_per_symbol*nfilts)

        # Automatic gain control
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)

        # Frequency correction
        fll_ntaps = 55
        self.freq_recov = digital.fll_band_edge_cc(self._samples_per_symbol, self._excess_bw,
                                                   fll_ntaps, self._freq_bw)

        # symbol timing recovery with RRC data filter
        taps = gr.firdes.root_raised_cosine(nfilts, nfilts*self._samples_per_symbol,
                                            1.0, self._excess_bw, ntaps)
        self.time_recov = digital.pfb_clock_sync_ccf(self._samples_per_symbol,
                                                     self._timing_bw, taps,
                                                     nfilts, nfilts//2, self._timing_max_dev)

        fmin = -0.25
        fmax = 0.25
        self.receiver = digital.constellation_receiver_cb(
            self._constellation.base(), self._phase_bw,
            fmin, fmax)

        # Do differential decoding based on phase change of symbols
        if differential:
            self.diffdec = digital.diff_decoder_bb(arity)

        if self.pre_diff_code:
            self.symbol_mapper = digital.map_bb(
                mod_codes.invert_code(self._constellation.pre_diff_code()))

        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()
        
        # Connect and Initialize base class
        blocks = [self, self.agc, self.freq_recov,
                  self.time_recov, self.receiver]
        if differential:
            blocks.append(self.diffdec)
        if self.pre_diff_code:
            blocks.append(self.symbol_mapper)
        blocks += [self.unpack, self]
        self.connect(*blocks)
示例#16
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        # Read in successfully decoded live data from Matlab
        linf=open('/home/demel/exchange/matlab_d.txt')
        lintu=range(120)
        for i in lintu:
            lintu[i]=float(linf.readline())
        #print lintu
        # source for live data
        self.srcl = gr.vector_source_f(lintu,False,120)
        
        # Read in .txt file with example MIB encoded + CRC checksum
        inf=open('/home/demel/exchange/crc.txt')
        self.intu=range(40)
        for i in self.intu:
            self.intu[i]=float(inf.readline())
                
        #inf=open('/home/demel/exchange/matlab_d.txt')
        #intu=range(120)
    	#for i in range(120):
    	#	intu[i]=float(inf.readline())
        
        # Source and conversions
        self.src  = gr.vector_source_f(self.intu,False,40)
        self.conv = gr.float_to_char(40,1)

        # Resize vector with repetition of last part
        # Vector to stream for encoder
        my_map1=range(46)
        for i in range(40):
            my_map1[i+6]=i
        for i in range(6):
            my_map1[i]=i+40
        self.map1 = lte.vector_resize_vbvb(my_map1,40,46)
        self.vtos = gr.vector_to_stream(1*gr.sizeof_char,46)
        
        # Encoding of input data
        self.fsm  = trellis.fsm(1,3,[91,121,117])
        self.enc  = trellis.encoder_bb(self.fsm,0)
        # unpack packed bits from encoder
        self.unp  = gr.unpack_k_bits_bb(3)
        # stream to vector
        self.stov = gr.stream_to_vector(1*gr.sizeof_char,138)
        # Remove first part which contains tail-biting init stuff
        map2 = range(120)
        for i in map2:
            map2[i]= i+18
        self.map2 = lte.vector_resize_vbvb(map2,138,120)
        # conversion from char to float to match input of decoder
        self.conv2= gr.char_to_float(120,1)
        
        
        ###############################################
        # From here on only "receiver side" processing
        ###############################################
        
        # like QPSK demodulation: NRZ coding.
        vec2=range(120)
        for i in vec2:
            vec2[i]=float(-2.0)
        self.mult = gr.multiply_const_vff(vec2)
        vec=range(120)
        for i in vec:
            vec[i]=1
        self.add  = gr.add_const_vff(vec)
        
        # this is the actual unit under test
        self.vit = lte.viterbi_vfvb()
        
        # Sinks
        self.snk = gr.vector_sink_b(40)
        self.snk2 = gr.vector_sink_f(120)
        
        # connecting blocks
        self.tb.connect(self.src,self.conv,self.map1,self.vtos,self.enc,self.unp)
        self.tb.connect(self.unp,self.stov,self.map2,self.conv2)
        self.tb.connect(self.conv2,self.mult,self.add)
        self.tb.connect(self.srcl,self.vit,self.snk)
        self.tb.connect(self.add,self.snk2)
示例#17
0
    def __init__(self, frame, panel, vbox, argv):
        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("-f",
                          "--freq",
                          type="eng_float",
                          default=107.2e6,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("--wavfile",
                          type="string",
                          default=None,
                          help="open .wav audio file FILE")
        parser.add_option("--xml",
                          type="string",
                          default="rds_data.xml",
                          help="open .xml RDS data FILE")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        usrp_interp = 500
        self.u = usrp.sink_c(0, usrp_interp)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.dac_rate() / usrp_interp  # 256 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)
        self.u.set_mux(
            usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        # set max Tx gain, tune frequency and enable transmitter
        gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(gain)
        print "Gain set to", gain
        if self.u.tune(self.subdev.which(), self.subdev, options.freq):
            print "Tuned to", options.freq / 1e6, "MHz"
        else:
            sys.exit(1)
        self.subdev.set_enable(True)

        # open wav file containing floats in the [-1, 1] range, repeat
        if options.wavfile is None:
            print "Please provide a wavfile to transmit! Exiting\n"
            sys.exit(1)
        self.src = gr.wavfile_source(options.wavfile, True)
        nchans = self.src.channels()
        sample_rate = self.src.sample_rate()
        bits_per_sample = self.src.bits_per_sample()
        print nchans, "channels,", sample_rate, "samples/sec,", \
         bits_per_sample, "bits/sample"

        # resample to usrp rate
        self.resample_left = blks2.rational_resampler_fff(
            usrp_rate, sample_rate)
        self.resample_right = blks2.rational_resampler_fff(
            usrp_rate, sample_rate)
        self.connect((self.src, 0), self.resample_left)
        self.connect((self.src, 1), self.resample_right)

        # create L+R (mono) and L-R (stereo)
        self.audio_lpr = gr.add_ff()
        self.audio_lmr = gr.sub_ff()
        self.connect(self.resample_left, (self.audio_lpr, 0))
        self.connect(self.resample_left, (self.audio_lmr, 0))
        self.connect(self.resample_right, (self.audio_lpr, 1))
        self.connect(self.resample_right, (self.audio_lmr, 1))

        # low-pass filter for L+R
        audio_lpr_taps = gr.firdes.low_pass(
            0.5,  # gain
            usrp_rate,  # sampling rate
            15e3,  # passband cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.audio_lpr_filter = gr.fir_filter_fff(1, audio_lpr_taps)
        self.connect(self.audio_lpr, self.audio_lpr_filter)

        # create pilot tone at 19 kHz
        self.pilot = gr.sig_source_f(
            usrp_rate,  # sampling rate
            gr.GR_SIN_WAVE,  # waveform
            19e3,  # frequency
            5e-2)  # amplitude

        # upconvert L-R to 38 kHz and band-pass
        self.mix_stereo = gr.multiply_ff()
        audio_lmr_taps = gr.firdes.band_pass(
            80,  # gain
            usrp_rate,  # sampling rate
            38e3 - 15e3,  # low cutoff
            38e3 + 15e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.audio_lmr_filter = gr.fir_filter_fff(1, audio_lmr_taps)
        self.connect(self.audio_lmr, (self.mix_stereo, 0))
        self.connect(self.pilot, (self.mix_stereo, 1))
        self.connect(self.pilot, (self.mix_stereo, 2))
        self.connect(self.mix_stereo, self.audio_lmr_filter)

        # create RDS bitstream
        # diff-encode, manchester-emcode, NRZ
        # enforce the 1187.5bps rate
        # pulse shaping filter (matched with receiver)
        # mix with 57kHz carrier (equivalent to BPSK)
        self.rds_enc = rds.data_encoder('rds_data.xml')
        self.diff_enc = gr.diff_encoder_bb(2)
        self.manchester1 = gr.map_bb([1, 2])
        self.manchester2 = gr.unpack_k_bits_bb(2)
        self.nrz = gr.map_bb([-1, 1])
        self.c2f = gr.char_to_float()
        self.rate_enforcer = rds.rate_enforcer(usrp_rate)
        pulse_shaping_taps = gr.firdes.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.pulse_shaping = gr.fir_filter_fff(1, pulse_shaping_taps)
        self.bpsk_mod = gr.multiply_ff()
        self.connect (self.rds_enc, self.diff_enc, self.manchester1, \
         self.manchester2, self.nrz, self.c2f)
        self.connect(self.c2f, (self.rate_enforcer, 0))
        self.connect(self.pilot, (self.rate_enforcer, 1))
        self.connect(self.rate_enforcer, (self.bpsk_mod, 0))
        self.connect(self.pilot, (self.bpsk_mod, 1))
        self.connect(self.pilot, (self.bpsk_mod, 2))
        self.connect(self.pilot, (self.bpsk_mod, 3))

        # RDS band-pass filter
        rds_filter_taps = gr.firdes.band_pass(
            50,  # gain
            usrp_rate,  # sampling rate
            57e3 - 3e3,  # low cutoff
            57e3 + 3e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_taps)
        self.connect(self.bpsk_mod, self.rds_filter)

        # mix L+R, pilot, L-R and RDS
        self.mixer = gr.add_ff()
        self.connect(self.audio_lpr_filter, (self.mixer, 0))
        self.connect(self.pilot, (self.mixer, 1))
        self.connect(self.audio_lmr_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # fm modulation, gain & TX
        max_dev = 75e3
        k = 2 * math.pi * max_dev / usrp_rate  # modulator sensitivity
        self.modulator = gr.frequency_modulator_fc(k)
        self.gain = gr.multiply_const_cc(5e3)
        self.connect(self.mixer, self.modulator, self.gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            self.fft = fftsink2.fft_sink_f(panel,
                                           title="Pre FM modulation",
                                           fft_size=512 * 4,
                                           sample_rate=usrp_rate,
                                           y_per_div=20,
                                           ref_level=-20)
            self.connect(self.mixer, self.fft)
            vbox.Add(self.fft.win, 1, wx.EXPAND)
        if 0:
            self.scope = scopesink2.scope_sink_f(panel,
                                                 title="RDS encoder output",
                                                 sample_rate=usrp_rate)
            self.connect(self.rds_enc, self.scope)
            vbox.Add(self.scope.win, 1, wx.EXPAND)
示例#18
0
文件: dqpsk2.py 项目: jinjoh/SDR
    def __init__(self, 
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 costas_alpha=_def_costas_alpha,
                 timing_alpha=_def_timing_alpha,
                 timing_max_dev=_def_timing_max_dev,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered DQPSK demodulation

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

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param costas_alpha: loop filter gain
        @type costas_alphas: float
        @param timing_alpha: timing loop alpha gain
        @type timing_alpha: float
        @param timing_max: timing loop maximum rate deviations
        @type timing_max: 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_demod",
			        gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
			        gr.io_signature(1, 1, gr.sizeof_char))       # Output signature

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._costas_alpha = costas_alpha
        self._timing_alpha = timing_alpha
        self._timing_beta = _def_timing_beta
        self._timing_max_dev=timing_max_dev
        self._gray_code = gray_code

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

        arity = pow(2,self.bits_per_symbol())
 
        # Automatic gain control
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        #self.agc = gr.feedforward_agc_cc(16, 2.0)

        self._costas_beta  = 0.25 * self._costas_alpha * self._costas_alpha
        # Allow a frequency swing of +/- half of the sample rate
        fmin = -0.5
        fmax = 0.5

        self.clock_recov = gr.costas_loop_cc(self._costas_alpha,
                                             self._costas_beta,
                                             fmax, fmin, arity)

        # symbol timing recovery with RRC data filter
        nfilts = 32
        ntaps = 11 * samples_per_symbol*nfilts
        taps = gr.firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(self._samples_per_symbol), self._excess_bw, ntaps)
        self.time_recov = gr.pfb_clock_sync_ccf(self._samples_per_symbol,
                                                self._timing_alpha,
                                                taps, nfilts, nfilts/2, self._timing_max_dev)
        self.time_recov.set_beta(self._timing_beta)
        
        # Perform Differential decoding on the constellation
        self.diffdec = gr.diff_phasor_cc()
        
        # find closest constellation point
        rot = 1
        rotated_const = map(lambda pt: pt * rot, psk.constellation[arity])
        self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity))

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity])
        else:
            self.symbol_mapper = gr.map_bb(psk.ungray_to_binary[arity])
        
        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()
        
        if log:
            self._setup_logging()
 
        # Connect
        self.connect(self, self.agc, 
                     self.clock_recov,
                     self.time_recov,
                     self.diffdec, self.slicer, self.symbol_mapper, self.unpack, self)
示例#19
0
    def __init__(self,
                 vlen_in=1,
                 vlen_out=1,
                 n_tailbits=6,
                 denom_mother_code_rate=6,
                 gen_poly=(91, 121, 101, 91, 121, 101),
                 bits_per_symbol=0,
                 N=1,
                 map_tab=0,
                 pp_0=0,
                 pp_0_tail=0,
                 pp_1=0,
                 pp_1_tail=0,
                 part_len_top=1,
                 part_len_bot=1,
                 M_total=0,
                 interl_seq_0_2=range(2),
                 interl_seq_1_2=range(2)):
        gr.hier_block2.__init__(
            self,
            "DRM MLC 16-QAM",
            gr.io_signature(1, 1, gr.sizeof_char * vlen_in),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen_out),
        )

        ##################################################
        # Parameters
        ##################################################
        self.vlen_in = vlen_in
        self.vlen_out = vlen_out
        self.n_tailbits = n_tailbits
        self.denom_mother_code_rate = denom_mother_code_rate
        self.gen_poly = gen_poly
        self.bits_per_symbol = bits_per_symbol
        self.N = N
        self.map_tab = map_tab
        self.pp_0 = pp_0
        self.pp_0_tail = pp_0_tail
        self.pp_1 = pp_1
        self.pp_1_tail = pp_1_tail
        self.part_len_top = part_len_top
        self.part_len_bot = part_len_bot
        self.M_total = M_total
        self.interl_seq_0_2 = interl_seq_0_2
        self.interl_seq_1_2 = interl_seq_1_2

        ##################################################
        # Blocks
        ##################################################
        self.trellis_encoder_xx_0_0 = trellis.encoder_bb(
            trellis.fsm(1, denom_mother_code_rate, gen_poly), 0)
        self.trellis_encoder_xx_0 = trellis.encoder_bb(
            trellis.fsm(1, denom_mother_code_rate, gen_poly), 0)
        self.gr_vector_to_stream_1_0 = gr.vector_to_stream(
            gr.sizeof_char * 1, part_len_bot + n_tailbits)
        self.gr_vector_to_stream_1 = gr.vector_to_stream(
            gr.sizeof_char * 1, part_len_top + n_tailbits)
        self.gr_unpack_k_bits_bb_0_0 = gr.unpack_k_bits_bb(
            denom_mother_code_rate)
        self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(
            denom_mother_code_rate)
        self.gr_stream_to_vector_0_0 = gr.stream_to_vector(
            gr.sizeof_char * 1,
            (part_len_bot + n_tailbits) * denom_mother_code_rate)
        self.gr_stream_to_vector_0 = gr.stream_to_vector(
            gr.sizeof_char * 1,
            (part_len_top + n_tailbits) * denom_mother_code_rate)
        self.drm_qam_map_vbvb_0 = drm.qam_map_vbvb(map_tab, bits_per_symbol,
                                                   vlen_out, 2)
        self.drm_punct_vbvb_0_0 = drm.punct_vbvb(
            pp_1, pp_1_tail,
            (part_len_bot + n_tailbits) * denom_mother_code_rate, vlen_out * 2,
            n_tailbits * denom_mother_code_rate)
        self.drm_punct_vbvb_0 = drm.punct_vbvb(
            pp_0, pp_0_tail,
            (part_len_top + n_tailbits) * denom_mother_code_rate, vlen_out * 2,
            n_tailbits * denom_mother_code_rate)
        self.drm_partitioning_16_vbvb_0 = drm.partitioning_vbvb(
            vlen_in, M_total)
        self.drm_interleaver_vbvb_0_0 = drm.interleaver_vbvb((interl_seq_1_2))
        self.drm_interleaver_vbvb_0 = drm.interleaver_vbvb((interl_seq_0_2))
        self.add_tailbits_vbvb_0_0 = drm.add_tailbits_vbvb(
            part_len_bot, n_tailbits)
        self.add_tailbits_vbvb_0 = drm.add_tailbits_vbvb(
            part_len_top, n_tailbits)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.drm_interleaver_vbvb_0, 0),
                     (self.drm_qam_map_vbvb_0, 0))
        self.connect((self.drm_qam_map_vbvb_0, 0), (self, 0))
        self.connect((self.trellis_encoder_xx_0, 0),
                     (self.gr_unpack_k_bits_bb_0, 0))
        self.connect((self.gr_stream_to_vector_0, 0),
                     (self.drm_punct_vbvb_0, 0))
        self.connect((self.gr_unpack_k_bits_bb_0, 0),
                     (self.gr_stream_to_vector_0, 0))
        self.connect((self.drm_punct_vbvb_0, 0),
                     (self.drm_interleaver_vbvb_0, 0))
        self.connect((self.trellis_encoder_xx_0_0, 0),
                     (self.gr_unpack_k_bits_bb_0_0, 0))
        self.connect((self.gr_stream_to_vector_0_0, 0),
                     (self.drm_punct_vbvb_0_0, 0))
        self.connect((self.gr_unpack_k_bits_bb_0_0, 0),
                     (self.gr_stream_to_vector_0_0, 0))
        self.connect((self.drm_punct_vbvb_0_0, 0),
                     (self.drm_interleaver_vbvb_0_0, 0))
        self.connect((self.drm_interleaver_vbvb_0_0, 0),
                     (self.drm_qam_map_vbvb_0, 1))
        self.connect((self.gr_vector_to_stream_1, 0),
                     (self.trellis_encoder_xx_0, 0))
        self.connect((self.gr_vector_to_stream_1_0, 0),
                     (self.trellis_encoder_xx_0_0, 0))
        self.connect((self, 0), (self.drm_partitioning_16_vbvb_0, 0))
        self.connect((self.add_tailbits_vbvb_0, 0),
                     (self.gr_vector_to_stream_1, 0))
        self.connect((self.add_tailbits_vbvb_0_0, 0),
                     (self.gr_vector_to_stream_1_0, 0))
        self.connect((self.drm_partitioning_16_vbvb_0, 1),
                     (self.add_tailbits_vbvb_0_0, 0))
        self.connect((self.drm_partitioning_16_vbvb_0, 0),
                     (self.add_tailbits_vbvb_0, 0))
示例#20
0
文件: rds_tx.py 项目: Shmuma/gr-rds
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Rds Tx")
        _icon_path = "/home/azimout/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.usrp_interp = usrp_interp = 500
        self.dac_rate = dac_rate = 128e6
        self.wav_rate = wav_rate = 44100
        self.usrp_rate = usrp_rate = int(dac_rate / usrp_interp)
        self.fm_max_dev = fm_max_dev = 120e3

        ##################################################
        # Blocks
        ##################################################
        self.band_pass_filter_0 = gr.interp_fir_filter_fff(
            1,
            firdes.band_pass(1, usrp_rate, 54e3, 60e3, 3e3, firdes.WIN_HAMMING,
                             6.76))
        self.band_pass_filter_1 = gr.interp_fir_filter_fff(
            1,
            firdes.band_pass(1, usrp_rate, 23e3, 53e3, 2e3, firdes.WIN_HAMMING,
                             6.76))
        self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_fff(
            interpolation=usrp_rate,
            decimation=wav_rate,
            taps=None,
            fractional_bw=None,
        )
        self.blks2_rational_resampler_xxx_1_0 = blks2.rational_resampler_fff(
            interpolation=usrp_rate,
            decimation=wav_rate,
            taps=None,
            fractional_bw=None,
        )
        self.gr_add_xx_0 = gr.add_vff(1)
        self.gr_add_xx_1 = gr.add_vff(1)
        self.gr_char_to_float_0 = gr.char_to_float()
        self.gr_diff_encoder_bb_0 = gr.diff_encoder_bb(2)
        self.gr_frequency_modulator_fc_0 = gr.frequency_modulator_fc(
            2 * math.pi * fm_max_dev / usrp_rate)
        self.gr_map_bb_0 = gr.map_bb(([-1, 1]))
        self.gr_map_bb_1 = gr.map_bb(([1, 2]))
        self.gr_multiply_xx_0 = gr.multiply_vff(1)
        self.gr_multiply_xx_1 = gr.multiply_vff(1)
        self.gr_rds_data_encoder_0 = rds.data_encoder(
            "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/test/rds_data.xml"
        )
        self.gr_rds_rate_enforcer_0 = rds.rate_enforcer(256000)
        self.gr_sig_source_x_0 = gr.sig_source_f(usrp_rate, gr.GR_COS_WAVE,
                                                 19e3, 0.3, 0)
        self.gr_sub_xx_0 = gr.sub_ff(1)
        self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(2)
        self.gr_wavfile_source_0 = gr.wavfile_source(
            "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/python/limmenso_stereo.wav",
            True)
        self.low_pass_filter_0 = gr.interp_fir_filter_fff(
            1,
            firdes.low_pass(1, usrp_rate, 1.5e3, 2e3, firdes.WIN_HAMMING,
                            6.76))
        self.low_pass_filter_0_0 = gr.interp_fir_filter_fff(
            1,
            firdes.low_pass(1, usrp_rate, 15e3, 2e3, firdes.WIN_HAMMING, 6.76))
        self.usrp_simple_sink_x_0 = grc_usrp.simple_sink_c(which=0, side="A")
        self.usrp_simple_sink_x_0.set_interp_rate(500)
        self.usrp_simple_sink_x_0.set_frequency(107.2e6, verbose=True)
        self.usrp_simple_sink_x_0.set_gain(0)
        self.usrp_simple_sink_x_0.set_enable(True)
        self.usrp_simple_sink_x_0.set_auto_tr(True)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
            self.GetWin(),
            baseband_freq=0,
            y_per_div=20,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=usrp_rate,
            fft_size=1024,
            fft_rate=30,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_sig_source_x_0, 0),
                     (self.gr_rds_rate_enforcer_0, 1))
        self.connect((self.gr_char_to_float_0, 0),
                     (self.gr_rds_rate_enforcer_0, 0))
        self.connect((self.gr_map_bb_0, 0), (self.gr_char_to_float_0, 0))
        self.connect((self.gr_frequency_modulator_fc_0, 0),
                     (self.usrp_simple_sink_x_0, 0))
        self.connect((self.gr_add_xx_1, 0),
                     (self.gr_frequency_modulator_fc_0, 0))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_add_xx_1, 1))
        self.connect((self.gr_sub_xx_0, 0), (self.gr_multiply_xx_1, 2))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_1, 1))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_1, 0))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 3))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 2))
        self.connect((self.blks2_rational_resampler_xxx_1_0, 0),
                     (self.gr_add_xx_0, 1))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.gr_add_xx_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_1_0, 0),
                     (self.gr_sub_xx_0, 1))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.gr_sub_xx_0, 0))
        self.connect((self.gr_wavfile_source_0, 1),
                     (self.blks2_rational_resampler_xxx_1_0, 0))
        self.connect((self.gr_wavfile_source_0, 0),
                     (self.blks2_rational_resampler_xxx_1, 0))
        self.connect((self.gr_rds_data_encoder_0, 0),
                     (self.gr_diff_encoder_bb_0, 0))
        self.connect((self.gr_diff_encoder_bb_0, 0), (self.gr_map_bb_1, 0))
        self.connect((self.gr_map_bb_1, 0), (self.gr_unpack_k_bits_bb_0, 0))
        self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_map_bb_0, 0))
        self.connect((self.gr_rds_rate_enforcer_0, 0),
                     (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.gr_multiply_xx_0, 0))
        self.connect((self.gr_multiply_xx_0, 0), (self.band_pass_filter_0, 0))
        self.connect((self.band_pass_filter_0, 0), (self.gr_add_xx_1, 0))
        self.connect((self.gr_multiply_xx_1, 0), (self.band_pass_filter_1, 0))
        self.connect((self.band_pass_filter_1, 0), (self.gr_add_xx_1, 3))
        self.connect((self.gr_add_xx_1, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 1))
        self.connect((self.gr_add_xx_0, 0), (self.low_pass_filter_0_0, 0))
        self.connect((self.low_pass_filter_0_0, 0), (self.gr_add_xx_1, 2))
示例#21
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        # Read in successfully decoded live data from Matlab
        linf=open('/home/demel/exchange/matlab_d.txt')
        lintu=range(120)
        for i in lintu:
            lintu[i]=float(linf.readline())
        #print lintu
        # source for live data
        self.srcl = gr.vector_source_f(lintu,False,120)
        
        # Read in .txt file with example MIB encoded + CRC checksum
        inf=open('/home/demel/exchange/crc.txt')
        self.intu=range(40)
        for i in self.intu:
            self.intu[i]=float(inf.readline())
                
        #inf=open('/home/demel/exchange/matlab_d.txt')
        #intu=range(120)
    	#for i in range(120):
    	#	intu[i]=float(inf.readline())
        
        # Source and conversions
        self.src  = gr.vector_source_f(self.intu,False,40)
        self.conv = gr.float_to_char(40,1)

        # Resize vector with repetition of last part
        # Vector to stream for encoder
        my_map1=range(46)
        for i in range(40):
            my_map1[i+6]=i
        for i in range(6):
            my_map1[i]=i+40
        self.map1 = lte.vector_resize_vbvb(my_map1,40,46)
        self.vtos = gr.vector_to_stream(1*gr.sizeof_char,46)
        
        # Encoding of input data
        self.fsm  = trellis.fsm(1,3,[91,121,117])
        self.enc  = trellis.encoder_bb(self.fsm,0)
        # unpack packed bits from encoder
        self.unp  = gr.unpack_k_bits_bb(3)
        # stream to vector
        self.stov = gr.stream_to_vector(1*gr.sizeof_char,138)
        # Remove first part which contains tail-biting init stuff
        map2 = range(120)
        for i in map2:
            map2[i]= i+18
        self.map2 = lte.vector_resize_vbvb(map2,138,120)
        # conversion from char to float to match input of decoder
        self.conv2= gr.char_to_float(120,1)
        
        
        ###############################################
        # From here on only "receiver side" processing
        ###############################################
        
        # like QPSK demodulation: NRZ coding.
        vec2=range(120)
        for i in vec2:
            vec2[i]=float(-2.0)
        self.mult = gr.multiply_const_vff(vec2)
        vec=range(120)
        for i in vec:
            vec[i]=1
        self.add  = gr.add_const_vff(vec)
        
        # this is the actual unit under test
        self.vit = lte.viterbi_vfvb()
        
        # Sinks
        self.snk = gr.vector_sink_b(40)
        self.snk2 = gr.vector_sink_f(120)
        
        # connecting blocks
        self.tb.connect(self.src,self.conv,self.map1,self.vtos,self.enc,self.unp)
        self.tb.connect(self.unp,self.stov,self.map2,self.conv2)
        self.tb.connect(self.conv2,self.mult,self.add)
        self.tb.connect(self.srcl,self.vit,self.snk)
        self.tb.connect(self.add,self.snk2)
    def __init__(self, fg,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 costas_alpha=_def_costas_alpha,
                 gain_mu=_def_gain_mu,
                 mu=_def_mu,
                 omega_relative_limit=_def_omega_relative_limit,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered DQPSK demodulation

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

	@param fg: flow graph
	@type fg: flow graph
	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param costas_alpha: loop filter gain
        @type costas_alphas: float
        @param gain_mu: for M&M block
        @type gain_mu: float
        @param mu: for M&M block
        @type mu: float
        @param omega_relative_limit: for M&M block
        @type omega_relative_limit: 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
	"""

        self._fg = fg
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._costas_alpha = costas_alpha
        self._mm_gain_mu = gain_mu
        self._mm_mu = mu
        self._mm_omega_relative_limit = omega_relative_limit
        self._gray_code = gray_code

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

        arity = pow(2,self.bits_per_symbol())
 
        # Automatic gain control
        scale = (1.0/16384.0)
        self.pre_scaler = gr.multiply_const_cc(scale)   # scale the signal from full-range to +-1
        #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        self.agc = gr.feedforward_agc_cc(16, 2.0)
       
        # RRC data filter
        ntaps = 11 * samples_per_symbol
        self.rrc_taps = gr.firdes.root_raised_cosine(
            1.0,                      # gain
            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(1, self.rrc_taps)        

        if not self._mm_gain_mu:
            sbs_to_mm = {2: 0.050, 3: 0.075, 4: 0.11, 5: 0.125, 6: 0.15, 7: 0.15}
            self._mm_gain_mu = sbs_to_mm[samples_per_symbol]

        self._mm_omega = self._samples_per_symbol
        self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu
        self._costas_beta  = 0.25 * self._costas_alpha * self._costas_alpha
        fmin = -0.025
        fmax = 0.025
        
        self.receiver=gr.mpsk_receiver_cc(arity, pi/4.0,
                                          self._costas_alpha, self._costas_beta,
                                          fmin, fmax,
                                          self._mm_mu, self._mm_gain_mu,
                                          self._mm_omega, self._mm_gain_omega,
                                          self._mm_omega_relative_limit)

        # Perform Differential decoding on the constellation
        self.diffdec = gr.diff_phasor_cc()
        
        # find closest constellation point
        rot = 1
        rotated_const = map(lambda pt: pt * rot, psk.constellation[arity])
        self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity))

        if self._gray_code:
            self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity])
        else:
            self.symbol_mapper = gr.map_bb(psk.ungray_to_binary[arity])
        
        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()
        
        if log:
            self._setup_logging()
 
        # Connect & Initialize base class
        self._fg.connect(self.pre_scaler, self.agc, self.rrc_filter, self.receiver,
                         self.diffdec, self.slicer, self.symbol_mapper, self.unpack)
        gr.hier_block.__init__(self, self._fg, self.pre_scaler, self.unpack)
示例#23
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Rds Tx")
		_icon_path = "/home/azimout/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.usrp_interp = usrp_interp = 500
		self.dac_rate = dac_rate = 128e6
		self.wav_rate = wav_rate = 44100
		self.usrp_rate = usrp_rate = int(dac_rate/usrp_interp)
		self.fm_max_dev = fm_max_dev = 120e3

		##################################################
		# Blocks
		##################################################
		self.band_pass_filter_0 = gr.interp_fir_filter_fff(1, firdes.band_pass(
			1, usrp_rate, 54e3, 60e3, 3e3, firdes.WIN_HAMMING, 6.76))
		self.band_pass_filter_1 = gr.interp_fir_filter_fff(1, firdes.band_pass(
			1, usrp_rate, 23e3, 53e3, 2e3, firdes.WIN_HAMMING, 6.76))
		self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_fff(
			interpolation=usrp_rate,
			decimation=wav_rate,
			taps=None,
			fractional_bw=None,
		)
		self.blks2_rational_resampler_xxx_1_0 = blks2.rational_resampler_fff(
			interpolation=usrp_rate,
			decimation=wav_rate,
			taps=None,
			fractional_bw=None,
		)
		self.gr_add_xx_0 = gr.add_vff(1)
		self.gr_add_xx_1 = gr.add_vff(1)
		self.gr_char_to_float_0 = gr.char_to_float()
		self.gr_diff_encoder_bb_0 = gr.diff_encoder_bb(2)
		self.gr_frequency_modulator_fc_0 = gr.frequency_modulator_fc(2*math.pi*fm_max_dev/usrp_rate)
		self.gr_map_bb_0 = gr.map_bb(([-1,1]))
		self.gr_map_bb_1 = gr.map_bb(([1,2]))
		self.gr_multiply_xx_0 = gr.multiply_vff(1)
		self.gr_multiply_xx_1 = gr.multiply_vff(1)
		self.gr_rds_data_encoder_0 = rds.data_encoder("/media/dimitris/mywork/gr/dimitris/rds/trunk/src/test/rds_data.xml")
		self.gr_rds_rate_enforcer_0 = rds.rate_enforcer(256000)
		self.gr_sig_source_x_0 = gr.sig_source_f(usrp_rate, gr.GR_COS_WAVE, 19e3, 0.3, 0)
		self.gr_sub_xx_0 = gr.sub_ff(1)
		self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(2)
		self.gr_wavfile_source_0 = gr.wavfile_source("/media/dimitris/mywork/gr/dimitris/rds/trunk/src/python/limmenso_stereo.wav", True)
		self.low_pass_filter_0 = gr.interp_fir_filter_fff(1, firdes.low_pass(
			1, usrp_rate, 1.5e3, 2e3, firdes.WIN_HAMMING, 6.76))
		self.low_pass_filter_0_0 = gr.interp_fir_filter_fff(1, firdes.low_pass(
			1, usrp_rate, 15e3, 2e3, firdes.WIN_HAMMING, 6.76))
		self.usrp_simple_sink_x_0 = grc_usrp.simple_sink_c(which=0, side="A")
		self.usrp_simple_sink_x_0.set_interp_rate(500)
		self.usrp_simple_sink_x_0.set_frequency(107.2e6, verbose=True)
		self.usrp_simple_sink_x_0.set_gain(0)
		self.usrp_simple_sink_x_0.set_enable(True)
		self.usrp_simple_sink_x_0.set_auto_tr(True)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
			self.GetWin(),
			baseband_freq=0,
			y_per_div=20,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=usrp_rate,
			fft_size=1024,
			fft_rate=30,
			average=False,
			avg_alpha=None,
			title="FFT Plot",
			peak_hold=False,
		)
		self.Add(self.wxgui_fftsink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_rds_rate_enforcer_0, 1))
		self.connect((self.gr_char_to_float_0, 0), (self.gr_rds_rate_enforcer_0, 0))
		self.connect((self.gr_map_bb_0, 0), (self.gr_char_to_float_0, 0))
		self.connect((self.gr_frequency_modulator_fc_0, 0), (self.usrp_simple_sink_x_0, 0))
		self.connect((self.gr_add_xx_1, 0), (self.gr_frequency_modulator_fc_0, 0))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_add_xx_1, 1))
		self.connect((self.gr_sub_xx_0, 0), (self.gr_multiply_xx_1, 2))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_1, 1))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_1, 0))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 3))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 2))
		self.connect((self.blks2_rational_resampler_xxx_1_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_add_xx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_1_0, 0), (self.gr_sub_xx_0, 1))
		self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_sub_xx_0, 0))
		self.connect((self.gr_wavfile_source_0, 1), (self.blks2_rational_resampler_xxx_1_0, 0))
		self.connect((self.gr_wavfile_source_0, 0), (self.blks2_rational_resampler_xxx_1, 0))
		self.connect((self.gr_rds_data_encoder_0, 0), (self.gr_diff_encoder_bb_0, 0))
		self.connect((self.gr_diff_encoder_bb_0, 0), (self.gr_map_bb_1, 0))
		self.connect((self.gr_map_bb_1, 0), (self.gr_unpack_k_bits_bb_0, 0))
		self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_map_bb_0, 0))
		self.connect((self.gr_rds_rate_enforcer_0, 0), (self.low_pass_filter_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.gr_multiply_xx_0, 0))
		self.connect((self.gr_multiply_xx_0, 0), (self.band_pass_filter_0, 0))
		self.connect((self.band_pass_filter_0, 0), (self.gr_add_xx_1, 0))
		self.connect((self.gr_multiply_xx_1, 0), (self.band_pass_filter_1, 0))
		self.connect((self.band_pass_filter_1, 0), (self.gr_add_xx_1, 3))
		self.connect((self.gr_add_xx_1, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 1))
		self.connect((self.gr_add_xx_0, 0), (self.low_pass_filter_0_0, 0))
		self.connect((self.low_pass_filter_0_0, 0), (self.gr_add_xx_1, 2))
示例#24
0
    def __init__(self):
        gr.top_block.__init__(self, "Simple QAM Simulation")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Simple QAM Simulation")
        self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

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

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

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_vector_source_x_0, 0),
                     (self.digital_scrambler_bb_0, 0))
        self.connect((self.digital_scrambler_bb_0, 0),
                     (self.gr_pack_k_bits_bb_0, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_constellation_receiver_cb_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.digital_constellation_receiver_cb_0, 0),
                     (self.gr_unpack_k_bits_bb_0, 0))
        self.connect((self.gr_unpack_k_bits_bb_0, 0),
                     (self.gr_descrambler_bb_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0), (self.gr_null_sink_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.digital_constellation_receiver_cb_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0),
                     (self.gr_char_to_float_0, 0))
        self.connect((self.gr_char_to_float_0, 0),
                     (self.qtgui_sink_x_0_0_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.gr_multiply_const_vxx_0_0, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.gr_file_sink_0_1, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.qtgui_sink_x_0_1, 0))
        self.connect((self.gr_char_to_float_1, 0),
                     (self.qtgui_sink_x_0_1_0, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0),
                     (self.gr_char_to_float_1, 0))
        self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_file_sink_0, 0))
        self.connect((self.gr_char_to_float_1_0, 0),
                     (self.qtgui_sink_x_0_1_0_0, 0))
        self.connect((self.gr_vector_source_x_0, 0),
                     (self.gr_char_to_float_1_0, 0))
        self.connect((self.gr_multiply_const_vxx_0_0, 0),
                     (self.gr_add_xx_0, 0))
        self.connect((self.gr_add_xx_0, 0), (self.qtgui_sink_x_0_0, 0))
        self.connect((self.gr_throttle_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_0_1_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.qtgui_sink_x_0_0_0_0, 0))
        self.connect((self.gr_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blks2_error_rate_0, 0), (self.gr_nlog10_ff_0, 0))
        self.connect((self.gr_vector_source_x_0_0, 0),
                     (self.blks2_error_rate_0, 0))
        self.connect((self.gr_descrambler_bb_0, 0),
                     (self.blks2_error_rate_0, 1))
示例#25
0
	def __init__(self):
		gr.top_block.__init__(self, "Simple QAM Simulation")
		Qt.QWidget.__init__(self)
		self.setWindowTitle("Simple QAM Simulation")
		self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
		self.top_scroll_layout = Qt.QVBoxLayout()
		self.setLayout(self.top_scroll_layout)
		self.top_scroll = Qt.QScrollArea()
		self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
		self.top_scroll_layout.addWidget(self.top_scroll)
		self.top_scroll.setWidgetResizable(True)
		self.top_widget = Qt.QWidget()
		self.top_scroll.setWidget(self.top_widget)
		self.top_layout = Qt.QVBoxLayout(self.top_widget)
		self.top_grid_layout = Qt.QGridLayout()
		self.top_layout.addLayout(self.top_grid_layout)


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

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

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_vector_source_x_0, 0), (self.digital_scrambler_bb_0, 0))
		self.connect((self.digital_scrambler_bb_0, 0), (self.gr_pack_k_bits_bb_0, 0))
		self.connect((self.gr_pack_k_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
		self.connect((self.digital_constellation_receiver_cb_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.digital_constellation_receiver_cb_0, 0), (self.gr_unpack_k_bits_bb_0, 0))
		self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_descrambler_bb_0, 0))
		self.connect((self.gr_descrambler_bb_0, 0), (self.gr_null_sink_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.digital_constellation_receiver_cb_0, 0))
		self.connect((self.gr_descrambler_bb_0, 0), (self.gr_char_to_float_0, 0))
		self.connect((self.gr_char_to_float_0, 0), (self.qtgui_sink_x_0_0_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_file_sink_0_1, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.qtgui_sink_x_0_1, 0))
		self.connect((self.gr_char_to_float_1, 0), (self.qtgui_sink_x_0_1_0, 0))
		self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_char_to_float_1, 0))
		self.connect((self.gr_pack_k_bits_bb_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_char_to_float_1_0, 0), (self.qtgui_sink_x_0_1_0_0, 0))
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_char_to_float_1_0, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.gr_add_xx_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.qtgui_sink_x_0_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_0_1_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.qtgui_sink_x_0_0_0_0, 0))
		self.connect((self.gr_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0))
		self.connect((self.blks2_error_rate_0, 0), (self.gr_nlog10_ff_0, 0))
		self.connect((self.gr_vector_source_x_0_0, 0), (self.blks2_error_rate_0, 0))
		self.connect((self.gr_descrambler_bb_0, 0), (self.blks2_error_rate_0, 1))
示例#26
0
    def __init__(self,
                 samples_per_symbol=_def_samples_per_symbol,
                 excess_bw=_def_excess_bw,
                 costas_alpha=_def_costas_alpha,
                 gain_mu=_def_gain_mu,
                 mu=_def_mu,
                 omega_relative_limit=_def_omega_relative_limit,
                 gray_code=_def_gray_code,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered DQPSK demodulation

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

	@param samples_per_symbol: samples per symbol >= 2
	@type samples_per_symbol: float
	@param excess_bw: Root-raised cosine filter excess bandwidth
	@type excess_bw: float
        @param costas_alpha: loop filter gain
        @type costas_alphas: float
        @param gain_mu: for M&M block
        @type gain_mu: float
        @param mu: for M&M block
        @type mu: float
        @param omega_relative_limit: for M&M block
        @type omega_relative_limit: 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,
            "dqpsk_demod",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))  # Output signature

        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._costas_alpha = costas_alpha
        self._mm_gain_mu = gain_mu
        self._mm_mu = mu
        self._mm_omega_relative_limit = omega_relative_limit
        self._gray_code = gray_code

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

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

        # Automatic gain control
        scale = (1.0 / 16384.0)
        self.pre_scaler = gr.multiply_const_cc(
            scale)  # scale the signal from full-range to +-1
        #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        self.agc = gr.feedforward_agc_cc(16, 2.0)

        # RRC data filter
        ntaps = 11 * samples_per_symbol
        self.rrc_taps = gr.firdes.root_raised_cosine(
            1.0,  # gain
            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(1, self.rrc_taps)

        if not self._mm_gain_mu:
            sbs_to_mm = {
                2: 0.050,
                3: 0.075,
                4: 0.11,
                5: 0.125,
                6: 0.15,
                7: 0.15
            }
            self._mm_gain_mu = sbs_to_mm[samples_per_symbol]

        self._mm_omega = self._samples_per_symbol
        self._mm_gain_omega = .25 * self._mm_gain_mu * self._mm_gain_mu
        self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha
        fmin = -0.25
        fmax = 0.25

        self.receiver = gr.mpsk_receiver_cc(
            arity, pi / 4.0, self._costas_alpha, self._costas_beta, fmin, fmax,
            self._mm_mu, self._mm_gain_mu, self._mm_omega, self._mm_gain_omega,
            self._mm_omega_relative_limit)

        # Perform Differential decoding on the constellation
        self.diffdec = gr.diff_phasor_cc()

        # find closest constellation point
        rot = 1
        rotated_const = map(lambda pt: pt * rot, psk.constellation[arity])
        self.slicer = gr.constellation_decoder_cb(rotated_const, range(arity))

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

        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

        # Connect & Initialize base class
        self.connect(self, self.pre_scaler, self.agc, self.rrc_filter,
                     self.receiver, self.diffdec, self.slicer,
                     self.symbol_mapper, self.unpack, self)
示例#27
0
    def __init__(self, frame, panel, vbox, argv):
        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(
            "-f",
            "--freq",
            type="eng_float",
            default=107.2e6,
            help="set Tx frequency to FREQ [required]",
            metavar="FREQ",
        )
        parser.add_option("--wavfile", type="string", default=None, help="open .wav audio file FILE")
        parser.add_option("--xml", type="string", default="rds_data.xml", help="open .xml RDS data FILE")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        usrp_interp = 500
        self.u = usrp.sink_c(0, usrp_interp)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.dac_rate() / usrp_interp  # 256 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)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        # set max Tx gain, tune frequency and enable transmitter
        gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(gain)
        print "Gain set to", gain
        if self.u.tune(self.subdev.which(), self.subdev, options.freq):
            print "Tuned to", options.freq / 1e6, "MHz"
        else:
            sys.exit(1)
        self.subdev.set_enable(True)

        # open wav file containing floats in the [-1, 1] range, repeat
        if options.wavfile is None:
            print "Please provide a wavfile to transmit! Exiting\n"
            sys.exit(1)
        self.src = gr.wavfile_source(options.wavfile, True)
        nchans = self.src.channels()
        sample_rate = self.src.sample_rate()
        bits_per_sample = self.src.bits_per_sample()
        print nchans, "channels,", sample_rate, "samples/sec,", bits_per_sample, "bits/sample"

        # resample to usrp rate
        self.resample_left = blks2.rational_resampler_fff(usrp_rate, sample_rate)
        self.resample_right = blks2.rational_resampler_fff(usrp_rate, sample_rate)
        self.connect((self.src, 0), self.resample_left)
        self.connect((self.src, 1), self.resample_right)

        # create L+R (mono) and L-R (stereo)
        self.audio_lpr = gr.add_ff()
        self.audio_lmr = gr.sub_ff()
        self.connect(self.resample_left, (self.audio_lpr, 0))
        self.connect(self.resample_left, (self.audio_lmr, 0))
        self.connect(self.resample_right, (self.audio_lpr, 1))
        self.connect(self.resample_right, (self.audio_lmr, 1))

        # low-pass filter for L+R
        audio_lpr_taps = gr.firdes.low_pass(
            0.5,  # gain
            usrp_rate,  # sampling rate
            15e3,  # passband cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.audio_lpr_filter = gr.fir_filter_fff(1, audio_lpr_taps)
        self.connect(self.audio_lpr, self.audio_lpr_filter)

        # create pilot tone at 19 kHz
        self.pilot = gr.sig_source_f(
            usrp_rate, gr.GR_SIN_WAVE, 19e3, 5e-2  # sampling rate  # waveform  # frequency
        )  # amplitude

        # upconvert L-R to 38 kHz and band-pass
        self.mix_stereo = gr.multiply_ff()
        audio_lmr_taps = gr.firdes.band_pass(
            80,  # gain
            usrp_rate,  # sampling rate
            38e3 - 15e3,  # low cutoff
            38e3 + 15e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.audio_lmr_filter = gr.fir_filter_fff(1, audio_lmr_taps)
        self.connect(self.audio_lmr, (self.mix_stereo, 0))
        self.connect(self.pilot, (self.mix_stereo, 1))
        self.connect(self.pilot, (self.mix_stereo, 2))
        self.connect(self.mix_stereo, self.audio_lmr_filter)

        # create RDS bitstream
        # diff-encode, manchester-emcode, NRZ
        # enforce the 1187.5bps rate
        # pulse shaping filter (matched with receiver)
        # mix with 57kHz carrier (equivalent to BPSK)
        self.rds_enc = rds.data_encoder("rds_data.xml")
        self.diff_enc = gr.diff_encoder_bb(2)
        self.manchester1 = gr.map_bb([1, 2])
        self.manchester2 = gr.unpack_k_bits_bb(2)
        self.nrz = gr.map_bb([-1, 1])
        self.c2f = gr.char_to_float()
        self.rate_enforcer = rds.rate_enforcer(usrp_rate)
        pulse_shaping_taps = gr.firdes.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.pulse_shaping = gr.fir_filter_fff(1, pulse_shaping_taps)
        self.bpsk_mod = gr.multiply_ff()
        self.connect(self.rds_enc, self.diff_enc, self.manchester1, self.manchester2, self.nrz, self.c2f)
        self.connect(self.c2f, (self.rate_enforcer, 0))
        self.connect(self.pilot, (self.rate_enforcer, 1))
        self.connect(self.rate_enforcer, (self.bpsk_mod, 0))
        self.connect(self.pilot, (self.bpsk_mod, 1))
        self.connect(self.pilot, (self.bpsk_mod, 2))
        self.connect(self.pilot, (self.bpsk_mod, 3))

        # RDS band-pass filter
        rds_filter_taps = gr.firdes.band_pass(
            50,  # gain
            usrp_rate,  # sampling rate
            57e3 - 3e3,  # low cutoff
            57e3 + 3e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_taps)
        self.connect(self.bpsk_mod, self.rds_filter)

        # mix L+R, pilot, L-R and RDS
        self.mixer = gr.add_ff()
        self.connect(self.audio_lpr_filter, (self.mixer, 0))
        self.connect(self.pilot, (self.mixer, 1))
        self.connect(self.audio_lmr_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # fm modulation, gain & TX
        max_dev = 75e3
        k = 2 * math.pi * max_dev / usrp_rate  # modulator sensitivity
        self.modulator = gr.frequency_modulator_fc(k)
        self.gain = gr.multiply_const_cc(5e3)
        self.connect(self.mixer, self.modulator, self.gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            self.fft = fftsink2.fft_sink_f(
                panel, title="Pre FM modulation", fft_size=512 * 4, sample_rate=usrp_rate, y_per_div=20, ref_level=-20
            )
            self.connect(self.mixer, self.fft)
            vbox.Add(self.fft.win, 1, wx.EXPAND)
        if 0:
            self.scope = scopesink2.scope_sink_f(panel, title="RDS encoder output", sample_rate=usrp_rate)
            self.connect(self.rds_enc, self.scope)
            vbox.Add(self.scope.win, 1, wx.EXPAND)
示例#28
0
	def __init__(self, vlen_in=1, vlen_out=1, n_tailbits=6, denom_mother_code_rate=6, gen_poly=(91, 121, 101, 91, 121, 101), bits_per_symbol=0, N=1, map_tab=0, pp_0=0, pp_0_tail=0, pp_1=0, pp_1_tail=0, part_len_top=1, part_len_bot=1, M_total=0, interl_seq_0_2=range(2), interl_seq_1_2=range(2)):
		gr.hier_block2.__init__(
			self, "DRM MLC 16-QAM",
			gr.io_signature(1, 1, gr.sizeof_char*vlen_in),
			gr.io_signature(1, 1, gr.sizeof_gr_complex*vlen_out),
		)

		##################################################
		# Parameters
		##################################################
		self.vlen_in = vlen_in
		self.vlen_out = vlen_out
		self.n_tailbits = n_tailbits
		self.denom_mother_code_rate = denom_mother_code_rate
		self.gen_poly = gen_poly
		self.bits_per_symbol = bits_per_symbol
		self.N = N
		self.map_tab = map_tab
		self.pp_0 = pp_0
		self.pp_0_tail = pp_0_tail
		self.pp_1 = pp_1
		self.pp_1_tail = pp_1_tail
		self.part_len_top = part_len_top
		self.part_len_bot = part_len_bot
		self.M_total = M_total
		self.interl_seq_0_2 = interl_seq_0_2
		self.interl_seq_1_2 = interl_seq_1_2

		##################################################
		# Blocks
		##################################################
		self.trellis_encoder_xx_0_0 = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0)
		self.trellis_encoder_xx_0 = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0)
		self.gr_vector_to_stream_1_0 = gr.vector_to_stream(gr.sizeof_char*1, part_len_bot+ n_tailbits)
		self.gr_vector_to_stream_1 = gr.vector_to_stream(gr.sizeof_char*1, part_len_top + n_tailbits)
		self.gr_unpack_k_bits_bb_0_0 = gr.unpack_k_bits_bb(denom_mother_code_rate)
		self.gr_unpack_k_bits_bb_0 = gr.unpack_k_bits_bb(denom_mother_code_rate)
		self.gr_stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_char*1, (part_len_bot + n_tailbits) * denom_mother_code_rate)
		self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_char*1, (part_len_top + n_tailbits) * denom_mother_code_rate)
		self.drm_qam_map_vbvc_0 = drm.qam_map_vbvc(map_tab, bits_per_symbol, vlen_out, 2)
		self.drm_punct_vbvb_0_0 = drm.punct_vbvb(pp_1, pp_1_tail, (part_len_bot + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate)
		self.drm_punct_vbvb_0 = drm.punct_vbvb(pp_0, pp_0_tail, (part_len_top + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate)
		self.drm_partitioning_16_vbvb_0 = drm.partitioning_vbvb(vlen_in, M_total)
		self.drm_interleaver_vbvb_0_0 = drm.interleaver_vbvb((interl_seq_1_2))
		self.drm_interleaver_vbvb_0 = drm.interleaver_vbvb((interl_seq_0_2))
		self.add_tailbits_vbvb_0_0 = drm.add_tailbits_vbvb(part_len_bot, n_tailbits)
		self.add_tailbits_vbvb_0 = drm.add_tailbits_vbvb(part_len_top, n_tailbits)

		##################################################
		# Connections
		##################################################
		self.connect((self.drm_interleaver_vbvb_0, 0), (self.drm_qam_map_vbvc_0, 0))
		self.connect((self.drm_qam_map_vbvc_0, 0), (self, 0))
		self.connect((self.trellis_encoder_xx_0, 0), (self.gr_unpack_k_bits_bb_0, 0))
		self.connect((self.gr_stream_to_vector_0, 0), (self.drm_punct_vbvb_0, 0))
		self.connect((self.gr_unpack_k_bits_bb_0, 0), (self.gr_stream_to_vector_0, 0))
		self.connect((self.drm_punct_vbvb_0, 0), (self.drm_interleaver_vbvb_0, 0))
		self.connect((self.trellis_encoder_xx_0_0, 0), (self.gr_unpack_k_bits_bb_0_0, 0))
		self.connect((self.gr_stream_to_vector_0_0, 0), (self.drm_punct_vbvb_0_0, 0))
		self.connect((self.gr_unpack_k_bits_bb_0_0, 0), (self.gr_stream_to_vector_0_0, 0))
		self.connect((self.drm_punct_vbvb_0_0, 0), (self.drm_interleaver_vbvb_0_0, 0))
		self.connect((self.drm_interleaver_vbvb_0_0, 0), (self.drm_qam_map_vbvc_0, 1))
		self.connect((self.gr_vector_to_stream_1, 0), (self.trellis_encoder_xx_0, 0))
		self.connect((self.gr_vector_to_stream_1_0, 0), (self.trellis_encoder_xx_0_0, 0))
		self.connect((self, 0), (self.drm_partitioning_16_vbvb_0, 0))
		self.connect((self.add_tailbits_vbvb_0, 0), (self.gr_vector_to_stream_1, 0))
		self.connect((self.add_tailbits_vbvb_0_0, 0), (self.gr_vector_to_stream_1_0, 0))
		self.connect((self.drm_partitioning_16_vbvb_0, 1), (self.add_tailbits_vbvb_0_0, 0))
		self.connect((self.drm_partitioning_16_vbvb_0, 0), (self.add_tailbits_vbvb_0, 0))
示例#29
0
    def __init__(self,
                 constellation,
                 samples_per_symbol=_def_samples_per_symbol,
                 differential=_def_differential,
                 excess_bw=_def_excess_bw,
                 gray_coded=True,
                 freq_bw=_def_freq_bw,
                 timing_bw=_def_timing_bw,
                 phase_bw=_def_phase_bw,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered differential generic demodulation.

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

	@param constellation: determines the modulation type
	@type constellation: gnuradio.digital.gr_constellation
	@param samples_per_symbol: samples per symbol >= 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 freq_bw: loop filter lock-in bandwidth
        @type freq_bw: float
        @param timing_bw: timing recovery loop lock-in bandwidth
        @type timing_bw: float
        @param phase_bw: phase recovery loop bandwidth
        @type phase_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,
            "generic_demod",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))  # Output signature

        self._constellation = constellation.base()
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._phase_bw = phase_bw
        self._freq_bw = freq_bw
        self._timing_bw = timing_bw
        self._timing_max_dev = _def_timing_max_dev
        self._differential = differential

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

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

        nfilts = 32
        ntaps = 11 * int(self._samples_per_symbol * nfilts)

        # Automatic gain control
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)

        # Frequency correction
        fll_ntaps = 55
        self.freq_recov = digital.fll_band_edge_cc(self._samples_per_symbol,
                                                   self._excess_bw, fll_ntaps,
                                                   self._freq_bw)

        # symbol timing recovery with RRC data filter
        taps = gr.firdes.root_raised_cosine(nfilts,
                                            nfilts * self._samples_per_symbol,
                                            1.0, self._excess_bw, ntaps)
        self.time_recov = digital.pfb_clock_sync_ccf(self._samples_per_symbol,
                                                     self._timing_bw, taps,
                                                     nfilts, nfilts // 2,
                                                     self._timing_max_dev)

        fmin = -0.25
        fmax = 0.25
        self.receiver = digital.constellation_receiver_cb(
            self._constellation, self._phase_bw, fmin, fmax)

        # Do differential decoding based on phase change of symbols
        if differential:
            self.diffdec = digital.diff_decoder_bb(arity)

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

        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()

        # Connect and Initialize base class
        blocks = [
            self, self.agc, self.freq_recov, self.time_recov, self.receiver
        ]
        if differential:
            blocks.append(self.diffdec)
        if self._constellation.apply_pre_diff_code():
            blocks.append(self.symbol_mapper)
        blocks += [self.unpack, self]
        self.connect(*blocks)
    def __init__(self, constellation,
                 samples_per_symbol=_def_samples_per_symbol,
                 differential=_def_differential,
                 excess_bw=_def_excess_bw,
                 gray_coded=True,
                 freq_bw=_def_freq_bw,
                 timing_bw=_def_timing_bw,
                 phase_bw=_def_phase_bw,
                 verbose=_def_verbose,
                 log=_def_log):
        """
	Hierarchical block for RRC-filtered differential generic demodulation.

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

	@param constellation: determines the modulation type
	@type constellation: gnuradio.digital.gr_constellation
	@param samples_per_symbol: samples per symbol >= 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 freq_bw: loop filter lock-in bandwidth
        @type freq_bw: float
        @param timing_bw: timing recovery loop lock-in bandwidth
        @type timing_bw: float
        @param phase_bw: phase recovery loop bandwidth
        @type phase_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, "generic_demod",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(1, 1, gr.sizeof_char))       # Output signature
				
        self._constellation = constellation.base()
        self._samples_per_symbol = samples_per_symbol
        self._excess_bw = excess_bw
        self._phase_bw = phase_bw
        self._freq_bw = freq_bw
        self._timing_bw = timing_bw
        self._timing_max_dev= _def_timing_max_dev
        self._differential = differential

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

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

        nfilts = 32
        ntaps = 11 * int(self._samples_per_symbol*nfilts)

        # Automatic gain control
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)

        # Frequency correction
        fll_ntaps = 55
        self.freq_recov = digital_swig.fll_band_edge_cc(self._samples_per_symbol, self._excess_bw,
                                                        fll_ntaps, self._freq_bw)

        # symbol timing recovery with RRC data filter
        taps = gr.firdes.root_raised_cosine(nfilts, nfilts*self._samples_per_symbol,
                                            1.0, self._excess_bw, ntaps)
        self.time_recov = gr.pfb_clock_sync_ccf(self._samples_per_symbol,
                                                self._timing_bw, taps,
                                                nfilts, nfilts//2, self._timing_max_dev)

        fmin = -0.25
        fmax = 0.25
        self.receiver = digital_swig.constellation_receiver_cb(
            self._constellation, self._phase_bw,
            fmin, fmax)

        # Do differential decoding based on phase change of symbols
        if differential:
            self.diffdec = gr.diff_decoder_bb(arity)

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

        # unpack the k bit vector into a stream of bits
        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())

        if verbose:
            self._print_verbage()

        if log:
            self._setup_logging()
        
        # Connect and Initialize base class
        blocks = [self, self.agc, self.freq_recov,
                  self.time_recov, self.receiver]
        if differential:
            blocks.append(self.diffdec)
        if self._constellation.apply_pre_diff_code():
            blocks.append(self.symbol_mapper)
        blocks += [self.unpack, self]
        self.connect(*blocks)
示例#31
0
    def __init__(self, pkt_size=32032):
        gr.hier_block2.__init__(
            self,
            "Sync Watcher",
            gr.io_signature(1, 1, gr.sizeof_char * 1),
            gr.io_signature(0, 0, 0),
        )

        ##################################################
        # Variables
        ##################################################
        crc_size = 32
        # size of crc, in bits
        preamble_size = 16
        access_code_size = 64
        # size of packet, including crc, but not including preamble or access_code
        # This is (probably) the number of bits left in the packet once an access_code flag is seen
        # TODO: verify timing of access_code flag with respect to the rest of the packet
        self.pkt_size = pkt_size  #use to be: 4000*8 + crc_size

        # number of bits we're interested in from the input byte stream
        self.significant_bits = 2

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

        # unpack bits takes one byte in and splits it into k bytes out.
        # bit 0 from input is placed in bit 0 of output byte 0
        # bit 1 from input is placed in bit 0 of output byte 1
        # ... and so on up to k
        self.unpack_bits = gr.unpack_k_bits_bb(self.significant_bits)

        # deinterleave splits single stream of bytes at rate of N bytes/sec into two separate
        # streams of bytes, each at a rate of N/2 bytes/sec
        self.deinterleave = gr.deinterleave(gr.sizeof_char * 1)

        self.char_to_float = gr.char_to_float(1)

        # Setup the downcounter that will raise the flag for max iterations upon high input
        self.downcounter = digital_ll.downcounter(self.pkt_size)

        # Null sinks 1 and 2 for tieing off lose ends
        self.null_sink_1 = gr.null_sink(gr.sizeof_char * 1)
        self.null_sink_2 = gr.null_sink(gr.sizeof_float * 1)

        #self.file_sink = gr.file_sink(gr.sizeof_short * 1, "/home/interlaken/a/cr22845/SDR/generalized-sdr-comms/demos/csma_month2/flag_out.dat")

        ##################################################
        # Connections
        ##################################################
        # unpack byte with bit 0 = data bit and bit 1 = flag bit into two bytes, byte 0 has bit
        # 0 = data bit and byte 1 has bit 0 = flag bit
        self.connect((self, 0), (self.unpack_bits, 0))

        # deinterleave to get two streams. One byte stream has only data bits, on stream has only
        # flag bits
        self.connect((self.unpack_bits, 0), (self.deinterleave, 0))

        # send data bytes to null
        self.connect((self.deinterleave, 1), (self.null_sink_1, 0))

        # convert flag bytes to floats for use with downcounter
        self.connect((self.deinterleave, 0), (self.char_to_float, 0))

        # connect the float output to the downcounter block
        self.connect((self.char_to_float, 0), (self.downcounter, 0))

        # finally tie it off with a null sink
        self.connect((self.downcounter, 0), (self.null_sink_2, 0))