Exemplo n.º 1
0
    def connect_audio_stage(self, input_port):
        stereo_rate = self.demod_rate
        normalizer = TWO_PI / stereo_rate
        pilot_tone = 19000
        pilot_low = pilot_tone * 0.98
        pilot_high = pilot_tone * 1.02

        def make_audio_filter():
            return grfilter.fir_filter_fff(
                stereo_rate // self.__audio_int_rate,  # decimation
                firdes.low_pass(1.0, stereo_rate, 15000, 5000,
                                firdes.WIN_HAMMING))

        stereo_pilot_filter = grfilter.fir_filter_fcc(
            1,  # decimation
            firdes.complex_band_pass(1.0, stereo_rate, pilot_low, pilot_high,
                                     300))  # TODO magic number from gqrx
        stereo_pilot_pll = analog.pll_refout_cc(
            loop_bw=0.001,
            max_freq=normalizer * pilot_high,
            min_freq=normalizer * pilot_low)
        stereo_pilot_doubler = blocks.multiply_cc()
        stereo_pilot_out = blocks.complex_to_real()
        difference_channel_mixer = blocks.multiply_ff()
        difference_channel_filter = make_audio_filter()
        mono_channel_filter = make_audio_filter()
        mixL = blocks.add_ff(1)
        mixR = blocks.sub_ff(1)

        # connections
        self.connect(input_port, mono_channel_filter)
        if self.__decode_stereo:
            # stereo pilot tone tracker
            self.connect(input_port, stereo_pilot_filter, stereo_pilot_pll)
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 0))
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 1))
            self.connect(stereo_pilot_doubler, stereo_pilot_out)

            # pick out stereo left-right difference channel (at stereo_rate)
            self.connect(input_port, (difference_channel_mixer, 0))
            self.connect(stereo_pilot_out, (difference_channel_mixer, 1))
            self.connect(
                difference_channel_mixer,
                blocks.multiply_const_ff(
                    50
                ),  # TODO: Completely empirical fudge factor. This should not be necessary. We're losing signal somewhere?
                difference_channel_filter)

            # recover left/right channels (at self.__audio_int_rate)
            self.connect(difference_channel_filter, (mixL, 1))
            self.connect(difference_channel_filter, (mixR, 1))
            resamplerL = self._make_resampler((mixL, 0), self.__audio_int_rate)
            resamplerR = self._make_resampler((mixR, 0), self.__audio_int_rate)
            self.connect(mono_channel_filter, (mixL, 0))
            self.connect(mono_channel_filter, (mixR, 0))
            self.connect_audio_output(resamplerL, resamplerR)
        else:
            resampler = self._make_resampler(mono_channel_filter,
                                             self.__audio_int_rate)
            self.connect_audio_output(resampler, resampler)
Exemplo n.º 2
0
def test_pll_refout_cc():
    top = gr.top_block()
    src = analog.fastnoise_source_c(analog.GR_UNIFORM, math.sqrt(2))
    pll = analog.pll_refout_cc(2*math.pi*1e3/300e3, 2*math.pi*200e3/300e3, 2*math.pi*220e3/300)
    probe = blocks.probe_rate(gr.sizeof_gr_complex)
    top.connect(src, pll, probe)

    return top, probe
Exemplo n.º 3
0
def test_pll_refout_cc():
    top = gr.top_block()
    src = analog.fastnoise_source_c(analog.GR_UNIFORM, math.sqrt(2))
    pll = analog.pll_refout_cc(2*math.pi*1e3/300e3, 2*math.pi*200e3/300e3, 2*math.pi*220e3/300)
    probe = blocks.probe_rate(gr.sizeof_gr_complex)
    top.connect(src, pll, probe)

    return top, probe
Exemplo n.º 4
0
    def connect_audio_stage(self, input_port):
        stereo_rate = self.demod_rate
        normalizer = TWO_PI / stereo_rate
        pilot_tone = 19000
        pilot_low = pilot_tone * 0.9
        pilot_high = pilot_tone * 1.1

        def make_audio_filter():
            return grfilter.fir_filter_fff(
                stereo_rate // self.__audio_int_rate,  # decimation
                firdes.low_pass(1.0, stereo_rate, 15000, 5000,
                                firdes.WIN_HAMMING))

        stereo_pilot_filter = grfilter.fir_filter_fcc(
            1,  # decimation
            firdes.complex_band_pass(1.0, stereo_rate, pilot_low, pilot_high,
                                     300))  # TODO magic number from gqrx
        stereo_pilot_pll = analog.pll_refout_cc(
            0.001,  # TODO magic number from gqrx
            normalizer * pilot_high,
            normalizer * pilot_low)
        stereo_pilot_doubler = blocks.multiply_cc()
        stereo_pilot_out = blocks.complex_to_imag()
        difference_channel_mixer = blocks.multiply_ff()
        difference_channel_filter = make_audio_filter()
        mono_channel_filter = make_audio_filter()
        mixL = blocks.add_ff(1)
        mixR = blocks.sub_ff(1)

        # connections
        self.connect(input_port, mono_channel_filter)
        if self.stereo:
            # stereo pilot tone tracker
            self.connect(input_port, stereo_pilot_filter, stereo_pilot_pll)
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 0))
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 1))
            self.connect(stereo_pilot_doubler, stereo_pilot_out)

            # pick out stereo left-right difference channel (at stereo_rate)
            self.connect(input_port, (difference_channel_mixer, 0))
            self.connect(stereo_pilot_out, (difference_channel_mixer, 1))
            self.connect(difference_channel_mixer, difference_channel_filter)

            # recover left/right channels (at self.__audio_int_rate)
            self.connect(difference_channel_filter, (mixL, 1))
            self.connect(difference_channel_filter, (mixR, 1))
            resamplerL = self._make_resampler((mixL, 0), self.__audio_int_rate)
            resamplerR = self._make_resampler((mixR, 0), self.__audio_int_rate)
            self.connect(mono_channel_filter, (mixL, 0))
            self.connect(mono_channel_filter, (mixR, 0))
            self.connect_audio_output(resamplerL, resamplerR)
        else:
            resampler = self._make_resampler(mono_channel_filter,
                                             self.__audio_int_rate)
            self.connect_audio_output(resampler, resampler)
Exemplo n.º 5
0
    def connect_audio_stage(self, input_port):
        stereo_rate = self.demod_rate
        normalizer = TWO_PI / stereo_rate
        pilot_tone = 19000
        pilot_low = pilot_tone * 0.9
        pilot_high = pilot_tone * 1.1

        def make_audio_filter():
            return grfilter.fir_filter_fff(
                stereo_rate // self.__audio_int_rate,  # decimation
                firdes.low_pass(1.0, stereo_rate, 15000, 5000, firdes.WIN_HAMMING),
            )

        stereo_pilot_filter = grfilter.fir_filter_fcc(
            1, firdes.complex_band_pass(1.0, stereo_rate, pilot_low, pilot_high, 300)  # decimation
        )  # TODO magic number from gqrx
        stereo_pilot_pll = analog.pll_refout_cc(
            0.001, normalizer * pilot_high, normalizer * pilot_low  # TODO magic number from gqrx
        )
        stereo_pilot_doubler = blocks.multiply_cc()
        stereo_pilot_out = blocks.complex_to_imag()
        difference_channel_mixer = blocks.multiply_ff()
        difference_channel_filter = make_audio_filter()
        mono_channel_filter = make_audio_filter()
        mixL = blocks.add_ff(1)
        mixR = blocks.sub_ff(1)

        # connections
        self.connect(input_port, mono_channel_filter)
        if self.stereo:
            # stereo pilot tone tracker
            self.connect(input_port, stereo_pilot_filter, stereo_pilot_pll)
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 0))
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 1))
            self.connect(stereo_pilot_doubler, stereo_pilot_out)

            # pick out stereo left-right difference channel (at stereo_rate)
            self.connect(input_port, (difference_channel_mixer, 0))
            self.connect(stereo_pilot_out, (difference_channel_mixer, 1))
            self.connect(difference_channel_mixer, difference_channel_filter)

            # recover left/right channels (at self.__audio_int_rate)
            self.connect(difference_channel_filter, (mixL, 1))
            self.connect(difference_channel_filter, (mixR, 1))
            resamplerL = self._make_resampler((mixL, 0), self.__audio_int_rate)
            resamplerR = self._make_resampler((mixR, 0), self.__audio_int_rate)
            self.connect(mono_channel_filter, (mixL, 0))
            self.connect(mono_channel_filter, (mixR, 0))
            self.connect_audio_output(resamplerL, resamplerR)
        else:
            resampler = self._make_resampler(mono_channel_filter, self.__audio_int_rate)
            self.connect_audio_output(resampler, resampler)
Exemplo n.º 6
0
    def __init__(self, audio_rate=48000, samp_rate=512e3):
        gr.hier_block2.__init__(
            self, "MPX Demodulator",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signaturev(5, 5, [gr.sizeof_char*1, gr.sizeof_char*1, gr.sizeof_float*1, gr.sizeof_float*1, gr.sizeof_gr_complex*1]),
        )

        ##################################################
        # Parameters
        ##################################################
        self.audio_rate = audio_rate
        self.samp_rate = samp_rate

        ##################################################
        # Blocks
        ##################################################
        self.rds_demod_0 = rds_demod(
            samp_rate=samp_rate,
        )
        self.fm_audio_demod_0 = fm_audio_demod(
            audio_rate=audio_rate,
            samp_rate=samp_rate,
        )
        self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.band_pass_filter_0_1 = filter.fir_filter_ccf(1, firdes.band_pass(
        	1, samp_rate, 19e3-500, 19e3+500, 1e3, firdes.WIN_HAMMING, 6.76))
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(2 * math.pi * 8 / samp_rate, 2 * math.pi * (19000+4) / samp_rate, 2 * math.pi * (19000-4) / samp_rate)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_0_0, 2))
        self.connect((self.band_pass_filter_0_1, 0), (self.analog_pll_refout_cc_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.fm_audio_demod_0, 1))
        self.connect((self.blocks_multiply_xx_0_0, 0), (self.rds_demod_0, 0))
        self.connect((self.fm_audio_demod_0, 0), (self, 1))
        self.connect((self.fm_audio_demod_0, 1), (self, 2))
        self.connect((self.fm_audio_demod_0, 2), (self, 3))
        self.connect((self, 0), (self.band_pass_filter_0_1, 0))
        self.connect((self, 0), (self.fm_audio_demod_0, 0))
        self.connect((self, 0), (self.rds_demod_0, 1))
        self.connect((self.rds_demod_0, 0), (self, 0))
        self.connect((self.rds_demod_0, 1), (self, 4))
Exemplo n.º 7
0
    def __init__(self,
                 final_decimation=4,
                 gain=21,
                 pllFreqMax=100,
                 pulse_duration=0.015,
                 pulse_freq=146000000,
                 samp_rate=3e6,
                 wnT=math.pi / 4.0 * 0 + 0.635):
        gr.hier_block2.__init__(
            self,
            "Pulsedetectbase",
            gr.io_signature(0, 0, 0),
            gr.io_signaturev(2, 2,
                             [gr.sizeof_float * 1, gr.sizeof_gr_complex * 1]),
        )

        ##################################################
        # Parameters
        ##################################################
        self.final_decimation = final_decimation
        self.gain = gain
        self.pllFreqMax = pllFreqMax
        self.pulse_duration = pulse_duration
        self.pulse_freq = pulse_freq
        self.samp_rate = samp_rate
        self.wnT = wnT

        ##################################################
        # Variables
        ##################################################
        self.decimate_1 = decimate_1 = 16
        self.samp_rate2 = samp_rate2 = samp_rate / decimate_1
        self.decimate_2 = decimate_2 = 16
        self.samp_rate3 = samp_rate3 = samp_rate2 / decimate_2
        self.taps3 = taps3 = firdes.low_pass_2(1.0, samp_rate3, 1.5e3, 0.3e3,
                                               30.0, firdes.WIN_KAISER,
                                               6.76 / 2)
        self.taps2 = taps2 = firdes.low_pass_2(1.0, samp_rate2, 1.5e3,
                                               16e3 - 1.5e3, 60.0,
                                               firdes.WIN_BLACKMAN_HARRIS,
                                               6.76)
        self.taps1 = taps1 = firdes.low_pass_2(1.0, samp_rate, 1.5e3,
                                               128e3 - 1.5e3, 60.0,
                                               firdes.WIN_BLACKMAN_HARRIS,
                                               6.76)
        self.decimate_3 = decimate_3 = final_decimation
        self.taps3_len = taps3_len = len(taps3)
        self.taps2_len = taps2_len = len(taps2)
        self.taps1_len = taps1_len = len(taps1)
        self.samp_rate4 = samp_rate4 = samp_rate3 / decimate_3
        self.inter_pulse_duration = inter_pulse_duration = 2
        self.fmin = fmin = -pllFreqMax
        self.fmax = fmax = pllFreqMax

        ##################################################
        # Blocks
        ##################################################
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               'airspy=0,sensitivity')
        self.osmosdr_source_0.set_clock_source('gpsdo', 0)
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(pulse_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gain, 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(
            decimate_1, (taps1), 0, samp_rate)
        self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccf(decimate_3, (taps3))
        self.fir_filter_xxx_0_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(decimate_2, (taps2))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_moving_average_xx_0_0 = blocks.moving_average_cc(
            int(samp_rate4 * pulse_duration), 1,
            int(samp_rate4 * inter_pulse_duration / 10.0))
        self.blocks_complex_to_mag_0_0 = blocks.complex_to_mag(1)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            wnT, math.pi / (samp_rate4 / 2.0) * fmax,
            math.pi / (samp_rate4 / 2.0) * fmin)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.blocks_complex_to_mag_0_0, 0), (self, 0))
        self.connect((self.blocks_moving_average_xx_0_0, 0),
                     (self.blocks_complex_to_mag_0_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.blocks_moving_average_xx_0_0, 0))
        self.connect((self.fir_filter_xxx_0_0, 0),
                     (self.fir_filter_xxx_0_0_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0),
                     (self.analog_pll_refout_cc_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0), (self, 1))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.fir_filter_xxx_0_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.freq_xlating_fir_filter_xxx_0, 0))
Exemplo n.º 8
0
    def test_pll_refout(self):
        expected_result = ((1+0j),
                            (1+6.408735764296125e-10j),
                            (0.9999844431877136+0.005577784031629562j),
                            (0.9998642802238464+0.016474783420562744j),
                            (0.9994739890098572+0.032431427389383316j),
                            (0.9985847473144531+0.05318402871489525j),
                            (0.996917188167572+0.07846084982156754j),
                            (0.9941533207893372+0.10797744989395142j),
                            (0.9899479150772095+0.14143235981464386j),
                            (0.9839394092559814+0.1785029172897339j),
                            (0.9757603406906128+0.2188417762517929j),
                            (0.9650475978851318+0.26207470893859863j),
                            (0.9514514803886414+0.30779871344566345j),
                            (0.9346449971199036+0.35558223724365234j),
                            (0.9143316149711609+0.40496626496315j),
                            (0.8902531862258911+0.4554659426212311j),
                            (0.8621962666511536+0.5065743923187256j),
                            (0.8299974799156189+0.5577671527862549j),
                            (0.7935484647750854+0.6085070967674255j),
                            (0.7527987360954285+0.6582507491111755j),
                            (0.7077582478523254+0.7064547538757324j),
                            (0.6584978699684143+0.7525825500488281j),
                            (0.6051493883132935+0.7961119413375854j),
                            (0.547903835773468+0.8365413546562195j),
                            (0.48700881004333496+0.8733970522880554j),
                            (0.42276495695114136+0.90623939037323j),
                            (0.35552138090133667+0.9346681237220764j),
                            (0.2856702208518982+0.9583280086517334j),
                            (0.21364101767539978+0.976912260055542j),
                            (0.13989387452602386+0.9901664853096008j),
                            (0.06491273641586304+0.9978909492492676j),
                            (-0.01080091018229723+0.9999416470527649j),
                            (-0.08673560619354248+0.9962313771247864j),
                            (-0.16237612068653107+0.9867289662361145j),
                            (-0.23721040785312653+0.9714583158493042j),
                            (-0.3107353150844574+0.95049649477005j),
                            (-0.3824624717235565+0.9239710569381714j),
                            (-0.45192304253578186+0.892056941986084j),
                            (-0.5186731219291687+0.8549726009368896j),
                            (-0.5822963714599609+0.812976598739624j),
                            (-0.6424083709716797+0.7663624882698059j),
                            (-0.6986585855484009+0.7154552340507507j),
                            (-0.7507330775260925+0.6606056690216064j),
                            (-0.7983550429344177+0.6021870970726013j),
                            (-0.841286301612854+0.5405898094177246j),
                            (-0.879327654838562+0.47621726989746094j),
                            (-0.912318229675293+0.4094819128513336j),
                            (-0.9401354789733887+0.340800940990448j),
                            (-0.9626938104629517+0.27059316635131836j),
                            (-0.979943573474884+0.1992751508951187j),
                            (-0.9918696284294128+0.12725839018821716j),
                            (-0.9984893202781677+0.054946307092905045j),
                            (-0.9998509287834167-0.017267409712076187j),
                            (-0.9960314631462097-0.08900183439254761j),
                            (-0.9871346950531006-0.1598907858133316j),
                            (-0.9732890129089355-0.2295832633972168j),
                            (-0.9546451568603516-0.29774588346481323j),
                            (-0.9313743710517883-0.3640628457069397j),
                            (-0.9036663174629211-0.42823725938796997j),
                            (-0.8717266321182251-0.48999255895614624j),
                            (-0.8357754945755005-0.5490713119506836j),
                            (-0.7960456013679504-0.6052366495132446j),
                            (-0.7527803182601929-0.658271849155426j),
                            (-0.706232488155365-0.7079799771308899j),
                            (-0.6566619873046875-0.7541850209236145j),
                            (-0.6043350696563721-0.7967302799224854j),
                            (-0.5495226979255676-0.8354787826538086j),
                            (-0.4924990236759186-0.8703129887580872j),
                            (-0.4335414469242096-0.9011335968971252j),
                            (-0.3729270100593567-0.927860677242279j),
                            (-0.3109343349933624-0.9504314064979553j),
                            (-0.2478405237197876-0.9688008427619934j),
                            (-0.18392162024974823-0.9829409122467041j),
                            (-0.11945075541734695-0.9928401112556458j),
                            (-0.05469784513115883-0.9985029697418213j),
                            (0.010069688782095909-0.9999492764472961j),
                            (0.07459097355604172-0.9972141981124878j),
                            (0.13860897719860077-0.9903472065925598j),
                            (0.2018725872039795-0.979411780834198j),
                            (0.2641367018222809-0.964485228061676j),
                            (0.32516375184059143-0.9456577301025391j),
                            (0.3847236633300781-0.9230318069458008j),
                            (0.44259318709373474-0.8967224955558777j),
                            (0.49855801463127136-0.8668563365936279j),
                            (0.5524120926856995-0.8335711359977722j),
                            (0.6039596796035767-0.7970148921012878j),
                            (0.6530137062072754-0.7573460936546326j),
                            (0.6993972063064575-0.7147331833839417j),
                            (0.7429447770118713-0.6693527102470398j),
                            (0.7835012078285217-0.6213902235031128j),
                            (0.8209227919578552-0.5710391998291016j),
                            (0.8550769090652466-0.5185011625289917j),
                            (0.8858439326286316-0.46398329734802246j),
                            (0.9131162166595459-0.4076994061470032j),
                            (0.936798632144928-0.3498689830303192j),
                            (0.956809401512146-0.2907160222530365j),
                            (0.9730796813964844-0.23046888411045074j),
                            (0.9855544567108154-0.16935895383358002j),
                            (0.9941920042037964-0.10762103646993637j),
                            (0.9989647269248962-0.045491550117731094j)) 

        sampling_freq = 10e3
        freq = sampling_freq / 100

        loop_bw = math.pi / 100.0
        maxf = 1
        minf = -1

        src = analog.sig_source_c(sampling_freq, analog.GR_COS_WAVE, freq, 1.0)
        pll = analog.pll_refout_cc(loop_bw, maxf, minf)
        head = blocks.head(gr.sizeof_gr_complex, int (freq))
        dst = blocks.vector_sink_c()

        self.tb.connect(src, pll, head)
        self.tb.connect(head, dst)

        self.tb.run()
        dst_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
