def test_001_t (self):
		# set up fg
		test_len = 1000
		packet_len = test_len
		pulse_send = (200,300,100)
		pulse_wait = (100,100)
		amplitude = 0.5
		
		num_skip = 5 # skip samples with skiphead
		num_xcorr = 300 # num of xcorrs to determine delay samples
		
		src = radar.signal_generator_sync_pulse_c(packet_len,pulse_send,pulse_wait,amplitude,"packet_len")
		head = blocks.head(8,test_len)
		skiphead = blocks.skiphead(8,num_skip)
		est = radar.estimator_sync_pulse_c(num_xcorr,"packet_len")
		res = radar.print_results()
		debug = blocks.message_debug()
		
		self.tb.connect(src,skiphead,head)
		self.tb.connect((head,0),(est,0)) # TX stream (undelayed but skiped)
		self.tb.connect((src,0),(est,1)) # RX stream (delayed but unskiped)
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')
		self.tb.run ()
		
		# check data
		msg = debug.get_message(0)
		num_skip_est = pmt.to_long(pmt.nth(1,pmt.nth(1,msg)))
		self.assertEqual(num_skip_est,num_skip)
Ejemplo n.º 2
0
    def handle_reset_frequency(self, msg_pmt):
        self.center_frequency = pmt.to_long(msg_pmt)

        ##################################################
        # Blocks
        ##################################################
        self.receiving_phy_0 = receiving_phy(
            block_id=block_id,
            constellation=constellation,
            develop_mode=develop_mode,
            matched_filter_coeff=matched_filter_coeff,
            mu=mu,
            preamble=preamble,
            rx_gain=rx_gain,
            samp_rate=samp_rate,
            sps=sps,
            threshold=threshold,
            usrp_device_address=usrp_device_address,
            center_frequency=center_frequency,
        )

        self.msg_connect((self.receiving_phy_0, 'rx_frame_out'),
                         (self, 'rx_frame_out'))
        self.msg_connect((self.receiving_phy_0, 'snr_out'), (self, 'snr_out'))
        self.msg_connect((self.receiving_phy_0, 'rx_power_out'),
                         (self, 'rx_power_out'))
        self.msg_connect((self, 'rx_switch_in'),
                         (self.receiving_phy_0, 'rx_switch_in'))
Ejemplo n.º 3
0
def count_bursts(data, tags, tsb_tag_key, vlen=1):
    lengthtags = [t for t in tags
                  if pmt.symbol_to_string(t.key) == tsb_tag_key]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}."
                .format(tsb_tag_key, tag.offset))
        lengths[tag.offset] = pmt.to_long(tag.value)*vlen
    in_burst = False
    in_packet = False
    packet_length = None
    packet_pos = None
    burst_count = 0
    for pos in range(len(data)):
        if pos in lengths:
            if in_packet:
                print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
                raise Exception("Received packet tag while in packet.")
            packet_pos = -1
            packet_length = lengths[pos]
            in_packet = True
            if not in_burst:
                burst_count += 1
            in_burst = True
        elif not in_packet:
            in_burst = False
        if in_packet:
            packet_pos += 1
            if packet_pos == packet_length-1:
                in_packet = False
                packet_pos = None
    return burst_count
Ejemplo n.º 4
0
def count_bursts(data, tags, lengthtagname, vlen=1):
    lengthtags = [t for t in tags
                  if pmt.symbol_to_string(t.key) == lengthtagname]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}."
                .format(lengthtagname, tag.offset))
        lengths[tag.offset] = pmt.to_long(tag.value)*vlen
    in_burst = False
    in_packet = False
    packet_length = None
    packet_pos = None
    burst_count = 0
    for pos in range(len(data)):
        if pos in lengths:
            if in_packet:
                print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
                raise StandardError("Received packet tag while in packet.")
            packet_pos = -1
            packet_length = lengths[pos]
            in_packet = True
            if not in_burst:
                burst_count += 1
            in_burst = True
        elif not in_packet:
            in_burst = False
        if in_packet:
            packet_pos += 1
            if packet_pos == packet_length-1:
                in_packet = False
                packet_pos = None
    return burst_count
