Exemple #1
0
	def setup_flowgraph(self, mode, ber_skipbytes=0):
		# parameters
		self.dp.set_mode(mode)
		self.rp.set_mode(mode)
		self.vlen = self.dp.num_carriers/4
		self.ber_skipbytes = ber_skipbytes

		# trigger signals
		frame_trigger = [1]+[0]*(self.dp.symbols_per_frame-2)
		self.frame_start = frame_trigger*(len(self.random_bytes)/(self.vlen*(self.dp.symbols_per_frame-1)))+frame_trigger[0:(len(self.random_bytes)/self.vlen)%(self.dp.symbols_per_frame-1)]

		# sources/sinks
		self.source    = gr.vector_source_b(self.random_bytes, False)
		self.trig      = gr.vector_source_b(self.frame_start, False)
		if self.ber_sink:
			self.sink = dab.blocks.measure_ber_b()
		else:
			self.sink = gr.vector_sink_b()
		self.trig_sink = gr.null_sink(gr.sizeof_char)

		# self.noise_start      = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
		# self.noise_start_head = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_START)
		# self.noise_end        = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
		# self.noise_end_head   = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_END)
		
		# blocks
		self.s2v       = gr.stream_to_vector(gr.sizeof_char, self.vlen)
		self.v2s       = gr.vector_to_stream(gr.sizeof_char, self.vlen)
		if self.ber_sink:
			self.ber_skipbytes0 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes)
			self.ber_skipbytes1 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes+self.dp.bytes_per_frame)
		
		# more blocks (they have state, so better reinitialise them)
		self.mod       = dab.ofdm_mod(self.dp, debug = False)
		self.rescale   = gr.multiply_const_cc(1)
		self.amp       = gr.multiply_const_cc(1)
		self.channel   = blks2.channel_model(noise_voltage=0, noise_seed=random.randint(0,10000))
		# self.cat       = dab.concatenate_signals(gr.sizeof_gr_complex)
		self.demod     = dab.ofdm_demod(self.dp, self.rp, debug = False, verbose = True)

		# connect it all
		if self.ber_sink:
			self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.ber_skipbytes0, self.sink)
			self.connect(self.source, self.ber_skipbytes1, (self.sink,1))
		else:
			self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.sink)
		self.connect(self.trig, (self.mod,1))
		self.connect((self.demod, 1), self.trig_sink)

		# SNR calculation and prober
		self.probe_signal = gr.probe_avg_mag_sqrd_c(0,0.00001)
		self.probe_total  = gr.probe_avg_mag_sqrd_c(0,0.00001)
		self.connect(self.amp, self.probe_signal)
		self.connect(self.channel, self.probe_total)
Exemple #2
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = 8000
        src = audio.source(sample_rate, options.audio_input)
        tx = blks2.digital_voice_tx(self)
        if_gain = gr.multiply_const_cc(10000)
        # channel simulator here...
        rx = blks2.digital_voice_rx(self)
        dst = audio.sink(sample_rate, options.audio_output)

        self.connect(src, tx, if_gain, rx, dst)
Exemple #3
0
	def __init__(self, sample_rate, symbol_rate):
		gr.hier_block2.__init__(self, "dvb_s_demodulator_cc",
				gr.io_signature(1, 1, gr.sizeof_gr_complex),	# Input signature
				gr.io_signature(1, 1, gr.sizeof_gr_complex))	# Output signature

		omega = sample_rate / symbol_rate
		gain_omega = omega * omega / 4.0
		freq_beta = freq_alpha * freq_alpha / 4.0
		mu = 0.0
		gain_mu = 0.05
		omega_relative_limit = 0.005

		# Automatic gain control
		self.agc = gr.agc2_cc(
				0.06,				# Attack rate
				0.001,				# Decay rate
				1,					# Reference
				1,					# Initial gain
				100)				# Max gain

		# Frequency correction with band-edge filters FLL
		freq_beta = freq_alpha * freq_alpha / 4
		self.freq_recov = digital.fll_band_edge_cc(omega, dvb_swig.RRC_ROLLOFF_FACTOR, 11 * int(omega), freq_bw)
		self.freq_recov.set_alpha(freq_alpha)
		self.freq_recov.set_beta(freq_beta)
		self.receiver = digital.mpsk_receiver_cc(M, 0, freq_bw, fmin, fmax, mu, gain_mu, omega, gain_omega, omega_relative_limit)
		self.receiver.set_alpha(freq_alpha)
		self.receiver.set_beta(freq_beta)
		self.rotate = gr.multiply_const_cc(0.707 + 0.707j)

		self.connect(self, self.agc, self.freq_recov, self.receiver, self.rotate, self)
Exemple #4
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        self.u = usrp2.sink_32fc(options.interface, options.mac_addr)
        self.samples_per_symbol = 2
        self.chan_num = options.channel
        self.data_rate = int(self.u.dac_rate() / self.samples_per_symbol /
                             options.interp_rate)

        self.u.set_center_freq(
            ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num])
        self.u.set_interp(options.interp_rate)
        if not options.gain:
            g = self.u.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        self.u.set_gain(options.gain)

        print "cordic_freq = %s" % (eng_notation.num_to_str(
            ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]))
        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_interp = ", options.interp_rate

        #self.u.set_pga(0, options.gain)
        #self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self.samples_per_symbol, msgq_limit=2)
        self.gain = gr.multiply_const_cc(1)

        self.connect(self.packet_transmitter, self.gain, self.u)
Exemple #5
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.frequency = 13.56e6
        self.gain = 100
        self.usrp_interpol = 32

        # USRP settings
        self.u_tx = usrp.sink_c() #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked 
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),)             

        #Set gain.. duh
        self.subdev_tx.set_gain(self.gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

        self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", False)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0))
        
        self.connect(self.src, self.conv, self.amp, self.u_tx)
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-c", "--calibration", type="eng_float", default=0, help="freq offset")
        parser.add_option("-g", "--gain", type="eng_float", default=1)
        parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file")
        parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file")
        parser.add_option("-r", "--new-sample-rate", type="int", default=96000, help="output sample rate")
        parser.add_option("-s", "--sample-rate", type="int", default=48000, help="input sample rate")
        (options, args) = parser.parse_args()
 
        sample_rate = options.sample_rate
        new_sample_rate = options.new_sample_rate

        IN = gr.file_source(gr.sizeof_gr_complex, options.input_file)
        OUT = gr.file_sink(gr.sizeof_gr_complex, options.output_file)

        LO = gr.sig_source_c(sample_rate, gr.GR_COS_WAVE, options.calibration, 1.0, 0)
        MIXER = gr.multiply_cc()

        AMP = gr.multiply_const_cc(options.gain)

        nphases = 32
        frac_bw = 0.05
        p1 = frac_bw
        p2 = frac_bw
        rs_taps = gr.firdes.low_pass(nphases, nphases, p1, p2)
        #RESAMP = blks2.pfb_arb_resampler_ccf(float(sample_rate) / float(new_sample_rate), (rs_taps), nphases, )
        RESAMP = blks2.pfb_arb_resampler_ccf(float(new_sample_rate) / float(sample_rate), (rs_taps), nphases, )

        self.connect(IN, (MIXER, 0))
        self.connect(LO, (MIXER, 1))

        self.connect(MIXER, AMP, RESAMP, OUT)
    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)