Exemplo n.º 9
0
    def __init__(self):
        gr.top_block.__init__(self, "FM Radio")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("FM Radio")
        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", "fm_radio")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.valid_gains = valid_gains = [0.0, 0.9, 1.4, 2.7, 3.7, 7.7, 8.7, 12.5, 14.4, 15.7, 16.6, 19.7, 20.7, 22.9, 25.4, 28.0, 29.7, 32.8, 33.8, 36.4, 37.2, 38.6, 40.2, 42.1, 43.4, 43.9, 44.5, 48.0, 49.6]
        self.samp_rate = samp_rate = 2.048e6
        self.baseband_decimation = baseband_decimation = 10
        self.rf_gain = rf_gain = len(valid_gains)-1
        self.rds_dec = rds_dec = 10
        self.pilot_tone = pilot_tone = 19e3
        self.baseband_rate = baseband_rate = samp_rate // baseband_decimation
        self.stereo_subcarrier = stereo_subcarrier = pilot_tone * 2
        self.stereo_button = stereo_button = 0
        self.slider_volume = slider_volume = 0
        self.sdr_gain = sdr_gain = valid_gains[rf_gain]
        self.rds_symbols_per_bit = rds_symbols_per_bit = 2
        self.rds_subcarrier = rds_subcarrier = pilot_tone * 3
        self.rds_samp_rate = rds_samp_rate = baseband_rate / rds_dec
        self.rds_bitrate = rds_bitrate = 1.1875e3
        self.rds_bandwidth = rds_bandwidth = 2.83e3
        self.fm_station = fm_station = 102.7
        self.fm_broadcast_seperation = fm_broadcast_seperation = 0.2
        self.fm_broadcast_low = fm_broadcast_low = 87.1
        self.fm_broadcast_high = fm_broadcast_high = 107.9
        self.audio_rate = audio_rate = 48e3

        ##################################################
        # Blocks
        ##################################################
        self.notebook_top = Qt.QTabWidget()
        self.notebook_top_widget_0 = Qt.QWidget()
        self.notebook_top_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_0)
        self.notebook_top_grid_layout_0 = Qt.QGridLayout()
        self.notebook_top_layout_0.addLayout(self.notebook_top_grid_layout_0)
        self.notebook_top.addTab(self.notebook_top_widget_0, "RF Receive")
        self.notebook_top_widget_1 = Qt.QWidget()
        self.notebook_top_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_1)
        self.notebook_top_grid_layout_1 = Qt.QGridLayout()
        self.notebook_top_layout_1.addLayout(self.notebook_top_grid_layout_1)
        self.notebook_top.addTab(self.notebook_top_widget_1, "Baseband")
        self.notebook_top_widget_2 = Qt.QWidget()
        self.notebook_top_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_2)
        self.notebook_top_grid_layout_2 = Qt.QGridLayout()
        self.notebook_top_layout_2.addLayout(self.notebook_top_grid_layout_2)
        self.notebook_top.addTab(self.notebook_top_widget_2, "Mono Audio")
        self.notebook_top_widget_3 = Qt.QWidget()
        self.notebook_top_layout_3 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_3)
        self.notebook_top_grid_layout_3 = Qt.QGridLayout()
        self.notebook_top_layout_3.addLayout(self.notebook_top_grid_layout_3)
        self.notebook_top.addTab(self.notebook_top_widget_3, "Sub-Carrier Generation")
        self.notebook_top_widget_4 = Qt.QWidget()
        self.notebook_top_layout_4 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_4)
        self.notebook_top_grid_layout_4 = Qt.QGridLayout()
        self.notebook_top_layout_4.addLayout(self.notebook_top_grid_layout_4)
        self.notebook_top.addTab(self.notebook_top_widget_4, "Stereo")
        self.notebook_top_widget_5 = Qt.QWidget()
        self.notebook_top_layout_5 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_top_widget_5)
        self.notebook_top_grid_layout_5 = Qt.QGridLayout()
        self.notebook_top_layout_5.addLayout(self.notebook_top_grid_layout_5)
        self.notebook_top.addTab(self.notebook_top_widget_5, "RDS")
        self.top_grid_layout.addWidget(self.notebook_top, 3, 0, 1, 8)
        self._slider_volume_range = Range(0, 11.1, 0.1, 0, 100)
        self._slider_volume_win = RangeWidget(self._slider_volume_range, self.set_slider_volume, 'Volume', "counter_slider", float)
        self.top_grid_layout.addWidget(self._slider_volume_win, 1, 1, 1, 1)
        self.notebook_subcarriers = Qt.QTabWidget()
        self.notebook_subcarriers_widget_0 = Qt.QWidget()
        self.notebook_subcarriers_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_subcarriers_widget_0)
        self.notebook_subcarriers_grid_layout_0 = Qt.QGridLayout()
        self.notebook_subcarriers_layout_0.addLayout(self.notebook_subcarriers_grid_layout_0)
        self.notebook_subcarriers.addTab(self.notebook_subcarriers_widget_0, "Pilot Signal")
        self.notebook_subcarriers_widget_1 = Qt.QWidget()
        self.notebook_subcarriers_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_subcarriers_widget_1)
        self.notebook_subcarriers_grid_layout_1 = Qt.QGridLayout()
        self.notebook_subcarriers_layout_1.addLayout(self.notebook_subcarriers_grid_layout_1)
        self.notebook_subcarriers.addTab(self.notebook_subcarriers_widget_1, "Spectrum")
        self.notebook_top_grid_layout_3.addWidget(self.notebook_subcarriers, 0, 0, 1, 1)
        self.notebook_rds = Qt.QTabWidget()
        self.notebook_rds_widget_0 = Qt.QWidget()
        self.notebook_rds_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_rds_widget_0)
        self.notebook_rds_grid_layout_0 = Qt.QGridLayout()
        self.notebook_rds_layout_0.addLayout(self.notebook_rds_grid_layout_0)
        self.notebook_rds.addTab(self.notebook_rds_widget_0, "RDS Signal")
        self.notebook_rds_widget_1 = Qt.QWidget()
        self.notebook_rds_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.notebook_rds_widget_1)
        self.notebook_rds_grid_layout_1 = Qt.QGridLayout()
        self.notebook_rds_layout_1.addLayout(self.notebook_rds_grid_layout_1)
        self.notebook_rds.addTab(self.notebook_rds_widget_1, "RDS Bitstream")
        self.notebook_top_grid_layout_5.addWidget(self.notebook_rds, 0, 0, 1, 1)
        self._fm_station_range = Range(fm_broadcast_low, fm_broadcast_high, fm_broadcast_seperation, 102.7, 200)
        self._fm_station_win = RangeWidget(self._fm_station_range, self.set_fm_station, "FM Station", "counter_slider", float)
        self.top_grid_layout.addWidget(self._fm_station_win, 0, 0, 1, 8)
        self._stereo_button_options = (0, 1, )
        self._stereo_button_labels = ("Mono", "Stereo", )
        self._stereo_button_tool_bar = Qt.QToolBar(self)
        self._stereo_button_tool_bar.addWidget(Qt.QLabel("Audio Output"+": "))
        self._stereo_button_combo_box = Qt.QComboBox()
        self._stereo_button_tool_bar.addWidget(self._stereo_button_combo_box)
        for label in self._stereo_button_labels: self._stereo_button_combo_box.addItem(label)
        self._stereo_button_callback = lambda i: Qt.QMetaObject.invokeMethod(self._stereo_button_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._stereo_button_options.index(i)))
        self._stereo_button_callback(self.stereo_button)
        self._stereo_button_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_stereo_button(self._stereo_button_options[i]))
        self.top_grid_layout.addWidget(self._stereo_button_tool_bar, 1, 2, 1, 1)
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(fm_station * 1e6, 0)
        self.rtlsdr_source_0.set_freq_corr(14, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(2, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(sdr_gain, 0)
        self.rtlsdr_source_0.set_if_gain(0, 0)
        self.rtlsdr_source_0.set_bb_gain(0, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine(
        	2, rds_samp_rate, rds_bitrate * rds_symbols_per_bit, 0.275, 16))
        self._rf_gain_range = Range(0, len(valid_gains)-1, 1, len(valid_gains)-1, 200)
        self._rf_gain_win = RangeWidget(self._rf_gain_range, self.set_rf_gain, "RF Gain", "counter_slider", int)
        self.top_grid_layout.addWidget(self._rf_gain_win, 1, 0, 1, 1)
        self.rds_qt_panel_0 = self.rds_qt_panel_0 = rds.qt_panel()
        self.notebook_top_layout_5.addWidget(self.rds_qt_panel_0)
          
        self.rational_resampler_xxx_0_0_0_1 = filter.rational_resampler_fff(
                interpolation=int(audio_rate),
                decimation=int(baseband_rate),
                taps=None,
                fractional_bw=None,
        )
        self.rational_resampler_xxx_0_0_0_0 = filter.rational_resampler_fff(
                interpolation=int(audio_rate),
                decimation=int(baseband_rate),
                taps=None,
                fractional_bw=None,
        )
        self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_fff(
                interpolation=int(audio_rate),
                decimation=int(baseband_rate),
                taps=None,
                fractional_bw=None,
        )
        self.qtgui_time_sink_x_1 = qtgui.time_sink_f(
        	1024, #size
        	samp_rate, #samp_rate
        	"RBDS Bit Stream", #name
        	2 #number of inputs
        )
        self.qtgui_time_sink_x_1.set_update_time(0.10)
        self.qtgui_time_sink_x_1.set_y_axis(-1.7, 1.7)
        
        self.qtgui_time_sink_x_1.set_y_label("Amplitude", "")
        
        self.qtgui_time_sink_x_1.enable_tags(-1, False)
        self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_1.enable_autoscale(False)
        self.qtgui_time_sink_x_1.enable_grid(True)
        self.qtgui_time_sink_x_1.enable_control_panel(False)
        
        if not True:
          self.qtgui_time_sink_x_1.disable_legend()
        
        labels = ["Raw Bit Stream", "Differential Decoded", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_1.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget)
        self.notebook_rds_layout_1.addWidget(self._qtgui_time_sink_x_1_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	1024, #size
        	baseband_rate, #samp_rate
        	"19 KHz Pilot Signal", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1.5, 1.5)
        
        self.qtgui_time_sink_x_0.set_y_label("Amplitude", "counts")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, False)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        if not False:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(1):
            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.notebook_subcarriers_grid_layout_0.addWidget(self._qtgui_time_sink_x_0_win, 0, 1, 1, 1)
        self.qtgui_freq_sink_x_1 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	rds_samp_rate, #bw
        	"RDS Subcarrier Signal (DSB-SSC)", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_1.set_update_time(0.10)
        self.qtgui_freq_sink_x_1.set_y_axis(-100, 0)
        self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_1.enable_autoscale(False)
        self.qtgui_freq_sink_x_1.enable_grid(False)
        self.qtgui_freq_sink_x_1.set_fft_average(1.0)
        self.qtgui_freq_sink_x_1.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_1.disable_legend()
        
        if complex == type(float()):
          self.qtgui_freq_sink_x_1.set_plot_pos_half(not 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"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_1.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_1_win = sip.wrapinstance(self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget)
        self.notebook_rds_grid_layout_0 .addWidget(self._qtgui_freq_sink_x_1_win,  0, 0, 1, 1)
        self.qtgui_freq_sink_x_0_1_0_1_0 = qtgui.freq_sink_f(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	audio_rate, #bw
        	"Stereo Audio Left", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_0_1_0_1_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_1_0_1_0.set_y_axis(-100, -30)
        self.qtgui_freq_sink_x_0_1_0_1_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_1_0_1_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_1_0_1_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_1_0_1_0.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0_1_0_1_0.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_0_1_0_1_0.disable_legend()
        
        if float == type(float()):
          self.qtgui_freq_sink_x_0_1_0_1_0.set_plot_pos_half(not False)
        
        labels = ["Stereo Left", "Stereo Right", "", "", "",
                  "", "", "", "", ""]
        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 xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_1_0_1_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_1_0_1_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_1_0_1_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_1_0_1_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_1_0_1_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_1_0_1_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_1_0_1_0.pyqwidget(), Qt.QWidget)
        self.notebook_top_grid_layout_4.addWidget(self._qtgui_freq_sink_x_0_1_0_1_0_win, 0, 0, 1, 1)
        self.qtgui_freq_sink_x_0_1_0_1 = qtgui.freq_sink_f(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	audio_rate, #bw
        	"Stereo Audio Right", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_0_1_0_1.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_1_0_1.set_y_axis(-100, -30)
        self.qtgui_freq_sink_x_0_1_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_1_0_1.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_1_0_1.enable_grid(False)
        self.qtgui_freq_sink_x_0_1_0_1.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0_1_0_1.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_0_1_0_1.disable_legend()
        
        if float == type(float()):
          self.qtgui_freq_sink_x_0_1_0_1.set_plot_pos_half(not False)
        
        labels = ["Stereo Right", "Stereo Right", "", "", "",
                  "", "", "", "", ""]
        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 xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_1_0_1.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_1_0_1.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_1_0_1.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_1_0_1.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_1_0_1.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_1_0_1_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_1_0_1.pyqwidget(), Qt.QWidget)
        self.notebook_top_grid_layout_4.addWidget(self._qtgui_freq_sink_x_0_1_0_1_win, 0, 1, 1, 1)
        self.qtgui_freq_sink_x_0_1_0_0 = qtgui.freq_sink_f(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	baseband_rate, #bw
        	"Pilot & Stereo Carrier", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_0_1_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_1_0_0.set_y_axis(-80, 0)
        self.qtgui_freq_sink_x_0_1_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_1_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_1_0_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_1_0_0.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0_1_0_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0_1_0_0.disable_legend()
        
        if float == type(float()):
          self.qtgui_freq_sink_x_0_1_0_0.set_plot_pos_half(not False)
        
        labels = ["Pilot Tone", "Stereo Carrier", "RDS Carrier", "", "",
                  "", "", "", "", ""]
        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 xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_1_0_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_1_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_1_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_1_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_1_0_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_1_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_1_0_0.pyqwidget(), Qt.QWidget)
        self.notebook_subcarriers_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_1_0_0_win, 0, 0, 1, 1)
        self.qtgui_freq_sink_x_0_0_0 = qtgui.freq_sink_f(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	audio_rate, #bw
        	"Mono Audio (L+R)", #name
        	2 #number of inputs
        )
        self.qtgui_freq_sink_x_0_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_0_0.set_y_axis(-100, -30)
        self.qtgui_freq_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_0_0.set_fft_average(0.2)
        self.qtgui_freq_sink_x_0_0_0.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_0_0_0.disable_legend()
        
        if float == type(float()):
          self.qtgui_freq_sink_x_0_0_0.set_plot_pos_half(not 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 xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_0_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_0_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0_0.pyqwidget(), Qt.QWidget)
        self.notebook_top_grid_layout_2.addWidget(self._qtgui_freq_sink_x_0_0_0_win, 1, 0, 1, 5)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_f(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	baseband_rate, #bw
        	"FM Baseband", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-100, -30)
        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(0.1)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_0_0.disable_legend()
        
        if float == type(float()):
          self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not 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 xrange(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.notebook_top_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 1, 1, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	fm_station * 1e6, #fc
        	samp_rate, #bw
        	"RF Frequency", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-90, 0)
        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(0.1)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)
        
        if not False:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if complex == type(float()):
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not 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"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_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.notebook_top_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 0, 1, 1, 1)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	1024, #size
        	"RDS BPSK Constellation", #name
        	1 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-1.6, 1.6)
        self.qtgui_const_sink_x_0.set_x_axis(-1.6, 1.6)
        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)
        
        if not False:
          self.qtgui_const_sink_x_0.disable_legend()
        
        labels = ["RBDS BPSK", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "red", "red", "red",
                  "red", "red", "red", "red", "red"]
        styles = [0, 0, 0, 0, 0,
                  0, 0, 0, 0, 0]
        markers = [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 xrange(1):
            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.notebook_rds_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0, 1, 1, 1)
        self.low_pass_filter_4 = filter.fir_filter_fff(1, firdes.low_pass(
        	1, baseband_rate, 60e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_2 = filter.fir_filter_fff(1, firdes.low_pass(
        	1, baseband_rate, 16e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_1 = filter.fir_filter_fff(1, firdes.low_pass(
        	10, baseband_rate, 15e3, 3e3, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0 = filter.fir_filter_ccf(baseband_decimation, firdes.low_pass(
        	1, samp_rate, 75e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.gr_rds_parser_0 = rds.parser(False, False, 1)
        self.gr_rds_decoder_0 = rds.decoder(False, False)
        self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_fcc(rds_dec, (firdes.low_pass(2500,baseband_rate,rds_bandwidth,1e3,firdes.WIN_HAMMING)), rds_subcarrier, baseband_rate)
        self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(2, 0, (2 * cmath.pi) / 100, -0.00006, 0.00006, 0.5, 0.05, rds_samp_rate / (rds_bitrate * 2), ((rds_samp_rate / (rds_bitrate * 2)) ** 2)/ 4, 0.005)
        self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_multiply_xx_1 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_1_0_1_0_1 = blocks.multiply_const_vff((11, ))
        self.blocks_multiply_const_vxx_1_0_1_0_0 = blocks.multiply_const_vff((11, ))
        self.blocks_multiply_const_vxx_1_0_1_0 = blocks.multiply_const_vff((11, ))
        self.blocks_multiply_const_vxx_1_0_1 = blocks.multiply_const_vff((slider_volume, ))
        self.blocks_multiply_const_vxx_1_0_0 = blocks.multiply_const_vff((slider_volume, ))
        self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((slider_volume, ))
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_char*1, 2)
        self.blocks_complex_to_real_1 = blocks.complex_to_real(1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.blocks_add_const_vxx_0_0 = blocks.add_const_vff((0.5, ))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1.5, ))
        self.blks2_selector_0_0 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=2,
        	num_outputs=1,
        	input_index=0,
        	output_index=0,
        )
        self.blks2_selector_0 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=2,
        	num_outputs=1,
        	input_index=0,
        	output_index=0,
        )
        self.band_pass_filter_1 = filter.fir_filter_fff(1, firdes.band_pass(
        	1, baseband_rate, stereo_subcarrier - 0.5e3, stereo_subcarrier + 0.5e3, 0.5e3, firdes.WIN_HAMMING, 6.76))
        self.band_pass_filter_0_0 = filter.fir_filter_fff(1, firdes.band_pass(
        	1, baseband_rate, 23e3, 53e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.band_pass_filter_0 = filter.fir_filter_fcc(1, firdes.complex_band_pass(
        	1, baseband_rate, pilot_tone - 0.5e3, pilot_tone+0.5e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.audio_sink_0 = audio.sink(48000, "", True)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
        	quad_rate=baseband_rate,
        	audio_decimation=1,
        )
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(1e-3, 2 * cmath.pi * (19000+200) / baseband_rate, 2 * cmath.pi * (19000-200) / baseband_rate)
        self.analog_fm_deemph_0_0_0_1 = analog.fm_deemph(fs=baseband_rate, tau=75e-6)
        self.analog_fm_deemph_0_0_0_0 = analog.fm_deemph(fs=baseband_rate, tau=75e-6)
        self.analog_fm_deemph_0_0_0 = analog.fm_deemph(fs=baseband_rate, tau=75e-6)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.gr_rds_decoder_0, 'out'), (self.gr_rds_parser_0, 'in'))    
        self.msg_connect((self.gr_rds_parser_0, 'out'), (self.rds_qt_panel_0, 'in'))    
        self.connect((self.analog_fm_deemph_0_0_0, 0), (self.rational_resampler_xxx_0_0_0, 0))    
        self.connect((self.analog_fm_deemph_0_0_0_0, 0), (self.rational_resampler_xxx_0_0_0_0, 0))    
        self.connect((self.analog_fm_deemph_0_0_0_1, 0), (self.rational_resampler_xxx_0_0_0_1, 0))    
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_complex_to_real_1, 0))    
        self.connect((self.analog_wfm_rcv_0, 0), (self.low_pass_filter_4, 0))    
        self.connect((self.band_pass_filter_0, 0), (self.analog_pll_refout_cc_0, 0))    
        self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_1, 1))    
        self.connect((self.band_pass_filter_1, 0), (self.blocks_multiply_xx_1, 0))    
        self.connect((self.band_pass_filter_1, 0), (self.qtgui_freq_sink_x_0_1_0_0, 1))    
        self.connect((self.blks2_selector_0, 0), (self.audio_sink_0, 0))    
        self.connect((self.blks2_selector_0_0, 0), (self.audio_sink_0, 1))    
        self.connect((self.blocks_add_const_vxx_0, 0), (self.qtgui_time_sink_x_1, 1))    
        self.connect((self.blocks_add_const_vxx_0_0, 0), (self.qtgui_time_sink_x_1, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.analog_fm_deemph_0_0_0_0, 0))    
        self.connect((self.blocks_complex_to_real_0, 0), (self.digital_binary_slicer_fb_0, 0))    
        self.connect((self.blocks_complex_to_real_1, 0), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.blocks_complex_to_real_1, 0), (self.blocks_multiply_xx_0, 1))    
        self.connect((self.blocks_complex_to_real_1, 0), (self.qtgui_freq_sink_x_0_1_0_0, 0))    
        self.connect((self.blocks_complex_to_real_1, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_uchar_to_float_0, 0))    
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.digital_diff_decoder_bb_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blks2_selector_0, 1))    
        self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.qtgui_freq_sink_x_0_1_0_1, 1))    
        self.connect((self.blocks_multiply_const_vxx_1_0_0, 0), (self.blks2_selector_0_0, 1))    
        self.connect((self.blocks_multiply_const_vxx_1_0_0, 0), (self.qtgui_freq_sink_x_0_1_0_1_0, 1))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1, 0), (self.blks2_selector_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1, 0), (self.blks2_selector_0_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1, 0), (self.qtgui_freq_sink_x_0_0_0, 1))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1_0, 0), (self.qtgui_freq_sink_x_0_0_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1_0_0, 0), (self.qtgui_freq_sink_x_0_1_0_1, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0_1_0_1, 0), (self.qtgui_freq_sink_x_0_1_0_1_0, 0))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.band_pass_filter_1, 0))    
        self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_2, 0))    
        self.connect((self.blocks_sub_xx_0, 0), (self.analog_fm_deemph_0_0_0, 0))    
        self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_add_const_vxx_0_0, 0))    
        self.connect((self.blocks_uchar_to_float_0_0, 0), (self.blocks_add_const_vxx_0, 0))    
        self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_keep_one_in_n_0, 0))    
        self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_uchar_to_float_0_0, 0))    
        self.connect((self.digital_diff_decoder_bb_0, 0), (self.gr_rds_decoder_0, 0))    
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_complex_to_real_0, 0))    
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.qtgui_const_sink_x_0, 0))    
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.qtgui_freq_sink_x_1, 0))    
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.root_raised_cosine_filter_0, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.analog_wfm_rcv_0, 0))    
        self.connect((self.low_pass_filter_1, 0), (self.analog_fm_deemph_0_0_0_1, 0))    
        self.connect((self.low_pass_filter_1, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.low_pass_filter_1, 0), (self.blocks_sub_xx_0, 0))    
        self.connect((self.low_pass_filter_2, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.low_pass_filter_2, 0), (self.blocks_sub_xx_0, 1))    
        self.connect((self.low_pass_filter_4, 0), (self.band_pass_filter_0, 0))    
        self.connect((self.low_pass_filter_4, 0), (self.band_pass_filter_0_0, 0))    
        self.connect((self.low_pass_filter_4, 0), (self.freq_xlating_fir_filter_xxx_1, 0))    
        self.connect((self.low_pass_filter_4, 0), (self.low_pass_filter_1, 0))    
        self.connect((self.low_pass_filter_4, 0), (self.qtgui_freq_sink_x_0_0, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.blocks_multiply_const_vxx_1_0, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.blocks_multiply_const_vxx_1_0_1_0_0, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0_0, 0), (self.blocks_multiply_const_vxx_1_0_0, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0_0, 0), (self.blocks_multiply_const_vxx_1_0_1_0_1, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0_1, 0), (self.blocks_multiply_const_vxx_1_0_1, 0))    
        self.connect((self.rational_resampler_xxx_0_0_0_1, 0), (self.blocks_multiply_const_vxx_1_0_1_0, 0))    
        self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_mpsk_receiver_cc_0, 0))    
        self.connect((self.root_raised_cosine_filter_0, 0), (self.qtgui_freq_sink_x_1, 1))    
        self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0))    
Exemplo n.º 10
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

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

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 240000
        self.fm = fm = 0.5
        self.fc = fc = 10000
        self.Df = Df = 1000
        self.An = An = 0
        self.Am = Am = 1

        ##################################################
        # Blocks
        ##################################################
        self._fc_range = Range(1000, 20000, 1000, 10000, 200)
        self._fc_win = RangeWidget(self._fc_range, self.set_fc, "fc", "counter_slider", float)
        self.top_layout.addWidget(self._fc_win)
        self._Df_range = Range(500, 2000, 100, 1000, 200)
        self._Df_win = RangeWidget(self._Df_range, self.set_Df, "Df", "counter_slider", float)
        self.top_layout.addWidget(self._Df_win)
        self._An_range = Range(0, 5, 0.5, 0, 200)
        self._An_win = RangeWidget(self._An_range, self.set_An, "An", "counter_slider", float)
        self.top_layout.addWidget(self._An_win)
        self._Am_range = Range(0, 10, 0.5, 1, 200)
        self._Am_win = RangeWidget(self._Am_range, self.set_Am, "Am", "counter_slider", float)
        self.top_layout.addWidget(self._Am_win)
        self.v = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1, Am, 0)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
        	1024, #size
        	samp_rate, #samp_rate
        	"", #name
        	2 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        
        self.qtgui_time_sink_x_0.set_y_label("Amplitude", "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        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_control_panel(True)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["Re{s(t)}", "Im{s(t)}", "Re{c(t)}", "Im{c(t)}", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 2, 1, 2, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(2*2):
            if len(labels[i]) == 0:
                if(i % 2 == 0):
                    self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                else:
                    self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	4096, #size
        	firdes.WIN_RECTANGULAR, #wintype
        	0, #fc
        	samp_rate, #bw
        	"", #name
        	2 #number of inputs
        )
        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_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_control_panel(True)
        
        if not True:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if "complex" == "float" or "complex" == "msg_float":
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
        
        labels = ["S(f)", "C(f)", "", "", "",
                  "", "", "", "", ""]
        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 xrange(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.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self._fm_range = Range(0, 1, 0.02, 0.5, 200)
        self._fm_win = RangeWidget(self._fm_range, self.set_fm, "fm", "counter_slider", float)
        self.top_layout.addWidget(self._fm_win)
        self.blocks_vco_c_0 = blocks.vco_c(samp_rate, 6283.1, 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, fc, 1, 0)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(0.0628318530717, (fc+Df)*0.0000261799387799, (fc-Df)*0.0000261799387799)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, An, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.analog_pll_refout_cc_0, 0), (self.qtgui_freq_sink_x_0, 1))    
        self.connect((self.analog_pll_refout_cc_0, 0), (self.qtgui_time_sink_x_0, 1))    
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))    
        self.connect((self.blocks_add_xx_0, 0), (self.analog_pll_refout_cc_0, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.qtgui_freq_sink_x_0, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_vco_c_0, 0))    
        self.connect((self.blocks_vco_c_0, 0), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.v, 0), (self.blocks_throttle_0, 0))    