Ejemplo n.º 5
0
    def write_data(self, msg):
        snr = pmt.to_double(pmt.dict_ref(msg, pmt.intern("snr"), pmt.from_double(0)))
        encoding = pmt.to_long(pmt.dict_ref(msg, pmt.intern("encoding"), pmt.from_long(0)))

        time_now = time() * 1000
        delay = str(time_now - self.last_time)
        self.last_time = time_now


        if self.snr_file != "":
            f_snr = open(self.snr_file, 'a')
            f_snr.write(str(snr) + '\n')
            f_snr.close()

        if self.enc_file != "":
            f_enc = open(self.enc_file, 'a')    
            f_enc.write(str(encoding) + '\n')
            f_enc.close()

        if self.delay_file != "":
            f_delay = open(self.delay_file, 'a')
            f_delay.write(delay + '\n')
            f_delay.close()

        if self.debug:
            print("SNR:" + str(snr))
            print("Encoding:" + str(encoding))
            print("Delay in millis: " + delay)
Ejemplo n.º 6
0
 def test14(self):
     const = self.MAXINT32 - 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     self.assertEqual(const,pmt.to_long(deser))
    def nodeid_handler_method(self, msg):
        self.nodeid = pmt.to_long(msg)
        pmt_to_send = pmt.make_dict()

        attributes = pmt.make_dict()
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("nodeID"),
                                  pmt.from_long(self.nodeid))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("nodeMac"),
                                  pmt.intern(self.mac))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("nodeIp"),
                                  pmt.intern(self.ip))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("latitude"),
                                  pmt.from_double(self.latitude))
        attributes = pmt.dict_add(attributes,
                                  pmt.string_to_symbol("longitude"),
                                  pmt.from_double(self.longitude))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("nodeType"),
                                  pmt.from_long(1))

        command = pmt.make_dict()
        command = pmt.dict_add(command, pmt.string_to_symbol("attributes"),
                               attributes)

        pmt_to_send = pmt.dict_add(pmt_to_send,
                                   pmt.string_to_symbol("NodeParam"), command)

        serialized_pmt = pmt.serialize_str(pmt_to_send)

        #print pmt_to_send

        UDP_IP = self.host
        UDP_PORT = self.port

        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(serialized_pmt, (UDP_IP, UDP_PORT))
Ejemplo n.º 8
0
    def test_003_frame_detect(self):
        alpha = 3.
        average_len = 8
        frame_len = 25
        backoff_len = 4
        tag_key = 'enertest'
        # set up fg
        detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key)

        data = np.zeros(100)
        data[50:] = 100
        src = blocks.vector_source_c(data)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, detector, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        tags = snk.tags()

        for t in tags:
            print 'srcid {}, key {}, offset {}, value {}'.format(t.srcid, t.key, t.offset, t.value)

        p = tags[0].offset
        self.assertEqual(p, 0)
        v = pmt.to_long(tags[0].value)
        fl = frame_len + 2 * backoff_len
        self.assertEqual(int(v), int(fl))

        self.assertComplexTuplesAlmostEqual(res, data[44:44 + len(res)])
 def test_001b_shifted (self):
     """ Same as before, but shifted, because that's the normal mode in OFDM Rx """
     fft_len = 16
     tx_symbols = (
         0, 0, 0, 0, 0,  0,  1,  2,    0,   3, 4,   5,  0, 0, 0, 0,
         0, 0, 0, 0, 6, 1j,  7,  8,    0,   9, 10, 1j, 11, 0, 0, 0,
         0, 0, 0, 0, 0, 12, 13, 14,    0,  15, 16, 17,  0, 0, 0, 0,
     )
     expected_result = tuple(range(18))
     occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name)
     sink = blocks.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Ejemplo n.º 10
0
 def test_003_channel_no_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset),
                      tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.c32vector_elements(tag.value), channel)
     self.assertEqual(sink_chanest.data(), channel)
Ejemplo n.º 11
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude)
     add = blocks.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = blocks.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
