Example #1
0
    def test_stretch_01(self):
        tb = self.tb

        data = 10*[1,]
        data0 = [x / 20.0 for x in data]
        data1 = [x / 10.0 for x in data]

        expected_result0 = 10*[0.05,]
        expected_result1 = 10*[0.1,]

        src0 = blocks.vector_source_f(data0, False)
        src1 = blocks.vector_source_f(data1, False)
        inter = blocks.streams_to_vector(gr.sizeof_float, 2)
        op = blocks.stretch_ff(0.1, 2)
        deinter = blocks.vector_to_streams(gr.sizeof_float, 2)
        dst0 = blocks.vector_sink_f()
        dst1 = blocks.vector_sink_f()

        tb.connect(src0, (inter,0))
        tb.connect(src1, (inter,1))
        tb.connect(inter, op)
        tb.connect(op, deinter)
        tb.connect((deinter,0), dst0)
        tb.connect((deinter,1), dst1)
        tb.run()

        dst0_data = dst0.data()
        dst1_data = dst1.data()

        self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4)
        self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4)
Example #2
0
 def __init__(self, n_chans, n_filterbanks=1, taps=None, outchans=None,
              atten=100, bw=1.0, tb=0.2, ripple=0.1):
     if n_filterbanks > n_chans:
         n_filterbanks = n_chans
     if outchans is None:
         outchans = list(range(n_chans))
     gr.hier_block2.__init__(
         self, "pfb_channelizer_hier_ccf",
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(len(outchans), len(outchans), gr.sizeof_gr_complex))
     if taps is None:
         taps = optfir.low_pass(1, n_chans, bw, bw+tb, ripple, atten)
     taps = list(taps)
     extra_taps = int(math.ceil(1.0*len(taps)/n_chans)*n_chans - len(taps))
     taps = taps + [0] * extra_taps
     # Make taps for each channel
     chantaps = [list(reversed(taps[i: len(taps): n_chans])) for i in range(0, n_chans)]
     # Convert the input stream into a stream of vectors.
     self.s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, n_chans)
     # Create a mapping to separate out each filterbank (a group of channels to be processed together)
     # And a list of sets of taps for each filterbank.
     low_cpp = int(n_chans / n_filterbanks)
     extra = n_chans - low_cpp*n_filterbanks
     cpps = [low_cpp+1]*extra + [low_cpp]*(n_filterbanks-extra)
     splitter_mapping = []
     filterbanktaps = []
     total = 0
     for cpp in cpps:
         splitter_mapping.append([(0, i) for i in range(total, total+cpp)])
         filterbanktaps.append(chantaps[total: total+cpp])
         total += cpp
     assert(total == n_chans)
     # Split the stream of vectors in n_filterbanks streams of vectors.
     self.splitter = blocks.vector_map(gr.sizeof_gr_complex, [n_chans], splitter_mapping)
     # Create the filterbanks
     self.fbs = [filter.filterbank_vcvcf(taps) for taps in filterbanktaps]
     # Combine the streams of vectors back into a single stream of vectors.
     combiner_mapping = [[]]
     for i, cpp in enumerate(cpps):
         for j in range(cpp):
             combiner_mapping[0].append((i, j))
     self.combiner = blocks.vector_map(gr.sizeof_gr_complex, cpps, combiner_mapping)
     # Add the final FFT to the channelizer.
     self.fft = fft.fft_vcc(n_chans, forward=True, window=[1.0]*n_chans)
     # Select the desired channels
     if outchans != list(range(n_chans)):
         selector_mapping = [[(0, i) for i in outchans]]
         self.selector = blocks.vector_map(gr.sizeof_gr_complex, [n_chans], selector_mapping)
     # Convert stream of vectors to a normal stream.
     self.v2ss = blocks.vector_to_streams(gr.sizeof_gr_complex, len(outchans))
     self.connect(self, self.s2v, self.splitter)
     for i in range(0, n_filterbanks):
         self.connect((self.splitter, i), self.fbs[i], (self.combiner, i))
     self.connect(self.combiner, self.fft)
     if outchans != list(range(n_chans)):
         self.connect(self.fft, self.selector, self.v2ss)
     else:
         self.connect(self.fft, self.v2ss)
     for i in range(0, len(outchans)):
         self.connect((self.v2ss, i), (self, i))
Example #3
0
    def test_stretch_01(self):
        tb = self.tb

        data = 10*[1,]
        data0 = map(lambda x: x/20.0, data)
        data1 = map(lambda x: x/10.0, data)

        expected_result0 = 10*[0.05,]
        expected_result1 = 10*[0.1,]

        src0 = blocks.vector_source_f(data0, False)
        src1 = blocks.vector_source_f(data1, False)
        inter = blocks.streams_to_vector(gr.sizeof_float, 2)
        op = blocks.stretch_ff(0.1, 2)
        deinter = blocks.vector_to_streams(gr.sizeof_float, 2)
        dst0 = blocks.vector_sink_f()
        dst1 = blocks.vector_sink_f()
        
        tb.connect(src0, (inter,0))
        tb.connect(src1, (inter,1))
        tb.connect(inter, op)
        tb.connect(op, deinter)
        tb.connect((deinter,0), dst0)
        tb.connect((deinter,1), dst1)
        tb.run()

        dst0_data = dst0.data()
        dst1_data = dst1.data()

        self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4)
        self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4)
Example #4
0
 def __init__(self, n_chans, n_filterbanks=1, taps=None, outchans=None,
              atten=100, bw=1.0, tb=0.2, ripple=0.1):
     if n_filterbanks > n_chans:
         n_filterbanks = n_chans
     if outchans is None:
         outchans = range(n_chans)
     gr.hier_block2.__init__(
         self, "pfb_channelizer_hier_ccf",
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(len(outchans), len(outchans), gr.sizeof_gr_complex))
     if taps is None:
         taps = optfir.low_pass(1, n_chans, bw, bw+tb, ripple, atten)
     taps = list(taps)
     extra_taps = int(math.ceil(1.0*len(taps)/n_chans)*n_chans - len(taps))
     taps = taps + [0] * extra_taps
     # Make taps for each channel
     chantaps = [list(reversed(taps[i: len(taps): n_chans])) for i in range(0, n_chans)]
     # Convert the input stream into a stream of vectors.
     self.s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, n_chans)
     # Create a mapping to separate out each filterbank (a group of channels to be processed together)
     # And a list of sets of taps for each filterbank.
     low_cpp = int(n_chans/n_filterbanks)
     extra = n_chans - low_cpp*n_filterbanks
     cpps = [low_cpp+1]*extra + [low_cpp]*(n_filterbanks-extra)
     splitter_mapping = []
     filterbanktaps = []
     total = 0
     for cpp in cpps:
         splitter_mapping.append([(0, i) for i in range(total, total+cpp)])
         filterbanktaps.append(chantaps[total: total+cpp])
         total += cpp
     assert(total == n_chans)
     # Split the stream of vectors in n_filterbanks streams of vectors.
     self.splitter = blocks.vector_map(gr.sizeof_gr_complex, [n_chans], splitter_mapping)
     # Create the filterbanks
     self.fbs = [filter.filterbank_vcvcf(taps) for taps in filterbanktaps]
     # Combine the streams of vectors back into a single stream of vectors.
     combiner_mapping = [[]]
     for i, cpp in enumerate(cpps):
         for j in range(cpp):
             combiner_mapping[0].append((i, j))
     self.combiner = blocks.vector_map(gr.sizeof_gr_complex, cpps, combiner_mapping)
     # Add the final FFT to the channelizer.
     self.fft = fft.fft_vcc(n_chans, forward=True, window=[1.0]*n_chans)
     # Select the desired channels
     if outchans != range(n_chans):
         selector_mapping = [[(0, i) for i in outchans]]
         self.selector = blocks.vector_map(gr.sizeof_gr_complex, [n_chans], selector_mapping)
     # Convert stream of vectors to a normal stream.
     self.v2ss = blocks.vector_to_streams(gr.sizeof_gr_complex, len(outchans))
     self.connect(self, self.s2v, self.splitter)
     for i in range(0, n_filterbanks):
         self.connect((self.splitter, i), self.fbs[i], (self.combiner, i))
     self.connect(self.combiner, self.fft)
     if outchans != range(n_chans):
         self.connect(self.fft, self.selector, self.v2ss)
     else:
         self.connect(self.fft, self.v2ss)
     for i in range(0, len(outchans)):
         self.connect((self.v2ss, i), (self, i))
Example #5
0
    def __init__(self, sample_rate, amplitude):
        gr.hier_block2.__init__(
            self,
            "gsm_source_c",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        self._symb_rate = 13e6 / 48
        self._samples_per_symbol = 2

        self._data = blocks.vector_source_b(self.gen_gsm_seq(), True, 2)
        self._split = blocks.vector_to_streams(gr.sizeof_char * 1, 2)

        self._pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self._mod = digital.gmsk_mod(self._samples_per_symbol, bt=0.35)

        self._pwr_f = blocks.char_to_float(1, 1)
        self._pwr_c = blocks.float_to_complex(1)
        self._pwr_w = blocks.repeat(gr.sizeof_gr_complex * 1,
                                    self._samples_per_symbol)

        self._mul = blocks.multiply_vcc(1)
        self._interpolate = filter.fractional_resampler_cc(
            0, (self._symb_rate * self._samples_per_symbol) / sample_rate)
        self._scale = blocks.multiply_const_cc(amplitude)

        self.connect(self._data, self._split)
        self.connect((self._split, 0), self._pack, self._mod, (self._mul, 0))
        self.connect((self._split, 1), self._pwr_f, self._pwr_c, self._pwr_w,
                     (self._mul, 1))
        self.connect(self._mul, self._interpolate, self._scale, self)
Example #6
0
    def __init__(self, sample_rate, amplitude):
        gr.hier_block2.__init__(self, "gsm_source_c",
            gr.io_signature(0, 0, 0), # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

        self._symb_rate = 13e6 / 48;
        self._samples_per_symbol = 2

        self._data  = blocks.vector_source_b(self.gen_gsm_seq(), True, 2)
        self._split = blocks.vector_to_streams(gr.sizeof_char*1, 2)

        self._pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self._mod  = digital.gmsk_mod(self._samples_per_symbol, bt=0.35)

        self._pwr_f = blocks.char_to_float(1, 1)
        self._pwr_c = blocks.float_to_complex(1)
        self._pwr_w = blocks.repeat(gr.sizeof_gr_complex*1, self._samples_per_symbol)

        self._mul = blocks.multiply_vcc(1)
        self._interpolate = filter.fractional_resampler_cc( 0,
            (self._symb_rate * self._samples_per_symbol) / sample_rate )
        self._scale = blocks.multiply_const_cc(amplitude)

        self.connect(self._data, self._split)
        self.connect((self._split, 0), self._pack, self._mod, (self._mul, 0))
        self.connect((self._split, 1), self._pwr_f, self._pwr_c, self._pwr_w, (self._mul, 1))
        self.connect(self._mul, self._interpolate, self._scale, self)
Example #7
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1e3

        ##################################################
        # Message Queues
        ##################################################
        #blocks_message_sink_0_msgq_out = blocks_message_source_0_msgq_in = gr.msg_queue(2)
        self.blocks_message_source_0_msgq_in = gr.msg_queue()

        ##################################################
        # Blocks
        ##################################################
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_char * 1, 4)
        #self.blocks_vector_source_x_0 = blocks.vector_source_b((1, 0, 0, 1), True, 4, [])
        self.blocks_uchar_to_float_0_2 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0_1 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 samp_rate, True)
        self.blocks_message_source_0 = blocks.message_source(
            gr.sizeof_char * 4, self.blocks_message_source_0_msgq_in)
        #self.blocks_message_source_0.message_port_register_in(pmt.pmt_intern("input_port"))
        #self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char*4, blocks_message_sink_0_msgq_out, False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float * 1,
                                                   "simple.float", False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_message_source_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.blocks_add_xx_0, 3))
        self.connect((self.blocks_uchar_to_float_0_0, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.blocks_uchar_to_float_0_1, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_uchar_to_float_0_2, 0),
                     (self.blocks_add_xx_0, 0))
        #self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_message_sink_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 3),
                     (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 2),
                     (self.blocks_uchar_to_float_0_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.blocks_uchar_to_float_0_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.blocks_uchar_to_float_0_2, 0))
Example #8
0
    def __init__(self):
        gr.hier_block2.__init__(self,
                                "bch_viterbi_vfvb",
                                gr.io_signature(1, 1, gr.sizeof_float * 120), # Input signature
                                gr.io_signature(1, 1, gr.sizeof_char * 40)) # Output signature

        # Define blocks and connect them
        # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff)
        #self.rpt = blocks.repeat(gr.sizeof_float * 120, 2)
        # viterbi decoder requires stream as input
        #self.vtos = blocks.vector_to_stream(1 * gr.sizeof_float, 120)

        # self.vtss = blocks.vector_to_streams(1* gr.sizeof_float, 120, "bch_viterbi_vector_to_streams_0")
        self.vtss = blocks.vector_to_streams(1* gr.sizeof_float, 120)
        #self.app = blocks.streams_to_stream(1* gr.sizeof_float, 138, "bch_viterbi_streams_to_stream_0")
        self.app = blocks.streams_to_stream(1* gr.sizeof_float, 138)
        self.connect(self, self.vtss)
        for i in range(18):
            self.connect( (self.vtss, 120-18+i), (self.app, i) )
        for i in range(120):
            self.connect( (self.vtss, i), (self.app, i+18) )



        # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation)
        self.fsm = trellis.fsm(1, 3, [91, 121, 117])

        # Values for viterbi decoder        
        K = 46  # steps for one coding block
        SO = 0  # initial state
        SK = -1 # final state (in this case unknown, therefore -1)
        D = 3   # dimensionality
        # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols.
        # (packed into one byte {0,1,...,7} )
        # with NRZ coding follows: 
        # 0 -->  1
        # 1 --> -1
        # This leads to the following constellation input
        #               |  0  |  1   | 2    | 3     |  4   |  5    |  6    |  7     |
        constellation = [1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1]
        # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O())
        # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE
        # FSM    = Finite State Machine
        # K      = number of output symbols produced by the FSM
        # SO     = initial state of the FSM
        # SK     = final state of the FSM (unknown in this example)
        # D      = dimensionality
        # TABLE  = constellation of the input symbols
        # self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D, constellation, 200, "bch_viterbi_combined_fb_0")
        self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D, constellation, 200)
        self.connect(self.app, self.vit)
        # connect all streams which are crated yet        
        #self.connect(self,self.rpt,self.vtos,self.vit)
        # self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6, "bch_viterbi_keep_m_in_n_0")
        self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6)
        # self.tovec = blocks.stream_to_vector(1, 40, "bch_viterbi_stream_to_vector_0")
        self.tovec = blocks.stream_to_vector(1, 40)
        self.connect(self.vit, self.keep, self.tovec, self)
Example #9
0
    def __rebuild(self):
        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(
                itemsize=output_length * gr.sizeof_float, nstreams=2)

        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(
            math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)

        self.__gate = blocks.copy(gr.sizeof_gr_complex)
        self.__gate.set_enabled(not self.__paused)

        self.__fft_sink = MessageDistributorSink(
            itemsize=output_length * gr.sizeof_char,
            context=self.__context,
            migrate=self.__fft_sink,
            notify=self.__update_interested)
        self.__overlapper = _OverlapGimmick(size=input_length,
                                            factor=overlap_factor,
                                            itemsize=self.__itemsize)

        # Adjusts units so displayed level is independent of resolution and sample rate. Also throw in the packing offset
        compensation = to_dB(input_length / sample_rate) + self.__power_offset
        # TODO: Consider not using the logpwrfft block

        self.__logpwrfft = logpwrfft.logpwrfft_c(
            sample_rate=sample_rate * overlap_factor,
            fft_size=input_length,
            ref_scale=10.0**(-compensation / 20.0) *
            2,  # not actually using this as a reference scale value but avoiding needing to use a separate add operation to apply the unit change -- this expression is the inverse of what logpwrfft does internally
            frame_rate=self.__frame_rate,
            avg_alpha=1.0,
            average=False)
        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(
            vlen=self.__freq_resolution, scale=1.0)

        self.__scope_sink = MessageDistributorSink(
            itemsize=self.__time_length * gr.sizeof_gr_complex,
            context=self.__context,
            migrate=self.__scope_sink,
            notify=self.__update_interested)
        self.__scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)