Exemplo n.º 11
0
	def connect_audio_stage(self):
		demod_rate = self.demod_rate
		stereo_rate = self.post_demod_rate
		audio_rate = self.audio_rate
		normalizer = 2 * math.pi / stereo_rate
		pilot_tone = 19000
		pilot_low = pilot_tone * 0.9
		pilot_high = pilot_tone * 1.1

		def make_audio_filter():
			return grfilter.fir_filter_fff(
				1,  # decimation
				firdes.low_pass(
					1.0,
					stereo_rate,
					15000,
					5000,
					firdes.WIN_HAMMING))

		stereo_pilot_filter = grfilter.fir_filter_fcc(
			1,  # decimation
			firdes.complex_band_pass(
				1.0,
				stereo_rate,
				pilot_low,
				pilot_high,
				300))  # TODO magic number from gqrx
		stereo_pilot_pll = analog.pll_refout_cc(
			0.001,  # TODO magic number from gqrx
			normalizer * pilot_high,
			normalizer * pilot_low)
		stereo_pilot_doubler = blocks.multiply_cc()
		stereo_pilot_out = blocks.complex_to_imag()
		difference_channel_mixer = blocks.multiply_ff()
		difference_channel_filter = make_audio_filter()
		difference_real = blocks.complex_to_real(1)
		mono_channel_filter = make_audio_filter()
		resamplerL = self._make_resampler()
		resamplerR = self._make_resampler()
		mixL = blocks.add_ff(1)
		mixR = blocks.sub_ff(1)
		
		# connections
		if self.audio_filter:
			self.connect(self.demod_block, mono_channel_filter)
			mono = mono_channel_filter
		else:
			mono = self.demod_block

		if self.stereo:
			# stereo pilot tone tracker
			self.connect(
				self.demod_block,
				stereo_pilot_filter,
				stereo_pilot_pll)
			self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 0))
			self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 1))
			self.connect(stereo_pilot_doubler, stereo_pilot_out)
		
			# pick out stereo left-right difference channel
			self.connect(self.demod_block, (difference_channel_mixer, 0))
			self.connect(stereo_pilot_out, (difference_channel_mixer, 1))
			self.connect(difference_channel_mixer, difference_channel_filter)
		
			# recover left/right channels
			self.connect(difference_channel_filter, (mixL, 1))
			self.connect(difference_channel_filter, (mixR, 1))
			self.connect(mono, (mixL, 0), resamplerL)
			self.connect(mono, (mixR, 0), resamplerR)
			self.connect_audio_output(resamplerL, resamplerR)
		else:
			self.connect(mono, resamplerL)
			self.connect_audio_output(resamplerL, resamplerL)
Exemplo n.º 12
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.5e6
        self.decim = decim = 1
        self.post_decim = post_decim = samp_rate / decim
        self.freq_ctr2 = freq_ctr2 = 990e6
        self.freq_ctr1 = freq_ctr1 = 990e6
        self.cutoff = cutoff = 1e4 * 5

        ##################################################
        # Blocks
        ##################################################
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "1")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "2")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "3")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "4")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "5")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "6")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "7")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "8")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "9")
        self.Add(self.notebook_0)
        _freq_ctr1_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_ctr1_text_box = forms.text_box(
            parent=self.notebook_0.GetPage(0).GetWin(),
            sizer=_freq_ctr1_sizer,
            value=self.freq_ctr1,
            callback=self.set_freq_ctr1,
            label="center frequency",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._freq_ctr1_slider = forms.slider(
            parent=self.notebook_0.GetPage(0).GetWin(),
            sizer=_freq_ctr1_sizer,
            value=self.freq_ctr1,
            callback=self.set_freq_ctr1,
            minimum=989.1e6,
            maximum=990.1e6,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.notebook_0.GetPage(0).Add(_freq_ctr1_sizer)
        self.wxgui_scopesink2_1_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(3).GetWin(),
            title="Scope Plot",
            sample_rate=post_decim,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_1_0.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(2).GetWin(),
            title="Scope Plot",
            sample_rate=post_decim,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_1.win)
        self.wxgui_numbersink2_0_0_0_1 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="phase",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0_1.win)
        self.wxgui_numbersink2_0_0_0_0 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="error",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0_0.win)
        self.wxgui_numbersink2_0_0_0 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="freq",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0.win)
        self.wxgui_numbersink2_0_0 = numbersink2.number_sink_c(
            self.notebook_0.GetPage(1).GetWin(),
            unit="",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="signal",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=freq_ctr1,
            y_per_div=10,
            y_divs=5,
            ref_level=-10,
            ref_scale=2.0,
            sample_rate=samp_rate * 0 + post_decim,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.2,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=freq_ctr1,
            y_per_div=10,
            y_divs=5,
            ref_level=-10,
            ref_scale=2.0,
            sample_rate=samp_rate * 0 + post_decim,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.2,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.osmosdr_source_c_0 = osmosdr.source_c(args="nchan=" + str(1) + " " + "rtl=0,xtal=28.8e6,tuner_xtal=28.8e6")
        self.osmosdr_source_c_0.set_sample_rate(samp_rate)
        self.osmosdr_source_c_0.set_center_freq(freq_ctr1, 0)
        self.osmosdr_source_c_0.set_freq_corr(0, 0)
        self.osmosdr_source_c_0.set_iq_balance_mode(2, 0)
        self.osmosdr_source_c_0.set_gain_mode(1, 0)
        self.osmosdr_source_c_0.set_gain(0, 0)
        self.osmosdr_source_c_0.set_if_gain(0, 0)

        self.low_pass_filter_0 = gr.fir_filter_ccf(
            decim, firdes.low_pass(1, samp_rate, samp_rate / 4, samp_rate / 4, firdes.WIN_HAMMING, 6.76)
        )
        _freq_ctr2_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_ctr2_text_box = forms.text_box(
            parent=self.notebook_0.GetPage(4).GetWin(),
            sizer=_freq_ctr2_sizer,
            value=self.freq_ctr2,
            callback=self.set_freq_ctr2,
            label="center frequency",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._freq_ctr2_slider = forms.slider(
            parent=self.notebook_0.GetPage(4).GetWin(),
            sizer=_freq_ctr2_sizer,
            value=self.freq_ctr2,
            callback=self.set_freq_ctr2,
            minimum=989.1e6,
            maximum=990.1e6,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.notebook_0.GetPage(4).Add(_freq_ctr2_sizer)
        self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(2, 0.05, 512, 0.008)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(math.pi / 1000, 2, -2)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_scopesink2_1_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 2), (self.wxgui_numbersink2_0_0_0_1, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 3), (self.wxgui_numbersink2_0_0_0_0, 0))
        self.connect((self.osmosdr_source_c_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.digital_fll_band_edge_cc_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 1), (self.wxgui_numbersink2_0_0_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 0), (self.analog_pll_refout_cc_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_scopesink2_1, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_numbersink2_0_0, 0))
Exemplo n.º 13
0
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        # Menu Bar
        self.frame_1_menubar = wx.MenuBar()
        self.SetMenuBar(self.frame_1_menubar)
        wxglade_tmp_menu = wx.Menu()
        self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit",
                                wx.ITEM_NORMAL)
        wxglade_tmp_menu.AppendItem(self.Exit)
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
        # Menu Bar end
        self.panel_1 = wx.Panel(self, -1)
        self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB")
        self.button_2 = wx.Button(self, ID_BUTTON_2, "USB")
        self.button_3 = wx.Button(self, ID_BUTTON_3, "AM")
        self.button_4 = wx.Button(self, ID_BUTTON_4, "CW")
        self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper")
        self.slider_fcutoff_hi = wx.Slider(self,
                                           ID_SLIDER_1,
                                           0,
                                           -15798,
                                           15799,
                                           style=wx.SL_HORIZONTAL
                                           | wx.SL_LABELS)
        self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower")
        self.slider_fcutoff_lo = wx.Slider(self,
                                           ID_SLIDER_2,
                                           0,
                                           -15799,
                                           15798,
                                           style=wx.SL_HORIZONTAL
                                           | wx.SL_LABELS)
        self.panel_5 = wx.Panel(self, -1)
        self.label_1 = wx.StaticText(self, -1, " Band\nCenter")
        self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "")
        self.panel_6 = wx.Panel(self, -1)
        self.panel_7 = wx.Panel(self, -1)
        self.panel_2 = wx.Panel(self, -1)
        self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq")
        self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000)
        self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100)
        self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol")
        self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500)
        self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20)
        self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time")
        self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew")
        self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd")
        self.panel_3 = wx.Panel(self, -1)
        self.label_2 = wx.StaticText(self, -1, "PGA               ")
        self.panel_4 = wx.Panel(self, -1)
        self.panel_8 = wx.Panel(self, -1)
        self.panel_9 = wx.Panel(self, -1)
        self.panel_10 = wx.Panel(self, -1)
        self.panel_11 = wx.Panel(self, -1)
        self.panel_12 = wx.Panel(self, -1)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

        parser = OptionParser(option_class=eng_option)
        parser.add_option("",
                          "--args",
                          type="string",
                          default="addr=''",
                          help="Arguments for UHD device, [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default="A:0",
                          help="UHD device subdev spec, [default=%default]")
        parser.add_option("-c",
                          "--ddc-freq",
                          type="eng_float",
                          default=3.9e6,
                          help="set Rx DDC frequency to FREQ",
                          metavar="FREQ")
        parser.add_option(
            "-s",
            "--samp-rate",
            type="eng_float",
            default=256000,
            help="set sample rate (bandwidth) [default=%default]")
        parser.add_option("-a",
                          "--audio_file",
                          default="",
                          help="audio output file",
                          metavar="FILE")
        parser.add_option("-r",
                          "--radio_file",
                          default="",
                          help="radio output file",
                          metavar="FILE")
        parser.add_option("-i",
                          "--input_file",
                          default="",
                          help="radio input file",
                          metavar="FILE")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse")
        parser.add_option("",
                          "--audio-rate",
                          type="int",
                          default=32000,
                          help="audio output sample rate [default=%default]")

        (options, args) = parser.parse_args()

        self.usrp_center = options.ddc_freq
        self.input_rate = input_rate = options.samp_rate
        self.slider_range = input_rate * 0.9375
        self.f_lo = self.usrp_center - (self.slider_range / 2)
        self.f_hi = self.usrp_center + (self.slider_range / 2)
        self.af_sample_rate = options.audio_rate
        self.tb = gr.top_block()

        # radio variables, initial conditions
        self.frequency = self.usrp_center
        # these map the frequency slider (0-6000) to the actual range
        self.f_slider_offset = self.f_lo
        self.f_slider_scale = 10000 / 250
        self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi)
        self.text_ctrl_1.SetValue(str(int(self.usrp_center)))
        self.slider_5.SetValue(0)
        self.AM_mode = False

        self.slider_3.SetValue(
            (self.frequency - self.f_slider_offset) / self.f_slider_scale)
        self.spin_ctrl_1.SetValue(int(self.frequency))

        POWERMATE = True
        try:
            self.pm = powermate.powermate(self)
        except:
            sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n")
            POWERMATE = False

        if POWERMATE:
            powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate)
            powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton)
            self.active_button = 7

        # command line options
        if options.audio_file == "": SAVE_AUDIO_TO_FILE = False
        else: SAVE_AUDIO_TO_FILE = True
        if options.radio_file == "": SAVE_RADIO_TO_FILE = False
        else: SAVE_RADIO_TO_FILE = True
        if options.input_file == "": self.PLAY_FROM_USRP = True
        else: self.PLAY_FROM_USRP = False

        if self.PLAY_FROM_USRP:
            self.src = uhd.usrp_source(options.args,
                                       stream_args=uhd.stream_args('fc32'))
            self.src.set_samp_rate(input_rate)
            self.src.set_subdev_spec(options.spec)
            self.input_rate = input_rate = self.src.get_samp_rate()

            self.src.set_center_freq(self.usrp_center, 0)
            self.tune_offset = 0

            fir_decim = long(self.input_rate / self.af_sample_rate)
            rrate = self.af_sample_rate / (self.input_rate / float(fir_decim))

            print "Actual Input Rate: ", self.input_rate
            print "FIR DECIM: ", fir_decim
            print "Remaining resampling: ", rrate
            print "Sampling Rate at Audio Sink: ", (self.input_rate /
                                                    fir_decim) * rrate
            print "Request Rate at Audio Sink: ", self.af_sample_rate

        else:
            self.src = blocks.file_source(gr.sizeof_short, options.input_file)
            self.tune_offset = 2200  # 2200 works for 3.5-4Mhz band

            # convert rf data in interleaved short int form to complex
            s2ss = blocks.stream_to_streams(gr.sizeof_short, 2)
            s2f1 = blocks.short_to_float()
            s2f2 = blocks.short_to_float()
            src_f2c = blocks.float_to_complex()
            self.tb.connect(self.src, s2ss)
            self.tb.connect((s2ss, 0), s2f1)
            self.tb.connect((s2ss, 1), s2f2)
            self.tb.connect(s2f1, (src_f2c, 0))
            self.tb.connect(s2f2, (src_f2c, 1))

            fir_decim = long(self.input_rate / self.af_sample_rate)
            rrate = self.af_sample_rate / (self.input_rate / float(fir_decim))

            print "FIR DECIM: ", fir_decim
            print "Remaining resampling: ", rrate
            print "Sampling Rate at Audio Sink: ", (self.input_rate /
                                                    fir_decim) * rrate
            print "Request Rate at Audio Sink: ", self.af_sample_rate

        # save radio data to a file
        if SAVE_RADIO_TO_FILE:
            radio_file = blocks.file_sink(gr.sizeof_short, options.radio_file)
            self.tb.connect(self.src, radio_file)

        # 2nd DDC
        xlate_taps = filter.firdes.low_pass ( \
           1.0, input_rate, 16e3, 4e3, filter.firdes.WIN_HAMMING )
        self.xlate = filter.freq_xlating_fir_filter_ccf ( \
           fir_decim, xlate_taps, self.tune_offset, input_rate )

        nflts = 32
        audio_coeffs = filter.firdes.complex_band_pass(
            nflts,  # gain
            self.input_rate * nflts,  # sample rate
            -3000.0,  # low cutoff
            0.0,  # high cutoff
            100.0,  # transition
            filter.firdes.WIN_KAISER,
            7.0)  # window
        self.slider_fcutoff_hi.SetValue(0)
        self.slider_fcutoff_lo.SetValue(-3000)

        # Filter and resample based on actual radio's sample rate
        self.audio_filter = filter.pfb.arb_resampler_ccc(rrate, audio_coeffs)

        # Main +/- 16Khz spectrum display
        self.fft = fftsink2.fft_sink_c(self.panel_2,
                                       fft_size=512,
                                       sample_rate=self.af_sample_rate,
                                       average=True,
                                       size=(640, 240),
                                       baseband_freq=self.usrp_center)
        c2f = blocks.complex_to_float()

        # AM branch
        self.sel_am = blocks.multiply_const_cc(0)
        # the following frequencies turn out to be in radians/sample
        # analog.pll_refout_cc(alpha,beta,min_freq,max_freq)
        # suggested alpha = X, beta = .25 * X * X
        pll = analog.pll_refout_cc(
            .05, (2. * math.pi * 7.5e3 / self.af_sample_rate),
            (2. * math.pi * 6.5e3 / self.af_sample_rate))
        self.pll_carrier_scale = blocks.multiply_const_cc(complex(10, 0))
        am_det = blocks.multiply_cc()
        # these are for converting +7.5kHz to -7.5kHz
        # for some reason blocks.conjugate_cc() adds noise ??
        c2f2 = blocks.complex_to_float()
        c2f3 = blocks.complex_to_float()
        f2c = blocks.float_to_complex()
        phaser1 = blocks.multiply_const_ff(1)
        phaser2 = blocks.multiply_const_ff(-1)

        # filter for pll generated carrier
        pll_carrier_coeffs = filter.firdes.complex_band_pass(
            2.0,  # gain
            self.af_sample_rate,  # sample rate
            7400,  # low cutoff
            7600,  # high cutoff
            100,  # transition
            filter.firdes.WIN_HAMMING)  # window

        self.pll_carrier_filter = filter.fir_filter_ccc(1, pll_carrier_coeffs)

        self.sel_sb = blocks.multiply_const_ff(1)
        combine = blocks.add_ff()

        #AGC
        sqr1 = blocks.multiply_ff()
        intr = filter.iir_filter_ffd([.004, 0], [0, .999])
        offset = blocks.add_const_ff(1)
        agc = blocks.divide_ff()

        self.scale = blocks.multiply_const_ff(0.00001)
        dst = audio.sink(long(self.af_sample_rate), options.audio_output)

        if self.PLAY_FROM_USRP:
            self.tb.connect(self.src, self.xlate, self.fft)
        else:
            self.tb.connect(src_f2c, self.xlate, self.fft)

        self.tb.connect(self.xlate, self.audio_filter, self.sel_am,
                        (am_det, 0))
        self.tb.connect(self.sel_am, pll, self.pll_carrier_scale,
                        self.pll_carrier_filter, c2f3)
        self.tb.connect((c2f3, 0), phaser1, (f2c, 0))
        self.tb.connect((c2f3, 1), phaser2, (f2c, 1))
        self.tb.connect(f2c, (am_det, 1))
        self.tb.connect(am_det, c2f2, (combine, 0))
        self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1))

        self.tb.connect(combine, self.scale)
        self.tb.connect(self.scale, (sqr1, 0))
        self.tb.connect(self.scale, (sqr1, 1))
        self.tb.connect(sqr1, intr, offset, (agc, 1))
        self.tb.connect(self.scale, (agc, 0))
        self.tb.connect(agc, blocks.null_sink(gr.sizeof_float))
        self.tb.connect(c2f3, dst)

        if SAVE_AUDIO_TO_FILE:
            f_out = blocks.file_sink(gr.sizeof_short, options.audio_file)
            sc1 = blocks.multiply_const_ff(64000)
            f2s1 = blocks.float_to_short()
            self.tb.connect(agc, sc1, f2s1, f_out)

        self.tb.start()

        # left click to re-tune
        self.fft.win.plotter.Bind(wx.EVT_LEFT_DOWN, self.Click)

        # start a timer to check for web commands
        if WEB_CONTROL:
            self.timer = UpdateTimer(self, 1000)  # every 1000 mSec, 1 Sec

        wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb)
        wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb)
        wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am)
        wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw)
        wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd)
        wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button)
        wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter)
        wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter)
        wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune)
        wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume)
        wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga)
        wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune)

        wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