Ejemplo n.º 12
0
    def test_001_t(self):
        # set up fg
        test_len = 1000
        packet_len = test_len
        pulse_send = (200, 300, 100)
        pulse_wait = (100, 100)
        amplitude = 0.5

        num_skip = 5  # skip samples with skiphead
        num_xcorr = 300  # num of xcorrs to determine delay samples

        src = radar.signal_generator_sync_pulse_c(packet_len, pulse_send,
                                                  pulse_wait, amplitude,
                                                  "packet_len")
        head = blocks.head(8, test_len)
        skiphead = blocks.skiphead(8, num_skip)
        est = radar.estimator_sync_pulse_c(num_xcorr, "packet_len")
        res = radar.print_results()
        debug = blocks.message_debug()

        self.tb.connect(src, skiphead, head)
        self.tb.connect((head, 0),
                        (est, 0))  # TX stream (undelayed but skiped)
        self.tb.connect((src, 0), (est, 1))  # RX stream (delayed but unskiped)
        self.tb.msg_connect(est, 'Msg out', res, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', debug, 'store')
        self.tb.run()

        # check data
        msg = debug.get_message(0)
        num_skip_est = pmt.to_long(pmt.nth(1, pmt.nth(1, msg)))
        self.assertEqual(num_skip_est, num_skip)
Ejemplo n.º 13
0
    def test_005_long_frame(self):
        alpha = 3.
        average_len = 32
        frame_len = 5000
        backoff_len = 2 * average_len
        tag_key = 'enertest'
        # set up fg
        detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key)

        test_frame = np.zeros(frame_len + 2 * backoff_len)
        test_frame[backoff_len:-backoff_len] = 100.
        data = np.zeros(10 * frame_len)
        p = 6 * average_len
        data[p:p + len(test_frame)] = test_frame

        src = blocks.vector_source_c(data)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, detector, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        # make sure output is a multiple of average_len!
        tags = snk.tags()
        for t in tags:
            print 'srcid {}, key {}, offset {}, value {}'.format(t.srcid, t.key, t.offset, t.value)

        p = tags[0].offset
        self.assertEqual(p, 0)
        v = pmt.to_long(tags[0].value)
        fl = frame_len + 2 * backoff_len
        self.assertEqual(int(v), int(fl))
        self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)
Ejemplo n.º 14
0
	def handle_msg(self, msg):
		if(pmt.is_tuple(msg)):
			t = pmt.to_long(pmt.tuple_ref(msg, 0))
			m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
			de = DataEvent([t, m])
			wx.PostEvent(self.panel, de)
			del de
Ejemplo n.º 15
0
def vectors_to_packets(data, tags, tsb_tag_key, vlen=1):
    lengthtags = [t for t in tags
                  if pmt.symbol_to_string(t.key) == tsb_tag_key]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}."
                .format(tsb_tag_key, tag.offset))
        lengths[tag.offset] = pmt.to_long(tag.value)*vlen
    if 0 not in lengths:
        raise ValueError("There is no tag with key {0} and an offset of 0"
                         .format(tsb_tag_key))
    pos = 0
    packets = []
    while pos < len(data):
        if pos not in lengths:
            raise ValueError("There is no tag with key {0} and an offset of {1}."
                             "We were expecting one."
                             .format(tsb_tag_key, pos))
        length = lengths[pos]
        if length == 0:
            raise ValueError("Packets cannot have zero length.")
        if pos+length > len(data):
            raise ValueError("The final packet is incomplete.")
        packets.append(data[pos: pos+length])
        pos += length
    return packets
Ejemplo n.º 16
0
 def test_006_channel_and_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0,  1,  0, 1,  0,  -1, 0, 1,   0, -1,   0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0,  1, -1, 1,  -1,  1, 0, 1,  -1, -1,  -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp  = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(sink.data(), tuple(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
Ejemplo n.º 17
0
 def test_004_channel_no_carroffset_1sym (self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0)
     #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     self.assertEqual(sink_chanest.data(), channel)
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.c32vector_elements(tag.value), channel)
Ejemplo n.º 18
0
 def test14(self):
     const = self.MAXINT32 - 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     self.assertEqual(const, pmt.to_long(deser))
Ejemplo n.º 19
0
 def test_005_packet_len_tag (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                   0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                   0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     expected_result = tuple(range(1, 16))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     tag2 = gr.tag_t()
     tag2.offset = 0
     tag2.key = pmt.string_to_symbol("packet_len")
     tag2.value = pmt.from_long(len(expected_result))
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag, tag2))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "packet_len", 0, "", False)
     sink = blocks.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.symbol_to_string(result_tag.key), "packet_len")
     self.assertEqual(pmt.to_long(result_tag.value), len(expected_result))
Ejemplo n.º 20
0
 def handle_msg(self, msg):
     if (pmt.is_tuple(msg)):
         t = pmt.to_long(pmt.tuple_ref(msg, 0))
         m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
         de = DataEvent([t, m])
         wx.PostEvent(self.panel, de)
         del de
Ejemplo n.º 21
0
 def test_001b_shifted (self):
     """ Same as before, but shifted, because that's the normal mode in OFDM Rx """
     fft_len = 16
     tx_symbols = (
         0, 0, 0, 0, 0,  0,  1,  2,    0,   3, 4,   5,  0, 0, 0, 0,
         0, 0, 0, 0, 6, 1j,  7,  8,    0,   9, 10, 1j, 11, 0, 0, 0,
         0, 0, 0, 0, 0, 12, 13, 14,    0,  15, 16, 17,  0, 0, 0, 0,
     )
     expected_result = tuple(range(18))
     occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name)
     sink = blocks.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Ejemplo n.º 22
