Exemplo n.º 1
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)
Exemplo n.º 2
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.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
Exemplo n.º 3
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)
Exemplo n.º 4
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.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value),
                              channel)
Exemplo n.º 5
0
    def test_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.channel_model(0.0, 0.0, 1.0, [
            1,
        ], 0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.0)
        op.set_frequency_offset(0.0)
        op.set_taps([
            1,
        ])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Exemplo n.º 6
0
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 1
     carr_offset = -2
     freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency
     occupied_carriers = ((-2, -1, 1, 2),)
     pilot_carriers = ((-3,),(3,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = (1, 2, 3, 4)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_data))
     offsettag = gr.tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, (1.0/fft_len,)*fft_len, True)
     oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0/fft_len)
     mixer = blocks.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     sink2 = blocks.vector_sink_c(fft_len)
     self.tb.connect(rx_fft, sink2)
     serializer = digital.ofdm_serializer_vcc(
             alloc, "", 0, "ofdm_sync_carr_offset", True
     )
     sink = blocks.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             blocks.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(oscillator, (mixer, 1))
     self.tb.run ()
     self.assertComplexTuplesAlmostEqual(sink.data()[-len(occupied_carriers[0]):], tx_data, places=4)
Exemplo n.º 7
0
    def test_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100

        fDTs = 0.01
        K = 4
        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.fading_model(8, fDTs=fDTs, LOS=True, K=K, seed=0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        self.assertAlmostEqual(K, op.K(), 4)
        self.assertAlmostEqual(fDTs, op.fDTs(), 4)
Exemplo n.º 8
0
    def test_002_cc(self):
        N = 10000        # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        freq = 10
        data = sig_source_c(fs, freq, 1, N)
        signal = blocks.vector_source_c(data)
        op = filter.fractional_resampler_cc(0.0, rrate)
        snk = blocks.vector_sink_c()

        self.tb.connect(signal, op, snk)
        self.tb.run() 

        Ntest = 5000
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs/rrate), xrange(L))

        phase = 0.1884
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
Exemplo n.º 9
0
    def test05(self):
        # 8PSK Convergence test with static rotation
        natfreq = 0.25
        order = 8
        self.test = digital.costas_loop_cc(natfreq, order)

        rot = cmath.exp(-cmath.pi / 8.0j)  # rotate to match Costas rotation
        const = psk.psk_constellation(order)
        data = [random.randint(0, 7) for i in xrange(100)]
        data = [2 * rot * const.points()[d] for d in data]

        N = 40  # settling time
        expected_result = data[N:]

        rot = cmath.exp(0.1j)  # some small rotation
        data = [rot * d for d in data]

        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

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

        dst_data = self.snk.data()[N:]

        # generously compare results; the loop will converge near to, but
        # not exactly on, the target data
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
Exemplo n.º 10
0
 def test_fir_filter_scc_002(self):
     self.generate_scc_source()
     expected_data = (
         (-0.0080680437386 - 0.00158522999845j),
         (-0.0037795654498 + 0.00733159901574j),
         (0.00842926371843 + 0.00777021236718j), (0.0112090632319 -
                                                  0.00249325321056j),
         (-0.0027476802934 - 0.0115710813552j), (-0.0158688724041 -
                                                 0.00715934624895j),
         (-0.00802888441831 + 0.00620818417519j), (0.0131985172629 +
                                                   0.0149175003171j),
         (0.0190298333764 + 0.00956719089299j), (-0.00112380902283 -
                                                 0.00936658866704j),
         (-0.0204226914793 - 0.0333464704454j), (-0.00695514678955 -
                                                 0.0437445007265j),
         (0.0314490310848 - 0.0207983348519j), (0.0529675260186 +
                                                0.0302227605134j),
         (0.0317338332534 + 0.0667510479689j), (-0.00775565672666 +
                                                0.0437112376094j),
         (-0.024347923696 - 0.0303014591336j), (-0.0108893103898 -
                                                0.0875638127327j),
         (0.00204296782613 - 0.0721434056759j), (-0.00527479872108 -
                                                 0.00698097236454j))
     src = blocks.vector_source_s(self.src_data)
     op = filter.freq_xlating_fir_filter_scc(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 11
0
 def test_fir_filter_scf_002(self):
     self.generate_scf_source()
     expected_data = ((0.00824625696987 - 1.50158575707e-05j),
                      (0.0020101047121 - 0.0116540221497j),
                      (-0.0126378880814 - 0.00259830290452j),
                      (-0.00363933457993 + 0.00837504956871j),
                      (0.00107023562305 + 0.00915473792702j),
                      (0.0169738996774 + 0.00422182958573j),
                      (0.00630031805485 - 0.025423232466j),
                      (-0.0283014029264 + 0.00104465708137j),
                      (0.00890890974551 + 0.0115978596732j),
                      (-0.0142687577754 + 0.00306978379376j),
                      (0.02845691517 + 0.0331163145602j),
                      (0.0538152232766 - 0.0908300876617j),
                      (-0.0843691527843 - 0.0956566259265j),
                      (0.0476895272732 + 0.0747984498739j),
                      (0.0898786485195 + 0.082478672266j),
                      (-0.0330070182681 + 0.101965606213j),
                      (0.0574697069824 - 0.0350842289627j),
                      (-0.0770940706134 - 0.230615705252j),
                      (-0.103762261569 -
                       0.0382265634835j), (0.11808334291 + 0.104863762856j))
     src = blocks.vector_source_s(self.src_data)
     op = filter.freq_xlating_fir_filter_scf(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 12
0
 def test_fir_filter_fcc_002(self):
     self.generate_fcc_source()
     expected_data = (
         (-6.94218761055e-05 - 9.90489479591e-06j),
         (-2.56973435171e-05 + 8.05932795629e-05j),
         (7.01698663761e-05 + 7.36373840482e-05j), (7.57163215894e-05 -
                                                    4.65324592369e-05j),
         (-3.01657128148e-05 - 0.000122838056996j), (-9.53659764491e-05 -
                                                     3.73945695173e-05j),
         (-2.33501577895e-05 + 0.000109135726234j), (6.65136758471e-05 +
                                                     0.000125709688291j),
         (3.08501912514e-05 - 9.16842873266e-06j), (-2.64703612629e-05 -
                                                    0.000135892929393j),
         (0.000136643866426 - 0.000162003751029j), (0.000501801609062 -
                                                    0.000185820827028j),
         (0.000694551155902 - 0.000299874518532j), (0.000424396857852 -
                                                    0.00038379128091j),
         (-9.1786707344e-05 - 0.000242479465669j), (-0.000337087287335 +
                                                    7.45999423089e-05j),
         (-0.000116414521472 + 0.000258556567132j), (0.000215422536712 +
                                                     0.000116706112749j),
         (0.000224391726078 - 0.000156330308528j), (-5.96956087975e-05 -
                                                    0.000211163976928j))
     src = blocks.vector_source_f(self.src_data)
     op = filter.freq_xlating_fir_filter_fcc(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 13
0
 def test_fir_filter_fcf_002(self):
     self.generate_fcf_source()
     expected_data = (
         (7.3052920925e-05 - 3.91741014028e-06j),
         (3.11913172482e-05 - 0.000109872074972j),
         (-0.000128646017401 - 3.49857727997e-05j), (-5.49546712136e-05 +
                                                     8.96326746442e-05j),
         (5.14321582159e-05 + 9.64698920143e-05j), (0.000120189361041 +
                                                    2.4231892894e-05j),
         (0.000100405508419 - 0.000223224604269j), (-0.000274751859251 -
                                                    2.33274622587e-05j),
         (1.52600114234e-06 + 0.000133301247843j), (3.77224641852e-05 +
                                                    5.29596509296e-05j),
         (-3.60160379387e-06 + 0.000247975171078j), (0.00113093166146 -
                                                     0.000663110695314j),
         (0.00059568521101 - 0.00099650840275j), (-0.000475480686873 +
                                                  0.000250602373853j),
         (0.000191397906747 + 0.000271986238658j), (0.000247183139436 -
                                                    0.000157510468853j),
         (-5.48357638763e-05 - 0.000113135029096j), (-0.00010601492977 -
                                                     0.00015005269961j),
         (-0.000204817260965 + 0.000160534662427j), (0.000114742244477 +
                                                     0.000205190313864j))
     src = blocks.vector_source_f(self.src_data)
     op = filter.freq_xlating_fir_filter_fcf(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
 def test_fir_filter_ccf_001(self):
     self.generate_ccf_source()
     expected_data = ((0.001697700354270637+0.004312471952289343j),
                      (0.003520616563037038-0.003014103975147009j),
                      (0.004252811893820763-0.008337559178471565j),
                      (0.0030743128154426813-0.010262271389365196j),
                      (0.0007344777695834637-0.007861139252781868j),
                      (-0.0011067686136811972-0.0028924935031682253j),
                      (-0.002371778478845954+0.0019914964213967323j),
                      (-0.003023319412022829+0.005717850290238857j),
                      (-0.0021738125942647457+0.007211698684841394j),
                      (-0.0004628606839105487+0.005501383915543556j),
                      (0.0007428556564264+0.0019867848604917526j),
                      (0.001634795218706131-0.0013514887541532516j),
                      (0.002205110155045986-0.00402155052870512j),
                      (0.0015480631263926625-0.005179159343242645j),
                      (0.00026722141774371266-0.003887997241690755j),
                      (-0.0004911854630336165-0.0013578246580436826j),
                      (-0.0011226939968764782+0.0009080552263185382j),
                      (-0.0016229727771133184+0.0028335191309452057j),
                      (-0.0010890064295381308+0.0037298379465937614j),
                      (-0.00012392725329846144+0.0027196139562875032j))
     src = blocks.vector_source_c(self.src_data)
     op  = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
Exemplo n.º 15
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)))
 def test_fir_filter_scf_002(self):
     self.generate_scf_source()
     expected_data = ((0.00824625696987-1.50158575707e-05j),
                      (0.0020101047121-0.0116540221497j),
                      (-0.0126378880814-0.00259830290452j),
                      (-0.00363933457993+0.00837504956871j),
                      (0.00107023562305+0.00915473792702j),
                      (0.0169738996774+0.00422182958573j),
                      (0.00630031805485-0.025423232466j),
                      (-0.0283014029264+0.00104465708137j),
                      (0.00890890974551+0.0115978596732j),
                      (-0.0142687577754+0.00306978379376j),
                      (0.02845691517+0.0331163145602j),
                      (0.0538152232766-0.0908300876617j),
                      (-0.0843691527843-0.0956566259265j),
                      (0.0476895272732+0.0747984498739j),
                      (0.0898786485195+0.082478672266j),
                      (-0.0330070182681+0.101965606213j),
                      (0.0574697069824-0.0350842289627j),
                      (-0.0770940706134-0.230615705252j),
                      (-0.103762261569-0.0382265634835j),
                      (0.11808334291+0.104863762856j))
     src = blocks.vector_source_s(self.src_data)
     op  = filter.freq_xlating_fir_filter_scf(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
Exemplo n.º 17
0
    def transform(self, src_data, gain, const):
	SRC = blocks.vector_source_c(src_data, False)
	EQU = digital.lms_dd_equalizer_cc(4, gain, 1, const.base())
	DST = blocks.vector_sink_c()
	self.tb.connect(SRC, EQU, DST)
	self.tb.run()
	return DST.data()
 def test_fir_filter_scc_001(self):
     self.generate_scc_source()
     expected_data = ((-0.00775564694777+0.0437113791704j),
                      (0.0108830630779+0.0433648750186j),
                      (0.015553932637-0.0133284125477j),
                      (-0.0264905355871-0.0403266139328j),
                      (-0.0243480335921-0.03030154109j),
                      (-0.000327925226884-0.069333948195j),
                      (-0.0306392069906-0.107313856483j),
                      (-0.0452371090651-0.0854917764664j),
                      (-0.0108894333243-0.0875641107559j),
                      (-0.0182112380862-0.118961036205j),
                      (-0.0447825863957-0.0922874584794j),
                      (-0.0147479763255-0.0572904124856j),
                      (0.00204290449619-0.0721436738968j),
                      (-0.027713002637-0.0548989400268j),
                      (-0.0149045493454-0.00210141134448j),
                      (0.0176361314952-0.00149522523861j),
                      (-0.00527482619509-0.00698099425063j),
                      (-0.0151527002454+0.036265052855j),
                      (0.0199296213686+0.0452499426901j),
                      (0.0122985243797+0.0143278446048j))
     src = blocks.vector_source_s(self.src_data)
     op  = filter.freq_xlating_fir_filter_scc(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = blocks.vector_source_c(v0)
        src1 = blocks.vector_source_b(v1)
        
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)

        # print "len(v) = %d" % (len(v))

        op = digital.ofdm_insert_preamble(fft_length, preamble)

        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = blocks.vector_sink_c()
        dst1 = blocks.vector_sink_b()

        tb.connect(src0, s2v, (op, 0))
        tb.connect(src1, (op, 1))
        tb.connect((op, 0), v2s, dst0)
        tb.connect((op, 1), dst1)

        tb.run()
        r0 = dst0.data()
        r0v = []
        for i in range(len(r0)//fft_length):
            r0v.append(r0[i*fft_length:(i+1)*fft_length])
            
        r1 = dst1.data()
        self.assertEqual(len(r0v), len(r1))
        return (r1, r0v)
Exemplo n.º 20
0
    def test04(self):
        # QPSK Convergence test with static rotation
        natfreq = 0.25
        order = 4
        self.test = digital.costas_loop_cc(natfreq, order)

        rot = cmath.exp(0.2j) # some small rotation
        data = [complex(2*random.randint(0,1)-1, 2*random.randint(0,1)-1)
                for i in xrange(100)]
        
        N = 40 # settling time
        expected_result = data[N:]
        data = [rot*d for d in data]

        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

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

        dst_data = self.snk.data()[N:]

        # generously compare results; the loop will converge near to, but
        # not exactly on, the target data
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
Exemplo n.º 21
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)))
 def test_fir_filter_fcc_002(self):
     self.generate_fcc_source()
     expected_data = ((-6.94218761055e-05-9.90489479591e-06j),
                      (-2.56973435171e-05+8.05932795629e-05j),
                      (7.01698663761e-05+7.36373840482e-05j),
                      (7.57163215894e-05-4.65324592369e-05j),
                      (-3.01657128148e-05-0.000122838056996j),
                      (-9.53659764491e-05-3.73945695173e-05j),
                      (-2.33501577895e-05+0.000109135726234j),
                      (6.65136758471e-05+0.000125709688291j),
                      (3.08501912514e-05-9.16842873266e-06j),
                      (-2.64703612629e-05-0.000135892929393j),
                      (0.000136643866426-0.000162003751029j),
                      (0.000501801609062-0.000185820827028j),
                      (0.000694551155902-0.000299874518532j),
                      (0.000424396857852-0.00038379128091j),
                      (-9.1786707344e-05-0.000242479465669j),
                      (-0.000337087287335+7.45999423089e-05j),
                      (-0.000116414521472+0.000258556567132j),
                      (0.000215422536712+0.000116706112749j),
                      (0.000224391726078-0.000156330308528j),
                      (-5.96956087975e-05-0.000211163976928j))
     src = blocks.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcc(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
 def test_001_t (self):
     """
     pretty simple (the carrier allocation is not a practical OFDM configuration!)
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     pilot_symbols = ((1j,),)
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((3,),)
     sync_word = (range(fft_len),)
     expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3])
     #                                                 ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, sync_word,
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 def test_fir_filter_fcc_001(self):
     self.generate_fcc_source()
     expected_data = ((-0.000337088305969+7.46004516259e-05j),
                      (-5.63409266761e-05+0.000301144464174j),
                      (9.16960561881e-05-2.89259278361e-05j),
                      (-0.000231866899412-6.25764005235e-05j),
                      (-0.000116414688819+0.000258557556663j),
                      (0.000206079319469+5.05045172758e-05j),
                      (-3.85114690289e-05-0.00019276549574j),
                      (-0.000146380873048+0.000112079876999j),
                      (0.000215423395275+0.000116706331028j),
                      (0.000136050162837-0.000232611957472j),
                      (-0.000155499437824-5.41604022146e-05j),
                      (0.000106907449663+0.00016310159117j),
                      (0.000224392410018-0.000156331108883j),
                      (-0.000131131906528-0.000172063446371j),
                      (-5.92393880652e-05+0.00016801241145j),
                      (0.000214921761653-5.32235890205e-06j),
                      (-5.96960526309e-05-0.000211164733628j),
                      (-0.000193948610104+0.000113364716526j),
                      (0.000134820176754+0.000142527525895j),
                      (4.74465123261e-05-0.000175131688593j))
     src = blocks.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcc(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
 def test_001_t2 (self):
     """
     pretty simple (same as before, but odd fft len)
     """
     fft_len = 5
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((-2,),)
     pilot_symbols = ((1j,),)
     expected_result = (1j, 0, 1, 2, 3)
     #                         ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
Exemplo n.º 26
0
 def test_fir_filter_fcc_001(self):
     self.generate_fcc_source()
     expected_data = (
         (-0.000337088305969 + 7.46004516259e-05j),
         (-5.63409266761e-05 + 0.000301144464174j),
         (9.16960561881e-05 - 2.89259278361e-05j), (-0.000231866899412 -
                                                    6.25764005235e-05j),
         (-0.000116414688819 + 0.000258557556663j), (0.000206079319469 +
                                                     5.05045172758e-05j),
         (-3.85114690289e-05 - 0.00019276549574j), (-0.000146380873048 +
                                                    0.000112079876999j),
         (0.000215423395275 + 0.000116706331028j), (0.000136050162837 -
                                                    0.000232611957472j),
         (-0.000155499437824 - 5.41604022146e-05j), (0.000106907449663 +
                                                     0.00016310159117j),
         (0.000224392410018 - 0.000156331108883j), (-0.000131131906528 -
                                                    0.000172063446371j),
         (-5.92393880652e-05 + 0.00016801241145j), (0.000214921761653 -
                                                    5.32235890205e-06j),
         (-5.96960526309e-05 - 0.000211164733628j), (-0.000193948610104 +
                                                     0.000113364716526j),
         (0.000134820176754 + 0.000142527525895j), (4.74465123261e-05 -
                                                    0.000175131688593j))
     src = blocks.vector_source_f(self.src_data)
     op = filter.freq_xlating_fir_filter_fcc(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
 def test_002_t (self):
     """
     same, but using negative carrier indices
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     pilot_symbols = ((1j,),)
     occupied_carriers = ((-1, 1, 2),)
     pilot_carriers = ((3,),)
     expected_result = (1j, 0, 1, 0, 2, 3)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
Exemplo n.º 28
0
 def test_fir_filter_scf_001(self):
     self.generate_scf_source()
     expected_data = (
         (-0.0330070219934 + 0.101965591311j),
         (-0.0484239049256 + 0.0872343629599j),
         (-0.0214109234512 + 0.102555386722j), (0.0484058149159 +
                                                0.0557125210762j),
         (0.0574690811336 - 0.0350844524801j), (0.0365394353867 -
                                                0.0802438184619j),
         (0.0453781634569 - 0.130992040038j), (0.00801951438189 -
                                               0.214278846979j),
         (-0.0770946145058 - 0.230616629124j), (-0.105601429939 -
                                                0.190731987357j),
         (-0.105361394584 - 0.177761554718j), (-0.131518915296 -
                                               0.136102750897j),
         (-0.103761836886 - 0.0382263250649j), (-0.0167790111154 +
                                                0.0152206514031j),
         (0.0277570039034 + 0.0300403907895j), (0.056065287441 +
                                                0.0806603953242j),
         (0.118084669113 + 0.104863211513j), (0.128281414509 +
                                              0.0677760615945j),
         (0.0748447552323 + 0.0619902014732j), (0.0512856245041 +
                                                0.0775099247694j))
     src = blocks.vector_source_s(self.src_data)
     op = filter.freq_xlating_fir_filter_scf(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
 def test_002_static_wo_tags (self):
     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_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     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))
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len)
     sink = blocks.vector_sink_c(fft_len)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, "", False, 4)
     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)