Example #10
0
    def __init__(self):
        gr.hier_block2.__init__(
            self,
            "bch_viterbi_vfvb",
            gr.io_signature(1, 1, gr.sizeof_float * 120),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char * 40))  # Output signature

        # Define blocks and connect them
        # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff)
        #self.rpt = blocks.repeat(gr.sizeof_float * 120, 2)
        # viterbi decoder requires stream as input
        #self.vtos = blocks.vector_to_stream(1 * gr.sizeof_float, 120)

        self.vtss = blocks.vector_to_streams(1 * gr.sizeof_float, 120)
        self.app = blocks.streams_to_stream(1 * gr.sizeof_float, 138)
        self.connect(self, self.vtss)
        for i in range(18):
            self.connect((self.vtss, 120 - 18 + i), (self.app, i))
        for i in range(120):
            self.connect((self.vtss, i), (self.app, i + 18))

        # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation)
        self.fsm = trellis.fsm(1, 3, [91, 121, 117])

        # Values for viterbi decoder
        K = 46  # steps for one coding block
        SO = 0  # initial state
        SK = -1  # final state (in this case unknown, therefore -1)
        D = 3  # dimensionality
        # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols.
        # (packed into one byte {0,1,...,7} )
        # with NRZ coding follows:
        # 0 -->  1
        # 1 --> -1
        # This leads to the following constellation input
        #               |  0  |  1   | 2    | 3     |  4   |  5    |  6    |  7     |
        constellation = [
            1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1,
            -1, 1, -1, -1, -1
        ]
        # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O())
        # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE
        # FSM    = Finite State Machine
        # K      = number of output symbols produced by the FSM
        # SO     = initial state of the FSM
        # SK     = final state of the FSM (unknown in this example)
        # D      = dimensionality
        # TABLE  = constellation of the input symbols
        self.vit = trellis.viterbi_combined_fb(self.fsm, K, SO, SK, D,
                                               constellation, 200)
        self.connect(self.app, self.vit)
        # connect all streams which are crated yet
        #self.connect(self,self.rpt,self.vtos,self.vit)
        self.keep = blocks.keep_m_in_n(gr.sizeof_char, 40, 46, 6)
        self.tovec = blocks.stream_to_vector(1, 40)
        self.connect(self.vit, self.keep, self.tovec, self)
Example #11
0
 def __do_connect(self, reason):
     # log.msg(u'receiver do_connect: %s' % (reason,))
     self.context.lock()
     try:
         self.disconnect_all()
         
         # Connect input of demodulator
         if self.__demod_tunable:
             self.connect(self, self.__demodulator)
         else:
             self.connect(self, self.__rotator, self.__demodulator)
         
         if self.__demod_output:
             # Construct stereo-to-mono conversion (used at least for level probe)
             if self.__demod_stereo:
                 splitter = blocks.vector_to_streams(gr.sizeof_float, 2)
                 mono_audio = blocks.multiply_matrix_ff(((0.5, 0.5),))
                 self.connect(self.__demodulator, splitter)
                 self.connect((splitter, 0), (mono_audio, 0))
                 self.connect((splitter, 1), (mono_audio, 1))
             else:
                 mono_audio = self.__demodulator
             
             # Connect mono audio to level probe
             self.connect(mono_audio, self.probe_audio)
             
             # Connect demodulator to output gain control, converting as needed
             if (self.__audio_channels == 2) == self.__demod_stereo:
                 # stereo to stereo or mono to mono
                 self.connect(self.__demodulator, self.__audio_gain_block)
             elif self.__audio_channels == 2 and not self.__demod_stereo:
                 # mono to stereo
                 duplicator = blocks.streams_to_vector(gr.sizeof_float, 2)
                 self.connect(self.__demodulator, (duplicator, 0))
                 self.connect(self.__demodulator, (duplicator, 1))
                 self.connect(duplicator, self.__audio_gain_block)
             elif self.__audio_channels == 1 and self.__demod_stereo:
                 # stereo to mono
                 self.connect(mono_audio, self.__audio_gain_block)
             else:
                 raise Exception('shouldn\'t happen')
                 
             # Connect gain control to output of receiver
             self.connect(self.__audio_gain_block, self)
         else:
             # Dummy output, ignored by containing block
             self.connect(
                 blocks.vector_source_f([], vlen=self.__audio_channels),
                 self)
         
         if self.__output_type != self.__last_output_type:
             self.__last_output_type = self.__output_type
             self.context.changed_needed_connections(u'changed output type')
     finally:
         self.context.unlock()
Example #12
0
 def __init__(self, mode, input_rate, output_rate, demod_class=None, freq=0.0, quiet=False):
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(2, 2, gr.sizeof_float))
     
     if demod_class is None:
         mode_def = lookup_mode(mode)
         if mode_def is None:
             raise Exception('{}: No demodulator registered for mode {!r}, only {!r}'.format(
                 type(self).__name__, mode, [md.mode for md in get_modes()]))
         demod_class = mode_def.demod_class
     
     context = _DemodulatorAdapterContext(adapter=self, freq=freq)
     
     demod = self.__demodulator = IDemodulator(demod_class(
         mode=mode,
         input_rate=input_rate,
         context=context))
     self.connect(self, demod)
     
     output_type = demod.get_output_type()
     demod_output_rate = output_type.get_sample_rate()
     same_rate = demod_output_rate == output_rate
     stereo = output_type.get_kind() == 'STEREO'
     
     # connect outputs, resampling and adapting mono/stereo as needed
     # TODO: Make the logic for this in receiver.py reusable?
     if output_type.get_kind() == 'NONE':
         # TODO: produce correct sample rate of zeroes and maybe a warning
         dummy = blocks.vector_source_f([])
         self.connect(dummy, (self, 0))
         self.connect(dummy, (self, 1))
     else:
         if stereo:
             splitter = blocks.vector_to_streams(gr.sizeof_float, 2)
             self.connect(demod, splitter)
         if same_rate:
             if stereo:
                 self.connect((splitter, 0), (self, 0))
                 self.connect((splitter, 1), (self, 1))
             else:
                 self.connect(demod, (self, 0))
                 self.connect(demod, (self, 1))
         else:
             if not quiet:
                 gr.log.info(b'{}: Native {} demodulated rate is {}; resampling to {}'.format(
                     type(self).__name__, mode, demod_output_rate, output_rate))
             if stereo:
                 self.connect((splitter, 0), make_resampler(demod_output_rate, output_rate), (self, 0))
                 self.connect((splitter, 1), make_resampler(demod_output_rate, output_rate), (self, 1))
             else:
                 resampler = make_resampler(demod_output_rate, output_rate)
                 self.connect(demod, resampler, (self, 0))
                 self.connect(resampler, (self, 1))
Example #13
0
 def __init__(self, mode, input_rate, output_rate, demod_class=None, freq=0.0, quiet=False):
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(2, 2, gr.sizeof_float))
     
     if demod_class is None:
         mode_def = lookup_mode(mode)
         if mode_def is None:
             raise Exception('{}: No demodulator registered for mode {!r}, only {!r}'.format(
                 type(self).__name__, mode, [md.mode for md in get_modes()]))
         demod_class = mode_def.demod_class
     
     context = _DemodulatorAdapterContext(adapter=self, freq=freq)
     
     demod = self.__demodulator = IDemodulator(demod_class(
         mode=mode,
         input_rate=input_rate,
         context=context))
     self.connect(self, demod)
     
     output_type = demod.get_output_type()
     demod_output_rate = output_type.get_sample_rate()
     same_rate = demod_output_rate == output_rate
     stereo = output_type.get_kind() == 'STEREO'
     
     # connect outputs, resampling and adapting mono/stereo as needed
     # TODO: Make the logic for this in receiver.py reusable?
     if output_type.get_kind() == 'NONE':
         # TODO: produce correct sample rate of zeroes and maybe a warning
         dummy = blocks.vector_source_f([])
         self.connect(dummy, (self, 0))
         self.connect(dummy, (self, 1))
     else:
         if stereo:
             splitter = blocks.vector_to_streams(gr.sizeof_float, 2)
             self.connect(demod, splitter)
         if same_rate:
             if stereo:
                 self.connect((splitter, 0), (self, 0))
                 self.connect((splitter, 1), (self, 1))
             else:
                 self.connect(demod, (self, 0))
                 self.connect(demod, (self, 1))
         else:
             if not quiet:
                 gr.log.info('{}: Native {} demodulated rate is {}; resampling to {}'.format(
                     type(self).__name__, mode, demod_output_rate, output_rate))
             if stereo:
                 self.connect((splitter, 0), make_resampler(demod_output_rate, output_rate), (self, 0))
                 self.connect((splitter, 1), make_resampler(demod_output_rate, output_rate), (self, 1))
             else:
                 resampler = make_resampler(demod_output_rate, output_rate)
                 self.connect(demod, resampler, (self, 0))
                 self.connect(resampler, (self, 1))
Example #14
0
    def __do_connect(self, reason):
        # log.msg(u'receiver do_connect: %s' % (reason,))
        self.context.lock()
        try:
            self.disconnect_all()

            # Connect input of demodulator
            if self.__demod_tunable:
                self.connect(self, self.__demodulator)
            else:
                self.connect(self, self.__rotator, self.__demodulator)

            if self.__demod_output:
                # Construct stereo-to-mono conversion (used at least for level probe)
                if self.__demod_stereo:
                    splitter = blocks.vector_to_streams(gr.sizeof_float, 2)
                    mono_audio = blocks.multiply_matrix_ff(((0.5, 0.5), ))
                    self.connect(self.__demodulator, splitter)
                    self.connect((splitter, 0), (mono_audio, 0))
                    self.connect((splitter, 1), (mono_audio, 1))
                else:
                    mono_audio = self.__demodulator

                # Connect mono audio to level probe
                self.connect(mono_audio, self.probe_audio)

                # Connect demodulator to output gain control, converting as needed
                if (self.__audio_channels == 2) == self.__demod_stereo:
                    # stereo to stereo or mono to mono
                    self.connect(self.__demodulator, self.__audio_gain_block)
                elif self.__audio_channels == 2 and not self.__demod_stereo:
                    # mono to stereo
                    duplicator = blocks.streams_to_vector(gr.sizeof_float, 2)
                    self.connect(self.__demodulator, (duplicator, 0))
                    self.connect(self.__demodulator, (duplicator, 1))
                    self.connect(duplicator, self.__audio_gain_block)
                elif self.__audio_channels == 1 and self.__demod_stereo:
                    # stereo to mono
                    self.connect(mono_audio, self.__audio_gain_block)
                else:
                    raise Exception('shouldn\'t happen')

                # Connect gain control to output of receiver
                self.connect(self.__audio_gain_block, self)
            else:
                # Dummy output, ignored by containing block
                self.connect(
                    blocks.vector_source_f([], vlen=self.__audio_channels),
                    self)

            if self.__output_type != self.__last_output_type:
                self.__last_output_type = self.__output_type
                self.context.changed_needed_connections(u'changed output type')
        finally:
            self.context.unlock()
Example #15
0
 def __rebuild(self):
     if self.__signal_type.is_analytic():
         input_length = self.__freq_resolution
         output_length = self.__freq_resolution
         self.__after_fft = None
     else:
         # use vector_to_streams to cut the output in half and discard the redundant part
         input_length = self.__freq_resolution * 2
         output_length = self.__freq_resolution
         self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
     
     sample_rate = self.__signal_type.get_sample_rate()
     overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
     # sanity limit -- OverlapGimmick is not free
     overlap_factor = min(16, overlap_factor)
     
     self.__gate = blocks.copy(gr.sizeof_gr_complex)
     self.__gate.set_enabled(not self.__paused)
     
     self.__fft_sink = MessageDistributorSink(
         itemsize=output_length * gr.sizeof_char,
         context=self.__context,
         migrate=self.__fft_sink,
         notify=self.__update_interested)
     self.__overlapper = _OverlapGimmick(
         size=input_length,
         factor=overlap_factor,
         itemsize=self.__itemsize)
     
     # Adjusts units so displayed level is independent of resolution and sample rate. Also throw in the packing offset
     compensation = to_dB(input_length / sample_rate) + self.__power_offset
     # TODO: Consider not using the logpwrfft block
     
     self.__logpwrfft = logpwrfft.logpwrfft_c(
         sample_rate=sample_rate * overlap_factor,
         fft_size=input_length,
         ref_scale=10.0 ** (-compensation / 20.0) * 2,  # not actually using this as a reference scale value but avoiding needing to use a separate add operation to apply the unit change -- this expression is the inverse of what logpwrfft does internally
         frame_rate=self.__frame_rate,
         avg_alpha=1.0,
         average=False)
     # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
     self.__fft_converter = blocks.float_to_char(vlen=self.__freq_resolution, scale=1.0)
 
     self.__scope_sink = MessageDistributorSink(
         itemsize=self.__time_length * gr.sizeof_gr_complex,
         context=self.__context,
         migrate=self.__scope_sink,
         notify=self.__update_interested)
     self.__scope_chunker = blocks.stream_to_vector_decimator(
         item_size=gr.sizeof_gr_complex,
         sample_rate=sample_rate,
         vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
         vec_len=self.__time_length)
Example #16
0
 def __init__(self, sample_rate, device_name, channels, ok_to_block=False):
     assert channels > 0
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_float * channels),
         gr.io_signature(0, 0, 0))
     sink = audio.sink(sample_rate, device_name, ok_to_block=ok_to_block)
     if channels > 1:
         splitter = blocks.vector_to_streams(gr.sizeof_float, channels)
         self.connect(self, splitter)
         for ch in xrange(channels):
             self.connect((splitter, ch), (sink, ch))
     else:
         self.connect(self, sink)
Example #17
0
 def __init__(self, sample_rate, device_name, channels, ok_to_block=False):
     assert channels > 0
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_float * channels),
         gr.io_signature(0, 0, 0))
     sink = audio.sink(sample_rate, device_name, ok_to_block=ok_to_block)
     if channels > 1:
         splitter = blocks.vector_to_streams(gr.sizeof_float, channels)
         self.connect(self, splitter)
         for ch in xrange(channels):
             self.connect((splitter, ch), (sink, ch))
     else:
         self.connect(self, sink)
Example #18
0
    def __init__(self, mpoints, taps=None):
        """
        Takes 1 complex stream in, produces M complex streams out
        that runs at 1/M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        Same channel to frequency mapping as described above.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(
            self,
            "analysis_filterbank",
            gr.io_signature(1, 1, item_size),  # Input signature
            gr.io_signature(mpoints, mpoints, item_size))  # Output signature

        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0, )

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        # print(>> sys.stderr, "mpoints =", mpoints, "len(sub_taps) =", len(sub_taps))

        self.s2ss = blocks.stream_to_streams(item_size, mpoints)
        # filters here
        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.fft = fft.fft_vcc(mpoints, True, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)

        self.connect(self, self.s2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[mpoints - i - 1])
            self.connect((self.s2ss, i), f)
            self.connect(f, (self.ss2v, i))
            self.connect((self.v2ss, i), (self, i))

        self.connect(self.ss2v, self.fft, self.v2ss)
Example #19
0
    def __init__(self, mpoints, taps=None):
        """
        Takes 1 complex stream in, produces M complex streams out
        that runs at 1/M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        Same channel to frequency mapping as described above.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(self, "analysis_filterbank",
                                gr.io_signature(1, 1, item_size),             # Input signature
                                gr.io_signature(mpoints, mpoints, item_size)) # Output signature

        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0,)

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        # print >> sys.stderr, "mpoints =", mpoints, "len(sub_taps) =", len(sub_taps)

        self.s2ss = blocks.stream_to_streams(item_size, mpoints)
        # filters here
        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.fft = fft.fft_vcc(mpoints, True, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)

        self.connect(self, self.s2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[mpoints-i-1])
            self.connect((self.s2ss, i), f)
            self.connect(f, (self.ss2v, i))
            self.connect((self.v2ss, i), (self, i))

        self.connect(self.ss2v, self.fft, self.v2ss)
Example #20
0
    def __init__(self, in_rate, out_rate, vlen, complex=False):
        # pylint: disable=redefined-builtin
        vitemsize = gr.sizeof_gr_complex if complex else gr.sizeof_float
        itemsize = vitemsize * vlen
        gr.hier_block2.__init__(
            self, type(self).__name__,
            gr.io_signature(1, 1, itemsize),
            gr.io_signature(1, 1, itemsize))

        if vlen == 1:
            self.connect(self, make_resampler(in_rate, out_rate, complex=complex), self)
        else:
            splitter = blocks.vector_to_streams(vitemsize, vlen)
            joiner = blocks.streams_to_vector(vitemsize, vlen)
            self.connect(self, splitter)
            for ch in xrange(vlen):
                self.connect(
                    (splitter, ch),
                    make_resampler(in_rate, out_rate, complex=complex),
                    (joiner, ch))
            self.connect(joiner, self)