0
 def test_004_channel_no_carroffset_1sym(self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0)
     #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     self.assertEqual(sink_chanest.data(), channel)
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.c32vector_elements(tag.value), channel)
Ejemplo n.º 23
0
    def work(self, input_items, output_items):
        in0 = input_items[0]
        out = output_items[0]
        out[:] = in0[:]


        nread = self.nitems_read(0) #number of items read on port 0
        ninput_items = len(in0)

        eob = pmt.string_to_symbol("tx_eob")
        sob = pmt.string_to_symbol("tx_sob")
        pan = pmt.string_to_symbol("pdu_length")
        value = pmt.from_bool(1)
        lng = pmt.from_long(8192)
        source = pmt.string_to_symbol("add_uhd_tag")

        tags = self.get_tags_in_range(0, nread, nread+ninput_items)
        print "total input items : " + str(ninput_items)
        for tag in tags:

            #print "key : " + str(tag.key)
            if str(tag.key) == "pdu_length":

                #print "Found burst start at offset : " + str(tag.offset) + " with value : " + str(tag.value)
                #print " -> Injecting tag tx_sob @" + str(tag.offset)
                #print " -> Injecting tag tx_eob @" + str(tag.offset + pmt.to_long(tag.value) -1)
                self.add_item_tag(0, tag.offset, sob, value, source)
                self.add_item_tag(0, tag.offset + pmt.to_long(tag.value) -1, eob, value, source)



        return len(out)
Ejemplo n.º 24
0
 def test_006_channel_and_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = list(range(fft_len))
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(
         sink.data(),
         tuple(
             numpy.multiply(shift_tuple(data_symbol, carr_offset),
                            channel)))
Ejemplo n.º 25
0
def vectors_to_packets(data, tags, tsb_tag_key, vlen=1):
    lengthtags = [
        t for t in tags if pmt.symbol_to_string(t.key) == tsb_tag_key
    ]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}.".
                format(tsb_tag_key, tag.offset))
        lengths[tag.offset] = pmt.to_long(tag.value) * vlen
    if 0 not in lengths:
        raise ValueError(
            "There is no tag with key {0} and an offset of 0".format(
                tsb_tag_key))
    pos = 0
    packets = []
    while pos < len(data):
        if pos not in lengths:
            raise ValueError(
                "There is no tag with key {0} and an offset of {1}."
                "We were expecting one.".format(tsb_tag_key, pos))
        length = lengths[pos]
        if length == 0:
            raise ValueError("Packets cannot have zero length.")
        if pos + length > len(data):
            raise ValueError("The final packet is incomplete.")
        packets.append(data[pos:pos + length])
        pos += length
    return packets
Ejemplo n.º 26
0
    def test_004_frames(self):
        alpha = 3.
        average_len = 8
        frame_len = 25
        backoff_len = 2 * average_len
        tag_key = 'enertest'
        # set up fg
        detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key)

        test_frame = np.zeros(frame_len + 2 * backoff_len)
        test_frame[backoff_len:-backoff_len] = 100.
        data = np.zeros(1000)
        p = 6 * average_len
        data[p:p + len(test_frame)] = test_frame
        p = 60 * average_len
        data[p:p + len(test_frame)] = test_frame
        ref = np.tile(test_frame, 2)

        src = blocks.vector_source_c(data)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, detector, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        # make sure output is a multiple of average_len!
        tags = snk.tags()

        p = tags[0].offset
        self.assertEqual(p, 0)
        v = pmt.to_long(tags[0].value)
        fl = frame_len + 2 * backoff_len
        self.assertEqual(int(v), int(fl))
        self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)
Ejemplo n.º 27
0
 def test_003_channel_no_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j,  1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.c32vector_elements(tag.value), channel)
     self.assertEqual(sink_chanest.data(), channel)
 def test_005_packet_len_tag (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                   0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                   0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     expected_result = tuple(range(1, 16))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     tag2 = gr.tag_t()
     tag2.offset = 0
     tag2.key = pmt.string_to_symbol("packet_len")
     tag2.value = pmt.from_long(len(expected_result))
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag, tag2))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "packet_len", 0, "", False)
     sink = blocks.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.symbol_to_string(result_tag.key), "packet_len")
     self.assertEqual(pmt.to_long(result_tag.value), len(expected_result))