Exemplo n.º 30
0
 def test_fir_filter_scc_001(self):
     self.generate_scc_source()
     expected_data = (
         (-0.00775564694777 + 0.0437113791704j),
         (0.0108830630779 + 0.0433648750186j),
         (0.015553932637 - 0.0133284125477j), (-0.0264905355871 -
                                               0.0403266139328j),
         (-0.0243480335921 - 0.03030154109j), (-0.000327925226884 -
                                               0.069333948195j),
         (-0.0306392069906 - 0.107313856483j), (-0.0452371090651 -
                                                0.0854917764664j),
         (-0.0108894333243 - 0.0875641107559j), (-0.0182112380862 -
                                                 0.118961036205j),
         (-0.0447825863957 - 0.0922874584794j), (-0.0147479763255 -
                                                 0.0572904124856j),
         (0.00204290449619 - 0.0721436738968j), (-0.027713002637 -
                                                 0.0548989400268j),
         (-0.0149045493454 - 0.00210141134448j), (0.0176361314952 -
                                                  0.00149522523861j),
         (-0.00527482619509 - 0.00698099425063j), (-0.0151527002454 +
                                                   0.036265052855j),
         (0.0199296213686 + 0.0452499426901j), (0.0122985243797 +
                                                0.0143278446048j))
     src = blocks.vector_source_s(self.src_data)
     op = filter.freq_xlating_fir_filter_scc(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 31
0
    def transform(self, src_data):
	SRC = blocks.vector_source_c(src_data, False)
	EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1)
	DST = blocks.vector_sink_c()
	self.tb.connect(SRC, EQU, DST)
	self.tb.run()
	return DST.data()
