예제 #1
0
    def test_dump(self):

        num_inputs = 4
        num_outputs = 4
        input_index = 1
        output_index = 2
        output_not_selected = 3

        op = blocks.selector(gr.sizeof_char, input_index, output_index)

        src = []
        dst = []
        for ii in range(num_inputs):
            src_data = [ii + 1] * 10
            src.append(blocks.vector_source_b(src_data))
            self.tb.connect(src[ii], (op, ii))
        for jj in range(num_outputs):
            dst.append(blocks.vector_sink_b())
            self.tb.connect((op, jj), dst[jj])

        self.tb.run()

        expected_result = []
        dst_data = list(dst[output_not_selected].data())

        self.assertEqual(expected_result, dst_data)
예제 #2
0
    def test_float_vector(self):

        num_inputs = 4
        num_outputs = 4
        input_index = 1
        output_index = 2

        veclen = 3

        op = blocks.selector(
            gr.sizeof_float * veclen,
            input_index,
            output_index)

        src = []
        dst = []
        for ii in range(num_inputs):
            src_data = [float(ii) + 1] * 10 * veclen
            src.append(
                blocks.vector_source_f(
                    src_data,
                    repeat=False,
                    vlen=veclen))
            self.tb.connect(src[ii], (op, ii))
        for jj in range(num_outputs):
            dst.append(blocks.vector_sink_f(vlen=veclen))
            self.tb.connect((op, jj), dst[jj])

        self.tb.run()

        expected_result = [float(input_index) + 1] * 10 * veclen
        dst_data = list(dst[output_index].data())

        self.assertEqual(expected_result, dst_data)
예제 #3
0
    def test_select_same(self):
        src_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        expected_result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        expected_drop = ()

        num_inputs = 4
        num_outputs = 4
        input_index = 1
        output_index = 2

        op = blocks.selector(gr.sizeof_char, input_index, output_index)

        src = []
        dst = []
        for ii in range(num_inputs):
            src.append(blocks.vector_source_b(src_data))
            self.tb.connect(src[ii], (op, ii))
        for jj in range(num_outputs):
            dst.append(blocks.vector_sink_b())
            self.tb.connect((op, jj), dst[jj])

        self.tb.run()

        dst_data = dst[output_index].data()

        self.assertEqual(expected_result, dst_data)
    def __init__(self):
        gr.top_block.__init__(self, "HF channel simulation")

        ##################################################
        # Variables
        ##################################################
        self.snr = snr = 40
        self.vol = vol = [1, 1]
        self.tau_a = tau_a = 1 / 100.
        self.tau = tau = 0.1
        self.snrVecOut = snrVecOut = ([0] * 3)
        self.samp_rate = samp_rate = 48000
        self.outSigRMSVec = outSigRMSVec = ([0] * 2)
        self.noSpread = noSpread = 0
        self.kN = kN = pow(10.0, (-snr / 20.0))
        self.freqShift = freqShift = 0.0
        self.fd = fd = 1
        self.en_noise = en_noise = [0, 0]
        self.doppler_ir = doppler_ir = [
            0.0016502763167573274, 0.0018854799389366934, 0.002149957633383614,
            0.0024466994528029662, 0.002778907461425479, 0.003149998028185868,
            0.003563602180973301, 0.00402356375450247, 0.004533935060796761,
            0.0050989698117900155, 0.005723113028669535, 0.006410987682800636,
            0.007167377828853199, 0.007997208012493867, 0.008905518763040982,
            0.00989743801603955, 0.010978148351927763, 0.012152849984840378,
            0.013426719489994542, 0.014804864318746317, 0.016292273216847054,
            0.01789376273305468, 0.019613920081278834, 0.021457042698902442,
            0.023427074925696508, 0.025527542310538734, 0.027761484135525694,
            0.030131384827462734, 0.03263910500345486, 0.035285812968654906,
            0.03807191754835305, 0.04099700319171279, 0.04405976832879332,
            0.04725796799434838, 0.050588361749672524, 0.05404666793605477,
            0.057627525278984175, 0.06132446283016882, 0.06512987918400244,
            0.0690350318359975, 0.073030037462906, 0.07710388379815894,
            0.08124445365265866, 0.08543856149104095, 0.08967200281887802,
            0.0939296164688993, 0.09819535969651079, 0.10245239580938088,
            0.10668319386560887, 0.1108696397832219, 0.11499315801386097,
            0.11903484274903825, 0.12297559745183839, 0.12679628134392928,
            0.1304778613306593, 0.13400156771907581, 0.1373490519778611,
            0.14050254470705797, 0.14344501193124823, 0.14616030780428022,
            0.14863332181791858, 0.15085011864154488, 0.1527980687853246,
            0.154465968374505, 0.15584414644656272, 0.15692455833401583,
            0.15770086387153975, 0.1581684893637365, 0.15832467246620405,
            0.1581684893637365, 0.15770086387153975, 0.15692455833401583,
            0.15584414644656272, 0.154465968374505, 0.1527980687853246,
            0.15085011864154488, 0.14863332181791858, 0.14616030780428022,
            0.14344501193124823, 0.14050254470705797, 0.1373490519778611,
            0.13400156771907581, 0.1304778613306593, 0.12679628134392928,
            0.12297559745183839, 0.11903484274903825, 0.11499315801386097,
            0.1108696397832219, 0.10668319386560887, 0.10245239580938088,
            0.09819535969651079, 0.0939296164688993, 0.08967200281887802,
            0.08543856149104095, 0.08124445365265866, 0.07710388379815894,
            0.073030037462906, 0.0690350318359975, 0.06512987918400244,
            0.06132446283016882, 0.057627525278984175, 0.05404666793605477,
            0.050588361749672524, 0.04725796799434838, 0.04405976832879332,
            0.04099700319171279, 0.03807191754835305, 0.035285812968654906,
            0.03263910500345486, 0.030131384827462734, 0.027761484135525694,
            0.025527542310538734, 0.023427074925696508, 0.021457042698902442,
            0.019613920081278834, 0.01789376273305468, 0.016292273216847054,
            0.014804864318746317, 0.013426719489994542, 0.012152849984840378,
            0.010978148351927763, 0.00989743801603955, 0.008905518763040982,
            0.007997208012493867, 0.007167377828853199, 0.006410987682800636,
            0.005723113028669535, 0.0050989698117900155, 0.004533935060796761,
            0.00402356375450247, 0.003563602180973301, 0.003149998028185868,
            0.002778907461425479, 0.0024466994528029662, 0.002149957633383614,
            0.0018854799389366934, 0.0016502763167573274
        ]
        self.ampl = ampl = [[1.0, 1.0], [1.0, 1.0]]

        ##################################################
        # Blocks
        ##################################################
        self.snrOut = blocks.probe_signal_vf(4)
        self.outSigRMS = blocks.probe_signal_vf(2)

        def _snrVecOut_probe():
            while True:

                val = self.snrOut.level()
                try:
                    self.set_snrVecOut(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))

        _snrVecOut_thread = threading.Thread(target=_snrVecOut_probe)
        _snrVecOut_thread.daemon = True
        _snrVecOut_thread.start()

        self.single_pole_iir_filter_xx_0_1 = filter.single_pole_iir_filter_ff(
            2 * pi * tau_a / samp_rate, 1)
        self.single_pole_iir_filter_xx_0_0_0 = filter.single_pole_iir_filter_ff(
            2 * pi * tau_a / samp_rate, 1)
        self.single_pole_iir_filter_xx_0_0 = filter.single_pole_iir_filter_ff(
            2 * pi * tau_a / samp_rate, 1)
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(
            2 * pi * tau_a / samp_rate, 1)

        def _outSigRMSVec_probe():
            while True:

                val = self.outSigRMS.level()
                try:
                    self.set_outSigRMSVec(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))

        _outSigRMSVec_thread = threading.Thread(target=_outSigRMSVec_probe)
        _outSigRMSVec_thread.daemon = True
        _outSigRMSVec_thread.start()

        self.low_pass_filter_2_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_2 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1_1 = filter.interp_fir_filter_ccf(
            int(samp_rate / 100),
            firdes.low_pass(ampl[1][0] * (samp_rate / 100.0), samp_rate, 50,
                            25, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1_0_0 = filter.interp_fir_filter_ccf(
            int(samp_rate / 100),
            firdes.low_pass(ampl[1][1] * (samp_rate / 100.0), samp_rate, 50,
                            25, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1_0 = filter.interp_fir_filter_ccf(
            int(samp_rate / 100),
            firdes.low_pass(ampl[0][1] * (samp_rate / 100.0), samp_rate, 50,
                            25, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1 = filter.interp_fir_filter_ccf(
            int(samp_rate / 100),
            firdes.low_pass(ampl[0][0] * (samp_rate / 100.0), samp_rate, 50,
                            25, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 1750 + 100, 600, firdes.WIN_HAMMING,
                            6.76))
        self.low_pass_filter_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 1750 + 100, 600, firdes.WIN_HAMMING,
                            6.76))
        self.epy_block_0_0_0_0 = epy_block_0_0_0_0.blk(fd=fd)
        self.epy_block_0_0_0 = epy_block_0_0_0.blk(fd=fd)
        self.epy_block_0_0 = epy_block_0_0.blk(fd=fd)
        self.epy_block_0 = epy_block_0.blk(fd=fd)
        self.blocks_streams_to_vector_0_0 = blocks.streams_to_vector(
            gr.sizeof_float * 1, 2)
        self.blocks_streams_to_vector_0 = blocks.streams_to_vector(
            gr.sizeof_float * 1, 4)
        self.blocks_selector_0_1 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                   noSpread, 0)
        self.blocks_selector_0_1.set_enabled(True)
        self.blocks_selector_0_0_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                     noSpread, 0)
        self.blocks_selector_0_0_0.set_enabled(True)
        self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                   noSpread, 0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                 noSpread, 0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_rms_xx_0_1 = blocks.rms_cf(2 * pi * tau_a * 100 /
                                               samp_rate)
        self.blocks_rms_xx_0_0_0 = blocks.rms_ff(2 * pi * tau_a * 10 /
                                                 samp_rate)
        self.blocks_rms_xx_0_0 = blocks.rms_ff(2 * pi * tau_a * 10 / samp_rate)
        self.blocks_rms_xx_0 = blocks.rms_cf(2 * pi * tau_a * 100 / samp_rate)
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float * 1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1)
        self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, 1, 0)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0)
        self.blocks_multiply_xx_1_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0_0_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0_0_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0_0_0_0 = 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_multiply_const_vxx_3_0 = blocks.multiply_const_ff(
            en_noise[1])
        self.blocks_multiply_const_vxx_3 = blocks.multiply_const_ff(
            en_noise[0])
        self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_cc(vol[1])
        self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc(vol[0])
        self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_ff(
            2 * sqrt(ampl[1][0]**2 + ampl[1][1]**2) * 2)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_ff(
            2 * sqrt(ampl[0][0]**2 + ampl[0][1]**2) * 2)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(0.5)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(0.5)
        self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_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_divide_xx_1_0 = blocks.divide_ff(1)
        self.blocks_divide_xx_1 = blocks.divide_ff(1)
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                             int(tau * samp_rate))
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           int(tau * samp_rate))
        self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_mag_squared_2_1 = blocks.complex_to_mag_squared(
            1)
        self.blocks_complex_to_mag_squared_2_0_0 = blocks.complex_to_mag_squared(
            1)
        self.blocks_complex_to_mag_squared_2_0 = blocks.complex_to_mag_squared(
            1)
        self.blocks_complex_to_mag_squared_2 = blocks.complex_to_mag_squared(1)
        self.blocks_add_xx_1_0 = blocks.add_vff(1)
        self.blocks_add_xx_1 = blocks.add_vff(1)
        self.blocks_add_xx_0_1 = blocks.add_vcc(1)
        self.blocks_add_xx_0_0_0 = blocks.add_vcc(1)
        self.blocks_add_xx_0_0 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.audio_source_0 = audio.source(samp_rate, 'hw:CARD=Rubix44,DEV=0',
                                           False)
        self.audio_sink_0 = audio.sink(samp_rate, 'hw:CARD=Rubix44,DEV=0',
                                       False)
        self.analog_sig_source_x_3 = analog.sig_source_f(
            samp_rate, analog.GR_COS_WAVE, 1000, 0.3, 0, 0)
        self.analog_sig_source_x_2_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0)
        self.analog_sig_source_x_2 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0)
        self.analog_sig_source_x_1_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0)
        self.analog_sig_source_x_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0)
        self.analog_sig_source_x_0_0_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0)
        self.analog_sig_source_x_0_0_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0)
        self.analog_sig_source_x_0_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0)
        self.analog_noise_source_x_1_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1e-0 * kN, 13)
        self.analog_noise_source_x_1 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1e-0 * kN, 3)
        self.analog_noise_source_x_0_1 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1, 10)
        self.analog_noise_source_x_0_0_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1, 11)
        self.analog_noise_source_x_0_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1, 1)
        self.analog_noise_source_x_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1, 0)
        self.analog_const_source_x_2_0 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)
        self.analog_const_source_x_2 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)
        self.analog_const_source_x_1_1 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, ampl[1][0])
        self.analog_const_source_x_1_0_0 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, ampl[1][1])
        self.analog_const_source_x_1_0 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, ampl[0][1])
        self.analog_const_source_x_1 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, ampl[0][0])
        self.analog_const_source_x_0_0 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)
        self.analog_const_source_x_0 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.analog_const_source_x_0_0, 0),
                     (self.blocks_float_to_complex_0_0, 1))
        self.connect((self.analog_const_source_x_1, 0),
                     (self.blocks_selector_0, 1))
        self.connect((self.analog_const_source_x_1_0, 0),
                     (self.blocks_selector_0_0, 1))
        self.connect((self.analog_const_source_x_1_0_0, 0),
                     (self.blocks_selector_0_0_0, 1))
        self.connect((self.analog_const_source_x_1_1, 0),
                     (self.blocks_selector_0_1, 1))
        self.connect((self.analog_const_source_x_2, 0),
                     (self.blocks_float_to_complex_1, 1))
        self.connect((self.analog_const_source_x_2_0, 0),
                     (self.blocks_float_to_complex_1_0, 1))
        self.connect((self.analog_noise_source_x_0, 0), (self.epy_block_0, 0))
        self.connect((self.analog_noise_source_x_0_0, 0),
                     (self.epy_block_0_0, 0))
        self.connect((self.analog_noise_source_x_0_0_0, 0),
                     (self.epy_block_0_0_0_0, 0))
        self.connect((self.analog_noise_source_x_0_1, 0),
                     (self.epy_block_0_0_0, 0))
        self.connect((self.analog_noise_source_x_1, 0),
                     (self.low_pass_filter_2, 0))
        self.connect((self.analog_noise_source_x_1_0, 0),
                     (self.low_pass_filter_2_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_sig_source_x_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.analog_sig_source_x_0_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0_1, 1))
        self.connect((self.analog_sig_source_x_0_0_1, 0),
                     (self.blocks_multiply_xx_0_1, 1))
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_multiply_xx_1, 0))
        self.connect((self.analog_sig_source_x_1_0, 0),
                     (self.blocks_multiply_xx_1_0, 0))
        self.connect((self.analog_sig_source_x_2, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0, 1))
        self.connect((self.analog_sig_source_x_2_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0_0, 1))
        self.connect((self.analog_sig_source_x_3, 0),
                     (self.blocks_multiply_const_vxx_3, 0))
        self.connect((self.analog_sig_source_x_3, 0),
                     (self.blocks_multiply_const_vxx_3_0, 0))
        self.connect((self.audio_source_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.audio_source_0, 1),
                     (self.blocks_float_to_complex_0_0, 0))
        self.connect((self.audio_source_0, 2), (self.blocks_null_sink_0, 0))
        self.connect((self.audio_source_0, 3), (self.blocks_null_sink_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_xx_1, 1))
        self.connect((self.blocks_add_xx_0_0, 0),
                     (self.blocks_multiply_const_vxx_2, 0))
        self.connect((self.blocks_add_xx_0_0_0, 0),
                     (self.blocks_multiply_const_vxx_2_0, 0))
        self.connect((self.blocks_add_xx_0_1, 0),
                     (self.blocks_multiply_xx_1_0, 1))
        self.connect((self.blocks_add_xx_1, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_add_xx_1_0, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_2, 0),
                     (self.single_pole_iir_filter_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_2_0, 0),
                     (self.single_pole_iir_filter_xx_0_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_2_0_0, 0),
                     (self.single_pole_iir_filter_xx_0_0_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_2_1, 0),
                     (self.single_pole_iir_filter_xx_0_1, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.blocks_add_xx_1, 0))
        self.connect((self.blocks_complex_to_real_0_0, 0),
                     (self.blocks_add_xx_1_0, 1))
        self.connect((self.blocks_delay_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0, 0))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0_1, 0))
        self.connect((self.blocks_divide_xx_1, 0),
                     (self.blocks_nlog10_ff_0, 0))
        self.connect((self.blocks_divide_xx_1_0, 0),
                     (self.blocks_nlog10_ff_0_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_float_to_complex_0_0, 0),
                     (self.blocks_multiply_xx_0_1, 0))
        self.connect((self.blocks_float_to_complex_1, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0, 2))
        self.connect((self.blocks_float_to_complex_1_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0_0, 2))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.audio_sink_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_rms_xx_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.blocks_rms_xx_0_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_float_to_complex_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1_0, 0),
                     (self.blocks_float_to_complex_1_0, 0))
        self.connect((self.blocks_multiply_const_vxx_2, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_multiply_const_vxx_2_0, 0),
                     (self.blocks_complex_to_real_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_3, 0),
                     (self.blocks_add_xx_1, 1))
        self.connect((self.blocks_multiply_const_vxx_3_0, 0),
                     (self.blocks_add_xx_1_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.low_pass_filter_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.blocks_delay_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.blocks_rms_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0),
                     (self.blocks_add_xx_0_0, 1))
        self.connect((self.blocks_multiply_xx_0_0_0_0_0, 0),
                     (self.blocks_complex_to_mag_squared_2_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0),
                     (self.blocks_add_xx_0_0_0, 1))
        self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0),
                     (self.blocks_complex_to_mag_squared_2_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0_0_1, 0),
                     (self.blocks_add_xx_0_1, 1))
        self.connect((self.blocks_multiply_xx_0_0_0_1, 0),
                     (self.blocks_add_xx_0_1, 0))
        self.connect((self.blocks_multiply_xx_0_0_1, 0),
                     (self.blocks_delay_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_1, 0),
                     (self.blocks_multiply_xx_0_0_0_1, 0))
        self.connect((self.blocks_multiply_xx_0_0_1, 0),
                     (self.blocks_rms_xx_0_1, 0))
        self.connect((self.blocks_multiply_xx_0_1, 0),
                     (self.low_pass_filter_0_0, 0))
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.blocks_add_xx_0_0, 0))
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.blocks_complex_to_mag_squared_2, 0))
        self.connect((self.blocks_multiply_xx_1_0, 0),
                     (self.blocks_add_xx_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_1_0, 0),
                     (self.blocks_complex_to_mag_squared_2_1, 0))
        self.connect((self.blocks_nlog10_ff_0, 0),
                     (self.blocks_streams_to_vector_0, 2))
        self.connect((self.blocks_nlog10_ff_0_0, 0),
                     (self.blocks_streams_to_vector_0, 3))
        self.connect((self.blocks_null_source_0, 0), (self.audio_sink_0, 2))
        self.connect((self.blocks_null_source_0, 1), (self.audio_sink_0, 3))
        self.connect((self.blocks_rms_xx_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_rms_xx_0_0, 0),
                     (self.blocks_streams_to_vector_0_0, 0))
        self.connect((self.blocks_rms_xx_0_0_0, 0),
                     (self.blocks_streams_to_vector_0_0, 1))
        self.connect((self.blocks_rms_xx_0_1, 0),
                     (self.blocks_multiply_const_vxx_1_0, 0))
        self.connect((self.blocks_selector_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 1))
        self.connect((self.blocks_selector_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0, 1))
        self.connect((self.blocks_selector_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0_1, 1))
        self.connect((self.blocks_selector_0_1, 0),
                     (self.blocks_multiply_xx_0_0_0_1, 1))
        self.connect((self.blocks_streams_to_vector_0, 0), (self.snrOut, 0))
        self.connect((self.blocks_streams_to_vector_0_0, 0),
                     (self.outSigRMS, 0))
        self.connect((self.epy_block_0, 0), (self.low_pass_filter_1, 0))
        self.connect((self.epy_block_0_0, 0), (self.low_pass_filter_1_0, 0))
        self.connect((self.epy_block_0_0_0, 0), (self.low_pass_filter_1_1, 0))
        self.connect((self.epy_block_0_0_0_0, 0),
                     (self.low_pass_filter_1_0_0, 0))
        self.connect((self.low_pass_filter_0, 0),
                     (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.low_pass_filter_0_0, 0),
                     (self.blocks_multiply_xx_0_0_1, 0))
        self.connect((self.low_pass_filter_1, 0), (self.blocks_selector_0, 0))
        self.connect((self.low_pass_filter_1_0, 0),
                     (self.blocks_selector_0_0, 0))
        self.connect((self.low_pass_filter_1_0_0, 0),
                     (self.blocks_selector_0_0_0, 0))
        self.connect((self.low_pass_filter_1_1, 0),
                     (self.blocks_selector_0_1, 0))
        self.connect((self.low_pass_filter_2, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0, 0))
        self.connect((self.low_pass_filter_2_0, 0),
                     (self.blocks_multiply_xx_0_0_0_0_0_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0),
                     (self.blocks_divide_xx_1, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0),
                     (self.blocks_streams_to_vector_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0_0, 0),
                     (self.blocks_divide_xx_1, 1))
        self.connect((self.single_pole_iir_filter_xx_0_0, 0),
                     (self.blocks_streams_to_vector_0, 1))
        self.connect((self.single_pole_iir_filter_xx_0_0_0, 0),
                     (self.blocks_divide_xx_1_0, 1))
        self.connect((self.single_pole_iir_filter_xx_0_1, 0),
                     (self.blocks_divide_xx_1_0, 0))