Example #21
0
    def test_004(self):

        #Test vector_to_streams.

        n = 8
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_vector(gr.sizeof_int, n)
        op2 = blocks.vector_to_streams(gr.sizeof_int, n)
        op3 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        self.tb.connect(src, op1, op2)
        for i in range(n):
            self.tb.connect((op2, i), (op3, i))
        self.tb.connect(op3, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Example #22
0
    def test_004(self):

        #Test vector_to_streams.

        n = 8
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_vector(gr.sizeof_int, n)
        op2 = blocks.vector_to_streams(gr.sizeof_int, n)
        op3 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        self.tb.connect(src, op1, op2)
        for i in range(n):
            self.tb.connect((op2, i), (op3, i))
        self.tb.connect(op3, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Example #23
0
    def __init__(self, in_rate, out_rate, vlen, complex=False):
        # pylint: disable=redefined-builtin
        vitemsize = gr.sizeof_gr_complex if complex else gr.sizeof_float
        itemsize = vitemsize * vlen
        gr.hier_block2.__init__(self,
                                type(self).__name__,
                                gr.io_signature(1, 1, itemsize),
                                gr.io_signature(1, 1, itemsize))

        if vlen == 1:
            self.connect(self,
                         make_resampler(in_rate, out_rate, complex=complex),
                         self)
        else:
            splitter = blocks.vector_to_streams(vitemsize, vlen)
            joiner = blocks.streams_to_vector(vitemsize, vlen)
            self.connect(self, splitter)
            for ch in six.moves.range(vlen):
                self.connect((splitter, ch),
                             make_resampler(in_rate, out_rate,
                                            complex=complex), (joiner, ch))
            self.connect(joiner, self)
Example #24
0
    def __do_connect(self):
        itemsize = self.__itemsize

        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(
                itemsize=output_length * gr.sizeof_float, nstreams=2)

        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(
            math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)

        self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length

        self.__gate = blocks.copy(itemsize)
        self.__gate.set_enabled(not self.__paused)

        overlapper = _OverlappedStreamToVector(size=input_length,
                                               factor=overlap_factor,
                                               itemsize=itemsize)

        self.__frame_dec = blocks.keep_one_in_n(
            itemsize=itemsize * input_length,
            n=max(
                1,
                int(
                    round(self.__frame_rate_to_decimation_conversion /
                          self.__frame_rate))))

        # the actual FFT logic, which is similar to GR's logpwrfft_c
        window = windows.build(self.__window_type, input_length, 6.76)
        window_power = sum(x * x for x in window)
        # TODO: use fft_vfc when applicable
        fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
            fft_size=input_length, forward=True, window=window)
        mag_squared = blocks.complex_to_mag_squared(input_length)
        logarithmizer = blocks.nlog10_ff(
            n=10,  # the "deci" in "decibel"
            vlen=input_length,
            k=(
                -to_dB(window_power) +  # compensate for window
                -to_dB(sample_rate)
                +  # convert from power-per-sample to power-per-Hz
                self.__power_offset  # offset for packing into bytes
            ))

        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(
            vlen=self.__freq_resolution, scale=1.0)

        fft_sink = self.__fft_cell.create_sink_internal(
            numpy.dtype((numpy.int8, output_length)))
        scope_sink = self.__scope_cell.create_sink_internal(
            numpy.dtype(('c8', self.__time_length)))
        scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)

        # connect everything
        self.__context.lock()
        try:
            self.disconnect_all()
            self.connect(self, self.__gate, overlapper, self.__frame_dec,
                         fft_block, mag_squared, logarithmizer)
            if self.__after_fft is not None:
                self.connect(logarithmizer, self.__after_fft)
                self.connect(self.__after_fft, self.__fft_converter, fft_sink)
                self.connect(
                    (self.__after_fft, 1),
                    blocks.null_sink(gr.sizeof_float * self.__freq_resolution))
            else:
                self.connect(logarithmizer, self.__fft_converter, fft_sink)
            if self.__enable_scope:
                self.connect(self.__gate, scope_chunker, scope_sink)
        finally:
            self.__context.unlock()
Example #25
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.Nt = Nt = 2
        self.dft_coef = dft_coef = np.exp(-2 * np.pi * 1j / Nt)
        self.A = A = np.arange(Nt)[np.newaxis]
        self.tlen = tlen = 4000
        self.samp_rate = samp_rate = 100000
        self.dft_matrix = dft_matrix = np.power(dft_coef,
                                                np.dot(A.transpose(), A))
        self.scramble_2 = scramble_2 = 2 * np.random.random_integers(
            0, 1, size=(tlen, Nt)) - 1
        self.scramble_1 = scramble_1 = 2 * np.random.random_integers(
            0, 1, size=(tlen, Nt)) - 1
        self.prefix = prefix = '/home/zhe/gr-PWF/examples'
        self.noise = noise = [np.identity(Nt), np.identity(Nt)]
        self.max_iteration = max_iteration = 20
        self.interpo = interpo = samp_rate / 1000
        self.dft_pilot_seq = dft_pilot_seq = np.tile(dft_matrix,
                                                     (tlen / Nt, 1))
        self.Q = Q = 4
        self.L = L = 2
        self.sigmagenfile = sigmagenfile = prefix + '/sigmagens/sigmagen_10.bin'
        self.pulse = pulse = filter.firdes.root_raised_cosine(
            Q, Q, 1, 0.35, 11 * Q)
        self.prewhiten1 = prewhiten1 = np.linalg.pinv(noise[1])
        self.prewhiten0 = prewhiten0 = np.linalg.pinv(noise[0])
        self.pilot_seq_2 = pilot_seq_2 = np.multiply(dft_pilot_seq, scramble_2)
        self.pilot_seq_1 = pilot_seq_1 = np.multiply(dft_pilot_seq, scramble_1)
        self.pilot2file = pilot2file = prefix + '/pilots/pilot2_4000.bin'
        self.pilot1file = pilot1file = prefix + '/pilots/pilot1_4000.bin'
        self.payload_size = payload_size = 0
        self.npoints = npoints = max_iteration * interpo
        self.noise_hat = noise_hat = [np.identity(Nt), np.identity(Nt)]
        self.ichn_gain_dB = ichn_gain_dB = 10
        self.channelfile = channelfile = prefix + '/channels/2x2channel_10dB_3.bin'
        self.channel = channel = np.true_divide(
            np.random.standard_normal(size=(L, L, Nt, Nt)) +
            np.random.standard_normal(size=(L, L, Nt, Nt)) * 1j, np.sqrt(2))
        self.Pt = Pt = 100

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            npoints,  #size
            samp_rate,  #samp_rate
            "Strong Interference (ichn_gain = 10dB)",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.1)
        self.qtgui_time_sink_x_0.set_y_axis(0, 20)

        self.qtgui_time_sink_x_0.set_y_label("Weighted Sum-Rate (bits/s/Hz)",
                                             "")

        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_AUTO,
                                                  qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                                  0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0.enable_grid(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)

        if not True:
            self.qtgui_time_sink_x_0.disable_legend()

        labels = [
            "Dual Link", "Identity Sigma", "", "", "", "", "", "", "", ""
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "blue"
        ]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.phase_corrector_0_2 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_1[:, 0],
        )
        self.phase_corrector_0_1_0 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_2[:, 0],
        )
        self.phase_corrector_0_1 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_2[:, 0],
        )
        self.phase_corrector_0_0_1 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_1[:, 1],
        )
        self.phase_corrector_0_0_0_0 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_2[:, 1],
        )
        self.phase_corrector_0_0_0 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_2[:, 1],
        )
        self.phase_corrector_0_0 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_1[:, 1],
        )
        self.phase_corrector_0 = phase_corrector(
            loop_bandwidth=2 * np.pi * 0.005,
            max_freq=2 * np.pi * 0.01,
            training_sequence=pilot_seq_1[:, 0],
        )
        self.interp_fir_filter_xxx_0_1_0 = filter.interp_fir_filter_ccc(
            Q, (pulse))
        self.interp_fir_filter_xxx_0_1_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0_1 = filter.interp_fir_filter_ccc(
            Q, (pulse))
        self.interp_fir_filter_xxx_0_1.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(
            Q, (pulse))
        self.interp_fir_filter_xxx_0_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(Q, (pulse))
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_1 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_1.declare_sample_delay(0)
        self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0.declare_sample_delay(0)
        self.blocks_vector_to_streams_1_2 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_1_1 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_1_0_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_1_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_1 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_0_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_1 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 4, 2)
        self.blocks_udp_source_1 = blocks.udp_source(gr.sizeof_gr_complex * 8,
                                                     "127.0.0.1", 1234, 1472,
                                                     True)
        self.blocks_udp_sink_1_0 = blocks.udp_sink(gr.sizeof_gr_complex * 8,
                                                   "127.0.0.1", 1234, 1472,
                                                   True)
        self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_gr_complex * 8,
                                                 "127.0.0.1", 1234, 1472, True)
        self.blocks_streams_to_vector_1_2 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_1_1 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_1_0_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_1_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_1 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_0_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_1 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 4, 2)
        self.blocks_streams_to_vector_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 4, 2)
        self.blocks_repeat_0_0 = blocks.repeat(gr.sizeof_float * 1, interpo)
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float * 1, interpo)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_gr_complex * 8,
            "/home/zhe/Dropbox/gnuradio_trunk/gnufiles/udp", False)
        self.blocks_file_sink_0.set_unbuffered(True)
        self.PWF_weighted_sum_rate_0 = PWF.weighted_sum_rate(
            L, Nt, Pt, channel, ichn_gain_dB, [1, 1], [prewhiten0, prewhiten1],
            False, channelfile)
        self.PWF_sigmagen_0 = PWF.sigmagen(L, Nt, Pt, True, sigmagenfile)
        self.PWF_power_adjust_1_0 = PWF.power_adjust(Nt, Pt, L)
        self.PWF_power_adjust_1 = PWF.power_adjust(Nt, Pt, L)
        self.PWF_pilot_receive_tx_0_0 = PWF.pilot_receive_tx(
            True, pilot1file, pilot_seq_1, Nt, tlen, noise_hat[0], tlen, 1)
        self.PWF_pilot_receive_tx_0 = PWF.pilot_receive_tx(
            True, pilot2file, pilot_seq_2, Nt, tlen, noise_hat[1], tlen, 1)
        self.PWF_pilot_receive_rx_0_0 = PWF.pilot_receive_rx(
            True, pilot2file, pilot_seq_2, prewhiten1, Nt, tlen,
            tlen + payload_size, 1)
        self.PWF_pilot_receive_rx_0 = PWF.pilot_receive_rx(
            True, pilot1file, pilot_seq_1, prewhiten0, Nt, tlen,
            tlen + payload_size, 1)
        self.PWF_pilot_gen_tx_0_0 = PWF.pilot_gen_tx(Nt, tlen, pilot_seq_2,
                                                     True, pilot2file)
        self.PWF_pilot_gen_tx_0 = PWF.pilot_gen_tx(Nt, tlen, pilot_seq_1, True,
                                                   pilot1file)
        self.PWF_pilot_gen_rx_0_0 = PWF.pilot_gen_rx(Nt, tlen, prewhiten0,
                                                     pilot_seq_1, True,
                                                     pilot1file)
        self.PWF_pilot_gen_rx_0 = PWF.pilot_gen_rx(Nt, tlen, prewhiten1,
                                                   pilot_seq_2, True,
                                                   pilot2file)
        self.PWF_debug_printmsg_0 = PWF.debug_printmsg(L, Nt, False, 20)
        self.PWF_channel_1 = PWF.channel(L, Nt, ichn_gain_dB, channel, False,
                                         noise_hat, False, channelfile)
        self.PWF_channel_0 = PWF.channel(L, Nt, ichn_gain_dB, channel, True,
                                         noise, True, channelfile)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.PWF_channel_0, 0),
                     (self.blocks_vector_to_streams_1_1, 0))
        self.connect((self.PWF_channel_0, 1),
                     (self.blocks_vector_to_streams_1_1_0, 0))
        self.connect((self.PWF_channel_1, 1),
                     (self.blocks_vector_to_streams_1_1_0_0, 0))
        self.connect((self.PWF_channel_1, 0),
                     (self.blocks_vector_to_streams_1_1_1, 0))
        self.connect((self.PWF_debug_printmsg_0, 0),
                     (self.PWF_pilot_gen_tx_0, 0))
        self.connect((self.PWF_debug_printmsg_0, 1),
                     (self.PWF_pilot_gen_tx_0_0, 0))
        self.connect((self.PWF_pilot_gen_rx_0, 0),
                     (self.blocks_vector_to_streams_1_0_0, 0))
        self.connect((self.PWF_pilot_gen_rx_0_0, 0),
                     (self.blocks_vector_to_streams_1_2, 0))
        self.connect((self.PWF_pilot_gen_tx_0, 0),
                     (self.blocks_vector_to_streams_1, 0))
        self.connect((self.PWF_pilot_gen_tx_0_0, 0),
                     (self.blocks_vector_to_streams_1_0, 0))
        self.connect((self.PWF_pilot_receive_rx_0, 0),
                     (self.PWF_power_adjust_1, 0))
        self.connect((self.PWF_pilot_receive_rx_0_0, 0),
                     (self.PWF_power_adjust_1, 1))
        self.connect((self.PWF_pilot_receive_tx_0, 0),
                     (self.PWF_power_adjust_1_0, 1))
        self.connect((self.PWF_pilot_receive_tx_0_0, 0),
                     (self.PWF_power_adjust_1_0, 0))
        self.connect((self.PWF_power_adjust_1, 1),
                     (self.PWF_pilot_gen_rx_0, 0))
        self.connect((self.PWF_power_adjust_1, 0),
                     (self.PWF_pilot_gen_rx_0_0, 0))
        self.connect((self.PWF_power_adjust_1_0, 0),
                     (self.blocks_streams_to_vector_0_0, 0))
        self.connect((self.PWF_power_adjust_1_0, 1),
                     (self.blocks_streams_to_vector_0_0, 1))
        self.connect((self.PWF_sigmagen_0, 0),
                     (self.blocks_streams_to_vector_0, 0))
        self.connect((self.PWF_sigmagen_0, 1),
                     (self.blocks_streams_to_vector_0, 1))
        self.connect((self.PWF_weighted_sum_rate_0, 0),
                     (self.blocks_repeat_0, 0))
        self.connect((self.PWF_weighted_sum_rate_0, 1),
                     (self.blocks_repeat_0_0, 0))
        self.connect((self.blocks_repeat_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_repeat_0_0, 0),
                     (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_streams_to_vector_0, 0),
                     (self.blocks_udp_sink_1, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0),
                     (self.blocks_udp_sink_1_0, 0))
        self.connect((self.blocks_streams_to_vector_1, 0),
                     (self.PWF_channel_0, 0))
        self.connect((self.blocks_streams_to_vector_1_0, 0),
                     (self.PWF_channel_0, 1))
        self.connect((self.blocks_streams_to_vector_1_0_0, 0),
                     (self.PWF_channel_1, 1))
        self.connect((self.blocks_streams_to_vector_1_1, 0),
                     (self.PWF_pilot_receive_rx_0, 0))
        self.connect((self.blocks_streams_to_vector_1_1_0, 0),
                     (self.PWF_pilot_receive_rx_0_0, 0))
        self.connect((self.blocks_streams_to_vector_1_1_0_0, 0),
                     (self.PWF_pilot_receive_tx_0, 0))
        self.connect((self.blocks_streams_to_vector_1_1_1, 0),
                     (self.PWF_pilot_receive_tx_0_0, 0))
        self.connect((self.blocks_streams_to_vector_1_2, 0),
                     (self.PWF_channel_1, 0))
        self.connect((self.blocks_udp_source_1, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_udp_source_1, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.PWF_debug_printmsg_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.PWF_debug_printmsg_0, 1))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.PWF_weighted_sum_rate_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.PWF_weighted_sum_rate_0, 1))
        self.connect((self.blocks_vector_to_streams_1, 0),
                     (self.interp_fir_filter_xxx_0, 0))
        self.connect((self.blocks_vector_to_streams_1, 1),
                     (self.interp_fir_filter_xxx_0_1, 0))
        self.connect((self.blocks_vector_to_streams_1_0, 0),
                     (self.interp_fir_filter_xxx_0_0, 0))
        self.connect((self.blocks_vector_to_streams_1_0, 1),
                     (self.interp_fir_filter_xxx_0_1_0, 0))
        self.connect((self.blocks_vector_to_streams_1_0_0, 0),
                     (self.blocks_streams_to_vector_1_0_0, 0))
        self.connect((self.blocks_vector_to_streams_1_0_0, 1),
                     (self.blocks_streams_to_vector_1_0_0, 1))
        self.connect((self.blocks_vector_to_streams_1_1, 0),
                     (self.fir_filter_xxx_0, 0))
        self.connect((self.blocks_vector_to_streams_1_1, 1),
                     (self.fir_filter_xxx_0_0, 0))
        self.connect((self.blocks_vector_to_streams_1_1_0, 1),
                     (self.fir_filter_xxx_0_0_0, 0))
        self.connect((self.blocks_vector_to_streams_1_1_0, 0),
                     (self.fir_filter_xxx_0_1, 0))
        self.connect((self.blocks_vector_to_streams_1_1_0_0, 1),
                     (self.phase_corrector_0_0_0_0, 0))
        self.connect((self.blocks_vector_to_streams_1_1_0_0, 0),
                     (self.phase_corrector_0_1_0, 0))
        self.connect((self.blocks_vector_to_streams_1_1_1, 1),
                     (self.phase_corrector_0_0_1, 0))
        self.connect((self.blocks_vector_to_streams_1_1_1, 0),
                     (self.phase_corrector_0_2, 0))
        self.connect((self.blocks_vector_to_streams_1_2, 1),
                     (self.blocks_streams_to_vector_1_2, 1))
        self.connect((self.blocks_vector_to_streams_1_2, 0),
                     (self.blocks_streams_to_vector_1_2, 0))
        self.connect((self.fir_filter_xxx_0, 0), (self.phase_corrector_0, 0))
        self.connect((self.fir_filter_xxx_0_0, 0),
                     (self.phase_corrector_0_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0),
                     (self.phase_corrector_0_0_0, 0))
        self.connect((self.fir_filter_xxx_0_1, 0),
                     (self.phase_corrector_0_1, 0))
        self.connect((self.interp_fir_filter_xxx_0, 0),
                     (self.blocks_streams_to_vector_1, 0))
        self.connect((self.interp_fir_filter_xxx_0_0, 0),
                     (self.blocks_streams_to_vector_1_0, 0))
        self.connect((self.interp_fir_filter_xxx_0_1, 0),
                     (self.blocks_streams_to_vector_1, 1))
        self.connect((self.interp_fir_filter_xxx_0_1_0, 0),
                     (self.blocks_streams_to_vector_1_0, 1))
        self.connect((self.phase_corrector_0, 0),
                     (self.blocks_streams_to_vector_1_1, 0))
        self.connect((self.phase_corrector_0_0, 0),
                     (self.blocks_streams_to_vector_1_1, 1))
        self.connect((self.phase_corrector_0_0_0, 0),
                     (self.blocks_streams_to_vector_1_1_0, 1))
        self.connect((self.phase_corrector_0_0_0_0, 0),
                     (self.blocks_streams_to_vector_1_1_0_0, 1))
        self.connect((self.phase_corrector_0_0_1, 0),
                     (self.blocks_streams_to_vector_1_1_1, 1))
        self.connect((self.phase_corrector_0_1, 0),
                     (self.blocks_streams_to_vector_1_1_0, 0))
        self.connect((self.phase_corrector_0_1_0, 0),
                     (self.blocks_streams_to_vector_1_1_0_0, 0))
        self.connect((self.phase_corrector_0_2, 0),
                     (self.blocks_streams_to_vector_1_1_1, 0))