Ejemplo n.º 29
0
    def handle_msg(self, msg):
        if(pmt.is_tuple(msg)):
            t = pmt.to_long(pmt.tuple_ref(msg, 0))
            m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))

            if (t==0):     #program information
                msg = unicode(m, errors='replace')
                self.stationID = msg
Ejemplo n.º 30
0
 def test17(self):
     const = self.MININT32 + 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     x_long = pmt.to_long(deser)
     self.assertEqual(const, x_long)
Ejemplo n.º 31
0
 def test17(self):
     const = self.MININT32 + 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     x_long = pmt.to_long(deser)
     self.assertEqual(const, x_long)
Ejemplo n.º 32
0
 def handle_msg(self, msg_pmt):
     """ Receiver a int on the input port, and print it out. """
     print "Message Handler Called"
     # Collect message, convert to Python format:
     newIndex = pmt.to_long(msg_pmt)
     print "Got New Message: "+str(newIndex)
     print id(self)
     # Change output to new from message
     self.set_output_index(newIndex)
Ejemplo n.º 33
0
    def handle_msg(self, msg):

        if (not pmt.is_tuple(msg)):
            return

        msg_type = pmt.to_long(pmt.tuple_ref(msg, 0))
        msg = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
        msg = msg

        self.msg_signal.emit(msg_type, msg)
Ejemplo n.º 34
0
	def act_prot_in(self, msg): # {{{
		if self.coord == False: # Coord already knows the current MAC protocol
			portid = pmt.to_long(msg)

			msg = "portid" + str(portid)
			self.message_port_pub(self.msg_port_ctrl_out, pmt.string_to_symbol(msg))
			if portid == 0:
				logging.info("Active protocol: CSMA/CA")
			elif portid == 1:
				logging.info("Active protocol: TDMA")
Ejemplo n.º 35
0
    def test_packet_parse_default(self):
        ac = packet_utils.default_access_code
        length = '0000000000000001'

        hdr_format_1bps = digital.header_format_default(ac, 0)
        hdr_format_4bps = digital.header_format_default(ac, 0, 4)

        ac_bits = [int(x) & 1 for x in ac]
        length_bits = [int(x) & 1 for x in length]
        header_bits = ac_bits + length_bits + length_bits

        src_hdr = blocks.vector_source_b(header_bits)

        parser_1bps = digital.protocol_parser_b(hdr_format_1bps)
        parser_4bps = digital.protocol_parser_b(hdr_format_4bps)

        snk_hdr_1bps = blocks.message_debug()
        snk_hdr_4bps = blocks.message_debug()

        self.tb.connect(src_hdr, parser_1bps)
        self.tb.connect(src_hdr, parser_4bps)

        self.tb.msg_connect(parser_1bps, 'info', snk_hdr_1bps, 'store')
        self.tb.msg_connect(parser_4bps, 'info', snk_hdr_4bps, 'store')

        self.tb.start()
        while (snk_hdr_1bps.num_messages() < 1) and (snk_hdr_4bps.num_messages() < 1):
            time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        result_1bps = snk_hdr_1bps.get_message(0)
        result_4bps = snk_hdr_4bps.get_message(0)

        self.assertTrue(pmt.dict_has_key(
            result_1bps, pmt.intern('payload symbols')))
        self.assertEqual(pmt.to_long(pmt.dict_ref(
            result_1bps, pmt.intern('payload symbols'), pmt.PMT_F)), 8)

        self.assertTrue(pmt.dict_has_key(
            result_4bps, pmt.intern('payload symbols')))
        self.assertEqual(pmt.to_long(pmt.dict_ref(
            result_4bps, pmt.intern('payload symbols'), pmt.PMT_F)), 2)
Ejemplo n.º 36
0
 def handle_msg(self, msg):
     f = open("songs.txt", "w")
     if(pmt.is_tuple(msg)):
         t = pmt.to_long(pmt.tuple_ref(msg, 0))
         m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
         print("message:", m)
         de = DataEvent([t, m])
         f.write(de,"w"); 
         del de
     f.close()
Ejemplo n.º 37
0
 def tag_propagation(self, ninput_items):
     self.set_tag_propagation_policy(0)
     nread = self.nitems_read(0)  #number of items read on port 0
     tags = self.get_tags_in_range(0, nread, nread + ninput_items)
     key = pmt.intern("packet_len")
     if tags:
         for i in range(len(tags)):
             offset = tags[i].offset * self.factor
             value = pmt.from_long(pmt.to_long(tags[i].value) * self.factor)
             self.add_item_tag(0, offset, key, value)
Ejemplo n.º 38
0
 def test18(self):
     if(self.sizeof_long <= 4):
         return
     const = self.MININT32 - 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     x_long = pmt.to_long(deser)
     self.assertEqual(const, x_long)