예제 #5
0
파일: lab4.py 프로젝트: wes268/course
    def __init__(self):
        gr.top_block.__init__(self, "Lab 4")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Lab 4")
        qtgui.util.check_set_qss()
        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", "lab4")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.echo_gain_iir = echo_gain_iir = 0
        self.delay_limit = delay_limit = 64
        self.delay_iir = delay_iir = 1
        self.sps = sps = 4
        self.pn6 = pn6 = [1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1 -1 -1]
        self.pn5 = pn5 = [1,-1,1,-1,1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1]
        self.iir_taps_2 = iir_taps_2 = np.concatenate( ([1], np.zeros(int(delay_iir-1)),[-echo_gain_iir],np.zeros(int(delay_limit-delay_iir)))     )
        self.h_filt = h_filt = [1,1,1,1]
        self.freqc = freqc = 900
        self.samp_rate = samp_rate = 1000
        self.pn6_up = pn6_up = sp.upfirdn( h_filt, pn6, sps )
        self.pn5_up = pn5_up = sp.upfirdn( h_filt, pn5, sps )
        self.phase_shift = phase_shift = 1
        self.lw = lw = 2
        self.iir_taps = iir_taps = iir_taps_2
        self.gain_ = gain_ = 0.5
        self.freqc_ = freqc_ = freqc
        self.fps = fps = 30
        self.fo = fo = 800
        self.equalize_on = equalize_on = 0
        self.echo_gain = echo_gain = 0
        self.delay = delay = 0
        self.const_qpsk = const_qpsk = digital.constellation_calcdist(digital.psk_4()[0], digital.psk_4()[1],
        4, 1).base()
        self.const_bpsk = const_bpsk = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1],
        2, 1).base()
        self.bw = bw = 1
        self.buff_size = buff_size = 32768
        self.axis = axis = 2
        self.PLL_ON = PLL_ON = 0

        ##################################################
        # Blocks
        ##################################################
        self.tab0 = Qt.QTabWidget()
        self.tab0_widget_0 = Qt.QWidget()
        self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0)
        self.tab0_grid_layout_0 = Qt.QGridLayout()
        self.tab0_layout_0.addLayout(self.tab0_grid_layout_0)
        self.tab0.addTab(self.tab0_widget_0, 'Cross-Correlation')
        self.tab0_widget_1 = Qt.QWidget()
        self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1)
        self.tab0_grid_layout_1 = Qt.QGridLayout()
        self.tab0_layout_1.addLayout(self.tab0_grid_layout_1)
        self.tab0.addTab(self.tab0_widget_1, 'Spectrum')
        self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2)
        for r in range(0, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        _phase_shift_check_box = Qt.QCheckBox('PI Phase Shift')
        self._phase_shift_choices = {True: 1, False: 0}
        self._phase_shift_choices_inv = dict((v,k) for k,v in self._phase_shift_choices.items())
        self._phase_shift_callback = lambda i: Qt.QMetaObject.invokeMethod(_phase_shift_check_box, "setChecked", Qt.Q_ARG("bool", self._phase_shift_choices_inv[i]))
        self._phase_shift_callback(self.phase_shift)
        _phase_shift_check_box.stateChanged.connect(lambda i: self.set_phase_shift(self._phase_shift_choices[bool(i)]))
        self.top_grid_layout.addWidget(_phase_shift_check_box, 12, 1, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._gain__range = Range(0.1, 1, 0.01, 0.5, 200)
        self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._freqc__range = Range(70, 6000, .01, freqc, 200)
        self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._fo_range = Range(-10000, 10000, 1, 800, 200)
        self._fo_win = RangeWidget(self._fo_range, self.set_fo, 'Frequency Offset (Hz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._fo_win, 12, 0, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._equalize_on_options = (0, 1, )
        # Create the labels list
        self._equalize_on_labels = ('Equalizer Off', 'Equalizer On', )
        # Create the combo box
        self._equalize_on_tool_bar = Qt.QToolBar(self)
        self._equalize_on_tool_bar.addWidget(Qt.QLabel('Equalizer Select' + ": "))
        self._equalize_on_combo_box = Qt.QComboBox()
        self._equalize_on_tool_bar.addWidget(self._equalize_on_combo_box)
        for _label in self._equalize_on_labels: self._equalize_on_combo_box.addItem(_label)
        self._equalize_on_callback = lambda i: Qt.QMetaObject.invokeMethod(self._equalize_on_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._equalize_on_options.index(i)))
        self._equalize_on_callback(self.equalize_on)
        self._equalize_on_combo_box.currentIndexChanged.connect(
            lambda i: self.set_equalize_on(self._equalize_on_options[i]))
        # Create the radio buttons
        self.top_grid_layout.addWidget(self._equalize_on_tool_bar, 13, 0, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._echo_gain_range = Range(0, 1, 0.01, 0, 200)
        self._echo_gain_win = RangeWidget(self._echo_gain_range, self.set_echo_gain, 'Echo Path Gain (A)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._echo_gain_win, 11, 0, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._delay_range = Range(0, delay_limit, 1, 0, 200)
        self._delay_win = RangeWidget(self._delay_range, self.set_delay, 'Delay (samples)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._delay_win, 11, 1, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._PLL_ON_options = (0, 1, )
        # Create the labels list
        self._PLL_ON_labels = ('PLL ON', 'PLL OFF', )
        # Create the combo box
        self._PLL_ON_tool_bar = Qt.QToolBar(self)
        self._PLL_ON_tool_bar.addWidget(Qt.QLabel('PLL Select' + ": "))
        self._PLL_ON_combo_box = Qt.QComboBox()
        self._PLL_ON_tool_bar.addWidget(self._PLL_ON_combo_box)
        for _label in self._PLL_ON_labels: self._PLL_ON_combo_box.addItem(_label)
        self._PLL_ON_callback = lambda i: Qt.QMetaObject.invokeMethod(self._PLL_ON_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._PLL_ON_options.index(i)))
        self._PLL_ON_callback(self.PLL_ON)
        self._PLL_ON_combo_box.currentIndexChanged.connect(
            lambda i: self.set_PLL_ON(self._PLL_ON_options[i]))
        # Create the radio buttons
        self.top_grid_layout.addWidget(self._PLL_ON_tool_bar, 13, 1, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f(
            4096, #size
            samp_rate*1000, #samp_rate
            "Cross Correlation", #name
            1 #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0.set_y_axis(-2, 2)

        self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_0_0.enable_tags(True)
        self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0_0.enable_grid(True)
        self.qtgui_time_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0.enable_control_panel(True)
        self.qtgui_time_sink_x_0_0.enable_stem_plot(False)


        labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
        widths = [1, 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]
        styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]


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

        self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_time_sink_x_0_0_win, 5, 0, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            4096, #size
            firdes.WIN_BLACKMAN_hARRIS, #wintype
            0, #fc
            samp_rate*1e3, #bw
            "", #name
            1
        )
        self.qtgui_freq_sink_x_0.set_update_time(1/fps)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(True)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(True)



        labels = ['In-Phase', 'Quadrature', '', '', '',
            '', '', '', '', '']
        widths = [1, 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_1.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_1.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0.set_processor_affinity([0])
        self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1))
        self.interp_fir_filter_xxx_1_0.declare_sample_delay(0)
        self.iir_filter_xxx_0 = filter.iir_filter_ccz([(1)], iir_taps, True)
        self.iio_pluto_source_0 = iio.pluto_source(epy_module_0.RX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True)
        self.iio_pluto_sink_0 = iio.pluto_sink(epy_module_0.TX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True)
        self._echo_gain_iir_range = Range(0, 1, 0.01, 0, 200)
        self._echo_gain_iir_win = RangeWidget(self._echo_gain_iir_range, self.set_echo_gain_iir, 'Equalizer Gain (A)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._echo_gain_iir_win, 14, 0, 1, 1)
        for r in range(14, 15):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.digital_glfsr_source_x_0 = digital.glfsr_source_b(6, True, 0, 1)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(3.14/100, 2, False)
        self.digital_corr_est_cc_0 = digital.corr_est_cc(pn6_up, sps, 0, 0.7, digital.THRESHOLD_ABSOLUTE)
        self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const_bpsk.points(), 1)
        self._delay_iir_range = Range(1, delay_limit, 1, 1, 200)
        self._delay_iir_win = RangeWidget(self._delay_iir_range, self.set_delay_iir, 'Equalizer Delay (samples)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._delay_iir_win, 14, 1, 1, 1)
        for r in range(14, 15):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.blocks_tag_gate_0_0_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_tag_gate_0_0_0.set_single_key("time_est")
        self.blocks_tag_gate_0_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_tag_gate_0_0.set_single_key("corr_est")
        self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_tag_gate_0.set_single_key("amp_est")
        self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,equalize_on,0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex*1,PLL_ON,0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc((1/63/sps)*np.exp(1j*pi*phase_shift))
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(echo_gain)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ )
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, delay)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate*1000, analog.GR_COS_WAVE, fo, 1, 0, 0)
        self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
        self.analog_agc_xx_0.set_max_gain(65536)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0), (self.blocks_selector_0, 1))
        self.connect((self.analog_agc_xx_0, 0), (self.digital_costas_loop_cc_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_tag_gate_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.iio_pluto_sink_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.blocks_selector_0_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.iir_filter_xxx_0, 0))
        self.connect((self.blocks_selector_0_0, 0), (self.digital_corr_est_cc_0, 0))
        self.connect((self.blocks_selector_0_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_tag_gate_0, 0), (self.blocks_tag_gate_0_0, 0))
        self.connect((self.blocks_tag_gate_0_0, 0), (self.blocks_tag_gate_0_0_0, 0))
        self.connect((self.blocks_tag_gate_0_0_0, 0), (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0))
        self.connect((self.digital_corr_est_cc_0, 1), (self.blocks_multiply_const_vxx_2, 0))
        self.connect((self.digital_corr_est_cc_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_selector_0, 0))
        self.connect((self.digital_glfsr_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0))
        self.connect((self.iio_pluto_source_0, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.iir_filter_xxx_0, 0), (self.blocks_selector_0_0, 1))
        self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_delay_0, 0))
예제 #6
0
    def __init__(self):
        gr.top_block.__init__(self, "Lab 2")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Lab 2")
        qtgui.util.check_set_qss()
        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", "lab2")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.sps = sps = 8
        self.roll_off = roll_off = 0.5
        self.freqc = freqc = 900
        self.std_dev = std_dev = 0.05
        self.samp_rate = samp_rate = 1024
        self.rrc_filter = rrc_filter = firdes.root_raised_cosine(4, sps, 1, roll_off, 32*sps+1)
        self.phase = phase = 0
        self.lw = lw = 2
        self.gain_ = gain_ = 0.5
        self.freqc_ = freqc_ = freqc
        self.fps = fps = 30
        self.const = const = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1],
        2, 1).base()
        self.bw = bw = 1
        self.buff_size = buff_size = 32768
        self.bNoise = bNoise = 0
        self.bFilter = bFilter = 0
        self.axis = axis = 2
        self.N = N = 0

        ##################################################
        # Blocks
        ##################################################
        self.tab0 = Qt.QTabWidget()
        self.tab0_widget_0 = Qt.QWidget()
        self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0)
        self.tab0_grid_layout_0 = Qt.QGridLayout()
        self.tab0_layout_0.addLayout(self.tab0_grid_layout_0)
        self.tab0.addTab(self.tab0_widget_0, 'Spectrum/Constellation')
        self.tab0_widget_1 = Qt.QWidget()
        self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1)
        self.tab0_grid_layout_1 = Qt.QGridLayout()
        self.tab0_layout_1.addLayout(self.tab0_grid_layout_1)
        self.tab0.addTab(self.tab0_widget_1, 'Eye Diagram')
        self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2)
        for r in range(0, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._std_dev_range = Range(0, 1, 0.01, 0.05, 200)
        self._std_dev_win = RangeWidget(self._std_dev_range, self.set_std_dev, 'Noise Std. Dev', "counter_slider", float)
        self.top_grid_layout.addWidget(self._std_dev_win, 11, 0, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._phase_range = Range(-180*2, 180*2, 0.1, 0, 200)
        self._phase_win = RangeWidget(self._phase_range, self.set_phase, 'Phase Offset (Degrees)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._phase_win, 11, 1, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._gain__range = Range(0.1, 1, 0.01, 0.5, 200)
        self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._freqc__range = Range(70, 6000, .01, freqc, 200)
        self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._bNoise_options = (0, 1, )
        # Create the labels list
        self._bNoise_labels = ('Noise Only', 'Signal + Noise', )
        # Create the combo box
        # Create the radio buttons
        self._bNoise_group_box = Qt.QGroupBox('Waveform Select' + ": ")
        self._bNoise_box = Qt.QHBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._bNoise_button_group = variable_chooser_button_group()
        self._bNoise_group_box.setLayout(self._bNoise_box)
        for i, _label in enumerate(self._bNoise_labels):
            radio_button = Qt.QRadioButton(_label)
            self._bNoise_box.addWidget(radio_button)
            self._bNoise_button_group.addButton(radio_button, i)
        self._bNoise_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bNoise_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bNoise_options.index(i)))
        self._bNoise_callback(self.bNoise)
        self._bNoise_button_group.buttonClicked[int].connect(
            lambda i: self.set_bNoise(self._bNoise_options[i]))
        self.top_grid_layout.addWidget(self._bNoise_group_box, 12, 1, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._bFilter_options = (0, 1, )
        # Create the labels list
        self._bFilter_labels = ('Rectangular', 'Raised Cosine', )
        # Create the combo box
        # Create the radio buttons
        self._bFilter_group_box = Qt.QGroupBox('Pulse Shaping Select' + ": ")
        self._bFilter_box = Qt.QHBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._bFilter_button_group = variable_chooser_button_group()
        self._bFilter_group_box.setLayout(self._bFilter_box)
        for i, _label in enumerate(self._bFilter_labels):
            radio_button = Qt.QRadioButton(_label)
            self._bFilter_box.addWidget(radio_button)
            self._bFilter_button_group.addButton(radio_button, i)
        self._bFilter_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bFilter_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bFilter_options.index(i)))
        self._bFilter_callback(self.bFilter)
        self._bFilter_button_group.buttonClicked[int].connect(
            lambda i: self.set_bFilter(self._bFilter_options[i]))
        self.top_grid_layout.addWidget(self._bFilter_group_box, 12, 0, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._N_range = Range(0, 7, 1, 0, 200)
        self._N_win = RangeWidget(self._N_range, self.set_N, 'Nth Sample', "counter_slider", float)
        self.top_grid_layout.addWidget(self._N_win, 13, 1, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._roll_off_range = Range(0.01, 0.99, 0.01, 0.5, 200)
        self._roll_off_win = RangeWidget(self._roll_off_range, self.set_roll_off, 'Beta (Roll-Off-Factor)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._roll_off_win, 13, 0, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            2*sps, #size
            1, #samp_rate
            "", #name
            10 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(1/fps)
        self.qtgui_time_sink_x_0.set_y_axis(-2, 2)

        self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_0.enable_tags(True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "buffer_start")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(True)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(True)
        self.qtgui_time_sink_x_0.enable_stem_plot(False)


        labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
        widths = [lw, lw, lw, lw, lw,
            lw, lw, lw, lw, lw]
        colors = ['blue', 'red', 'yellow', '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]
        styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]


        for i in range(10):
            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.tab0_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 5, 1)
        for r in range(0, 5):
            self.tab0_grid_layout_1.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_1.setColumnStretch(c, 1)
        self.qtgui_histogram_sink_x_0 = qtgui.histogram_sink_f(
            int(1e5),
            400,
            -axis,
            axis,
            "",
            1
        )

        self.qtgui_histogram_sink_x_0.set_update_time(1/fps)
        self.qtgui_histogram_sink_x_0.enable_autoscale(True)
        self.qtgui_histogram_sink_x_0.enable_accumulate(False)
        self.qtgui_histogram_sink_x_0.enable_grid(True)
        self.qtgui_histogram_sink_x_0.enable_axis_labels(True)


        labels = ['', '', '', '', '',
            '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
            "magenta", "yellow", "dark red", "dark green", "dark 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_histogram_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_histogram_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_histogram_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_histogram_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_histogram_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_histogram_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_histogram_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_histogram_sink_x_0_win = sip.wrapinstance(self.qtgui_histogram_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_histogram_sink_x_0_win, 5, 1, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(1, 2):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            1024, #size
            firdes.WIN_BLACKMAN_hARRIS, #wintype
            0, #fc
            samp_rate*1e3, #bw
            "", #name
            1
        )
        self.qtgui_freq_sink_x_0_0.set_update_time(1/fps)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0.enable_grid(True)
        self.qtgui_freq_sink_x_0_0.set_fft_average(0.05)
        self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)



        labels = ['Magnitude', '', '', '', '',
            '', '', '', '', '']
        widths = [1, 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0, 5, 1)
        for r in range(0, 5):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0_0.set_processor_affinity([0])
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f(
            1024, #size
            firdes.WIN_BLACKMAN_hARRIS, #wintype
            0, #fc
            samp_rate*1e3, #bw
            "", #name
            2
        )
        self.qtgui_freq_sink_x_0.set_update_time(1/fps)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.05)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)


        self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)

        labels = ['In-Phase', 'Quadrature', '', '', '',
            '', '', '', '', '']
        widths = [1, 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 range(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0.set_processor_affinity([0])
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            1024, #size
            "", #name
            2 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(1/fps)
        self.qtgui_const_sink_x_0.set_y_axis(-axis, axis)
        self.qtgui_const_sink_x_0.set_x_axis(-axis, axis)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(False)
        self.qtgui_const_sink_x_0.enable_grid(True)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)


        labels = ['', '', '', '', '',
            '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        colors = ["blue", "red", "red", "red", "red",
            "red", "red", "red", "red", "red"]
        styles = [0, 1, 0, 0, 0,
            0, 0, 0, 0, 0]
        markers = [0, -1, 0, 0, 0,
            0, 0, 0, 0, 0]
        alphas = [1.0, 0.5, 1.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0, 1.0]

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

        self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0, 1, 5, 1)
        for r in range(0, 5):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(1, 2):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_const_sink_x_0.set_processor_affinity([0])
        self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1))
        self.interp_fir_filter_xxx_1_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_ccc(sps, rrc_filter)
        self.interp_fir_filter_xxx_1.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(1, rrc_filter)
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.iio_pluto_source_0 = iio.pluto_source('', int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True)
        self.iio_pluto_sink_0 = iio.pluto_sink('', int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True)
        self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const.points(), 1)
        self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_tag_gate_0.set_single_key("")
        self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,bFilter,0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex*1,N,0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(np.exp(1j*2*pi*phase/360))
        self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_cc(2)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_cc(bNoise)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ )
        self.blocks_delay_0_2 = blocks.delay(gr.sizeof_float*1, -N+1024)
        self.blocks_delay_0_1 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_1 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_0_1_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_0_1 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_0_0_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, sps)
        self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_gr_complex*1, 1)
        self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_random_source_x_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 8192))), True)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, std_dev, 0)
        self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
        self.analog_agc_xx_0.set_max_gain(65536)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0), (self.blocks_deinterleave_0, 0))
        self.connect((self.analog_agc_xx_0, 0), (self.blocks_tag_gate_0, 0))
        self.connect((self.analog_agc_xx_0, 0), (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0), (self.qtgui_freq_sink_x_0, 1))
        self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_delay_0_2, 0))
        self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_complex_to_real_0_0, 0), (self.qtgui_histogram_sink_x_0, 0))
        self.connect((self.blocks_deinterleave_0, 7), (self.blocks_selector_0, 7))
        self.connect((self.blocks_deinterleave_0, 4), (self.blocks_selector_0, 4))
        self.connect((self.blocks_deinterleave_0, 3), (self.blocks_selector_0, 3))
        self.connect((self.blocks_deinterleave_0, 6), (self.blocks_selector_0, 6))
        self.connect((self.blocks_deinterleave_0, 5), (self.blocks_selector_0, 5))
        self.connect((self.blocks_deinterleave_0, 0), (self.blocks_selector_0, 0))
        self.connect((self.blocks_deinterleave_0, 1), (self.blocks_selector_0, 1))
        self.connect((self.blocks_deinterleave_0, 2), (self.blocks_selector_0, 2))
        self.connect((self.blocks_delay_0, 0), (self.blocks_delay_0_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_delay_0_0, 0), (self.blocks_delay_0_0_0, 0))
        self.connect((self.blocks_delay_0_0, 0), (self.qtgui_time_sink_x_0, 2))
        self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_delay_0_0_0_0, 0))
        self.connect((self.blocks_delay_0_0_0, 0), (self.qtgui_time_sink_x_0, 3))
        self.connect((self.blocks_delay_0_0_0_0, 0), (self.blocks_delay_0_1, 0))
        self.connect((self.blocks_delay_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 4))
        self.connect((self.blocks_delay_0_0_0_0_0, 0), (self.blocks_delay_0_0_0_1_0, 0))
        self.connect((self.blocks_delay_0_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 8))
        self.connect((self.blocks_delay_0_0_0_1, 0), (self.blocks_delay_0_0_0_0_0, 0))
        self.connect((self.blocks_delay_0_0_0_1, 0), (self.qtgui_time_sink_x_0, 7))
        self.connect((self.blocks_delay_0_0_0_1_0, 0), (self.qtgui_time_sink_x_0, 9))
        self.connect((self.blocks_delay_0_0_1, 0), (self.blocks_delay_0_0_0_1, 0))
        self.connect((self.blocks_delay_0_0_1, 0), (self.qtgui_time_sink_x_0, 6))
        self.connect((self.blocks_delay_0_1, 0), (self.blocks_delay_0_0_1, 0))
        self.connect((self.blocks_delay_0_1, 0), (self.qtgui_time_sink_x_0, 5))
        self.connect((self.blocks_delay_0_2, 0), (self.blocks_delay_0, 0))
        self.connect((self.blocks_delay_0_2, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.iio_pluto_sink_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0_0, 0), (self.blocks_selector_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.blocks_complex_to_real_0_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.qtgui_const_sink_x_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.qtgui_const_sink_x_0, 1))
        self.connect((self.blocks_selector_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_tag_gate_0, 0), (self.blocks_complex_to_imag_0, 0))
        self.connect((self.blocks_tag_gate_0, 0), (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0))
        self.connect((self.iio_pluto_source_0, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_selector_0_0, 1))
        self.connect((self.interp_fir_filter_xxx_1, 0), (self.interp_fir_filter_xxx_0, 0))
        self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_multiply_const_vxx_0_0_0, 0))