Example #26
0
    def __init__(self, filenames, dev_addrs,
                 onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps):
        gr.top_block.__init__(self)

        if mix:
            raise NotImplementedError("TODO: Hilbert remix mode not implemented.")

        uhd_sinks = [
            uhd.usrp_sink(",".join(
                [addr, "send_frame_size=32768,num_send_frames=128"]),
                          uhd.stream_args(
                              cpu_format="fc32",
                              otwformat="sc8",
                              channels=[0]))
            for addr in dev_addrs]

        for sink in uhd_sinks:
            sink.set_clock_rate(fs*2, uhd.ALL_MBOARDS)
            sink.set_samp_rate(fs)
            sink.set_center_freq(fc, 0)
            sink.set_gain(gain, 0)
            # TODO Use offset tuning?
            if sync_pps:
                sink.set_clock_source("external") # 10 MHz
                sink.set_time_source("external") # PPS

        if unint:
            if noise or onebit or not iq:
                raise NotImplementedError("TODO: RX channel-interleaved mode only "
                                          "supported for noiseless 8-bit complex.")
            
            BLOCK_N=16*1024*1024
            demux = blocks.vector_to_streams(2, len(uhd_sinks))
            self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False),
                         blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N),
                         demux)
            for ix, sink in enumerate(uhd_sinks):
                self.connect((demux, ix),
                             blocks.vector_to_stream(1, 2),
                             blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
                             blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125)
#                             blocks.vector_to_stream(8, 16*1024),
                             sink)

        else:
            file_srcs = [blocks.file_source(gr.sizeof_char*1, f, False)
                         for f in filenames]

            for src, sink in zip(file_srcs, uhd_sinks):

                if iq:
                    node = blocks.multiply_const_cc(1.0/1024)
                    if onebit:
                        self.connect(src,
                                     blocks.unpack_k_bits_bb(8), 
                                     blocks.char_to_short(), # [0, 1] -> [0, 256]
                                     blocks.add_const_ss(-128), # [-128, +128],
                                     blocks.interleaved_short_to_complex(), # [ -128.0, +128.0]
                                     node) # [-0.125, +0.125]
                    else:
                        self.connect(src, # [-128..127]
                                     blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
                                     node) # [-0.125, +0.125)
                    
                else:
                    node = blocks.float_to_complex(1)
                    if onebit:
                        self.connect(src,
                                     blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125]
                                     blocks.char_to_float(vlen=1, scale=4),
                                     blocks.add_const_vff((-0.125, )),
                                     node)
                    else:
                        self.connect(src, # [-128..127] -> [-0.125, +0.125)
                                     blocks.char_to_float(vlen=1, scale=1024),
                                     node)
                        
                if noise:
                    combiner = blocks.add_vcc(1)
                    self.connect(node,
                                 combiner,
                                 sink)
                    self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192),
                                 (combiner, 1))
                else:
                    self.connect(node,
                                 sink)

        print "Setting clocks..."
        if sync_pps:
            time.sleep(1.1) # Ensure there's been an edge.  TODO: necessary?
            last_pps_time = uhd_sinks[0].get_time_last_pps()
            while last_pps_time == uhd_sinks[0].get_time_last_pps():
                time.sleep(0.1)
            print "Got edge"
            [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks]
            time.sleep(1.0) # Wait for edge to set the clocks
        else:
            # No external PPS/10 MHz.  Just set each clock and accept some skew.
            t = time.time()
            [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks]
            if len(uhd_sinks) > 1:
                print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % (
                    (time.time()-t) * 1000)

        t_start = uhd.time_spec(time.time() + 1.5)
        [sink.set_start_time(t_start) for sink in uhd_sinks]
        print "ready"
Example #27
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.fftl = fftl = 2048
        self.samp_rate = samp_rate = fftl * 15e3
        self.rxant = rxant = 2
        self.resampler = resampler = 400
        self.frame_key = frame_key = "slot"
        self.N_rb_dl = N_rb_dl = 50

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0_1 = filter.rational_resampler_ccc(
            interpolation=1536 * fftl / 1024,
            decimation=resampler,
            taps=None,
            fractional_bw=None,
        )
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
            interpolation=1536 * fftl / 1024,
            decimation=resampler,
            taps=None,
            fractional_bw=None,
        )
        self.lte_mimo_sss_sync_0 = lte_mimo_sss_sync(
            rxant=rxant,
            N_rb_dl=N_rb_dl,
        )
        self.lte_mimo_pss_sync_0 = lte_mimo_pss_sync(
            fftlen=fftl,
            rxant=rxant,
            synclen=5,
        )
        self.lte_mimo_pss_based_frey_sync_0 = lte_mimo_pss_based_frey_sync(
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_ofdm_rx_0 = lte_mimo_ofdm_rx(
            fftlen=fftl,
            ofdm_key=frame_key,
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.lte_mimo_estimator_0 = lte_mimo_estimator(
            estimator_key=frame_key,
            N_rb_dl=N_rb_dl,
            initial_id=2,
            rxant=rxant,
        )
        self.lte_mimo_decode_pbch_0 = lte_mimo_decode_pbch(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 2,
                                                 samp_rate, True)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 2,
            "/home/maier/LTE test files/live data/lte_capture_Wed_Aug_6_19:36:39_2014_RXant2_4MS_telekom_band1800_wg_karlruhe_hinten raus.dat",
            True)
        self.bch_decode_bch_hier_gr37_0 = decode_bch_hier_gr37()
        self.MIB = lte.mib_unpack_vbm("MIB")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rational_resampler_xxx_0_1, 0),
                     (self.lte_mimo_pss_sync_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0),
                     (self.lte_mimo_pss_sync_0, 1))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.rational_resampler_xxx_0_1, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.lte_mimo_sss_sync_0, 0),
                     (self.lte_mimo_estimator_0, 0))
        self.connect((self.lte_mimo_sss_sync_0, 0),
                     (self.lte_mimo_decode_pbch_0, 0))
        self.connect((self.bch_decode_bch_hier_gr37_0, 1), (self.MIB, 1))
        self.connect((self.bch_decode_bch_hier_gr37_0, 0), (self.MIB, 0))
        self.connect((self.lte_mimo_estimator_0, 1),
                     (self.lte_mimo_decode_pbch_0, 2))
        self.connect((self.lte_mimo_estimator_0, 0),
                     (self.lte_mimo_decode_pbch_0, 1))
        self.connect((self.lte_mimo_decode_pbch_0, 0),
                     (self.bch_decode_bch_hier_gr37_0, 0))
        self.connect((self.lte_mimo_pss_sync_0, 1),
                     (self.lte_mimo_pss_based_frey_sync_0, 1))
        self.connect((self.lte_mimo_pss_sync_0, 0),
                     (self.lte_mimo_pss_based_frey_sync_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 0),
                     (self.lte_mimo_ofdm_rx_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 1),
                     (self.lte_mimo_ofdm_rx_0, 1))
        self.connect((self.lte_mimo_ofdm_rx_0, 0),
                     (self.lte_mimo_sss_sync_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id",
                         self.lte_mimo_estimator_0, "cell_id")
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id",
                         self.lte_mimo_decode_pbch_0, "cell_id")
        self.msg_connect(self.lte_mimo_pss_sync_0, "N_id_2",
                         self.lte_mimo_sss_sync_0, "N_id_2")
Example #28
0
    def __do_connect(self):
        itemsize = self.__itemsize
        
        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
        
        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)
        
        self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length
        
        self.__gate = blocks.copy(itemsize)
        self.__gate.set_enabled(not self.__paused)
        
        overlapper = _OverlappedStreamToVector(
            size=input_length,
            factor=overlap_factor,
            itemsize=itemsize)
        
        self.__frame_dec = blocks.keep_one_in_n(
            itemsize=itemsize * input_length,
            n=int(round(self.__frame_rate_to_decimation_conversion / self.__frame_rate)))
        
        # the actual FFT logic, which is similar to GR's logpwrfft_c
        window = windows.blackmanharris(input_length)
        window_power = sum(x * x for x in window)
        # TODO: use fft_vfc when applicable
        fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
            fft_size=input_length,
            forward=True,
            window=window)
        mag_squared = blocks.complex_to_mag_squared(input_length)
        logarithmizer = blocks.nlog10_ff(
            n=10,  # the "deci" in "decibel"
            vlen=input_length,
            k=(
                -to_dB(window_power) +  # compensate for window
                -to_dB(sample_rate) +  # convert from power-per-sample to power-per-Hz
                self.__power_offset  # offset for packing into bytes
            ))
        
        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(vlen=self.__freq_resolution, scale=1.0)
        
        self.__fft_sink = MessageDistributorSink(
            itemsize=output_length * gr.sizeof_char,
            context=self.__context,
            migrate=self.__fft_sink,
            notify=self.__update_interested)
    
        self.__scope_sink = MessageDistributorSink(
            itemsize=self.__time_length * gr.sizeof_gr_complex,
            context=self.__context,
            migrate=self.__scope_sink,
            notify=self.__update_interested)
        scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)

        # connect everything
        self.__context.lock()
        try:
            self.disconnect_all()
            self.connect(
                self,
                self.__gate,
                overlapper,
                self.__frame_dec,
                fft_block,
                mag_squared,
                logarithmizer)
            if self.__after_fft is not None:
                self.connect(logarithmizer, self.__after_fft)
                self.connect(self.__after_fft, self.__fft_converter, self.__fft_sink)
                self.connect((self.__after_fft, 1), blocks.null_sink(gr.sizeof_float * self.__freq_resolution))
            else:
                self.connect(logarithmizer, self.__fft_converter, self.__fft_sink)
            if self.__enable_scope:
                self.connect(
                    self.__gate,
                    scope_chunker,
                    self.__scope_sink)
        finally:
            self.__context.unlock()