Exemplo n.º 32
0
 def test_fir_filter_ccf_001(self):
     self.generate_ccf_source()
     expected_data = ((0.001697700354270637 + 0.004312471952289343j),
                      (0.003520616563037038 - 0.003014103975147009j),
                      (0.004252811893820763 - 0.008337559178471565j),
                      (0.0030743128154426813 - 0.010262271389365196j),
                      (0.0007344777695834637 - 0.007861139252781868j),
                      (-0.0011067686136811972 - 0.0028924935031682253j),
                      (-0.002371778478845954 + 0.0019914964213967323j),
                      (-0.003023319412022829 + 0.005717850290238857j),
                      (-0.0021738125942647457 + 0.007211698684841394j),
                      (-0.0004628606839105487 + 0.005501383915543556j),
                      (0.0007428556564264 + 0.0019867848604917526j),
                      (0.001634795218706131 - 0.0013514887541532516j),
                      (0.002205110155045986 - 0.00402155052870512j),
                      (0.0015480631263926625 - 0.005179159343242645j),
                      (0.00026722141774371266 - 0.003887997241690755j),
                      (-0.0004911854630336165 - 0.0013578246580436826j),
                      (-0.0011226939968764782 + 0.0009080552263185382j),
                      (-0.0016229727771133184 + 0.0028335191309452057j),
                      (-0.0010890064295381308 +
                       0.0037298379465937614j), (-0.00012392725329846144 +
                                                 0.0027196139562875032j))
     src = blocks.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 33
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))
Exemplo n.º 34
0
    def test04(self):
        # QPSK Convergence test with static rotation
        natfreq = 0.25
        order = 4
        self.test = digital.costas_loop_cc(natfreq, order)

        rot = cmath.exp(0.2j)  # some small rotation
        data = [
            complex(2 * random.randint(0, 1) - 1, 2 * random.randint(0, 1) - 1)
            for i in xrange(100)
        ]

        N = 40  # settling time
        expected_result = data[N:]
        data = [rot * d for d in data]

        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

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

        dst_data = self.snk.data()[N:]

        # generously compare results; the loop will converge near to, but
        # not exactly on, the target data
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
Exemplo n.º 35
0
 def __init__(self, data, len_tag_key):
     gr.top_block.__init__(self, "ofdm_tx")
     tx_data, tags = tagged_streams.packets_to_vectors((data,), len_tag_key)
     src = blocks.vector_source_b(data, False, 1, tags)
     self.tx = ofdm_tx(packet_length_tag_key=len_tag_key, debug_log=LOG_DEBUG_INFO)
     self.sink = blocks.vector_sink_c()
     self.connect(src, self.tx, self.sink)