Ejemplo n.º 39
0
 def test_001_offset_2sym(self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol("test_tag_1")
     tag1.value = pmt.from_long(23)
     tag2 = gr.tag_t()
     tag2.offset = 2
     tag2.key = pmt.string_to_symbol("test_tag_2")
     tag2.value = pmt.from_long(42)
     src = blocks.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
         'ofdm_sync_carr_offset': False,
         'test_tag_1': False,
         'test_tag_2': False
     }
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
Ejemplo n.º 40
0
 def test_001_offset_2sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol("test_tag_1")
     tag1.value = pmt.from_long(23)
     tag2 = gr.tag_t()
     tag2.offset = 2
     tag2.key = pmt.string_to_symbol("test_tag_2")
     tag2.value = pmt.from_long(42)
     src = blocks.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
             'ofdm_sync_carr_offset': False,
             'test_tag_1': False,
             'test_tag_2': False
     }
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
Ejemplo n.º 41
0
 def handler(self, rds_data):
     msg_type = pmt.to_long(pmt.tuple_ref(rds_data, 0))
     msg = pmt.symbol_to_string(pmt.tuple_ref(rds_data, 1))
     if msg_type == 4:
         self.radio_text.setText(msg.strip())
     elif msg_type == 1:
         self.station_name.setText(msg)
     elif msg_type == 0:
         self.program_info.setText(callsign(msg))
     elif msg_type == 3:
         self.flags.update(msg)
Ejemplo n.º 42
0
 def handler(self, rds_data):
     msg_type = pmt.to_long(pmt.tuple_ref(rds_data, 0))
     msg = pmt.symbol_to_string(pmt.tuple_ref(rds_data, 1))
     if msg_type == 4:
         self.radio_text.setText(msg.strip())
     elif msg_type == 1:
         self.station_name.setText(msg)
     elif msg_type == 0:
         self.program_info.setText(callsign(msg))
     elif msg_type == 3:
         self.flags.update(msg)
Ejemplo n.º 43
0
    def work(self, input_items, output_items):
        num_input_items = len(input_items[0])
        nread = self.nitems_read(0)
        tags = self.get_tags_in_range(0, nread, nread + num_input_items)
        for tag in tags:
            if pmt.symbol_to_string(tag.key) == 'pa_ramp':
                tx_on = pmt.to_long(tag.value)
                if tx_on == 1:
                    self.tx_on_at = tag.offset
                else:
                    self.tx_off_at = tag.offset

        return num_input_items
 def set_signal_number_msg(self, msg):
     if pmt.is_pair(msg):
         key = pmt.car(msg)
         val = pmt.cdr(msg)
         if pmt.eq(key, pmt.string_to_symbol("signal_number_msg")):
             if pmt.is_integer(val):
                 self.n = pmt.to_long(val)
             else:
                 print("DoA Esprit: Not an integer")
         else:
             print("DoA Esprit: Key not 'signal_number_msg'")
     else:
         print("DoA Esprit: Not a tuple")
Ejemplo n.º 45
0
    def work(self, input_items, output_items):
        num_input_items = len(input_items[0])
        nread = self.nitems_read(0)
        tags = self.get_tags_in_range(0, nread, nread+num_input_items);
        for tag in tags:
            if pmt.symbol_to_string(tag.key) == 'pa_ramp':
                tx_on = pmt.to_long(tag.value)
                if tx_on == 1:
                    self.tx_on_at = tag.offset
                else:
                    self.tx_off_at = tag.offset
                

        return num_input_items
Ejemplo n.º 46
0
 def test_002_offset_1sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Difference to previous test is, it only uses one synchronisation symbol. """
     fft_len = 16
     carr_offset = -2
     # This will not correct for +2 because it thinks carrier 14 is used
     # (because of interpolation)
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     # 17 is out of bounds!
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1, 0, 17)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
Ejemplo n.º 47
0
 def test_002_offset_1sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Difference to previous test is, it only uses one synchronisation symbol. """
     fft_len = 16
     carr_offset = -2
     # This will not correct for +2 because it thinks carrier 14 is used
     # (because of interpolation)
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     # 17 is out of bounds!
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1, 0, 17)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
Ejemplo n.º 48
0
 def test_002_simpledfe (self):
     """ Use the simple DFE equalizer. """
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0
                -1, -1, 0, 2, -1, 2, 0, -1, # 8
                -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols)
                -1, -1, 1, 1, -1, 0, 2, -1] # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data]
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = (
             [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], []
     )
     equalizer = digital.ofdm_equalizer_simpledfe(
         fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01
     )
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly...
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0  # ...and again here.
     ]
     for idx in range(fft_len, 2*fft_len):
         channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5))
         idx2 = idx+2*fft_len
         channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5))
     len_tag_key = "frame_len"
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(4)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len])
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()]
     self.assertEqual(tx_data, rx_data)
     for tag in sink.tags():
         if pmt.symbol_to_string(tag.key) == len_tag_key:
             self.assertEqual(pmt.to_long(tag.value), 4)
         if pmt.symbol_to_string(tag.key) == "ofdm_sync_chan_taps":
             self.assertComplexTuplesAlmostEqual(list(pmt.c32vector_elements(tag.value)), channel[-fft_len:], places=1)