Exemplo n.º 14
0
    def __init__(self, param_samp_rate, param_freq, param_gain, address):
        grc_wxgui.top_block_gui.__init__(self, title="UHD FFT")

        ##################################################
        # Parameters
        ##################################################
        param_freq = 5.792e9
        self.if_freq = 960e6
        self.square_freq = 4e6
        self.num_steps = 32
        self.lo_start_freq = 5.312e9
        self.param_samp_rate = param_samp_rate
        self.param_freq = param_freq
        self.param_gain = param_gain
        self.address = address

        self.offset_freq = 10e3

        ##################################################
        # Variables
        ##################################################
        self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value(
            "", False, "")
        self.samp_rate = samp_rate = param_samp_rate
        self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool()
        self.gain = gain = param_gain
        self.freq = freq = param_freq
        self.ant = ant = "J1"
        self.test = options.test
        self.tofile = options.tofile

        ##################################################
        # Blocks
        ##################################################
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            label="RX Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            minimum=0,
            maximum=112.5,
            num_steps=225,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_sizer, 2, 0, 1, 8)
        if self.test == False:
            self.source = uhd.usrp_source(
                device_addr=address,
                stream_args=uhd.stream_args(
                    cpu_format="fc32",
                    channels=range(2),
                ),
            )

            #Channel 0
            self.source.set_subdev_spec("A:0 B:0")
            self.source.set_center_freq(freq, 0)
            self.source.set_gain(gain, 0)
            self.source.set_antenna(ant, 0)
            self.source.set_bandwidth(samp_rate, 0)

            #Channel 1
            g = self.source.get_gain_range(1)
            print "rx gain range is (%f,%f)" % (g.start(), g.stop())
            self.source.set_center_freq(self.if_freq, 1)  #Mixer @ 4992 MHz
            self.source.set_gain(g.stop(), 1)
            #self.source.set_antenna(ant, 1)
            self.source.set_bandwidth(36e6, 1)  #Need Turbo mode!

            self.source.set_samp_rate(samp_rate)

        else:
            self.source_pre = blocks.file_source(gr.sizeof_gr_complex,
                                                 "test.dat", True)
            self.source = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate)
            self.connect(self.source_pre, self.source)
            self.source_freqs_pre = blocks.file_source(gr.sizeof_gr_complex,
                                                       "test_freqs.dat", True)
            self.source_freqs = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                samp_rate)
            self.connect(self.source_freqs_pre, self.source_freqs)

        self.nb0 = self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "FFT")
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Waterfall")
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Scope")
        self.GridAdd(self.nb0, 0, 0, 1, 8)
        #        self.scopesink_0 = scopesink2.scope_sink_c(
        #        	self.nb0.GetPage(0).GetWin(),
        #        	title="Scope Plot",
        #        	sample_rate=samp_rate,
        #        	v_scale=0,
        #        	v_offset=0,
        #        	t_scale=0,
        #        	ac_couple=False,
        #        	xy_mode=False,
        #        	num_inputs=1,
        #        	trig_mode=wxgui.TRIG_MODE_AUTO,
        #        	y_axis_label="Counts",
        #        )
        #        self.nb0.GetPage(0).Add(self.scopesink_0.win)
        self.scopesink_0 = fftsink2.fft_sink_c(
            self.nb0.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=15,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
            size=((-1, 400)),
        )
        self.nb0.GetPage(0).Add(self.scopesink_0.win)

        self.scopesink_1 = scopesink2.scope_sink_c(
            self.nb0.GetPage(1).GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.nb0.GetPage(1).Add(self.scopesink_1.win)
        self.scopesink_2 = scopesink2.scope_sink_c(
            self.nb0.GetPage(2).GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.nb0.GetPage(2).Add(self.scopesink_2.win)

        ##################################################
        # Connections
        ##################################################

        #Actual demo code
        self.multiply_0 = blocks.multiply_vcc(1)
        self.multiply_1 = blocks.multiply_vcc(1)
        self.carrier_est = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE,
                                               100000, 1, 0)
        self.subcarrier_est = analog.sig_source_c(samp_rate,
                                                  analog.GR_COS_WAVE, -300000,
                                                  1, 0)
        chan_coeffs = filter.firdes.low_pass(1.0, 1.0, 0.05, 0.05,
                                             filter.firdes.WIN_HANN)
        self.carrier_tracking_filter = filter.fft_filter_ccc(1, chan_coeffs)
        self.carrier_tracking = analog.pll_refout_cc(0.0003, .15, -.15)
        self.carrier_tracking_conj = blocks.conjugate_cc()
        self.subcarrier_tracking_filter = filter.fft_filter_ccc(1, chan_coeffs)
        self.subcarrier_tracking = analog.pll_carriertracking_cc(
            0.0005, .001, -0.001)
        self.stitcher = fast_square.freq_stitcher("cal.dat", 14 * 4)

        if self.test == True:
            self.connect(self.source_freqs, self.stitcher)
        else:
            if self.tofile == True:
                self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex,
                                                 "usrp_chan0.dat")
                self.connect((self.source, 0), self.logfile0)
                self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex,
                                                 "usrp_chan1.dat")
                self.connect((self.source, 1), self.logfile1)
            self.connect((self.source, 1), self.stitcher)

        self.connect((self.source, 0), (self.multiply_0, 0))
        self.connect(self.carrier_est, (self.multiply_0, 1))
        self.connect(self.multiply_0, self.carrier_tracking_filter,
                     self.carrier_tracking, self.carrier_tracking_conj)
        self.connect(self.carrier_tracking_conj, (self.multiply_1, 0))
        self.connect((self.source, 0), (self.multiply_1, 1))
        self.connect(self.subcarrier_est, (self.multiply_1, 2))
        self.connect(self.multiply_1, self.subcarrier_tracking_filter,
                     self.subcarrier_tracking)

        #	self.connect((self.source, 0), self.scopesink_0)
        self.connect(self.multiply_1, self.scopesink_0)
        self.connect(self.subcarrier_tracking, self.scopesink_1)

        #	self.connect(self.subcarrier_tracking, self.scopesink_2)

        def _freq_tracker():
            loop_count = 0
            while True:
                loop_count = loop_count + 1

                #TODO: Is this whole calculation section correct?
                carrier_freq = self.carrier_tracking.get_frequency(
                ) / 2 / math.pi * self.samp_rate
                subcarrier_freq = self.subcarrier_tracking.get_frequency(
                ) / 2 / math.pi * self.samp_rate

                print "carrier_freq = %f, \t subcarrier_freq = %f" % (
                    carrier_freq, subcarrier_freq)

                #TODO: DEBUG ONLY
                #if loop_count > 100:
                #	print "GOING DOWN"
                #	#carrier_freq = self.offset_freq
                #	carrier_freq = carrier_freq + self.offset_freq
                #	self.offset_freq = self.offset_freq - 1e2

                #Translate to absolute frequency
                carrier_freq = self.param_freq + carrier_freq - 100e3
                subcarrier_freq = self.square_freq + subcarrier_freq

                #Figure out what harmonic we will be centered on
                next_harmonic = math.ceil(
                    ((self.lo_start_freq + self.if_freq) -
                     (self.param_freq + self.square_freq)) / self.square_freq /
                    2)
                next_harmonic_freq = self.param_freq + self.square_freq + next_harmonic * self.square_freq * 2
                target_freq = next_harmonic_freq - self.square_freq
                actual_freq = carrier_freq + next_harmonic * subcarrier_freq * 2
                carrier_mixer_freq = -(actual_freq - target_freq)
                subcarrier_mixer_freq = subcarrier_freq

                carrier_reg = carrier_mixer_freq / 64e6
                if carrier_reg < 0:
                    carrier_reg = carrier_reg + 1.0
                carrier_reg = int(carrier_reg * (2**32))
                if self.test == False:
                    self.source.set_user_register(
                        64 + 0,
                        carrier_reg)  #Write to FR_USER_0 (Carrier offset reg)

                subcarrier_reg = subcarrier_mixer_freq / 64e6  #Subcarrier freq register is absolute freq, not error
                subcarrier_reg = int(subcarrier_reg * (2**32))
                if self.test == False:
                    self.source.set_user_register(
                        64 + 1, subcarrier_reg
                    )  #Write to FR_USER_1 (Subcarrier freq reg)

                freq_step = ((self.square_freq - subcarrier_freq) * 8) / 64e6
                if freq_step < 0:
                    freq_step = freq_step + 1.0
                freq_step_reg = int(freq_step * (2**32))
                if self.test == False:
                    self.source.set_user_register(64 + 2, freq_step_reg)

                print "carrier_freq = %f, \t subcarrier_freq = %f, \t freq_step = %f, \t carrier_reg = %d, \t subcarrier_reg = %d, \t freq_step_reg = %d" % (
                    carrier_freq, subcarrier_freq, freq_step, carrier_reg,
                    subcarrier_reg, freq_step_reg)

                time.sleep(1.0 / (10))

        _freq_tracker_thread = threading.Thread(target=_freq_tracker)
        _freq_tracker_thread.daemon = True
        _freq_tracker_thread.start()
Exemplo n.º 15
0
    def __init__ (self, demod_rate, audio_decimation):
        """
        Hierarchical block for demodulating a broadcast FM signal.

        The input is the downconverted complex baseband signal
        (gr_complex).  The output is two streams of the demodulated
        audio (float) 0=Left, 1=Right.

        Args:
            demod_rate: input sample rate of complex baseband input. (float)
            audio_decimation: how much to decimate demod_rate to get to audio. (integer)
        """
	gr.hier_block2.__init__(self, "wfm_rcv_fmdet",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(2, 2, gr.sizeof_float))      # Output signature
        lowfreq = -125e3/demod_rate
	highfreq = 125e3/demod_rate
        audio_rate = demod_rate / audio_decimation

        # We assign to self so that outsiders can grab the demodulator
        # if they need to.  E.g., to plot its output.
        #
        # input: complex; output: float

        self.fm_demod = analog.fmdet_cf(demod_rate, lowfreq, highfreq, 0.05)

        # input: float; output: float
        self.deemph_Left  = fm_deemph(audio_rate)
        self.deemph_Right = fm_deemph(audio_rate)

        # compute FIR filter taps for audio filter
        width_of_transition_band = audio_rate / 32
        audio_coeffs = filter.firdes.low_pass(1.0 ,         # gain
                                              demod_rate,   # sampling rate
                                              15000 ,
                                              width_of_transition_band,
                                              filter.firdes.WIN_HAMMING)

        # input: float; output: float
        self.audio_filter = filter.fir_filter_fff(audio_decimation, audio_coeffs)
        if 1:
            # Pick off the stereo carrier/2 with this filter. It
            # attenuated 10 dB so apply 10 dB gain We pick off the
            # negative frequency half because we want to base band by
            # it!
            ##  NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO
            ##  DEEMPHASIS

            stereo_carrier_filter_coeffs = \
                filter.firdes.complex_band_pass(10.0,
                                                demod_rate,
                                                -19020,
                                                -18980,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)

            #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs)
            #print "stereo carrier filter ", stereo_carrier_filter_coeffs
            #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate

            # Pick off the double side band suppressed carrier
            # Left-Right audio. It is attenuated 10 dB so apply 10 dB
            # gain

            stereo_dsbsc_filter_coeffs = \
                filter.firdes.complex_band_pass(20.0,
                                                demod_rate,
                                                38000-15000/2,
                                                38000+15000/2,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)
            #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
            #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs

            # construct overlap add filter system from coefficients
            # for stereo carrier
            self.stereo_carrier_filter = \
                filter.fir_filter_fcc(audio_decimation,
                                      stereo_carrier_filter_coeffs)

            # carrier is twice the picked off carrier so arrange to do
            # a commplex multiply
            self.stereo_carrier_generator = blocks.multiply_cc();

            # Pick off the rds signal
            stereo_rds_filter_coeffs = \
                filter.firdes.complex_band_pass(30.0,
                                                demod_rate,
                                                57000 - 1500,
                                                57000 + 1500,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)
            #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
            #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs
            # construct overlap add filter system from coefficients for stereo carrier

	    self.rds_signal_filter = \
                filter.fir_filter_fcc(audio_decimation,
                                      stereo_rds_filter_coeffs)
	    self.rds_carrier_generator = blocks.multiply_cc();
	    self.rds_signal_generator = blocks.multiply_cc();
	    self_rds_signal_processor = blocks.null_sink(gr.sizeof_gr_complex);

            loop_bw = 2*math.pi/100.0
            max_freq = -2.0*math.pi*18990/audio_rate;
            min_freq = -2.0*math.pi*19010/audio_rate;
            self.stereo_carrier_pll_recovery = analog.pll_refout_cc(loop_bw,
                                                                    max_freq,
                                                                    min_freq);

            #self.stereo_carrier_pll_recovery.squelch_enable(False)
            ##pll_refout does not have squelch yet, so disabled for
            #now

            # set up mixer (multiplier) to get the L-R signal at
            # baseband

            self.stereo_basebander = blocks.multiply_cc();

            # pick off the real component of the basebanded L-R
            # signal.  The imaginary SHOULD be zero

            self.LmR_real = blocks.complex_to_real();
            self.Make_Left = blocks.add_ff();
            self.Make_Right = blocks.sub_ff();

            self.stereo_dsbsc_filter = \
                filter.fir_filter_fcc(audio_decimation,
                                      stereo_dsbsc_filter_coeffs)


        if 1:

            # send the real signal to complex filter to pick off the
            # carrier and then to one side of a multiplier
            self.connect(self, self.fm_demod, self.stereo_carrier_filter,
                         self.stereo_carrier_pll_recovery,
                         (self.stereo_carrier_generator,0))

            # send the already filtered carrier to the otherside of the carrier
            # the resulting signal from this multiplier is the carrier
            # with correct phase but at -38000 Hz.
            self.connect(self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1))

            # send the new carrier to one side of the mixer (multiplier)
            self.connect(self.stereo_carrier_generator, (self.stereo_basebander,0))

            # send the demphasized audio to the DSBSC pick off filter,  the complex
            # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier
            # the result is BASEBANDED DSBSC with phase zero!
            self.connect(self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1))

            # Pick off the real part since the imaginary is
            # theoretically zero and then to one side of a summer
            self.connect(self.stereo_basebander, self.LmR_real, (self.Make_Left,0))

            #take the same real part of the DSBSC baseband signal and
            #send it to negative side of a subtracter
            self.connect(self.LmR_real,(self.Make_Right,1))

	    # Make rds carrier by taking the squared pilot tone and
	    # multiplying by pilot tone
	    self.connect(self.stereo_basebander,(self.rds_carrier_generator,0))
            self.connect(self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1))

	    # take signal, filter off rds, send into mixer 0 channel
	    self.connect(self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0))

            # take rds_carrier_generator output and send into mixer 1
            # channel
	    self.connect(self.rds_carrier_generator,(self.rds_signal_generator,1))

	    # send basebanded rds signal and send into "processor"
	    # which for now is a null sink
	    self.connect(self.rds_signal_generator,self_rds_signal_processor)


        if 1:
            # pick off the audio, L+R that is what we used to have and
            # send it to the summer
            self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1))

            # take the picked off L+R audio and send it to the PLUS
            # side of the subtractor
            self.connect(self.audio_filter,(self.Make_Right, 0))

            # The result of  Make_Left  gets    (L+R) +  (L-R) and results in 2*L
            # The result of Make_Right gets  (L+R) - (L-R) and results in 2*R
            self.connect(self.Make_Left , self.deemph_Left, (self, 0))
            self.connect(self.Make_Right, self.deemph_Right, (self, 1))
Exemplo n.º 16
0
    def __init__(self):
        gr.top_block.__init__(self, "Not titled yet")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Not titled yet")
        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", "gnuAM")

        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.samp_rate = samp_rate = 10e6
        self.carrier_min_freq = carrier_min_freq = 995e3
        self.carrier_max_freq = carrier_max_freq = 1005e3
        self.taps_LP = taps_LP = firdes.low_pass(1.0, samp_rate, 1e3, 2e3,
                                                 firdes.WIN_HAMMING, 6.76)
        self.taps_BP_PLL = taps_BP_PLL = firdes.band_pass(
            1.0, samp_rate, carrier_min_freq, carrier_max_freq, 10e3,
            firdes.WIN_HAMMING, 6.76)

        ##################################################
        # Blocks
        ##################################################
        self.views = Qt.QTabWidget()
        self.views_widget_0 = Qt.QWidget()
        self.views_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                            self.views_widget_0)
        self.views_grid_layout_0 = Qt.QGridLayout()
        self.views_layout_0.addLayout(self.views_grid_layout_0)
        self.views.addTab(self.views_widget_0, 'Señal recibida')
        self.views_widget_1 = Qt.QWidget()
        self.views_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                            self.views_widget_1)
        self.views_grid_layout_1 = Qt.QGridLayout()
        self.views_layout_1.addLayout(self.views_grid_layout_1)
        self.views.addTab(self.views_widget_1, 'Envolvente')
        self.views_widget_2 = Qt.QWidget()
        self.views_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                            self.views_widget_2)
        self.views_grid_layout_2 = Qt.QGridLayout()
        self.views_layout_2.addLayout(self.views_grid_layout_2)
        self.views.addTab(self.views_widget_2, 'Sincronico')
        self.top_grid_layout.addWidget(self.views)
        self.qtgui_time_sink_x_1_0 = qtgui.time_sink_c(
            4096,  #size
            samp_rate,  #samp_rate
            "Señal en tiempo",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_1_0.set_update_time(0.10)
        self.qtgui_time_sink_x_1_0.set_y_axis(-2, 2)

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

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

        labels = [
            'Real', 'Imag', '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_1_0.set_line_label(
                        i, "Re{{Data {0}}}".format(i / 2))
                else:
                    self.qtgui_time_sink_x_1_0.set_line_label(
                        i, "Im{{Data {0}}}".format(i / 2))
            else:
                self.qtgui_time_sink_x_1_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_1_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_1_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_1_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_1_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_1_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_1_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_1_0.pyqwidget(), Qt.QWidget)
        self.views_layout_2.addWidget(self._qtgui_time_sink_x_1_0_win)
        self.qtgui_time_sink_x_1 = qtgui.time_sink_c(
            2048,  #size
            samp_rate,  #samp_rate
            "Señal en tiempo",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_1.set_update_time(0.10)
        self.qtgui_time_sink_x_1.set_y_axis(-2, 2)

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

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

        labels = [
            'Real', 'Imag', '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_1.set_line_label(
                        i, "Re{{Data {0}}}".format(i / 2))
                else:
                    self.qtgui_time_sink_x_1.set_line_label(
                        i, "Im{{Data {0}}}".format(i / 2))
            else:
                self.qtgui_time_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_1_win = sip.wrapinstance(
            self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget)
        self.views_layout_0.addWidget(self._qtgui_time_sink_x_1_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #samp_rate
            "Mensaje recuperado",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)

        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, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0.enable_stem_plot(False)

        labels = [
            'msg', '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.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.views_layout_1.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_1 = qtgui.freq_sink_f(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Espectro del mensaje",  #name
            1)
        self.qtgui_freq_sink_x_1.set_update_time(0.10)
        self.qtgui_freq_sink_x_1.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_1.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0,
                                                  "")
        self.qtgui_freq_sink_x_1.enable_autoscale(False)
        self.qtgui_freq_sink_x_1.enable_grid(False)
        self.qtgui_freq_sink_x_1.set_fft_average(1.0)
        self.qtgui_freq_sink_x_1.enable_axis_labels(True)
        self.qtgui_freq_sink_x_1.enable_control_panel(False)

        self.qtgui_freq_sink_x_1.set_plot_pos_half(not 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"
        ]
        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_1.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_1_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget)
        self.views_layout_1.addWidget(self._qtgui_freq_sink_x_1_win)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Espectro de la Señal",  #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.views_layout_2.addWidget(self._qtgui_freq_sink_x_0_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Espectro de la Señal",  #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.views_layout_0.addWidget(self._qtgui_freq_sink_x_0_win)
        self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(
            1, taps_BP_PLL)
        self.interp_fir_filter_xxx_0.declare_sample_delay(0)
        self.fir_filter_xxx_1 = filter.fir_filter_ccc(1, taps_LP)
        self.fir_filter_xxx_1.declare_sample_delay(0)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1,
            '/home/fran/Documents/UCA/4to año/Radiodifusión/git/Radiodifusion/TP1/Parte2/TPAMb.dat',
            True, 0, 0)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            np.pi / 200, 2 * np.pi * (carrier_max_freq / samp_rate),
            2 * np.pi * (carrier_min_freq / samp_rate))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.qtgui_freq_sink_x_1, 0))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.fir_filter_xxx_1, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.interp_fir_filter_xxx_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.qtgui_time_sink_x_1, 0))
        self.connect((self.fir_filter_xxx_1, 0),
                     (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.fir_filter_xxx_1, 0),
                     (self.qtgui_time_sink_x_1_0, 0))
        self.connect((self.interp_fir_filter_xxx_0, 0),
                     (self.analog_pll_refout_cc_0, 0))
Exemplo n.º 17
0
    def __init__(self, demod_rate, audio_decimation, deemph_tau):
        """
        Hierarchical block for demodulating a broadcast FM signal.

        The input is the downconverted complex baseband signal (gr_complex).
        The output is two streams of the demodulated audio (float) 0=Left, 1=Right.

        Args:
            demod_rate: input sample rate of complex baseband input. (float)
            audio_decimation: how much to decimate demod_rate to get to audio. (integer)
            deemph_tau: deemphasis ime constant in seconds (75us in US, 50us in EUR). (float)
        """
        gr.hier_block2.__init__(self, "wfm_rcv_pll",
                                # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(2, 2, gr.sizeof_float))      # Output signature

        if audio_decimation != int(audio_decimation):
            raise ValueError("audio_decimation needs to be an integer")
        audio_decimation = int(audio_decimation)

        ##################################################
        # Variables
        ##################################################
        self.demod_rate = demod_rate
        self.deemph_tau = deemph_tau
        self.stereo_carrier_filter_coeffs = stereo_carrier_filter_coeffs = firdes.band_pass(
            -2.0, demod_rate, 37600, 38400, 400, fft.window.WIN_HAMMING, 6.76)
        self.pilot_carrier_filter_coeffs = pilot_carrier_filter_coeffs = firdes.complex_band_pass(
            1.0, demod_rate, 18980, 19020, 1500, fft.window.WIN_HAMMING, 6.76)
        self.deviation = deviation = 75000
        self.audio_filter_coeffs = audio_filter_coeffs = firdes.low_pass(
            1, demod_rate, 15000, 1500, fft.window.WIN_HAMMING, 6.76)
        self.audio_decim = audio_decim = audio_decimation
        self.audio_rate = audio_rate = demod_rate / audio_decim
        self.samp_delay = samp_delay = (len(
            pilot_carrier_filter_coeffs) - 1) // 2 + (len(stereo_carrier_filter_coeffs) - 1) // 2

        ##################################################
        # Blocks
        ##################################################
        self.pilot_carrier_bpf = filter.fir_filter_fcc(
            1, pilot_carrier_filter_coeffs)
        self.pilot_carrier_bpf.declare_sample_delay(0)
        self.stereo_carrier_bpf = filter.fft_filter_fff(
            1, stereo_carrier_filter_coeffs, 1)
        self.stereo_carrier_bpf.declare_sample_delay(0)
        self.stereo_audio_lpf = filter.fft_filter_fff(
            audio_decim, audio_filter_coeffs, 1)
        self.stereo_audio_lpf.declare_sample_delay(0)
        self.mono_audio_lpf = filter.fft_filter_fff(
            audio_decim, audio_filter_coeffs, 1)
        self.mono_audio_lpf.declare_sample_delay(0)
        self.blocks_stereo_multiply = blocks.multiply_ff(1)
        self.blocks_pilot_multiply = blocks.multiply_cc(1)
        self.blocks_complex_to_imag = blocks.complex_to_imag(1)
        self.blocks_right_sub = blocks.sub_ff(1)
        self.blocks_left_add = blocks.add_ff(1)
        self.analog_quadrature_demod_cf = analog.quadrature_demod_cf(
            demod_rate / (2 * math.pi * deviation))
        self.analog_pll_refout_cc = analog.pll_refout_cc(
            0.001, 2 * math.pi * 19200 / demod_rate, 2 * math.pi * 18800 / demod_rate)
        self.analog_right_fm_deemph = analog.fm_deemph(
            fs=audio_rate, tau=deemph_tau)
        self.analog_left_fm_deemph = analog.fm_deemph(
            fs=audio_rate, tau=deemph_tau)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, samp_delay)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_left_fm_deemph, 0), (self, 0))
        self.connect((self.analog_right_fm_deemph, 0), (self, 1))
        self.connect((self.analog_pll_refout_cc, 0),
                     (self.blocks_pilot_multiply, 1))
        self.connect((self.analog_pll_refout_cc, 0),
                     (self.blocks_pilot_multiply, 0))
        self.connect((self.analog_quadrature_demod_cf, 0),
                     (self.blocks_delay_0, 0))
        self.connect((self.blocks_delay_0, 0),
                     (self.blocks_stereo_multiply, 0))
        self.connect((self.blocks_delay_0, 0), (self.mono_audio_lpf, 0))
        self.connect((self.analog_quadrature_demod_cf, 0),
                     (self.pilot_carrier_bpf, 0))
        self.connect((self.blocks_left_add, 0),
                     (self.analog_left_fm_deemph, 0))
        self.connect((self.blocks_right_sub, 0),
                     (self.analog_right_fm_deemph, 0))
        self.connect((self.blocks_complex_to_imag, 0),
                     (self.stereo_carrier_bpf, 0))
        self.connect((self.blocks_pilot_multiply, 0),
                     (self.blocks_complex_to_imag, 0))
        self.connect((self.blocks_stereo_multiply, 0),
                     (self.stereo_audio_lpf, 0))  # L - R path
        self.connect((self.mono_audio_lpf, 0), (self.blocks_left_add, 1))
        self.connect((self.mono_audio_lpf, 0), (self.blocks_right_sub, 0))
        self.connect((self.stereo_audio_lpf, 0), (self.blocks_left_add, 0))
        self.connect((self.stereo_audio_lpf, 0), (self.blocks_right_sub, 1))
        self.connect((self.stereo_carrier_bpf, 0),
                     (self.blocks_stereo_multiply, 1))
        self.connect((self.pilot_carrier_bpf, 0),
                     (self.analog_pll_refout_cc, 0))
        self.connect((self, 0), (self.analog_quadrature_demod_cf, 0))