Exemple #8
0
    def __init__(self, options, payload=''):
        gr.top_block.__init__(self)

        if (options.tx_freq is not None):
            self.sink = uhd_transmitter(options.args, options.bandwidth,
                                        options.tx_freq, options.tx_gain,
                                        options.spec, options.antenna,
                                        options.verbose)
        elif (options.to_file is not None):
            self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file)
        else:
            self.sink = gr.null_sink(gr.sizeof_gr_complex)

        options.interp = 100e6 / options.bandwidth  # FTW-specific convertion

        # do this after for any adjustments to the options that may
        # occur in the sinks (specifically the UHD sink)
        if (options.from_file is None):
            self.txpath = ftw_transmit_path(options, payload)
        else:
            self.txpath = gr.file_source(gr.sizeof_gr_complex,
                                         options.from_file)
#            options.tx_amplitude = 1

# static value to make sure we do not exceed +-1 for the floats being sent to the sink
        self._tx_amplitude = options.tx_amplitude
        self.amp = gr.multiply_const_cc(self._tx_amplitude)

        # self.txpath = ftw_pnc_transmit_path(options, payload)
        self.connect(self.txpath, self.amp, self.sink)

        if options.log:
            self.connect(
                self.txpath,
                gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
    def __init__(self, rx, reader, tx):
        gr.top_block.__init__(self)

        samp_freq = (64 / dec_rate) * 1e6
        amplitude = 33000

        num_taps = int(
            64000 /
            (dec_rate * up_link_freq * 2))  #Matched filter for 1/2 cycle

        taps = [complex(1, 1)] * num_taps

        print num_taps

        filt = gr.fir_filter_ccc(sw_dec, taps)

        to_mag = gr.complex_to_mag()
        amp = gr.multiply_const_cc(amplitude)

        c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR)
        zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2)

        dummy = gr.null_sink(gr.sizeof_float)
        to_complex = gr.float_to_complex()

        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print "Warning: failed to enable realtime scheduling"

        self.connect(rx, filt, to_mag, c_gate, zc, reader, amp, tx)
    def __init__(self):
        gr.top_block.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate()
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        self.picksubdev = pick_subdevice(self.u)
        #self.u.set_mux(usrp.determine_rx_mux_value(self.u, self.picksubdev))
        self.subdev = usrp.selected_subdev(self.u, pick_subdevice(self.u))
        print "Using TX d'board %s" % (self.subdev.side_and_name())

        #self.u.tune(0, self.subdev, 2475000000)
        #self.u.tune(0, self.subdev, 2480000000)
        self.u.tune(0, self.subdev, 2425000000)
        self.u.set_pga(0, 0)
        self.u.set_pga(1, 0)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2)

        self.gain = gr.multiply_const_cc (self.normal_gain)

        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Exemple #11
0
    def __init__(self, mod, options):
        gr.top_block.__init__(self, "tx_mpsk")

        self._modulator_class = mod

        # Get mod_kwargs
        mod_kwargs = self._modulator_class.extract_kwargs_from_options(options)

        # transmitter
        self._modulator = self._modulator_class(**mod_kwargs)

        if (options.tx_freq is not None):
            symbol_rate = options.bitrate / self._modulator.bits_per_symbol()
            self._sink = uhd_transmitter(options.args, symbol_rate,
                                         options.samples_per_symbol,
                                         options.tx_freq, options.tx_gain,
                                         options.spec, options.antenna,
                                         options.verbose)
            options.samples_per_symbol = self._sink._sps

        elif (options.to_file is not None):
            self._sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file)
        else:
            self._sink = gr.null_sink(gr.sizeof_gr_complex)

        self._transmitter = bert_transmit(self._modulator._constellation,
                                          options.samples_per_symbol,
                                          options.differential,
                                          options.excess_bw,
                                          gray_coded=True,
                                          verbose=options.verbose,
                                          log=options.log)

        self.amp = gr.multiply_const_cc(options.amplitude)
        self.connect(self._transmitter, self.amp, self._sink)
Exemple #12
0
    def __init__(self, gain):
        """
            Parameters:

                gain: gr_complex
        """
        gr.hier_block2.__init__(
            self,
            "No HW model",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
        )

        ##################################################
        # Parameters
        ##################################################
        self.gain = gain

        ##################################################
        # Blocks
        ##################################################
        self.multiply = gr.multiply_const_cc(self.gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.multiply, 0))
        self.connect((self.multiply, 0), (self, 0))
    def __init__(self, options):
        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate();
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # 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 TX d'board %s" % (self.subdev.side_and_name(),)

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc (self.normal_gain)
        
        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
    def __init__(self, ifile, ofile, options):
        gr.top_block.__init__(self)

        SNR = 10.0**(options.snr / 10.0)
        time_offset = options.time_offset
        phase_offset = options.phase_offset * (math.pi / 180.0)

        # calculate noise voltage from SNR
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal / SNR
        noise_voltage = math.sqrt(noise_power)
        print "Noise voltage: ", noise_voltage

        frequency_offset = options.frequency_offset / options.fft_length

        self.src = gr.file_source(gr.sizeof_gr_complex, ifile)
        #self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage,
                                        frequency_offset,
                                        time_offset,
                                        noise_seed=-random.randint(0, 100000))
        self.phase = gr.multiply_const_cc(
            complex(math.cos(phase_offset), math.sin(phase_offset)))
        self.snk = gr.file_sink(gr.sizeof_gr_complex, ofile)

        self.connect(self.src, self.channel, self.phase, self.snk)
Exemple #15
0
def main():
    gr.enable_realtime_scheduling()
    tb = gr.top_block ()
    src = gr.file_source(gr.sizeof_gr_complex, "transmit-data.dat", True)
    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    (options, args) = parser.parse_args ()
    d = {'verbose': True, 'discontinuous': False, 'samples_per_symbol': 2, 'usrpx': None, 'interp': INTERP, 'fusb_block_size': 0, 'megabytes': 1.0, 'rx_freq': 2.475e9, 'size': 1500, 'show_tx_gain_range': False, 'log': False, 'tx_subdev_spec': None, 'fusb_nblocks': 0, 'lo_offset': None, 'tx_gain': TXGAIN, 'which': 0, 'modulation': 'gmsk', 'excess_bw': 0.34999999999999998, 'bt': 0.34999999999999998, 'interface': 'eth0', 'freq': None, 'bitrate': 100000.0, 'from_file': None, 'tx_freq': 2475000000.0, 'mac_addr': '', 'tx_amplitude': 0.1, 'gray_code': True}
    for i, j in d.items():
        setattr(options, i, j)

    u = usrp_options.create_usrp_sink(options)
    dac_rate = u.dac_rate()
    if options.verbose:
        print 'USRP Sink:', u
    (_bitrate, _samples_per_symbol, _interp) = \
                    pick_tx_bitrate(options.bitrate, 2, \
                                    options.samples_per_symbol, options.interp, dac_rate, \
                                    u.get_interp_rates())

    u.set_interp(_interp)
    u.set_auto_tr(True)

    if not u.set_center_freq(options.tx_freq):
        print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.tx_freq))
        raise ValueError, eng_notation.num_to_str(options.tx_freq)
    
    m = gr.multiply_const_cc(CONSTANT)
    tb.connect(src, m, u)


    tb.run()
Exemple #16
0
    def __init__(self, options):
        '''
        See below for what options should hold
        '''

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

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

        self._verbose = options.verbose  # turn verbose mode on/off
        self._tx_amplitude = options.tx_amplitude  # digital amplitude sent to USRP

        self.ofdm_tx = \
                     blks2.ofdm_mod(options, msgq_limit=4, pad_for_usrp=False)

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

        # Display some information about the setup
        if self._verbose:
            self._print_verbage()

        # Create and setup transmit path flow graph
        self.connect(self.ofdm_tx, self.amp, self)
