Beispiel #1
0
    def __init__(self, options, msgq_limit=2, pad_for_usrp=True):
        """
	Hierarchical block for sending packets

        Packets to be sent are enqueued by calling send_pkt.
        The output is the complex modulated signal at baseband.

        @param options: pass modulation options from higher layers (fft length, occupied tones, etc.)
        @param msgq_limit: maximum number of messages in message queue
        @type msgq_limit: int
        @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
        """

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

        self._pad_for_usrp = pad_for_usrp
        self._modulation = options.modulation
        self._fft_length = options.fft_length
        self._occupied_tones = options.occupied_tones
        self._cp_length = options.cp_length

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

        # Use freq domain to get doubled-up known symbol for correlation in time domain
        zeros_on_left = int(
            math.ceil((self._fft_length - self._occupied_tones) / 2.0))
        ksfreq = known_symbols_4512_3[0:self._occupied_tones]
        for i in range(len(ksfreq)):
            if ((zeros_on_left + i) & 1):
                ksfreq[i] = 0

        # hard-coded known symbols
        preambles = (ksfreq, )

        padded_preambles = list()
        for pre in preambles:
            padded = self._fft_length * [
                0,
            ]
            padded[zeros_on_left:zeros_on_left + self._occupied_tones] = pre
            padded_preambles.append(padded)

        symbol_length = options.fft_length + options.cp_length

        mods = {
            "bpsk": 2,
            "qpsk": 4,
            "8psk": 8,
            "qam8": 8,
            "qam16": 16,
            "qam64": 64,
            "qam256": 256
        }
        arity = mods[self._modulation]

        rot = 1
        if self._modulation == "qpsk":
            rot = (0.707 + 0.707j)

        if (self._modulation.find("psk") >= 0):
            rotated_const = map(lambda pt: pt * rot,
                                psk.gray_constellation[arity])
        elif (self._modulation.find("qam") >= 0):
            rotated_const = map(lambda pt: pt * rot, qam.constellation[arity])
        #print rotated_const
        self._pkt_input = gr.ofdm_mapper_bcv(rotated_const, msgq_limit,
                                             options.occupied_tones,
                                             options.fft_length)

        self.preambles = gr.ofdm_insert_preamble(self._fft_length,
                                                 padded_preambles)
        self.ifft = gr.fft_vcc(self._fft_length, False, win, True)
        self.cp_adder = gr.ofdm_cyclic_prefixer(self._fft_length,
                                                symbol_length)
        self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length))

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

        if options.verbose:
            self._print_verbage()

        if options.log:
            self.connect(
                self._pkt_input,
                gr.file_sink(gr.sizeof_gr_complex * options.fft_length,
                             "ofdm_mapper_c.dat"))
            self.connect(
                self.preambles,
                gr.file_sink(gr.sizeof_gr_complex * options.fft_length,
                             "ofdm_preambles.dat"))
            self.connect(
                self.ifft,
                gr.file_sink(gr.sizeof_gr_complex * options.fft_length,
                             "ofdm_ifft_c.dat"))
            self.connect(
                self.cp_adder,
                gr.file_sink(gr.sizeof_gr_complex, "ofdm_cp_adder_c.dat"))