Exemplo n.º 18
0
    def __init__(self):
        gr.top_block.__init__(self, "Stereo Fm")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Stereo Fm")
        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", "stereo_fm")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.demod_rate = demod_rate = 192000
        self.audio_decimation = audio_decimation = 4
        self.audio_rate = audio_rate = demod_rate / audio_decimation
        self.width_of_transition_band = width_of_transition_band = audio_rate / 32
        self.volume = volume = 1
        self.stereo_carr_loop_bw = stereo_carr_loop_bw = 2.0 * math.pi * 10 / 100
        self.samp_rate = samp_rate = 1000e3
        self.range1 = range1 = 88.1
        self.max_freq = max_freq = 2.0 * math.pi * (80) * 1e3 / demod_rate
        self.loop_bw = loop_bw = 2.0 * math.pi * 28 / 100

        ##################################################
        # Blocks
        ##################################################
        self._range1_layout = Qt.QVBoxLayout()
        self._range1_tool_bar = Qt.QToolBar(self)
        self._range1_layout.addWidget(self._range1_tool_bar)
        self._range1_tool_bar.addWidget(Qt.QLabel("Tune" + ": "))

        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)

            @pyqtSlot("double")
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)

        self._range1_counter = qwt_counter_pyslot()
        self._range1_counter.setRange(88, 108, 0.1)
        self._range1_counter.setNumButtons(2)
        self._range1_counter.setValue(self.range1)
        self._range1_tool_bar.addWidget(self._range1_counter)
        self._range1_counter.valueChanged.connect(self.set_range1)
        self._range1_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._range1_slider.setRange(88, 108, 0.1)
        self._range1_slider.setValue(self.range1)
        self._range1_slider.setMinimumWidth(200)
        self._range1_slider.valueChanged.connect(self.set_range1)
        self._range1_layout.addWidget(self._range1_slider)
        self.top_layout.addLayout(self._range1_layout)
        self._volume_layout = Qt.QVBoxLayout()
        self._volume_tool_bar = Qt.QToolBar(self)
        self._volume_layout.addWidget(self._volume_tool_bar)
        self._volume_tool_bar.addWidget(Qt.QLabel("Volume" + ": "))

        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)

            @pyqtSlot("double")
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)

        self._volume_counter = qwt_counter_pyslot()
        self._volume_counter.setRange(0.000001, 100, 0.01)
        self._volume_counter.setNumButtons(2)
        self._volume_counter.setValue(self.volume)
        self._volume_tool_bar.addWidget(self._volume_counter)
        self._volume_counter.valueChanged.connect(self.set_volume)
        self._volume_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._volume_slider.setRange(0.000001, 100, 0.01)
        self._volume_slider.setValue(self.volume)
        self._volume_slider.setMinimumWidth(200)
        self._volume_slider.valueChanged.connect(self.set_volume)
        self._volume_layout.addWidget(self._volume_slider)
        self.top_layout.addLayout(self._volume_layout)
        self.stereo_carrier_pll_recovery = analog.pll_refout_cc(
            stereo_carr_loop_bw, -2.0 * math.pi * 18990 / demod_rate, -2.0 * math.pi * 19010 / demod_rate
        )
        self.stereo_carrier__filter = filter.fir_filter_fcc(
            1,
            firdes.complex_band_pass(1, demod_rate, -19020, -18980, width_of_transition_band, firdes.WIN_HAMMING, 6.76),
        )
        self.stereo_carr_gen = blocks.multiply_vcc(1)
        self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True, output_size=gr.sizeof_gr_complex)
        self.rtl2832_source_0.set_verbose(True)
        self.rtl2832_source_0.set_vid(0x0)
        self.rtl2832_source_0.set_pid(0x0)
        self.rtl2832_source_0.set_tuner_name("")
        self.rtl2832_source_0.set_default_timeout(0)
        self.rtl2832_source_0.set_use_buffer(True)
        self.rtl2832_source_0.set_fir_coefficients(([]))

        self.rtl2832_source_0.set_read_length(0)

        if self.rtl2832_source_0.create() == False:
            raise Exception("Failed to create RTL2832 Source: rtl2832_source_0")

        self.rtl2832_source_0.set_sample_rate(samp_rate)

        self.rtl2832_source_0.set_frequency(range1 * 1e6)

        self.rtl2832_source_0.set_auto_gain_mode(True)
        self.rtl2832_source_0.set_relative_gain(True)
        self.rtl2832_source_0.set_gain(1)

        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(
            1, firdes.root_raised_cosine(1, 192000, 2375 / 2, 0.4, 100)
        )
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
            interpolation=demod_rate, decimation=int(samp_rate), taps=None, fractional_bw=None
        )
        self.qtgui_const_sink_x_1 = qtgui.const_sink_c(1024, "", 1)  # size  # name  # number of inputs
        self.qtgui_const_sink_x_1.set_update_time(0.10)
        self.qtgui_const_sink_x_1.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_1.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.qtgui_const_sink_x_1.enable_autoscale(True)
        self.qtgui_const_sink_x_1.enable_grid(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, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [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 xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_1.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_1.set_line_alpha(i, alphas[i])

        self._qtgui_const_sink_x_1_win = sip.wrapinstance(self.qtgui_const_sink_x_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_1_win)
        self.fm_demod = analog.pll_freqdet_cf(loop_bw, max_freq, -max_freq)
        self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(
            2, 0, 1 * cmath.pi / 100.0, -0.06, 0.06, 0.5, 0.05, demod_rate / 2375.0, 0.001, 0.005
        )
        self.RDS_signal_gen = blocks.multiply_vcc(1)
        self.RDS_sig_filter = filter.fir_filter_fcc(
            1,
            firdes.complex_band_pass(
                1, demod_rate, 57000 - 1500, 57000 + 1500, width_of_transition_band, firdes.WIN_HAMMING, 6.76
            ),
        )
        self.RDS_carr_gen = blocks.multiply_vcc(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.RDS_carr_gen, 0), (self.RDS_signal_gen, 0))
        self.connect((self.RDS_sig_filter, 0), (self.RDS_signal_gen, 1))
        self.connect((self.RDS_signal_gen, 0), (self.root_raised_cosine_filter_0, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.qtgui_const_sink_x_1, 0))
        self.connect((self.fm_demod, 0), (self.RDS_sig_filter, 0))
        self.connect((self.fm_demod, 0), (self.stereo_carrier__filter, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0), (self.fm_demod, 0))
        self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_mpsk_receiver_cc_0, 0))
        self.connect((self.rtl2832_source_0, 0), (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.stereo_carr_gen, 0), (self.RDS_carr_gen, 1))
        self.connect((self.stereo_carrier__filter, 0), (self.stereo_carrier_pll_recovery, 0))
        self.connect((self.stereo_carrier_pll_recovery, 0), (self.RDS_carr_gen, 0))
        self.connect((self.stereo_carrier_pll_recovery, 0), (self.stereo_carr_gen, 1))
        self.connect((self.stereo_carrier_pll_recovery, 0), (self.stereo_carr_gen, 0))
Exemplo n.º 19
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="FM Stereo Receiver")

        ##################################################
        # Variables
        ##################################################
        self.smux_filt_samprate = smux_filt_samprate = 256e3
        self.smux_decim = smux_decim = 8
        self.samp_rate = samp_rate = 2.048e6
        self.right_gain = right_gain = 3
        self.left_gain = left_gain = 3
        self.bpf_base = bpf_base = 23e3
        self.RF_Gain = RF_Gain = 45
        self.CF = CF = 99.3e6

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.samp_rate,
            callback=self.set_samp_rate,
            label=
            "Sample Rate: 1.024M, 1.4M, 1.8M, 1.92M, 2.048M, 2.4M & 2. 56M",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 1)
        _right_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._right_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_right_gain_sizer,
            value=self.right_gain,
            callback=self.set_right_gain,
            label="R Audio Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._right_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_right_gain_sizer,
            value=self.right_gain,
            callback=self.set_right_gain,
            minimum=0,
            maximum=5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_right_gain_sizer, 0, 1, 1, 1)
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(),
                                                        style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0),
                                "BB Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0),
                                "Demod Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0),
                                "Stereo Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0),
                                "Stereo Signal")
        self.GridAdd(self.notebook_0, 2, 0, 1, 2)
        _left_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._left_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_left_gain_sizer,
            value=self.left_gain,
            callback=self.set_left_gain,
            label="L Audio Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._left_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_left_gain_sizer,
            value=self.left_gain,
            callback=self.set_left_gain,
            minimum=0,
            maximum=5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_left_gain_sizer, 0, 0, 1, 1)
        _RF_Gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_Gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_RF_Gain_sizer,
            value=self.RF_Gain,
            callback=self.set_RF_Gain,
            label="RF Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._RF_Gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_RF_Gain_sizer,
            value=self.RF_Gain,
            callback=self.set_RF_Gain,
            minimum=0,
            maximum=100,
            num_steps=45,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_RF_Gain_sizer, 1, 1, 1, 1)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=0,
            dynamic_range=100,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=512,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Baseband Waterfall",
            size=(800, 100),
        )
        self.notebook_0.GetPage(0).GridAdd(self.wxgui_waterfallsink2_0.win, 3,
                                           0, 1, 2)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.notebook_0.GetPage(3).GetWin(),
            title="Scope Plot",
            sample_rate=32e3,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=2,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label="Counts",
            size=(800, 500),
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0_1 = fftsink2.fft_sink_f(
            self.notebook_0.GetPage(2).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=32e3,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Difference FFT ",
            peak_hold=False,
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_0_1.win)
        self.wxgui_fftsink2_0_0_0 = fftsink2.fft_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate / 8,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Demodulated FFT",
            peak_hold=False,
            size=(800, 800),
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_0_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Baseband FFT",
            peak_hold=False,
            size=(800, 100),
        )
        self.notebook_0.GetPage(0).GridAdd(self.wxgui_fftsink2_0_0.win, 2, 0,
                                           1, 2)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
            self.notebook_0.GetPage(2).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=32e3,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Sum FFT",
            peak_hold=False,
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_0.win)
        self.rfgain = blocks.multiply_const_vcc((RF_Gain, ))
        self.low_pass_filter_1_0 = filter.fir_filter_fff(
            smux_decim,
            firdes.low_pass(1, smux_filt_samprate, 15e3, 500,
                            firdes.WIN_HAMMING, 1))
        self.low_pass_filter_0 = filter.fir_filter_ccf(
            2,
            firdes.low_pass(2, samp_rate / 4, 100e3, 500, firdes.WIN_KAISER,
                            6.76))
        self.iir_filter_xxx_0 = filter.iir_filter_ccf(
            (-0.00266, 0.00504, -0.00309, -0.00136, 0.00663, -0.01052, 0.01103,
             -0.00731, 0.00016, 0.00800, -0.01396, 0.01490, -0.00971, -0.00035,
             0.01173, -0.01979, 0.02054, -0.01240, -0.00273, 0.01960, -0.03122,
             0.03124, -0.01669, -0.01017, 0.04137, -0.06448, 0.06476, -0.02634,
             -0.07449, 0.33571, -0.00000, -0.33571, 0.07449, 0.02634, -0.06476,
             0.06448, -0.04137, 0.01017, 0.01669, -0.03124, 0.03122, -0.01960,
             0.00273, 0.01240, -0.02054, 0.01979, -0.01173, 0.00035, 0.00971,
             -0.01490, 0.01396, -0.00800, -0.00016, 0.00731, -0.01103, 0.01052,
             -0.00663, 0.00136, 0.00309, -0.00504, 0.00266), (1, ), False)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(4, (1, 1, 1, 1))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_multiply_xx_1_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff(
            (right_gain, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (left_gain, ))
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_file_source_0_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1,
            "/Users/bretttt/iCloud_drive/16S/engs110/project/radio_dat/IQ_Data_STEREO1",
            True)
        self.blocks_divide_xx_1 = blocks.divide_cc(1)
        self.blocks_delay_2 = blocks.delay(gr.sizeof_gr_complex * 1, 30)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
        self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vcc((0.1, ))
        self.baseband_LPF = filter.fir_filter_fff(
            smux_decim,
            firdes.low_pass(1, smux_filt_samprate, 15e3, 500,
                            firdes.WIN_KAISER, 6.76))
        self.band_pass_filter_0_0_0 = filter.fir_filter_fcc(
            1,
            firdes.complex_band_pass(1, smux_filt_samprate, 18000, 20000, 1000,
                                     firdes.WIN_KAISER, 1))
        self.band_pass_filter_0 = filter.fir_filter_fff(
            1,
            firdes.band_pass(1, smux_filt_samprate, bpf_base, bpf_base + 30e3,
                             500, firdes.WIN_KAISER, 6.76))
        self.audio_sink_0_0_0_0 = audio.sink(32000, "", True)
        self.analog_pll_refout_cc_0_0 = analog.pll_refout_cc(
            3.14 / 100, 0.152 * 3.14, 0.144 * 3.14)
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=samp_rate / 8,
                                                     tau=75e-6)
        self.analog_fm_deemph_0 = analog.fm_deemph(fs=samp_rate / 8, tau=75e-6)
        self.analog_const_source_x_0 = analog.sig_source_f(
            0, analog.GR_CONST_WAVE, 0, 0, 0)
        _CF_sizer = wx.BoxSizer(wx.VERTICAL)
        self._CF_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_CF_sizer,
            value=self.CF,
            callback=self.set_CF,
            label="Center Frequency",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._CF_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_CF_sizer,
            value=self.CF,
            callback=self.set_CF,
            minimum=80e6,
            maximum=108e6,
            num_steps=280,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_CF_sizer, 3, 0, 1, 2)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.analog_fm_deemph_0, 0),
                     (self.audio_sink_0_0_0_0, 0))
        self.connect((self.analog_fm_deemph_0_0, 0),
                     (self.audio_sink_0_0_0_0, 1))
        self.connect((self.analog_pll_refout_cc_0_0, 0),
                     (self.blocks_multiply_xx_1_0, 0))
        self.connect((self.analog_pll_refout_cc_0_0, 0),
                     (self.blocks_multiply_xx_1_0, 1))
        self.connect((self.band_pass_filter_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.band_pass_filter_0_0_0, 0),
                     (self.analog_pll_refout_cc_0_0, 0))
        self.connect((self.baseband_LPF, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.baseband_LPF, 0), (self.blocks_sub_xx_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.blocks_divide_xx_1, 1))
        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.band_pass_filter_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.band_pass_filter_0_0_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.baseband_LPF, 0))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.wxgui_fftsink2_0_0_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_delay_2, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.blocks_divide_xx_1, 0), (self.blocks_delay_2, 0))
        self.connect((self.blocks_divide_xx_1, 0), (self.iir_filter_xxx_0, 0))
        self.connect((self.blocks_file_source_0_0, 0), (self.rfgain, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.blocks_complex_to_imag_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.analog_fm_deemph_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.analog_fm_deemph_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.wxgui_fftsink2_0_1, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.wxgui_scopesink2_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.low_pass_filter_1_0, 0))
        self.connect((self.blocks_multiply_xx_1_0, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_sub_xx_0, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.fir_filter_xxx_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.fir_filter_xxx_0_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.iir_filter_xxx_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.low_pass_filter_0, 0),
                     (self.blocks_complex_to_mag_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.blocks_divide_xx_1, 0))
        self.connect((self.low_pass_filter_1_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.low_pass_filter_1_0, 0), (self.blocks_sub_xx_0, 1))
        self.connect((self.rfgain, 0), (self.blocks_throttle_0, 0))
Exemplo n.º 20
0
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        # Menu Bar
        self.frame_1_menubar = wx.MenuBar()
        self.SetMenuBar(self.frame_1_menubar)
        wxglade_tmp_menu = wx.Menu()
        self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL)
        wxglade_tmp_menu.AppendItem(self.Exit)
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
        # Menu Bar end
        self.panel_1 = wx.Panel(self, -1)
        self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB")
        self.button_2 = wx.Button(self, ID_BUTTON_2, "USB")
        self.button_3 = wx.Button(self, ID_BUTTON_3, "AM")
        self.button_4 = wx.Button(self, ID_BUTTON_4, "CW")
        self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper")
        self.slider_fcutoff_hi = wx.Slider(self, ID_SLIDER_1, 0, -15798, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
        self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower")
        self.slider_fcutoff_lo = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15798, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
        self.panel_5 = wx.Panel(self, -1)
        self.label_1 = wx.StaticText(self, -1, " Band\nCenter")
        self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "")
        self.panel_6 = wx.Panel(self, -1)
        self.panel_7 = wx.Panel(self, -1)
        self.panel_2 = wx.Panel(self, -1)
        self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq")
        self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000)
        self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100)
        self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol")
        self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500)
        self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20)
        self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time")
        self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew")
        self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd")
        self.panel_3 = wx.Panel(self, -1)
        self.label_2 = wx.StaticText(self, -1, "PGA               ")
        self.panel_4 = wx.Panel(self, -1)
        self.panel_8 = wx.Panel(self, -1)
        self.panel_9 = wx.Panel(self, -1)
        self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier")
        self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
        self.label_4 = wx.StaticText(self, -1, "Antenna Tune")
        self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
        self.panel_10 = wx.Panel(self, -1)
        self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune")
        self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate")
        self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset")
        self.panel_11 = wx.Panel(self, -1)
        self.panel_12 = wx.Panel(self, -1)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "",
            "--address",
            type="string",
            default="addr=192.168.10.2",
            help="Address of UHD device, [default=%default]",
        )
        parser.add_option(
            "-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ"
        )
        parser.add_option(
            "-s", "--samp-rate", type="eng_float", default=256e3, help="set sample rate (bandwidth) [default=%default]"
        )
        parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE")
        parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE")
        parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse",
        )

        (options, args) = parser.parse_args()

        self.usrp_center = options.ddc_freq
        input_rate = options.samp_rate
        self.slider_range = input_rate * 0.9375
        self.f_lo = self.usrp_center - (self.slider_range / 2)
        self.f_hi = self.usrp_center + (self.slider_range / 2)
        self.af_sample_rate = 32000
        fir_decim = long(input_rate / self.af_sample_rate)

        # data point arrays for antenna tuner
        self.xdata = []
        self.ydata = []

        self.tb = gr.top_block()

        # radio variables, initial conditions
        self.frequency = self.usrp_center
        # these map the frequency slider (0-6000) to the actual range
        self.f_slider_offset = self.f_lo
        self.f_slider_scale = 10000
        self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi)
        self.text_ctrl_1.SetValue(str(int(self.usrp_center)))
        self.slider_5.SetValue(0)
        self.AM_mode = False

        self.slider_3.SetValue((self.frequency - self.f_slider_offset) / self.f_slider_scale)
        self.spin_ctrl_1.SetValue(int(self.frequency))

        POWERMATE = True
        try:
            self.pm = powermate.powermate(self)
        except:
            sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n")
            POWERMATE = False

        if POWERMATE:
            powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate)
            powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton)
        self.active_button = 7

        # command line options
        if options.audio_file == "":
            SAVE_AUDIO_TO_FILE = False
        else:
            SAVE_AUDIO_TO_FILE = True
        if options.radio_file == "":
            SAVE_RADIO_TO_FILE = False
        else:
            SAVE_RADIO_TO_FILE = True
        if options.input_file == "":
            self.PLAY_FROM_USRP = True
        else:
            self.PLAY_FROM_USRP = False

        if self.PLAY_FROM_USRP:
            self.src = uhd.usrp_source(device_addr=options.address, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1)
            self.src.set_samp_rate(input_rate)
            input_rate = self.src.get_samp_rate()

            self.src.set_center_freq(self.usrp_center, 0)
            self.tune_offset = 0

        else:
            self.src = blocks.file_source(gr.sizeof_short, options.input_file)
            self.tune_offset = 2200  # 2200 works for 3.5-4Mhz band

            # convert rf data in interleaved short int form to complex
            s2ss = blocks.stream_to_streams(gr.sizeof_short, 2)
            s2f1 = blocks.short_to_float()
            s2f2 = blocks.short_to_float()
            src_f2c = blocks.float_to_complex()
            self.tb.connect(self.src, s2ss)
            self.tb.connect((s2ss, 0), s2f1)
            self.tb.connect((s2ss, 1), s2f2)
            self.tb.connect(s2f1, (src_f2c, 0))
            self.tb.connect(s2f2, (src_f2c, 1))

        # save radio data to a file
        if SAVE_RADIO_TO_FILE:
            radio_file = blocks.file_sink(gr.sizeof_short, options.radio_file)
            self.tb.connect(self.src, radio_file)

        # 2nd DDC
        xlate_taps = filter.firdes.low_pass(1.0, input_rate, 16e3, 4e3, filter.firdes.WIN_HAMMING)
        self.xlate = filter.freq_xlating_fir_filter_ccf(fir_decim, xlate_taps, self.tune_offset, input_rate)

        # Complex Audio filter
        audio_coeffs = filter.firdes.complex_band_pass(
            1.0,  # gain
            self.af_sample_rate,  # sample rate
            -3000,  # low cutoff
            0,  # high cutoff
            100,  # transition
            filter.firdes.WIN_HAMMING,
        )  # window
        self.slider_fcutoff_hi.SetValue(0)
        self.slider_fcutoff_lo.SetValue(-3000)

        self.audio_filter = filter.fir_filter_ccc(1, audio_coeffs)

        # Main +/- 16Khz spectrum display
        self.fft = fftsink2.fft_sink_c(
            self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)
        )

        # AM Sync carrier
        if AM_SYNC_DISPLAY:
            self.fft2 = fftsink.fft_sink_c(
                self.tb,
                self.panel_9,
                y_per_div=20,
                fft_size=512,
                sample_rate=self.af_sample_rate,
                average=True,
                size=(640, 240),
            )

        c2f = blocks.complex_to_float()

        # AM branch
        self.sel_am = blocks.multiply_const_cc(0)
        # the following frequencies turn out to be in radians/sample
        # analog.pll_refout_cc(alpha,beta,min_freq,max_freq)
        # suggested alpha = X, beta = .25 * X * X
        pll = analog.pll_refout_cc(
            0.5, 0.0625, (2.0 * math.pi * 7.5e3 / self.af_sample_rate), (2.0 * math.pi * 6.5e3 / self.af_sample_rate)
        )
        self.pll_carrier_scale = blocks.multiply_const_cc(complex(10, 0))
        am_det = blocks.multiply_cc()
        # these are for converting +7.5kHz to -7.5kHz
        # for some reason blocks.conjugate_cc() adds noise ??
        c2f2 = blocks.complex_to_float()
        c2f3 = blocks.complex_to_float()
        f2c = blocks.float_to_complex()
        phaser1 = blocks.multiply_const_ff(1)
        phaser2 = blocks.multiply_const_ff(-1)

        # filter for pll generated carrier
        pll_carrier_coeffs = filter.firdes.complex_band_pass(
            2.0,  # gain
            self.af_sample_rate,  # sample rate
            7400,  # low cutoff
            7600,  # high cutoff
            100,  # transition
            filter.firdes.WIN_HAMMING,
        )  # window

        self.pll_carrier_filter = filter.fir_filter_ccc(1, pll_carrier_coeffs)

        self.sel_sb = blocks.multiply_const_ff(1)
        combine = blocks.add_ff()

        # AGC
        sqr1 = blocks.multiply_ff()
        intr = filter.iir_filter_ffd([0.004, 0], [0, 0.999])
        offset = blocks.add_const_ff(1)
        agc = blocks.divide_ff()

        self.scale = blocks.multiply_const_ff(0.00001)
        dst = audio.sink(long(self.af_sample_rate), options.audio_output)

        if self.PLAY_FROM_USRP:
            self.tb.connect(self.src, self.xlate, self.fft)
        else:
            self.tb.connect(src_f2c, self.xlate, self.fft)

        self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0))
        self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3)
        self.tb.connect((c2f3, 0), phaser1, (f2c, 0))
        self.tb.connect((c2f3, 1), phaser2, (f2c, 1))
        self.tb.connect(f2c, (am_det, 1))
        self.tb.connect(am_det, c2f2, (combine, 0))
        self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1))

        if AM_SYNC_DISPLAY:
            self.tb.connect(self.pll_carrier_filter, self.fft2)

        self.tb.connect(combine, self.scale)
        self.tb.connect(self.scale, (sqr1, 0))
        self.tb.connect(self.scale, (sqr1, 1))
        self.tb.connect(sqr1, intr, offset, (agc, 1))
        self.tb.connect(self.scale, (agc, 0))
        self.tb.connect(agc, dst)

        if SAVE_AUDIO_TO_FILE:
            f_out = blocks.file_sink(gr.sizeof_short, options.audio_file)
            sc1 = blocks.multiply_const_ff(64000)
            f2s1 = blocks.float_to_short()
            self.tb.connect(agc, sc1, f2s1, f_out)

        self.tb.start()

        # for mouse position reporting on fft display
        self.fft.win.Bind(wx.EVT_LEFT_UP, self.Mouse)
        # and left click to re-tune
        self.fft.win.Bind(wx.EVT_LEFT_DOWN, self.Click)

        # start a timer to check for web commands
        if WEB_CONTROL:
            self.timer = UpdateTimer(self, 1000)  # every 1000 mSec, 1 Sec

        wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb)
        wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb)
        wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am)
        wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw)
        wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd)
        wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew)
        wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate)
        wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button)
        wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button)
        wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter)
        wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter)
        wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune)
        wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume)
        wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga)
        wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier)
        wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune)
        wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune)

        wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