Exemple #17
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.freq is not None:
            u = usrp2.sink(options)
        elif options.outfile is not None:
            u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            raise SystemExit("--freq or --outfile must be specified\n")

        if options.infile is not None:
            tx = gr.file_source(gr.sizeof_gr_complex, options.infile)
        else:
            tx = qam_rxtx.TX(options)
            framebytes = tx.framebytes
            if options.txdata is not None:
                data = gr.file_source(framebytes * gr.sizeof_char,
                                      options.txdata, options.repeat)
            else:
                data = qam_rxtx.make_data(framebytes)
                if options.log:
                    self.connect(
                        data,
                        gr.file_sink(framebytes * gr.sizeof_char,
                                     'tx-data.datb'))

            self.connect(data, tx)
            self.sender = ofdm_rxtx.sender_thread(tx.ofdm, options)

        if options.amp != 1:
            amp = gr.multiply_const_cc(options.amp)
            self.connect(tx, amp, u)
        else:
            self.connect(tx, u)
    def configure_cc2420(self):
        self.disconnect_all()
        gain = 0
        cordic_freq = 2415000000
        self.normal_gain = 8000

        dac_rate = self.u.dac_rate()
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, (0, 0)))
        self.subdev = usrp.selected_subdev(self.u, (0, 0))
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, cordic_freq)
        self.u.set_pga(0, gain)
        self.u.set_pga(1, gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc(self.normal_gain)

        self.connect(self.packet_transmitter, self.gain, self.u)

        #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'rx_test.dat')
        #self.connect(self.gain, self.filesink)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
    def configure_cc2420(self):
        self.disconnect_all()
        gain = 0
        cordic_freq = 2415000000
        self.normal_gain = 8000

        dac_rate = self.u.dac_rate();
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, (0, 0)))
        self.subdev = usrp.selected_subdev(self.u, (0, 0))
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.u.tune(self.subdev._which, self.subdev, cordic_freq)
        self.u.set_pga(0, gain)
        self.u.set_pga(1, gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc (self.normal_gain)
        
        self.connect(self.packet_transmitter, self.gain, self.u)

        #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'rx_test.dat')
        #self.connect(self.gain, self.filesink)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Exemple #20
0
    def __init__(self):
        gr.top_block.__init__(self)

        sample_rate = 32000
        ampl = 0.1

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

        # Constructing a sine source and the fft blocks
        src0 = gr.sig_source_c (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        ss2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._fft_length)
        sv2s = gr.vector_to_stream(gr.sizeof_gr_complex, self._fft_length)
        fft_demod = gr.fft_vcc(self._fft_length, True, win2, False)
        ifft = gr.fft_vcc(self._fft_length, False, win, False)
        scale = gr.multiply_const_cc(1.0 / self._fft_length)
        
        # Some output data files
        trans_output = gr.file_sink(gr.sizeof_gr_complex, "trans_output.dat")
        reg_output = gr.file_sink(gr.sizeof_gr_complex, "reg_output.dat")

        # make the connections #
        self.connect(src0, ss2v, fft_demod, ifft, sv2s, scale, trans_output)
        self.connect(src0, reg_output)
Exemple #21
0
    def __init__(self, sample_rate, symbol_rate):
        gr.hier_block2.__init__(
            self,
            "dvb_s_demodulator_cc",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        omega = sample_rate / symbol_rate
        gain_omega = omega * omega / 4.0
        freq_beta = freq_alpha * freq_alpha / 4.0
        mu = 0.0
        gain_mu = 0.05
        omega_relative_limit = 0.005

        # Automatic gain control
        self.agc = gr.agc2_cc(
            0.06,  # Attack rate
            0.001,  # Decay rate
            1,  # Reference
            1,  # Initial gain
            100)  # Max gain

        # Frequency correction with band-edge filters FLL
        freq_beta = freq_alpha * freq_alpha / 4
        self.freq_recov = gr.fll_band_edge_cc(omega,
                                              dvb_swig.RRC_ROLLOFF_FACTOR,
                                              11 * int(omega), freq_alpha,
                                              freq_beta)
        self.receiver = gr.mpsk_receiver_cc(M, 0, freq_alpha, freq_beta, fmin,
                                            fmax, mu, gain_mu, omega,
                                            gain_omega, omega_relative_limit)
        self.rotate = gr.multiply_const_cc(0.707 + 0.707j)

        self.connect(self, self.agc, self.freq_recov, self.receiver,
                     self.rotate, self)
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.outfile is not None:
          u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        elif (options.tx_freq is not None) or (options.channel is not None):
          if options.channel is not None:
            self.chan_num = options.channel
            options.tx_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]

          u = uhd_transmitter(options.tx_args,
                              options.bandwidth,
                              options.tx_freq, options.tx_gain,
                              options.spec, options.antenna,
                              options.verbose, options.external)
        else:
          raise SystemExit("--tx-freq, --channel or --outfile must be specified\n")

        self.samples_per_symbol = 2

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self,
                spb=self.samples_per_symbol, msgq_limit=2, log=options.log)
        self.amp = gr.multiply_const_cc(1)

        self.u = u
        self.connect(self.packet_transmitter, self.amp, self.u)

        self.connect(self.amp, gr.file_sink(gr.sizeof_gr_complex, 'cc2420-tx-diag.dat'))
    def __init__(self, tx, zc, reader, rx, matched_filter,
                 reader_monitor_cmd_gate, cr, tag_monitor, amplitude):
        gr.top_block.__init__(self)

        # ASK/PSK demodulators
        to_mag_L = gr.complex_to_mag()
        to_mag_R = gr.complex_to_mag()

        # Others blocks for Buettner's reader
        samp_freq = (64 / dec_rate) * 1e6
        num_taps = int(64000 / (dec_rate * up_link_freq * 4))
        taps = [complex(1, 1)] * num_taps
        filt = gr.fir_filter_ccc(sw_dec, taps)  # Matched filter
        amp = gr.multiply_const_cc(amplitude)
        c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR)

        # Null sink for terminating the Listener graph
        null_sink = gr.null_sink(gr.sizeof_float * 1)

        # Deinterleaver to separate FPGA channels
        di = gr.deinterleave(gr.sizeof_gr_complex)

        # Enable real-time scheduling
        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print "Warning: failed to enable realtime scheduling"

# Create flow-graph
        self.connect(rx, di)
        self.connect((di, 0), filt, to_mag_R, c_gate, zc, reader, amp, tx)
        self.connect((di, 1), matched_filter, to_mag_L,
                     reader_monitor_cmd_gate, cr, tag_monitor, null_sink)
Exemple #24
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.frequency = 13.56e6
        self.gain = 100
        # for 4 MS/s, 32
        # 
        self.usrp_interpol = 32

        # USRP settings
        self.u_tx = usrp.sink_c() #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked 
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),)             

        #Set gain.. duh
        self.subdev_tx.set_gain(self.gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

#        self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", True)
        self.src = gr.wavfile_source("wave52.wav", True)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0))
        
        self.connect(self.src, self.conv, self.amp, self.u_tx)
    def __init__(self, rx, reader, tx):
        gr.top_block.__init__(self)
               
        samp_freq = (64 / dec_rate) * 1e6
        amplitude = 33000

        num_taps = int(64000 / (dec_rate * up_link_freq * 2))  #Matched filter for 1/2 cycle

        taps = [complex(1,1)] * num_taps
        
        print num_taps

        filt = gr.fir_filter_ccc(sw_dec, taps)
        
        to_mag = gr.complex_to_mag()
        amp = gr.multiply_const_cc(amplitude)

        c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR)
        zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2);
        
        dummy = gr.null_sink(gr.sizeof_float)
        to_complex = gr.float_to_complex()


        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print "Warning: failed to enable realtime scheduling"
    
        


        self.connect(rx, filt, to_mag, c_gate, zc,  reader, amp, tx);   