Exemplo n.º 36
0
    def test05(self):
        # 8PSK Convergence test with static rotation
        natfreq = 0.25
        order = 8
        self.test = digital.costas_loop_cc(natfreq, order)

        rot = cmath.exp(-cmath.pi/8.0j) # rotate to match Costas rotation
        const = psk.psk_constellation(order)
        data = [random.randint(0,7) for i in xrange(100)]
        data = [2*rot*const.points()[d] for d in data]
        
        N = 40 # settling time
        expected_result = data[N:]

        rot = cmath.exp(0.1j) # some small rotation
        data = [rot*d for d in data]

        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

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

        dst_data = self.snk.data()[N:]
        
	# generously compare results; the loop will converge near to, but
        # not exactly on, the target data
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
Exemplo n.º 37
0
    def test01(self):
        # Test complex/complex version
        omega = 2
        gain_omega = 0.001
        mu = 0.5
        gain_mu = 0.01
        omega_rel_lim = 0.001

        self.test = digital.clock_recovery_mm_cc(omega, gain_omega,
                                                 mu, gain_mu,
                                                 omega_rel_lim)
        
        data = 100*[complex(1, 1),]
        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()
        
        expected_result = 100*[complex(0.99972, 0.99972)] # doesn't quite get to 1.0
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 30
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]

        #print expected_result
        #print dst_data
        
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
Exemplo n.º 38
0
 def transform(self, src_data):
     SRC = blocks.vector_source_c(src_data, False)
     EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1)
     DST = blocks.vector_sink_c()
     self.tb.connect(SRC, EQU, DST)
     self.tb.run()
     return DST.data()
 def test_fir_filter_scf_001(self):
     self.generate_scf_source()
     expected_data = ((-0.0330070219934+0.101965591311j),
                      (-0.0484239049256+0.0872343629599j),
                      (-0.0214109234512+0.102555386722j),
                      (0.0484058149159+0.0557125210762j),
                      (0.0574690811336-0.0350844524801j),
                      (0.0365394353867-0.0802438184619j),
                      (0.0453781634569-0.130992040038j),
                      (0.00801951438189-0.214278846979j),
                      (-0.0770946145058-0.230616629124j),
                      (-0.105601429939-0.190731987357j),
                      (-0.105361394584-0.177761554718j),
                      (-0.131518915296-0.136102750897j),
                      (-0.103761836886-0.0382263250649j),
                      (-0.0167790111154+0.0152206514031j),
                      (0.0277570039034+0.0300403907895j),
                      (0.056065287441+0.0806603953242j),
                      (0.118084669113+0.104863211513j),
                      (0.128281414509+0.0677760615945j),
                      (0.0748447552323+0.0619902014732j),
                      (0.0512856245041+0.0775099247694j))
     src = blocks.vector_source_s(self.src_data)
     op  = filter.freq_xlating_fir_filter_scf(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
 def test_with_tags_2s_rolloff(self):
     " With tags and a 2-sample rolloff "
     fft_len = 8
     cp_len = 2
     tag_name = "length"
     expected_result = (7.0/2,       8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
                        7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0/2)
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(2)
     tag2 = gr.tag_t()
     tag2.offset = 1
     tag2.key = pmt.string_to_symbol("random_tag")
     tag2.value = pmt.from_long(42)
     src = blocks.vector_source_c(range(1, fft_len+1) * 2, False, fft_len, (tag, tag2))
     cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2, tag_name)
     sink = blocks.vector_sink_c()
     self.tb.connect(src, cp, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     tags = [gr.tag_to_python(x) for x in sink.tags()]
     tags = sorted([(x.offset, x.key, x.value) for x in tags])
     expected_tags = [
         (0, tag_name, len(expected_result)),
         (fft_len+cp_len, "random_tag", 42)
     ]
     self.assertEqual(tags, expected_tags)
 def test_fir_filter_scc_002(self):
     self.generate_scc_source()
     expected_data = ((-0.0080680437386-0.00158522999845j),
                      (-0.0037795654498+0.00733159901574j),
                      (0.00842926371843+0.00777021236718j),
                      (0.0112090632319-0.00249325321056j),
                      (-0.0027476802934-0.0115710813552j),
                      (-0.0158688724041-0.00715934624895j),
                      (-0.00802888441831+0.00620818417519j),
                      (0.0131985172629+0.0149175003171j),
                      (0.0190298333764+0.00956719089299j),
                      (-0.00112380902283-0.00936658866704j),
                      (-0.0204226914793-0.0333464704454j),
                      (-0.00695514678955-0.0437445007265j),
                      (0.0314490310848-0.0207983348519j),
                      (0.0529675260186+0.0302227605134j),
                      (0.0317338332534+0.0667510479689j),
                      (-0.00775565672666+0.0437112376094j),
                      (-0.024347923696-0.0303014591336j),
                      (-0.0108893103898-0.0875638127327j),
                      (0.00204296782613-0.0721434056759j),
                      (-0.00527479872108-0.00698097236454j))
     src = blocks.vector_source_s(self.src_data)
     op  = filter.freq_xlating_fir_filter_scc(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
Exemplo n.º 42
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]))
Exemplo n.º 43
0
 def test_fir_filter_ccf_002(self):
     self.generate_ccf_source()
     expected_data = ((6.419439159799367e-05 - 0.0006292851758189499j),
                      (-0.00037074743886478245 + 0.0013245552545413375j),
                      (0.0006853155209682882 - 0.0023769831750541925j),
                      (-0.001427714480087161 + 0.002608160488307476j),
                      (0.0015907397028058767 - 0.000811046629678458j),
                      (-0.0004226673918310553 - 0.0024389736354351044j),
                      (-0.0013841050677001476 + 0.006231029983609915j),
                      (0.0035029184073209763 - 0.009738259017467499j),
                      (-0.005924836732447147 + 0.010320881381630898j),
                      (0.006831614300608635 - 0.003950652200728655j),
                      (-0.0021247887052595615 - 0.015604906715452671j),
                      (-0.04283163696527481 + 0.09995654970407486j),
                      (-0.01391829177737236 + 0.07924056798219681j),
                      (0.010886997915804386 - 0.02463012933731079j),
                      (-0.0056075905449688435 + 0.004998659715056419j),
                      (0.0016976913902908564 + 0.004312459379434586j),
                      (0.0007344821933656931 - 0.007861112244427204j),
                      (-0.002173811662942171 + 0.007211671676486731j),
                      (0.0022051059640944004 -
                       0.00402153329923749j), (-0.0011226903880015016 +
                                               0.0009080505697056651j))
     src = blocks.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccf(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 44
0
    def test03(self):
        # Test complex/complex version with varying input
        omega = 2
        gain_omega = 0.01
        mu = 0.25
        gain_mu = 0.1
        omega_rel_lim = 0.0001

        self.test = digital.clock_recovery_mm_cc(omega, gain_omega,
                                                 mu, gain_mu,
                                                 omega_rel_lim)
        
        data = 1000*[complex(1, 1), complex(1, 1), complex(-1, -1), complex(-1, -1)]
        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()
        
        expected_result = 1000*[complex(-1.2, -1.2), complex(1.2, 1.2)]
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 100
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]
        
        #print expected_result
        #print dst_data
        
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
Exemplo n.º 45
0
 def test_fir_filter_ccc_001(self):
     self.generate_ccc_source()
     expected_data = (
         (0.0036842757836 - 0.0114002721384j),
         (0.00324621866457 - 0.0108166672289j),
         (0.00206564785913 - 0.00923090614378j), (0.00109899020754 -
                                                  0.00656201224774j),
         (0.000506619049702 - 0.00402844604105j), (-0.000523390364833 -
                                                   0.00166808743961j),
         (-0.00140534969978 + 0.00103991874494j), (-0.00154365820345 +
                                                   0.00315759982914j),
         (-0.00180402118713 + 0.00427215453237j), (-0.00216706306674 +
                                                   0.00524478312582j),
         (-0.00178848754149 + 0.0057489364408j), (-0.00129876169376 +
                                                  0.00512680830434j),
         (-0.00122803379782 + 0.00427244976163j), (-0.000722666736692 +
                                                   0.00351428100839j),
         (5.53092104383e-05 + 0.00207865727134j), (0.000227351076319 +
                                                   0.000517217209563j),
         (0.000414477253798 - 0.000383921898901j), (0.000998671515845 -
                                                    0.00135387131013j),
         (0.00104933069088 - 0.00243046949618j), (0.000765930046327 -
                                                  0.0026717747096j))
     src = blocks.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccc(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 46
0
    def transform(self, src_data, rate, freq):
	src = blocks.vector_source_f(src_data, False)
        dft = fft.goertzel_fc(rate, rate, freq)
	dst = blocks.vector_sink_c()
	self.tb.connect(src, dft, dst)
	self.tb.run()
	return dst.data()
Exemplo n.º 47
0
 def test_fir_filter_ccc_002(self):
     self.generate_ccc_source()
     expected_data = (
         (-0.000650451984257 + 0.00120697380044j),
         (-9.59713361226e-05 + 0.00102412770502j),
         (0.000958710326813 - 0.00145424995571j), (0.000901343999431 -
                                                   0.00290832063183j),
         (-0.000822560978122 + 0.000296717538731j), (-0.00211223773658 +
                                                     0.00519825471565j),
         (-0.00037001183955 + 0.00358242215589j), (0.00327983591706 -
                                                   0.00616005761549j),
         (0.00356886954978 - 0.0117237549275j), (-0.00328874029219 +
                                                 0.00182871113066j),
         (-0.0139285130426 + 0.0320657044649j), (-0.0198133718222 +
                                                 0.0562113076448j),
         (-0.0157803222537 + 0.0530290603638j), (-0.00550725404173 +
                                                 0.0255754813552j),
         (0.00252919178456 - 0.00232240976766j), (0.00368427345529 -
                                                  0.0114002330229j),
         (0.000506620621309 - 0.00402843113989j), (-0.00180401885882 +
                                                   0.00427213776857j),
         (-0.00122803344857 + 0.00427243299782j), (0.000414476031438 -
                                                   0.000383919978049j))
     src = blocks.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccc(4, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 48
0
    def test_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        freq = 100

        fDTs = 0.01
        K = 4
        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.fading_model(8, fDTs=fDTs, LOS=True,
                                   K=K, seed=0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        self.assertAlmostEqual(K, op.K(), 4)
        self.assertAlmostEqual(fDTs, op.fDTs(), 4)
Exemplo n.º 49
0
 def test_fir_filter_fcf_001(self):
     self.generate_fcf_source()
     expected_data = (
         (0.000247188087087 - 0.000157509770361j),
         (-0.000155229790835 - 0.000246197130764j),
         (-0.000264906557277 + 0.000174603672349j), (6.99016964063e-05 +
                                                     0.000174961372977j),
         (-5.48477692064e-05 - 0.0001131295503j), (-0.000237467131228 +
                                                   0.000118011368613j),
         (0.000136614587973 + 0.000229531884543j), (0.000229347482673 -
                                                    0.000166581812664j),
         (-0.000106010869786 - 0.000150042149471j), (2.92293734674e-05 +
                                                     0.000142060467624j),
         (0.000228707227507 - 9.30760797928e-05j), (-0.000124306126963 -
                                                    0.000216641055886j),
         (-0.000204823678359 + 0.00016052465071j), (0.00012825592421 +
                                                    0.000133123627165j),
         (-1.18284006021e-05 - 0.000159015646204j), (-0.000219973371713 +
                                                     7.5438656495e-05j),
         (0.000114713984658 + 0.000205190401175j), (0.000185727752978 -
                                                    0.000154630601173j),
         (-0.000141745767905 - 0.000120098840853j), (-3.9850056055e-07 +
                                                     0.000168364742422j))
     src = blocks.vector_source_f(self.src_data)
     op = filter.freq_xlating_fir_filter_fcf(1, self.taps, self.fc, self.fs)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)