Exemplo n.º 21
0
    def __init__(self):
        gr.top_block.__init__(
            self,
            "8PSK Modulation and Demodulation with Frequency Correction Simulation"
        )
        Qt.QWidget.__init__(self)
        self.setWindowTitle(
            "8PSK Modulation and Demodulation with Frequency Correction Simulation"
        )
        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", "E8PSK_ModDemod_FC")

        if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
            self.restoreGeometry(self.settings.value("geometry").toByteArray())
        else:
            self.restoreGeometry(
                self.settings.value("geometry", type=QtCore.QByteArray))

        ##################################################
        # Variables
        ##################################################
        self.RangeRow = RangeRow = 0
        self.BiRow = BiRow = RangeRow + 1
        self.ConsRow = ConsRow = BiRow + 1
        self.samp_rate = samp_rate = 1e6
        self.nfilts = nfilts = 100
        self.SampSymb = SampSymb = 8
        self.FreqRow = FreqRow = ConsRow + 1
        self.FDP = FDP = 0.005
        self.rrc_taps_0 = rrc_taps_0 = firdes.root_raised_cosine(
            nfilts, nfilts, 1.0 / float(SampSymb), 0.35, 45 * nfilts)
        self.min_PLL = min_PLL = 2 * np.pi * (1 / float(SampSymb) -
                                              1 / float(SampSymb) * FDP)
        self.max_PLL = max_PLL = 2 * np.pi * (1 / float(SampSymb) +
                                              1 / float(SampSymb) * FDP)
        self.Values = Values = 2
        self.TimeRow = TimeRow = FreqRow + 1
        self.SPS = SPS = 2

        self.QPSK_CO = QPSK_CO = digital.constellation_qpsk().base()

        self.Noise = Noise = 0
        self.LBP_PLL = LBP_PLL = (samp_rate / float(SampSymb) -
                                  samp_rate / float(SampSymb) * FDP * 2)
        self.HBP_PLL = HBP_PLL = (samp_rate / float(SampSymb) +
                                  samp_rate / float(SampSymb) * FDP * 2)
        self.FreqOff = FreqOff = 0.005

        ##################################################
        # Blocks
        ##################################################
        self._Noise_range = Range(0, 1, 0.01, 0, 200)
        self._Noise_win = RangeWidget(self._Noise_range, self.set_Noise,
                                      'Channel Noise', "counter_slider", float)
        self.top_grid_layout.addWidget(self._Noise_win, 0, 1, 1, 2)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 3)]
        self._FreqOff_range = Range(-1, 1, 0.001, 0.005, 200)
        self._FreqOff_win = RangeWidget(self._FreqOff_range, self.set_FreqOff,
                                        'Frequency Offset', "counter_slider",
                                        float)
        self.top_grid_layout.addWidget(self._FreqOff_win, 0, 3, 1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(3, 4)]
        self.sync_encoder = sync_encoder.blk()
        self.sync_decoder = sync_decoder.blk()
        self.repeat_first_byte = repeat_first_byte.blk(repeat=3)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f(
            512,  #size
            samp_rate,  #samp_rate
            "Original vs Received Data",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.064)
        self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1)

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

        self.qtgui_time_sink_x_0_0.enable_tags(-1, 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(True)
        self.qtgui_time_sink_x_0_0.enable_grid(False)
        self.qtgui_time_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0_0.enable_stem_plot(False)

        if not True:
            self.qtgui_time_sink_x_0_0.disable_legend()

        labels = ['Original', 'Received', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "blue"
        ]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in xrange(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_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.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 1, 0,
                                       1, 3)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 3)]
        self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0,
                                                       qtgui.NUM_GRAPH_NONE, 1)
        self.qtgui_number_sink_0_0.set_update_time(0.10)
        self.qtgui_number_sink_0_0.set_title("BER")

        labels = [' ', '', '', '', '', '', '', '', '', '']
        units = ['', '', '', '', '', '', '', '', '', '']
        colors = [("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black")]
        factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        for i in xrange(1):
            self.qtgui_number_sink_0_0.set_min(i, 0)
            self.qtgui_number_sink_0_0.set_max(i, 255)
            self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0_0.set_label(i, labels[i])
            self.qtgui_number_sink_0_0.set_unit(i, units[i])
            self.qtgui_number_sink_0_0.set_factor(i, factor[i])

        self.qtgui_number_sink_0_0.enable_autoscale(False)
        self._qtgui_number_sink_0_0_win = sip.wrapinstance(
            self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_win, 0, 4,
                                       1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(4, 5)]
        self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0,
                                                     qtgui.NUM_GRAPH_NONE, 1)
        self.qtgui_number_sink_0.set_update_time(0.10)
        self.qtgui_number_sink_0.set_title("First Byte")

        labels = [' ', '', '', '', '', '', '', '', '', '']
        units = ['', '', '', '', '', '', '', '', '', '']
        colors = [("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black")]
        factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        for i in xrange(1):
            self.qtgui_number_sink_0.set_min(i, 0)
            self.qtgui_number_sink_0.set_max(i, 255)
            self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0.set_label(i, labels[i])
            self.qtgui_number_sink_0.set_unit(i, units[i])
            self.qtgui_number_sink_0.set_factor(i, factor[i])

        self.qtgui_number_sink_0.enable_autoscale(False)
        self._qtgui_number_sink_0_win = sip.wrapinstance(
            self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 0, 5, 1,
                                       1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(5, 6)]
        self.qtgui_freq_sink_x_1 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Pre PSK Demod",  #name
            2  #number of inputs
        )
        self.qtgui_freq_sink_x_1.set_update_time(0.064)
        self.qtgui_freq_sink_x_1.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_1.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0,
                                                  "")
        self.qtgui_freq_sink_x_1.enable_autoscale(False)
        self.qtgui_freq_sink_x_1.enable_grid(False)
        self.qtgui_freq_sink_x_1.set_fft_average(1.0)
        self.qtgui_freq_sink_x_1.enable_axis_labels(True)
        self.qtgui_freq_sink_x_1.enable_control_panel(False)

        if not True:
            self.qtgui_freq_sink_x_1.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.qtgui_freq_sink_x_1.set_plot_pos_half(not True)

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

        self._qtgui_freq_sink_x_1_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 1, 3, 1,
                                       2)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(3, 5)]
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Post Polyphase Clock",  #name
            1  #number of inputs
        )
        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)

        if not False:
            self.qtgui_freq_sink_x_0_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not 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"
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_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, 3, 1,
                                       1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 2)]
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Post_Channel_Model",  #name
            3  #number of inputs
        )
        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)

        if not False:
            self.qtgui_freq_sink_x_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)

        labels = [
            'Post PLL CPSK', 'Post Filter', 'Pre Filter', '', '', '', '', '',
            '', ''
        ]
        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 xrange(3):
            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, 3, 0, 1,
                                       1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)]
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            1024,  #size
            "Pre Polyphase Clock",  #name
            2  #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.1)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        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(False)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)

        if not False:
            self.qtgui_const_sink_x_0.disable_legend()

        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, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [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 xrange(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.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 2, 0, 1,
                                       1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)]
        self.get_first_byte = get_first_byte.blk()
        self.digital_psk_mod_0 = digital.psk.psk_mod(
            constellation_points=8,
            mod_code="gray",
            differential=True,
            samples_per_symbol=SampSymb,
            excess_bw=0.35,
            verbose=False,
            log=False,
        )
        self.digital_psk_demod_0 = digital.psk.psk_demod(
            constellation_points=8,
            differential=True,
            samples_per_symbol=SampSymb,
            excess_bw=0.35,
            phase_bw=6.28 / 100.0,
            timing_bw=6.28 / 100.0,
            mod_code="gray",
            verbose=False,
            log=False,
        )
        self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(
            SampSymb, 0.1, (rrc_taps_0), nfilts, nfilts / 2, 1.5, 1)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(.1, 8, False)
        self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(
            15, 1, .01, 2)
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=Noise,
            frequency_offset=FreqOff,
            epsilon=1.0,
            taps=(1.0 + 1.0j, ),
            noise_seed=0,
            block_tags=False)
        self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate,
                                                 True)
        self.blocks_skiphead_1 = blocks.skiphead(gr.sizeof_char * 1, 3)
        self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_char * 1, 31)
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(
            1, 8, "", False, gr.GR_MSB_FIRST)
        self.blocks_multiply_xx_1 = 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_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_char * 1, 5)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
            type='BER',
            win_size=64000,
            bits_per_symbol=8,
        )
        self.band_pass_filter_0_0 = filter.interp_fir_filter_ccf(
            1,
            firdes.band_pass(1, samp_rate,
                             (2 * samp_rate / float(SampSymb) - 130e3),
                             (2 * samp_rate / float(SampSymb) + 100e3), 10e3,
                             firdes.WIN_HAMMING, 6.76))
        self.band_pass_filter_0 = filter.interp_fir_filter_ccf(
            1,
            firdes.band_pass(1, samp_rate, 95e3, 105e3, 10e3,
                             firdes.WIN_HAMMING, 6.76))
        self.analog_sig_source_x_0_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_SIN_WAVE, 100e3, 1, 0)
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            samp_rate, analog.GR_SIN_WAVE, 100e3, 1, 0)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            0.2, 2 * np.pi * 103e3 / samp_rate, 2 * np.pi * 97e3 / samp_rate)
        self.Video_Source = blocks.file_source(
            gr.sizeof_char * 1,
            '/home/teddy/Documents/DVB_last_stand/Source_Files/Test_Video.ts',
            False)
        self.Video_Sink = blocks.file_sink(
            gr.sizeof_char * 1,
            '/home/teddy/Documents/DVB_last_stand/Received_Files/Test_Video_8PSK_FC_received.ts',
            False)
        self.Video_Sink.set_unbuffered(True)
        self._Values_range = Range(0, 255, 1, 2, 200)
        self._Values_win = RangeWidget(self._Values_range, self.set_Values,
                                       'Vector Values', "counter_slider", int)
        self.top_grid_layout.addWidget(self._Values_win, 0, 0, 1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)]
        self.Post_Polyphase_Clock_Cons = qtgui.const_sink_c(
            1024,  #size
            'Post Polyphase Clock',  #name
            1  #number of inputs
        )
        self.Post_Polyphase_Clock_Cons.set_update_time(0.10)
        self.Post_Polyphase_Clock_Cons.set_y_axis(-2, 2)
        self.Post_Polyphase_Clock_Cons.set_x_axis(-2, 2)
        self.Post_Polyphase_Clock_Cons.set_trigger_mode(
            qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.Post_Polyphase_Clock_Cons.enable_autoscale(False)
        self.Post_Polyphase_Clock_Cons.enable_grid(True)
        self.Post_Polyphase_Clock_Cons.enable_axis_labels(True)

        if not False:
            self.Post_Polyphase_Clock_Cons.disable_legend()

        labels = ['Timing Recov.', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "red"
        ]
        styles = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        alphas = [0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.Post_Polyphase_Clock_Cons.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.Post_Polyphase_Clock_Cons.set_line_label(i, labels[i])
            self.Post_Polyphase_Clock_Cons.set_line_width(i, widths[i])
            self.Post_Polyphase_Clock_Cons.set_line_color(i, colors[i])
            self.Post_Polyphase_Clock_Cons.set_line_style(i, styles[i])
            self.Post_Polyphase_Clock_Cons.set_line_marker(i, markers[i])
            self.Post_Polyphase_Clock_Cons.set_line_alpha(i, alphas[i])

        self._Post_Polyphase_Clock_Cons_win = sip.wrapinstance(
            self.Post_Polyphase_Clock_Cons.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._Post_Polyphase_Clock_Cons_win, 2,
                                       1, 1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 2)]
        self.Post_Costas_Loop_Freq = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Post Costas Loop",  #name
            1  #number of inputs
        )
        self.Post_Costas_Loop_Freq.set_update_time(0.10)
        self.Post_Costas_Loop_Freq.set_y_axis(-140, 10)
        self.Post_Costas_Loop_Freq.set_y_label('Relative Gain', 'dB')
        self.Post_Costas_Loop_Freq.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0,
                                                    0, "")
        self.Post_Costas_Loop_Freq.enable_autoscale(False)
        self.Post_Costas_Loop_Freq.enable_grid(False)
        self.Post_Costas_Loop_Freq.set_fft_average(1.0)
        self.Post_Costas_Loop_Freq.enable_axis_labels(True)
        self.Post_Costas_Loop_Freq.enable_control_panel(False)

        if not False:
            self.Post_Costas_Loop_Freq.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.Post_Costas_Loop_Freq.set_plot_pos_half(not 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"
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.Post_Costas_Loop_Freq.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.Post_Costas_Loop_Freq.set_line_label(i, labels[i])
            self.Post_Costas_Loop_Freq.set_line_width(i, widths[i])
            self.Post_Costas_Loop_Freq.set_line_color(i, colors[i])
            self.Post_Costas_Loop_Freq.set_line_alpha(i, alphas[i])

        self._Post_Costas_Loop_Freq_win = sip.wrapinstance(
            self.Post_Costas_Loop_Freq.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._Post_Costas_Loop_Freq_win, 3, 3,
                                       1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(3, 4)]
        self.Post_Costas_Loop_Cons = qtgui.const_sink_c(
            1024,  #size
            'Post Costas Loop',  #name
            1  #number of inputs
        )
        self.Post_Costas_Loop_Cons.set_update_time(0.10)
        self.Post_Costas_Loop_Cons.set_y_axis(-2, 2)
        self.Post_Costas_Loop_Cons.set_x_axis(-2, 2)
        self.Post_Costas_Loop_Cons.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                    qtgui.TRIG_SLOPE_POS, 0.0,
                                                    0, "")
        self.Post_Costas_Loop_Cons.enable_autoscale(False)
        self.Post_Costas_Loop_Cons.enable_grid(False)
        self.Post_Costas_Loop_Cons.enable_axis_labels(True)

        if not False:
            self.Post_Costas_Loop_Cons.disable_legend()

        labels = ['Locked', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "red"
        ]
        styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        alphas = [0.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.Post_Costas_Loop_Cons.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.Post_Costas_Loop_Cons.set_line_label(i, labels[i])
            self.Post_Costas_Loop_Cons.set_line_width(i, widths[i])
            self.Post_Costas_Loop_Cons.set_line_color(i, colors[i])
            self.Post_Costas_Loop_Cons.set_line_style(i, styles[i])
            self.Post_Costas_Loop_Cons.set_line_marker(i, markers[i])
            self.Post_Costas_Loop_Cons.set_line_alpha(i, alphas[i])

        self._Post_Costas_Loop_Cons_win = sip.wrapinstance(
            self.Post_Costas_Loop_Cons.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._Post_Costas_Loop_Cons_win, 2, 3,
                                       1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(3, 4)]
        self.Post_CMA_Equalizer_Freq = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Post CMA Equalizer",  #name
            1  #number of inputs
        )
        self.Post_CMA_Equalizer_Freq.set_update_time(0.10)
        self.Post_CMA_Equalizer_Freq.set_y_axis(-140, 10)
        self.Post_CMA_Equalizer_Freq.set_y_label('Relative Gain', 'dB')
        self.Post_CMA_Equalizer_Freq.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                      0.0, 0, "")
        self.Post_CMA_Equalizer_Freq.enable_autoscale(False)
        self.Post_CMA_Equalizer_Freq.enable_grid(False)
        self.Post_CMA_Equalizer_Freq.set_fft_average(1.0)
        self.Post_CMA_Equalizer_Freq.enable_axis_labels(True)
        self.Post_CMA_Equalizer_Freq.enable_control_panel(False)

        if not False:
            self.Post_CMA_Equalizer_Freq.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.Post_CMA_Equalizer_Freq.set_plot_pos_half(not 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"
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.Post_CMA_Equalizer_Freq.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.Post_CMA_Equalizer_Freq.set_line_label(i, labels[i])
            self.Post_CMA_Equalizer_Freq.set_line_width(i, widths[i])
            self.Post_CMA_Equalizer_Freq.set_line_color(i, colors[i])
            self.Post_CMA_Equalizer_Freq.set_line_alpha(i, alphas[i])

        self._Post_CMA_Equalizer_Freq_win = sip.wrapinstance(
            self.Post_CMA_Equalizer_Freq.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._Post_CMA_Equalizer_Freq_win, 3, 2,
                                       1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(2, 3)]
        self.Post_CMA_Eq_Cons = qtgui.const_sink_c(
            1024,  #size
            'Post CMA Equalizer',  #name
            1  #number of inputs
        )
        self.Post_CMA_Eq_Cons.set_update_time(0.10)
        self.Post_CMA_Eq_Cons.set_y_axis(-2, 2)
        self.Post_CMA_Eq_Cons.set_x_axis(-2, 2)
        self.Post_CMA_Eq_Cons.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                               qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                               "")
        self.Post_CMA_Eq_Cons.enable_autoscale(False)
        self.Post_CMA_Eq_Cons.enable_grid(False)
        self.Post_CMA_Eq_Cons.enable_axis_labels(True)

        if not False:
            self.Post_CMA_Eq_Cons.disable_legend()

        labels = ['Equalized', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "red"
        ]
        styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        alphas = [0.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.Post_CMA_Eq_Cons.set_line_label(i, "Data {0}".format(i))
            else:
                self.Post_CMA_Eq_Cons.set_line_label(i, labels[i])
            self.Post_CMA_Eq_Cons.set_line_width(i, widths[i])
            self.Post_CMA_Eq_Cons.set_line_color(i, colors[i])
            self.Post_CMA_Eq_Cons.set_line_style(i, styles[i])
            self.Post_CMA_Eq_Cons.set_line_marker(i, markers[i])
            self.Post_CMA_Eq_Cons.set_line_alpha(i, alphas[i])

        self._Post_CMA_Eq_Cons_win = sip.wrapinstance(
            self.Post_CMA_Eq_Cons.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._Post_CMA_Eq_Cons_win, 2, 2, 1, 1)
        [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)]
        [self.top_grid_layout.setColumnStretch(c, 1) for c in range(2, 3)]

        ##################################################
        # Connections
        ##################################################
        self.connect((self.Video_Source, 0), (self.blocks_throttle_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_xx_1, 0))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0_0, 1))
        self.connect((self.analog_sig_source_x_0_0_0, 0),
                     (self.blocks_multiply_xx_1, 1))
        self.connect((self.band_pass_filter_0, 0),
                     (self.analog_pll_refout_cc_0, 0))
        self.connect((self.band_pass_filter_0, 0),
                     (self.qtgui_freq_sink_x_0, 1))
        self.connect((self.band_pass_filter_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.blks2_error_rate_0, 0),
                     (self.qtgui_number_sink_0_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.channels_channel_model_0, 0))
        self.connect((self.blocks_delay_0, 0),
                     (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.digital_pfb_clock_sync_xxx_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.digital_psk_demod_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.qtgui_freq_sink_x_1, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0),
                     (self.blocks_skiphead_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.sync_decoder, 0))
        self.connect((self.blocks_skiphead_1, 0), (self.blks2_error_rate_0, 0))
        self.connect((self.blocks_skiphead_1, 0),
                     (self.blocks_uchar_to_float_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_skiphead_1, 0))
        self.connect((self.blocks_throttle_0, 0), (self.repeat_first_byte, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0_0, 1))
        self.connect((self.blocks_uchar_to_float_0_0, 0),
                     (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.band_pass_filter_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.band_pass_filter_0_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.qtgui_freq_sink_x_0, 2))
        self.connect((self.digital_cma_equalizer_cc_0, 0),
                     (self.Post_CMA_Eq_Cons, 0))
        self.connect((self.digital_cma_equalizer_cc_0, 0),
                     (self.Post_CMA_Equalizer_Freq, 0))
        self.connect((self.digital_cma_equalizer_cc_0, 0),
                     (self.digital_costas_loop_cc_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.Post_Costas_Loop_Cons, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.Post_Costas_Loop_Freq, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0),
                     (self.Post_Polyphase_Clock_Cons, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0),
                     (self.digital_cma_equalizer_cc_0, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0),
                     (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.digital_psk_demod_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.digital_psk_mod_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.digital_psk_mod_0, 0),
                     (self.qtgui_const_sink_x_0, 1))
        self.connect((self.digital_psk_mod_0, 0),
                     (self.qtgui_freq_sink_x_1, 1))
        self.connect((self.get_first_byte, 0), (self.qtgui_number_sink_0, 0))
        self.connect((self.repeat_first_byte, 0), (self.sync_encoder, 0))
        self.connect((self.sync_decoder, 0), (self.Video_Sink, 0))
        self.connect((self.sync_decoder, 0), (self.blks2_error_rate_0, 1))
        self.connect((self.sync_decoder, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.sync_decoder, 0), (self.get_first_byte, 0))
        self.connect((self.sync_encoder, 0), (self.digital_psk_mod_0, 0))