Example #29
0
    def __init__(self):
        gr.top_block.__init__(self, "MIMO TOP FLOW")

        ##################################################
        # Variables
        ##################################################
        self.fftl = fftl = 128
        self.samp_rate = samp_rate = fftl*15e3
        self.rxant = rxant = 2
        self.resampler = resampler = 400
        self.frame_key = frame_key = "slot"
        self.N_rb_dl = N_rb_dl = 50

        ##################################################
        # Blocks
        ##################################################
        self.lte_mimo_sss_sync_0 = lte_mimo_sss_sync(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.lte_mimo_pss_sync_0 = lte_mimo_pss_sync(
            rxant=rxant,
            synclen=5,
            fftlen=fftl,
        )
        self.lte_mimo_pss_based_frey_sync_0 = lte_mimo_pss_based_frey_sync(
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_ofdm_rx_0 = lte_mimo_ofdm_rx(
            N_rb_dl=N_rb_dl,
            ofdm_key=frame_key,
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_estimator_0 = lte_mimo_estimator(
            N_rb_dl=N_rb_dl,
            estimator_key=frame_key,
            initial_id=2,
            rxant=rxant,
        )
        self.lte_mimo_decode_pbch_0 = lte_mimo_decode_pbch(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*2, samp_rate,True)
        self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*12 * N_rb_dl, 2)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*2, "/home/johannes/src/gr-lte/tests/lte_test_data_RX2_NRBDL6.dat", True)
        self.bch_decode_bch_hier_gr37_0 = decode_bch_hier_gr37()
        self.MIB = lte.mib_unpack_vbm("MIB")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.lte_mimo_pss_sync_0, 1), (self.lte_mimo_pss_based_frey_sync_0, 1))
        self.connect((self.lte_mimo_pss_sync_0, 0), (self.lte_mimo_pss_based_frey_sync_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 0), (self.lte_mimo_ofdm_rx_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 1), (self.lte_mimo_ofdm_rx_0, 1))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0), (self.lte_mimo_pss_sync_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1), (self.lte_mimo_pss_sync_0, 1))
        self.connect((self.lte_mimo_ofdm_rx_0, 0), (self.lte_mimo_sss_sync_0, 0))
        self.connect((self.lte_mimo_ofdm_rx_0, 1), (self.lte_mimo_sss_sync_0, 1))
        self.connect((self.lte_mimo_decode_pbch_0, 0), (self.bch_decode_bch_hier_gr37_0, 0))
        self.connect((self.lte_mimo_estimator_0, 0), (self.lte_mimo_decode_pbch_0, 1))
        self.connect((self.lte_mimo_estimator_0, 1), (self.lte_mimo_decode_pbch_0, 2))
        self.connect((self.bch_decode_bch_hier_gr37_0, 1), (self.MIB, 1))
        self.connect((self.bch_decode_bch_hier_gr37_0, 0), (self.MIB, 0))
        self.connect((self.lte_mimo_sss_sync_0, 1), (self.blocks_streams_to_vector_0_0, 1))
        self.connect((self.lte_mimo_sss_sync_0, 0), (self.blocks_streams_to_vector_0_0, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0), (self.lte_mimo_estimator_0, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0), (self.lte_mimo_decode_pbch_0, 0))
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id", self.lte_mimo_estimator_0, "cell_id")
        self.msg_connect(self.lte_mimo_pss_sync_0, "N_id_2", self.lte_mimo_sss_sync_0, "N_id_2")
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id", self.lte_mimo_decode_pbch_0, "cell_id")
    def __init__(self):
        gr.top_block.__init__(self, "Run Music Lin Array Simulation")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Run Music Lin Array Simulation")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "run_MUSIC_lin_array_simulation")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.theta1_deg = theta1_deg = 123
        self.theta0_deg = theta0_deg = 30
        self.input_variables = input_variables = struct({'SampleRate': 320000, 'ToneFreq1': 10000, 'ToneFreq2': 20000, 'NormSpacing': 0.4, 'NumTargets': 2, 'NumArrayElements': 4, 'PSpectrumLength': 2**10, 'SnapshotSize': 2**11, 'OverlapSize': 2**9, })
        self.theta1 = theta1 = numpy.pi*theta1_deg/180
        self.theta0 = theta0 = numpy.pi*theta0_deg/180
        self.ant_locs = ant_locs = numpy.dot(input_variables.NormSpacing, numpy.arange(input_variables.NumArrayElements/2, -input_variables.NumArrayElements/2, -1) if (input_variables.NumArrayElements%2==1) else numpy.arange(input_variables.NumArrayElements/2-0.5, -input_variables.NumArrayElements/2-0.5, -1))
        self.amv1 = amv1 = numpy.exp(-1j*ant_locs*2*numpy.pi*numpy.cos(theta1))
        self.amv0 = amv0 = numpy.exp(-1j*ant_locs*2*numpy.pi*numpy.cos(theta0))
        self.array_manifold_matrix = array_manifold_matrix = numpy.array([amv0, amv1]).transpose()

        ##################################################
        # Blocks
        ##################################################
        self.tab = Qt.QTabWidget()
        self.tab_widget_0 = Qt.QWidget()
        self.tab_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_0)
        self.tab_grid_layout_0 = Qt.QGridLayout()
        self.tab_layout_0.addLayout(self.tab_grid_layout_0)
        self.tab.addTab(self.tab_widget_0, 'Pseudo-Spectrum')
        self.tab_widget_1 = Qt.QWidget()
        self.tab_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_1)
        self.tab_grid_layout_1 = Qt.QGridLayout()
        self.tab_layout_1.addLayout(self.tab_grid_layout_1)
        self.tab.addTab(self.tab_widget_1, 'Direction of Arrival')
        self.tab_widget_2 = Qt.QWidget()
        self.tab_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab_widget_2)
        self.tab_grid_layout_2 = Qt.QGridLayout()
        self.tab_layout_2.addLayout(self.tab_grid_layout_2)
        self.tab.addTab(self.tab_widget_2, 'Direction of Arrival')
        self.top_layout.addWidget(self.tab)
        self._theta1_deg_range = Range(0, 180, 1, 123, 200)
        self._theta1_deg_win = RangeWidget(self._theta1_deg_range, self.set_theta1_deg, 'AoA', "counter_slider", float)
        self.top_layout.addWidget(self._theta1_deg_win)
        self._theta0_deg_range = Range(0, 180, 1, 30, 200)
        self._theta0_deg_win = RangeWidget(self._theta0_deg_range, self.set_theta0_deg, 'AoA', "counter_slider", float)
        self.top_layout.addWidget(self._theta0_deg_win)
        self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f(
            input_variables.PSpectrumLength,
            0,
            180.0/input_variables.PSpectrumLength,
            "angle (in degrees)",
            "Pseudo-Spectrum (dB)",
            "",
            1 # Number of inputs
        )
        self.qtgui_vector_sink_f_0.set_update_time(0.05)
        self.qtgui_vector_sink_f_0.set_y_axis(-50, 0)
        self.qtgui_vector_sink_f_0.enable_autoscale(False)
        self.qtgui_vector_sink_f_0.enable_grid(True)
        self.qtgui_vector_sink_f_0.set_x_axis_units("")
        self.qtgui_vector_sink_f_0.set_y_axis_units("")
        self.qtgui_vector_sink_f_0.set_ref_level(0)
        
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [2, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_vector_sink_f_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_vector_sink_f_0.set_line_label(i, labels[i])
            self.qtgui_vector_sink_f_0.set_line_width(i, widths[i])
            self.qtgui_vector_sink_f_0.set_line_color(i, colors[i])
            self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_vector_sink_f_0_win = sip.wrapinstance(self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget)
        self.tab_layout_0.addWidget(self._qtgui_vector_sink_f_0_win)
        self.doa_find_local_max_0 = doa.find_local_max(input_variables.NumTargets, input_variables.PSpectrumLength, 0.0, 180.0)
        self.doa_compass_0 = doa.compass("", 0, 180, 10, 0)
        self.tab_layout_1.addLayout(self.doa_compass_0.this_layout)
        self.doa_compass = doa.compass("", 0, 180, 10, 0)
        self.tab_layout_2.addLayout(self.doa_compass.this_layout)
        self.doa_autocorrelate_0 = doa.autocorrelate(input_variables.NumArrayElements, input_variables.SnapshotSize, input_variables.OverlapSize, 1)
        self.doa_MUSIC_lin_array_0 = doa.MUSIC_lin_array(input_variables.NormSpacing, input_variables.NumTargets, input_variables.NumArrayElements, input_variables.PSpectrumLength)
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(gr.sizeof_float*1, input_variables.NumTargets)
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, input_variables.SampleRate,True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*input_variables.NumTargets)
        self.blocks_multiply_matrix_xx_0 = blocks.multiply_matrix_cc(array_manifold_matrix, gr.TPP_ALL_TO_ALL)
        self.blocks_add_xx_0_0 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(input_variables.SampleRate, analog.GR_COS_WAVE, input_variables.ToneFreq2, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(input_variables.SampleRate, analog.GR_COS_WAVE, input_variables.ToneFreq1, 1, 0)
        self.analog_noise_source_x_0_0_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0.5, 0)
        self.analog_noise_source_x_0_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0.0005, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.analog_noise_source_x_0_0_0, 0), (self.blocks_add_xx_0_0, 1))    
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_add_xx_0_0, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_matrix_xx_0, 0))    
        self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_throttle_0_0, 0))    
        self.connect((self.blocks_multiply_matrix_xx_0, 0), (self.doa_autocorrelate_0, 0))    
        self.connect((self.blocks_multiply_matrix_xx_0, 1), (self.doa_autocorrelate_0, 1))    
        self.connect((self.blocks_multiply_matrix_xx_0, 2), (self.doa_autocorrelate_0, 2))    
        self.connect((self.blocks_multiply_matrix_xx_0, 3), (self.doa_autocorrelate_0, 3))    
        self.connect((self.blocks_throttle_0_0, 0), (self.blocks_multiply_matrix_xx_0, 1))    
        self.connect((self.blocks_vector_to_streams_0, 0), (self.doa_compass, 0))    
        self.connect((self.blocks_vector_to_streams_0, 1), (self.doa_compass_0, 0))    
        self.connect((self.doa_MUSIC_lin_array_0, 0), (self.doa_find_local_max_0, 0))    
        self.connect((self.doa_MUSIC_lin_array_0, 0), (self.qtgui_vector_sink_f_0, 0))    
        self.connect((self.doa_autocorrelate_0, 0), (self.doa_MUSIC_lin_array_0, 0))    
        self.connect((self.doa_find_local_max_0, 0), (self.blocks_null_sink_0, 0))    
        self.connect((self.doa_find_local_max_0, 1), (self.blocks_vector_to_streams_0, 0))    
Example #31
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.Nt = Nt = 2
        self.dft_coef = dft_coef = np.exp(-2*np.pi*1j/Nt)
        self.A = A = np.arange(Nt)[np.newaxis]
        self.tlen = tlen = 4000
        self.samp_rate = samp_rate = 100000
        self.dft_matrix = dft_matrix = np.power(dft_coef, np.dot(A.transpose(),A))
        self.scramble_2 = scramble_2 = 2*np.random.random_integers(0,1,size=(tlen,Nt))-1
        self.scramble_1 = scramble_1 = 2*np.random.random_integers(0,1,size=(tlen,Nt))-1
        self.prefix = prefix = '/home/zhe/gr-PWF/examples'
        self.noise = noise = [np.identity(Nt), np.identity(Nt)]
        self.max_iteration = max_iteration = 20
        self.interpo = interpo = samp_rate/1000
        self.dft_pilot_seq = dft_pilot_seq = np.tile(dft_matrix,(tlen/Nt,1))
        self.Q = Q = 4
        self.L = L = 2
        self.sigmagenfile = sigmagenfile = prefix+'/sigmagens/sigmagen_10.bin'
        self.pulse = pulse = filter.firdes.root_raised_cosine(Q,Q,1,0.35,11*Q)
        self.prewhiten1 = prewhiten1 = np.linalg.pinv(noise[1])
        self.prewhiten0 = prewhiten0 = np.linalg.pinv(noise[0])
        self.pilot_seq_2 = pilot_seq_2 = np.multiply(dft_pilot_seq,scramble_2)
        self.pilot_seq_1 = pilot_seq_1 = np.multiply(dft_pilot_seq,scramble_1)
        self.pilot2file = pilot2file = prefix+'/pilots/pilot2_4000.bin'
        self.pilot1file = pilot1file = prefix+'/pilots/pilot1_4000.bin'
        self.payload_size = payload_size = 0
        self.npoints = npoints = max_iteration*interpo
        self.noise_hat = noise_hat = [np.identity(Nt), np.identity(Nt)]
        self.ichn_gain_dB = ichn_gain_dB = 10
        self.channelfile = channelfile = prefix+'/channels/2x2channel_10dB_3.bin'
        self.channel = channel = np.true_divide(np.random.standard_normal(size=(L,L,Nt,Nt))+np.random.standard_normal(size=(L,L,Nt,Nt))*1j,np.sqrt(2))
        self.Pt = Pt = 100

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	npoints, #size
        	samp_rate, #samp_rate
        	"Strong Interference (ichn_gain = 10dB)", #name
        	2 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.1)
        self.qtgui_time_sink_x_0.set_y_axis(0, 20)
        
        self.qtgui_time_sink_x_0.set_y_label("Weighted Sum-Rate (bits/s/Hz)", "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_AUTO, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0.enable_grid(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["Dual Link", "Identity Sigma", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.phase_corrector_0_2 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_1[:,0],
        )
        self.phase_corrector_0_1_0 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_2[:,0],
        )
        self.phase_corrector_0_1 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_2[:,0],
        )
        self.phase_corrector_0_0_1 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_1[:,1],
        )
        self.phase_corrector_0_0_0_0 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_2[:,1],
        )
        self.phase_corrector_0_0_0 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_2[:,1],
        )
        self.phase_corrector_0_0 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_1[:,1],
        )
        self.phase_corrector_0 = phase_corrector(
            loop_bandwidth=2*np.pi*0.005,
            max_freq=2*np.pi*0.01,
            training_sequence=pilot_seq_1[:,0],
        )
        self.interp_fir_filter_xxx_0_1_0 = filter.interp_fir_filter_ccc(Q, (pulse))
        self.interp_fir_filter_xxx_0_1_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0_1 = filter.interp_fir_filter_ccc(Q, (pulse))
        self.interp_fir_filter_xxx_0_1.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(Q, (pulse))
        self.interp_fir_filter_xxx_0_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(Q, (pulse))
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_1 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_1.declare_sample_delay(0)
        self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0 = filter.fir_filter_ccc(Q, (pulse))
        self.fir_filter_xxx_0.declare_sample_delay(0)
        self.blocks_vector_to_streams_1_2 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_1_1 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_1_0_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_1_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_1 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_0_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_1 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*4, 2)
        self.blocks_udp_source_1 = blocks.udp_source(gr.sizeof_gr_complex*8, "127.0.0.1", 1234, 1472, True)
        self.blocks_udp_sink_1_0 = blocks.udp_sink(gr.sizeof_gr_complex*8, "127.0.0.1", 1234, 1472, True)
        self.blocks_udp_sink_1 = blocks.udp_sink(gr.sizeof_gr_complex*8, "127.0.0.1", 1234, 1472, True)
        self.blocks_streams_to_vector_1_2 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_1_1 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_1_0_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_1_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_1 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_0_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_1 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, 2)
        self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*4, 2)
        self.blocks_streams_to_vector_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*4, 2)
        self.blocks_repeat_0_0 = blocks.repeat(gr.sizeof_float*1, interpo)
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, interpo)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*8, "/home/zhe/Dropbox/gnuradio_trunk/gnufiles/udp", False)
        self.blocks_file_sink_0.set_unbuffered(True)
        self.PWF_weighted_sum_rate_0 = PWF.weighted_sum_rate(L, Nt, Pt, channel, ichn_gain_dB, [1,1],[prewhiten0 ,prewhiten1], False, channelfile)
        self.PWF_sigmagen_0 = PWF.sigmagen(L, Nt, Pt, True, sigmagenfile)
        self.PWF_power_adjust_1_0 = PWF.power_adjust(Nt, Pt, L)
        self.PWF_power_adjust_1 = PWF.power_adjust(Nt, Pt, L)
        self.PWF_pilot_receive_tx_0_0 = PWF.pilot_receive_tx(True, pilot1file, pilot_seq_1, Nt, tlen,noise_hat[0], tlen, 1)
        self.PWF_pilot_receive_tx_0 = PWF.pilot_receive_tx(True, pilot2file, pilot_seq_2, Nt, tlen,noise_hat[1], tlen, 1)
        self.PWF_pilot_receive_rx_0_0 = PWF.pilot_receive_rx(True, pilot2file, pilot_seq_2, prewhiten1, Nt, tlen, tlen+payload_size, 1)
        self.PWF_pilot_receive_rx_0 = PWF.pilot_receive_rx(True, pilot1file, pilot_seq_1, prewhiten0, Nt, tlen, tlen+payload_size, 1)
        self.PWF_pilot_gen_tx_0_0 = PWF.pilot_gen_tx(Nt, tlen, pilot_seq_2, True, pilot2file)
        self.PWF_pilot_gen_tx_0 = PWF.pilot_gen_tx(Nt, tlen, pilot_seq_1, True, pilot1file)
        self.PWF_pilot_gen_rx_0_0 = PWF.pilot_gen_rx(Nt, tlen, prewhiten0, pilot_seq_1, True, pilot1file)
        self.PWF_pilot_gen_rx_0 = PWF.pilot_gen_rx(Nt, tlen, prewhiten1, pilot_seq_2, True, pilot2file)
        self.PWF_debug_printmsg_0 = PWF.debug_printmsg(L, Nt, False, 20)
        self.PWF_channel_1 = PWF.channel(L, Nt, ichn_gain_dB, channel, False,noise_hat, False, channelfile)
        self.PWF_channel_0 = PWF.channel(L, Nt, ichn_gain_dB, channel, True,noise, True, channelfile)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.PWF_channel_0, 0), (self.blocks_vector_to_streams_1_1, 0))    
        self.connect((self.PWF_channel_0, 1), (self.blocks_vector_to_streams_1_1_0, 0))    
        self.connect((self.PWF_channel_1, 1), (self.blocks_vector_to_streams_1_1_0_0, 0))    
        self.connect((self.PWF_channel_1, 0), (self.blocks_vector_to_streams_1_1_1, 0))    
        self.connect((self.PWF_debug_printmsg_0, 0), (self.PWF_pilot_gen_tx_0, 0))    
        self.connect((self.PWF_debug_printmsg_0, 1), (self.PWF_pilot_gen_tx_0_0, 0))    
        self.connect((self.PWF_pilot_gen_rx_0, 0), (self.blocks_vector_to_streams_1_0_0, 0))    
        self.connect((self.PWF_pilot_gen_rx_0_0, 0), (self.blocks_vector_to_streams_1_2, 0))    
        self.connect((self.PWF_pilot_gen_tx_0, 0), (self.blocks_vector_to_streams_1, 0))    
        self.connect((self.PWF_pilot_gen_tx_0_0, 0), (self.blocks_vector_to_streams_1_0, 0))    
        self.connect((self.PWF_pilot_receive_rx_0, 0), (self.PWF_power_adjust_1, 0))    
        self.connect((self.PWF_pilot_receive_rx_0_0, 0), (self.PWF_power_adjust_1, 1))    
        self.connect((self.PWF_pilot_receive_tx_0, 0), (self.PWF_power_adjust_1_0, 1))    
        self.connect((self.PWF_pilot_receive_tx_0_0, 0), (self.PWF_power_adjust_1_0, 0))    
        self.connect((self.PWF_power_adjust_1, 1), (self.PWF_pilot_gen_rx_0, 0))    
        self.connect((self.PWF_power_adjust_1, 0), (self.PWF_pilot_gen_rx_0_0, 0))    
        self.connect((self.PWF_power_adjust_1_0, 0), (self.blocks_streams_to_vector_0_0, 0))    
        self.connect((self.PWF_power_adjust_1_0, 1), (self.blocks_streams_to_vector_0_0, 1))    
        self.connect((self.PWF_sigmagen_0, 0), (self.blocks_streams_to_vector_0, 0))    
        self.connect((self.PWF_sigmagen_0, 1), (self.blocks_streams_to_vector_0, 1))    
        self.connect((self.PWF_weighted_sum_rate_0, 0), (self.blocks_repeat_0, 0))    
        self.connect((self.PWF_weighted_sum_rate_0, 1), (self.blocks_repeat_0_0, 0))    
        self.connect((self.blocks_repeat_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.blocks_repeat_0_0, 0), (self.qtgui_time_sink_x_0, 1))    
        self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_udp_sink_1, 0))    
        self.connect((self.blocks_streams_to_vector_0_0, 0), (self.blocks_udp_sink_1_0, 0))    
        self.connect((self.blocks_streams_to_vector_1, 0), (self.PWF_channel_0, 0))    
        self.connect((self.blocks_streams_to_vector_1_0, 0), (self.PWF_channel_0, 1))    
        self.connect((self.blocks_streams_to_vector_1_0_0, 0), (self.PWF_channel_1, 1))    
        self.connect((self.blocks_streams_to_vector_1_1, 0), (self.PWF_pilot_receive_rx_0, 0))    
        self.connect((self.blocks_streams_to_vector_1_1_0, 0), (self.PWF_pilot_receive_rx_0_0, 0))    
        self.connect((self.blocks_streams_to_vector_1_1_0_0, 0), (self.PWF_pilot_receive_tx_0, 0))    
        self.connect((self.blocks_streams_to_vector_1_1_1, 0), (self.PWF_pilot_receive_tx_0_0, 0))    
        self.connect((self.blocks_streams_to_vector_1_2, 0), (self.PWF_channel_1, 0))    
        self.connect((self.blocks_udp_source_1, 0), (self.blocks_file_sink_0, 0))    
        self.connect((self.blocks_udp_source_1, 0), (self.blocks_vector_to_streams_0, 0))    
        self.connect((self.blocks_vector_to_streams_0, 0), (self.PWF_debug_printmsg_0, 0))    
        self.connect((self.blocks_vector_to_streams_0, 1), (self.PWF_debug_printmsg_0, 1))    
        self.connect((self.blocks_vector_to_streams_0, 0), (self.PWF_weighted_sum_rate_0, 0))    
        self.connect((self.blocks_vector_to_streams_0, 1), (self.PWF_weighted_sum_rate_0, 1))    
        self.connect((self.blocks_vector_to_streams_1, 0), (self.interp_fir_filter_xxx_0, 0))    
        self.connect((self.blocks_vector_to_streams_1, 1), (self.interp_fir_filter_xxx_0_1, 0))    
        self.connect((self.blocks_vector_to_streams_1_0, 0), (self.interp_fir_filter_xxx_0_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_0, 1), (self.interp_fir_filter_xxx_0_1_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_0_0, 0), (self.blocks_streams_to_vector_1_0_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_0_0, 1), (self.blocks_streams_to_vector_1_0_0, 1))    
        self.connect((self.blocks_vector_to_streams_1_1, 0), (self.fir_filter_xxx_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_1, 1), (self.fir_filter_xxx_0_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_0, 1), (self.fir_filter_xxx_0_0_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_0, 0), (self.fir_filter_xxx_0_1, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_0_0, 1), (self.phase_corrector_0_0_0_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_0_0, 0), (self.phase_corrector_0_1_0, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_1, 1), (self.phase_corrector_0_0_1, 0))    
        self.connect((self.blocks_vector_to_streams_1_1_1, 0), (self.phase_corrector_0_2, 0))    
        self.connect((self.blocks_vector_to_streams_1_2, 1), (self.blocks_streams_to_vector_1_2, 1))    
        self.connect((self.blocks_vector_to_streams_1_2, 0), (self.blocks_streams_to_vector_1_2, 0))    
        self.connect((self.fir_filter_xxx_0, 0), (self.phase_corrector_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.phase_corrector_0_0, 0))    
        self.connect((self.fir_filter_xxx_0_0_0, 0), (self.phase_corrector_0_0_0, 0))    
        self.connect((self.fir_filter_xxx_0_1, 0), (self.phase_corrector_0_1, 0))    
        self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_streams_to_vector_1, 0))    
        self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.blocks_streams_to_vector_1_0, 0))    
        self.connect((self.interp_fir_filter_xxx_0_1, 0), (self.blocks_streams_to_vector_1, 1))    
        self.connect((self.interp_fir_filter_xxx_0_1_0, 0), (self.blocks_streams_to_vector_1_0, 1))    
        self.connect((self.phase_corrector_0, 0), (self.blocks_streams_to_vector_1_1, 0))    
        self.connect((self.phase_corrector_0_0, 0), (self.blocks_streams_to_vector_1_1, 1))    
        self.connect((self.phase_corrector_0_0_0, 0), (self.blocks_streams_to_vector_1_1_0, 1))    
        self.connect((self.phase_corrector_0_0_0_0, 0), (self.blocks_streams_to_vector_1_1_0_0, 1))    
        self.connect((self.phase_corrector_0_0_1, 0), (self.blocks_streams_to_vector_1_1_1, 1))    
        self.connect((self.phase_corrector_0_1, 0), (self.blocks_streams_to_vector_1_1_0, 0))    
        self.connect((self.phase_corrector_0_1_0, 0), (self.blocks_streams_to_vector_1_1_0_0, 0))    
        self.connect((self.phase_corrector_0_2, 0), (self.blocks_streams_to_vector_1_1_1, 0))    