Exemple #26
0
    def __init__(self):
        gr.top_block.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate()
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        self.picksubdev = pick_subdevice(self.u)
        #self.u.set_mux(usrp.determine_rx_mux_value(self.u, self.picksubdev))
        self.subdev = usrp.selected_subdev(self.u, pick_subdevice(self.u))
        print "Using TX d'board %s" % (self.subdev.side_and_name())

        #self.u.tune(0, self.subdev, 2475000000)
        #self.u.tune(0, self.subdev, 2480000000)
        self.u.tune(0, self.subdev, 2425000000)
        self.u.set_pga(0, 0)
        self.u.set_pga(1, 0)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self._spb, msgq_limit=2)

        self.gain = gr.multiply_const_cc(self.normal_gain)

        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
    def __init__(self, options):
        '''
        See below for what options should hold
        '''

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

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

        self._verbose      = options.verbose      # turn verbose mode on/off
        self._tx_amplitude = options.tx_amplitude # digital amp sent to radio

        self.ofdm_tx = digital.ofdm_mod(options,
                                        msgq_limit=4,
                                        pad_for_usrp=False)

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

        # Display some information about the setup
        if self._verbose:
            self._print_verbage()

        # Create and setup transmit path flow graph
        self.connect(self.ofdm_tx, self.amp, self)
    def __init__(self,
                 sps,               # Samples per symbol
                 excess_bw,         # RRC filter excess bandwidth (typically 0.35-0.5)
                 amplitude,         # DAC output level, 0-32767, typically 2000-8000
                 vector_source,   # Indicate if it's the infinite sequence of 1, or by use the code to change the amplitude
                 ):

            gr.hier_block2.__init__(self, "bpsk_modulator",
                                gr.io_signature(0, 0, 0),                    # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
            
            # Create BERT data bit stream	
            
            self.vector_source = vector_source
            
            self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit scrambler
            
            # Map to constellation
            self._constellation = [-1+0j, 1+0j]
            self._mapper = gr.chunks_to_symbols_bc(self._constellation)	
            
            # Create RRC with specified excess bandwidth
            taps = gr.firdes.root_raised_cosine(sps,  # Gain
					    sps,	    # Sampling rate
					    1.0,	    # Symbol rate
					    excess_bw,	    # Roll-off factor
					    11*sps)         # Number of taps
            
            self._rrc = gr.interp_fir_filter_ccf(sps,	    # Interpolation rate
					     taps)	    # FIR taps
            
            self.amp = gr.multiply_const_cc(amplitude)
            
            # Wire block inputs and outputs
            self.connect(self.vector_source, self._scrambler, self._mapper, self._rrc, self.amp, self)
    def __init__(self, options):
        gr.top_block.__init__(self)

        self.u = usrp2.sink_32fc(options.interface, options.mac_addr)
        self.samples_per_symbol = 2
        self.chan_num = options.channel
        self.data_rate = int(self.u.dac_rate() / self.samples_per_symbol / options.interp_rate)

        self.u.set_center_freq(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num])
        self.u.set_interp(options.interp_rate)
        if not options.gain:
            g = self.u.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        self.u.set_gain(options.gain)

        print "cordic_freq = %s" % (eng_notation.num_to_str(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]))
        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_interp = ", options.interp_rate

        # self.u.set_pga(0, options.gain)
        # self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self.samples_per_symbol, msgq_limit=2
        )
        self.gain = gr.multiply_const_cc(1)

        self.connect(self.packet_transmitter, self.gain, self.u)
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.outfile is not None:
            u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        elif (options.tx_freq is not None) or (options.channel is not None):
            if options.channel is not None:
                self.chan_num = options.channel
                options.tx_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[
                    self.chan_num]

            u = uhd_transmitter(options.tx_args, options.bandwidth,
                                options.tx_freq, options.tx_gain, options.spec,
                                options.antenna, options.verbose,
                                options.external)
        else:
            raise SystemExit(
                "--tx-freq, --channel or --outfile must be specified\n")

        self.samples_per_symbol = 2

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self.samples_per_symbol, msgq_limit=2, log=options.log)
        self.amp = gr.multiply_const_cc(1)

        self.u = u
        self.connect(self.packet_transmitter, self.amp, self.u)

        self.connect(self.amp,
                     gr.file_sink(gr.sizeof_gr_complex, 'cc2420-tx-diag.dat'))
Exemple #31
0
    def __init__(self, options):
        gr.hier_block2.__init__(self, "transmit_path",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))

        # constants for usrp
        usrp_rate = 128000000
        usrp_interp = 200
        tari_rate = 40000
        gain = 5000

        run_usrp = True

        testit = False
        if testit:
            self.downlink = gr.file_source(gr.sizeof_gr_complex, "readout.dat",
                                           True)
        else:
            self.downlink = rfidbts.downlink_src(samp_per_delimiter=8,
                                                 samp_per_cw=64 * 16 * 60,
                                                 samp_per_wait=64 * 16 * 4,
                                                 samp_per_tari=16,
                                                 samp_per_pw=8,
                                                 samp_per_trcal=53,
                                                 samp_per_data1=32)

        if run_usrp:
            self.sink = downlink_usrp_sink(options, usrp_rate, usrp_interp,
                                           tari_rate)
        else:
            self.sink = downlink_test_file_sink(usrp_rate, usrp_interp)

        self.gain = gr.multiply_const_cc(gain)

        self.connect(self.downlink, self.gain, self.sink)
def build_graph (input, raw, snr, freq_offset, coeffs, mag):

    # Initialize empty flow graph
    fg = gr.top_block ()

    # Set up file source
    src = gr.file_source (1, input)

    # Set up GMSK modulator, 2 samples per symbol
    mod = gmsk_mod(2)

    # Amplify the signal
    tx_amp = 1
    amp = gr.multiply_const_cc(1)
    amp.set_k(tx_amp)

    # Compute proper noise voltage based on SNR
    SNR = 10.0**(snr/10.0)
    power_in_signal = abs(tx_amp)**2
    noise_power = power_in_signal/SNR
    noise_voltage = math.sqrt(noise_power)

    # Generate noise
    rseed = int(time.time())
    noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, rseed)
    adder = gr.add_cc()
    fg.connect(noise, (adder, 1))
    
    # Create the frequency offset, 0 for now
    offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, freq_offset, 1.0, 0.0)
    mixer = gr.multiply_cc()
    fg.connect(offset, (mixer, 1))

    # Pass the noisy data to the matched filter
    dfile = open(coeffs, 'r')
    data = []
    for line in dfile:
      data.append(complex(*map(float,line.strip().strip("()").split(" "))).conjugate())
    dfile.close()
    data.reverse()
    mfilter = gr.fir_filter_ccc(1, data)


    # Connect the flow graph
    fg.connect(src, mod)
    fg.connect(mod, (mixer, 0))
    fg.connect(mixer, (adder, 0))

    if mag:
      raw_dst = gr.file_sink (gr.sizeof_float, raw)
      magnitude = gr.complex_to_mag(1)
      fg.connect(adder, mfilter, magnitude, raw_dst)
    else:
      raw_dst = gr.file_sink (gr.sizeof_gr_complex, raw)
      fg.connect(adder, mfilter, raw_dst)

    print "SNR(db): " + str(snr)
    print "Frequency Offset: " + str(freq_offset)

    return fg
