Esempio n. 1
0
    def dice_csi_tags(self, data, type, num_inputs, num_tags, tag_pos, vlen=1):
        tags = []
        expected_result = np.empty([np.size(data, 0)*np.size(data,1)], dtype=complex)

        if type == 'MMSE':
            # Add an SNR tag at the start of the stream for MMSE.
            tags.append(gr.tag_utils.python_to_tag((0,
                                                    pmt.string_to_symbol("snr"),
                                                    pmt.make_f32vector(num_inputs, 1e8),
                                                    pmt.from_long(0))))

        for i in range(0, num_tags):
            # Randomly generate CSI for one symbol.
            csi = (np.random.randn(vlen, num_inputs, num_inputs) + 1j * np.random.randn(vlen, num_inputs, num_inputs))
            # Assign the CSI vector to a PMT vector.
            csi_pmt = pmt.make_vector(vlen, pmt.make_vector(num_inputs, pmt.make_c32vector(num_inputs, 1.0)))
            for k, carrier in enumerate(csi):
                carrier_vector_pmt = pmt.make_vector(num_inputs, pmt.make_c32vector(num_inputs, csi[k][0][0]))
                for l, rx in enumerate(csi[k]):
                    line_vector_pmt = pmt.make_c32vector(num_inputs, csi[k][l][0])
                    for m, tx in enumerate(csi[k][l]):
                        pmt.c32vector_set(v=line_vector_pmt, k=m, x=csi[k][l][m])
                    pmt.vector_set(carrier_vector_pmt, l, line_vector_pmt)
                pmt.vector_set(csi_pmt, k, carrier_vector_pmt)

            # Append stream tags with CSI to data stream.
            tags.append(gr.tag_utils.python_to_tag((tag_pos[i],
                                                    pmt.string_to_symbol("csi"),
                                                    csi_pmt,
                                                    pmt.from_long(0))))

            # Calculate expected result.
            expected_result[tag_pos[i]*num_inputs::] = np.reshape(np.transpose(np.dot(np.linalg.inv(csi), data[::, tag_pos[i]::])), (np.size(data, 0)*(np.size(data,1)-tag_pos[i])))
        return tags, expected_result
Esempio n. 2
0
    def test_001_t (self):
        # Define test params.
        data_length = 20
        repetitions = 3
        num_tags = 3
        vlen = 1
        result = np.empty(shape=[data_length*vlen], dtype=complex)

        for n in range(repetitions):
            # Generate random input data.
            data = np.random.randn(data_length*vlen) + 1j * np.random.randn(data_length*vlen)
            # Generate random tag positions.
            tag_pos = np.random.randint(low=0, high=data_length/2, size=num_tags)*2
            # Add tag pos 0 for initial channel state.
            tag_pos = np.append(tag_pos, 0)
            tag_pos = np.sort(tag_pos)

            # Iterate over tags.
            for i in range(0, num_tags+1):
                # Randomly generate CSI for one symbol. (Flat channel)
                csi = (np.random.randn(1, 1, 2) + 1j * np.random.randn(1, 1, 2))
                # Assign the CSI vector to a PMT vector.
                csi_pmt = pmt.make_vector(vlen, pmt.make_vector(1, pmt.make_c32vector(2, 1.0)))
                for k, carrier in enumerate(csi):
                    carrier_vector_pmt = pmt.make_vector(1, pmt.make_c32vector(2, csi[0][0][0]))
                    for l, rx in enumerate(csi[k]):
                        row_vector_pmt = pmt.make_c32vector(2, csi[0][l][0])
                        for m, tx in enumerate(csi[k][l]):
                            pmt.c32vector_set(v=row_vector_pmt, k=m, x=csi[0][l][m])
                        pmt.vector_set(carrier_vector_pmt, l, row_vector_pmt)
                    pmt.vector_set(csi_pmt, k, carrier_vector_pmt)
                # Append stream tags with CSI to data stream.
                tags = [(gr.tag_utils.python_to_tag((0,
                                                     pmt.string_to_symbol("csi"),
                                                     csi_pmt,
                                                     pmt.from_long(0))))]

                # Build up the test flowgraph.
                subdata = data[tag_pos[i]*vlen::]
                src = blocks.vector_source_c(data=subdata,
                                             repeat=False,
                                             tags=tags)
                alamouti_encoder = digital.alamouti_encoder_cc()
                # Simulate channel with matrix multiplication.
                channel = blocks.multiply_matrix_cc_make(csi[0])
                alamouti_decoder = digital.alamouti_decoder_cc(vlen=vlen)
                sink = blocks.vector_sink_c()
                self.tb.connect(src, alamouti_encoder, channel,
                                blocks.stream_to_vector(gr.sizeof_gr_complex, vlen),
                                alamouti_decoder, sink)
                self.tb.connect((alamouti_encoder, 1), (channel, 1))
                # Run flowgraph.
                self.tb.run()
                result[tag_pos[i]*vlen::] = sink.data()

            '''
            Check if the expected result (=the data itself, because
            we do a loopback) equals the actual result. '''
            self.assertComplexTuplesAlmostEqual(data, result, 4)
 def notest_debug(self):
     src = blocks.vector_source_c(range(100), False, 1, [])
     separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100)
     msg = pmt.make_vector(1, pmt.PMT_NIL)
     flanks = pmt.make_f32vector(2, 0.0)
     pmt.f32vector_set(flanks, 0, 12500)
     pmt.f32vector_set(flanks, 1, 20)
     pmt.vector_set(msg, 0, flanks)
     msg_src = blocks.message_strobe(msg, 100)