Exemplo n.º 22
0
    def __init__(self, demod_rate, audio_decimation):
        """
        Hierarchical block for demodulating a broadcast FM signal.

        The input is the downconverted complex baseband signal (gr_complex).
        The output is two streams of the demodulated audio (float) 0=Left, 1=Right.

        Args:
            demod_rate: input sample rate of complex baseband input. (float)
            audio_decimation: how much to decimate demod_rate to get to audio. (integer)
        """
        gr.hier_block2.__init__(
            self,
            "wfm_rcv_pll",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(2, 2, gr.sizeof_float))  # Output signature
        bandwidth = 250e3
        audio_rate = demod_rate / audio_decimation

        # We assign to self so that outsiders can grab the demodulator
        # if they need to.  E.g., to plot its output.
        #
        # input: complex; output: float
        loop_bw = 2 * math.pi / 100.0
        max_freq = 2.0 * math.pi * 90e3 / demod_rate
        self.fm_demod = analog.pll_freqdet_cf(loop_bw, max_freq, -max_freq)

        # input: float; output: float
        self.deemph_Left = fm_deemph(audio_rate)
        self.deemph_Right = fm_deemph(audio_rate)

        # compute FIR filter taps for audio filter
        width_of_transition_band = audio_rate / 32
        audio_coeffs = filter.firdes.low_pass(
            1.0,  # gain
            demod_rate,  # sampling rate
            15000,
            width_of_transition_band,
            filter.firdes.WIN_HAMMING)
        # input: float; output: float
        self.audio_filter = filter.fir_filter_fff(audio_decimation,
                                                  audio_coeffs)
        if 1:
            # Pick off the stereo carrier/2 with this filter. It attenuated 10 dB so apply 10 dB gain
            # We pick off the negative frequency half because we want to base band by it!
            ##  NOTE  THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO DEEMPHASIS

            stereo_carrier_filter_coeffs = \
                filter.firdes.complex_band_pass(10.0,
                                                demod_rate,
                                                -19020,
                                                -18980,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)

            #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs)
            #print "stereo carrier filter ", stereo_carrier_filter_coeffs
            #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate

            # Pick off the double side band suppressed carrier Left-Right audio. It is attenuated 10 dB so apply 10 dB gain

            stereo_dsbsc_filter_coeffs = \
                filter.firdes.complex_band_pass(20.0,
                                                demod_rate,
                                                38000-15000/2,
                                                38000+15000/2,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)
            #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
            #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs
            # construct overlap add filter system from coefficients for stereo carrier

            self.stereo_carrier_filter = \
                filter.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs)

            # carrier is twice the picked off carrier so arrange to do a commplex multiply

            self.stereo_carrier_generator = blocks.multiply_cc()

            # Pick off the rds signal

            stereo_rds_filter_coeffs = \
                filter.firdes.complex_band_pass(30.0,
                                                demod_rate,
                                                57000 - 1500,
                                                57000 + 1500,
                                                width_of_transition_band,
                                                filter.firdes.WIN_HAMMING)
            #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
            #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs
            # construct overlap add filter system from coefficients for stereo carrier

            self.rds_signal_filter = \
                       filter.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs)

            self.rds_carrier_generator = blocks.multiply_cc()
            self.rds_signal_generator = blocks.multiply_cc()
            self_rds_signal_processor = blocks.null_sink(gr.sizeof_gr_complex)

            loop_bw = 2 * math.pi / 100.0
            max_freq = -2.0 * math.pi * 18990 / audio_rate
            min_freq = -2.0 * math.pi * 19010 / audio_rate

            self.stereo_carrier_pll_recovery = \
                analog.pll_refout_cc(loop_bw, max_freq, min_freq)
            #self.stereo_carrier_pll_recovery.squelch_enable(False) #pll_refout does not have squelch yet, so disabled for now

            # set up mixer (multiplier) to get the L-R signal at baseband

            self.stereo_basebander = blocks.multiply_cc()

            # pick off the real component of the basebanded L-R signal.  The imaginary SHOULD be zero

            self.LmR_real = blocks.complex_to_real()
            self.Make_Left = blocks.add_ff()
            self.Make_Right = blocks.sub_ff()

            self.stereo_dsbsc_filter = \
                filter.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs)

        if 1:

            # send the real signal to complex filter to pick off the carrier and then to one side of a multiplier
            self.connect(self, self.fm_demod, self.stereo_carrier_filter,
                         self.stereo_carrier_pll_recovery,
                         (self.stereo_carrier_generator, 0))
            # send the already filtered carrier to the otherside of the carrier
            self.connect(self.stereo_carrier_pll_recovery,
                         (self.stereo_carrier_generator, 1))
            # the resulting signal from this multiplier is the carrier with correct phase but at -38000 Hz.

            # send the new carrier to one side of the mixer (multiplier)
            self.connect(self.stereo_carrier_generator,
                         (self.stereo_basebander, 0))
            # send the demphasized audio to the DSBSC pick off filter,  the complex
            # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier
            self.connect(self.fm_demod, self.stereo_dsbsc_filter,
                         (self.stereo_basebander, 1))
            # the result is BASEBANDED DSBSC with phase zero!

            # Pick off the real part since the imaginary is theoretically zero and then to one side of a summer
            self.connect(self.stereo_basebander, self.LmR_real,
                         (self.Make_Left, 0))
            #take the same real part of the DSBSC baseband signal and send it to negative side of a subtracter
            self.connect(self.LmR_real, (self.Make_Right, 1))

            # Make rds carrier by taking the squared pilot tone and multiplying by pilot tone
            self.connect(self.stereo_basebander,
                         (self.rds_carrier_generator, 0))
            self.connect(self.stereo_carrier_pll_recovery,
                         (self.rds_carrier_generator, 1))
            # take signal, filter off rds,  send into mixer 0 channel
            self.connect(self.fm_demod, self.rds_signal_filter,
                         (self.rds_signal_generator, 0))
            # take rds_carrier_generator output and send into mixer 1 channel
            self.connect(self.rds_carrier_generator,
                         (self.rds_signal_generator, 1))
            # send basebanded rds signal and send into "processor" which for now is a null sink
            self.connect(self.rds_signal_generator, self_rds_signal_processor)

        if 1:
            # pick off the audio, L+R that is what we used to have and send it to the summer
            self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1))
            # take the picked off L+R audio and send it to the PLUS side of the subtractor
            self.connect(self.audio_filter, (self.Make_Right, 0))
            # The result of  Make_Left  gets    (L+R) +  (L-R) and results in 2*L
            # The result of Make_Right gets  (L+R) - (L-R) and results in 2*R
            self.connect(self.Make_Left, self.deemph_Left, (self, 0))
            self.connect(self.Make_Right, self.deemph_Right, (self, 1))
Exemplo n.º 23
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Stereo FM receiver and RDS Decoder")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1000000
        self.bb_decim = bb_decim = 4
        self.freq_offset = freq_offset = 250000
        self.freq = freq = 106.1e6
        self.baseband_rate = baseband_rate = samp_rate/bb_decim
        self.audio_decim = audio_decim = 5
        self.xlate_bandwidth = xlate_bandwidth = 100000
        self.volume = volume = 0
        self.gain = gain = 37.6
        self.freq_tune = freq_tune = freq - freq_offset
        self.audio_rate = audio_rate = 48000
        self.audio_decim_rate = audio_decim_rate = baseband_rate/audio_decim

        ##################################################
        # Blocks
        ##################################################
        _volume_sizer = wx.BoxSizer(wx.VERTICAL)
        self._volume_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_volume_sizer,
        	value=self.volume,
        	callback=self.set_volume,
        	label="Volume",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._volume_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_volume_sizer,
        	value=self.volume,
        	callback=self.set_volume,
        	minimum=-20,
        	maximum=10,
        	num_steps=300,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_volume_sizer, 0, 1, 1, 1)
        self.nb = self.nb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Demod")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "L+R")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Pilot")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "DSBSC")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "RDS")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "L-R")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "RDS constellation")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Waterfall")
        self.GridAdd(self.nb, 2, 0, 1, 2)
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	label="RF Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	minimum=0,
        	maximum=49.6,
        	num_steps=124,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_gain_sizer, 0, 0, 1, 1)
        _freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	label="Freq",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._freq_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	minimum=88.1e6,
        	maximum=107.9e6,
        	num_steps=99,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_freq_sizer, 1, 0, 1, 2)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f(
        	self.nb.GetPage(8).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=baseband_rate,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.nb.GetPage(8).Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
        	self.nb.GetPage(7).GetWin(),
        	title="Scope Plot",
        	sample_rate=2375,
        	v_scale=0.4,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=True,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.nb.GetPage(7).Add(self.wxgui_scopesink2_1.win)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.nb.GetPage(3).GetWin(),
        	title="Pilot",
        	sample_rate=baseband_rate,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.nb.GetPage(3).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0_0_0_1_0_1 = fftsink2.fft_sink_c(
        	self.nb.GetPage(5).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=audio_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="RDS",
        	peak_hold=False,
        )
        self.nb.GetPage(5).Add(self.wxgui_fftsink2_0_0_0_1_0_1.win)
        self.wxgui_fftsink2_0_0_0_1_0_0 = fftsink2.fft_sink_f(
        	self.nb.GetPage(6).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=-50,
        	ref_scale=2.0,
        	sample_rate=baseband_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="L-R",
        	peak_hold=False,
        )
        self.nb.GetPage(6).Add(self.wxgui_fftsink2_0_0_0_1_0_0.win)
        self.wxgui_fftsink2_0_0_0_1 = fftsink2.fft_sink_f(
        	self.nb.GetPage(4).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=baseband_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="DSBSC Sub-carrier",
        	peak_hold=False,
        )
        self.nb.GetPage(4).Add(self.wxgui_fftsink2_0_0_0_1.win)
        self.wxgui_fftsink2_0_0_0 = fftsink2.fft_sink_f(
        	self.nb.GetPage(2).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=audio_decim_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="L+R",
        	peak_hold=False,
        )
        self.nb.GetPage(2).Add(self.wxgui_fftsink2_0_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_f(
        	self.nb.GetPage(1).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=baseband_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=True,
        	avg_alpha=0.8,
        	title="FM Demod",
        	peak_hold=False,
        )
        self.nb.GetPage(1).Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.nb.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=-30,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=True,
        	avg_alpha=0.8,
        	title="Baseband",
        	peak_hold=False,
        )
        self.nb.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(freq_tune, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(gain, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine(
        	1, samp_rate/bb_decim/audio_decim, 2375, 1, 100))
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff(
                interpolation=audio_rate,
                decimation=audio_decim_rate,
                taps=None,
                fractional_bw=None,
        )
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
                interpolation=audio_rate,
                decimation=audio_decim_rate,
                taps=None,
                fractional_bw=None,
        )
        self.gr_rds_parser_0 = rds.parser(False, True)
        self.gr_rds_panel_0 = rds.rdsPanel(freq, self.GetWin())
        self.Add(self.gr_rds_panel_0.panel)
        self.gr_rds_decoder_0 = rds.decoder(False, False)
        self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_fcc(audio_decim, (firdes.low_pass(2500.0,baseband_rate,2.4e3,2e3,firdes.WIN_HAMMING)), 57e3, baseband_rate)
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (firdes.low_pass(1, samp_rate, xlate_bandwidth, 100000)), freq_offset, samp_rate)
        self.fir_filter_xxx_5 = filter.fir_filter_fff(audio_decim, (firdes.low_pass(1.0,baseband_rate,20e3,40e3,firdes.WIN_HAMMING)))
        self.fir_filter_xxx_5.declare_sample_delay(0)
        self.fir_filter_xxx_3 = filter.fir_filter_fff(1, (firdes.band_pass(1.0,baseband_rate,38e3-13e3,38e3+13e3,3e3,firdes.WIN_HAMMING)))
        self.fir_filter_xxx_3.declare_sample_delay(0)
        self.fir_filter_xxx_2 = filter.fir_filter_fcc(1, (firdes.complex_band_pass(1.0,baseband_rate,19e3-500,19e3+500,1e3,firdes.WIN_HAMMING)))
        self.fir_filter_xxx_2.declare_sample_delay(0)
        self.fir_filter_xxx_1 = filter.fir_filter_fff(audio_decim, (firdes.low_pass(1.0,baseband_rate,13e3,3e3,firdes.WIN_HAMMING)))
        self.fir_filter_xxx_1.declare_sample_delay(0)
        self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(2, 0, 1*cmath.pi/100.0, -0.06, 0.06, 0.5, 0.05, samp_rate/bb_decim/audio_decim/ 2375.0, 0.001, 0.005)
        self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*1)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((10**(1.*(volume+15)/10), ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((10**(1.*(volume+15)/10), ))
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_char*1, 2)
        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_vff(1)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
        	quad_rate=samp_rate,
        	audio_decimation=bb_decim,
        )
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(0.001, 2 * math.pi * (19000+200) / baseband_rate, 2 * math.pi * (19000-200) / baseband_rate)
        self.analog_fm_deemph_0_0_0 = analog.fm_deemph(fs=audio_decim_rate, tau=75e-6)
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=audio_decim_rate, tau=75e-6)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.fir_filter_xxx_1, 0), (self.wxgui_fftsink2_0_0_0, 0))
        self.connect((self.fir_filter_xxx_1, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.fir_filter_xxx_3, 0), (self.wxgui_fftsink2_0_0_0_1, 0))
        self.connect((self.fir_filter_xxx_1, 0), (self.blocks_sub_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.fir_filter_xxx_5, 0))
        self.connect((self.analog_fm_deemph_0_0_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.analog_fm_deemph_0_0_0, 0))
        self.connect((self.blocks_sub_xx_0, 0), (self.analog_fm_deemph_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_fftsink2_0_0_0_1_0_0, 0))
        self.connect((self.fir_filter_xxx_5, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.fir_filter_xxx_5, 0), (self.blocks_sub_xx_0, 1))
        self.connect((self.fir_filter_xxx_3, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.rational_resampler_xxx_0, 0))
        self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_wfm_rcv_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_1, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_3, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_2, 0))
        self.connect((self.fir_filter_xxx_2, 0), (self.analog_pll_refout_cc_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_1, 1))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.blocks_multiply_xx_1, 0))
        self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_complex_to_imag_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0), (self.wxgui_scopesink2_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_wfm_rcv_0, 0), (self.freq_xlating_fir_filter_xxx_1, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.wxgui_fftsink2_0_0_0_1_0_1, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.wxgui_scopesink2_1, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.root_raised_cosine_filter_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_mpsk_receiver_cc_0, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_keep_one_in_n_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0), (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.digital_diff_decoder_bb_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.digital_diff_decoder_bb_0, 0), (self.gr_rds_decoder_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_null_sink_0, 1))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.gr_rds_decoder_0, "out", self.gr_rds_parser_0, "in")
        self.msg_connect(self.gr_rds_parser_0, "out", self.gr_rds_panel_0, "in")
Exemplo n.º 24
0
    def connect_audio_stage(self, input_port):
        stereo_rate = self.demod_rate
        normalizer = TWO_PI / stereo_rate
        pilot_tone = 19000
        pilot_low = pilot_tone * 0.98
        pilot_high = pilot_tone * 1.02

        def make_audio_filter():
            return grfilter.fir_filter_fff(
                stereo_rate // self.__audio_int_rate,  # decimation
                firdes.low_pass(
                    1.0,
                    stereo_rate,
                    15000,
                    5000,
                    firdes.WIN_HAMMING))

        stereo_pilot_filter = grfilter.fir_filter_fcc(
            1,  # decimation
            firdes.complex_band_pass(
                1.0,
                stereo_rate,
                pilot_low,
                pilot_high,
                300))  # TODO magic number from gqrx
        stereo_pilot_pll = analog.pll_refout_cc(
            loop_bw=0.001,
            max_freq=normalizer * pilot_high,
            min_freq=normalizer * pilot_low)
        stereo_pilot_doubler = blocks.multiply_cc()
        stereo_pilot_out = blocks.complex_to_real()
        difference_channel_mixer = blocks.multiply_ff()
        difference_channel_filter = make_audio_filter()
        mono_channel_filter = make_audio_filter()
        mixL = blocks.add_ff(1)
        mixR = blocks.sub_ff(1)
        
        # connections
        self.connect(input_port, mono_channel_filter)
        if self.__decode_stereo:
            # stereo pilot tone tracker
            self.connect(
                input_port,
                stereo_pilot_filter,
                stereo_pilot_pll)
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 0))
            self.connect(stereo_pilot_pll, (stereo_pilot_doubler, 1))
            self.connect(stereo_pilot_doubler, stereo_pilot_out)
        
            # pick out stereo left-right difference channel (at stereo_rate)
            self.connect(input_port, (difference_channel_mixer, 0))
            self.connect(stereo_pilot_out, (difference_channel_mixer, 1))
            self.connect(
                difference_channel_mixer,
                blocks.multiply_const_ff(6),  # TODO: Completely empirical fudge factor. This should not be necessary. I believe this is at least partly due to phase error in the pilot signal.
                difference_channel_filter)
        
            # recover left/right channels (at self.__audio_int_rate)
            self.connect(difference_channel_filter, (mixL, 1))
            self.connect(difference_channel_filter, (mixR, 1))
            self.connect(mono_channel_filter, (mixL, 0))
            self.connect(mono_channel_filter, (mixR, 0))
            resamplerL = self._make_resampler((mixL, 0), self.__audio_int_rate)
            resamplerR = self._make_resampler((mixR, 0), self.__audio_int_rate)
            deemphL = fm_emph.fm_deemph(self.__audio_int_rate, 75e-6)
            deemphR = fm_emph.fm_deemph(self.__audio_int_rate, 75e-6)
            self.connect(resamplerL, deemphL)
            self.connect(resamplerR, deemphR)
            self.connect_audio_output(deemphL, deemphR)
        else:
            resampler = self._make_resampler(mono_channel_filter, self.__audio_int_rate)
            deemph = fm_emph.fm_deemph(self.__audio_int_rate, 75e-6)
            self.connect(resampler, deemph)
            self.connect_audio_output(deemph, deemph)
Exemplo n.º 25
0
    def __init__(self, demod_rate, audio_decimation):
        """
        Hierarchical block for demodulating a broadcast FM signal.

        The input is the downconverted complex baseband signal (gr_complex).
        The output is two streams of the demodulated audio (float) 0=Left, 1=Right.

        Args:
            demod_rate: input sample rate of complex baseband input. (float)
            audio_decimation: how much to decimate demod_rate to get to audio. (integer) FIXME: Not actually implemented!
        """
        gr.hier_block2.__init__(
            self,
            "wfm_rcv_pll",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(2, 2, gr.sizeof_float))  # Output signature

        if audio_decimation != int(audio_decimation):
            raise ValueError("audio_decimation needs to be an integer")
        audio_decimation = int(audio_decimation)

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 3840000
        self.rf_decim = rf_decim = 10
        self.demod_rate = demod_rate = (int)(samp_rate / rf_decim)
        self.stereo_carrier_filter_coeffs_0 = stereo_carrier_filter_coeffs_0 = firdes.band_pass(
            1.0, demod_rate, 37600, 38400, 400, fft.window.WIN_HAMMING, 6.76)
        self.stereo_carrier_filter_coeffs = stereo_carrier_filter_coeffs = firdes.complex_band_pass(
            1.0, demod_rate, 18980, 19020, 1500, fft.window.WIN_HAMMING, 6.76)
        self.deviation = deviation = 75000
        self.audio_filter = audio_filter = firdes.low_pass(
            1, demod_rate, 15000, 1500, fft.window.WIN_HAMMING, 6.76)
        self.audio_decim = audio_decim = (int)(demod_rate / 48000)

        ##################################################
        # Blocks
        ##################################################
        self.fir_filter_xxx_1 = filter.fir_filter_fcc(
            1, stereo_carrier_filter_coeffs)
        self.fir_filter_xxx_1.declare_sample_delay(0)
        self.fft_filter_xxx_3 = filter.fft_filter_fff(
            1, stereo_carrier_filter_coeffs_0, 1)
        self.fft_filter_xxx_3.declare_sample_delay(0)
        self.fft_filter_xxx_2 = filter.fft_filter_fff(audio_decim,
                                                      audio_filter, 1)
        self.fft_filter_xxx_2.declare_sample_delay(0)
        self.fft_filter_xxx_1 = filter.fft_filter_fff(audio_decim,
                                                      audio_filter, 1)
        self.fft_filter_xxx_1.declare_sample_delay(0)
        self.blocks_multiply_xx_2 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_ff(5.5)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(-5.5)
        self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1)
        self.blocks_add_xx_0_0 = blocks.add_vff(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(
            demod_rate / (2 * math.pi * deviation))
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            0.001, 2 * math.pi * 19200 / demod_rate,
            2 * math.pi * 18800 / demod_rate)
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=48000, tau=75e-6)
        self.analog_fm_deemph_0 = analog.fm_deemph(fs=48000, tau=75e-6)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_fm_deemph_0, 0), (self, 0))
        self.connect((self.analog_fm_deemph_0_0, 0), (self, 1))
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0),
                     (self.blocks_multiply_xx_2, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0),
                     (self.fft_filter_xxx_1, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0),
                     (self.fir_filter_xxx_1, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.analog_fm_deemph_0, 0))
        self.connect((self.blocks_add_xx_0_0, 0),
                     (self.analog_fm_deemph_0_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.fft_filter_xxx_3, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_1, 0),
                     (self.blocks_add_xx_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.blocks_complex_to_imag_0, 0))
        self.connect((self.blocks_multiply_xx_2, 0),
                     (self.fft_filter_xxx_2, 0))
        self.connect((self.fft_filter_xxx_1, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.fft_filter_xxx_1, 0), (self.blocks_add_xx_0_0, 1))
        self.connect((self.fft_filter_xxx_2, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.fft_filter_xxx_2, 0),
                     (self.blocks_multiply_const_vxx_0_1, 0))
        self.connect((self.fft_filter_xxx_3, 0),
                     (self.blocks_multiply_xx_2, 1))
        self.connect((self.fir_filter_xxx_1, 0),
                     (self.analog_pll_refout_cc_0, 0))
        self.connect((self, 0), (self.analog_quadrature_demod_cf_0, 0))