Exemple #33
0
    def set_waveform(self, type):
        self.lock()
        self.disconnect_all()
        if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
            self._src = gr.sig_source_c(
                self[SAMP_RATE_KEY],  # Sample rate
                type,  # Waveform type
                self[WAVEFORM_FREQ_KEY],  # Waveform frequency
                self[AMPLITUDE_KEY],  # Waveform amplitude
                self[WAVEFORM_OFFSET_KEY])  # Waveform offset
        elif type == gr.GR_GAUSSIAN or type == gr.GR_UNIFORM:
            self._src = gr.noise_source_c(type, self[AMPLITUDE_KEY])
        elif type == "2tone":
            self._src1 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE,
                                         self[WAVEFORM_FREQ_KEY],
                                         self[AMPLITUDE_KEY] / 2.0, 0)
            if (self[WAVEFORM2_FREQ_KEY] is None):
                self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY]

            self._src2 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE,
                                         self[WAVEFORM2_FREQ_KEY],
                                         self[AMPLITUDE_KEY] / 2.0, 0)
            self._src = gr.add_cc()
            self.connect(self._src1, (self._src, 0))
            self.connect(self._src2, (self._src, 1))
        elif type == "sweep":
            # rf freq is center frequency
            # waveform_freq is total swept width
            # waveform2_freq is sweep rate
            # will sweep from (rf_freq-waveform_freq/2) to (rf_freq+waveform_freq/2)
            if self[WAVEFORM2_FREQ_KEY] is None:
                self[WAVEFORM2_FREQ_KEY] = 0.1

            self._src1 = gr.sig_source_f(self[SAMP_RATE_KEY], gr.GR_TRI_WAVE,
                                         self[WAVEFORM2_FREQ_KEY], 1.0, -0.5)
            self._src2 = gr.frequency_modulator_fc(
                self[WAVEFORM_FREQ_KEY] * 2 * math.pi / self[SAMP_RATE_KEY])
            self._src = gr.multiply_const_cc(self[AMPLITUDE_KEY])
            self.connect(self._src1, self._src2, self._src)
        else:
            raise RuntimeError("Unknown waveform type")

        self.connect(self._src, self._u)
        self.unlock()

        if self._verbose:
            print "Set baseband modulation to:", waveforms[type]
            if type == gr.GR_SIN_WAVE:
                print "Modulation frequency: %sHz" % (n2s(
                    self[WAVEFORM_FREQ_KEY]), )
                print "Initial phase:", self[WAVEFORM_OFFSET_KEY]
            elif type == "2tone":
                print "Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]), )
                print "Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), )
            elif type == "sweep":
                print "Sweeping across %sHz to %sHz" % (n2s(
                    -self[WAVEFORM_FREQ_KEY] /
                    2.0), n2s(self[WAVEFORM_FREQ_KEY] / 2.0))
                print "Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), )
            print "TX amplitude:", self[AMPLITUDE_KEY]
Exemple #34
0
    def __init__(self, options):
        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate()
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # 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 TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc(self.normal_gain)

        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Exemple #35
0
    def __init__(self, options):
        '''
        See below for what options should hold
        '''

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

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

        self._verbose = options.verbose  # turn verbose mode on/off
        self._tx_amplitude = options.tx_amplitude  # digital amp sent to radio

        self.packet_tx = ofdm_mod(options, msgq_limit=4, pad_for_usrp=False)

        self.amp = gr.multiply_const_cc(1)
        self.set_tx_amplitude(self._tx_amplitude)
        self.null_sink = gr.null_sink(gr.sizeof_char)
        self.coding_block_length = options.block_length

        # Display some information about the setup
        if self._verbose:
            self._print_verbage()

        # Create and setup transmit path flow graph
        self.connect(self.packet_tx, self.amp, self)
        # connect hier block input to null when not using streaming inputs
        self.connect(self, self.null_sink)
Exemple #36
0
    def __init__(self, options, payload=''):
        gr.top_block.__init__(self)

	if(options.tx_freq is not None):
            self.sink = uhd_transmitter(options.args,
                                        options.bandwidth,
                                        options.tx_freq, options.tx_gain,
                                        options.spec, options.antenna,
                                        options.verbose)
        elif(options.to_file is not None):
            self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file)
        else:
            self.sink = gr.null_sink(gr.sizeof_gr_complex)

	options.interp	= 100e6/options.bandwidth	# FTW-specific convertion

        # do this after for any adjustments to the options that may
        # occur in the sinks (specifically the UHD sink)
        if(options.from_file is None):
            self.txpath = ftw_transmit_path(options, payload)    
        else:
            self.txpath = gr.file_source(gr.sizeof_gr_complex, options.from_file);
#            options.tx_amplitude = 1

        # static value to make sure we do not exceed +-1 for the floats being sent to the sink
	self._tx_amplitude = options.tx_amplitude        
	self.amp = gr.multiply_const_cc(self._tx_amplitude)

        # self.txpath = ftw_pnc_transmit_path(options, payload)
        self.connect(self.txpath, self.amp, self.sink)

        if options.log:
            self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
Exemple #37
0
  def __init__(self, options):
    gr.top_block.__init__(self)

    if options.freq is not None:
      u = usrp2.sink(options)
    elif options.outfile is not None:
      u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
    else:
      raise SystemExit("--freq or --outfile must be specified\n")

    if options.infile is not None:
      tx = gr.file_source(gr.sizeof_gr_complex, options.infile)
    else:
      tx = qam_rxtx.TX(options)
      framebytes = tx.framebytes
      if options.txdata is not None:
        data = gr.file_source(framebytes * gr.sizeof_char, options.txdata, options.repeat)
      else:
        data = qam_rxtx.make_data(framebytes)
        if options.log:
          self.connect(data, gr.file_sink(framebytes * gr.sizeof_char, 'tx-data.datb'))

      self.connect(data, tx)
      self.sender = ofdm_rxtx.sender_thread(tx.ofdm, options)

    if options.amp != 1:
      amp = gr.multiply_const_cc(options.amp)
      self.connect(tx, amp, u)
    else:
      self.connect(tx, u)
Exemple #38
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] side-A-tx-freq side-B-tx-freq"
        parser = OptionParser(option_class=eng_option, usage=usage)
        (options, args) = parser.parse_args()

        if len(args) != 2:
            parser.print_help()
            raise SystemExit
        else:
            freq0 = str_to_num(args[0])
            freq1 = str_to_num(args[1])

        # ----------------------------------------------------------------
        # Set up USRP to transmit on both daughterboards

        self.u = usrp.sink_c(nchan=2)  # say we want two channels

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

        # we're using both daughterboard slots, thus subdev is a 2-tuple
        self.subdev = (self.u.db(0, 0), self.u.db(1, 0))
        print "Using TX d'board %s" % (self.subdev[0].side_and_name(), )
        print "Using TX d'board %s" % (self.subdev[1].side_and_name(), )

        # set up the Tx mux so that
        #  channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
        self.u.set_mux(0xba98)

        self.subdev[0].set_gain(
            self.subdev[0].gain_range()[1])  # set max Tx gain
        self.subdev[1].set_gain(
            self.subdev[1].gain_range()[1])  # set max Tx gain

        self.set_freq(0, freq0)
        self.set_freq(1, freq1)
        self.subdev[0].set_enable(True)  # enable transmitter
        self.subdev[1].set_enable(True)  # enable transmitter

        # ----------------------------------------------------------------
        # build two signal sources, interleave them, amplify and connect them to usrp

        sig0 = example_signal_0(self.usrp_rate)
        sig1 = example_signal_1(self.usrp_rate)

        intl = gr.interleave(gr.sizeof_gr_complex)
        self.connect(sig0, (intl, 0))
        self.connect(sig1, (intl, 1))

        # apply some gain
        if_gain = 10000
        ifamp = gr.multiply_const_cc(if_gain)

        # and wire them up
        self.connect(intl, ifamp, self.u)
    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)