Esempio n. 4
0
    def test_001_t(self):
        src = blocks.vector_source_c(list(range(10000)), False, 1, [])
        separator = inspector_test.signal_separator_c(
            32000, firdes.WIN_HAMMING, 0.1, 100, False,
            inspector_test.map_float_vector({0.0: [0.0]}))
        vec_sink = blocks.vector_sink_c(1)
        ext = inspector_test.signal_extractor_c(0)
        snk = blocks.vector_sink_c(1)
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 20)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        taps = filter.firdes.low_pass(1, 32000, 500, 50, firdes.WIN_HAMMING,
                                      6.76)

        self.tb.connect(src, separator)
        self.tb.connect(src, vec_sink)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        self.tb.msg_connect((separator, 'sig_out'), (ext, 'sig_in'))
        self.tb.connect(ext, snk)

        self.tb.start()
        time.sleep(0.3)
        self.tb.stop()
        self.tb.wait()

        data = vec_sink.data()

        sig = numpy.zeros(len(vec_sink.data()), dtype=complex)
        for i in range(len(vec_sink.data())):
            sig[i] = data[i] * numpy.exp(
                -1j * 2 * numpy.pi * 12500 * i * 1 / 32000)

        taps = filter.firdes.low_pass(1, 32000, 900, 90, firdes.WIN_HAMMING,
                                      6.76)
        sig = numpy.convolve(sig, taps, 'full')
        out = numpy.empty([0])
        decim = 32000 / 20 / 100
        j = 0
        for i in range(len(sig) / decim):
            out = numpy.append(out, sig[j])
            j += decim

        data = snk.data()
        for i in range(min(len(out), len(data))):
            self.assertComplexAlmostEqual2(out[i], data[i], abs_eps=0.01)
Esempio n. 5
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)
    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)
Esempio n. 7
0
    def no_test_sebastian (self):
        src = blocks.vector_source_c(range(100), False, 1, [])
        separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100)

        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12490)
        pmt.f32vector_set(flanks, 1, 12510)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        self.tb.connect(src, separator)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))

        self.tb.run()
    def test_001_t (self):
        src = blocks.vector_source_c(range(10000), False, 1, [])
        separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100, False, inspector_test.map_float_vector({0.0:[0.0]}))
        vec_sink = blocks.vector_sink_c(1)
        ext = inspector_test.signal_extractor_c(0)
        snk = blocks.vector_sink_c(1)
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 20)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        taps = filter.firdes.low_pass(1, 32000, 500, 50, firdes.WIN_HAMMING, 6.76)

        self.tb.connect(src, separator)
        self.tb.connect(src, vec_sink)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        self.tb.msg_connect((separator, 'sig_out'), (ext, 'sig_in'))
        self.tb.connect(ext, snk)

        self.tb.start()
        time.sleep(0.3)
        self.tb.stop()
        self.tb.wait()

        data = vec_sink.data()

        sig = numpy.zeros(len(vec_sink.data()), dtype=complex)
        for i in range(len(vec_sink.data())):
            sig[i] = data[i]*numpy.exp(-1j*2*numpy.pi*12500*i*1/32000)

        taps = filter.firdes.low_pass(1, 32000, 900, 90, firdes.WIN_HAMMING, 6.76)
        sig = numpy.convolve(sig, taps, 'full')
        out = numpy.empty([0])
        decim = 32000/20/100
        j = 0
        for i in range(len(sig)/decim):
            out = numpy.append(out, sig[j])
            j += decim

        data = snk.data()
        for i in range(min(len(out), len(data))):
            self.assertComplexAlmostEqual2(out[i], data[i], abs_eps=0.01)