Example #32
0
    def __init__(self,
                 center_freq,
                 samp_rate,
                 gain,
                 fsk_deviation_hz,
                 baseband_file_name,
                 baseband_samp_rate,
                 freq_hop_list,
                 verbose=False,
                 hardware_transmit_enable=True,
                 hw_sel=0,
                 hw_gain=0,
                 iq_file_out=False):
        gr.top_block.__init__(self)

        # display the parameters used for transmit
        if True:  #verbose:
            print "Baseband File Name: {}".format(baseband_file_name)
            print "Baseband Sample Rate: {}".format(baseband_samp_rate)
            print "SDR Center Freq: {}".format(center_freq)
            print "SDR Sample Rate: {}".format(samp_rate)
            print "Flowgraph Gain: {}".format(gain)
            print "GFSK deviation: {}".format(fsk_deviation_hz)
            print "Freq 0-2: {}".format(freq_hop_list)
            print "Verbose: {}".format(verbose)
            print "Hardware TX Enable: {}".format(hardware_transmit_enable)
            print "IQ to File: {}".format(iq_file_out)

        ##################################################
        # Variables
        ##################################################
        self.center_freq = center_freq
        self.samp_rate = samp_rate
        self.gain = gain
        self.fsk_deviation_hz = fsk_deviation_hz
        self.baseband_file_name = baseband_file_name
        self.baseband_samp_rate = baseband_samp_rate
        self.freq_hop_list = freq_hop_list
        self.hw_sel = hw_sel
        self.hw_gain = hw_gain
        """
        r = gr.enable_realtime_scheduling()
        if r == gr.RT_OK:
            print "Note: Realtime scheduling enabled"
        """
        # self.cutoff_freq = channel_width/2
        ##################################################
        # Blocks
        ##################################################
        # replace this with a message source
        #self.blocks_file_source_0 = blocks.file_source(
        #    gr.sizeof_char * 1,
        #    baseband_file_name,
        #    repeat)
        # message sink is primary method of getting baseband data into
        # the flowgraph
        #self.source_queue = gr.msg_queue()
        #self.blocks_message_source_0 = blocks.message_source(
        #    gr.sizeof_char*1,
        #    self.source_queue)
        #self.blocks_message_source_0.set_max_output_buffer(1)

        # TESTING FLOWGRAPH ONLY (DELETE WHEN DONE)
        #blocks_message_sink_0_msgq_out = blocks_message_source_0_msgq_in = gr.msg_queue(2)
        #self.blocks_vector_source_x_0 = blocks.vector_source_b((1, 0, 0, 1), True, 4, [])
        #self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char * 4, blocks_message_sink_0_msgq_out, False)
        #self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_message_sink_0, 0))

        self.source_queue_v = gr.msg_queue()
        #self.source_queue_v = gr.msg_queue(2048) # smaller values cause hang
        self.blocks_message_source_0 = blocks.message_source(
            gr.sizeof_char * 4, self.source_queue_v)
        self.blocks_vector_to_streams = blocks.vector_to_streams(
            gr.sizeof_char * 1, 4)
        self.connect((self.blocks_message_source_0, 0),
                     (self.blocks_vector_to_streams, 0))

        # blocks and connections for carrier for first hop frequency
        self.analog_sig_source_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq_hop_list[0] - center_freq, 1,
            0)
        self.repeat_0 = blocks.repeat(gr.sizeof_char * 1,
                                      int(samp_rate / baseband_samp_rate))
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_multiply_0 = blocks.multiply_vcc(1)
        self.connect((self.blocks_vector_to_streams, 1), (self.repeat_0, 0))
        self.connect((self.repeat_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_0, 1))
        self.connect((self.analog_sig_source_0, 0),
                     (self.blocks_multiply_0, 0))

        # blocks and connections for carrier for second hop frequency
        self.analog_sig_source_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq_hop_list[1] - center_freq, 1,
            0)
        self.repeat_1 = blocks.repeat(gr.sizeof_char * 1,
                                      int(samp_rate / baseband_samp_rate))
        self.blocks_uchar_to_float_1 = blocks.uchar_to_float()
        self.blocks_float_to_complex_1 = blocks.float_to_complex(1)
        self.blocks_multiply_1 = blocks.multiply_vcc(1)
        self.connect((self.blocks_vector_to_streams, 2), (self.repeat_1, 0))
        self.connect((self.repeat_1, 0), (self.blocks_uchar_to_float_1, 0))
        self.connect((self.blocks_uchar_to_float_1, 0),
                     (self.blocks_float_to_complex_1, 0))
        self.connect((self.blocks_uchar_to_float_1, 0),
                     (self.blocks_float_to_complex_1, 1))
        self.connect((self.blocks_float_to_complex_1, 0),
                     (self.blocks_multiply_1, 1))
        self.connect((self.analog_sig_source_1, 0),
                     (self.blocks_multiply_1, 0))

        # blocks and connections for carrier for third hop frequency
        self.analog_sig_source_2 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq_hop_list[2] - center_freq, 1,
            0)
        self.repeat_2 = blocks.repeat(gr.sizeof_char * 1,
                                      int(samp_rate / baseband_samp_rate))
        self.blocks_uchar_to_float_2 = blocks.uchar_to_float()
        self.blocks_float_to_complex_2 = blocks.float_to_complex(1)
        self.blocks_multiply_2 = blocks.multiply_vcc(1)
        self.connect((self.blocks_vector_to_streams, 3), (self.repeat_2, 0))
        self.connect((self.repeat_2, 0), (self.blocks_uchar_to_float_2, 0))
        self.connect((self.blocks_uchar_to_float_2, 0),
                     (self.blocks_float_to_complex_2, 0))
        self.connect((self.blocks_uchar_to_float_2, 0),
                     (self.blocks_float_to_complex_2, 1))
        self.connect((self.blocks_float_to_complex_2, 0),
                     (self.blocks_multiply_2, 1))
        self.connect((self.analog_sig_source_2, 0),
                     (self.blocks_multiply_2, 0))

        # now add the three gated carrier together; the selected
        # one will pass through
        self.blocks_add = blocks.add_vcc(1)
        self.connect((self.blocks_multiply_0, 0), (self.blocks_add, 0))
        self.connect((self.blocks_multiply_1, 0), (self.blocks_add, 1))
        self.connect((self.blocks_multiply_2, 0), (self.blocks_add, 2))

        # all of the baseband data goes to the modulation chain
        self.blocks_unpacked_to_packed = blocks.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)
        self.digital_gfsk_mod = digital.gfsk_mod(
            samples_per_symbol=int(samp_rate / baseband_samp_rate),
            sensitivity=(2 * math.pi * (fsk_deviation_hz / 2)) / samp_rate,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.connect((self.blocks_vector_to_streams, 0),
                     (self.blocks_unpacked_to_packed, 0))
        self.connect((self.blocks_unpacked_to_packed, 0),
                     (self.digital_gfsk_mod, 0))

        # use the passed-through carrier to tune/modulate the gfsk output
        self.blocks_multiply_tune = blocks.multiply_vcc(1)
        self.connect((self.digital_gfsk_mod, 0),
                     (self.blocks_multiply_tune, 0))
        self.connect((self.blocks_add, 0), (self.blocks_multiply_tune, 1))

        # setup osmocom block for HackRF control
        # NEED: add control switch for USRP models
        if hardware_transmit_enable:
            if self.hw_sel == 0:
                self.osmosdr_sink = osmosdr.sink(args="numchan=" + str(1) +
                                                 " " + "")
                self.osmosdr_sink.set_sample_rate(samp_rate)
                self.osmosdr_sink.set_center_freq(center_freq, 0)
                self.osmosdr_sink.set_freq_corr(0, 0)
                self.osmosdr_sink.set_gain(hw_gain, 0)
                self.osmosdr_sink.set_if_gain(20, 0)
                self.osmosdr_sink.set_bb_gain(20, 0)
                self.osmosdr_sink.set_antenna("", 0)
                self.osmosdr_sink.set_bandwidth(0, 0)
                self.connect((self.blocks_multiply_tune, 0),
                             (self.osmosdr_sink, 0))
            elif self.hw_sel == 1:
                self.uhd_usrp_sink_0 = uhd.usrp_sink(
                    ",".join(("", "")),
                    uhd.stream_args(
                        cpu_format="fc32",
                        channels=range(1),
                    ),
                )
                self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
                self.uhd_usrp_sink_0.set_center_freq(center_freq, 0)
                self.uhd_usrp_sink_0.set_gain(hw_gain, 0)
                self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
                self.connect((self.blocks_multiply_tune, 0),
                             (self.uhd_usrp_sink_0, 0))

        # this file sink provides an IQ capture of the RF
        # being transmitted by this app; the resulting file
        # is used for debugging only and should be disabled
        # under normal use
        if iq_file_out:
            self.blocks_file_sink_iq = blocks.file_sink(
                gr.sizeof_gr_complex * 1, "takeover_output_c435M_s8M.iq",
                False)
            self.blocks_file_sink_iq.set_unbuffered(False)

            self.connect((self.blocks_multiply_tune, 0),
                         (self.blocks_file_sink_iq, 0))

        # attempts to decrease latency
        #self.blocks_message_source_0.set_max_noutput_items(128)
        #self.blocks_multiply_tune.set_max_noutput_items(512)
        buffer_size = 1
        self.blocks_message_source_0.set_max_output_buffer(buffer_size)
        self.blocks_vector_to_streams.set_max_output_buffer(buffer_size)
Example #33
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.fsk_deviation_hz = fsk_deviation_hz = 15e3
        self.channel_width = channel_width = fsk_deviation_hz * 1.3
        self.t_width = t_width = channel_width / 10
        self.samp_rate = samp_rate = 8e6
        self.freq2 = freq2 = 433.777e6
        self.freq1 = freq1 = 434.138e6
        self.freq0 = freq0 = 433.178e6
        self.channel_filter_taps = channel_filter_taps = firdes.low_pass(
            1, samp_rate, channel_width, t_width)
        self.center_freq = center_freq = 435e6
        self.baseband_samp_rate = baseband_samp_rate = 16e3

        ##################################################
        # Message Queues
        ##################################################
        #blocks_message_sink_0_msgq_out = blocks_message_source_0_msgq_in = gr.msg_queue(2)
        self.blocks_message_source_0_msgq_in = gr.msg_queue()
        ##################################################
        # Blocks
        ##################################################

        self.digital_gfsk_mod_0 = digital.gfsk_mod(
            samples_per_symbol=int(samp_rate / baseband_samp_rate),
            sensitivity=(2 * math.pi * (fsk_deviation_hz / 2)) / samp_rate,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_char * 1, 4)
        self.blocks_vector_source_x_0 = blocks.vector_source_b((1, 0, 0, 1),
                                                               True, 4, [])
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)
        self.blocks_uchar_to_float_1_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_1_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_1 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1)
        self.blocks_multiply_xx_0_0_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_message_source_0 = blocks.message_source(
            gr.sizeof_char * 4, self.blocks_message_source_0_msgq_in)
        #self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char * 4, blocks_message_sink_0_msgq_out, False)
        self.blocks_float_to_complex_0_1 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1,
                                                   "test.iq", False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0_0_0_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq2 - center_freq, 1, 0)
        self.analog_sig_source_x_0_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq1 - center_freq, 1, 0)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freq0 - center_freq, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.analog_sig_source_x_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 0))
        self.connect((self.analog_sig_source_x_0_0_0_1, 0),
                     (self.blocks_multiply_xx_0_0_0_1, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.blocks_float_to_complex_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 1))
        self.connect((self.blocks_float_to_complex_0_1, 0),
                     (self.blocks_multiply_xx_0_0_0_1, 1))
        self.connect((self.blocks_message_source_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0_0_0_1, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.blocks_uchar_to_float_1, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_uchar_to_float_1, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_uchar_to_float_1_0, 0),
                     (self.blocks_float_to_complex_0_0, 0))
        self.connect((self.blocks_uchar_to_float_1_0, 0),
                     (self.blocks_float_to_complex_0_0, 1))
        self.connect((self.blocks_uchar_to_float_1_0_0, 0),
                     (self.blocks_float_to_complex_0_1, 0))
        self.connect((self.blocks_uchar_to_float_1_0_0, 0),
                     (self.blocks_float_to_complex_0_1, 1))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0),
                     (self.digital_gfsk_mod_0, 0))
        #self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_message_sink_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.blocks_uchar_to_float_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 2),
                     (self.blocks_uchar_to_float_1_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 3),
                     (self.blocks_uchar_to_float_1_0_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.digital_gfsk_mod_0, 0),
                     (self.blocks_multiply_xx_0, 1))
