def test_001(self):
        """
        Test the energy of a simple sequence (1, 2, -1, -2).
        """
        # input and expected results
        src_data = (1, 1, 1, 1)
        expected_result = 1

        # blocks
        fft_size = len(src_data)
        mavg_size = 1

        src = blocks.vector_source_c(data=src_data)
        dst = blocks.probe_signal_f()
        ed = EnergySSArch(fft_size, mavg_size, EnergyDecision(1))
        #radio_device = RadioDevice(the_source = src, the_sink = dst)

        radio_device = RadioDevice()
        radio_device.add_arch(source=src, arch=ed, sink=dst, uhd_device=None, name='ed')
        ################ FIM NOVO RADIO DEVICE

        ## flowgraph
        ##self.tb.add_arch(ed, radio_device, 'ed')
        self.tb.add_radio(radio_device)
        self.tb.run()

        result_data = dst.level()
        self.assertEqual(expected_result, result_data)
    def device_definition(options):
        """
        Definition of the devices used in the program.
        @param options
        """

        tb = OpERAFlow(name='US')

        the_source = blocks.file_source(gr.sizeof_gr_complex, "./%d_%d_%d_%d_noise.bin" % (options.fft_length, options.cp_length, options.ebn0, options.it), False)
        radio = RadioDevice(name="radio")

        det = Correlator()
        middle = gr.hier_block2(
                name='hier',
                input_signature  = gr.io_signature(1, 1, gr.sizeof_gr_complex),
                output_signature = gr.io_signature(1, 1, gr.sizeof_float * 1024),
        )
        middle.connect(middle, blocks.stream_to_vector(gr.sizeof_gr_complex, 1024), blocks.complex_to_mag(1024), middle)
        ed = EnergySSArch(1024, 1, EnergyDecision(th = options.threshold))

        radio.add_arch(source = the_source, arch = middle, sink =(det,0), uhd_device=the_source, name='estimator')
        radio.add_arch(source = the_source, arch = ed,     sink =(det,1), uhd_device=the_source, name = "ed")
        tb.add_radio(radio, "radio")

        return tb, radio, det
    def test_004(self):
        """
        Test EDTopBlock with a simple input (1, 2, 3, 4).
        """
        arr = (1.0, 2.0, 3.0, 4.0)
        expected_result = 30  # before expected result was 2536

        ed = EnergySSArch(fft_size=len(arr),
                          mavg_size=1,
                          algorithm=EnergyDecision(expected_result + 1)  # (expected_out + 1)
                          )

        src = blocks.vector_source_c(data=arr, vlen=1)
        sink = blocks.probe_signal_f()

        device = RadioDevice()
        device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed')

        self.tb.add_radio(device, 'ed')

        self.tb.start()
        self.tb.wait()

        ###self.assertEqual(expected_result , device.sink.output()[1])
        self.assertEqual(expected_result, device.ed.output()[1])  # uses 'name' parameter of the add_arch method
Ejemplo n.º 4
0
    def test_003(self):
        """
        Test a more elaborate scenario with feedback.
        In this test the FeedbackTopBlock is utilized with n waveform algorithm as manager, an energy and a feedback
        algorithm.
        """
        return
        """
	::TODO::
	Update this test.
	"""

        # Random 'signal' utilized in the test
        arr = [random.random() for i in xrange(1024)]
        fft_size = 1024

        # Bayes learning parameters
        in_th = 1
        min_th = 0.001
        max_th = 20
        delta_th = 0.001
        k = 1

        # Feeback architecture
        bl_algo = BayesLearningThreshold(in_th=in_th,
                                         min_th=min_th,
                                         max_th=max_th,
                                         delta_th=delta_th,
                                         k=k)

        # detectors utilized
        bl = EnergyDetectorC(fft_size, 1, bl_algo)
        ev = WaveformSSArch(fft_size, WaveformDecision(0.7))


        # top block
        t = FeedbackSSArch(block_manager=ev,
                           block_learner=bl,
                           feedback_algorithm=FeedbackAlgorithm(bl_algo, AlwaysTimeFeedback())
                           ### learner, manager, a_feedback_strategy
        )

        source = blocks.vector_source_c(data=arr, vlen=1)
        sink = blocks.probe_signal_f()

        device = RadioDevice()
        device.add_arch(source=source, arch=t, sink=sink, uhd_device=None, name='ss_arch')

        self.tb.add_path(t, device, 'ss')
        self.tb.run()

        # As the waveform will (probably) not detected the channel as occupied, the feedback system should decrease the threshold by 1
        self.assertEqual(0, bl_algo.feedback)
Ejemplo n.º 5
0
def build_radio(options):
    """

    @param options
    """
    radio = RadioDevice(name='radio')

    #############################
    #
    # RX PATH - sensing and packet
    #
    #############################
    ss_and_rx_source = UHDSource(device_addr="ip=%s" % options.my_ip, antenna="TX/RX")

    ss_sink = blocks.probe_signal_f()
    ss_path = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=5.0/10**4))
    radio.add_arch(source=ss_and_rx_source,
                   sink=ss_sink,
                   arch=ss_path,
                   name='ss',
                   uhd_device=ss_and_rx_source)

    pkt_rx_path = PacketGMSKRx(callback=PktQueue())
    radio.add_arch(source=ss_and_rx_source,
                   sink=None,
                   arch=pkt_rx_path,
                   name='rx',
                   uhd_device=ss_and_rx_source)

    #############################
    #
    # TX PATH - packet
    #
    #############################
    #uhd_sink = UHDSink("addr=%s" % options.my_ip)
    #pkt_tx_path = PacketGMSKTx()

    #radio.add_arch(source = None,
    #        sink = uhd_sink,
    #        arch = pkt_tx_path,
    #        name = 'tx',
    #        uhd_device = uhd_sink)

    #radio.set_samp_rate(200e3)
    return radio
    def test_003(self):
        """
        Test EDTopBlock with the input (1, 1, 1, 1, 1, 1, 1, 1).
        """
        arr = (1, 1, 1, 1, 1, 1, 1, 1)
        expected_out = 8

        ed = EnergySSArch(fft_size=len(arr),
                          mavg_size=8,
                          algorithm=EnergyDecision(expected_out - 1)
                          )

        src = blocks.vector_source_c(data=arr, vlen=1)
        sink = blocks.probe_signal_f()

        device = RadioDevice()
        device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed')

        self.tb.add_radio(device, 'ed')
        self.tb.run()

        ##self.assertEqual(1 , device.sink.level()) # didn't work
        self.assertEqual(1, device.output()[0])
Ejemplo n.º 7
0
    import OpERAFlow                            #pylint: disable=F0401
    from utils import Channel                   #pylint: disable=F0401
    from device import UHDSource, RadioDevice   #pylint: disable=F0401
    from sensing import RankingArch   #pylint: disable=F0401

    channel_list = [
            Channel(1, 205.25e6, 200e3),
            Channel(2, 211.25e6, 200e3),
            Channel(3, 219.25e6, 200e3),
        ]


    source = UHDSource()
    arch   = RankingArch(100)

    radio = RadioDevice(name = 'radio')
    radio.add_arch(source = source, arch = arch, sink = None, uhd_device = source, name = 'ss')

    top = OpERAFlow.OpERAFlow(name = "top_block")
    top.add_radio( radio, "radio")

    top.start()


    l = QNoise(
            n_weight = 0.5, n_data = ( 0.5, 3, [0.2, 0.35, 0.45] ),
            h_weight = 0.5, h_data = ( 0.5, 3, [0.2, 0.35, 0.45] ) )
    chimas = Chimas(radio, l)


    while True: