示例#1
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._N = 10000000  # number of samples to use
        self._fs = 10000  # initial sampling rate
        self._decim = 20  # Decimation rate

        # Generate the prototype filter taps for the decimators with a 200 Hz bandwidth
        self._taps = gr.firdes.low_pass_2(1,
                                          self._fs,
                                          200,
                                          150,
                                          attenuation_dB=120,
                                          window=gr.firdes.WIN_BLACKMAN_hARRIS)

        # Calculate the number of taps per channel for our own information
        tpc = scipy.ceil(float(len(self._taps)) / float(self._decim))
        print "Number of taps:     ", len(self._taps)
        print "Number of filters:  ", self._decim
        print "Taps per channel:   ", tpc

        # Build the input signal source
        # We create a list of freqs, and a sine wave is generated and added to the source
        # for each one of these frequencies.
        self.signals = list()
        self.add = gr.add_cc()
        freqs = [10, 20, 2040]
        for i in xrange(len(freqs)):
            self.signals.append(
                gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1))
            self.connect(self.signals[i], (self.add, i))

        self.head = gr.head(gr.sizeof_gr_complex, self._N)

        # Construct a PFB decimator filter
        self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)

        # Construct a standard FIR decimating filter
        self.dec = gr.fir_filter_ccf(self._decim, self._taps)

        self.snk_i = gr.vector_sink_c()

        # Connect the blocks
        self.connect(self.add, self.head, self.pfb)
        self.connect(self.add, self.snk_i)

        # Create the sink for the decimated siganl
        self.snk = gr.vector_sink_c()
        self.connect(self.pfb, self.snk)
示例#2
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._N = 10000000      # number of samples to use
        self._fs = 10000        # initial sampling rate
        self._decim = 20        # Decimation rate
        
        # Generate the prototype filter taps for the decimators with a 200 Hz bandwidth
        self._taps = gr.firdes.low_pass_2(1, self._fs, 200, 150,
                                          attenuation_dB=120, window=gr.firdes.WIN_BLACKMAN_hARRIS)

        # Calculate the number of taps per channel for our own information
        tpc = scipy.ceil(float(len(self._taps)) /  float(self._decim))
        print "Number of taps:     ", len(self._taps)
        print "Number of filters:  ", self._decim
        print "Taps per channel:   ", tpc
        
        # Build the input signal source
        # We create a list of freqs, and a sine wave is generated and added to the source
        # for each one of these frequencies.
        self.signals = list()
        self.add = gr.add_cc()
        freqs = [10, 20, 2040]
        for i in xrange(len(freqs)):
            self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1))
            self.connect(self.signals[i], (self.add,i))

        self.head = gr.head(gr.sizeof_gr_complex, self._N)
        
        # Construct a PFB decimator filter
        self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)

        # Construct a standard FIR decimating filter
        self.dec = gr.fir_filter_ccf(self._decim, self._taps)

        self.snk_i = gr.vector_sink_c()

        # Connect the blocks
        self.connect(self.add, self.head, self.pfb)
        self.connect(self.add, self.snk_i)

        # Create the sink for the decimated siganl
        self.snk = gr.vector_sink_c()
        self.connect(self.pfb, self.snk)
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        options = get_options()

        self.ifreq = options.frequency
        self.rfgain = options.gain

        self.src = osmosdr.source_c(options.args)
        self.src.set_center_freq(self.ifreq)
        self.src.set_sample_rate(int(options.sample_rate))
        #sq5bpf: dodalem ppm
        self.src.set_freq_corr(8)

        if self.rfgain is None:
            self.src.set_gain_mode(1)
            self.iagc = 1
            self.rfgain = 0
        else:
            self.iagc = 0
            self.src.set_gain_mode(0)
            self.src.set_gain(self.rfgain)

        # may differ from the requested rate
        sample_rate = self.src.get_sample_rate()
        sys.stderr.write("sample rate: %d\n" % (sample_rate))

        symbol_rate = 18000
        sps = 2  # output rate will be 36,000
        out_sample_rate = symbol_rate * sps

        options.low_pass = options.low_pass / 2.0

        if sample_rate == 96000:  # FunCube Dongle
            first_decim = 2
        else:
            first_decim = 10

        self.offset = 0

        taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass,
                                  options.low_pass * 0.2, gr.firdes.WIN_HANN)
        self.tuner = gr.freq_xlating_fir_filter_ccf(first_decim, taps,
                                                    self.offset, sample_rate)

        self.demod = cqpsk.cqpsk_demod(samples_per_symbol=sps,
                                       excess_bw=0.35,
                                       costas_alpha=0.03,
                                       gain_mu=0.05,
                                       mu=0.05,
                                       omega_relative_limit=0.05,
                                       log=options.log,
                                       verbose=options.verbose)

        self.output = gr.file_sink(gr.sizeof_float, options.output_file)

        rerate = float(
            sample_rate / float(first_decim)) / float(out_sample_rate)
        sys.stderr.write("resampling factor: %f\n" % rerate)

        if rerate.is_integer():
            sys.stderr.write("using pfb decimator\n")
            self.resamp = blks2.pfb_decimator_ccf(int(rerate))
        else:
            sys.stderr.write("using pfb resampler\n")
            self.resamp = blks2.pfb_arb_resampler_ccf(1 / rerate)

        self.connect(self.src, self.tuner, self.resamp, self.demod,
                     self.output)

        self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.Main.AddPage(grc_wxgui.Panel(self.Main), "Wideband Spectrum")
        self.Main.AddPage(grc_wxgui.Panel(self.Main), "Channel Spectrum")
        self.Main.AddPage(grc_wxgui.Panel(self.Main), "Soft Bits")

        def set_ifreq(ifreq):
            self.ifreq = ifreq
            self._ifreq_text_box.set_value(self.ifreq)
            self.src.set_center_freq(self.ifreq)

        self._ifreq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.ifreq,
            callback=set_ifreq,
            label="Center Frequency",
            converter=forms.float_converter(),
        )
        self.Add(self._ifreq_text_box)

        def set_iagc(iagc):
            self.iagc = iagc
            self._agc_check_box.set_value(self.iagc)
            self.src.set_gain_mode(self.iagc, 0)
            self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0)

        self._agc_check_box = forms.check_box(
            parent=self.GetWin(),
            value=self.iagc,
            callback=set_iagc,
            label="Automatic Gain",
            true=1,
            false=0,
        )

        self.Add(self._agc_check_box)

        def set_rfgain(rfgain):
            self.rfgain = rfgain
            self._rfgain_slider.set_value(self.rfgain)
            self._rfgain_text_box.set_value(self.rfgain)
            self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0)

        _rfgain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rfgain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_rfgain_sizer,
            value=self.rfgain,
            callback=set_rfgain,
            label="RF Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._rfgain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_rfgain_sizer,
            value=self.rfgain,
            callback=set_rfgain,
            minimum=0,
            maximum=50,
            num_steps=200,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )

        self.Add(_rfgain_sizer)

        self.Add(self.Main)

        def fftsink2_callback(x, y):
            x = x - self.ifreq
            sys.stderr.write("sq5bpf: x: %d \n" % x)
            if abs(x / (sample_rate / 2)) > 0.9:
                set_ifreq(self.ifreq + x / 2)
            else:
                sys.stderr.write("coarse tuned to: %d Hz\n" % x)
                self.offset = -x
                self.tuner.set_center_freq(self.offset)
                self._rxfreq_text_box.set_value(self.ifreq -
                                                self.offset)  #sq5bpf

        self.scope = fftsink2.fft_sink_c(
            self.Main.GetPage(0).GetWin(),
            title="Wideband Spectrum (click to coarse tune)",
            baseband_freq=self.ifreq,  #sq5bpf
            fft_size=1024,
            sample_rate=sample_rate,
            ref_scale=2.0,
            ref_level=0,
            y_divs=10,
            fft_rate=10,
            average=False,
            avg_alpha=0.6)

        self.Main.GetPage(0).Add(self.scope.win)
        self.scope.set_callback(fftsink2_callback)

        self.connect(self.src, self.scope)

        def fftsink2_callback2(x, y):
            self.offset = self.offset - (x / 10)
            sys.stderr.write("fine tuned to: %d Hz\n" % self.offset)
            self.tuner.set_center_freq(self.offset)
            self._rxfreq_text_box.set_value(self.ifreq - self.offset)  #sq5bpf

        self.scope2 = fftsink2.fft_sink_c(
            self.Main.GetPage(1).GetWin(),
            title="Channel Spectrum (click to fine tune)",
            fft_size=1024,
            sample_rate=out_sample_rate,
            ref_scale=2.0,
            ref_level=-20,
            y_divs=10,
            fft_rate=10,
            average=False,
            avg_alpha=0.6)

        self.Main.GetPage(1).Add(self.scope2.win)
        self.scope2.set_callback(fftsink2_callback2)

        self.connect(self.resamp, self.scope2)

        self.scope3 = scopesink2.scope_sink_f(
            self.Main.GetPage(2).GetWin(),
            title="Soft Bits",
            sample_rate=out_sample_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0.001,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Main.GetPage(2).Add(self.scope3.win)

        self.connect(self.demod, self.scope3)
        #sq5bpf
        self._rxfreq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.ifreq - self.offset,
            label="RX Freq",
            converter=forms.float_converter(),
        )
        self.Add(self._rxfreq_text_box)
  def __init__(self):
    grc_wxgui.top_block_gui.__init__(self, title="Top Block")

    options = get_options()

    self.ifreq = options.frequency
    self.rfgain = options.gain
    self.offset = options.frequency_offset

    self.src = osmosdr.source_c(options.args)
    self.src.set_center_freq(self.ifreq)
    self.src.set_sample_rate(int(options.sample_rate))

    if self.rfgain is None:
        self.src.set_gain_mode(1)
        self.iagc = 1
        self.rfgain = 0
    else:
        self.iagc = 0
        self.src.set_gain_mode(0)
        self.src.set_gain(self.rfgain)

    # may differ from the requested rate
    sample_rate = self.src.get_sample_rate()
    sys.stderr.write("sample rate: %d\n" % (sample_rate))

    symbol_rate = 18000
    sps = 2 # output rate will be 36,000
    out_sample_rate = symbol_rate * sps

    options.low_pass = options.low_pass / 2.0

    if sample_rate == 96000: # FunCube Dongle
        first_decim = 2
    else:
        first_decim = 10

    self.offset = 0

    taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, gr.firdes.WIN_HANN)
    self.tuner = gr.freq_xlating_fir_filter_ccf(first_decim, taps, self.offset, sample_rate)

    self.demod = cqpsk.cqpsk_demod(
        samples_per_symbol = sps,
        excess_bw=0.35,
        costas_alpha=0.03,
        gain_mu=0.05,
        mu=0.05,
        omega_relative_limit=0.05,
        log=options.log,
        verbose=options.verbose)

    self.output = gr.file_sink(gr.sizeof_float, options.output_file)

    rerate = float(sample_rate / float(first_decim)) / float(out_sample_rate)
    sys.stderr.write("resampling factor: %f\n" % rerate)

    if rerate.is_integer():
        sys.stderr.write("using pfb decimator\n")
        self.resamp = blks2.pfb_decimator_ccf(int(rerate))
    else:
        sys.stderr.write("using pfb resampler\n")
        self.resamp = blks2.pfb_arb_resampler_ccf(1 / rerate)

    self.connect(self.src, self.tuner, self.resamp, self.demod, self.output)

    self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
    self.Main.AddPage(grc_wxgui.Panel(self.Main), "Wideband Spectrum")
    self.Main.AddPage(grc_wxgui.Panel(self.Main), "Channel Spectrum")
    self.Main.AddPage(grc_wxgui.Panel(self.Main), "Soft Bits")

    def set_ifreq(ifreq):
        self.ifreq = ifreq
        self._ifreq_text_box.set_value(self.ifreq)
        self.src.set_center_freq(self.ifreq)

    self._ifreq_text_box = forms.text_box(
        parent=self.GetWin(),
        value=self.ifreq,
        callback=set_ifreq,
        label="Center Frequency",
        converter=forms.float_converter(),
    )
    self.Add(self._ifreq_text_box)

    def set_iagc(iagc):
        self.iagc = iagc
        self._agc_check_box.set_value(self.iagc)
        self.src.set_gain_mode(self.iagc, 0)
        self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0)

    self._agc_check_box = forms.check_box(
        parent=self.GetWin(),
        value=self.iagc,
        callback=set_iagc,
        label="Automatic Gain",
        true=1,
        false=0,
    )

    self.Add(self._agc_check_box)

    def set_rfgain(rfgain):
        self.rfgain = rfgain
        self._rfgain_slider.set_value(self.rfgain)
        self._rfgain_text_box.set_value(self.rfgain)
        self.src.set_gain(0 if self.iagc == 1 else self.rfgain, 0)

    _rfgain_sizer = wx.BoxSizer(wx.VERTICAL)
    self._rfgain_text_box = forms.text_box(
        parent=self.GetWin(),
        sizer=_rfgain_sizer,
        value=self.rfgain,
        callback=set_rfgain,
        label="RF Gain",
        converter=forms.float_converter(),
        proportion=0,
    )
    self._rfgain_slider = forms.slider(
        parent=self.GetWin(),
        sizer=_rfgain_sizer,
        value=self.rfgain,
        callback=set_rfgain,
        minimum=0,
        maximum=50,
        num_steps=200,
        style=wx.SL_HORIZONTAL,
        cast=float,
        proportion=1,
    )

    self.Add(_rfgain_sizer)

    self.Add(self.Main)

    def fftsink2_callback(x, y):
        if abs(x / (sample_rate / 2)) > 0.9:
            set_ifreq(self.ifreq + x / 2)
        else:
            self.offset = -x
            sys.stderr.write("coarse tuned to: %d Hz => %d Hz\n" % (self.offset, (self.ifreq + self.offset)))
            self.tuner.set_center_freq(self.offset)

    self.scope = fftsink2.fft_sink_c(self.Main.GetPage(0).GetWin(),
        title="Wideband Spectrum (click to coarse tune)",
        fft_size=1024,
        sample_rate=sample_rate,
        ref_scale=2.0,
        ref_level=0,
        y_divs=10,
        fft_rate=10,
        average=False,
        avg_alpha=0.6)

    self.Main.GetPage(0).Add(self.scope.win)
    self.scope.set_callback(fftsink2_callback)

    self.connect(self.src, self.scope)

    def fftsink2_callback2(x, y):
        self.offset = self.offset - (x / 10)
        sys.stderr.write("fine tuned to: %d Hz => %d Hz\n" % (self.offset, (self.ifreq + self.offset)))
        self.tuner.set_center_freq(self.offset)

    self.scope2 = fftsink2.fft_sink_c(self.Main.GetPage(1).GetWin(),
        title="Channel Spectrum (click to fine tune)",
        fft_size=1024,
        sample_rate=out_sample_rate,
        ref_scale=2.0,
        ref_level=-20,
        y_divs=10,
        fft_rate=10,
        average=False,
        avg_alpha=0.6)

    self.Main.GetPage(1).Add(self.scope2.win)
    self.scope2.set_callback(fftsink2_callback2)

    self.connect(self.resamp, self.scope2)

    self.scope3 = scopesink2.scope_sink_f(
        self.Main.GetPage(2).GetWin(),
        title="Soft Bits",
        sample_rate=out_sample_rate,
        v_scale=0,
        v_offset=0,
        t_scale=0.001,
        ac_couple=False,
        xy_mode=False,
        num_inputs=1,
        trig_mode=gr.gr_TRIG_MODE_AUTO,
        y_axis_label="Counts",
	)
    self.Main.GetPage(2).Add(self.scope3.win)

    self.connect(self.demod, self.scope3)