예제 #7
0
    def __init__(self):
        gr.top_block.__init__(self, "Lab 3")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Lab 3")
        qtgui.util.check_set_qss()
        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", "lab3")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.freqc = freqc = 900
        self.zeta = zeta = 0.707
        self.std_dev = std_dev = 0.01
        self.sps = sps = 8
        self.samp_rate = samp_rate = 1000
        self.nat_freq = nat_freq = 10000
        self.lw = lw = 2
        self.gain_ = gain_ = 0.5
        self.freqc_ = freqc_ = freqc
        self.fps = fps = 30
        self.fo = fo = 0
        self.const_qpsk = const_qpsk = digital.constellation_calcdist(digital.psk_4()[0], digital.psk_4()[1],
        4, 1).base()
        self.const_bpsk = const_bpsk = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1],
        2, 1).base()
        self.bw = bw = 1
        self.buff_size = buff_size = 32768
        self.bSignal = bSignal = 0
        self.bSelectPLL = bSelectPLL = 0
        self.axis = axis = 2

        ##################################################
        # Blocks
        ##################################################
        self._zeta_range = Range(0, 4, 0.001, 0.707, 200)
        self._zeta_win = RangeWidget(self._zeta_range, self.set_zeta, 'Damping Factor (Zeta)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._zeta_win, 13, 0, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.tab0 = Qt.QTabWidget()
        self.tab0_widget_0 = Qt.QWidget()
        self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0)
        self.tab0_grid_layout_0 = Qt.QGridLayout()
        self.tab0_layout_0.addLayout(self.tab0_grid_layout_0)
        self.tab0.addTab(self.tab0_widget_0, 'Loop Filter Output')
        self.tab0_widget_1 = Qt.QWidget()
        self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1)
        self.tab0_grid_layout_1 = Qt.QGridLayout()
        self.tab0_layout_1.addLayout(self.tab0_grid_layout_1)
        self.tab0.addTab(self.tab0_widget_1, 'Spectrum')
        self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2)
        for r in range(0, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._std_dev_range = Range(0, 0.1, 0.001, 0.01, 200)
        self._std_dev_win = RangeWidget(self._std_dev_range, self.set_std_dev, 'Noise Std. Dev', "counter_slider", float)
        self.top_grid_layout.addWidget(self._std_dev_win, 11, 0, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._nat_freq_range = Range(0, 100e3, 1, 10000, 200)
        self._nat_freq_win = RangeWidget(self._nat_freq_range, self.set_nat_freq, 'Natural Freq (Hz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._nat_freq_win, 13, 1, 1, 1)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._gain__range = Range(0.1, 1, 0.01, 0.5, 200)
        self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._freqc__range = Range(70, 6000, .01, freqc, 200)
        self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1)
        for r in range(10, 11):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._fo_range = Range(0, 100e3, 100, 0, 200)
        self._fo_win = RangeWidget(self._fo_range, self.set_fo, 'Frequency Offset (Hz)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._fo_win, 11, 1, 1, 1)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._bSignal_options = (0, 1, 2, )
        # Create the labels list
        self._bSignal_labels = ('Tone', 'BPSK', 'QPSK', )
        # Create the combo box
        # Create the radio buttons
        self._bSignal_group_box = Qt.QGroupBox('Signal Select' + ": ")
        self._bSignal_box = Qt.QHBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._bSignal_button_group = variable_chooser_button_group()
        self._bSignal_group_box.setLayout(self._bSignal_box)
        for i, _label in enumerate(self._bSignal_labels):
            radio_button = Qt.QRadioButton(_label)
            self._bSignal_box.addWidget(radio_button)
            self._bSignal_button_group.addButton(radio_button, i)
        self._bSignal_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bSignal_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bSignal_options.index(i)))
        self._bSignal_callback(self.bSignal)
        self._bSignal_button_group.buttonClicked[int].connect(
            lambda i: self.set_bSignal(self._bSignal_options[i]))
        self.top_grid_layout.addWidget(self._bSignal_group_box, 12, 0, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        # Create the options list
        self._bSelectPLL_options = (0, 1, 2, 3, )
        # Create the labels list
        self._bSelectPLL_labels = ('Standard', 'Costas', 'Costas w/ HL', 'QPSK Costas', )
        # Create the combo box
        # Create the radio buttons
        self._bSelectPLL_group_box = Qt.QGroupBox('PLL Order' + ": ")
        self._bSelectPLL_box = Qt.QHBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._bSelectPLL_button_group = variable_chooser_button_group()
        self._bSelectPLL_group_box.setLayout(self._bSelectPLL_box)
        for i, _label in enumerate(self._bSelectPLL_labels):
            radio_button = Qt.QRadioButton(_label)
            self._bSelectPLL_box.addWidget(radio_button)
            self._bSelectPLL_button_group.addButton(radio_button, i)
        self._bSelectPLL_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bSelectPLL_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bSelectPLL_options.index(i)))
        self._bSelectPLL_callback(self.bSelectPLL)
        self._bSelectPLL_button_group.buttonClicked[int].connect(
            lambda i: self.set_bSelectPLL(self._bSelectPLL_options[i]))
        self.top_grid_layout.addWidget(self._bSelectPLL_group_box, 12, 1, 1, 1)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.wes_costas_cc_0 = wes.costas_cc(nat_freq / (samp_rate*1000), zeta, bSelectPLL)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_c(
            4096, #size
            samp_rate*1000, #samp_rate
            "", #name
            1 #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0.set_y_axis(-10000, 10000)

        self.qtgui_time_sink_x_0_0.set_y_label('Frequency (Hz)', "")

        self.qtgui_time_sink_x_0_0.enable_tags(True)
        self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0_0.enable_grid(True)
        self.qtgui_time_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0.enable_control_panel(True)
        self.qtgui_time_sink_x_0_0.enable_stem_plot(False)


        labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
        widths = [1, 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]
        styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]


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

        self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_0.addWidget(self._qtgui_time_sink_x_0_0_win, 5, 0, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_0.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_0.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024, #size
            firdes.WIN_BLACKMAN_hARRIS, #wintype
            0, #fc
            samp_rate*1e3, #bw
            "", #name
            1
        )
        self.qtgui_freq_sink_x_0.set_update_time(1/fps)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(True)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)



        labels = ['In-Phase', 'Quadrature', '', '', '',
            '', '', '', '', '']
        widths = [1, 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.tab0_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1)
        for r in range(5, 10):
            self.tab0_grid_layout_1.setRowStretch(r, 1)
        for c in range(0, 1):
            self.tab0_grid_layout_1.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0.set_processor_affinity([0])
        self.interp_fir_filter_xxx_1_0_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1))
        self.interp_fir_filter_xxx_1_0_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1))
        self.interp_fir_filter_xxx_1_0.declare_sample_delay(0)
        self.iio_pluto_source_0 = iio.pluto_source(epy_module_0.RX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True)
        self.iio_pluto_sink_0 = iio.pluto_sink(epy_module_0.TX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True)
        self.digital_chunks_to_symbols_xx_1_0 = digital.chunks_to_symbols_bc(const_qpsk.points(), 1)
        self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const_bpsk.points(), 1)
        self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_tag_gate_0.set_single_key("")
        self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,bSignal,0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc(1/6.28*samp_rate*1000)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(0)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ )
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_cc(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate*1000, analog.GR_COS_WAVE, fo, 1, 0, 0)
        self.analog_random_source_x_0_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 4, 8192))), True)
        self.analog_random_source_x_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 8192))), True)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, std_dev, 0)
        self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
        self.analog_agc_xx_0.set_max_gain(65536)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.analog_agc_xx_0, 0), (self.wes_costas_cc_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0))
        self.connect((self.analog_random_source_x_0_0, 0), (self.digital_chunks_to_symbols_xx_1_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_selector_0_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_2, 0), (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.iio_pluto_sink_0, 0))
        self.connect((self.blocks_selector_0_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_tag_gate_0, 0), (self.blocks_multiply_const_vxx_2, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1_0, 0), (self.interp_fir_filter_xxx_1_0_0, 0))
        self.connect((self.iio_pluto_source_0, 0), (self.analog_agc_xx_0, 0))
        self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_selector_0_0, 1))
        self.connect((self.interp_fir_filter_xxx_1_0_0, 0), (self.blocks_selector_0_0, 2))
        self.connect((self.wes_costas_cc_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.wes_costas_cc_0, 1), (self.blocks_tag_gate_0, 0))