Exemplo n.º 26
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="FM Stereo Receiver")

        ##################################################
        # Variables
        ##################################################
        self.smux_filt_samprate = smux_filt_samprate = 256e3
        self.smux_decim = smux_decim = 8
        self.samp_rate = samp_rate = 2.048e6
        self.right_gain = right_gain = 3
        self.left_gain = left_gain = 3
        self.bpf_base = bpf_base = 23e3
        self.RF_Gain = RF_Gain = 45
        self.CF = CF = 99.3e6

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.samp_rate,
        	callback=self.set_samp_rate,
        	label="Sample Rate: 1.024M, 1.4M, 1.8M, 1.92M, 2.048M, 2.4M & 2. 56M",
        	converter=forms.float_converter(),
        )
        self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 1)
        _right_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._right_gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_right_gain_sizer,
        	value=self.right_gain,
        	callback=self.set_right_gain,
        	label="R Audio Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._right_gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_right_gain_sizer,
        	value=self.right_gain,
        	callback=self.set_right_gain,
        	minimum=0,
        	maximum=5,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_right_gain_sizer, 0, 1, 1, 1)
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "BB Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Demod Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Stereo Spectrum")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Stereo Signal")
        self.GridAdd(self.notebook_0, 2, 0, 1, 2)
        _left_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._left_gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_left_gain_sizer,
        	value=self.left_gain,
        	callback=self.set_left_gain,
        	label="L Audio Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._left_gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_left_gain_sizer,
        	value=self.left_gain,
        	callback=self.set_left_gain,
        	minimum=0,
        	maximum=5,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_left_gain_sizer, 0, 0, 1, 1)
        _RF_Gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_Gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_RF_Gain_sizer,
        	value=self.RF_Gain,
        	callback=self.set_RF_Gain,
        	label="RF Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._RF_Gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_RF_Gain_sizer,
        	value=self.RF_Gain,
        	callback=self.set_RF_Gain,
        	minimum=0,
        	maximum=100,
        	num_steps=45,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_RF_Gain_sizer, 1, 1, 1, 1)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.notebook_0.GetPage(0).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Baseband Waterfall",
        	size=(800,100),
        )
        self.notebook_0.GetPage(0).GridAdd(self.wxgui_waterfallsink2_0.win, 3, 0, 1, 2)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.notebook_0.GetPage(3).GetWin(),
        	title="Scope Plot",
        	sample_rate=32e3,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=2,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        	size=(800,500),
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0_1 = fftsink2.fft_sink_f(
        	self.notebook_0.GetPage(2).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=32e3,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Difference FFT ",
        	peak_hold=False,
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_0_1.win)
        self.wxgui_fftsink2_0_0_0 = fftsink2.fft_sink_f(
        	self.notebook_0.GetPage(1).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate/8,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Demodulated FFT",
        	peak_hold=False,
        	size=(800,800),
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_0_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
        	self.notebook_0.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Baseband FFT",
        	peak_hold=False,
        	size=(800,100),
        )
        self.notebook_0.GetPage(0).GridAdd(self.wxgui_fftsink2_0_0.win, 2, 0, 1, 2)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
        	self.notebook_0.GetPage(2).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=32e3,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Sum FFT",
        	peak_hold=False,
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_0.win)
        self.rfgain = blocks.multiply_const_vcc((RF_Gain, ))
        self.low_pass_filter_1_0 = filter.fir_filter_fff(smux_decim, firdes.low_pass(
        	1, smux_filt_samprate, 15e3, 500, firdes.WIN_HAMMING, 1))
        self.low_pass_filter_0 = filter.fir_filter_ccf(2, firdes.low_pass(
        	2, samp_rate/4, 100e3, 500, firdes.WIN_KAISER, 6.76))
        self.iir_filter_xxx_0 = filter.iir_filter_ccf((-0.00266, 0.00504, -0.00309, -0.00136, 0.00663, -0.01052, 0.01103, -0.00731, 0.00016, 0.00800, -0.01396, 0.01490, -0.00971, -0.00035, 0.01173, -0.01979, 0.02054, -0.01240, -0.00273, 0.01960, -0.03122, 0.03124, -0.01669, -0.01017, 0.04137, -0.06448, 0.06476, -0.02634, -0.07449, 0.33571, -0.00000, -0.33571, 0.07449, 0.02634, -0.06476, 0.06448, -0.04137, 0.01017, 0.01669, -0.03124, 0.03122, -0.01960, 0.00273, 0.01240, -0.02054, 0.01979, -0.01173, 0.00035, 0.00971, -0.01490, 0.01396, -0.00800, -0.00016, 0.00731, -0.01103, 0.01052, -0.00663, 0.00136, 0.00309, -0.00504, 0.00266
        ), (1 , ), False)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(4, (1,1,1,1))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_multiply_xx_1_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((right_gain, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((left_gain, ))
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_file_source_0_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/Users/bretttt/iCloud_drive/16S/engs110/project/radio_dat/IQ_Data_STEREO1", True)
        self.blocks_divide_xx_1 = blocks.divide_cc(1)
        self.blocks_delay_2 = blocks.delay(gr.sizeof_gr_complex*1, 30)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
        self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vcc((0.1, ))
        self.baseband_LPF = filter.fir_filter_fff(smux_decim, firdes.low_pass(
        	1, smux_filt_samprate, 15e3, 500, firdes.WIN_KAISER, 6.76))
        self.band_pass_filter_0_0_0 = filter.fir_filter_fcc(1, firdes.complex_band_pass(
        	1, smux_filt_samprate, 18000, 20000, 1000, firdes.WIN_KAISER, 1))
        self.band_pass_filter_0 = filter.fir_filter_fff(1, firdes.band_pass(
        	1, smux_filt_samprate, bpf_base, bpf_base+30e3, 500, firdes.WIN_KAISER, 6.76))
        self.audio_sink_0_0_0_0 = audio.sink(32000, "", True)
        self.analog_pll_refout_cc_0_0 = analog.pll_refout_cc(3.14/100, 0.152*3.14, 0.144*3.14)
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=samp_rate/8, tau=75e-6)
        self.analog_fm_deemph_0 = analog.fm_deemph(fs=samp_rate/8, tau=75e-6)
        self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0)
        _CF_sizer = wx.BoxSizer(wx.VERTICAL)
        self._CF_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_CF_sizer,
        	value=self.CF,
        	callback=self.set_CF,
        	label="Center Frequency",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._CF_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_CF_sizer,
        	value=self.CF,
        	callback=self.set_CF,
        	minimum=80e6,
        	maximum=108e6,
        	num_steps=280,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_CF_sizer, 3, 0, 1, 2)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1))    
        self.connect((self.analog_fm_deemph_0, 0), (self.audio_sink_0_0_0_0, 0))    
        self.connect((self.analog_fm_deemph_0_0, 0), (self.audio_sink_0_0_0_0, 1))    
        self.connect((self.analog_pll_refout_cc_0_0, 0), (self.blocks_multiply_xx_1_0, 0))    
        self.connect((self.analog_pll_refout_cc_0_0, 0), (self.blocks_multiply_xx_1_0, 1))    
        self.connect((self.band_pass_filter_0, 0), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.band_pass_filter_0_0_0, 0), (self.analog_pll_refout_cc_0_0, 0))    
        self.connect((self.baseband_LPF, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.baseband_LPF, 0), (self.blocks_sub_xx_0, 0))    
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_divide_xx_1, 1))    
        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.band_pass_filter_0, 0))    
        self.connect((self.blocks_complex_to_imag_0, 0), (self.band_pass_filter_0_0_0, 0))    
        self.connect((self.blocks_complex_to_imag_0, 0), (self.baseband_LPF, 0))    
        self.connect((self.blocks_complex_to_imag_0, 0), (self.wxgui_fftsink2_0_0_0, 0))    
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_float_to_complex_0, 0))    
        self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_xx_0, 1))    
        self.connect((self.blocks_delay_2, 0), (self.blocks_multiply_conjugate_cc_0, 1))    
        self.connect((self.blocks_divide_xx_1, 0), (self.blocks_delay_2, 0))    
        self.connect((self.blocks_divide_xx_1, 0), (self.iir_filter_xxx_0, 0))    
        self.connect((self.blocks_file_source_0_0, 0), (self.rfgain, 0))    
        self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_add_const_vxx_0, 0))    
        self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_imag_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.analog_fm_deemph_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.wxgui_fftsink2_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.analog_fm_deemph_0_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.wxgui_fftsink2_0_1, 0))    
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.wxgui_scopesink2_0, 1))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_1_0, 0))    
        self.connect((self.blocks_multiply_xx_1_0, 0), (self.blocks_complex_to_real_0, 0))    
        self.connect((self.blocks_sub_xx_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.fir_filter_xxx_0_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_waterfallsink2_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.iir_filter_xxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.blocks_complex_to_mag_0, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.blocks_divide_xx_1, 0))    
        self.connect((self.low_pass_filter_1_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.low_pass_filter_1_0, 0), (self.blocks_sub_xx_0, 1))    
        self.connect((self.rfgain, 0), (self.blocks_throttle_0, 0))    
Exemplo n.º 27
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(
            self, title="Stereo FM receiver and RDS Decoder")
        _icon_path = "/usr/share/icons/hicolor/24x24/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1000000
        self.bb_decim = bb_decim = 4
        self.freq_offset = freq_offset = 250000
        self.freq = freq = 97e6
        self.baseband_rate = baseband_rate = samp_rate / bb_decim
        self.audio_decim = audio_decim = 5
        self.xlate_bandwidth = xlate_bandwidth = 100000
        self.volume = volume = 0
        self.gain = gain = 20
        self.freq_tune = freq_tune = freq - freq_offset
        self.audio_rate = audio_rate = 48000
        self.audio_decim_rate = audio_decim_rate = baseband_rate / audio_decim

        ##################################################
        # Blocks
        ##################################################
        _volume_sizer = wx.BoxSizer(wx.VERTICAL)
        self._volume_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_volume_sizer,
            value=self.volume,
            callback=self.set_volume,
            label='Volume',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._volume_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_volume_sizer,
            value=self.volume,
            callback=self.set_volume,
            minimum=-20,
            maximum=10,
            num_steps=300,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_volume_sizer, 0, 1, 1, 1)
        self.nb = self.nb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Demod")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "L+R")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Pilot")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "DSBSC")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "RDS")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "L-R")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "RDS constellation")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Waterfall")
        self.GridAdd(self.nb, 2, 0, 1, 2)
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            label='RF Gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            minimum=0,
            maximum=49.6,
            num_steps=124,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_sizer, 0, 0, 1, 1)
        _freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_freq_sizer,
            value=self.freq,
            callback=self.set_freq,
            label='Freq',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._freq_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_freq_sizer,
            value=self.freq,
            callback=self.set_freq,
            minimum=88.1e6,
            maximum=107.9e6,
            num_steps=99,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_freq_sizer, 1, 0, 1, 2)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f(
            self.nb.GetPage(8).GetWin(),
            baseband_freq=0,
            dynamic_range=100,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=baseband_rate,
            fft_size=512,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title='Waterfall Plot',
        )
        self.nb.GetPage(8).Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.nb.GetPage(7).GetWin(),
            title='Scope Plot',
            sample_rate=2375,
            v_scale=0.4,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label='Counts',
        )
        self.nb.GetPage(7).Add(self.wxgui_scopesink2_1.win)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.nb.GetPage(3).GetWin(),
            title='Pilot',
            sample_rate=baseband_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label='Counts',
        )
        self.nb.GetPage(3).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0_0_0_1_0_1 = fftsink2.fft_sink_c(
            self.nb.GetPage(5).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=audio_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title='RDS',
            peak_hold=False,
        )
        self.nb.GetPage(5).Add(self.wxgui_fftsink2_0_0_0_1_0_1.win)
        self.wxgui_fftsink2_0_0_0_1_0_0 = fftsink2.fft_sink_f(
            self.nb.GetPage(6).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-50,
            ref_scale=2.0,
            sample_rate=baseband_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title='L-R',
            peak_hold=False,
        )
        self.nb.GetPage(6).Add(self.wxgui_fftsink2_0_0_0_1_0_0.win)
        self.wxgui_fftsink2_0_0_0_1 = fftsink2.fft_sink_f(
            self.nb.GetPage(4).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=baseband_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title='DSBSC Sub-carrier',
            peak_hold=False,
        )
        self.nb.GetPage(4).Add(self.wxgui_fftsink2_0_0_0_1.win)
        self.wxgui_fftsink2_0_0_0 = fftsink2.fft_sink_f(
            self.nb.GetPage(2).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=audio_decim_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title='L+R',
            peak_hold=False,
        )
        self.nb.GetPage(2).Add(self.wxgui_fftsink2_0_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_f(
            self.nb.GetPage(1).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=baseband_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.8,
            title='FM Demod',
            peak_hold=False,
        )
        self.nb.GetPage(1).Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.nb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-30,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.8,
            title='Baseband',
            peak_hold=False,
        )
        self.nb.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, samp_rate / bb_decim / audio_decim,
                                      2375, 1, 100))
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff(
            interpolation=audio_rate,
            decimation=audio_decim_rate,
            taps=None,
            fractional_bw=None,
        )
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
            interpolation=audio_rate,
            decimation=audio_decim_rate,
            taps=None,
            fractional_bw=None,
        )
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               '')
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(freq_tune, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gain, 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.gr_rds_parser_0 = rds.parser(True, False, 0)
        self.gr_rds_panel_0 = rds.rdsPanel(freq, self.GetWin())
        self.Add(self.gr_rds_panel_0.panel)
        self.gr_rds_decoder_0 = rds.decoder(False, False)
        self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_fcc(
            audio_decim, (firdes.low_pass(2500.0, baseband_rate, 2.4e3, 2e3,
                                          firdes.WIN_HAMMING)), 57e3,
            baseband_rate)
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(
            1, (firdes.low_pass(1, samp_rate, xlate_bandwidth, 100000)),
            freq_offset, samp_rate)
        self.fir_filter_xxx_5 = filter.fir_filter_fff(
            audio_decim, (firdes.low_pass(1.0, baseband_rate, 20e3, 40e3,
                                          firdes.WIN_HAMMING)))
        self.fir_filter_xxx_5.declare_sample_delay(0)
        self.fir_filter_xxx_3 = filter.fir_filter_fff(
            1, (firdes.band_pass(1.0, baseband_rate, 38e3 - 13e3, 38e3 + 13e3,
                                 3e3, firdes.WIN_HAMMING)))
        self.fir_filter_xxx_3.declare_sample_delay(0)
        self.fir_filter_xxx_2 = filter.fir_filter_fcc(
            1, (firdes.complex_band_pass(1.0, baseband_rate, 19e3 - 500,
                                         19e3 + 500, 1e3, firdes.WIN_HAMMING)))
        self.fir_filter_xxx_2.declare_sample_delay(0)
        self.fir_filter_xxx_1 = filter.fir_filter_fff(
            audio_decim, (firdes.low_pass(1.0, baseband_rate, 13e3, 3e3,
                                          firdes.WIN_HAMMING)))
        self.fir_filter_xxx_1.declare_sample_delay(0)
        self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(
            2, 0, 1 * cmath.pi / 100.0, -0.06, 0.06, 0.5, 0.05,
            samp_rate / bb_decim / audio_decim / 2375.0, 0.001, 0.005)
        self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff(
            (10**(1. * (volume + 15) / 10), ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (10**(1. * (volume + 15) / 10), ))
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(
            gr.sizeof_char * 1, 2)
        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_vff(1)
        self.audio_sink_0 = audio.sink(audio_rate, '', True)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
            quad_rate=samp_rate,
            audio_decimation=bb_decim,
        )
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            0.001, 2 * math.pi * (19000 + 200) / baseband_rate,
            2 * math.pi * (19000 - 200) / baseband_rate)
        self.analog_fm_deemph_0_0_0 = analog.fm_deemph(fs=audio_decim_rate,
                                                       tau=75e-6)
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=audio_decim_rate,
                                                     tau=75e-6)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.gr_rds_decoder_0, 'out'),
                         (self.gr_rds_parser_0, 'in'))
        self.msg_connect((self.gr_rds_parser_0, 'out'),
                         (self.gr_rds_panel_0, 'in'))
        self.connect((self.analog_fm_deemph_0_0, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.analog_fm_deemph_0_0_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_xx_1, 0))
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_xx_1, 1))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_1, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_2, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.fir_filter_xxx_3, 0))
        self.connect((self.analog_wfm_rcv_0, 0),
                     (self.freq_xlating_fir_filter_xxx_1, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0),
                     (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.analog_fm_deemph_0_0_0, 0))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_complex_to_imag_0, 0),
                     (self.wxgui_scopesink2_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.blocks_keep_one_in_n_0, 0),
                     (self.digital_diff_decoder_bb_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.rational_resampler_xxx_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.fir_filter_xxx_5, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.wxgui_fftsink2_0_0_0_1_0_0, 0))
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.blocks_complex_to_imag_0, 0))
        self.connect((self.blocks_sub_xx_0, 0), (self.analog_fm_deemph_0_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.blocks_keep_one_in_n_0, 0))
        self.connect((self.digital_diff_decoder_bb_0, 0),
                     (self.gr_rds_decoder_0, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_mpsk_receiver_cc_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.fir_filter_xxx_1, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.fir_filter_xxx_1, 0), (self.blocks_sub_xx_0, 0))
        self.connect((self.fir_filter_xxx_1, 0),
                     (self.wxgui_fftsink2_0_0_0, 0))
        self.connect((self.fir_filter_xxx_2, 0),
                     (self.analog_pll_refout_cc_0, 0))
        self.connect((self.fir_filter_xxx_3, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.fir_filter_xxx_3, 0),
                     (self.wxgui_fftsink2_0_0_0_1, 0))
        self.connect((self.fir_filter_xxx_5, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.fir_filter_xxx_5, 0), (self.blocks_sub_xx_0, 1))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.analog_wfm_rcv_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_1, 0),
                     (self.wxgui_fftsink2_0_0_0_1_0_1, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0),
                     (self.audio_sink_0, 1))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.digital_mpsk_receiver_cc_0, 0))
Exemplo n.º 28
0
    def test_pll_refout(self):
        expected_result = ((1+0j),
                            (1+6.408735764296125e-10j),
                            (0.9999844431877136+0.005577784031629562j),
                            (0.9998642802238464+0.016474783420562744j),
                            (0.9994739890098572+0.032431427389383316j),
                            (0.9985847473144531+0.05318402871489525j),
                            (0.996917188167572+0.07846084982156754j),
                            (0.9941533207893372+0.10797744989395142j),
                            (0.9899479150772095+0.14143235981464386j),
                            (0.9839394092559814+0.1785029172897339j),
                            (0.9757603406906128+0.2188417762517929j),
                            (0.9650475978851318+0.26207470893859863j),
                            (0.9514514803886414+0.30779871344566345j),
                            (0.9346449971199036+0.35558223724365234j),
                            (0.9143316149711609+0.40496626496315j),
                            (0.8902531862258911+0.4554659426212311j),
                            (0.8621962666511536+0.5065743923187256j),
                            (0.8299974799156189+0.5577671527862549j),
                            (0.7935484647750854+0.6085070967674255j),
                            (0.7527987360954285+0.6582507491111755j),
                            (0.7077582478523254+0.7064547538757324j),
                            (0.6584978699684143+0.7525825500488281j),
                            (0.6051493883132935+0.7961119413375854j),
                            (0.547903835773468+0.8365413546562195j),
                            (0.48700881004333496+0.8733970522880554j),
                            (0.42276495695114136+0.90623939037323j),
                            (0.35552138090133667+0.9346681237220764j),
                            (0.2856702208518982+0.9583280086517334j),
                            (0.21364101767539978+0.976912260055542j),
                            (0.13989387452602386+0.9901664853096008j),
                            (0.06491273641586304+0.9978909492492676j),
                            (-0.01080091018229723+0.9999416470527649j),
                            (-0.08673560619354248+0.9962313771247864j),
                            (-0.16237612068653107+0.9867289662361145j),
                            (-0.23721040785312653+0.9714583158493042j),
                            (-0.3107353150844574+0.95049649477005j),
                            (-0.3824624717235565+0.9239710569381714j),
                            (-0.45192304253578186+0.892056941986084j),
                            (-0.5186731219291687+0.8549726009368896j),
                            (-0.5822963714599609+0.812976598739624j),
                            (-0.6424083709716797+0.7663624882698059j),
                            (-0.6986585855484009+0.7154552340507507j),
                            (-0.7507330775260925+0.6606056690216064j),
                            (-0.7983550429344177+0.6021870970726013j),
                            (-0.841286301612854+0.5405898094177246j),
                            (-0.879327654838562+0.47621726989746094j),
                            (-0.912318229675293+0.4094819128513336j),
                            (-0.9401354789733887+0.340800940990448j),
                            (-0.9626938104629517+0.27059316635131836j),
                            (-0.979943573474884+0.1992751508951187j),
                            (-0.9918696284294128+0.12725839018821716j),
                            (-0.9984893202781677+0.054946307092905045j),
                            (-0.9998509287834167-0.017267409712076187j),
                            (-0.9960314631462097-0.08900183439254761j),
                            (-0.9871346950531006-0.1598907858133316j),
                            (-0.9732890129089355-0.2295832633972168j),
                            (-0.9546451568603516-0.29774588346481323j),
                            (-0.9313743710517883-0.3640628457069397j),
                            (-0.9036663174629211-0.42823725938796997j),
                            (-0.8717266321182251-0.48999255895614624j),
                            (-0.8357754945755005-0.5490713119506836j),
                            (-0.7960456013679504-0.6052366495132446j),
                            (-0.7527803182601929-0.658271849155426j),
                            (-0.706232488155365-0.7079799771308899j),
                            (-0.6566619873046875-0.7541850209236145j),
                            (-0.6043350696563721-0.7967302799224854j),
                            (-0.5495226979255676-0.8354787826538086j),
                            (-0.4924990236759186-0.8703129887580872j),
                            (-0.4335414469242096-0.9011335968971252j),
                            (-0.3729270100593567-0.927860677242279j),
                            (-0.3109343349933624-0.9504314064979553j),
                            (-0.2478405237197876-0.9688008427619934j),
                            (-0.18392162024974823-0.9829409122467041j),
                            (-0.11945075541734695-0.9928401112556458j),
                            (-0.05469784513115883-0.9985029697418213j),
                            (0.010069688782095909-0.9999492764472961j),
                            (0.07459097355604172-0.9972141981124878j),
                            (0.13860897719860077-0.9903472065925598j),
                            (0.2018725872039795-0.979411780834198j),
                            (0.2641367018222809-0.964485228061676j),
                            (0.32516375184059143-0.9456577301025391j),
                            (0.3847236633300781-0.9230318069458008j),
                            (0.44259318709373474-0.8967224955558777j),
                            (0.49855801463127136-0.8668563365936279j),
                            (0.5524120926856995-0.8335711359977722j),
                            (0.6039596796035767-0.7970148921012878j),
                            (0.6530137062072754-0.7573460936546326j),
                            (0.6993972063064575-0.7147331833839417j),
                            (0.7429447770118713-0.6693527102470398j),
                            (0.7835012078285217-0.6213902235031128j),
                            (0.8209227919578552-0.5710391998291016j),
                            (0.8550769090652466-0.5185011625289917j),
                            (0.8858439326286316-0.46398329734802246j),
                            (0.9131162166595459-0.4076994061470032j),
                            (0.936798632144928-0.3498689830303192j),
                            (0.956809401512146-0.2907160222530365j),
                            (0.9730796813964844-0.23046888411045074j),
                            (0.9855544567108154-0.16935895383358002j),
                            (0.9941920042037964-0.10762103646993637j),
                            (0.9989647269248962-0.045491550117731094j)) 

        sampling_freq = 10e3
        freq = sampling_freq / 100

        loop_bw = math.pi / 100.0
        maxf = 1
        minf = -1

        src = analog.sig_source_c(sampling_freq, analog.GR_COS_WAVE, freq, 1.0)
        pll = analog.pll_refout_cc(loop_bw, maxf, minf)
        head = blocks.head(gr.sizeof_gr_complex, int (freq))
        dst = blocks.vector_sink_c()

        self.tb.connect(src, pll, head)
        self.tb.connect(head, dst)

        self.tb.run()
        dst_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
Exemplo n.º 29
0
    def __init__(self):
        gr.top_block.__init__(self, "Not titled yet")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Not titled yet")
        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", "TP2c")

        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.sintonizador = sintonizador = 95.1e6
        self.samp_rate = samp_rate = 2e6
        self.fsk_deviation_hz = fsk_deviation_hz = 75e3
        self.carrier_min_freq = carrier_min_freq = sintonizador - 5e3
        self.carrier_max_freq = carrier_max_freq = sintonizador + 5e3

        ##################################################
        # Blocks
        ##################################################
        self._sintonizador_range = Range(88.1e6, 103.5e6, 200e3, 95.1e6, 200)
        self._sintonizador_win = RangeWidget(self._sintonizador_range,
                                             self.set_sintonizador,
                                             'sintonizador', "counter_slider",
                                             float)
        self.top_grid_layout.addWidget(self._sintonizador_win)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
            2048,  #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_time_sink_x_1 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #samp_rate
            "",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_1.set_update_time(0.10)
        self.qtgui_time_sink_x_1.set_y_axis(-1, 1)

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

        self.qtgui_time_sink_x_1.enable_tags(True)
        self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                  qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                                  0, "")
        self.qtgui_time_sink_x_1.enable_autoscale(False)
        self.qtgui_time_sink_x_1.enable_grid(False)
        self.qtgui_time_sink_x_1.enable_axis_labels(True)
        self.qtgui_time_sink_x_1.enable_control_panel(False)
        self.qtgui_time_sink_x_1.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_1.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_1_win = sip.wrapinstance(
            self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
            1024,  #size
            samp_rate,  #samp_rate
            "",  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)

        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, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        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 = [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.set_line_label(
                        i, "Re{{Data {0}}}".format(i / 2))
                else:
                    self.qtgui_time_sink_x_0.set_line_label(
                        i, "Im{{Data {0}}}".format(i / 2))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f(
            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)

        self.qtgui_freq_sink_x_0.set_plot_pos_half(not 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"
        ]
        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.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(
            1, [1], sintonizador, samp_rate)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1,
            '/home/fran/Documents/UCA/4to año/Radiodifusión/Drive/Unidad 1 - Introducción a la teledifusión/Practicas/radio_240k.dat',
            True, 0, 0)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)
        self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(
            samp_rate / (2 * math.pi * fsk_deviation_hz / 8.0))
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            np.pi / 200, 2 * np.pi * (carrier_max_freq / samp_rate),
            2 * np.pi * (carrier_min_freq / samp_rate))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.analog_quadrature_demod_cf_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0),
                     (self.qtgui_time_sink_x_1, 0))
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.analog_pll_refout_cc_0, 0))