Ejemplo n.º 49
0
 def test_002_simpledfe (self):
     """ Use the simple DFE equalizer. """
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0
                -1, -1, 0, 2, -1, 2, 0, -1, # 8
                -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols)
                -1, -1, 1, 1, -1, 0, 2, -1] # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data]
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = (
             [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], []
     )
     equalizer = digital.ofdm_equalizer_simpledfe(
         fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01
     )
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly...
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0  # ...and again here.
     ]
     for idx in range(fft_len, 2*fft_len):
         channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5))
         idx2 = idx+2*fft_len
         channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5))
     len_tag_key = "frame_len"
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(4)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len])
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()]
     self.assertEqual(tx_data, rx_data)
     for tag in sink.tags():
         if pmt.symbol_to_string(tag.key) == len_tag_key:
             self.assertEqual(pmt.to_long(tag.value), 4)
         if pmt.symbol_to_string(tag.key) == "ofdm_sync_chan_taps":
             self.assertComplexTuplesAlmostEqual(list(pmt.c32vector_elements(tag.value)), channel[-fft_len:], places=1)
Ejemplo n.º 50
0
    def test_001_t(self):
        fftlen = 128
        cell_id = 124
        taps = filter.optfir.low_pass(1, fftlen*15e3, 472.5e3, 900e3, 0.2, 40)
        samples = t.get_mod_frame(cell_id, 6, 1, fftlen)
        samps = np.tile(samples[0], 5)

        src = blocks.vector_source_c(samps, repeat=False, vlen=1)
        fir = filter.fir_filter_ccc(fftlen/64, taps)
        sync = lte.mimo_pss_coarse_sync(4, 1)
        dbg0 = blocks.message_debug()
        dbg1 = blocks.message_debug()
        dbg2 = blocks.message_debug()

        self.tb.connect(src, fir, sync)
        self.tb.msg_connect((sync, 'control'), (dbg0, 'store'))
        self.tb.msg_connect((sync, 'N_id_2'), (dbg1, 'store'))
        self.tb.msg_connect((sync, 'coarse_pos'), (dbg2, 'store'))
        # set up fg
        self.tb.run()
        # check data
        self.assertEqual(pmt.to_long(dbg1.get_message(0)), int(cell_id % 3))

        ctrl_res = pmt.to_bool(dbg0.get_message(0))
        assert ctrl_res

        offset = 10 + 5 * 9 + 6 * fftlen
        print(offset)

        # print()
        pos = pmt.to_long(dbg2.get_message(0))
        print(pos)
        print(pos * 2 - (len(taps) // 2))
        import matplotlib.pyplot as plt
        plt.plot(np.abs(samps))
        plt.show()
Ejemplo n.º 51
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = []

        seq = lte.encode_nrz(lte.generate_pn_sequence(1920, cell_id))

        pmt_list = pmt.list1(pmt.from_double(seq[0]))
        for i in range(len(seq) - 1):
            pmt_list = pmt.list_add(pmt_list, pmt.from_double(seq[i+1]))
        self.message_port_pub(self.msg_buf_out, pmt_list)
Ejemplo n.º 52
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = []

        seq = lte.encode_nrz(lte.generate_pn_sequence(1920, cell_id))

        pmt_list = pmt.list1(pmt.from_double(seq[0]))
        for i in range(len(seq) - 1):
            pmt_list = pmt.list_add(pmt_list, pmt.from_double(seq[i + 1]))
        self.message_port_pub(self.msg_buf_out, pmt_list)
 def wait_tags(self, in0, out):
     n_read = self.nitems_read(0) #Number of items read on port 0
     tags = self.get_tags_in_range(0, n_read, n_read+self.n_input_items)
     key = pmt.intern("pdu_len")
     if tags:
         for i in range(len(tags)):
             if (pmt.eq(key, tags[i].key)):
                 self.offset_rel = tags[i].offset - n_read 
                 self.pdu_len = pmt.to_long(tags[i].value) * 8
                 self.add_item_tag(0, self.offset_tag, key,  pmt.from_long(self.pdu_len))
                 self.offset_tag = self.offset_tag + self.pdu_len
                 self.num = 1
                 break
         self.consume(0,self.offset_rel)
     else:
         self.num = 0
Ejemplo n.º 54
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = pmt.make_vector(10, pmt.make_vector(32, pmt.from_double(0.0)))
        for ns in range(10):
            scr = utils.get_pcfich_scrambling_sequence(cell_id, ns)
            scr = utils.encode_nrz(scr)
            pmt_seq = pmt.make_vector(len(scr), pmt.from_double(0.0))
            for i in range(len(scr)):
                pmt.vector_set(pmt_seq, i, pmt.from_double(scr[i]))
            pmt.vector_set(seqs, ns, pmt_seq)
        self.message_port_pub(self.msg_buf_out, seqs)
Ejemplo n.º 55
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if cell_id == self.cell_id:
            return
        else:
            self.cell_id = cell_id

        print self.name(), " cell_id = ", self.cell_id, " generating RS map!"
        #print "generate pilot map: cell_id = " + str(cell_id) + "\tant_port = " + str(self.ant_port)
        Ncp = 1  # Always 1 for our purposes --> thus it's hard coded
        [rs_poss, rs_vals] = self.frame_pilot_value_and_position(self.N_rb_dl, cell_id, Ncp, self.ant_port)

        pmt_rs = self.rs_pos_to_pmt(rs_poss)
        pmt_vals = self.rs_val_to_pmt(rs_vals)
        pmt_pilots = pmt.list2(pmt_rs, pmt_vals)

        self.message_port_pub(self.msg_buf_out, pmt_pilots)
Ejemplo n.º 56
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = pmt.make_vector(10, pmt.make_vector(32, pmt.from_double(0.0)))
        for ns in range(10):
            scr = utils.get_pcfich_scrambling_sequence(cell_id, ns)
            scr = utils.encode_nrz(scr)
            pmt_seq = pmt.make_vector(len(scr), pmt.from_double(0.0))
            for i in range(len(scr)):
                pmt.vector_set(pmt_seq, i, pmt.from_double(scr[i]))
            pmt.vector_set(seqs, ns, pmt_seq)
        self.message_port_pub(self.msg_buf_out, seqs)
Ejemplo n.º 57
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if cell_id == self.cell_id:
            return
        else:
            self.cell_id = cell_id

        print self.name(), " cell_id = ", self.cell_id, " generating RS map!"
        #print "generate pilot map: cell_id = " + str(cell_id) + "\tant_port = " + str(self.ant_port)
        Ncp = 1  # Always 1 for our purposes --> thus it's hard coded
        [rs_poss, rs_vals] = self.frame_pilot_value_and_position(self.N_rb_dl, cell_id, Ncp, self.ant_port)

        pmt_rs = self.rs_pos_to_pmt(rs_poss)
        pmt_vals = self.rs_val_to_pmt(rs_vals)
        pmt_pilots = pmt.list2(pmt_rs, pmt_vals)

        self.message_port_pub(self.msg_buf_out, pmt_pilots)
 def test_001(self):
     payload = "test packet"     # payload length is 11 bytes
     header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped)
     packet = header + payload
     pad = (0,) * 64
     src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad
     expected = tuple(map(int, src_data[9+32:-len(pad)]))
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_bb_ts("1011", 0, "sync")
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     result_tags = dst.tags()
     self.assertEqual(len(result_data), len(payload)*8)
     self.assertEqual(result_tags[0].offset, 0)
     self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8)
     self.assertEqual(result_data, expected)
 def test_002(self):
     payload = "test packet"     # payload length is 11 bytes
     header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped)
     packet = header + payload
     pad = (0,) * 64
     src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad
     src_floats = tuple(2*b-1 for b in src_data) # convert to binary antipodal symbols (-1,1)
     expected = src_floats[9+32:-len(pad)]
     src = blocks.vector_source_f(src_floats)
     op = digital.correlate_access_code_ff_ts("1011", 0, "sync")
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     result_tags = dst.tags()
     self.assertEqual(len(result_data), len(payload)*8)
     self.assertEqual(result_tags[0].offset, 0)
     self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8)
     self.assertFloatTuplesAlmostEqual(result_data, expected, 5)