Esempio n. 9
0
    def test_001_t (self):
        # set up fg
        src = blocks.vector_source_c(range(1024), False, 1, [])
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 8)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)


        separator = inspector_test.signal_separator_c(1024, firdes.WIN_HAMMING, 0.1, 1)
        extractor = inspector.signal_extractor_c(0)

        taps = firdes.low_pass(1, 1024, 2, 0.1*2, firdes.WIN_HAMMING, 6.76)
        reference = numpy.convolve(range(1024), taps, 'same')
        #xlator = filter.freq_xlating_fir_filter_ccf(160, taps, 12500, 32000)
        stv1 = blocks.stream_to_vector(gr.sizeof_gr_complex, 128)
        #stv2 = blocks.stream_to_vector(gr.sizeof_gr_complex, 128)
        snk1 = blocks.vector_sink_c(128)
        #snk2 = blocks.vector_sink_c(128)
        null1 = blocks.null_sink(gr.sizeof_gr_complex)
        # connect this
        self.tb.connect(src, separator)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        #self.tb.connect(src, xlator)
        #self.tb.connect(xlator, null1)
        self.tb.msg_connect((separator, 'msg_out'), (extractor, 'sig_in'))
        self.tb.connect(extractor, stv1)
        #self.tb.connect(xlator, stv2)
        self.tb.connect(stv1, snk1)
        #self.tb.connect(stv2, snk2)

        self.tb.start()
        time.sleep(0.5)
        self.tb.stop()
        # check data
        data1 = snk1.data()
        #data2 = snk2.data()
        data2 = reference[0::8]

        for i in range(min(len(data2), len(data1))):
            self.assertComplexAlmostEqual(data1[i], data2[i], 4)
Esempio n. 10
0
    def build_and_run_flowgraph(self,
                                repetitions,
                                data_length,
                                num_inputs_min,
                                num_inputs_max,
                                equalizer_type,
                                vlen=[1, 1]):
        for a in range(repetitions):
            num_inputs = np.random.randint(low=num_inputs_min,
                                           high=num_inputs_max + 1)
            # Generate random input data.
            data = np.random.randn(
                data_length * num_inputs * vlen[a]) + 1j * np.random.randn(
                    data_length * num_inputs * vlen[a])

            # Randomly generate CSI for one symbol.
            csi = (np.random.randn(vlen[a], num_inputs, num_inputs) +
                   1j * np.random.randn(vlen[a], num_inputs, num_inputs))

            # Assign the CSI vector to a PMT vector.
            csi_pmt = pmt.make_vector(
                vlen[a],
                pmt.make_vector(num_inputs,
                                pmt.make_c32vector(num_inputs, 1.0)))
            for k, carrier in enumerate(csi):
                carrier_vector_pmt = pmt.make_vector(
                    num_inputs, pmt.make_c32vector(num_inputs, csi[k][0][0]))
                for l, rx in enumerate(csi[k]):
                    line_vector_pmt = pmt.make_c32vector(
                        num_inputs, csi[k][l][0])
                    for m, tx in enumerate(csi[k][l]):
                        pmt.c32vector_set(v=line_vector_pmt,
                                          k=m,
                                          x=csi[k][l][m])
                    pmt.vector_set(carrier_vector_pmt, l, line_vector_pmt)
                pmt.vector_set(csi_pmt, k, carrier_vector_pmt)

            # Append stream tags with CSI to data stream.

            tags = [(gr.tag_utils.python_to_tag(
                (0, pmt.string_to_symbol("csi"), csi_pmt, pmt.from_long(0))))]

            if equalizer_type == 'MMSE':
                # Add an SNR tag at the start of the stream for MMSE.
                tags.append(
                    gr.tag_utils.python_to_tag(
                        (0, pmt.string_to_symbol("snr"),
                         pmt.make_f32vector(num_inputs,
                                            1e8), pmt.from_long(0))))

            # Build up the test flowgraph.
            src = blocks.vector_source_c(data=data, repeat=False, tags=tags)
            vblast_encoder = digital.vblast_encoder_cc(num_inputs)
            demux = []
            channels = []
            for i in range(0, vlen[a]):
                for j in range(0, num_inputs):
                    demux.append(
                        blocks.keep_m_in_n(gr.sizeof_gr_complex, 1, vlen[a],
                                           i))
                # Simulate channel with matrix multiplication.
                channels.append(blocks.multiply_matrix_cc_make(csi[i]))
            mux = []
            s2v = []
            for i in range(0, num_inputs):
                mux.append(
                    blocks.stream_mux(gr.sizeof_gr_complex, [1] * vlen[a]))
                s2v.append(
                    blocks.stream_to_vector(gr.sizeof_gr_complex, vlen[a]))

            vblast_decoder = digital.vblast_decoder_cc(num_inputs,
                                                       equalizer_type, vlen[a])
            sink = blocks.vector_sink_c()
            self.tb.connect(src, vblast_encoder)
            for n in range(0, num_inputs):
                for i in range(0, vlen[a]):
                    self.tb.connect((vblast_encoder, n),
                                    demux[i * num_inputs + n],
                                    (channels[i], n))
                    self.tb.connect((channels[i], n), (mux[n], i))
                self.tb.connect(mux[n], s2v[n], (vblast_decoder, n))

            self.tb.connect(vblast_decoder, sink)
            # Run flowgraph.
            self.tb.run()
            ''' 
            Check if the expected result (=the data itself, because 
            we do a loopback) equals the actual result. '''
            self.assertComplexTuplesAlmostEqual(data, sink.data(), 2)
