def test_pa(self, param):
    """this function run the defined test, for easier understanding"""

    tb = self.tb
    data_gain = namedtuple('data_gain', 'src out time')

    src_phase_acc =blocks.vector_source_f((np.linspace(0, param.value * param.items, param.items, endpoint=True)), False, 1, [])
    src_noise = analog.noise_source_f(analog.GR_GAUSSIAN, param.noise, 0)

    adder = blocks.add_vff(1)
    throttle = blocks.throttle(gr.sizeof_float*1, param.samp_rate,True)
    head = blocks.head(gr.sizeof_float, int (param.items))

    dst_pc_out = flaress.vector_sink_int64()
    dst_gain_out = flaress.vector_sink_int64()

    pc = ecss.phase_converter(param.N)
    gain = ecss.gain_phase_accumulator(param.reset, param.uplink, param.downlink)

    tb.connect(src_phase_acc, (adder, 0))
    tb.connect(src_noise, (adder, 1))
    tb.connect(adder, throttle)
    tb.connect(throttle, head)
    tb.connect(head, pc)
    tb.connect(pc, gain)
    tb.connect(pc, dst_pc_out)
    tb.connect(gain, dst_gain_out)

    self.tb.run()

    data_gain.src = dst_pc_out.data()
    data_gain.out = dst_gain_out.data()
    data_gain.time = np.linspace(0, (param.items * 1.0 / param.samp_rate), param.items, endpoint=False)

    return data_gain
def test_ramp(self, param):
    """this function run the defined test, for easier understanding"""

    tb = self.tb
    data_pc = namedtuple('data_pc', 'src out time')

    src_ramp = analog.sig_source_f(param.samp_rate, analog.GR_SAW_WAVE, (param.samp_rate * 0.5 / param.items), 2.0 * (param.max_value - param.min_value), (2.0 * param.min_value - param.max_value))

    throttle = blocks.throttle(gr.sizeof_float*1, param.samp_rate,True)
    head = blocks.head(gr.sizeof_float, int (param.items))

    dst_source = blocks.vector_sink_f()
    dst_pc_out = flaress.vector_sink_int64()

    pc = ecss.phase_converter(param.N)

    tb.connect(src_ramp, throttle)
    tb.connect(throttle, head)
    tb.connect(head, dst_source)
    tb.connect(head, pc)
    tb.connect(pc, dst_pc_out)

    self.tb.run()

    data_pc.src = dst_source.data()
    data_pc.out = dst_pc_out.data()
    data_pc.time = np.linspace(0, (param.items * 1.0 / param.samp_rate), param.items, endpoint=False)

    return data_pc
Exemple #3
0
    def test_005_t(self):
        """test_005_t: reset switch in the middle of the simulation"""

        tb = self.tb
        data_gain = namedtuple('data_gain', 'src out time')
        param = namedtuple(
            'param', 'samp_rate items N noise uplink downlink value reset')
        param.N = 38
        param.samp_rate = 4096
        param.items = param.samp_rate * 3
        param.value = math.pi / 200  # to express it in rad/s
        param.noise = 0.0
        param.uplink = 221
        param.downlink = 240
        param.reset = True

        print_parameters(param)

        debug_switch = flaress.debug_func_probe(gr.sizeof_float * 1)
        gain = ecss.gain_phase_accumulator(param.reset, param.uplink,
                                           param.downlink)

        def _probe_func_probe():
            time.sleep(
                1
            )  #in the middle of one block of items, to be more sure that both functions are executed in the at the same time.
            try:
                gain.set_reset(False)
                debug_switch.debug_nitems()
                self.debug_reset = gain.get_reset()
            except AttributeError:
                pass

        _probe_func_thread = threading.Thread(target=_probe_func_probe)
        _probe_func_thread.daemon = True

        src_phase_acc = blocks.vector_source_f((np.linspace(
            0, param.value * param.items, param.items, endpoint=True)), False,
                                               1, [])
        src_noise = analog.noise_source_f(analog.GR_GAUSSIAN, param.noise, 0)

        adder = blocks.add_vff(1)
        throttle = blocks.throttle(gr.sizeof_float * 1, param.samp_rate, True)
        head = blocks.head(gr.sizeof_float, int(param.items))

        dst_pc_out = flaress.vector_sink_int64()
        dst_gain_out = flaress.vector_sink_int64()

        pc = ecss.phase_converter(param.N)

        throttle.set_max_noutput_items(param.samp_rate)
        throttle.set_min_noutput_items(param.samp_rate)

        tb.connect(src_phase_acc, (adder, 0))
        tb.connect(src_noise, (adder, 1))
        tb.connect(adder, throttle)
        tb.connect(throttle, head)
        tb.connect(head, pc)
        tb.connect(head, debug_switch)
        tb.connect(pc, gain)
        tb.connect(pc, dst_pc_out)
        tb.connect(gain, dst_gain_out)

        _probe_func_thread.start()
        self.tb.run()

        switch = debug_switch.data()

        data_gain.src = dst_pc_out.data()
        data_gain.out = dst_gain_out.data()
        data_gain.time = np.linspace(0, (param.items * 1.0 / param.samp_rate),
                                     param.items,
                                     endpoint=False)

        plot(self, data_gain)

        #check the switch
        self.assertEqual(len(switch), 1)
        self.assertEqual(self.debug_reset, 0)
        print("-Final reset value of the gain phase accumulator: %d;" %
              self.debug_reset)
        print(
            "-Set function received at the moment (of the simulation): %.2f s;"
            % (switch[0] * (1.0 / param.samp_rate)))

        #check the value after reset
        self.assertEqual(data_gain.src[switch[0]], data_gain.out[switch[0]])

        #check slope
        src_min_step, src_slope = check_integer_phase(data_gain.src, param.N,
                                                      10)
        gain_min_step, gain_slope = check_integer_phase(
            data_gain.out, param.N, 10)
        tar = (param.downlink * 1.0 / param.uplink)  #turn around ratio

        self.assertAlmostEqual((tar * src_slope), gain_slope, 2)
        self.assertAlmostEqual((tar * src_min_step), gain_min_step, 2)
        print("-Input Slope : %f rad/s;" % (src_slope * param.samp_rate))
        print("-Input Min step : %f rad;" % src_min_step)
        print("-Turn Around Ration : %f;" % tar)
        print("-Output Slope : %f rad/s;" % (gain_slope * param.samp_rate))
        print("-Output Min step : %f rad." % gain_min_step)