Beispiel #2
0
    def __init__(self, options, msgq_limit=2, pad_for_usrp=True):
        """
	Hierarchical block for sending packets

        Packets to be sent are enqueued by calling send_pkt.
        The output is the complex modulated signal at baseband.

        @param options: pass modulation options from higher layers (fft length, occupied tones, etc.)
        @param msgq_limit: maximum number of messages in message queue
        @type msgq_limit: int
        @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
        """

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

        self._pad_for_usrp = pad_for_usrp
        self._modulation = options.modulation
        self._fft_length = options.fft_length
        self._occupied_tones = options.occupied_tones
        self._cp_length = options.cp_length

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

        # Use freq domain to get doubled-up known symbol for correlation in time domain
        zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0))
        ksfreq = known_symbols_4512_3[0:self._occupied_tones]
        for i in range(len(ksfreq)):
            if((zeros_on_left + i) & 1):
                ksfreq[i] = 0

        # hard-coded known symbols
        preambles = (ksfreq,)
                
        padded_preambles = list()
        for pre in preambles:
            padded = self._fft_length*[0,]
            padded[zeros_on_left : zeros_on_left + self._occupied_tones] = pre
            padded_preambles.append(padded)
            
        symbol_length = options.fft_length + options.cp_length
        
        mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
        arity = mods[self._modulation]
        
        rot = 1
        if self._modulation == "qpsk":
            rot = (0.707+0.707j)
            
        if(self._modulation.find("psk") >= 0):
            rotated_const = map(lambda pt: pt * rot, psk.gray_constellation[arity])
        elif(self._modulation.find("qam") >= 0):
            rotated_const = map(lambda pt: pt * rot, qam.constellation[arity])
        #print rotated_const
        self._pkt_input = gr.ofdm_mapper_bcv(rotated_const, msgq_limit,
                                             options.occupied_tones, options.fft_length)
        
        self.preambles = gr.ofdm_insert_preamble(self._fft_length, padded_preambles)
        self.ifft = gr.fft_vcc(self._fft_length, False, win, True)
        self.cp_adder = gr.ofdm_cyclic_prefixer(self._fft_length, symbol_length)
        self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length))
        
        self.connect((self._pkt_input, 0), (self.preambles, 0))
        self.connect((self._pkt_input, 1), (self.preambles, 1))
        self.connect(self.preambles, self.ifft, self.cp_adder, self.scale, self)
        
        if options.verbose:
            self._print_verbage()

        if options.log:
            self.connect(self._pkt_input, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                       "ofdm_mapper_c.dat"))
            self.connect(self.preambles, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                      "ofdm_preambles.dat"))
            self.connect(self.ifft, gr.file_sink(gr.sizeof_gr_complex*options.fft_length,
                                                 "ofdm_ifft_c.dat"))
            self.connect(self.cp_adder, gr.file_sink(gr.sizeof_gr_complex,
                                                     "ofdm_cp_adder_c.dat"))
Beispiel #3
0
        def __init__(self):
		parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
		expert_grp = parser.add_option_group("Expert")
		parser.add_option("-s", "--size", type="eng_float", default=400,
			  help="set packet size [default=%default]")
		parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
			  help="set megabytes to transmit [default=%default]")
		parser.add_option("","--discontinuous", action="store_true", default=False,
			  help="enable discontinuous mode")
		(options, args) = parser.parse_args ()
		msgq_limit=2
		
                gr.top_block.__init__(self)
                padded_preambles = list()
                
                # Set of pre-defined parameters. In actual code this is passed as parameter in options
                #known_symb = [-1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1]
                known_symb = 1000 *[1,-1]
                fft_length = 512
                occupied_tones = 200
                cp_length = 128
                pad_for_usrp = True
                modulation = "qpsk"
                
                zeros_on_left= int(math.ceil((fft_length - occupied_tones)/2.0))
                ksfreq = known_symb[0:occupied_tones]
                preambles = (ksfreq,)
                print zeros_on_left
                for pre in preambles:
                        padded = fft_length*[0,]
                        padded[zeros_on_left : zeros_on_left + occupied_tones] = pre
                        padded_preambles.append(padded)
                        
                        
                symbol_length = fft_length + cp_length
		
		#mods returns the number of points in the constellation given the index as the mod type "bpsk" etc
		mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
		arity = mods[modulation]
		
		rot = 1
		if modulation == "qpsk":
		    rot = (0.707+0.707j)
		    
		if(modulation.find("psk") >= 0):#check if it is psk or qpsk, returns the position of string "psk"
		    rotated_const = map(lambda pt: pt * rot, psk.gray_constellation[arity])
		elif(modulation.find("qam") >= 0):
		    rotated_const = map(lambda pt: pt * rot, qam.constellation[arity])
		#print rotated_const
		
		self._pkt_input = gr.ofdm_mapper_bcv(rotated_const, msgq_limit,
						    occupied_tones,fft_length)
                self.preambles_2 = gr.ofdm_insert_preamble(fft_length,padded_preambles)
                
                #Setting up the user defined data to test the working of the blocks
                data1 = 512*[complex(2,3)] #How to generate complex modulated values
                twos = 511*[1]
                twos_arr = array('B',twos)
		data2 = array('B',[1])
		data2.extend(twos_arr)
                #print data
                
                
		self.data_src1 = gr.vector_source_c(data1,True,16)
		self.data_src2 = gr.vector_source_b(data2,True,1)
		self.sink_n  = gr.vector_sink_c(512)
		
		# End of data setting
		
		self.sink_file = gr.file_sink(512*gr.sizeof_gr_complex,'pad')
		v2s = gr.vector_to_stream(4096,1)
		
                self.connect((self._pkt_input,0),(self.preambles_2,0))
		self.connect((self._pkt_input,1),(self.preambles_2,1))
		self.connect((self.preambles_2,0),self.sink_n)
		self.connect((self.preambles_2,0),self.sink_file)