Exemple #40
0
 def __init__(self, **kwargs):
     gr.hier_block2.__init__(self, "generic_usrp_sink",
         gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
         gr.io_signature(0, 0, 0)) # Output signature
     _generic_usrp_base.__init__(self, **kwargs)
     if self._type == USRP1_TYPE: #scale 0.0 to 1.0 input for usrp1
         self.connect(self, gr.multiply_const_cc((2**15)-1), self._u)
     else: self.connect(self, self._u)
Exemple #41
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] side-A-tx-freq side-B-tx-freq"
        parser = OptionParser(option_class=eng_option, usage=usage)
        (options, args) = parser.parse_args()

        if len(args) != 2:
            parser.print_help()
            raise SystemExit
        else:
            freq0 = str_to_num(args[0])
            freq1 = str_to_num(args[1])

        # ----------------------------------------------------------------
        # Set up USRP to transmit on both daughterboards

        self.u = usrp.sink_c(nchan=2)  # say we want two channels

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

        # we're using both daughterboard slots, thus subdev is a 2-tuple
        self.subdev = (self.u.db(0, 0), self.u.db(1, 0))
        print "Using TX d'board %s" % (self.subdev[0].side_and_name(),)
        print "Using TX d'board %s" % (self.subdev[1].side_and_name(),)

        # set up the Tx mux so that
        #  channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
        self.u.set_mux(0xBA98)

        self.subdev[0].set_gain(self.subdev[0].gain_range()[1])  # set max Tx gain
        self.subdev[1].set_gain(self.subdev[1].gain_range()[1])  # set max Tx gain

        self.set_freq(0, freq0)
        self.set_freq(1, freq1)
        self.subdev[0].set_enable(True)  # enable transmitter
        self.subdev[1].set_enable(True)  # enable transmitter

        # ----------------------------------------------------------------
        # build two signal sources, interleave them, amplify and connect them to usrp

        sig0 = example_signal_0(self.usrp_rate)
        sig1 = example_signal_1(self.usrp_rate)

        intl = gr.interleave(gr.sizeof_gr_complex)
        self.connect(sig0, (intl, 0))
        self.connect(sig1, (intl, 1))

        # apply some gain
        if_gain = 10000
        ifamp = gr.multiply_const_cc(if_gain)

        # and wire them up
        self.connect(intl, ifamp, self.u)
Exemple #42
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self,
            "transmit_path",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt,
                     (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
Exemple #43
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__(self)

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

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

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

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

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

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

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

        # signal gain
        gain = gr.multiply_const_cc(4000)

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

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

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Exemple #44
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)  # Input signature
        )  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
Exemple #45
0
    def __init__(self, fd, M, sample_rate):
        gr.hier_block2.__init__(self, "Rayleigh Channel",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.M = M
        self.sample_rate = sample_rate
        n = range(1, M + 1)
        N = 4 * M + 2

        f_n = [fd * math.cos(2 * math.pi * x / N) for x in n]

        beta_n = [math.pi / M * x for x in n]

        a_n = [2 * math.cos(x) for x in beta_n]
        a_n.append(math.sqrt(2) * math.cos(math.pi / 4))
        a_n = [x * 2 / math.sqrt(N) for x in a_n]

        b_n = [2 * math.sin(x) for x in beta_n]
        b_n.append(math.sqrt(2) * math.sin(math.pi / 4))
        b_n = [x * 2 / math.sqrt(N) for x in b_n]

        f_n.append(fd)

        self.sin_real = [
            gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], a_n[i])
            for i in range(M + 1)
        ]
        self.sin_imag = [
            gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], b_n[i])
            for i in range(M + 1)
        ]

        self.add_real = gr.add_ff(1)
        self.add_imag = gr.add_ff(1)

        for i in range(M + 1):
            self.connect(self.sin_real[i], (self.add_real, i))

        for i in range(M + 1):
            self.connect(self.sin_imag[i], (self.add_imag, i))

        self.ftoc = gr.float_to_complex(1)

        self.connect(self.add_real, (self.ftoc, 0))
        self.connect(self.add_imag, (self.ftoc, 1))
        self.mulc = gr.multiply_const_cc((0.5))

        #self.divide = gr.divide_cc(1)
        #self.connect(self,(self.divide,0))
        #self.connect(self.ftoc,(self.divide,1))
        #self.connect(self.divide, self)
        self.prod = gr.multiply_cc(1)
        self.connect(self, (self.prod, 0))
        self.connect(self.ftoc, self.mulc, (self.prod, 1))
        self.connect(self.prod, self)
Exemple #46
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__ (self)

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

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

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

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

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

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

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

        # signal gain
        gain = gr.multiply_const_cc(4000)

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

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

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Exemple #47
0
 def __init__(self, **kwargs):
     gr.hier_block2.__init__(
         self,
         "generic_usrp_sink",
         gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
         gr.io_signature(0, 0, 0))  # Output signature
     _generic_usrp_base.__init__(self, **kwargs)
     if self._type == USRP1_TYPE:  #scale 0.0 to 1.0 input for usrp1
         self.connect(self, gr.multiply_const_cc((2**15) - 1), self._u)
     else:
         self.connect(self, self._u)
    def __init__(self,count, options, payload=''):
        gr.hier_block2.__init__(self, "transmit_path",
				gr.io_signature(0, 0, 0), # Input signature
				gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

	# the modulator itself
        self.ofdm_tx       = ofdm_mod(count,options, payload, msgq_limit=2, pad_for_usrp=False)

	# static value to make sure we do not exceed +-1 for the floats being sent to the sink
        self._norm         = options.norm        
        self.amp = gr.multiply_const_cc(self._norm)
        # setup basic connections
        self.connect(self.ofdm_tx, self.amp, self)
Exemple #49
0
   def __init__(self,fd,M,sample_rate):
       gr.hier_block2.__init__(self,"Rayleigh Channel",
                               gr.io_signature(1,1,gr.sizeof_gr_complex),
                               gr.io_signature(1,1,gr.sizeof_gr_complex))
       
       self.M = M
       self.sample_rate = sample_rate
       n=range(1,M+1)
       N = 4*M+2
       
       f_n= [fd*math.cos(2*math.pi*x/N) for x in n]
               
       beta_n = [math.pi/M*x for x in n]
       
       a_n = [2*math.cos(x) for x in beta_n]
       a_n.append(math.sqrt(2)*math.cos(math.pi/4))
       a_n = [x*2/math.sqrt(N) for x in a_n]
       
       
       b_n= [2*math.sin(x) for x in beta_n]
       b_n.append(math.sqrt(2)*math.sin(math.pi/4))
       b_n = [x*2/math.sqrt(N) for x in b_n]
       
       f_n.append(fd)
               
       self.sin_real = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],a_n[i]) for i in range(M+1)]
       self.sin_imag = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],b_n[i]) for i in range(M+1)]
           
       self.add_real = gr.add_ff(1)
       self.add_imag = gr.add_ff(1)
       
       for i in range (M+1):
           self.connect(self.sin_real[i],(self.add_real,i))
 
       for i in range (M+1):
           self.connect(self.sin_imag[i],(self.add_imag,i))          
           
       self.ftoc = gr.float_to_complex(1)
       
       self.connect(self.add_real,(self.ftoc,0))
       self.connect(self.add_imag,(self.ftoc,1))
       self.mulc = gr.multiply_const_cc((0.5))
       
       #self.divide = gr.divide_cc(1)
       #self.connect(self,(self.divide,0))
       #self.connect(self.ftoc,(self.divide,1))
       #self.connect(self.divide, self)
       self.prod = gr.multiply_cc(1)
       self.connect(self,(self.prod,0))
       self.connect(self.ftoc,self.mulc,(self.prod,1))
       self.connect(self.prod, self)
    def __init__(self, inputfile, callback, options):
        gr.top_block.__init__(self)

        # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py
        # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/pkt.py

        if options.dsp:
            self.src = audio.source(options.dsp_sample_rate, "", True)
        else:
            self.src = gr.wavfile_source( inputfile, False )

        self.iq_to_c = gr.float_to_complex()
        if options.dsp and options.wait:
            samples = options.dsp_sample_rate * options.wait
            self._head0 = gr.head(gr.sizeof_float, samples)
            self._head1 = gr.head(gr.sizeof_float, samples)
            self.connect( (self.src, 0), self._head0, (self.iq_to_c, 0) )
            self.connect( (self.src, 1), self._head1, (self.iq_to_c, 1) )
            if verbose: print "installed %d second head filter on dsp (%d samples at %d sps)" % (options.wait, samples, options.dsp_sample_rate)
        else:
            self.connect( (self.src, 0), (self.iq_to_c, 0) )
            self.connect( (self.src, 1), (self.iq_to_c, 1) )

        self.demodulator = blks2.gmsk_demod(samples_per_symbol=options.samples_per_symbol)
        self.pkt_queue   = blks2.demod_pkts( demodulator=self.demodulator, callback=callback, threshold=options.threshold )

        if options.carrier_frequency == 0:
            self.mixer = self.iq_to_c
        else:
            self.carrier  = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, - options.carrier_frequency, 1.0 )
            self.mixer    = gr.multiply_vcc(1)
            self.connect(self.iq_to_c, (self.mixer, 0) )
            self.connect(self.carrier, (self.mixer, 1) )

        self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude)
        self.connect(self.mixer, self.amp, self.pkt_queue)

        if options.debug_wavs:
            from myblks import debugwav
            self._dpass = debugwav("rx_passband", options)
            self._dbase = debugwav("rx_baseband", options)
            self.connect(self.iq_to_c, self._dpass)
            self.connect(self.mixer,   self._dbase)

        if options.debug_files:
            self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_passband.d_c")
            self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_baseband.d_c")
            self.connect(self.iq_to_c, self._dpassf)
            self.connect(self.mixer,   self._dbasef)
Exemple #51
0
    def __init__(self, options, need_padding=False):
        gr.hier_block2.__init__(
            self, "cs_mac", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)
        )

        # Create a logger
        self._logger = logging.getLogger("MAC(" + str(options.mac_address) + ")")

        # Extract options
        self._local_addr = options.mac_address
        self._need_padding = need_padding

        # Create queue for packets received from physical layer
        self._phy_rx_queue = Queue.Queue()

        # Create the ack_queue which the condition variable and thread use
        self.ack_queue = Queue.Queue()
        self.condition = threading.Condition()

        # Create physical layer implementation (modulator, demodulator)
        self._phy = cs434_hw4_phy.AVAILABLE[options.phy](options, lambda ok, payload: self._handle_recv(ok, payload))

        # Received samples are redirected to two places. GNU Radio doesn't
        # currently let us attach 2 blocks to a hierarchical block input, so
        # we first copy, then split.
        rx_dup = gr.kludge_copy(gr.sizeof_gr_complex)
        self.connect(self, rx_dup)

        # Create and connect carrier-sensing block
        self._phy_rx_probe = gr.probe_avg_mag_sqrd_c(options.cs_threshold, 0.001)
        self.connect(rx_dup, self._phy_rx_probe)

        # Construct receive chain: received packets are delivered via callback from PHY
        self.connect(rx_dup, self._phy)

        # For certain settings, we may need to 'pad' our
        # transmissions with a 0-powered signal when we
        # aren't actively transmitting a packet
        if need_padding:
            import cs434_hw4

            self._phy_tx_padder = cs434_hw4.channel_runner_cc()
        else:
            self._phy_tx_padder = gr.kludge_copy(gr.sizeof_gr_complex)

        # Construct transmit chain: packets are delivered to PHY via 'send_pkt()' method
        self._phy_tx_scale = gr.multiply_const_cc(options.tx_amplitude)
        self.connect(self._phy, self._phy_tx_scale, self._phy_tx_padder, self)