예제 #8
0
    def __init__(self):
        gr.top_block.__init__(self, "QO-100 ssb and CW resever")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("QO-100 ssb and CW resever")
        qtgui.util.check_set_qss()
        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", "qo_100_ssb_cw_rx")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.variable_slider_1 = variable_slider_1 = 0.01
        self.variable_slider_0 = variable_slider_0 = 11.5e3
        self.variable_chooser_0 = variable_chooser_0 = 0
        self.samp_rate = samp_rate = 1.2e6

        ##################################################
        # Blocks
        ##################################################
        self._variable_slider_1_range = Range(0, 1, 0.1, 0.01, 200)
        self._variable_slider_1_win = RangeWidget(
            self._variable_slider_1_range, self.set_variable_slider_1,
            'Audio gain', "counter_slider", float)
        self.top_grid_layout.addWidget(self._variable_slider_1_win)
        self._variable_slider_0_range = Range(-24e3, 24e3, 1, 11.5e3, 200)
        self._variable_slider_0_win = RangeWidget(
            self._variable_slider_0_range, self.set_variable_slider_0,
            'Frequency', "counter_slider", float)
        self.top_grid_layout.addWidget(self._variable_slider_0_win)
        # Create the options list
        self._variable_chooser_0_options = (
            0,
            1,
            2,
            3,
        )
        # Create the labels list
        self._variable_chooser_0_labels = (
            '900',
            '500',
            '200',
            'SSB (2.7khz)',
        )
        # Create the combo box
        # Create the radio buttons
        self._variable_chooser_0_group_box = Qt.QGroupBox('Filter - CW' + ": ")
        self._variable_chooser_0_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._variable_chooser_0_button_group = variable_chooser_button_group()
        self._variable_chooser_0_group_box.setLayout(
            self._variable_chooser_0_box)
        for i, _label in enumerate(self._variable_chooser_0_labels):
            radio_button = Qt.QRadioButton(_label)
            self._variable_chooser_0_box.addWidget(radio_button)
            self._variable_chooser_0_button_group.addButton(radio_button, i)
        self._variable_chooser_0_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._variable_chooser_0_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._variable_chooser_0_options.index(i)))
        self._variable_chooser_0_callback(self.variable_chooser_0)
        self._variable_chooser_0_button_group.buttonClicked[int].connect(
            lambda i: self.set_variable_chooser_0(
                self._variable_chooser_0_options[i]))
        self.top_grid_layout.addWidget(self._variable_chooser_0_group_box)
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
            interpolation=1, decimation=8, taps=None, fractional_bw=None)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "",  #name
            1  #number of inputs
        )
        self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
        self.qtgui_waterfall_sink_x_0.enable_grid(False)
        self.qtgui_waterfall_sink_x_0.enable_axis_labels(True)

        labels = ['', '', '', '', '', '', '', '', '', '']
        colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in range(1):
            if len(labels[i]) == 0:
                self.qtgui_waterfall_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i])
            self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i])

        self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10)

        self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(
            self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win)
        self.qtgui_sink_x_0 = qtgui.sink_f(
            1024,  #fftsize
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            48000,  #bw
            "",  #name
            True,  #plotfreq
            True,  #plotwaterfall
            True,  #plottime
            True  #plotconst
        )
        self.qtgui_sink_x_0.set_update_time(1.0 / 10)
        self._qtgui_sink_x_0_win = sip.wrapinstance(
            self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget)

        self.qtgui_sink_x_0.enable_rf_freq(False)

        self.top_grid_layout.addWidget(self._qtgui_sink_x_0_win)
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               'rtl=0')
        self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(145.825e6, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_gain(10, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(
            25, firdes.low_pass(1, 48000, 500, 50), variable_slider_0, 1.2e6)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_float * 1,
                                                 variable_chooser_0, 0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_multiply_xx_1 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(
            variable_slider_1)
        self.blocks_complex_to_float_1 = blocks.complex_to_float(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.band_pass_filter_2_0 = filter.fir_filter_fff(
            1,
            firdes.band_pass(1, 48000, 100, 2700, 50, firdes.WIN_HAMMING,
                             6.76))
        self.band_pass_filter_2 = filter.fir_filter_fff(
            1,
            firdes.band_pass(1, 48000, 600, 800, 50, firdes.WIN_HAMMING, 6.76))
        self.band_pass_filter_1 = filter.fir_filter_fff(
            1,
            firdes.band_pass(1, 48000, 450, 950, 100, firdes.WIN_HAMMING,
                             6.76))
        self.band_pass_filter_0 = filter.fir_filter_fff(
            1,
            firdes.band_pass(1, 48000, 300, 1100, 100, firdes.WIN_HAMMING,
                             6.76))
        self.audio_sink_0 = audio.sink(48000, '', True)
        self.analog_sig_source_x_1 = analog.sig_source_f(
            48000, analog.GR_COS_WAVE, 700, 1, 0, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(
            48000, analog.GR_SIN_WAVE, 700, 1, 0, 0)
        self.analog_agc2_xx_0 = analog.agc2_ff(1e-3, 1e-2, 1.0, 1.0)
        self.analog_agc2_xx_0.set_max_gain(65536)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc2_xx_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_multiply_xx_1, 1))
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.band_pass_filter_0, 0), (self.blocks_selector_0, 0))
        self.connect((self.band_pass_filter_1, 0), (self.blocks_selector_0, 1))
        self.connect((self.band_pass_filter_2, 0), (self.blocks_selector_0, 2))
        self.connect((self.band_pass_filter_2_0, 0),
                     (self.blocks_selector_0, 3))
        self.connect((self.blocks_add_xx_0, 0), (self.band_pass_filter_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.band_pass_filter_1, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.band_pass_filter_2, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.band_pass_filter_2_0, 0))
        self.connect((self.blocks_complex_to_float_1, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_complex_to_float_1, 1),
                     (self.blocks_multiply_xx_1, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.audio_sink_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_selector_0, 0), (self.analog_agc2_xx_0, 0))
        self.connect((self.blocks_selector_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.blocks_complex_to_float_1, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.qtgui_sink_x_0, 0))