Exemple #4
0
def test_accumulator_gain(self, param):
    """this function run the defined test, for easier understanding"""

    tb = self.tb
    data_pc = namedtuple('data_pc', 'src_rad src_int64 out carrier phase time')
    data_fft = namedtuple('data_fft', 'out cnr_out bins')

    # src_ramp = analog.sig_source_f(param.samp_rate, analog.GR_SAW_WAVE, (param.samp_rate * 0.5 / param.items), (2.0 * param.items), (- param.items))
    # src_phase_acc =blocks.vector_source_f((np.linspace(0, param.step * param.items, param.items, endpoint=True)), False, 1, [])
    src = analog.sig_source_c(param.samp_rate, analog.GR_COS_WAVE, param.freq,
                              1, 0)
    arg = blocks.complex_to_arg(1)

    throttle = blocks.throttle(gr.sizeof_float * 1, param.samp_rate, True)
    head = blocks.head(gr.sizeof_float, int(param.items))

    dst_src_rad = blocks.vector_sink_f()
    dst_src_pa = flaress.vector_sink_int64()
    dst_out_cpm = blocks.vector_sink_c()

    snr_estimator = flaress.snr_estimator_cfv(auto_carrier=True,
                                              carrier=True,
                                              all_spectrum=True,
                                              freq_central=0,
                                              samp_rate=param.samp_rate,
                                              nintems=param.fft_size,
                                              signal_bw=0,
                                              noise_bw=param.noise_bw,
                                              avg_alpha=1.0,
                                              average=False,
                                              win=window.blackmanharris)
    dst_out_fft = blocks.vector_sink_f(param.fft_size, param.items)
    dst_out_cnr = blocks.vector_sink_f()
    dst_freq_det = blocks.vector_sink_f()
    dst_phase = blocks.vector_sink_f()

    phase = blocks.complex_to_arg(1)

    pc = ecss.phase_converter(param.N)
    cpm = ecss.coherent_phase_modulator(param.N, param.inputs)
    gain = ecss.gain_phase_accumulator(False, param.uplink, param.downlink)

    tb.connect(src, arg)
    tb.connect(arg, head)
    tb.connect(head, dst_src_rad)
    tb.connect(head, pc)
    tb.connect(pc, dst_src_pa)

    tb.connect(pc, gain)
    tb.connect(gain, cpm)
    tb.connect(cpm, snr_estimator)

    tb.connect((snr_estimator, 0), dst_out_cnr)
    tb.connect((snr_estimator, 1), dst_out_fft)
    tb.connect(cpm, dst_out_cpm)
    tb.connect(cpm, phase)
    tb.connect(phase, dst_phase)

    self.tb.run()

    data_pc.src_rad = dst_src_rad.data()
    data_pc.src_int64 = dst_src_pa.data()
    data_pc.out = dst_out_cpm.data()
    data_pc.time = np.linspace(0, (param.items * 1.0 / param.samp_rate),
                               param.items,
                               endpoint=False)
    data_pc.phase = dst_phase.data()

    out = dst_out_fft.data()
    cnr_out = dst_out_cnr.data()

    # data_fft.out = out[param.items - (param.fft_size / 2) : param.items] + out[param.items - param.fft_size : param.items - (param.fft_size / 2)] #take the last fft_size elements
    data_fft.out = out[param.items - param.fft_size:
                       param.items]  #take the last fft_size elements
    data_fft.cnr_out = cnr_out[-1]  #take the last element
    data_fft.bins = np.linspace(-(param.samp_rate / 2.0),
                                (param.samp_rate / 2.0),
                                param.fft_size,
                                endpoint=True)

    return data_pc, data_fft