Esempio n. 11
0
    def dice_csi_tags(self, input, num_tags, tag_pos, vlen=1):
        tags = []
        # Calculate initial behaviour before first tag.
        output = np.empty(shape=[len(input)], dtype=complex)
        output[::2] = (input[::2] + np.conj(input[1::2])) / 2.0
        output[1::2] = (input[::2] - np.conj(input[1::2])) / 2.0

        # Iterate over tags and update the calculated output according to the diced CSI.
        for i in range(0, num_tags):
            # Randomly generate CSI for one symbol.
            csi = (np.random.randn(vlen, 1, 2) +
                   1j * np.random.randn(vlen, 1, 2))
            # Assign the CSI vector to a PMT vector.
            csi_pmt = pmt.make_vector(
                vlen, pmt.make_vector(1, pmt.make_c32vector(2, 1.0)))
            for k, carrier in enumerate(csi):
                carrier_vector_pmt = pmt.make_vector(
                    1, pmt.make_c32vector(2, csi[k][0][0]))
                for l, rx in enumerate(csi[k]):
                    row_vector_pmt = pmt.make_c32vector(2, csi[k][l][0])
                    for m, tx in enumerate(csi[k][l]):
                        pmt.c32vector_set(v=row_vector_pmt,
                                          k=m,
                                          x=csi[k][l][m])
                    pmt.vector_set(carrier_vector_pmt, l, row_vector_pmt)
                pmt.vector_set(csi_pmt, k, carrier_vector_pmt)
            # Append stream tags with CSI to data stream.
            tags.append(
                gr.tag_utils.python_to_tag(
                    (tag_pos[i], pmt.string_to_symbol("csi"), csi_pmt,
                     pmt.from_long(0))))
            # Calculate the expected result.
            if vlen == 1:
                total_branch_energy = np.sum(np.square(np.abs(csi[0][0])))
                if tag_pos[i] % 2 == 0:
                    output[tag_pos[i]::2] = (
                        np.conj(csi[0][0][0]) * input[tag_pos[i]::2] +
                        csi[0][0][1] * np.conj(input[tag_pos[i] + 1::2])
                    ) / total_branch_energy
                    output[tag_pos[i] + 1::2] = (
                        np.conj(csi[0][0][1]) * input[tag_pos[i]::2] -
                        csi[0][0][0] * np.conj(input[tag_pos[i] + 1::2])
                    ) / total_branch_energy
                else:
                    output[tag_pos[i] + 1::2] = (
                        np.conj(csi[0][0][0]) * input[tag_pos[i] + 1::2] +
                        csi[0][0][1] * np.conj(input[tag_pos[i] + 2::2])
                    ) / total_branch_energy
                    output[tag_pos[i] + 2::2] = (
                        np.conj(csi[0][0][1]) * input[tag_pos[i] + 1::2] -
                        csi[0][0][0] * np.conj(input[tag_pos[i] + 2::2])
                    ) / total_branch_energy
            else:
                if tag_pos[i] % 2 == 0:
                    for j in range(tag_pos[i] * vlen, len(input), 2):
                        total_branch_energy = np.sum(
                            np.square(np.abs(csi[j % vlen][0])))
                        output[j] = (np.conj(csi[j % vlen][0][0]) * input[j] +
                                     csi[j % vlen][0][1] * np.conj(
                                         input[j + 1])) / total_branch_energy
                        output[j +
                               1] = (np.conj(csi[j % vlen][0][1]) * input[j] -
                                     csi[j % vlen][0][0] * np.conj(
                                         input[j + 1])) / total_branch_energy
                else:
                    for j in range((tag_pos[i] + 1) * vlen, len(input), 2):
                        total_branch_energy = np.sum(
                            np.square(np.abs(csi[j % vlen][0])))
                        output[j] = (np.conj(csi[j % vlen][0][0]) * input[j] +
                                     csi[j % vlen][0][1] * np.conj(
                                         input[j + 1])) / total_branch_energy
                        output[j +
                               1] = (np.conj(csi[j % vlen][0][1]) * input[j] -
                                     csi[j % vlen][0][0] * np.conj(
                                         input[j + 1])) / total_branch_energy
        return tags, output