예제 #9
0
    def __init__(self,
                 bFilter=1,
                 rect_taps=(1, 1, 1, 1, 1, 1, 1, 1),
                 roll_off=0.7,
                 sps=4):
        gr.hier_block2.__init__(
            self,
            "Pulse Shaping Block (Hier)",
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.bFilter = bFilter
        self.rect_taps = rect_taps
        self.roll_off = roll_off
        self.sps = sps

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
        self.rrc_filter = rrc_filter = firdes.root_raised_cosine(
            4, sps, 1, roll_off, 32 * sps + 1)

        ##################################################
        # Blocks
        ##################################################
        self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(
            sps, rect_taps)
        self.interp_fir_filter_xxx_1_0.declare_sample_delay(0)
        self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_ccc(
            sps, rrc_filter)
        self.interp_fir_filter_xxx_1.declare_sample_delay(0)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(
            1, rrc_filter)
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                   bFilter, 0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_cc(2)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(0.5)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0_0, 0),
                     (self.blocks_selector_0_0, 0))
        self.connect((self.blocks_selector_0_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.interp_fir_filter_xxx_0, 0),
                     (self.blocks_selector_0_0, 1))
        self.connect((self.interp_fir_filter_xxx_1, 0),
                     (self.blocks_selector_0_0, 2))
        self.connect((self.interp_fir_filter_xxx_1, 0),
                     (self.interp_fir_filter_xxx_0, 0))
        self.connect((self.interp_fir_filter_xxx_1_0, 0),
                     (self.blocks_multiply_const_vxx_0_0_0, 0))
        self.connect((self, 0), (self.interp_fir_filter_xxx_1, 0))
        self.connect((self, 0), (self.interp_fir_filter_xxx_1_0, 0))
    def __init__(self):
        gr.top_block.__init__(self, "10Ghz 2de Garmonic with hackrf")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("10Ghz 2de Garmonic with hackrf")
        qtgui.util.check_set_qss()
        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",
                                     "The_10G_second_harmonic_hackrf")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.variable_qtgui_range_0_1 = variable_qtgui_range_0_1 = 10352560000
        self.variable_qtgui_range_0_0_0_0 = variable_qtgui_range_0_0_0_0 = 50
        self.variable_qtgui_range_0_0_0 = variable_qtgui_range_0_0_0 = 60
        self.variable_qtgui_range_0_0 = variable_qtgui_range_0_0 = 60
        self.variable_qtgui_range_0 = variable_qtgui_range_0 = 2.5e3
        self.variable_qtgui_label_0 = variable_qtgui_label_0 = variable_qtgui_range_0_1 / 2
        self.variable_qtgui_chooser_PTT_0 = variable_qtgui_chooser_PTT_0 = 0
        self.samp_rate = samp_rate = 4800000

        ##################################################
        # Blocks
        ##################################################
        self._variable_qtgui_range_0_1_range = Range(10338000000, 10702000000,
                                                     1, 10352560000, 200)
        self._variable_qtgui_range_0_1_win = RangeWidget(
            self._variable_qtgui_range_0_1_range,
            self.set_variable_qtgui_range_0_1, 'Frequency', "counter_slider",
            float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_1_win)
        self._variable_qtgui_range_0_0_0_0_range = Range(5, 60, 1, 50, 200)
        self._variable_qtgui_range_0_0_0_0_win = RangeWidget(
            self._variable_qtgui_range_0_0_0_0_range,
            self.set_variable_qtgui_range_0_0_0_0, 'bb_power',
            "counter_slider", float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_0_0_win)
        self._variable_qtgui_range_0_0_0_range = Range(5, 60, 1, 60, 200)
        self._variable_qtgui_range_0_0_0_win = RangeWidget(
            self._variable_qtgui_range_0_0_0_range,
            self.set_variable_qtgui_range_0_0_0, 'if_power', "counter_slider",
            float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_0_win)
        self._variable_qtgui_range_0_0_range = Range(10, 65, 1, 60, 200)
        self._variable_qtgui_range_0_0_win = RangeWidget(
            self._variable_qtgui_range_0_0_range,
            self.set_variable_qtgui_range_0_0, 'tx_power', "counter_slider",
            float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_win)
        self._variable_qtgui_range_0_range = Range(0, 12.5e3, 1, 2.5e3, 200)
        self._variable_qtgui_range_0_win = RangeWidget(
            self._variable_qtgui_range_0_range,
            self.set_variable_qtgui_range_0, 'div', "counter_slider", float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_win)
        # Create the options list
        self._variable_qtgui_chooser_PTT_0_options = (
            0,
            1,
        )
        # Create the labels list
        self._variable_qtgui_chooser_PTT_0_labels = (
            'TX',
            'RX',
        )
        # Create the combo box
        self._variable_qtgui_chooser_PTT_0_tool_bar = Qt.QToolBar(self)
        self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget(
            Qt.QLabel('PTT' + ": "))
        self._variable_qtgui_chooser_PTT_0_combo_box = Qt.QComboBox()
        self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget(
            self._variable_qtgui_chooser_PTT_0_combo_box)
        for _label in self._variable_qtgui_chooser_PTT_0_labels:
            self._variable_qtgui_chooser_PTT_0_combo_box.addItem(_label)
        self._variable_qtgui_chooser_PTT_0_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._variable_qtgui_chooser_PTT_0_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._variable_qtgui_chooser_PTT_0_options.index(i)
                     ))
        self._variable_qtgui_chooser_PTT_0_callback(
            self.variable_qtgui_chooser_PTT_0)
        self._variable_qtgui_chooser_PTT_0_combo_box.currentIndexChanged.connect(
            lambda i: self.set_variable_qtgui_chooser_PTT_0(
                self._variable_qtgui_chooser_PTT_0_options[i]))
        # Create the radio buttons
        self.top_grid_layout.addWidget(
            self._variable_qtgui_chooser_PTT_0_tool_bar)
        self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self)

        if None:
            self._variable_qtgui_label_0_formatter = None
        else:
            self._variable_qtgui_label_0_formatter = lambda x: eng_notation.num_to_str(
                x)

        self._variable_qtgui_label_0_tool_bar.addWidget(
            Qt.QLabel('freq' + ": "))
        self._variable_qtgui_label_0_label = Qt.QLabel(
            str(
                self._variable_qtgui_label_0_formatter(
                    self.variable_qtgui_label_0)))
        self._variable_qtgui_label_0_tool_bar.addWidget(
            self._variable_qtgui_label_0_label)
        self.top_grid_layout.addWidget(self._variable_qtgui_label_0_tool_bar)
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
            interpolation=10, decimation=1, taps=None, fractional_bw=None)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "",  #name
            1)
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0,
                                                  "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " +
                                           'hackrf=0')
        self.osmosdr_sink_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.osmosdr_sink_0.set_sample_rate(samp_rate)
        self.osmosdr_sink_0.set_center_freq(variable_qtgui_range_0_1 / 2, 0)
        self.osmosdr_sink_0.set_freq_corr(0, 0)
        self.osmosdr_sink_0.set_gain(variable_qtgui_range_0_0, 0)
        self.osmosdr_sink_0.set_if_gain(variable_qtgui_range_0_0_0, 0)
        self.osmosdr_sink_0.set_bb_gain(variable_qtgui_range_0_0_0_0, 0)
        self.osmosdr_sink_0.set_antenna('', 0)
        self.osmosdr_sink_0.set_bandwidth(0, 0)
        self.blocks_wavfile_source_0 = blocks.wavfile_source(
            '/home/anton/gnuradio-grc-examples/test_audio.wav', True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, 48000,
                                                 True)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                 variable_qtgui_chooser_PTT_0,
                                                 0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(1)
        self.analog_nbfm_tx_0_0 = analog.nbfm_tx(
            audio_rate=48000,
            quad_rate=480000,
            tau=75e-6,
            max_dev=variable_qtgui_range_0,
            fh=-1.0,
        )
        self.analog_const_source_x_0_0 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0_0, 0),
                     (self.blocks_selector_0, 1))
        self.connect((self.analog_nbfm_tx_0_0, 0), (self.blocks_selector_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_selector_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.analog_nbfm_tx_0_0, 0))
        self.connect((self.blocks_wavfile_source_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.osmosdr_sink_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
예제 #11
0
    def __init__(self, num_bins=256, num_integrations=100000):
        gr.top_block.__init__(self, "radio_process")

        ##################################################
        # Parameters
        ##################################################
        self.num_bins = num_bins
        self.num_integrations = num_integrations

        ##################################################
        # Variables
        ##################################################
        self.sinc_sample_locations = sinc_sample_locations = np.arange(
            -np.pi * 4 / 2.0, np.pi * 4 / 2.0, np.pi / num_bins)
        self.sinc_samples = sinc_samples = np.sinc(sinc_sample_locations /
                                                   np.pi)
        self.vslr = vslr = np.nan
        self.tsys = tsys = 171
        self.tcal = tcal = 290
        self.soutrack = soutrack = "at_stow"
        self.samp_rate = samp_rate = 2400000
        self.motor_el = motor_el = np.nan
        self.motor_az = motor_az = np.nan
        self.is_running = is_running = False
        self.glon = glon = np.nan
        self.glat = glat = np.nan
        self.freq = freq = 1420000000
        self.fft_window = fft_window = window.blackmanharris(num_bins)
        self.custom_window = custom_window = sinc_samples * np.hamming(
            4 * num_bins)
        self.cal_values = cal_values = np.repeat(np.nan, num_bins)
        self.cal_pwr = cal_pwr = 1
        self.beam_switch = beam_switch = 0

        ##################################################
        # Blocks
        ##################################################
        self.zeromq_pub_sink_2_0 = zeromq.pub_sink(gr.sizeof_float, num_bins,
                                                   'tcp://127.0.0.1:5561', 100,
                                                   False, -1)
        self.zeromq_pub_sink_2 = zeromq.pub_sink(gr.sizeof_float, num_bins,
                                                 'tcp://127.0.0.1:5560', 100,
                                                 True, -1)
        self.zeromq_pub_sink_1_0 = zeromq.pub_sink(gr.sizeof_float, num_bins,
                                                   'tcp://127.0.0.1:5562', 100,
                                                   True, -1)
        self.zeromq_pub_sink_1 = zeromq.pub_sink(gr.sizeof_float, num_bins,
                                                 'tcp://127.0.0.1:5563', 100,
                                                 False, -1)
        self.zeromq_pub_sink_0_0 = zeromq.pub_sink(gr.sizeof_gr_complex, 1,
                                                   'tcp://127.0.0.1:5559', 100,
                                                   False, -1)
        self.zeromq_pub_sink_0 = zeromq.pub_sink(gr.sizeof_gr_complex, 1,
                                                 'tcp://127.0.0.1:5558', 100,
                                                 True, -1)
        self.xmlrpc_server_0 = xmlrpc.server.SimpleXMLRPCServer(
            ('localhost', 5557), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        self.xmlrpc_server_0_thread = threading.Thread(
            target=self.xmlrpc_server_0.serve_forever)
        self.xmlrpc_server_0_thread.daemon = True
        self.xmlrpc_server_0_thread.start()
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               "soapy=0")
        self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_gain(49.6, 0)
        self.osmosdr_source_0.set_if_gain(0, 0)
        self.osmosdr_source_0.set_bb_gain(0, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
        self.fft_vxx_0 = fft.fft_vcc(num_bins, True, fft_window, True, 3)
        self.dc_blocker_xx_0 = filter.dc_blocker_cc(
            num_bins * num_integrations, False)
        self.blocks_tags_strobe_0_0 = blocks.tags_strobe(
            gr.sizeof_gr_complex * 1,
            pmt.to_pmt({
                "num_bins": num_bins,
                "samp_rate": samp_rate,
                "num_integrations": num_integrations,
                "motor_az": motor_az,
                "motor_el": motor_el,
                "freq": freq,
                "tsys": tsys,
                "tcal": tcal,
                "cal_pwr": cal_pwr,
                "vslr": vslr,
                "glat": glat,
                "glon": glon,
                "soutrack": soutrack,
                "bsw": beam_switch
            }), min(num_bins * 64, num_bins * num_integrations),
            pmt.intern("metadata"))
        self.blocks_tags_strobe_0 = blocks.tags_strobe(
            gr.sizeof_gr_complex * 1, pmt.to_pmt(float(freq)),
            min(num_bins * 64, num_bins * num_integrations),
            pmt.intern("rx_freq"))
        self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, num_bins)
        self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, num_bins)
        self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, num_bins)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, num_bins)
        self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex * 1,
                                                 num_bins * num_integrations)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1, 0,
                                                 0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_multiply_const_xx_0 = blocks.multiply_const_ff(
            1.0 / float(num_integrations), num_bins)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff([
            (tsys + tcal) / (value * cal_pwr) for value in cal_values
        ])
        self.blocks_multiply_const_vxx_0_0_0_0 = blocks.multiply_const_vcc(
            custom_window[0:num_bins])
        self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_vcc(
            custom_window[num_bins:2 * num_bins])
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc(
            custom_window[2 * num_bins:3 * num_bins])
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(
            custom_window[-num_bins:])
        self.blocks_message_strobe_0 = blocks.message_strobe(
            pmt.to_pmt(is_running), 100)
        self.blocks_integrate_xx_0 = blocks.integrate_ff(
            num_integrations, num_bins)
        self.blocks_delay_0_1 = blocks.delay(gr.sizeof_gr_complex * 1,
                                             num_bins)
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                             num_bins * 2)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           num_bins * 3)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(
            num_bins)
        self.blocks_add_xx_0_0 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(num_bins)
        self.add_clock_tags = add_clock_tags.clk(nsamps=num_bins * 8)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'),
                         (self.blocks_selector_0, 'en'))
        self.connect((self.add_clock_tags, 0), (self.blocks_add_xx_0_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_selector_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.blocks_integrate_xx_0, 0))
        self.connect((self.blocks_delay_0, 0),
                     (self.blocks_stream_to_vector_0_2, 0))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.blocks_stream_to_vector_0_0, 0))
        self.connect((self.blocks_delay_0_1, 0),
                     (self.blocks_stream_to_vector_0_1, 0))
        self.connect((self.blocks_integrate_xx_0, 0),
                     (self.blocks_multiply_const_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0_0_0, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.blocks_multiply_const_vxx_0_0_0_0, 0),
                     (self.blocks_add_xx_0, 3))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.zeromq_pub_sink_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.zeromq_pub_sink_1_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0),
                     (self.zeromq_pub_sink_2, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0),
                     (self.zeromq_pub_sink_2_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.dc_blocker_xx_0, 0))
        self.connect((self.blocks_selector_0, 0), (self.zeromq_pub_sink_0, 0))
        self.connect((self.blocks_selector_0, 0),
                     (self.zeromq_pub_sink_0_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.blocks_delay_0_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.blocks_delay_0_1, 0))
        self.connect((self.blocks_skiphead_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_stream_to_vector_0_0, 0),
                     (self.blocks_multiply_const_vxx_0_0_0, 0))
        self.connect((self.blocks_stream_to_vector_0_1, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_stream_to_vector_0_2, 0),
                     (self.blocks_multiply_const_vxx_0_0_0_0, 0))
        self.connect((self.blocks_tags_strobe_0, 0),
                     (self.blocks_add_xx_0_0, 0))
        self.connect((self.blocks_tags_strobe_0_0, 0),
                     (self.blocks_add_xx_0_0, 2))
        self.connect((self.dc_blocker_xx_0, 0), (self.blocks_skiphead_0, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.add_clock_tags, 0))