Example #34
0
    def __init__(
            self,
            scrambler,
            fieldSize = 4,
            codewordLength = 12,
            augmentingLength = 3,
            continuous = True,
            autocovarianceLength = 32,
            distributionWidth = 32,
            symbols = long(1e7),
            windowSize = 16384,
            selectionMethod = 'MSW'):
        gr.top_block.__init__(self, "Guided Scrambling Statistical Simulation")

        ##################################################
        # Variables
        ##################################################
        scramblingPolynomial = scrambler
        self.constellation = constellation = gs.defaultConstellation_f(fieldSize)
        self.windowSize = windowSize

        ##################################################
        # Blocks
        ##################################################
        self.symbolGenerator = gs.SymbolGenerator_b(([1] * fieldSize), '')
        self.guidedScrambler = gs.GuidedScrambler_bb(
                fieldSize,
                codewordLength,
                augmentingLength,
                continuous,
                (scrambler))
        self.terminator = gs.Terminator(1*gr.sizeof_char, symbols)
        self.symbolMapper = gs.SymbolMapper_bc((constellation))
        self.integrate = gs.Integrate_cc(1)
        self.streamToVector = blocks.stream_to_vector(
                gr.sizeof_gr_complex*1,
                codewordLength)
        self.vectorToStreams = blocks.vector_to_streams(
                gr.sizeof_gr_complex*1,
                codewordLength)

        self.autocovariances = []
        self.XXaverages = []
        self.XYaverages = []
        self.YXaverages = []
        self.YYaverages = []

        self.distributions = []

        for i in range(codewordLength):
            self.autocovariances.append(gs.Autocovariance_cf(
                autocovarianceLength,
                0,
                codewordLength,
                i))
            self.XXaverages.append(gs.Average_ff(autocovarianceLength))
            self.XYaverages.append(gs.Average_ff(autocovarianceLength))
            self.YXaverages.append(gs.Average_ff(autocovarianceLength))
            self.YYaverages.append(gs.Average_ff(autocovarianceLength))

            self.distributions.append(gs.Distribution_cf(
                    distributionWidth,
                    1,
                    -distributionWidth*(1+1j)/2,
                    False))

        self.fftStreamToVector = blocks.stream_to_vector(
                gr.sizeof_gr_complex,
                windowSize)

        fftWindow = window.hanning(windowSize)
        self.windowConstant = np.sum(np.array(fftWindow)**2)

        self.fft = gr_fft.fft_vcc(
                windowSize,
                True,
                (fftWindow),
                True,
                8)
        self.complexToMagSquared = blocks.complex_to_mag_squared(windowSize)
        self.fftAverage = gs.Average_ff(windowSize)

        self.powerComplexToMagSquared = blocks.complex_to_mag_squared(1)
        self.powerAverage = gs.Average_ff(1)


        ##################################################
        # Connections
        ##################################################
        self.connect((self.symbolGenerator, 0), (self.guidedScrambler, 0))
        self.connect((self.guidedScrambler, 0), (self.symbolMapper, 0))
        self.connect((self.guidedScrambler, 0), (self.terminator, 0))
        self.connect((self.symbolMapper, 0), (self.integrate, 0))
        self.connect((self.integrate, 0), (self.streamToVector, 0))
        self.connect((self.streamToVector, 0), (self.vectorToStreams, 0))

        for i in range(codewordLength):
            self.connect((self.integrate, 0), (self.autocovariances[i], 0))    
            self.connect((self.autocovariances[i], 0), (self.XXaverages[i], 0))    
            self.connect((self.autocovariances[i], 1), (self.XYaverages[i], 0))    
            self.connect((self.autocovariances[i], 2), (self.YXaverages[i], 0))    
            self.connect((self.autocovariances[i], 3), (self.YYaverages[i], 0))    

            self.connect((self.vectorToStreams, i), (self.distributions[i], 0))    

        self.connect((self.symbolMapper, 0), (self.fftStreamToVector, 0))    
        self.connect((self.fftStreamToVector, 0), (self.fft, 0))    
        self.connect((self.fft, 0), (self.complexToMagSquared, 0))    
        self.connect((self.complexToMagSquared, 0), (self.fftAverage, 0))

        self.connect((self.symbolMapper, 0), (self.powerComplexToMagSquared, 0))    
        self.connect((self.powerComplexToMagSquared, 0), (self.powerAverage, 0))
    def __init__(self):
        gr.top_block.__init__(self, "MIMO TOP FLOW 4 Tx ant")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("MIMO TOP FLOW 4 Tx ant")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "MIMO_TOP_FLOW_4_TXant")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.fftl = fftl = 1024
        self.samp_rate = samp_rate = fftl*15e3
        self.rxant = rxant = 2
        self.resampler = resampler = 400
        self.frame_key = frame_key = "slot"
        self.N_rb_dl = N_rb_dl = 50

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0_1 = filter.rational_resampler_ccc(
                interpolation=1536*fftl/1024,
                decimation=resampler,
                taps=None,
                fractional_bw=None,
        )
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
                interpolation=1536*fftl/1024,
                decimation=resampler,
                taps=None,
                fractional_bw=None,
        )
        self.lte_mimo_sss_sync_0 = lte_mimo_sss_sync(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.lte_mimo_pss_sync_0 = lte_mimo_pss_sync(
            rxant=rxant,
            synclen=5,
            fftlen=fftl,
        )
        self.lte_mimo_pss_based_frey_sync_0 = lte_mimo_pss_based_frey_sync(
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_ofdm_rx_0 = lte_mimo_ofdm_rx(
            N_rb_dl=N_rb_dl,
            ofdm_key=frame_key,
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_estimator_4_txant_0 = lte_mimo_estimator_4_txant(
            N_rb_dl=N_rb_dl,
            estimator_key=frame_key,
            initial_id=333,
            rxant=rxant,
        )
        self.lte_mimo_decode_pbch_4_txant_0 = lte_mimo_decode_pbch_4_txant(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(gr.sizeof_gr_complex*1, 2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*2, samp_rate,True)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*2, "/home/maier/LTE test files/live data/lte_capture_Wed_Aug_6_19:36:39_2014_RXant2_4MS_telekom_band1800_wg_karlruhe_hinten raus_messung1.dat", True)
        self.bch_decode_bch_hier_gr37_0 = decode_bch_hier_gr37()
        self.MIB = lte.mib_unpack_vbm("MIB")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.lte_mimo_sss_sync_0, 0), (self.lte_mimo_estimator_4_txant_0, 0))
        self.connect((self.lte_mimo_sss_sync_0, 0), (self.lte_mimo_decode_pbch_4_txant_0, 0))
        self.connect((self.lte_mimo_estimator_4_txant_0, 0), (self.lte_mimo_decode_pbch_4_txant_0, 1))
        self.connect((self.lte_mimo_estimator_4_txant_0, 1), (self.lte_mimo_decode_pbch_4_txant_0, 2))
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.lte_mimo_decode_pbch_4_txant_0, 0), (self.bch_decode_bch_hier_gr37_0, 0))
        self.connect((self.bch_decode_bch_hier_gr37_0, 0), (self.MIB, 0))
        self.connect((self.bch_decode_bch_hier_gr37_0, 1), (self.MIB, 1))
        self.connect((self.lte_mimo_estimator_4_txant_0, 2), (self.lte_mimo_decode_pbch_4_txant_0, 3))
        self.connect((self.lte_mimo_estimator_4_txant_0, 3), (self.lte_mimo_decode_pbch_4_txant_0, 4))
        self.connect((self.blocks_vector_to_streams_0, 0), (self.rational_resampler_xxx_0_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 1), (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.lte_mimo_pss_sync_0, 0), (self.lte_mimo_pss_based_frey_sync_0, 0))
        self.connect((self.lte_mimo_ofdm_rx_0, 0), (self.lte_mimo_sss_sync_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 0), (self.lte_mimo_ofdm_rx_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 1), (self.lte_mimo_ofdm_rx_0, 1))
        self.connect((self.lte_mimo_pss_sync_0, 1), (self.lte_mimo_pss_based_frey_sync_0, 1))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_vector_to_streams_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0), (self.lte_mimo_pss_sync_0, 1))
        self.connect((self.rational_resampler_xxx_0_1, 0), (self.lte_mimo_pss_sync_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id", self.lte_mimo_estimator_4_txant_0, "cell_id")
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id", self.lte_mimo_decode_pbch_4_txant_0, "cell_id")
        self.msg_connect(self.lte_mimo_pss_sync_0, "N_id_2", self.lte_mimo_sss_sync_0, "N_id_2")
Example #36
0
    def __init__(self, mpoints, taps=None):
        """
        Takes M complex streams in, produces single complex stream out
        that runs at M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        The channel spacing is equal to the input sample rate.
        The total bandwidth and output sample rate are equal the input
        sample rate * nchannels.

        Output stream to frequency mapping:

          channel zero is at zero frequency.

          if mpoints is odd:

            Channels with increasing positive frequencies come from
            channels 1 through (N-1)/2.

            Channel (N+1)/2 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

          if mpoints is even:

            Channels with increasing positive frequencies come from
            channels 1 through (N/2)-1.

            Channel (N/2) is evenly split between the max positive and
            negative bins.

            Channel (N/2)+1 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

            Channels near the frequency extremes end up getting cut
            off by subsequent filters and therefore have diminished
            utility.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(self, "synthesis_filterbank",
                                gr.io_signature(mpoints, mpoints, item_size), # Input signature
                                gr.io_signature(1, 1, item_size))             # Output signature


        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0,)

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.ifft = fft.fft_vcc(mpoints, False, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)
        # mpoints filters go in here...
        self.ss2s = blocks.streams_to_stream(item_size, mpoints)

        for i in range(mpoints):
            self.connect((self, i), (self.ss2v, i))

        self.connect(self.ss2v, self.ifft, self.v2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[i])
            self.connect((self.v2ss, i), f)
            self.connect(f, (self.ss2s, i))

            self.connect(self.ss2s, self)
Example #37
0
    def __init__(self, source):
        gr.top_block.__init__(self, "Vector To Streams")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 3e6
        self.source = source

        ##################################################
        # Blocks
        ##################################################
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_float * 1, 15)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 15,
                                                 samp_rate, True)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_float * 15,
                                                       self.source, False)
        self.blocks_file_sink_0_5 = blocks.file_sink(
            gr.sizeof_float * 1,
            '/home/rich/Desktop/testbed_measurements/automation/bin/tx11.bin',
            False)
        self.blocks_file_sink_0_5.set_unbuffered(False)
        self.blocks_file_sink_0_4_1 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx12.bin',
            False)
        self.blocks_file_sink_0_4_1.set_unbuffered(False)
        self.blocks_file_sink_0_4_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx7.bin', False)
        self.blocks_file_sink_0_4_0.set_unbuffered(False)
        self.blocks_file_sink_0_4 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/tx2.bin', False)
        self.blocks_file_sink_0_4.set_unbuffered(False)
        self.blocks_file_sink_0_3_1 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx13.bin',
            False)
        self.blocks_file_sink_0_3_1.set_unbuffered(False)
        self.blocks_file_sink_0_3_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx8.bin', False)
        self.blocks_file_sink_0_3_0.set_unbuffered(False)
        self.blocks_file_sink_0_3 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx3.bin', False)
        self.blocks_file_sink_0_3.set_unbuffered(False)
        self.blocks_file_sink_0_2_1 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx14.bin',
            False)
        self.blocks_file_sink_0_2_1.set_unbuffered(False)
        self.blocks_file_sink_0_2_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx9.bin', False)
        self.blocks_file_sink_0_2_0.set_unbuffered(False)
        self.blocks_file_sink_0_2 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx4.bin', False)
        self.blocks_file_sink_0_2.set_unbuffered(False)
        self.blocks_file_sink_0_1 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx6.bin', False)
        self.blocks_file_sink_0_1.set_unbuffered(False)
        self.blocks_file_sink_0_0_1 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx15.bin',
            False)
        self.blocks_file_sink_0_0_1.set_unbuffered(False)
        self.blocks_file_sink_0_0_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx10.bin',
            False)
        self.blocks_file_sink_0_0_0.set_unbuffered(False)
        self.blocks_file_sink_0_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx5.bin', False)
        self.blocks_file_sink_0_0.set_unbuffered(False)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_float * 1, '/home/rich/Desktop/repos/bin/tx1.bin', False)
        self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 4),
                     (self.blocks_file_sink_0_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 9),
                     (self.blocks_file_sink_0_0_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 14),
                     (self.blocks_file_sink_0_0_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 5),
                     (self.blocks_file_sink_0_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 3),
                     (self.blocks_file_sink_0_2, 0))
        self.connect((self.blocks_vector_to_streams_0, 8),
                     (self.blocks_file_sink_0_2_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 13),
                     (self.blocks_file_sink_0_2_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 2),
                     (self.blocks_file_sink_0_3, 0))
        self.connect((self.blocks_vector_to_streams_0, 7),
                     (self.blocks_file_sink_0_3_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 12),
                     (self.blocks_file_sink_0_3_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.blocks_file_sink_0_4, 0))
        self.connect((self.blocks_vector_to_streams_0, 6),
                     (self.blocks_file_sink_0_4_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 11),
                     (self.blocks_file_sink_0_4_1, 0))
        self.connect((self.blocks_vector_to_streams_0, 10),
                     (self.blocks_file_sink_0_5, 0))
Example #38
0
    def __init__(self):
        gr.top_block.__init__(self, "MIMO TOP FLOW")

        ##################################################
        # Variables
        ##################################################
        self.fftl = fftl = 128
        self.samp_rate = samp_rate = fftl * 15e3
        self.rxant = rxant = 2
        self.resampler = resampler = 400
        self.frame_key = frame_key = "slot"
        self.N_rb_dl = N_rb_dl = 50

        ##################################################
        # Blocks
        ##################################################
        self.lte_mimo_sss_sync_0 = lte_mimo_sss_sync(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.lte_mimo_pss_sync_0 = lte_mimo_pss_sync(
            rxant=rxant,
            synclen=5,
            fftlen=fftl,
        )
        self.lte_mimo_pss_based_frey_sync_0 = lte_mimo_pss_based_frey_sync(
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_ofdm_rx_0 = lte_mimo_ofdm_rx(
            N_rb_dl=N_rb_dl,
            ofdm_key=frame_key,
            fftlen=fftl,
            rxant=rxant,
        )
        self.lte_mimo_estimator_0 = lte_mimo_estimator(
            N_rb_dl=N_rb_dl,
            estimator_key=frame_key,
            initial_id=2,
            rxant=rxant,
        )
        self.lte_mimo_decode_pbch_0 = lte_mimo_decode_pbch(
            N_rb_dl=N_rb_dl,
            rxant=rxant,
        )
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_gr_complex * 1, 2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 2,
                                                 samp_rate, True)
        self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector(
            gr.sizeof_gr_complex * 12 * N_rb_dl, 2)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 2,
            "/home/johannes/src/gr-lte/tests/lte_test_data_RX2_NRBDL6.dat",
            True)
        self.bch_decode_bch_hier_gr37_0 = decode_bch_hier_gr37()
        self.MIB = lte.mib_unpack_vbm("MIB")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.lte_mimo_pss_sync_0, 1),
                     (self.lte_mimo_pss_based_frey_sync_0, 1))
        self.connect((self.lte_mimo_pss_sync_0, 0),
                     (self.lte_mimo_pss_based_frey_sync_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 0),
                     (self.lte_mimo_ofdm_rx_0, 0))
        self.connect((self.lte_mimo_pss_based_frey_sync_0, 1),
                     (self.lte_mimo_ofdm_rx_0, 1))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.lte_mimo_pss_sync_0, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.lte_mimo_pss_sync_0, 1))
        self.connect((self.lte_mimo_ofdm_rx_0, 0),
                     (self.lte_mimo_sss_sync_0, 0))
        self.connect((self.lte_mimo_ofdm_rx_0, 1),
                     (self.lte_mimo_sss_sync_0, 1))
        self.connect((self.lte_mimo_decode_pbch_0, 0),
                     (self.bch_decode_bch_hier_gr37_0, 0))
        self.connect((self.lte_mimo_estimator_0, 0),
                     (self.lte_mimo_decode_pbch_0, 1))
        self.connect((self.lte_mimo_estimator_0, 1),
                     (self.lte_mimo_decode_pbch_0, 2))
        self.connect((self.bch_decode_bch_hier_gr37_0, 1), (self.MIB, 1))
        self.connect((self.bch_decode_bch_hier_gr37_0, 0), (self.MIB, 0))
        self.connect((self.lte_mimo_sss_sync_0, 1),
                     (self.blocks_streams_to_vector_0_0, 1))
        self.connect((self.lte_mimo_sss_sync_0, 0),
                     (self.blocks_streams_to_vector_0_0, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0),
                     (self.lte_mimo_estimator_0, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0),
                     (self.lte_mimo_decode_pbch_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id",
                         self.lte_mimo_estimator_0, "cell_id")
        self.msg_connect(self.lte_mimo_pss_sync_0, "N_id_2",
                         self.lte_mimo_sss_sync_0, "N_id_2")
        self.msg_connect(self.lte_mimo_sss_sync_0, "cell_id",
                         self.lte_mimo_decode_pbch_0, "cell_id")
Example #39
0
    def __init__(self):
        gr.top_block.__init__(self, "Run Rootmusic Calib Lin Array Simulation")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Run Rootmusic Calib Lin Array Simulation")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings(
            "GNU Radio", "run_RootMUSIC_calib_lin_array_simulation")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.theta1_deg = theta1_deg = 123
        self.theta0_deg = theta0_deg = 30
        self.input_variables = input_variables = struct({
            'SampleRate':
            320000,
            'ToneFreq1':
            10000,
            'ToneFreq2':
            20000,
            'NormSpacing':
            0.44,
            'NumTargets':
            2,
            'NumArrayElements':
            4,
            'PSpectrumLength':
            2**10,
            'SnapshotSize':
            2**11,
            'OverlapSize':
            2**9,
            'AntGains':
            numpy.array([0.94984789, 0.4544107, 0.34649469, 0.25083929]),
            'AntPhases':
            numpy.array([0.28647672, 5.27248071, 2.71271102, 1.36970886]),
            'DirectoryConfigFiles':
            "/tmp",
            'AntennaCalibration':
            "calibration_lin_array_simulated.cfg",
        })
        self.theta1 = theta1 = numpy.pi * theta1_deg / 180
        self.theta0 = theta0 = numpy.pi * theta0_deg / 180
        self.ant_locs = ant_locs = numpy.dot(
            input_variables.NormSpacing,
            numpy.arange(input_variables.NumArrayElements /
                         2, -input_variables.NumArrayElements / 2, -1) if
            (input_variables.NumArrayElements % 2 == 1) else numpy.arange(
                input_variables.NumArrayElements / 2 -
                0.5, -input_variables.NumArrayElements / 2 - 0.5, -1))
        self.ant_coeffs = ant_coeffs = input_variables.AntGains * numpy.exp(
            1j * input_variables.AntPhases)
        self.amv1_true = amv1_true = numpy.exp(-1j * ant_locs * 2 * numpy.pi *
                                               numpy.cos(theta1))
        self.amv0_true = amv0_true = numpy.exp(-1j * ant_locs * 2 * numpy.pi *
                                               numpy.cos(theta0))
        self.amv1 = amv1 = numpy.multiply(ant_coeffs, amv1_true)
        self.amv0 = amv0 = numpy.multiply(ant_coeffs, amv0_true)
        self.array_manifold_matrix = array_manifold_matrix = numpy.array(
            [amv0, amv1]).transpose()
        self.antenna_calibration_file_name = antenna_calibration_file_name = os.path.join(
            input_variables.DirectoryConfigFiles,
            input_variables.AntennaCalibration)

        ##################################################
        # Blocks
        ##################################################
        self.tab = Qt.QTabWidget()
        self.tab_widget_0 = Qt.QWidget()
        self.tab_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_0)
        self.tab_grid_layout_0 = Qt.QGridLayout()
        self.tab_layout_0.addLayout(self.tab_grid_layout_0)
        self.tab.addTab(self.tab_widget_0, 'Direction of Arrival')
        self.tab_widget_1 = Qt.QWidget()
        self.tab_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                          self.tab_widget_1)
        self.tab_grid_layout_1 = Qt.QGridLayout()
        self.tab_layout_1.addLayout(self.tab_grid_layout_1)
        self.tab.addTab(self.tab_widget_1, 'Direction of Arrival')
        self.top_layout.addWidget(self.tab)
        self._theta1_deg_range = Range(0, 180, 1, 123, 200)
        self._theta1_deg_win = RangeWidget(self._theta1_deg_range,
                                           self.set_theta1_deg, 'AoA',
                                           "counter_slider", float)
        self.top_layout.addWidget(self._theta1_deg_win)
        self._theta0_deg_range = Range(0, 180, 1, 30, 200)
        self._theta0_deg_win = RangeWidget(self._theta0_deg_range,
                                           self.set_theta0_deg, 'AoA',
                                           "counter_slider", float)
        self.top_layout.addWidget(self._theta0_deg_win)
        self.doa_rootMUSIC_linear_array_0 = doa.rootMUSIC_linear_array(
            input_variables.NormSpacing, input_variables.NumTargets,
            input_variables.NumArrayElements)
        self.doa_compass_0 = doa.compass("", 0, 180, 10, 0)
        self.tab_layout_1.addLayout(self.doa_compass_0.this_layout)
        self.doa_compass = doa.compass("", 0, 180, 10, 0)
        self.tab_layout_0.addLayout(self.doa_compass.this_layout)
        self.doa_autocorrelate_0 = doa.autocorrelate(
            input_variables.NumArrayElements, input_variables.SnapshotSize,
            input_variables.OverlapSize, 1)
        self.doa_antenna_correction_0 = doa.antenna_correction(
            input_variables.NumArrayElements, antenna_calibration_file_name)
        self.blocks_vector_to_streams_0 = blocks.vector_to_streams(
            gr.sizeof_float * 1, input_variables.NumTargets)
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                   input_variables.SampleRate,
                                                   True)
        self.blocks_multiply_matrix_xx_0 = blocks.multiply_matrix_cc(
            array_manifold_matrix, gr.TPP_ALL_TO_ALL)
        self.blocks_add_xx_0_0 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            input_variables.SampleRate, analog.GR_COS_WAVE,
            input_variables.ToneFreq2, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            input_variables.SampleRate, analog.GR_COS_WAVE,
            input_variables.ToneFreq1, 1, 0)
        self.analog_noise_source_x_0_0_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 0.5, 0)
        self.analog_noise_source_x_0_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 0.0005, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.analog_noise_source_x_0_0_0, 0),
                     (self.blocks_add_xx_0_0, 1))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_add_xx_0_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.blocks_multiply_matrix_xx_0, 0))
        self.connect((self.blocks_add_xx_0_0, 0),
                     (self.blocks_throttle_0_0, 0))
        self.connect((self.blocks_multiply_matrix_xx_0, 0),
                     (self.doa_antenna_correction_0, 0))
        self.connect((self.blocks_multiply_matrix_xx_0, 1),
                     (self.doa_antenna_correction_0, 1))
        self.connect((self.blocks_multiply_matrix_xx_0, 2),
                     (self.doa_antenna_correction_0, 2))
        self.connect((self.blocks_multiply_matrix_xx_0, 3),
                     (self.doa_antenna_correction_0, 3))
        self.connect((self.blocks_throttle_0_0, 0),
                     (self.blocks_multiply_matrix_xx_0, 1))
        self.connect((self.blocks_vector_to_streams_0, 0),
                     (self.doa_compass, 0))
        self.connect((self.blocks_vector_to_streams_0, 1),
                     (self.doa_compass_0, 0))
        self.connect((self.doa_antenna_correction_0, 0),
                     (self.doa_autocorrelate_0, 0))
        self.connect((self.doa_antenna_correction_0, 1),
                     (self.doa_autocorrelate_0, 1))
        self.connect((self.doa_antenna_correction_0, 2),
                     (self.doa_autocorrelate_0, 2))
        self.connect((self.doa_antenna_correction_0, 3),
                     (self.doa_autocorrelate_0, 3))
        self.connect((self.doa_autocorrelate_0, 0),
                     (self.doa_rootMUSIC_linear_array_0, 0))
        self.connect((self.doa_rootMUSIC_linear_array_0, 0),
                     (self.blocks_vector_to_streams_0, 0))
Example #40
0
    def __init__(self, mpoints, taps=None):
        """
        Takes M complex streams in, produces single complex stream out
        that runs at M times the input sample rate

        Args:
            mpoints: number of freq bins/interpolation factor/subbands
            taps: filter taps for subband filter

        The channel spacing is equal to the input sample rate.
        The total bandwidth and output sample rate are equal the input
        sample rate * nchannels.

        Output stream to frequency mapping:

          channel zero is at zero frequency.

          if mpoints is odd:

            Channels with increasing positive frequencies come from
            channels 1 through (N-1)/2.

            Channel (N+1)/2 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

          if mpoints is even:

            Channels with increasing positive frequencies come from
            channels 1 through (N/2)-1.

            Channel (N/2) is evenly split between the max positive and
            negative bins.

            Channel (N/2)+1 is the maximum negative frequency, and
            frequency increases through N-1 which is one channel lower
            than the zero frequency.

            Channels near the frequency extremes end up getting cut
            off by subsequent filters and therefore have diminished
            utility.
        """
        item_size = gr.sizeof_gr_complex
        gr.hier_block2.__init__(self, "synthesis_filterbank",
                                gr.io_signature(mpoints, mpoints, item_size), # Input signature
                                gr.io_signature(1, 1, item_size))             # Output signature


        if taps is None:
            taps = _generate_synthesis_taps(mpoints)

        # pad taps to multiple of mpoints
        r = len(taps) % mpoints
        if r != 0:
            taps = taps + (mpoints - r) * (0,)

        # split in mpoints separate set of taps
        sub_taps = _split_taps(taps, mpoints)

        self.ss2v = blocks.streams_to_vector(item_size, mpoints)
        self.ifft = fft.fft_vcc(mpoints, False, [])
        self.v2ss = blocks.vector_to_streams(item_size, mpoints)
        # mpoints filters go in here...
        self.ss2s = blocks.streams_to_stream(item_size, mpoints)

        for i in range(mpoints):
            self.connect((self, i), (self.ss2v, i))

        self.connect(self.ss2v, self.ifft, self.v2ss)

        # build mpoints fir filters...
        for i in range(mpoints):
            f = fft_filter_ccc(1, sub_taps[i])
            self.connect((self.v2ss, i), f)
            self.connect(f, (self.ss2s, i))

	self.connect(self.ss2s, self)
Example #41
0
  def __init__(self, filenames, dev_addrs, dual,
         onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps):
    gr.top_block.__init__(self)
    if mix:
      raise NotImplementedError("TODO: Hilbert remix mode not implemented.")

    if dual:
      channels = [0, 1]
    else:
      channels = [0]
    uhd_sinks = [
      uhd.usrp_sink(",".join(
        [addr, "send_frame_size=32768,num_send_frames=128"]),
              uhd.stream_args(
                cpu_format="fc32",
                otwformat="sc8",
                channels=channels))
      for addr in dev_addrs]

    for sink in uhd_sinks:
      a = sink.get_usrp_info()
      for each in a.keys():
        print each + " : " + a.get(each)
      sink.set_clock_rate(fs, uhd.ALL_MBOARDS)
      sink.set_samp_rate(fs)
      sink.set_center_freq(fc, 0)
      sink.set_gain(gain, 0)
      if dual:
        sink.set_center_freq(fc, 1)
        sink.set_gain(gain, 1)
        sink.set_subdev_spec("A:B A:A", 0)
        # TODO Use offset tuning?
      if sync_pps:
        sink.set_clock_source("external") # 10 MHz
        sink.set_time_source("external") # PPS

    if unint:
      if noise or onebit or not iq:
        raise NotImplementedError("TODO: RX channel-interleaved mode only "
                      "supported for noiseless 8-bit complex.")

      BLOCK_N = 16*1024*1024
      demux = blocks.vector_to_streams(2, len(uhd_sinks))
      self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False),
             blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N),
             demux)
      for ix, sink in enumerate(uhd_sinks):
        self.connect((demux, ix),
               blocks.vector_to_stream(1, 2),
               blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
               blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125)
#               blocks.vector_to_stream(8, 16*1024),
               sink)

    else:
      for i, filename in enumerate(filenames):
        src = blocks.file_source(gr.sizeof_char*1, filename, False)
        if dual:
          channel = i % 2
          sink = uhd_sinks[i/2]
        else:
          channel = 0
          sink = uhd_sinks[i]
        if iq:
          node = blocks.multiply_const_cc(1.0/1024)
          if onebit:
            self.connect(src,
                   blocks.unpack_k_bits_bb(8),
                   blocks.char_to_short(), # [0, 1] -> [0, 256]
                   blocks.add_const_ss(-128), # [-128, +128],
                   blocks.interleaved_short_to_complex(), # [ -128.0, +128.0]
                   node) # [-0.125, +0.125]
          else:
            self.connect(src, # [-128..127]
                   blocks.interleaved_char_to_complex(), # [-128.0, +127.0]
                   node) # [-0.125, +0.125)

        else:
          node = blocks.float_to_complex(1)
          if onebit:
            self.connect(src,
                   blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125]
                   blocks.char_to_float(vlen=1, scale=4),
                   blocks.add_const_vff((-0.125, )),
                   node)
          else:
            self.connect(src, # [-128..127] -> [-0.125, +0.125)
                   blocks.char_to_float(vlen=1, scale=1024),
                   node)

        if noise:
          combiner = blocks.add_vcc(1)
          self.connect((node, 0),
                 (combiner, 0),
                 (sink, channel))
          self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192),
                 (combiner, 1))
        else:
          self.connect((node, 0),
                 (sink, channel))

    print "Setting clocks..."
    if sync_pps:
      time.sleep(1.1) # Ensure there's been an edge.  TODO: necessary?
      last_pps_time = uhd_sinks[0].get_time_last_pps()
      while last_pps_time == uhd_sinks[0].get_time_last_pps():
        time.sleep(0.1)
      print "Got edge"
      [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks]
      time.sleep(1.0) # Wait for edge to set the clocks
    else:
      # No external PPS/10 MHz.  Just set each clock and accept some skew.
      t = time.time()
      [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks]
      if len(uhd_sinks) > 1:
        print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % (
          (time.time()-t) * 1000)

    t_start = uhd.time_spec(time.time() + 1.5)
    [sink.set_start_time(t_start) for sink in uhd_sinks]
    print "ready"