Exemple #52
0
    def __init__(self, options):
        """
    @param options: parsed raw.ofdm_params
    """

        self.params = ofdm_params(options)
        params = self.params

        gr.hier_block2.__init__(
            self,
            "ofdm_mod",
            gr.io_signature2(2, 2, gr.sizeof_gr_complex * params.data_tones,
                             gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        win = []  #[1 for i in range(self._fft_length)]
        # see gr_fft_vcc_fftw that it works differently if win = [1 1 1 ...]

        self.mapper = raw.ofdm_mapper(params.padded_carriers)
        self.preambles = digital.ofdm_insert_preamble(params.fft_length,
                                                      params.padded_preambles)
        self.ifft = gr.fft_vcc(params.fft_length, False, win, True)
        self.cp_adder = digital.ofdm_cyclic_prefixer(
            params.fft_length, params.fft_length + params.cp_length)
        self.scale = gr.multiply_const_cc(1.0 / math.sqrt(params.fft_length))

        self.connect((self, 0), self.mapper, (self.preambles, 0))
        self.connect((self, 1), (self.preambles, 1))
        self.connect(self.preambles, self.ifft, self.cp_adder, self.scale,
                     self)

        if options.log:
            self.connect(
                self.mapper,
                gr.file_sink(gr.sizeof_gr_complex * params.fft_length,
                             "tx-map.dat"))
            self.connect(
                self.preambles,
                gr.file_sink(gr.sizeof_gr_complex * params.fft_length,
                             "tx-pre.dat"))
            self.connect(
                self.ifft,
                gr.file_sink(gr.sizeof_gr_complex * params.fft_length,
                             "tx-ifft.dat"))
            self.connect(self.cp_adder,
                         gr.file_sink(gr.sizeof_gr_complex, "tx-cp.dat"))
Exemple #53
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=1e6,
                           help="set samplerate to RATE [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=1.8e9,
                           help="set center frequency to RATE [default=%default]")

        parser.add_option("-d", "--soft-decimate", type="eng_float", default=1,
                           help="decimate the given samplingrate further by a factor of [default=%default]")


        (options,values) = parser.parse_args()

        pspectrum_len = 1024
        nsamples = 512

        # build our flow graph
        input_rate = options.sample_rate
        soft_decimation = int(options.soft_decimate)
        center_freq = options.freq

        source = uhd.single_usrp_source(device_addr='type=usrp2',io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1)
        source.set_samp_rate(input_rate)
        source.set_gain(45,0)
        source.set_center_freq(center_freq,0)

        item_size = gr.sizeof_gr_complex

        dec  = gr.keep_one_in_n(item_size, soft_decimation)

        sink1 = spectrum_sink_c (panel, title="ESPRIT Spectrum", pspectrum_len=pspectrum_len,
                            sample_rate=input_rate / soft_decimation, baseband_freq=0,
                            ref_level=0, y_per_div=20, y_divs=10, m = 128, n = 6, nsamples = nsamples,
                            estimator='esprit')

        vbox.Add (sink1.win, 1, wx.EXPAND)
        #sink2 = spectrum_sink_c (panel, title="MUSIC Spectrum", pspectrum_len=pspectrum_len,
                            #sample_rate=input_rate / soft_decimation, baseband_freq=0,
                            #ref_level=0, y_per_div=20, y_divs=10, m = 64, n = 2, nsamples = nsamples,
                            #estimator='music')

        scale = gr.multiply_const_cc(30.0e3)
        #vbox.Add (sink2.win, 1, wx.EXPAND)
        self.connect(source,scale,sink1)
Exemple #54
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.tx_freq is not None:
            u = uhd_transmitter(options.args, options.bandwidth,
                                options.tx_freq, options.tx_gain, options.spec,
                                options.antenna, options.external,
                                options.verbose)
        elif options.outfile is not None:
            u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            raise SystemExit("--freq or --outfile must be specified\n")

        if options.infile is not None:
            tx = gr.file_source(gr.sizeof_gr_complex,
                                options.infile,
                                repeat=options.repeat)
        else:
            tx = ofdm_rxtx.TX(options)
            data_tones = tx.params.data_tones
            if options.char > 0:
                # read char from file
                data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
                # NOTE: we use repeat, assuming the file is long enough or properly aligned
                self.connect(
                    gr.file_source(gr.sizeof_char, options.txdata,
                                   repeat=True), gr.char_to_float(),
                    gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                    data)
            else:
                data = ofdm_rxtx.make_data(data_tones, options.size,
                                           options.txdata)
                if options.log:
                    self.connect(
                        data,
                        gr.file_sink(data_tones * gr.sizeof_gr_complex,
                                     'tx-data.dat'))

            self.connect(data, tx)
            self.sender = ofdm_rxtx.sender_thread(tx, options)

        if options.amp != 1:
            amp = gr.multiply_const_cc(options.amp)
            self.connect(tx, amp, u)
        else:
            self.connect(tx, u)
    def __init__(self, outputfile, options):
        gr.top_block.__init__(self)

        if options.dsp:
            self.dst = audio.sink( options.dsp_sample_rate )
        else:
            self.dst = gr.wavfile_sink(outputfile, 2, options.wav_sample_rate, 16)

        self.c_to_iq = gr.complex_to_float()
        self.connect( (self.c_to_iq, 0), (self.dst, 0))
        self.connect( (self.c_to_iq, 1), (self.dst, 1))

        # settings for the modulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py

        self.modulator = blks2.gmsk_mod(samples_per_symbol=options.samples_per_symbol)
        self.pkt_queue = blks2.mod_pkts( modulator=self.modulator )

        if options.carrier_frequency == 0:
            self.mixer = self.pkt_queue
        else:
            self.mixer   = gr.multiply_vcc(1)
            self.carrier = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, options.carrier_frequency, 1.0 )
            self.lowpass = gr.fir_filter_ccf(1, firdes.low_pass(1, 48000, 48000/(2*options.samples_per_symbol)+500, 500, firdes.WIN_HAMMING, 6.76))
            self.connect(self.pkt_queue, self.lowpass, (self.mixer, 0) )
            self.connect(self.carrier,   (self.mixer, 1) )

        self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude)
        self.connect(self.mixer, self.amp, self.c_to_iq)

        if options.debug_wavs:
            from myblks import debugwav
            self._dpassw = debugwav("tx_passband", options)
            self._dprefw = debugwav("tx_prefband", options)
            self._dbasew = debugwav("tx_baseband", options)
            self.connect(self.amp, self._dpassw)
            self.connect(self.lowpass, self._dbasew)
            self.connect(self.pkt_queue, self._dprefw)

        if options.debug_files:
            self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_passband.d_c")
            self._dpreff = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_prefband.d_c")
            self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_baseband.d_c")
            self.connect(self.amp, self._dpassf)
            self.connect(self.pkt_queue, self._dpreff)
            self.connect(self.lowpass, self._dbasef)
    def configure_cc1k(self):
        #self.disconnect_all()
        cordic_freq = 434845200
        data_rate = 38400
        gain = 0

        print "cordic_freq = %s" % (eng_notation.num_to_str(cordic_freq))

        self.data_rate = data_rate
        self.samples_per_symbol = 8
        self.fs = self.data_rate * self.samples_per_symbol
        payload_size = 128  # bytes

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "fs = ", eng_notation.num_to_str(self.fs)

        self.normal_gain = 8000

        dac_rate = self.u.dac_rate()

        self.interp = int(128e6 / self.samples_per_symbol / self.data_rate)
        print "usrp interp = ", self.interp
        self.fs = 128e6 / self.interp

        self.u.set_interp_rate(self.interp)

        # determine the daughterboard subdevice we're using
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, (1, 0)))
        self.subdev = usrp.selected_subdev(self.u, (1, 0))
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, cordic_freq)
        self.u.set_pga(0, gain)
        self.u.set_pga(1, gain)

        # transmitter
        self.packet_transmitter = cc1k_sos_pkt.cc1k_mod_pkts(
            self, spb=self.samples_per_symbol, msgq_limit=2)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        self.connect(self.packet_transmitter, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Exemple #57
0
    def __init__(self, options):
        gr.hier_block2.__init__(self, "transmit_path",
                        gr.io_signature(0, 0, 0),                    # Input signature
                        gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

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

        self._verbose            = options.verbose
        self._tx_amplitude       = options.tx_amplitude    # digital amplitude sent to USRP

        self.ofdm_tx = flex_ofdm_code.ofdm_mod(options, msgq_limit=1, pad_for_usrp=False)
        self.amp = gr.multiply_const_cc(1)
        self.set_tx_amplitude(self._tx_amplitude)

        if self._verbose:
            self._print_verbage()

        self.connect(self.ofdm_tx, self.amp, self)
Exemple #58
0
 def __init__(self,ampl_i,band,symbol_rate,sps):
     gr.hier_block2.__init__(self,"Channel",
                             gr.io_signature(1,1,gr.sizeof_gr_complex),
                             gr.io_signature(1,1,gr.sizeof_gr_complex))
     
     self.symbol_rate = symbol_rate
     self.sample_rate=symbol_rate*sps
     self.fading = False
     self.adder = gr.add_cc()
     self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, -42)
     self.ampl = gr.multiply_const_cc(ampl_i)
     self.taps = gr.firdes.low_pass_2 (1,280,band/2,5,80,gr.firdes.WIN_KAISER)
     self.filter=gr.fir_filter_ccf(1,self.taps)
     
     #Connects
     self.connect(self,self.filter,(self.adder,0))
     self.connect(self.noise, self.ampl, (self.adder,1))
     self.connect(self.adder, self)