예제 #12
0
    def __init__(self,
                 samp_rate=1000000,
                 center_freq=2400000000,
                 gain=40,
                 sources=4,
                 addresses="addr0=192.168.10.2, addr1=192.168.20.3",
                 antenna="RX2",
                 num_samps=100000):

        clk_time_src = 'external'
        subdevs = 'A:0 B:0'
        antenna_list = ["RX2", "TX/RX"]
        self.usrp_sources = sources
        if antenna == "Toggle":
            self.toggle = True
            self.antenna = antenna_list[0]
            self.output_sources = sources * 2
        else:
            self.toggle = False
            self.antenna = antenna
            self.output_sources = sources

        gr.hier_block2.__init__(
            self,
            "TwoRx USRP",
            gr.io_signature(0, 0, 0),
            gr.io_signaturev(self.output_sources, self.output_sources,
                             gen_sig_io(self.output_sources)),
        )

        ##################################################
        # Parameters
        ##################################################
        self.samp_rate = samp_rate
        self.center_freq = center_freq
        self.gain = gain
        self.addresses = addresses
        self.num_samps = num_samps

        self.msg_port = "command"

        ##################################################
        # Blocks
        ##################################################
        issue_stream_cmd_on_start = not self.toggle
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join((self.addresses, "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(self.usrp_sources),
            ),
            issue_stream_cmd_on_start=issue_stream_cmd_on_start,
        )
        if self.toggle:
            msgs = list()
            for ant in antenna_list:
                msg = pmt.make_dict()
                msg = pmt.dict_add(msg, pmt.intern("antenna"), pmt.intern(ant))
                msgs.append(msg)
            periods = [0.5, 0.5]
            self.gen_msgs = msg_strobe(
                msgs=msgs,
                periods=periods,
                add_time=True,
                get_time=self.uhd_usrp_source_0.get_time_now,
                extra_cmd=self.stream_samps)
            self.selectors = list()
            for _ in range(self.usrp_sources):
                self.selectors.append(
                    blocks.selector(gr.sizeof_gr_complex, 0, 0))

        self.uhd_usrp_source_0.set_clock_source(clk_time_src, 0)
        self.uhd_usrp_source_0.set_time_source(clk_time_src, 0)
        if self.usrp_sources == 4:
            self.uhd_usrp_source_0.set_clock_source(clk_time_src, 1)
            self.uhd_usrp_source_0.set_time_source(clk_time_src, 1)
        time.sleep(1)  # Let clocks settle
        self.uhd_usrp_source_0.set_time_unknown_pps(uhd.time_spec())
        time.sleep(1)  # Let clocks settle
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_subdev_spec(subdevs, 0)
        if self.usrp_sources == 4:
            self.uhd_usrp_source_0.set_subdev_spec(subdevs, 1)
        self.uhd_usrp_source_0.set_antenna(self.antenna, 0)
        self.uhd_usrp_source_0.set_antenna(self.antenna, 1)
        if self.usrp_sources == 4:
            self.uhd_usrp_source_0.set_antenna(self.antenna, 2)
            self.uhd_usrp_source_0.set_antenna(self.antenna, 3)

        # Set channel specific settings
        self.uhd_usrp_source_0.set_gain(gain, 0)
        self.uhd_usrp_source_0.set_auto_dc_offset(True, 0)
        self.uhd_usrp_source_0.set_gain(gain, 1)
        self.uhd_usrp_source_0.set_auto_dc_offset(True, 1)
        if self.usrp_sources == 4:
            self.uhd_usrp_source_0.set_gain(gain, 2)
            self.uhd_usrp_source_0.set_auto_dc_offset(True, 2)
            self.uhd_usrp_source_0.set_gain(gain, 3)
            self.uhd_usrp_source_0.set_auto_dc_offset(True, 3)

        # Use timed commands to set frequencies
        self.set_center_freq(center_freq)

        ##################################################
        # Connections
        ##################################################
        if self.toggle:
            for source in range(self.usrp_sources):
                self.connect((self.uhd_usrp_source_0, source),
                             (self.selectors[source], 0))
                self.selectors[source].set_enabled(True)
                self.connect((self.selectors[source], 0), (self, source))
                self.connect((self.selectors[source], 1),
                             (self, self.usrp_sources + source))
            self.msg_connect((self.gen_msgs, 'command'),
                             (self.uhd_usrp_source_0, 'command'))
        else:
            for source in range(self.usrp_sources):
                self.connect((self.uhd_usrp_source_0, source), (self, source))
예제 #13
0
    def __init__(self):
        gr.top_block.__init__(self, "SSB Transmitter")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("SSB Transmitter")
        qtgui.util.check_set_qss()
        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", "SSB_transmitter")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.variable_qtgui_range_RF_out_gain = variable_qtgui_range_RF_out_gain = 10
        self.variable_qtgui_range_Cut_off_freq = variable_qtgui_range_Cut_off_freq = 16000
        self.variable_qtgui_range_Audio_in = variable_qtgui_range_Audio_in = 0.1
        self.variable_qtgui_range_0_1_0 = variable_qtgui_range_0_1_0 = 10352560000
        self.variable_qtgui_range_0_1 = variable_qtgui_range_0_1 = 145500000
        self.variable_qtgui_push_button_CW = variable_qtgui_push_button_CW = 0
        self.variable_qtgui_chooser_PTT_0 = variable_qtgui_chooser_PTT_0 = 0
        self.variable_qtgui_chooser_PTT = variable_qtgui_chooser_PTT = 0
        self.samp_rate_Baseband_Hackrf = samp_rate_Baseband_Hackrf = 2112000
        self.samp_rate_Baseband = samp_rate_Baseband = 192e3
        self.samp_rate_Audio = samp_rate_Audio = 48000

        ##################################################
        # Blocks
        ##################################################
        self._variable_qtgui_range_RF_out_gain_range = Range(
            0, 15000, 1, 10, 200)
        self._variable_qtgui_range_RF_out_gain_win = RangeWidget(
            self._variable_qtgui_range_RF_out_gain_range,
            self.set_variable_qtgui_range_RF_out_gain, 'RF Out Gain',
            "counter_slider", float)
        self.top_grid_layout.addWidget(
            self._variable_qtgui_range_RF_out_gain_win)
        self._variable_qtgui_range_Cut_off_freq_range = Range(
            0, 50000, 1, 16000, 200)
        self._variable_qtgui_range_Cut_off_freq_win = RangeWidget(
            self._variable_qtgui_range_Cut_off_freq_range,
            self.set_variable_qtgui_range_Cut_off_freq, 'Cut off Freq',
            "counter_slider", float)
        self.top_grid_layout.addWidget(
            self._variable_qtgui_range_Cut_off_freq_win)
        self._variable_qtgui_range_Audio_in_range = Range(0, 2, 0.1, 0.1, 200)
        self._variable_qtgui_range_Audio_in_win = RangeWidget(
            self._variable_qtgui_range_Audio_in_range,
            self.set_variable_qtgui_range_Audio_in, 'Audio Input Gain',
            "counter_slider", float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_Audio_in_win)
        self._variable_qtgui_range_0_1_range = Range(144000000, 440000000, 1,
                                                     145500000, 200)
        self._variable_qtgui_range_0_1_win = RangeWidget(
            self._variable_qtgui_range_0_1_range,
            self.set_variable_qtgui_range_0_1, 'Frequency', "counter_slider",
            float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_1_win)
        _variable_qtgui_push_button_CW_push_button = Qt.QPushButton('cw Key')
        _variable_qtgui_push_button_CW_push_button = Qt.QPushButton('cw Key')
        self._variable_qtgui_push_button_CW_choices = {
            'Pressed': 1,
            'Released': 0
        }
        _variable_qtgui_push_button_CW_push_button.pressed.connect(
            lambda: self.set_variable_qtgui_push_button_CW(
                self._variable_qtgui_push_button_CW_choices['Pressed']))
        _variable_qtgui_push_button_CW_push_button.released.connect(
            lambda: self.set_variable_qtgui_push_button_CW(
                self._variable_qtgui_push_button_CW_choices['Released']))
        self.top_grid_layout.addWidget(
            _variable_qtgui_push_button_CW_push_button)
        # Create the options list
        self._variable_qtgui_chooser_PTT_options = (
            0,
            1,
        )
        # Create the labels list
        self._variable_qtgui_chooser_PTT_labels = (
            'TX',
            'RX',
        )
        # Create the combo box
        self._variable_qtgui_chooser_PTT_tool_bar = Qt.QToolBar(self)
        self._variable_qtgui_chooser_PTT_tool_bar.addWidget(
            Qt.QLabel('PTT' + ": "))
        self._variable_qtgui_chooser_PTT_combo_box = Qt.QComboBox()
        self._variable_qtgui_chooser_PTT_tool_bar.addWidget(
            self._variable_qtgui_chooser_PTT_combo_box)
        for _label in self._variable_qtgui_chooser_PTT_labels:
            self._variable_qtgui_chooser_PTT_combo_box.addItem(_label)
        self._variable_qtgui_chooser_PTT_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._variable_qtgui_chooser_PTT_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._variable_qtgui_chooser_PTT_options.index(i)))
        self._variable_qtgui_chooser_PTT_callback(
            self.variable_qtgui_chooser_PTT)
        self._variable_qtgui_chooser_PTT_combo_box.currentIndexChanged.connect(
            lambda i: self.set_variable_qtgui_chooser_PTT(
                self._variable_qtgui_chooser_PTT_options[i]))
        # Create the radio buttons
        self.top_grid_layout.addWidget(
            self._variable_qtgui_chooser_PTT_tool_bar)
        self._variable_qtgui_range_0_1_0_range = Range(10338000000,
                                                       10702000000, 1,
                                                       10352560000, 200)
        self._variable_qtgui_range_0_1_0_win = RangeWidget(
            self._variable_qtgui_range_0_1_0_range,
            self.set_variable_qtgui_range_0_1_0, 'Frequency', "counter_slider",
            float)
        self.top_grid_layout.addWidget(self._variable_qtgui_range_0_1_0_win)
        # Create the options list
        self._variable_qtgui_chooser_PTT_0_options = (
            0,
            1,
        )
        # Create the labels list
        self._variable_qtgui_chooser_PTT_0_labels = (
            'TX',
            'RX',
        )
        # Create the combo box
        self._variable_qtgui_chooser_PTT_0_tool_bar = Qt.QToolBar(self)
        self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget(
            Qt.QLabel('PTT' + ": "))
        self._variable_qtgui_chooser_PTT_0_combo_box = Qt.QComboBox()
        self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget(
            self._variable_qtgui_chooser_PTT_0_combo_box)
        for _label in self._variable_qtgui_chooser_PTT_0_labels:
            self._variable_qtgui_chooser_PTT_0_combo_box.addItem(_label)
        self._variable_qtgui_chooser_PTT_0_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._variable_qtgui_chooser_PTT_0_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._variable_qtgui_chooser_PTT_0_options.index(i)
                     ))
        self._variable_qtgui_chooser_PTT_0_callback(
            self.variable_qtgui_chooser_PTT_0)
        self._variable_qtgui_chooser_PTT_0_combo_box.currentIndexChanged.connect(
            lambda i: self.set_variable_qtgui_chooser_PTT_0(
                self._variable_qtgui_chooser_PTT_0_options[i]))
        # Create the radio buttons
        self.top_grid_layout.addWidget(
            self._variable_qtgui_chooser_PTT_0_tool_bar)
        self.rational_resampler_xxx_1 = filter.rational_resampler_ccc(
            interpolation=11, decimation=1, taps=None, fractional_bw=None)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate_Baseband,  #bw
            'RF Out',  #name
            1)
        self.qtgui_freq_sink_x_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0,
                                                    0, "")
        self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win)
        self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " +
                                           "hackrf")
        self.osmosdr_sink_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.osmosdr_sink_0.set_sample_rate(samp_rate_Baseband_Hackrf)
        self.osmosdr_sink_0.set_center_freq(variable_qtgui_range_0_1, 0)
        self.osmosdr_sink_0.set_freq_corr(0, 0)
        self.osmosdr_sink_0.set_gain(10, 0)
        self.osmosdr_sink_0.set_if_gain(20, 0)
        self.osmosdr_sink_0.set_bb_gain(20, 0)
        self.osmosdr_sink_0.set_antenna('', 0)
        self.osmosdr_sink_0.set_bandwidth(0, 0)
        self.blocks_wavfile_source_0 = blocks.wavfile_source(
            '/home/anton/gnuradio-grc-examples/test_audio.wav', True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 samp_rate_Audio, True)
        self.blocks_selector_0_0 = blocks.selector(
            gr.sizeof_gr_complex * 1, variable_qtgui_push_button_CW, 0)
        self.blocks_selector_0_0.set_enabled(True)
        self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1,
                                                 variable_qtgui_chooser_PTT, 0)
        self.blocks_selector_0.set_enabled(True)
        self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(
            variable_qtgui_range_RF_out_gain)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(
            variable_qtgui_range_Audio_in)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.band_pass_filter_0 = filter.fir_filter_ccf(
            1,
            firdes.band_pass(1, samp_rate_Baseband, 16.3e3, 19e3, 200,
                             firdes.WIN_HAMMING, 6.76))
        self.analog_sig_source_x_2 = analog.sig_source_c(
            samp_rate_Baseband_Hackrf, analog.GR_SIN_WAVE, 800, 1, 0, 0)
        self.analog_sig_source_x_1 = analog.sig_source_c(
            samp_rate_Baseband, analog.GR_COS_WAVE, 0, 1, 0, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate_Baseband, analog.GR_SIN_WAVE,
            variable_qtgui_range_Cut_off_freq, 1, 0, 0)
        self.analog_const_source_x_0_0 = analog.sig_source_c(
            0, analog.GR_CONST_WAVE, 0, 0, 0)
        self.analog_const_source_x_0 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.analog_const_source_x_0_0, 0),
                     (self.blocks_selector_0, 1))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.analog_sig_source_x_2, 0),
                     (self.blocks_selector_0_0, 1))
        self.connect((self.band_pass_filter_0, 0),
                     (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_selector_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.band_pass_filter_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.rational_resampler_xxx_1, 0))
        self.connect((self.blocks_selector_0, 0), (self.osmosdr_sink_0, 0))
        self.connect((self.blocks_selector_0, 0),
                     (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.blocks_selector_0_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.blocks_wavfile_source_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.rational_resampler_xxx_1, 0),
                     (self.blocks_selector_0_0, 0))
예제 #14
0
    def __init__(self, k, rate, polys, state_start, padding, samp_rate, bit_rate, sel_convolutional, sel_encoder, sel_srrc, roll_off, num_taps, sine, freq_sub):
        gr.hier_block2.__init__(self,
            "modulator",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_float)) # Output signature

        ##################################################
        # Variables
        ##################################################
        
        self.framebits = 1
        self.k = k
        self.rate = rate
        self.polys = polys
        self.state_start = state_start
        self.mode = fec.CC_STREAMING
        self.padding = padding

        self.samp_rate = samp_rate
        self.bit_rate = bit_rate

        self.sel_convolutional = sel_convolutional
        self.sel_encoder = sel_encoder
        self.sel_srrc = sel_srrc

        self.threading = 'capillary'
        self.puncpat = '11'
        self.roll_off = roll_off
        self.num_taps = num_taps
        
        self.sine = sine
        self.freq_sub = freq_sub

        # if ndim == 0 :
        self.encoder_variable =  fec.cc_encoder_make(self.framebits, self.k, self.rate, self.polys, self.state_start, self.mode, self.padding)
        # elif ndim == 1:
        #     self.encoder_variable =  map( (lambda a: fec.cc_encoder_make(self.framebits, self.k, self.rate, self.polys, self.state_start, self.mode, self.padding)), range(0, dim1) ); #slurp
        # else:
        #     self.encoder_variable = map( (lambda b: map( ( lambda a: fec.cc_encoder_make(self.framebits, self.k, self.rate, self.polys, self.state_start, self.mode, self.padding)), range(0, dim2) ) ), range(0, dim1)); #slurp

        ##################################################
        # Blocks
        ##################################################
        self.selector_convolutional_in = blocks.selector(gr.sizeof_char*1, self.sel_convolutional, 1, 2)
        self.selector_convolutional_out = blocks.selector(gr.sizeof_char*1, self.sel_convolutional, 2, 1)
        self.selector_srrc_in = blocks.selector(gr.sizeof_float*1, self.sel_srrc, 1, 2)
        self.selector_srrc_out = blocks.selector(gr.sizeof_float*1, self.sel_srrc, 2, 1)
        self.selector_encoder_in = blocks.selector(gr.sizeof_char*1, self.sel_encoder, 1, 3)
        self.selector_encoder_out = blocks.selector(gr.sizeof_float*1, self.sel_encoder, 3, 1)

        self.convolutional_encoder = fec.extended_encoder(encoder_obj_list=self.encoder_variable, threading=self.threading, puncpat=self.puncpat)
        self.root_raised_cosine_filter = filter.fir_filter_fff(1, firdes.root_raised_cosine(1, self.samp_rate, self.bit_rate, self.roll_off, self.num_taps)) #symbol rate =  bit rate

        self.spl_encoder = ecss.spl_encoder(self.bit_rate, self.samp_rate)
        self.nrzl_encoder_subcarrier = ecss.nrzl_encoder_subcarrier(self.sine, self.freq_sub, self.bit_rate, self.samp_rate)
        self.nrzl_encoder = ecss.nrzl_encoder(self.bit_rate, self.samp_rate)

        ##################################################
        # Connections
        ##################################################
        # self.connect(self, (self.selector_convolutional_in, 0))
        # self.connect((self.selector_convolutional_in, 0), (self.convolutional_encoder, 0))
        # self.connect((self.convolutional_encoder, 0), (self.selector_convolutional_out, 0))
        # self.connect((self.selector_convolutional_in, 1), (self.selector_convolutional_out, 1))
        # self.connect((self.selector_convolutional_out, 0), (self.selector_encoder_in, 0))
        # self.connect((self.selector_encoder_in, 1), (self.nrzl_encoder, 0))
        # self.connect((self.selector_encoder_in, 2), (self.nrzl_encoder_subcarrier, 0))
        # self.connect((self.selector_encoder_in, 0), (self.spl_encoder, 0))
        # self.connect((self.nrzl_encoder, 0), (self.selector_encoder_out, 1))
        # self.connect((self.nrzl_encoder_subcarrier, 0), (self.selector_encoder_out, 2))
        # self.connect((self.spl_encoder, 0), (self.selector_encoder_out, 0))
        # self.connect((self.selector_encoder_out, 0), (self.selector_srrc_in, 0))
        # self.connect((self.selector_srrc_in, 0), (self.root_raised_cosine_filter, 0))
        # self.connect((self.selector_srrc_in, 1), (self.selector_srrc_out, 1))
        # self.connect((self.root_raised_cosine_filter, 0), (self.selector_srrc_out, 0))
        # self.connect((self.selector_srrc_out, 0), self)



        # self.connect(self, (self.convolutional_encoder, 0))
        # self.connect((self.convolutional_encoder, 0), (self.selector_convolutional_out, 0))
        # self.connect(self, (self.selector_convolutional_out, 1))

        # self.connect((self.selector_convolutional_out, 0), (self.nrzl_encoder, 0))
        # self.connect((self.selector_convolutional_out, 0), (self.nrzl_encoder_subcarrier, 0))
        # self.connect((self.selector_convolutional_out, 0), (self.spl_encoder, 0))
        # self.connect((self.nrzl_encoder, 0), (self.selector_encoder_out, 2))
        # self.connect((self.nrzl_encoder_subcarrier, 0), (self.selector_encoder_out, 1))
        # self.connect((self.spl_encoder, 0), (self.selector_encoder_out, 0))
        
        # self.connect((self.selector_encoder_out, 0), (self.root_raised_cosine_filter, 0))
        # self.connect((self.selector_encoder_out, 0), (self.selector_srrc_out, 1))
        # self.connect((self.root_raised_cosine_filter, 0), (self.selector_srrc_out, 0))
        # self.connect((self.selector_srrc_out, 0), self)



        if (sel_encoder == 0):
            encoder = self.spl_encoder
        elif (sel_encoder == 1 ):
            encoder = self.nrzl_encoder
        else:
            encoder = self.nrzl_encoder_subcarrier


        if (sel_convolutional == 0):
            self.connect(self, self.convolutional_encoder, encoder)
        else:
            self.connect(self, encoder)
        
        if (sel_srrc == 0):
            self.connect(encoder, self.root_raised_cosine_filter, self)
        else:
            self.connect(encoder, self)