def __init__(self, decim=32, sync_check=False, satellite='METEOR-M-1', baseband_file=os.environ['HOME'] + '/METEOR-M-1.dat', frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt'):
		gr.top_block.__init__(self, "Meteor M N1 HRPT Baseband To Frames")

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.sync_check = sync_check
		self.satellite = satellite
		self.baseband_file = baseband_file
		self.frames_file = frames_file

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/mn1_hrpt.conf'
		self._saved_pll_alpha_config = ConfigParser.ConfigParser()
		self._saved_pll_alpha_config.read(config_filename)
		try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_clock_alpha_config = ConfigParser.ConfigParser()
		self._saved_clock_alpha_config.read(config_filename)
		try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(sync_check)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_mn1_hrpt_deframer_0, 0))
		self.connect((self.poesweather_mn1_hrpt_deframer_0, 0), (self.frame_sink, 0))
Exemplo n.º 2
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] samples_file"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-m", "--dab-mode", type="int", default=1,
            help="DAB mode [default=%default]")
        parser.add_option("-c", "--complex", action="store_true", default=False,
            help="Sample file is float complex (64 bit per sample, 32 I + 32 Q) format")
        parser.add_option("-n", "--config", type="string", default="channel.conf",
            help="DAB+ channel configuration file [default=%default]")
        
        (options, args) = parser.parse_args ()
        
        if len(args)<1:
            print "error: need file with samples"
            sys.exit(1)
        else:
            filename = args[0]
            if options.complex:
                src = gr.file_source(gr.sizeof_gr_complex, filename, True)
            else:
                sinput = gr.file_source(gr.sizeof_short, filename, True)
                src = gr.interleaved_short_to_complex()
                self.connect(sinput, src)

        self.conf = options.config
        
        mode=options.dab_mode
        param = dabp.parameters(mode)
        # null symbol detector
        samples_per_null_sym=param.get_Nnull()
        #print "samples per null symbol : %d" % samples_per_null_sym
        nulldet = dabp.detect_null(samples_per_null_sym)
        # ofdm demod
        demod = dabp.ofdm_demod(mode)
        # FIC/MSC demultiplexer
        demux = dabp.fic_msc_demux(0, mode)
        # depuncturer
        punc = dabp.depuncturer_fic(mode)
        I=punc.getI()
        # viterbi
        vit = dabp.vitdec(I)
        # descrambler
        scram = dabp.scrambler(I)
        # FIB sink
        self.dst = dabp.fib_sink()
        
        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(src, nulldet)
        self.connect(src, (demod,0))
        self.connect(nulldet, (demod,1))
        self.connect((demod,0), demux, punc, vit, scram, self.dst)
        self.connect((demod,1), nullsink)
Exemplo n.º 3
0
 def __init__(self, mode, freq, gain, conf, subchid, record=None, usrp=True):
     gr.top_block.__init__(self)
     
     if usrp: # set up usrp source
         src = dabp_usrp.setup_usrp(freq, gain)
     else: # set up sample file source
         sinput = gr.file_source(gr.sizeof_short, samp.encode('ascii'), False)
         src = gr.interleaved_short_to_complex()
         self.connect(sinput, src)
         
     # channel configuration
     cc = dabp.channel_conf(conf)
     #sys.stderr.write("Playing Channel: "+cc.get_label(options.subchid)+"\n")
     
     start_addr = cc.get_start_addr(subchid)
     subchsz = cc.get_subchsz(subchid)
     optprot = cc.get_optprot(subchid)
     #print "start_addr=%d, subchsz=%d, optprot=%d" % (start_addr, subchsz, optprot)
     
     param = dabp.parameters(mode)
     
     # null symbol detector
     samples_per_null_sym=param.get_Nnull()
     #print "samples per null symbol : %d" % samples_per_null_sym
     nulldet = dabp.detect_null(samples_per_null_sym)
     # ofdm demod
     demod = dabp.ofdm_demod(mode)
     # FIC/MSC demultiplexer
     demux = dabp.fic_msc_demux(1, mode)
     
     cifsz = param.get_cifsz()
     scs = dabp.subchannel_selector(cifsz,start_addr,subchsz)
     intlv = dabp.time_deinterleaver(subchsz)
     punc = dabp.depuncturer(subchsz,optprot)
     I = punc.getI()
     vit = dabp.vitdec(I)
     scram = dabp.scrambler(I)
     len_logfrm=scram.get_nbytes()
     sync = dabp.super_frame_sync(len_logfrm)
     subchidx = sync.get_subchidx()
     rs = dabp.super_frame_rsdec(subchidx)
     if record == None:
         mplayer = subprocess.Popen(['mplayer', '-af', 'volume=20', '-ac', '+faad', '-rawaudio', 'format=0xff', '-demuxer', '+rawaudio','-'], stdin=subprocess.PIPE)
         dst = dabp.super_frame_sink(subchidx, mplayer.stdin.fileno())
     else:
         dst = dabp.super_frame_sink(subchidx, record.encode('ascii'))
     
     nullsink = gr.null_sink(gr.sizeof_char)
     # connect everything
     self.connect(src, nulldet)
     self.connect(src, (demod,0))
     self.connect(nulldet, (demod,1))
     self.connect((demod,0), demux, scs, intlv, punc, vit, scram, sync, rs, dst)
     self.connect((demod,1), nullsink)
Exemplo n.º 4
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        parser.add_option("-d", "--decim", type="int", default=16,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-W", "--waterfall", action="store_true", default=False,
                          help="Enable waterfall display")
        parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
                          help="Enable oscilloscope display")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
	self.options = options
        self.options.gain = 1.0
        self.show_debug_info = True
        

        input_rate = 100e6 / options.decim

        self.src = gr.file_descriptor_source(gr.sizeof_short, 0, False);
        self.s2c = gr.interleaved_short_to_complex()

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.oscilloscope:
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
        else:
            self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, y_divs=12, sample_rate=input_rate,ref_level=110,fft_rate=20)

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

        self._build_gui(vbox)
	self._setup_events()
	
        # set initial values

        if options.freq is None:
            # if no freq was specified, use the mid-point
            options.freq = 0.0

        if self.show_debug_info:
            self.myform['decim'].set_value(self.options.decim)
Exemplo n.º 5
0
	def __init__(self, input_filename="usrp.dat", output_filename="frames.dat", decim=32, pll_alpha=0.01, clock_alpha=0.01):
		gr.top_block.__init__(self, "Hrpt Demod")

		##################################################
		# Parameters
		##################################################
		self.input_filename = input_filename
		self.output_filename = output_filename
		self.decim = decim
		self.pll_alpha = pll_alpha
		self.clock_alpha = clock_alpha

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 4e6
		self.sps = sps = sample_rate/sym_rate
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.noaa_hrpt_deframer_0 = noaa.hrpt_deframer()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.gr_file_sink_0.set_unbuffered(False)
		self.file_source = gr.file_source(gr.sizeof_short*1, input_filename, False)
		self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
		self.decoder = noaa.hrpt_decoder(True,False)
		self.cs2cf = gr.interleaved_short_to_complex()
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)

		##################################################
		# Connections
		##################################################
		self.connect((self.file_source, 0), (self.cs2cf, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.noaa_hrpt_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
		self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0))
		self.connect((self.digital_binary_slicer_fb_0, 0), (self.noaa_hrpt_deframer_0, 0))
Exemplo n.º 6
0
 def __init__(self, mode, freq, gain, conf, samp=None, usrp=True):
     gr.top_block.__init__(self)
     
     if usrp: # set up usrp source
         src = dabp_usrp.setup_usrp(freq, gain)
     else: # set up sample file source
         sinput = gr.file_source(gr.sizeof_short, samp.encode('ascii'), False)
         src = gr.interleaved_short_to_complex()
         self.connect(sinput, src)
         
     param = dabp.parameters(mode)
     # null symbol detector
     samples_per_null_sym=param.get_Nnull()
     #print "samples per null symbol : %d" % samples_per_null_sym
     nulldet = dabp.detect_null(samples_per_null_sym)
     # ofdm demod
     demod = dabp.ofdm_demod(mode)
     # FIC/MSC demultiplexer
     demux = dabp.fic_msc_demux(0, mode)
     # depuncturer
     punc = dabp.depuncturer_fic(mode)
     I=punc.getI()
     # viterbi
     vit = dabp.vitdec(I)
     # descrambler
     scram = dabp.scrambler(I)
     # FIB sink
     self.dst = dabp.fib_sink()
     
     nullsink = gr.null_sink(gr.sizeof_char)
     # connect everything
     self.connect(src, nulldet)
     self.connect(src, (demod,0))
     self.connect(nulldet, (demod,1))
     self.connect((demod,0), demux, punc, vit, scram, self.dst)
     self.connect((demod,1), nullsink)
     
Exemplo n.º 7
0
    def __init__(self, mode, freq, gain, conf, samp=None, usrp=True):
        gr.top_block.__init__(self)

        if usrp:  # set up usrp source
            src = dabp_usrp.setup_usrp(freq, gain)
        else:  # set up sample file source
            sinput = gr.file_source(gr.sizeof_short, samp.encode('ascii'),
                                    False)
            src = gr.interleaved_short_to_complex()
            self.connect(sinput, src)

        param = dabp.parameters(mode)
        # null symbol detector
        samples_per_null_sym = param.get_Nnull()
        #print "samples per null symbol : %d" % samples_per_null_sym
        nulldet = dabp.detect_null(samples_per_null_sym)
        # ofdm demod
        demod = dabp.ofdm_demod(mode)
        # FIC/MSC demultiplexer
        demux = dabp.fic_msc_demux(0, mode)
        # depuncturer
        punc = dabp.depuncturer_fic(mode)
        I = punc.getI()
        # viterbi
        vit = dabp.vitdec(I)
        # descrambler
        scram = dabp.scrambler(I)
        # FIB sink
        self.dst = dabp.fib_sink()

        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(src, nulldet)
        self.connect(src, (demod, 0))
        self.connect(nulldet, (demod, 1))
        self.connect((demod, 0), demux, punc, vit, scram, self.dst)
        self.connect((demod, 1), nullsink)
    def __init__(self,
                 frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt',
                 decim=32,
                 satellite='NOAA-XX',
                 baseband_file=os.environ['HOME'] + '/NOAA-XX.dat',
                 sync_check=False):
        grc_wxgui.top_block_gui.__init__(self,
                                         title="NOAA HRPT Baseband To Frames")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.frames_file = frames_file
        self.decim = decim
        self.satellite = satellite
        self.baseband_file = baseband_file
        self.sync_check = sync_check

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/noaa_hrpt.conf'
        self.sps = sps = sample_rate / sym_rate
        self._saved_pll_alpha_config = ConfigParser.ConfigParser()
        self._saved_pll_alpha_config.read(config_filename)
        try:
            saved_pll_alpha = self._saved_pll_alpha_config.getfloat(
                "satname", 'pll_alpha')
        except:
            saved_pll_alpha = 0.01
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_clock_alpha_config = ConfigParser.ConfigParser()
        self._saved_clock_alpha_config.read(config_filename)
        try:
            saved_clock_alpha = self._saved_clock_alpha_config.getfloat(
                "satname", 'clock_alpha')
        except:
            saved_clock_alpha = 0.01
        self.saved_clock_alpha = saved_clock_alpha
        self.sync_check_txt = sync_check_txt = sync_check
        self.satname_txt = satname_txt = satellite
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self.frames_file_txt = frames_file_txt = frames_file
        self.decim_txt = decim_txt = decim
        self.clock_alpha = clock_alpha = saved_clock_alpha
        self.baseband_file_txt = baseband_file_txt = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays),
                              "NOAA HRPT Spectrum")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
        self.Add(self.displays)

        ##################################################
        # Controls
        ##################################################
        self._sync_check_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.sync_check_txt,
            callback=self.set_sync_check_txt,
            label="Sync check",
            converter=forms.int_converter(),
        )
        self.GridAdd(self._sync_check_txt_static_text, 0, 3, 1, 1)
        self._satname_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.satname_txt,
            callback=self.set_satname_txt,
            label="Satellite",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._satname_txt_static_text, 0, 0, 1, 1)
        _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            minimum=0.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 1, 0, 1, 1)
        self._frames_file_txt_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.frames_file_txt,
            callback=self.set_frames_file_txt,
            label="Frames output filename",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._frames_file_txt_static_text, 2,
                                         0, 1, 1)
        self._decim_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.decim_txt,
            callback=self.set_decim_txt,
            label="Decimation",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._decim_txt_static_text, 0, 1, 1, 1)
        _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            label="Clock Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            minimum=0.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 1, 1, 1, 1)
        self._baseband_file_txt_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.baseband_file_txt,
            callback=self.set_baseband_file_txt,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._baseband_file_txt_static_text,
                                         1, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder(True, False)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1,
                                       "/home/jerry/NOAA-XX.hrpt")
        self.frame_sink.set_unbuffered(False)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_short * 1,
            "/home/jerry/hrpt/baseband/NOAA-18/2011-01-07T132821-NOAA-18.dat",
            False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(
            sync_check)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=45,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="NOAA HRPT Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).Add(self.rx_fft.win)
        self.throttle = gr.throttle(gr.sizeof_short * 1, sample_rate * 10)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.throttle, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.frame_sink, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.decoder, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_noaa_hrpt_deframer_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        parser.add_option("-w", "--which", type="int", default=0,
                          help="select which USRP (0, 1, ...) default is %default",
			  metavar="NUM")
#        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
#                          help="select USRP Rx side A or B (default=first one with a daughterboard)")
        parser.add_option("-A", "--antenna", default=None,
                          help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option("-d", "--decim", type="int", default=32,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=0.0,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-W", "--waterfall", action="store_true", default=False,
                          help="Enable waterfall display")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
#        parser.add_option( "--no-hb", action="store_true", default=False,
#                          help="don't use halfband filter in usrp")
        parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
                          help="Enable oscilloscope display (default)")
        parser.add_option("-F", "--fft", action="store_true", default=False,
                          help="Enable FFT display")
        parser.add_option("-n", "--frame-decim", type="int", default=1,
                          help="set oscope frame decimation factor to n [default=1]")
        parser.add_option("-v", "--v-scale", type="eng_float", default=1,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=10e-6,
                          help="set oscope initial s/div to SCALE [default=10us]")
        parser.add_option ("--digital", action="store_true", default=False, 
                       help="show (only) the digital wave on lsb (will be input from gpio pins with special usrp firmware)")
        parser.add_option ("--analog", action="store_true", default=False, 
                       help="show (only) the analog wave on msbs (will be input from analog inputs)")
        parser.add_option ("--file",  default=None, 
                       help="input from file FILE in stead of USRP (will be input from raw file in interleaved short format)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
	self.options = options
        self.show_debug_info = True

        self.u = usrp.source_s(which=options.which, decim_rate=options.decim, fpga_filename=gpio.fpga_filename)

        print "Warning: This script only supports boards on RXA, change the script if you want otherwise"
        #options.rx_subdev_spec=(0, 0)#force the use of RXA 
        options.rx_subdev_spec=None   #force the use of RXA      

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)

        #This hardcoded mux setting is why this script only supports RXA
        #We want both I and Q active, even when using basicRX
        #set to 0x10 for RXA
        #set to 0x32 for RXB
        self.u.set_mux(0x10) #usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        if options.width_8:
            width = 8
            shift = 8
            format = self.u.make_format(width, shift)
            print "format =", hex(format)
            r = self.u.set_format(format)
            print "set_format =", r
            
        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        #if options.rx_subdev_spec==(0,0):
        #  rx_subdev_spec2=(0,1)
        #  self.subdev2 = usrp.selected_subdev(self.u, rx_subdev_spec2)
        input_rate = self.u.adc_freq() / self.u.decim_rate()

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.fft:
            self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        else: # options.oscilloscope:
            #self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate,
                                            frame_decim=options.frame_decim,
                                            v_scale=options.v_scale,
                                            t_scale=options.t_scale)

        self.is2c = gr.interleaved_short_to_complex()
        if not (options.file is None):
          self.filesrc=gr.file_source(gr.sizeof_short, options.file, True)
          thr = gr.throttle(gr.sizeof_short, input_rate)
          self.connect(self.filesrc,thr,self.is2c,self.scope)
        elif options.digital:
          self.select_dig=gpio.and_const_ss(0x0001)
          self.connect(self.u, self.select_dig,self.is2c,self.scope)
        elif options.analog:
          self.select_ana=gpio.and_const_ss(0xFFFE)
          self.connect(self.u, self.select_ana,self.is2c,self.scope)
        else:
          self.connect(self.u,self.is2c,self.scope)

        self._build_gui(vbox)
	self._setup_events()
	
        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2

        if options.freq is None:
            # if no freq was specified, use the mid-point
            r = self.subdev.freq_range()
            options.freq = float(r[0]+r[1])/2

        self.set_gain(options.gain)

	if options.antenna is not None:
            print "Selecting antenna %s" % (options.antenna,)
            self.subdev.select_rx_antenna(options.antenna)

        if self.show_debug_info:
            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
            self.myform['dbname'].set_value(self.subdev.name())
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)

        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 10
0
    def __init__(self, input_filename="usrp.dat", decim=32):
        grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.input_filename = input_filename
        self.decim = decim

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self.sps = sps = sample_rate / sym_rate
        self._saved_pll_alpha_config = ConfigParser.ConfigParser()
        self._saved_pll_alpha_config.read(config_filename)
        try:
            saved_pll_alpha = self._saved_pll_alpha_config.getfloat(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            saved_pll_alpha = 0.01
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_clock_alpha_config = ConfigParser.ConfigParser()
        self._saved_clock_alpha_config.read(config_filename)
        try:
            saved_clock_alpha = self._saved_clock_alpha_config.getfloat(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            saved_clock_alpha = 0.01
        self.saved_clock_alpha = saved_clock_alpha
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self.clock_alpha = clock_alpha = saved_clock_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Spectrum")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Demod")
        self.GridAdd(self.displays, 1, 0, 1, 2)

        ##################################################
        # Controls
        ##################################################
        _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            minimum=0.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 0, 0, 1, 1)
        _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            label="Clock Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            minimum=0.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 0, 1, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder(True, False)
        self.deframer = noaa.hrpt_deframer()
        self.demod_scope = scopesink2.scope_sink_f(
            self.displays.GetPage(1).GetWin(),
            title="Post-Demod",
            sample_rate=sym_rate * 2.0,
            v_scale=0.5,
            v_offset=0,
            t_scale=10.0 / sym_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(1).GridAdd(self.demod_scope.win, 0, 0, 1, 1)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               input_filename, False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=8,
            ref_level=-5,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.1,
            title="RX Spectrum",
            peak_hold=False,
            size=(640, 360),
        )
        self.displays.GetPage(0).GridAdd(self.rx_fft.win, 0, 0, 1, 1)
        self.throttle = gr.throttle(gr.sizeof_short * 1, 2 * sample_rate)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.demod_scope, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.throttle, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0), (self.deframer, 0))
    def __init__(self,
                 decim=32,
                 freq=1698e6,
                 gain=35,
                 side="A",
                 frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt',
                 baseband_file=os.environ['HOME'] + '/NOAA-XX.dat',
                 satellite='NOAA-XX',
                 sync_check=False):
        gr.top_block.__init__(self, "USRP NOAA HRPT Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.decim = decim
        self.freq = freq
        self.gain = gain
        self.side = side
        self.frames_file = frames_file
        self.baseband_file = baseband_file
        self.satellite = satellite
        self.sync_check = sync_check

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.samp_rate = samp_rate = 64e6 / decim
        self.sps = sps = samp_rate / sym_rate
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/noaa_hrpt.conf'
        self._saved_pll_alpha_config = ConfigParser.ConfigParser()
        self._saved_pll_alpha_config.read(config_filename)
        try:
            saved_pll_alpha = self._saved_pll_alpha_config.getfloat(
                "satname", 'pll_alpha')
        except:
            saved_pll_alpha = 0.005
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
        except:
            saved_gain = gain
        self.saved_gain = saved_gain
        self._saved_clock_alpha_config = ConfigParser.ConfigParser()
        self._saved_clock_alpha_config.read(config_filename)
        try:
            saved_clock_alpha = self._saved_clock_alpha_config.getfloat(
                "satname", 'clock_alpha')
        except:
            saved_clock_alpha = 0.001
        self.saved_clock_alpha = saved_clock_alpha
        self.max_clock_offset = max_clock_offset = 0.1
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate
        self.hs = hs = int(sps / 2.0)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-5, 1.0, 1.0 / 32768.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, saved_clock_alpha**2 / 4.0, 0.5, saved_clock_alpha,
            max_clock_offset)
        self.gr_file_sink_0 = gr.file_sink(gr.sizeof_short * 1, baseband_file)
        self.gr_file_sink_0.set_unbuffered(False)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False)
        self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(
            sync_check)
        self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0,
                                                               side=side,
                                                               rx_ant="RXA")
        self.usrp_simple_source_x_0.set_decim_rate(decim)
        self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
        self.usrp_simple_source_x_0.set_gain(gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.noaa_hrpt_decoder_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_noaa_hrpt_deframer_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_file_sink_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
Exemplo n.º 12
0
    def __init__(self,frame,panel,vbox,argv):
        stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)

        usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser=OptionParser(option_class=eng_option)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=64,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-o", "--out-filename", type="string", default="sdl",
                          help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat file in a loop")
        parser.add_option("-N", "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")

        (options, args) = parser.parse_args()
        if not ((len(args) == 1) or (len(args) == 0)):
            parser.print_help()
            sys.exit(1)
        
        if len(args) == 1:
          filename = args[0]
        else:
          filename = None

        self.frame = frame
        self.panel = panel
        
        self.contrast = options.contrast
        self.brightness = options.brightness
        self.state = "FREQ"
        self.freq = 0

        # build graph

        self.u=None

        usrp_decim = options.decim # 32

        if not (options.out_filename=="sdl"):
          options.repeat=False

        if not ((filename is None) or (filename=="usrp")):
          self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat) # file is data source
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          adc_rate=64e6
          self.src=self.istoc
          options.gain=0.0
          self.gain=0.0
        else:
          if options.no_hb or (options.decim<8):
            self.fpga_filename="std_4rx_0tx.rbf" #contains 4 Rx paths without halfbands and 0 tx paths
          else:
            self.fpga_filename="std_2rxhb_2tx.rbf" # contains 2 Rx paths with halfband filters and 2 tx paths (the default)
          self.u = usrp.source_c(0,fpga_filename=self.fpga_filename)                    # usrp is data source
          if options.width_8:
              sample_width = 8
              sample_shift = 8
              format = self.u.make_format(sample_width, sample_shift)
              r = self.u.set_format(format)
          adc_rate = self.u.adc_rate()                # 64 MS/s
          self.u.set_decim_rate(usrp_decim)
          if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)
          self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
          self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
          print "Using RX d'board %s" % (self.subdev.side_and_name(),)
          if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2
          self.src=self.u

        usrp_rate = adc_rate / usrp_decim           # 320 kS/s

        f2uc=gr.float_to_uchar()
        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL
        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768
        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640
        width=int(usrp_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if (options.out_filename=="sdl"):
          #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height,0,show_width,height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" + options.out_filename
          print "(Use the spacebar to advance to next frames)" 
          options.repeat=False
          file_sink=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink 

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0)

        # now wire it all together
        #sample_rate=options.width*options.height*options.framerate

        process_type='do_no_sync'
        if process_type=='do_no_sync':
          self.connect (self.src, self.agc,self.am_demod,self.invert_and_scale, self.set_blacklevel,f2uc,self.dst)
        elif process_type=='do_tv_sync_adv':
          #defaults: gr.tv_sync_adv (double sampling_freq, unsigned int tv_format,bool output_active_video_only=false, bool do_invert=false, double wanted_black_level=0.0, double wanted_white_level=255.0, double avg_alpha=0.1, double initial_gain=1.0, double initial_offset=0.0,bool debug=false)
          self.tv_sync_adv=gr.tv_sync_adv(usrp_rate,0,False,False,0.0,255.0,0.01,1.0,0.0,False) #note, this block is not yet in cvs
          self.connect (self.src, self.am_demod,self.invert_and_scale,self.tv_sync_adv,s2f,f2uc,self.dst) 
        elif process_type=='do_nullsink':
          #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
          c2r=gr.complex_to_real()
          nullsink=gr.null_sink(gr.sizeof_float)
          self.connect (self.src, c2r,nullsink) #video_sink)
        elif process_type=='do_tv_sync_corr':
          frame_size=width*height #int(usrp_rate/25.0)
          nframes=10# 32
          search_window=20*nframes 
          debug=False
          video_alpha=0.3 #0.1
          corr_alpha=0.3
          tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window, video_alpha, corr_alpha,debug) #Note: this block is not yet in cvs
          shift=gr.add_const_ff(-0.7)
          self.connect (self.src, self.agc,self.am_demod,tv_corr,self.invert_and_scale, self.set_blacklevel,f2uc,self.dst) #self.agc,
        else: # process_type=='do_test_image':
          src_vertical_bars = gr.sig_source_f (usrp_rate, gr.GR_SIN_WAVE, 10.0 *usrp_rate/320, 255,128)
          self.connect(src_vertical_bars,f2uc,self.dst)

        self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate)

   
        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values
        self.set_gain(options.gain)
        self.set_contrast(self.contrast)
        self.set_brightness(options.brightness)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 13
0
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                wxDefaultPosition)

        self.pga = 0
        self.pgaMin = -20
        self.pgaMax = 0
        self.pgaStep = 0.25

# Parsing options
        parser = OptionParser(option_class=eng_option,
                usage="usage: %prog [options] filename1" \
                " [-f frequency2 filename2 [...]]")
        parser.add_option("-a", "--agc", action="store_true",
                help="enable agc")
        parser.add_option("-c", "--clockrate", type="eng_float", default=128e6,
                help="set USRP clock rate (128e6)")
        parser.add_option("--copy", action="store_true",
                help="enable real to imag data copy when in real mode")
        parser.add_option("-e", "--encoding", type="choice", choices=["s", "f"],
                default="f", help="choose data encoding: [s]igned or [f]loat.")
        parser.add_option("-f", "--frequency", type="eng_float",
                action="callback", callback=appendFrequency,
                help="set output frequency (222.064e6)")
        parser.add_option("-g", "--gain", type="float",
                help="set output pga gain")
        parser.add_option("-l", "--list", action="callback", callback=listUsrp,
                help="list USRPs and daugtherboards")
        parser.add_option("-m", "--mode", type="eng_float", default=2,
                help="mode: 1: real, 2: complex (2)")
        parser.add_option("-o", "--osc", action="store_true",
                help="enable oscilloscope")
        parser.add_option("-r", "--samplingrate", type="eng_float",
                default=3.2e6,
                help="set input sampling rate (3200000)")
        parser.add_option("-s", "--spectrum", action="store_true",
                help="enable spectrum analyzer")
#        parser.add_option("-t", "--tx", type="choice", choices=["A", "B"],
#                default="A", help="choose USRP tx A|B output (A)")
        parser.add_option("-u", "--usrp", action="store_true",
                help="enable USRP output")

        (options, args) = parser.parse_args()
        if len(args) == 0 :
            options.filename = [ "/dev/stdin" ]
        else :
            options.filename = args
# Setting default frequency
        if options.frequency is None :
            options.frequency = [ 222.064e6 ]
        if len(options.filename) != len(options.frequency) :
            parser.error("Nb input file != nb frequency!")

# Status bar
#        self.CreateStatusBar(3, 0)
#        msg = "PGA: %.2f dB" % (self.pga * self.pgaStep)
#        self.SetStatusText(msg, 1)
#        msg = "Freq: %.3f mHz" % (options.frequency[0] / 1000000.0)
#        self.SetStatusText(msg, 2)

# Menu bar
        menu = wxMenu()
        menu.Append(ID_ABOUT, "&About",
                "More information about this program")
        menu.AppendSeparator()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = wxMenuBar()
        menuBar.Append(menu, "&File")
        self.SetMenuBar(menuBar)
        

# Main windows
        mainSizer = wxFlexGridSizer(0, 1)
        sliderSizer = wxFlexGridSizer(0, 2)
        buttonSizer = wxBoxSizer(wxHORIZONTAL)

        if options.usrp :
            # TX d'board 0
            gainLabel = wxStaticText(self, -1, "PGA 0")
            gainSlider = wxSlider(self, ID_GAIN_SLIDER0, self.pga,
                    self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep,
                    style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
            gainSlider.SetSize((400, -1))
            sliderSizer.Add(gainLabel, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
            sliderSizer.Add(gainSlider, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            freqLabel = wxStaticText(self, -1, "Frequency 0")
            freqSlider = wxSlider(self, ID_FREQ_SLIDER0,
                    options.frequency[0] / 16000, 0, 20e3,
                    style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
            freqSlider.SetSize((400, -1))
            sliderSizer.Add(freqLabel, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
            sliderSizer.Add(freqSlider, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            if len(options.frequency) > 1 :
                # TX d'board 1
                gainLabel = wxStaticText(self, -1, "PGA 1")
                gainSlider = wxSlider(self, ID_GAIN_SLIDER1, self.pga,
                        self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep,
                        style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
                gainSlider.SetSize((400, -1))
                sliderSizer.Add(gainLabel, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
                sliderSizer.Add(gainSlider, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

                freqLabel = wxStaticText(self, -1, "Frequency 1")
                freqSlider = wxSlider(self, ID_FREQ_SLIDER1,
                        options.frequency[1] / 16000, 0, 20e3,
                        style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
                freqSlider.SetSize((400, -1))
                sliderSizer.Add(freqLabel, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
                sliderSizer.Add(freqSlider, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            mainSizer.Add(sliderSizer, 1, wxEXPAND, 0)

        start = wxButton(self, ID_START, "Start")
        stop = wxButton(self, ID_STOP, "Stop")
        buttonSizer.Add(start, 1, wxALIGN_CENTER, 0)
        buttonSizer.Add(stop, 1, wxALIGN_CENTER, 0)
        mainSizer.Add(buttonSizer, 1, wxEXPAND, 0)
    
# GnuRadio
        self.fg = gr.flow_graph()
        if options.mode == 1 :
            print "Source: real"
            if (options.encoding == "s") :
                print "Source encoding: short"
                src = gr.file_source(gr.sizeof_short, options.filename[0], 1)
                if (options.copy) :
                    print "Imag: copy"
                    imag = src
                else :
                    print "Imag: null"
                    imag = gr.null_source(gr.sizeof_short)
                interleaver = gr.interleave(gr.sizeof_short)
                self.fg.connect(src, (interleaver, 0))
                self.fg.connect(imag, (interleaver, 1))
                tail = interleaver
            elif (options.encoding == "f") :
                print "Source encoding: float"
                src = gr.file_source(gr.sizeof_gr_complex,
                    options.filename[0], 1)
                tail = src
        elif (options.mode == 2) :
            print "Source: complex"
            if len(options.frequency) == 1 :
                if (options.encoding == "s") :
                    print "Source encoding: short"
                    src = gr.file_source(gr.sizeof_short,
                            options.filename[0], 1)
                elif (options.encoding == "f") :
                    print "Source encoding: float"
                    src = gr.file_source(gr.sizeof_gr_complex,
                            options.filename[0], 1)
                else :
                    parser.error("Invalid encoding type for complex data!")
                tail = src
                    
            elif (len(options.frequency) == 2) :
                src0 = gr.file_source(gr.sizeof_gr_complex,
                        options.filename[0], 1)
                src1 = gr.file_source(gr.sizeof_gr_complex,
                        options.filename[1], 1)
                interleaver = gr.interleave(gr.sizeof_gr_complex)
                self.fg.connect(src0, (interleaver, 0))
                self.fg.connect(src1, (interleaver, 1))
                tail = interleaver
            else :
                parser.error(
                        "Invalid number of source (> 2) with complex input!")
        else :
            parser.error("Invalid mode!")

# Interpolation
        dac_freq = options.clockrate
        interp = int(dac_freq / options.samplingrate)
        if interp == 0 :
            parser.error("Invalid sampling rate!")
        if options.mode == 2 :
            print "Input sampling rate: %s complex samples/s" % \
                num_to_str(options.samplingrate)
        else :
            print "Input sampling rate: %s samples/s" % \
                num_to_str(options.samplingrate)
        print "Interpolation rate: int(%s / %s) = %sx" % \
            (num_to_str(dac_freq), num_to_str(options.samplingrate), interp)
        if interp > 512 :
            factor = gcd(dac_freq / 512, options.samplingrate)
            num = int((dac_freq / 512) / factor)
            den = int(options.samplingrate / factor)
            print "Resampling by %i / %i" % (num, den)
            resampler = blks.rational_resampler_ccc(self.fg, num, den)
            self.fg.connect(tail, resampler)
            tail = resampler
            interp = 512
            options.samplingrate = dac_freq / 512

# AGC
        if options.agc :
            agc = gr.agc_cc()
            self.fg.connect(tail, agc)
            tail = agc
            
# USRP
        if options.usrp :
            nchan = len(options.frequency)
            if len(options.frequency) == 1 :
                if options.mode == 1 :
                    mux = 0x00000098
                elif options.mode == 2 :
                    mux = 0x00000098
                else :
                    parser.error("Unsupported mode for USRP mux!")
            elif len(options.frequency) == 2 :
                if options.mode == 1 :
                    mux = 0x0000ba98
                elif options.mode == 2 :
                    mux = 0x0000ba98
                else :
                    parser.error("Unsupported mode for USRP mux!")
            else :
                parser.error("Invalid number of frequency [0..2]!")
#            if options.tx == "A" :
#                mux = 0x00000098
#            else :
#                mux = 0x00009800
            print "Nb channels: ", nchan
            print "Mux: 0x%x" % mux
            if options.encoding == 's' :
                dst = usrp.sink_s(0, interp, nchan, mux)
            elif options.encoding == 'f' :
                dst = usrp.sink_c(0, interp, nchan, mux)
            else :
                parser.error("Unsupported data encoding for USRP!")
            
            dst.set_verbose(1)

            for i in range(len(options.frequency)) :
                if options.gain is None :
                    print "Setting gain to %f" % dst.pga_max()
                    dst.set_pga(i << 1, dst.pga_max())
                else :
                    print "Setting gain to %f" % options.gain
                    dst.set_pga(i << 1, options.gain)

                tune = false
                for dboard in dst.db:
                    if (dboard[0].dbid() != -1):
                        device = dboard[0]
                        print "Tuning TX d'board %s to %sHz" % \
                                (device.side_and_name(),
                                num_to_str(options.frequency[i]))
                        device.lo_offset = 38e6
                        (min, max, offset) = device.freq_range()
                        print " Frequency"
                        print "  Min:    %sHz" % num_to_str(min)
                        print "  Max:    %sHz" % num_to_str(max)
                        print "  Offset: %sHz" % num_to_str(offset)
#device.set_gain(device.gain_range()[1])
                        device.set_enable(True)
                        tune = \
                            dst.tune(device._which, device,
                                    options.frequency[i] * 128e6 / dac_freq)
                        if tune:
                            print "  Baseband frequency: %sHz" % \
                                num_to_str(tune.baseband_freq)
                            print "  DXC frequency: %sHz" % \
                                num_to_str(tune.dxc_freq)
                            print "  Residual Freqency: %sHz" % \
                                num_to_str(tune.residual_freq)
                            print "  Inverted: ", \
                                tune.inverted
                            mux = usrp.determine_tx_mux_value(dst,
                                    (device._which, 0))
                            dst.set_mux(mux)
                            break
                        else:
                            print "  Failed!"
                if not tune:
                    print "  Failed!"
                    raise SystemExit

# int nunderruns ()

            print "USRP"
            print " Rx halfband: ", dst.has_rx_halfband()
            print " Tx halfband: ", dst.has_tx_halfband()
            print " Nb DDC: ", dst.nddc()
            print " Nb DUC: ", dst.nduc()
#dst._write_9862(0, 14, 224)
            
            print " DAC frequency: %s samples/s" % num_to_str(dst.dac_freq())
            print " Fpga decimation rate: %s -> %s samples/s" % \
                (num_to_str(dst.interp_rate()),
                 num_to_str(dac_freq / dst.interp_rate()))
            print " Nb channels:",
            if hasattr(dst, "nchannels()") :
                print dst.nchannels()
            else:
                print "N/A"
            print " Mux:",
            if hasattr(dst, "mux()") :
                print "0x%x" % dst.mux()
            else :
                print "N/A"
            print " FPGA master clock frequency:",
            if hasattr(dst, "fpga_master_clock_freq()") :
                print "%sHz" % num_to_str(dst.fpga_master_clock_freq())
            else :
                print "N/A"
            print " Converter rate:",
            if hasattr(dst, "converter_rate()") :
                print "%s" % num_to_str(dst.converter_rate())
            else :
                print "N/A"
            print " DAC rate:",
            if hasattr(dst, "dac_rate()") :
                print "%s sample/s" % num_to_str(dst.dac_rate())
            else :
                print "N/A"
            print " Interp rate: %sx" % num_to_str(dst.interp_rate())
            print " DUC frequency 0: %sHz" % num_to_str(dst.tx_freq(0))
            print " DUC frequency 1: %sHz" % num_to_str(dst.tx_freq(1))
            print " Programmable Gain Amplifier 0: %s dB" % \
                num_to_str(dst.pga(0))
            print " Programmable Gain Amplifier 1: %s dB" % \
                num_to_str(dst.pga(2))

        else :
            dst = gr.null_sink(gr.sizeof_gr_complex)
            
# AGC
        if options.agc :
            agc = gr.agc_cc()
            self.fg.connect(tail, agc)
            tail = agc
            
        self.fg.connect(tail, dst)

# oscilloscope
        if options.osc :
            oscPanel = wxPanel(self, -1)
            if (options.encoding == "s") :
                converter = gr.interleaved_short_to_complex()
                self.fg.connect(tail, converter)
                signal = converter
            elif (options.encoding == "f") :
                signal = tail
            else :
                parser.error("Unsupported data encoding for oscilloscope!")

#block = scope_sink_f(fg, parent, title=label, sample_rate=input_rate)
#return (block, block.win)

            oscWin = scopesink.scope_sink_c(self.fg, oscPanel, "Signal",
                    options.samplingrate)
            self.fg.connect(signal, oscWin)
            mainSizer.Add(oscPanel, 1, wxEXPAND)

# spectrometer
        if options.spectrum :
            ymin = 0
            ymax = 160
            fftPanel = wxPanel(self, -1)
            if (options.encoding == "s") :
                converter = gr.interleaved_short_to_complex()
                self.fg.connect(tail, converter)
                signal = converter
            elif (options.encoding == "f") :
                signal = tail
            else :
                parser.error("Unsupported data encoding for oscilloscope!")

            fftWin = fftsink.fft_sink_c(self.fg, fftPanel,
                    title="Spectrum",
                    fft_size=2048,
                    sample_rate=options.samplingrate,
                    y_per_div=(ymax - ymin) / 8,
                    ref_level=ymax,
                    fft_rate=50,
                    average=True
                    )
            self.fg.connect(signal, fftWin)
            mainSizer.Add(fftPanel, 1, wxEXPAND)

# Events
        EVT_MENU(self, ID_ABOUT, self.OnAbout)
        EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
        EVT_SLIDER(self, ID_GAIN_SLIDER0, self.slideEvent)
        EVT_SLIDER(self, ID_FREQ_SLIDER0, self.slideEvent)
        EVT_SLIDER(self, ID_GAIN_SLIDER1, self.slideEvent)
        EVT_SLIDER(self, ID_FREQ_SLIDER1, self.slideEvent)
        EVT_BUTTON(self, ID_START, self.onClick)
        EVT_BUTTON(self, ID_STOP, self.onClick)

#Layout sizers
        self.SetSizer(mainSizer)
        self.SetAutoLayout(1)
        mainSizer.Fit(self)

        self.fg.start()
Exemplo n.º 14
0
                                             udp_interface, udp_port,
                                             self._packet_size, True, True,
                                             True)
            #print "--> UDP Source listening on port:", udp_port, "interface:", udp_interface, "MTU:", self._packet_size
            if self._format == "fc32":
                try:
                    self.vec2stream = blocks.vector_to_stream(
                        gr.sizeof_short * 1, 2)
                except:
                    self.vec2stream = gr.vector_to_stream(
                        gr.sizeof_short * 1, 2)
                try:
                    self.ishort2complex = blocks.interleaved_short_to_complex(
                    )  # FIXME: Use vector mode and skip 'vector_to_stream'
                except:
                    self.ishort2complex = gr.interleaved_short_to_complex()
                mul_factor = 1. / 2**15
                try:
                    self.multiply_const = blocks.multiply_const_cc(mul_factor)
                except:
                    self.multiply_const = gr.multiply_const_cc(mul_factor)

                self.connect(self.udp_source, self.vec2stream,
                             self.ishort2complex, self.multiply_const, self)
            elif self._format == "sc16":
                self.connect(self.udp_source, self)
        else:
            assert self.vec2stream is not None and self.ishort2complex is not None

        if self._listen_only == False:
            if self._last_antenna is not None:
Exemplo n.º 15
0
    def __init__(self,
                 fg,
                 master_serialno,
                 decim,
                 nchan=2,
                 pga_gain=0.0,
                 cordic_freq=0.0,
                 mux=None,
                 align_interval=-1,
                 fpga_filename="multi_2rxhb_2tx.rbf"):
        """
        Align multiple sources (usrps) using samplenumbers in the first channel.

        Takes two ore more sources producing interleaved shorts.
				produces nchan * nsources gr_complex output streams.

        @param nchan: number of interleaved channels in source
        @param align_interval: number of samples to minimally skip between alignments
				                       default = -1 which means align only once per work call.
        @param master_serial_no: serial number of the source which must be the master.


        Exported sub-blocks (attributes):
          master_source
          slave_source
          usrp_master
          usrp_slave
        """
        mode = usrp.FPGA_MODE_NORMAL
        mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT  #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT
        align = gr.align_on_samplenumbers_ss(nchan, align_interval)
        self.usrp_master = None
        self.usrp_slave = None
        # um is master usrp
        # us is slave usrp
        if mux is None:
            mux = self.get_default_mux(
            )  #Note that all channels have shifted left because of the added 32 bit counter channel

        u1 = usrp.source_s(1,
                           decim,
                           nchan,
                           gru.hexint(mux),
                           mode,
                           fpga_filename=fpga_filename)
        u0 = usrp.source_s(0,
                           decim,
                           nchan,
                           gru.hexint(mux),
                           mode,
                           fpga_filename=fpga_filename)
        print 'usrp[0] serial', u0.serial_number()
        print 'usrp[1] serial', u1.serial_number()
        #default, choose the second found usrp as master (which is usually the usrp which was first plugged in)
        um_index = 1
        um = u1
        us_index = 0
        us = u0
        if (not (master_serialno is
                 None)):  #((master_serialno>0) | (master_serialno <-2)):
            if (u0.serial_number() == master_serialno):
                um_index = 0
                um = u0
                us_index = 1
                us = u1
            elif (u1.serial_number() != master_serialno):
                errorstring = 'Error. requested master_serialno ' + master_serialno + ' not found\n'
                errorstring = errorstring + 'Available are:\n'
                errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number(
                ) + '\n'
                errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number(
                ) + '\n'
                print errorstring
                raise ValueError, errorstring
            else:  #default, just choose the first found usrp as master
                um_index = 1
                um = u1
                us_index = 0
                us = u0

        self.usrp_master = um
        self.usrp_slave = us
        print 'usrp_master=usrp[%i] serial_no = %s' % (
            um_index,
            self.usrp_master.serial_number(),
        )
        print 'usrp_slave=usrp[%i] serial_no = %s' % (
            us_index,
            self.usrp_slave.serial_number(),
        )
        self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0, 0))
        self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1, 0))
        self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0, 0))
        self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1, 0))
        #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate)
        if not (pga_gain is None):
            um.set_pga(0, pga_gain)
            um.set_pga(1, pga_gain)

            us.set_pga(0, pga_gain)
            us.set_pga(1, pga_gain)

        self.input_rate = um.adc_freq() / um.decim_rate()
        deintm = gr.deinterleave(gr.sizeof_gr_complex)
        deints = gr.deinterleave(gr.sizeof_gr_complex)
        nullsinkm = gr.null_sink(gr.sizeof_gr_complex)
        nullsinks = gr.null_sink(gr.sizeof_gr_complex)

        tocomplexm = gr.interleaved_short_to_complex()
        tocomplexs = gr.interleaved_short_to_complex()

        fg.connect(um, (align, 0))
        fg.connect(us, (align, 1))
        fg.connect((align, 0), tocomplexm)
        fg.connect((align, 1), tocomplexs)
        fg.connect(tocomplexm, deintm)
        fg.connect(tocomplexs, deints)
        fg.connect(
            (deintm, 0), nullsinkm
        )  #The counters are not usefull for the user but must be connected to something
        fg.connect(
            (deints, 0), nullsinks
        )  #The counters are not usefull for the user but must be connected to something
        if 4 == nchan:
            nullsinkm3 = gr.null_sink(gr.sizeof_gr_complex)
            nullsinks3 = gr.null_sink(gr.sizeof_gr_complex)
            fg.connect(
                (deintm, 3),
                nullsinkm3)  #channel 4 is not used but must be connected
            fg.connect(
                (deints, 3),
                nullsinks3)  #channel 4 is not used but must be connected

        self.fg = fg
        self.master_source = deintm
        self.slave_source = deints

        if not (cordic_freq is None):
            um.set_rx_freq(1, cordic_freq)
            um.set_rx_freq(0, cordic_freq)
            us.set_rx_freq(1, cordic_freq)
            us.set_rx_freq(0, cordic_freq)

        self.enable_master_and_slave()
        # add an idle handler
        self.unsynced = True
Exemplo n.º 16
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-w",
            "--which",
            type="int",
            default=0,
            help="select which USRP (0, 1, ...) default is %default",
            metavar="NUM")
        #        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
        #                          help="select USRP Rx side A or B (default=first one with a daughterboard)")
        parser.add_option("-A",
                          "--antenna",
                          default=None,
                          help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=32,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=0.0,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-W",
                          "--waterfall",
                          action="store_true",
                          default=False,
                          help="Enable waterfall display")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        #        parser.add_option( "--no-hb", action="store_true", default=False,
        #                          help="don't use halfband filter in usrp")
        parser.add_option("-S",
                          "--oscilloscope",
                          action="store_true",
                          default=False,
                          help="Enable oscilloscope display (default)")
        parser.add_option("-F",
                          "--fft",
                          action="store_true",
                          default=False,
                          help="Enable FFT display")
        parser.add_option(
            "-n",
            "--frame-decim",
            type="int",
            default=1,
            help="set oscope frame decimation factor to n [default=1]")
        parser.add_option(
            "-v",
            "--v-scale",
            type="eng_float",
            default=1,
            help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option(
            "-t",
            "--t-scale",
            type="eng_float",
            default=10e-6,
            help="set oscope initial s/div to SCALE [default=10us]")
        parser.add_option(
            "--digital",
            action="store_true",
            default=False,
            help=
            "show (only) the digital wave on lsb (will be input from gpio pins with special usrp firmware)"
        )
        parser.add_option(
            "--analog",
            action="store_true",
            default=False,
            help=
            "show (only) the analog wave on msbs (will be input from analog inputs)"
        )
        parser.add_option(
            "--file",
            default=None,
            help=
            "input from file FILE in stead of USRP (will be input from raw file in interleaved short format)"
        )
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        self.options = options
        self.show_debug_info = True

        self.u = usrp.source_s(which=options.which,
                               decim_rate=options.decim,
                               fpga_filename=gpio.fpga_filename)

        print "Warning: This script only supports boards on RXA, change the script if you want otherwise"
        #options.rx_subdev_spec=(0, 0)#force the use of RXA
        options.rx_subdev_spec = None  #force the use of RXA

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)

        #This hardcoded mux setting is why this script only supports RXA
        #We want both I and Q active, even when using basicRX
        #set to 0x10 for RXA
        #set to 0x32 for RXB
        self.u.set_mux(
            0x10
        )  #usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        if options.width_8:
            width = 8
            shift = 8
            format = self.u.make_format(width, shift)
            print "format =", hex(format)
            r = self.u.set_format(format)
            print "set_format =", r

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        #if options.rx_subdev_spec==(0,0):
        #  rx_subdev_spec2=(0,1)
        #  self.subdev2 = usrp.selected_subdev(self.u, rx_subdev_spec2)
        input_rate = self.u.adc_freq() / self.u.decim_rate()

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.fft:
            self.scope = fftsink2.fft_sink_c(panel,
                                             fft_size=1024,
                                             sample_rate=input_rate)
        else:  # options.oscilloscope:
            #self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
            self.scope = scopesink2.scope_sink_c(
                panel,
                sample_rate=input_rate,
                frame_decim=options.frame_decim,
                v_scale=options.v_scale,
                t_scale=options.t_scale)

        self.is2c = gr.interleaved_short_to_complex()
        if not (options.file is None):
            self.filesrc = gr.file_source(gr.sizeof_short, options.file, True)
            thr = gr.throttle(gr.sizeof_short, input_rate)
            self.connect(self.filesrc, thr, self.is2c, self.scope)
        elif options.digital:
            self.select_dig = gr.and_const_ss(0x0001)
            self.connect(self.u, self.select_dig, self.is2c, self.scope)
        elif options.analog:
            self.select_ana = gr.and_const_ss(0xFFFE)
            self.connect(self.u, self.select_ana, self.is2c, self.scope)
        else:
            self.connect(self.u, self.is2c, self.scope)

        self._build_gui(vbox)
        self._setup_events()

        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        if options.freq is None:
            # if no freq was specified, use the mid-point
            r = self.subdev.freq_range()
            options.freq = float(r[0] + r[1]) / 2

        self.set_gain(options.gain)

        if options.antenna is not None:
            print "Selecting antenna %s" % (options.antenna, )
            self.subdev.select_rx_antenna(options.antenna)

        if self.show_debug_info:
            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['fs@usb'].set_value(self.u.adc_freq() /
                                            self.u.decim_rate())
            self.myform['dbname'].set_value(self.subdev.name())
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)

        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
    def __init__(
            self,
            deframer_insync_frames=2,
            viterbi_insync_frames=5,
            deframer_outsync_frames=5,
            viterbi_outsync_frames=20,
            viterbi_sync_check=True,
            viterbi_sync_threshold=0.1,
            deframer_sync_check=True,
            pll_alpha=0.005,
            freq=1691.02e6,
            gain=23,
            side="A",
            decim=25,
            symb_rate=(3500e3 / 3 + 3500e3) / 2,
            frames_file=os.environ['HOME'] + '/MetOp-AHRPT_cadu_frames.cadu',
            clock_alpha=0.05,
            baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam',
            satellite='MetOp'):
        grc_wxgui.top_block_gui.__init__(
            self, title="MetOp AHRPT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.pll_alpha = pll_alpha
        self.freq = freq
        self.gain = gain
        self.side = side
        self.decim = decim
        self.symb_rate = symb_rate
        self.frames_file = frames_file
        self.clock_alpha = clock_alpha
        self.baseband_file = baseband_file
        self.satellite = satellite

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.cs2cf = gr.interleaved_short_to_complex()
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 4)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               baseband_file, True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="QPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_null_sink_0, 0))
	def __init__(self, satellite='NOAAxx', decim=50, baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam", frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf', deframer_outsync_frames=5, deframer_insync_frames=2, clock_alpha=0.005, gain_mu=0.005, pll_alpha=0.005, pll_beta=0.00001, deframer_sync_check=True, symb_rate=600*1109):
		grc_wxgui.top_block_gui.__init__(self, title="NOAA HRPT Receiver from baseband file")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.satellite = satellite
		self.decim = decim
		self.baseband_file = baseband_file
		self.frames_file = frames_file
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_insync_frames = deframer_insync_frames
		self.clock_alpha = clock_alpha
		self.gain_mu = gain_mu
		self.pll_alpha = pll_alpha
		self.pll_beta = pll_beta
		self.deframer_sync_check = deframer_sync_check
		self.symb_rate = symb_rate

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_beta_sl = pll_beta_sl = pll_beta
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.max_clock_offset = max_clock_offset = 0.1
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate
		self.hs = hs = int(sps/2.0)
		self.gain_mu_sl = gain_mu_sl = gain_mu
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_beta_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_beta_sl_sizer,
			value=self.pll_beta_sl,
			callback=self.set_pll_beta_sl,
			label="PLL Beta",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_beta_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_beta_sl_sizer,
			value=self.pll_beta_sl,
			callback=self.set_pll_beta_sl,
			minimum=0.000001,
			maximum=0.001,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		_gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._gain_mu_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_gain_mu_sl_sizer,
			value=self.gain_mu_sl,
			callback=self.set_gain_mu_sl,
			label="Gain MU",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._gain_mu_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_gain_mu_sl_sizer,
			value=self.gain_mu_sl,
			callback=self.set_gain_mu_sl,
			minimum=0.0001,
			maximum=0.01,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.cs2cf = gr.interleaved_short_to_complex()
		self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps/2.0, clock_alpha**2/4.0, 0.5, gain_mu_sl, max_clock_offset)
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl, 0.07, -0.07, 2)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0/hs, 4000)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*2)
		self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False)
		self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=50,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="PSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
		self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_1, 0))
Exemplo n.º 19
0
	def __init__(self, deframer_insync_frames=2, deframer_outsync_frames=5, deframer_sync_check=True, pll_alpha=0.005, baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam', satellite='MetOp', viterbi_sync_threshold=0.1, viterbi_outsync_frames=20, viterbi_insync_frames=5, frames_file=os.environ['HOME'] + '/MetOp-cadu_frames.cadu', clock_alpha=0.05, symb_rate=(3500e3/3+3500e3)/2, symb_rate_0=3*3500/4, viterbi_sync_check=True, decim=24):
		grc_wxgui.top_block_gui.__init__(self, title="MetOp AHRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_sync_check = deframer_sync_check
		self.pll_alpha = pll_alpha
		self.baseband_file = baseband_file
		self.satellite = satellite
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_insync_frames = viterbi_insync_frames
		self.frames_file = frames_file
		self.clock_alpha = clock_alpha
		self.symb_rate = symb_rate
		self.symb_rate_0 = symb_rate_0
		self.viterbi_sync_check = viterbi_sync_check
		self.decim = decim

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Blocks
		##################################################
		self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			title="QPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_scopesink2_1.win)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=-15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(False, 1024, 5, 25)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*10)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.6, ))
		self.gr_file_source_0_0_0_0 = gr.file_source(gr.sizeof_short*1, "/home/martin/hrpt/baseband/METOP-A/2011/07/24/METOP-A_2011-07-24_122614-U2d24.sam", False)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/home/martin/MetOp-cadu_frames.cadu")
		self.gr_file_sink_0.set_unbuffered(False)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 4)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self.fec_decode_viterbi_ahrpt_metop_cb_0 = fec.decode_viterbi_ahrpt_metop_cb(True, 0.2, 5, 50, 50)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		self.cs2cf = gr.interleaved_short_to_complex()
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).Add(self._baseband_file_text_inf_static_text)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_file_source_0_0_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.fec_decode_viterbi_ahrpt_metop_cb_0, 0))
		self.connect((self.fec_decode_viterbi_ahrpt_metop_cb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
Exemplo n.º 20
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-e",
                          "--interface",
                          type="string",
                          default="eth0",
                          help="select Ethernet interface, default is eth0")
        parser.add_option(
            "-m",
            "--mac-addr",
            type="string",
            default="",
            help="select USRP by MAC address, default is auto-select")
        parser.add_option("-W",
                          "--bw",
                          type="float",
                          default=1e6,
                          help="set bandwidth of receiver [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default="2.4G",
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("--fft-size",
                          type="int",
                          default=2048,
                          help="Set number of FFT bins [default=%default]")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        self.options = options
        self.show_debug_info = True

        self.qapp = QtGui.QApplication(sys.argv)

        #        self.u = usrp2.source_32fc(options.interface, options.mac_addr)
        self.u = msdd_rs.source_simple("192.168.1.20", 10000)
        self.conv = gr.interleaved_short_to_complex()
        self._adc_rate = self.u.pull_adc_freq()
        self.set_bandwidth(options.bw)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            #            g = self.u.gain_range()
            g = [0, 10]
            #options.gain = float(g[0]+g[1])/2
            options.gain = float(0)
        self.set_gain(options.gain)

        if options.freq is None:
            options.freq = 2.4e9
#            # if no frequency was specified, use the mid-point of the subdev
#            f = self.u.freq_range()
#            options.freq = float(f[0]+f[1])/2

        self.set_frequency(options.freq)

        self._fftsize = options.fft_size

        self._freq = options.freq
        self._bandwidth = 400

        self.set_bandwidth(self._bandwidth)

        self.snk = qtgui.sink_c(options.fft_size,
                                gr.firdes.WIN_BLACKMAN_hARRIS, self._freq,
                                self._bandwidth, "USRP2 Display", True, True,
                                False, True, False)

        # Set up internal amplifier
        self.amp = gr.multiply_const_cc(0.0)
        self.set_amplifier_gain(0.01)

        # Create a single-pole IIR filter to remove DC
        #   but don't connect it yet
        self.dc_gain = 0.001
        self.dc = gr.single_pole_iir_filter_cc(self.dc_gain)
        self.dc_sub = gr.sub_cc()

        self.agc = gr.agc2_cc(1e-3, 1e-5, 0.01, 0.01, 10)

        self.connect(self.u, self.conv, self.snk)
        #self.connect(self.u, self.conv, self.amp, self.snk)

        if self.show_debug_info:
            print "Decimation rate: ", self._decim
            print "Bandwidth: ", self._bandwidth


#            print "D'board: ", self.u.daughterboard_id()

# Get the reference pointer to the SpectrumDisplayForm QWidget
# Wrap the pointer as a PyQt SIP object
#     This can now be manipulated as a PyQt4.QtGui.QWidget
        self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget)

        self.main_win = main_window(self.pysink, self)

        self.main_win.set_frequency(self._freq)
        self.main_win.set_gain(self._gain)
        self.main_win.set_bandwidth(self._bandwidth)
        self.main_win.set_amplifier(self._amp_value)

        self.main_win.show()
Exemplo n.º 21
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=16,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-W",
                          "--waterfall",
                          action="store_true",
                          default=False,
                          help="Enable waterfall display")
        parser.add_option("-S",
                          "--oscilloscope",
                          action="store_true",
                          default=False,
                          help="Enable oscilloscope display")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        self.options = options
        self.options.gain = 1.0
        self.show_debug_info = True

        input_rate = 100e6 / options.decim

        self.src = gr.file_descriptor_source(gr.sizeof_short, 0, False)
        self.s2c = gr.interleaved_short_to_complex()

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.oscilloscope:
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
        else:
            self.scope = fftsink2.fft_sink_c(panel,
                                             fft_size=1024,
                                             y_divs=12,
                                             sample_rate=input_rate,
                                             ref_level=110,
                                             fft_rate=20)

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

        self._build_gui(vbox)
        self._setup_events()

        # set initial values

        if options.freq is None:
            # if no freq was specified, use the mid-point
            options.freq = 0.0

        if self.show_debug_info:
            self.myform['decim'].set_value(self.options.decim)
Exemplo n.º 22
0
    def __init__(self):
        gr.top_block.__init__(self)

        # Build an options parser to bring in information from the user on usage
        usage = "usage: %prog [options] host min_freq max_freq"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=32,
                          help="set gain in dB (default is midpoint)")
        parser.add_option(
            "",
            "--tune-delay",
            type="eng_float",
            default=5e-5,
            metavar="SECS",
            help=
            "time to delay (in seconds) after changing frequency [default=%default]"
        )
        parser.add_option(
            "",
            "--dwell-delay",
            type="eng_float",
            default=50e-5,
            metavar="SECS",
            help=
            "time to dwell (in seconds) at a given frequncy [default=%default]"
        )
        parser.add_option("-F",
                          "--fft-size",
                          type="int",
                          default=256,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("-d",
                          "--decim",
                          type="intx",
                          default=16,
                          help="set decimation to DECIM [default=%default]")
        parser.add_option("",
                          "--real-time",
                          action="store_true",
                          default=False,
                          help="Attempt to enable real-time scheduling")

        (options, args) = parser.parse_args()
        if len(args) != 3:
            parser.print_help()
            sys.exit(1)

        # get user-provided info on address of MSDD and frequency to sweep
        self.address = args[0]
        self.min_freq = eng_notation.str_to_num(args[1])
        self.max_freq = eng_notation.str_to_num(args[2])

        self.decim = options.decim
        self.gain = options.gain

        if self.min_freq > self.max_freq:
            self.min_freq, self.max_freq = self.max_freq, self.min_freq  # swap them

        self.fft_size = options.fft_size

        if not options.real_time:
            realtime = False
        else:
            # Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        # Sampling rate is hardcoded and cannot be read off device
        adc_rate = 102.4e6
        self.int_rate = adc_rate / self.decim
        print "Sampling rate: ", self.int_rate

        # build graph
        self.port = 10001  # required port for UDP packets

        #	which board,	op mode,	adx,	port
        #        self.src = msdd.source_c(0, 1, self.address, self.port)  # build source object

        self.conv = gr.interleaved_short_to_complex()

        self.src = msdd.source_simple(self.address, self.port)
        self.src.set_decim_rate(self.decim)  # set decimation rate
        #        self.src.set_desired_packet_size(0, 1460)                # set packet size to collect

        self.set_gain(self.gain)  # set receiver's attenuation
        self.set_freq(self.min_freq)  # set receiver's rx frequency

        # restructure into vector format for FFT input
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        # set up FFT processing block
        mywindow = window.blackmanharris(self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, mywindow, True)
        power = 0
        for tap in mywindow:
            power += tap * tap

        # calculate magnitude squared of output of FFT
        c2mag = gr.complex_to_mag_squared(self.fft_size)

        # FIXME the log10 primitive is dog slow
        log = gr.nlog10_ff(
            10, self.fft_size, -20 * math.log10(self.fft_size) -
            10 * math.log10(power / self.fft_size))

        # Set the freq_step to % of the actual data throughput.
        # This allows us to discard the bins on both ends of the spectrum.
        self.percent = 0.4

        # Calculate the frequency steps to use in the collection over the whole bandwidth
        self.freq_step = self.percent * self.int_rate
        self.min_center_freq = self.min_freq + self.freq_step / 2
        nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step)
        self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step)

        self.next_freq = self.min_center_freq

        # use these values to set receiver settling time between samples and sampling time
        # the default values provided seem to work well with the MSDD over 100 Mbps ethernet
        tune_delay = max(0,
                         int(
                             round(options.tune_delay * self.int_rate /
                                   self.fft_size)))  # in fft_frames
        dwell_delay = max(1,
                          int(
                              round(options.dwell_delay * self.int_rate /
                                    self.fft_size)))  # in fft_frames

        # set up message callback routine to get data from bin_statistics_f block
        self.msgq = gr.msg_queue(16)
        self._tune_callback = tune(
            self)  # hang on to this to keep it from being GC'd

        # FIXME this block doesn't like to work with negatives because of the "d_max[i]=0" on line
        # 151 of gr_bin_statistics_f.cc file. Set this to -10000 or something to get it to work.
        stats = gr.bin_statistics_f(self.fft_size, self.msgq,
                                    self._tune_callback, tune_delay,
                                    dwell_delay)

        # FIXME there's a concern over the speed of the log calculation
        # We can probably calculate the log inside the stats block
        self.connect(self.src, self.conv, s2v, fft, c2mag, log, stats)
Exemplo n.º 23
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename. \n Special output_filename \"sdl\" will use video_sink_sdl as realtime output window. " \
              "You then need to have gr-video-sdl installed. \n" \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-d", "--decim", type="int", default=8,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be interleaved shorts \n " +
                               "Use usrp_rx_file.py or usrp_rx_cfile.py --output-shorts. \n"
                               "Special name \"usrp\"  results in realtime capturing and processing using usrp. \n" +
                               "You then probably need a decimation factor of 64 or higher.")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-N", "--nframes", type="eng_float", default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option( "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")
        (options, args) = parser.parse_args ()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n');
            sys.exit(1)
        
        filename = args[0]

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n');
            raise SystemExit, 1

        if not (filename=="sdl"):
          options.repeat=False

        if not (options.in_filename=="usrp"):
          self.filesource = gr.file_source(gr.sizeof_short,options.in_filename,options.repeat) # file is data source, capture with usr_rx_csfile.py
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.adc_rate=64e6
          self.src=self.istoc
        else:
          if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1
          if abs(options.freq) < 1e6:
              options.freq *= 1e6
          if options.no_hb or (options.decim<8):
            self.fpga_filename="std_4rx_0tx.rbf" #contains 4 Rx paths without halfbands and 0 tx paths
          else:
            self.fpga_filename="std_2rxhb_2tx.rbf" # contains 2 Rx paths with halfband filters and 2 tx paths (the default)

          # build the graph
          self.u = usrp.source_c(decim_rate=options.decim,fpga_filename=self.fpga_filename)
          self.src=self.u
          if options.width_8:
              sample_width = 8
              sample_shift = 8
              format = self.u.make_format(sample_width, sample_shift)
              r = self.u.set_format(format)
          self.adc_rate=self.u.adc_freq()
          if options.rx_subdev_spec is None:
              options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
          self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
          # determine the daughterboard subdevice we're using
          self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
          print "Using RX d'board %s" % (self.subdev.side_and_name(),)

          if options.gain is None:
              # if no gain was specified, use the mid-point in dB
              g = self.subdev.gain_range()
              options.gain = float(g[0]+g[1])/2
          self.subdev.set_gain(options.gain)

          r = self.u.tune(0, self.subdev, options.freq)
          if not r:
              sys.stderr.write('Failed to set frequency\n')
              raise SystemExit, 1

        input_rate = self.adc_rate / options.decim
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(options.brightness +255.0)
        self.invert_and_scale = gr.multiply_const_ff (-options.contrast *128.0*255.0/(200.0))
        self.f2uc=gr.float_to_uchar()

          # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL
        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768
        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640
        width=int(input_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if filename=="sdl":
          #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height,0,show_width,height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename
          print "(Use the spacebar to advance to next frames)" 
          file_sink=gr.file_sink(gr.sizeof_char, filename)
          self.dst =file_sink 

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
            self.connect(self.src, self.head, self.agc)

        self.connect (self.agc,self.am_demod,self.invert_and_scale, self.set_blacklevel,self.f2uc,self.dst)
Exemplo n.º 24
0
	def __init__(self, side="A", gain=35, decim=32, sync_check=False, satellite='METEOR-M-1', frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt', freq=1700e6):
		grc_wxgui.top_block_gui.__init__(self, title="USRP NOAA HRPT Receiver")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.side = side
		self.gain = gain
		self.decim = decim
		self.sync_check = sync_check
		self.satellite = satellite
		self.frames_file = frames_file
		self.freq = freq

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.samp_rate = samp_rate = 64e6/decim
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/mn1_hrpt.conf'
		self.sps = sps = samp_rate/sym_rate
		self._saved_pll_alpha_config = ConfigParser.ConfigParser()
		self._saved_pll_alpha_config.read(config_filename)
		try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.005
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_clock_alpha_config = ConfigParser.ConfigParser()
		self._saved_clock_alpha_config.read(config_filename)
		try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.001
		self.saved_clock_alpha = saved_clock_alpha
		self.sync_check_txt = sync_check_txt = sync_check
		self.side_text = side_text = side
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
		except: saved_gain = gain
		self.saved_gain = saved_gain
		self.satellite_text = satellite_text = satellite
		self.sample_rate_text = sample_rate_text = samp_rate
		self.pll_alpha = pll_alpha = saved_pll_alpha
		self.max_clock_offset = max_clock_offset = 0.1
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate
		self.hs = hs = int(sps/2.0)
		self.gain_slider = gain_slider = gain
		self.freq_tb = freq_tb = freq
		self.frames_outfile_text = frames_outfile_text = frames_file
		self.decim_tb = decim_tb = decim
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha = clock_alpha = saved_clock_alpha

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "RX Meteor M N1 HRPT")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
		self.Add(self.displays)

		##################################################
		# Controls
		##################################################
		self._sync_check_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.sync_check_txt,
			callback=self.set_sync_check_txt,
			label="Sync check",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._sync_check_txt_static_text, 0, 2, 1, 1)
		self._side_text_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.side_text,
			callback=self.set_side_text,
			label="USRP Side",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._side_text_static_text, 0, 0, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Satellite",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._satellite_text_static_text, 0, 1, 1, 1)
		self._sample_rate_text_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.sample_rate_text,
			callback=self.set_sample_rate_text,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._sample_rate_text_static_text, 3, 0, 1, 1)
		_pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_pll_alpha_sizer,
			value=self.pll_alpha,
			callback=self.set_pll_alpha,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_pll_alpha_sizer,
			value=self.pll_alpha,
			callback=self.set_pll_alpha,
			minimum=0.005,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_pll_alpha_sizer, 2, 1, 1, 1)
		_gain_slider_sizer = wx.BoxSizer(wx.VERTICAL)
		self._gain_slider_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_gain_slider_sizer,
			value=self.gain_slider,
			callback=self.set_gain_slider,
			label="Gain",
			converter=forms.int_converter(),
			proportion=0,
		)
		self._gain_slider_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_gain_slider_sizer,
			value=self.gain_slider,
			callback=self.set_gain_slider,
			minimum=0,
			maximum=100,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=int,
			proportion=1,
		)
		self.GridAdd(_gain_slider_sizer, 2, 0, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_outfile_text_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.frames_outfile_text,
			callback=self.set_frames_outfile_text,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._frames_outfile_text_static_text, 4, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.GridAdd(self._decim_tb_text_box, 1, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Acquisition start",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._datetime_text_static_text, 2, 0, 1, 1)
		_clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_clock_alpha_sizer,
			value=self.clock_alpha,
			callback=self.set_clock_alpha,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_clock_alpha_sizer,
			value=self.clock_alpha,
			callback=self.set_clock_alpha,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_clock_alpha_sizer, 2, 2, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_rms_xx_0 = gr.rms_cf(0.2)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(sync_check)
		self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source_x_0.set_decim_rate(decim)
		self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
		self.usrp_simple_source_x_0.set_gain(gain)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.displays.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=45,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Meteor M N1 HRPT FFT Spectrum",
			peak_hold=False,
		)
		self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win)
		self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
			self.GetWin(),
			unit="Units",
			minval=0,
			maxval=5000,
			factor=1.0,
			decimal_places=4,
			ref_level=0,
			sample_rate=samp_rate,
			number_rate=15,
			average=True,
			avg_alpha=0.07,
			label="S-Meter",
			peak_hold=False,
			show_gauge=True,
		)
		self.Add(self.wxgui_numbersink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_mn1_hrpt_deframer_0, 0))
		self.connect((self.usrp_simple_source_x_0, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.gr_rms_xx_0, 0))
		self.connect((self.gr_rms_xx_0, 0), (self.wxgui_numbersink2_0, 0))
		self.connect((self.poesweather_mn1_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
Exemplo n.º 25
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] samples_file"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-m", "--dab-mode", type="int", default=1,
            help="DAB mode [default=%default]")
        parser.add_option("-c", "--complex", action="store_true", default=False,
            help="Sample file is float complex (64 bit per sample, 32 I + 32 Q) format")
        parser.add_option("-i", "--subchid", type="int", default=-1,
            help="Subchannel ID")
        parser.add_option("-n", "--config", type="string", default="channel2.conf",
            help="DAB+ channel configuration file [default=%default]")
        parser.add_option("-p", "--mplayer", action="store_true", default=False,
            help="Play the program by MPlayer [default=%default, stdout]")
        (options, args) = parser.parse_args ()
        
        if len(args)<1:
            parser.print_help()
            raise SystemExit, 1
        else:
            filename = args[0]
            if options.complex:
                src = gr.file_source(gr.sizeof_gr_complex, filename, False)
            else:
                sinput = gr.file_source(gr.sizeof_short, filename, False)
                src = gr.interleaved_short_to_complex()
                self.connect(sinput, src)
        
        # channel configuration
        cc = dabp.channel_conf(options.config)
        sys.stderr.write("Playing Channel: "+cc.get_label(options.subchid)+"\n")
        
        start_addr = cc.get_start_addr(options.subchid)
        subchsz = cc.get_subchsz(options.subchid)
        optprot = cc.get_optprot(options.subchid)
        # print "start_addr=%d, subchsz=%d, optprot=%d" % (start_addr, subchsz, optprot)
        
        mode=options.dab_mode
        param = dabp.parameters(mode)
        
        # null symbol detector
        samples_per_null_sym=param.get_Nnull()
        #print "samples per null symbol : %d" % samples_per_null_sym
        nulldet = dabp.detect_null(samples_per_null_sym)
        # ofdm demod
        demod = dabp.ofdm_demod(mode)
        # FIC/MSC demultiplexer
        demux = dabp.fic_msc_demux(1, mode)
        
        cifsz = param.get_cifsz()
        scs = dabp.subchannel_selector(cifsz,start_addr,subchsz)
        intlv = dabp.time_deinterleaver(subchsz)
        punc = dabp.depuncturer(subchsz,optprot)
        I = punc.getI()
        vit = dabp.vitdec(I)
        scram = dabp.scrambler(I)
        len_logfrm=scram.get_nbytes()
        sync = dabp.super_frame_sync(len_logfrm)
        subchidx = sync.get_subchidx()
        rs = dabp.super_frame_rsdec(subchidx)
        if options.mplayer:
            mplayer = subprocess.Popen(['mplayer', '-ac', 'faad', '-rawaudio', 'format=0xff', '-demuxer', 'rawaudio','-'], stdin=subprocess.PIPE)
            dst = dabp.super_frame_sink(subchidx, mplayer.stdin.fileno())
        else:
            dst = dabp.super_frame_sink(subchidx, "-")
        
        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(src, nulldet)
        self.connect(src, (demod,0))
        self.connect(nulldet, (demod,1))
        self.connect((demod,0), demux, scs)
        self.connect((scs,0), (intlv,0), (punc,0), (vit,0), (scram,0), (sync,0), (rs,0), (dst,0))
        self.connect((demod,1), nullsink)
        self.connect((scs,1), (intlv,1), (punc,1), (vit,1), (scram,1), (sync,1), (rs,1), (dst,1))
        
        # debug
        #self.connect(nulldet, gr.file_sink(gr.sizeof_char, "debug_nulldet.dat"))
        #self.connect((scs,0), gr.file_sink(gr.sizeof_float, "debug_scs.dat"))
        #self.connect((intlv,0), gr.file_sink(gr.sizeof_float, "debug_int.dat"))
        #self.connect((punc,0), gr.file_sink(gr.sizeof_float, "debug_punc.dat"))
        #self.connect((vit,0), gr.file_sink(gr.sizeof_char, "debug_vit.dat"))
        #self.connect((scram,0), gr.file_sink(gr.sizeof_char, "debug_scr.dat"))
        self.connect((sync,0), gr.file_sink(gr.sizeof_char, "debug_sync.dat"))
Exemplo n.º 26
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-e", "--interface", type="string", default="eth0",
                          help="select Ethernet interface, default is eth0")
        parser.add_option("-m", "--mac-addr", type="string", default="",
                          help="select USRP by MAC address, default is auto-select")
        parser.add_option("-W", "--bw", type="float", default=1e6,
                          help="set bandwidth of receiver [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default="2.4G",
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("--fft-size", type="int", default=2048,
                          help="Set number of FFT bins [default=%default]")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
	self.options = options
        self.show_debug_info = True
        
        self.qapp = QtGui.QApplication(sys.argv)

#        self.u = usrp2.source_32fc(options.interface, options.mac_addr)
	self.u = msdd_rs.source_simple("192.168.1.20", 10000);
	self.conv = gr.interleaved_short_to_complex();
        self._adc_rate = self.u.pull_adc_freq()
        self.set_bandwidth(options.bw)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
#            g = self.u.gain_range()	
 	    g = [0, 10]
            #options.gain = float(g[0]+g[1])/2
            options.gain = float(0)
        self.set_gain(options.gain)

        if options.freq is None:
		options.freq = 2.4e9;
#            # if no frequency was specified, use the mid-point of the subdev
#            f = self.u.freq_range()
#            options.freq = float(f[0]+f[1])/2

	self.set_frequency(options.freq)

        self._fftsize = options.fft_size


	self._freq = options.freq;
	self._bandwidth = 400;
        
	self.set_bandwidth(self._bandwidth);

        self.snk = qtgui.sink_c(options.fft_size, gr.firdes.WIN_BLACKMAN_hARRIS,
                                self._freq, self._bandwidth,
                                "USRP2 Display",
                                True, True, False, True, False)

        # Set up internal amplifier
        self.amp = gr.multiply_const_cc(0.0)
        self.set_amplifier_gain(0.01)

        # Create a single-pole IIR filter to remove DC
        #   but don't connect it yet
        self.dc_gain = 0.001
        self.dc = gr.single_pole_iir_filter_cc(self.dc_gain)
        self.dc_sub = gr.sub_cc()

	self.agc = gr.agc2_cc(1e-3, 1e-5, 0.01, 0.01, 10);

        self.connect(self.u, self.conv, self.snk)
        #self.connect(self.u, self.conv, self.amp, self.snk)

        if self.show_debug_info:
            print "Decimation rate: ", self._decim
            print "Bandwidth: ", self._bandwidth
#            print "D'board: ", self.u.daughterboard_id()

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        # Wrap the pointer as a PyQt SIP object
        #     This can now be manipulated as a PyQt4.QtGui.QWidget
        self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget)

        self.main_win = main_window(self.pysink, self)

        self.main_win.set_frequency(self._freq)
        self.main_win.set_gain(self._gain)
        self.main_win.set_bandwidth(self._bandwidth)
        self.main_win.set_amplifier(self._amp_value)

        self.main_win.show()
Exemplo n.º 27
0
	def __init__(self):
		gr.top_block.__init__(self, "USRP HRPT Receiver")

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 4e6
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/config.conf'
		self._pll_alpha_config = ConfigParser.ConfigParser()
		self._pll_alpha_config.read(config_filename)
		try: pll_alpha = self._pll_alpha_config.getfloat('usrp_rx_hrpt', 'pll_alpha')
		except: pll_alpha = 0.01
		self.pll_alpha = pll_alpha
		self._output_filename_config = ConfigParser.ConfigParser()
		self._output_filename_config.read(config_filename)
		try: output_filename = self._output_filename_config.get('usrp_rx_hrpt', 'filename')
		except: output_filename = 'frames.hrpt'
		self.output_filename = output_filename
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self._gain_config = ConfigParser.ConfigParser()
		self._gain_config.read(config_filename)
		try: gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
		except: gain = 35
		self.gain = gain
		self._freq_config = ConfigParser.ConfigParser()
		self._freq_config.read(config_filename)
		try: freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
		except: freq = 1698e6
		self.freq = freq
		self._clock_alpha_config = ConfigParser.ConfigParser()
		self._clock_alpha_config.read(config_filename)
		try: clock_alpha = self._clock_alpha_config.getfloat('usrp_rx_hrpt', 'clock_alpha')
		except: clock_alpha = 0.01
		self.clock_alpha = clock_alpha

		##################################################
		# Blocks
		##################################################
		self.throttle = gr.throttle(gr.sizeof_short*1, 2*sample_rate)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, "input_filename", False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.frame_sink.set_unbuffered(False)
		self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
		self.deframer = noaa.hrpt_deframer()
		self.decoder = noaa.hrpt_decoder(True,True)
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_moving_average_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.deframer, 0), (self.decoder, 0))
		self.connect((self.deframer, 0), (self.frame_sink, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0))
		self.connect((self.digital_binary_slicer_fb_0, 0), (self.deframer, 0))
Exemplo n.º 28
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] samples_file"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option(
            "-c",
            "--complex",
            action="store_true",
            default=False,
            help=
            "Sample file is float complex (64 bit per sample, 32 I + 32 Q) format"
        )
        parser.add_option(
            "-n",
            "--config",
            type="string",
            default="channel.conf",
            help="DAB+ channel configuration file [default=%default]")

        (options, args) = parser.parse_args()

        if len(args) < 1:
            print "error: need file with samples"
            sys.exit(1)
        else:
            filename = args[0]
            if options.complex:
                src = gr.file_source(gr.sizeof_gr_complex, filename, True)
            else:
                sinput = gr.file_source(gr.sizeof_short, filename, True)
                src = gr.interleaved_short_to_complex()
                self.connect(sinput, src)

        self.conf = options.config

        mode = options.dab_mode
        param = dabp.parameters(mode)
        # null symbol detector
        samples_per_null_sym = param.get_Nnull()
        #print "samples per null symbol : %d" % samples_per_null_sym
        nulldet = dabp.detect_null(samples_per_null_sym)
        # ofdm demod
        demod = dabp.ofdm_demod(mode)
        # FIC/MSC demultiplexer
        demux = dabp.fic_msc_demux(0, mode)
        # depuncturer
        punc = dabp.depuncturer_fic(mode)
        I = punc.getI()
        # viterbi
        vit = dabp.vitdec(I)
        # descrambler
        scram = dabp.scrambler(I)
        # FIB sink
        self.dst = dabp.fib_sink()

        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(src, nulldet)
        self.connect(src, (demod, 0))
        self.connect(nulldet, (demod, 1))
        self.connect((demod, 0), demux, punc, vit, scram, self.dst)
        self.connect((demod, 1), nullsink)
Exemplo n.º 29
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-w",
            "--which",
            type="int",
            default=0,
            help="select which MSDD (0, 1, ...) default is %default",
            metavar="NUM")
        parser.add_option(
            "-R",
            "--rx-subdev-spec",
            type="subdev",
            default=None,
            help=
            "select MSDD Rx side A or B (default=first one with a daughterboard)"
        )
        parser.add_option("-A",
                          "--antenna",
                          default=None,
                          help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=16,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-W",
                          "--waterfall",
                          action="store_true",
                          default=False,
                          help="Enable waterfall display")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-S",
                          "--oscilloscope",
                          action="store_true",
                          default=False,
                          help="Enable oscilloscope display")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True

        # build the graph

        #self.u = MSDD.source_simo(which=options.which, decim_rate=options.decim)
        self.u = msdd.source_simple("192.168.1.200", 0)
        self.u.set_decim_rate(options.decim)  #(16)

        #        msdd_src = gr.file_source(gr.sizeof_gr_complex, 'msdd.dat')
        #        thr = gr.throttle(gr.sizeof_gr_complex, 200000)
        #        self.connect(msdd_src, thr)

        #        if options.rx_subdev_spec is None:
        #           options.rx_subdev_spec = pick_subdevice(self.u)
        #        self.u.set_mux(MSDD.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        #        if options.width_8:
        #            width = 8
        #            shift = 8
        #            format = self.u.make_format(width, shift)
        #            print "format =", hex(format)
        #            r = self.u.set_format(format)
        #            print "set_format =", r

        # determine the daughterboard subdevice we're using
        #        self.subdev = MSDD.selected_subdev(self.u, options.rx_subdev_spec)

        #        print "Initial Freq", self.u.rx_freq(0), "deci: ", self.u.decim_rate()
        #        input_rate = 50e6 / self.u.decim_rate()
        input_rate = 50e6 / options.decim

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.oscilloscope:
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
        else:
            self.scope = fftsink2.fft_sink_c(panel,
                                             fft_size=1024,
                                             sample_rate=input_rate)


#        self.connect(self.u, self.scope)

        msdd_sink = gr.file_sink(gr.sizeof_gr_complex, 'schmen1.dat')

        self.conv = gr.interleaved_short_to_complex()
        self.connect(self.u, self.conv, msdd_sink)
        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            #g = self.subdev.gain_range()
            self.gain_range = (20, 70, .5)
            options.gain = float(self.gain_range[0] + self.gain_range[1]) / 2

        if options.freq is None:
            # if no freq was specified, use the mid-point
            #r = self.subdev.freq_range()
            r = (30e6, 6e9, 1e6)
            options.freq = float(r[0] + r[1]) / 2

        self.set_gain(options.gain)
        #
        #	if options.antenna is not None:
        #            print "Selecting antenna %s" % (options.antenna,)
        #            self.subdev.select_rx_antenna(options.antenna)

        if self.show_debug_info:
            #self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['decim'].set_value(options.decim)
            #           self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
            #           self.myform['dbname'].set_value(self.subdev.name())
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)

        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 30
0
from gnuradio import gr,audio;
import mediatools;
sys.path.append(".");

# Construct playlist
pl = mediatools.strvec(["1.mp3","2.ogg"]);

# Setup sample rates
dac_sample_rate = 44100;
file_sample_rate = 44100;
default_device = "";

# Instantiate blocks
tb = gr.top_block();
src = mediatools.audiosource_s(pl);
s2c = gr.interleaved_short_to_complex();
c2f = gr.complex_to_float();
mc = gr.multiply_const_cc(1.0/(32768.0)); # scale to the +1 / -1 range
sink = audio.sink(dac_sample_rate,default_device);

# Connect up flowgraph
tb.connect(src,s2c,mc,c2f);  # connect src->scalar->float conversion
tb.connect(c2f,sink);           # connect left channel
tb.connect((c2f,1),(sink,1));   # connect right channel

# And go
tb.run();



Exemplo n.º 31
0
#!/usr/bin/python

from pylab import *
#from scipy.fftpack import fftshift;

import math

from gnuradio import msdd, gr

tb = gr.top_block()

src = msdd.source_simple("10.45.4.43", 0)
convert = gr.interleaved_short_to_complex()
sink = gr.vector_sink_c()

gain = 40

fc = 2.4e9

src.set_decim_rate(8)
#src.set_rx_freq(0,3500000000);
src.set_rx_freq(0, fc)
src.set_pga(0, gain)

tb.connect(src, convert, sink)

tb.start()

v = []
for i in range(0, 10000):
    b = math.sqrt(i)
Exemplo n.º 32
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        parser.add_option("-w", "--which", type="int", default=0,
                          help="select which USRP (0, 1, ...) default is %default",
			  metavar="NUM")
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select USRP Rx side A or B (default=first one with a daughterboard)")
        parser.add_option("-A", "--antenna", default=None,
                          help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option("-d", "--decim", type="int", default=16,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-W", "--waterfall", action="store_true", default=False,
                          help="Enable waterfall display")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option( "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
                          help="Enable oscilloscope display")
	parser.add_option("", "--avg-alpha", type="eng_float", default=1e-1,
			  help="Set fftsink averaging factor, default=[%default]")
	parser.add_option("", "--ref-scale", type="eng_float", default=13490.0,
			  help="Set dBFS=0dB input value, default=[%default]")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
	self.options = options
        self.show_debug_info = True
        
        # build the graph
        if options.no_hb or (options.decim<8):
          #Min decimation of this firmware is 4. 
          #contains 4 Rx paths without halfbands and 0 tx paths.
          self.fpga_filename="std_4rx_0tx.rbf"
#          self.u = usrp.source_c(which=options.which, decim_rate=options.decim, fpga_filename=self.fpga_filename)
	  self.u = msdd.source_simple("192.168.1.200",0);
        else:
          #Min decimation of standard firmware is 8. 
          #standard fpga firmware "std_2rxhb_2tx.rbf" 
          #contains 2 Rx paths with halfband filters and 2 tx paths (the default)
          #self.u = usrp.source_c(which=options.which, decim_rate=options.decim)
	  self.u = msdd.source_simple("192.168.1.200",0);

            
        input_rate = self.u.adc_freq() / self.u.decim_rate()

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.oscilloscope:
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
        else:
            self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate, 
					      ref_scale=options.ref_scale, ref_level=0.0, y_divs = 10,
					      avg_alpha=options.avg_alpha)

	self.conv = gr.interleaved_short_to_complex();
        self.connect(self.u, self.conv,  self.scope)

        self._build_gui(vbox)
	self._setup_events()
	
        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            #g = self.subdev.gain_range()
            #g = self.u.gain_range()
            g = [0,10]
            options.gain = float(g[0]+g[1])/2

        if options.freq is None:
            # if no freq was specified, use the mid-point
            #r = self.subdev.freq_range()
            #r = self.u.freq_range()
	    r = [30e6, 6e9]
            options.freq = float(r[0]+r[1])/2

        self.set_gain(options.gain)

	if options.antenna is not None:
            print "Selecting antenna %s" % (options.antenna,)
            self.subdev.select_rx_antenna(options.antenna)

        if self.show_debug_info:
            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
            self.myform['dbname'].set_value("no subdevs used")
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)

        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 33
0
    def __init__(
            self,
            satellite='NOAAxx',
            decim=50,
            baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam",
            frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf',
            deframer_outsync_frames=5,
            deframer_insync_frames=2,
            clock_alpha=0.005,
            gain_mu=0.005,
            pll_alpha=0.005,
            pll_beta=0.00001,
            deframer_sync_check=True,
            symb_rate=600 * 1109):
        grc_wxgui.top_block_gui.__init__(
            self, title="NOAA HRPT Receiver from baseband file")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.satellite = satellite
        self.decim = decim
        self.baseband_file = baseband_file
        self.frames_file = frames_file
        self.deframer_outsync_frames = deframer_outsync_frames
        self.deframer_insync_frames = deframer_insync_frames
        self.clock_alpha = clock_alpha
        self.gain_mu = gain_mu
        self.pll_alpha = pll_alpha
        self.pll_beta = pll_beta
        self.deframer_sync_check = deframer_sync_check
        self.symb_rate = symb_rate

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_beta_sl = pll_beta_sl = pll_beta
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.max_clock_offset = max_clock_offset = 0.1
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate
        self.hs = hs = int(sps / 2.0)
        self.gain_mu_sl = gain_mu_sl = gain_mu
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_beta_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_beta_sl_sizer,
            value=self.pll_beta_sl,
            callback=self.set_pll_beta_sl,
            label="PLL Beta",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_beta_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_beta_sl_sizer,
            value=self.pll_beta_sl,
            callback=self.set_pll_beta_sl,
            minimum=0.000001,
            maximum=0.001,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        _gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_mu_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_gain_mu_sl_sizer,
            value=self.gain_mu_sl,
            callback=self.set_gain_mu_sl,
            label="Gain MU",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_mu_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_gain_mu_sl_sizer,
            value=self.gain_mu_sl,
            callback=self.set_gain_mu_sl,
            minimum=0.0001,
            maximum=0.01,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.cs2cf = gr.interleaved_short_to_complex()
        self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, gain_mu_sl, max_clock_offset)
        self.gr_complex_to_real_0 = gr.complex_to_real(1)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl,
                                                     0.07, -0.07, 2)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               baseband_file, False)
        self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0 / hs, 4000)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2)
        self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False)
        self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(
            deframer_sync_check, 11090, deframer_insync_frames,
            deframer_outsync_frames)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="PSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
        self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_univ_hrpt_deframer_0, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.noaa_hrpt_decoder_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
Exemplo n.º 34
0
    def __init__(
            self,
            decim=50,
            satellite='Meteor-M-N1',
            frames_file=os.environ['HOME'] + '/MN1_hrpt_frames.hmf',
            baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_Meteor-M-N1_2011-02-27_09-30-46_UTC_U2_d50.sam",
            symb_rate=600 * 1109,
            clock_alpha=0.050,
            pll_alpha=0.05,
            deframer_outsync_frames=100,
            deframer_insync_frames=3,
            deframer_sync_check=False):
        grc_wxgui.top_block_gui.__init__(
            self, title="Meteor M-N1 HRPT Receiver from baseband file")
        _icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.decim = decim
        self.satellite = satellite
        self.frames_file = frames_file
        self.baseband_file = baseband_file
        self.symb_rate = symb_rate
        self.clock_alpha = clock_alpha
        self.pll_alpha = pll_alpha
        self.deframer_outsync_frames = deframer_outsync_frames
        self.deframer_insync_frames = deframer_insync_frames
        self.deframer_sync_check = deframer_sync_check

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.sps = sps = samp_rate / symb_rate_tb
        self.v = v = True
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.max_clock_offset = max_clock_offset = 0.1
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate
        self.hs = hs = int(sps / 2.0)
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

        ##################################################
        # Blocks
        ##################################################
        self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.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=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self._v_check_box = forms.check_box(
            parent=self.GetWin(),
            value=self.v,
            callback=self.set_v,
            label="Open",
            true=True,
            false=False,
        )
        self.Add(self._v_check_box)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        self.poesweather_meteor_cadu_deframer_0 = poesweather.meteor_cadu_deframer(
            deframer_sync_check, 256, deframer_insync_frames,
            deframer_outsync_frames)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 10)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((-1, ))
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.gr_file_source_0_0 = gr.file_source(
            gr.sizeof_short * 1,
            "/home/martin/hrpt/baseband/METEOR-M-1/2011/07/24/METEOR-M-1_2011-07-24T113448_U2d50.sam",
            False)
        self.gr_file_sink_0_0_0 = gr.file_sink(gr.sizeof_char * 1,
                                               "frames.mn1")
        self.gr_file_sink_0_0_0.set_unbuffered(False)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        self.cs2cf = gr.interleaved_short_to_complex()
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
        self.connect((self.gr_agc_xx_0_0, 0), (self.pll, 0))
        self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.poesweather_meteor_cadu_deframer_0, 0),
                     (self.gr_file_sink_0_0_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_meteor_cadu_deframer_0, 0))
        self.connect((self.gr_file_source_0_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.wxgui_scopesink2_0, 0))
Exemplo n.º 35
0
    def __init__(self,frame,panel,vbox,argv):
        stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)

        usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser=OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
                          help="set sample rate")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-o", "--out-filename", type="string", default="sdl",
                          help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat file in a loop")
        parser.add_option("", "--freq-min", type="eng_float", default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("", "--freq-max", type="eng_float", default=900.25e6,
                          help="Set a maximum frequency [default=%default]")

        (options, args) = parser.parse_args()
        if not ((len(args) == 1) or (len(args) == 0)):
            parser.print_help()
            sys.exit(1)

        if len(args) == 1:
          filename = args[0]
        else:
          filename = None

        self.frame = frame
        self.panel = panel

        self.contrast = options.contrast
        self.brightness = options.brightness
        self.state = "FREQ"
        self.freq = 0

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        # build graph
        self.u=None

        if not (options.out_filename=="sdl"):
          options.repeat=False

        usrp_rate = options.samp_rate

        if not ((filename is None) or (filename=="usrp")):
          # file is data source
          self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat)
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.src=self.istoc

          options.gain=0.0
          self.gain=0.0

        else: # use a UHD device
          self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))

          # Set the subdevice spec
          if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

          # Set the antenna
          if(options.antenna):
            self.u.set_antenna(options.antenna, 0)

          self.u.set_samp_rate(usrp_rate)
          dev_rate = self.u.get_samp_rate()

          if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            options.gain = float(g.start()+g.stop())/2.0

          self.src=self.u

        self.gain = options.gain

        f2uc=gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL

        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768

        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640

        width=int(usrp_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if (options.out_filename=="sdl"):
          #Here comes the tv screen, you have to build and install
          #gr-video-sdl for this (subproject of gnuradio, only in cvs
          #for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height, 0,
                                             show_width, height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) \
              + " gray:" + options.out_filename
          print "(Use the spacebar to advance to next frames)"
          options.repeat=False
          file_sink=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0)

        # now wire it all together
        #sample_rate=options.width*options.height*options.framerate

        process_type='do_no_sync'
        if process_type=='do_no_sync':
          self.connect (self.src, self.agc,self.am_demod,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc,self.dst)
        elif process_type=='do_tv_sync_adv':
          #defaults: gr.tv_sync_adv (double sampling_freq, unsigned
          #int tv_format,bool output_active_video_only=false, bool
          #do_invert=false, double wanted_black_level=0.0, double
          #wanted_white_level=255.0, double avg_alpha=0.1, double
          #initial_gain=1.0, double initial_offset=0.0,bool
          #debug=false)

          #note, this block is not yet in cvs
          self.tv_sync_adv=gr.tv_sync_adv(usrp_rate, 0, False, False,
                                          0.0, 255.0, 0.01, 1.0, 0.0, False)
          self.connect (self.src, self.am_demod, self.invert_and_scale,
                        self.tv_sync_adv, s2f, f2uc, self.dst)

        elif process_type=='do_nullsink':
          #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
          c2r=gr.complex_to_real()
          nullsink=gr.null_sink(gr.sizeof_float)
          self.connect (self.src, c2r,nullsink) #video_sink)
        elif process_type=='do_tv_sync_corr':
          frame_size=width*height #int(usrp_rate/25.0)
          nframes=10# 32
          search_window=20*nframes
          debug=False
          video_alpha=0.3 #0.1
          corr_alpha=0.3

          #Note: this block is not yet in cvs
          tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window,
                                      video_alpha, corr_alpha,debug)
          shift=gr.add_const_ff(-0.7)

          self.connect (self.src, self.agc, self.am_demod, tv_corr,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc, self.dst)
        else: # process_type=='do_test_image':
          src_vertical_bars = gr.sig_source_f (usrp_rate, gr.GR_SIN_WAVE,
                                               10.0 *usrp_rate/320, 255,128)
          self.connect(src_vertical_bars, f2uc, self.dst)

        self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate)


        frange = self.u.get_freq_range()
        if(frange.start() > self.tv_freq_max or frange.stop() <  self.tv_freq_min):
            sys.stderr.write("Radio does not support required frequency range.\n")
            sys.exit(1)
        if(options.freq < self.tv_freq_min or options.freq > self.tv_freq_max):
            sys.stderr.write("Requested frequency is outside of required frequency range.\n")
            sys.exit(1)

        # set initial values
        self.set_gain(options.gain)
        self.set_contrast(self.contrast)
        self.set_brightness(options.brightness)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 36
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename. \n Special output_filename \"sdl\" will use video_sink_sdl as realtime output window. " \
              "You then need to have gr-video-sdl installed. \n" \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-c",
                          "--contrast",
                          type="eng_float",
                          default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b",
                          "--brightness",
                          type="eng_float",
                          default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=8,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option(
            "-i",
            "--in-filename",
            type="string",
            default=None,
            help=
            "Use input file as source. samples must be interleaved shorts \n "
            + "Use usrp_rx_file.py or usrp_rx_cfile.py --output-shorts. \n"
            "Special name \"usrp\"  results in realtime capturing and processing using usrp. \n"
            + "You then probably need a decimation factor of 64 or higher.")
        parser.add_option(
            "-f",
            "--freq",
            type="eng_float",
            default=None,
            help=
            "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel",
            metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p",
                          "--pal",
                          action="store_true",
                          default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n",
                          "--ntsc",
                          action="store_true",
                          default=False,
                          help="NTSC video format")
        parser.add_option("-r",
                          "--repeat",
                          action="store_false",
                          default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-N",
                          "--nframes",
                          type="eng_float",
                          default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        (options, args) = parser.parse_args()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n')
            sys.exit(1)

        filename = args[0]

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write(
                'You must specify the input -i FILENAME or -i usrp\n')
            raise SystemExit, 1

        if not (filename == "sdl"):
            options.repeat = False

        if not (options.in_filename == "usrp"):
            self.filesource = gr.file_source(
                gr.sizeof_short, options.in_filename, options.repeat
            )  # file is data source, capture with usr_rx_csfile.py
            self.istoc = gr.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.adc_rate = 64e6
            self.src = self.istoc
        else:
            if options.freq is None:
                parser.print_help()
                sys.stderr.write(
                    'You must specify the frequency with -f FREQ\n')
                raise SystemExit, 1
            if abs(options.freq) < 1e6:
                options.freq *= 1e6
            if options.no_hb or (options.decim < 8):
                self.fpga_filename = "std_4rx_0tx.rbf"  #contains 4 Rx paths without halfbands and 0 tx paths
            else:
                self.fpga_filename = "std_2rxhb_2tx.rbf"  # contains 2 Rx paths with halfband filters and 2 tx paths (the default)

            # build the graph
            self.u = usrp.source_c(decim_rate=options.decim,
                                   fpga_filename=self.fpga_filename)
            self.src = self.u
            if options.width_8:
                sample_width = 8
                sample_shift = 8
                format = self.u.make_format(sample_width, sample_shift)
                r = self.u.set_format(format)
            self.adc_rate = self.u.adc_freq()
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
            self.u.set_mux(
                usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
            # determine the daughterboard subdevice we're using
            self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
            print "Using RX d'board %s" % (self.subdev.side_and_name(), )

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.subdev.gain_range()
                options.gain = float(g[0] + g[1]) / 2
            self.subdev.set_gain(options.gain)

            r = self.u.tune(0, self.subdev, options.freq)
            if not r:
                sys.stderr.write('Failed to set frequency\n')
                raise SystemExit, 1

        input_rate = self.adc_rate / options.decim
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.agc = gr.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = gr.complex_to_mag()
        self.set_blacklevel = gr.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = gr.multiply_const_ff(-options.contrast *
                                                     128.0 * 255.0 / (200.0))
        self.f2uc = gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
            options.pal = True  #set default to PAL
        if options.pal:
            lines_per_frame = 625.0
            frames_per_sec = 25.0
            show_width = 768
        elif options.ntsc:
            lines_per_frame = 525.0
            frames_per_sec = 29.97002997
            show_width = 640
        width = int(input_rate / (lines_per_frame * frames_per_sec))
        height = int(lines_per_frame)

        if filename == "sdl":
            #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now)
            try:
                video_sink = video_sdl.sink_uc(frames_per_sec, width, height,
                                               0, show_width, height)
            except:
                print "gr-video-sdl is not installed"
                print "realtime \"sdl\" video output window is not available"
                raise SystemExit, 1
            self.dst = video_sink
        else:
            print "You can use the imagemagick display tool to show the resulting imagesequence"
            print "use the following line to show the demodulated TV-signal:"
            print "display -depth 8 -size " + str(width) + "x" + str(
                height) + " gray:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = gr.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex,
                                int(options.nframes * width * height))
            self.connect(self.src, self.head, self.agc)

        self.connect(self.agc, self.am_demod, self.invert_and_scale,
                     self.set_blacklevel, self.f2uc, self.dst)
Exemplo n.º 37
0
	def __init__(self, decim=50, satellite='Meteor-M-N1', frames_file=os.environ['HOME'] + '/MN1_hrpt_frames.hmf', baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_Meteor-M-N1_2011-02-27_09-30-46_UTC_U2_d50.sam", symb_rate=600*1109, clock_alpha=0.050, pll_alpha=0.05, deframer_outsync_frames=100, deframer_insync_frames=3, deframer_sync_check=False):
		grc_wxgui.top_block_gui.__init__(self, title="Meteor M-N1 HRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.satellite = satellite
		self.frames_file = frames_file
		self.baseband_file = baseband_file
		self.symb_rate = symb_rate
		self.clock_alpha = clock_alpha
		self.pll_alpha = pll_alpha
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_sync_check = deframer_sync_check

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.sps = sps = samp_rate/symb_rate_tb
		self.v = v = True
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.max_clock_offset = max_clock_offset = 0.1
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate
		self.hs = hs = int(sps/2.0)
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Blocks
		##################################################
		self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.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=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=50,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self._v_check_box = forms.check_box(
			parent=self.GetWin(),
			value=self.v,
			callback=self.set_v,
			label="Open",
			true=True,
			false=False,
		)
		self.Add(self._v_check_box)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		self.poesweather_meteor_cadu_deframer_0 = poesweather.meteor_cadu_deframer(deframer_sync_check, 256, deframer_insync_frames, deframer_outsync_frames)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*10)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((-1, ))
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_file_source_0_0 = gr.file_source(gr.sizeof_short*1, "/home/martin/hrpt/baseband/METEOR-M-1/2011/07/24/METEOR-M-1_2011-07-24T113448_U2d50.sam", False)
		self.gr_file_sink_0_0_0 = gr.file_sink(gr.sizeof_char*1, "frames.mn1")
		self.gr_file_sink_0_0_0.set_unbuffered(False)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		self.cs2cf = gr.interleaved_short_to_complex()
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
		self.connect((self.gr_agc_xx_0_0, 0), (self.pll, 0))
		self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.poesweather_meteor_cadu_deframer_0, 0), (self.gr_file_sink_0_0_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_meteor_cadu_deframer_0, 0))
		self.connect((self.gr_file_source_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_0, 0))
Exemplo n.º 38
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage=("%prog: [options] output_filename.\nSpecial output_filename" + \
            "\"sdl\" will use video_sink_sdl as realtime output window. " + \
            "You then need to have gr-video-sdl installed.\n" +\
            "Make sure your input capture file containes interleaved " + \
            "shorts not complex floats")
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
                          help="set sample rate")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be " + \
                            "interleaved shorts \n Use usrp_rx_file.py or " + \
                            "usrp_rx_cfile.py --output-shorts.\n Special " + \
                            "name \"usrp\" results in realtime capturing " + \
                            "and processing using usrp.\n" + \
                            "You then probably need a decimation factor of 64 or higher.")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-N", "--nframes", type="eng_float", default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("", "--freq-min", type="eng_float", default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("", "--freq-max", type="eng_float", default=900.25e6,
                          help="Set a maximum frequency [default=%default]")
        (options, args) = parser.parse_args ()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n');
            sys.exit(1)

        filename = args[0]

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n');
            raise SystemExit, 1

        if not (filename=="sdl"):
          options.repeat=False

        input_rate = options.samp_rate
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        if not (options.in_filename=="usrp"):
          # file is data source, capture with usr_rx_csfile.py
          self.filesource = gr.file_source(gr.sizeof_short,
                                           options.in_filename,
                                           options.repeat)
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.src=self.istoc
        else:
          if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1

          # build the graph
          self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))

          # Set the subdevice spec
          if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

          # Set the antenna
          if(options.antenna):
            self.u.set_antenna(options.antenna, 0)

          self.u.set_samp_rate(input_rate)
          dev_rate = self.u.get_samp_rate()

          self.src=self.u

          if options.gain is None:
              # if no gain was specified, use the mid-point in dB
              g = self.u.get_gain_range()
              options.gain = float(g.start()+g.stop())/2.0
          self.u.set_gain(options.gain)

          r = self.u.set_center_freq(options.freq)
          if not r:
              sys.stderr.write('Failed to set frequency\n')
              raise SystemExit, 1


        self.agc = gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel = gr.add_const_ff(options.brightness +255.0)
        self.invert_and_scale = gr.multiply_const_ff (-options.contrast *128.0*255.0/(200.0))
        self.f2uc = gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL
        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768
        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640
        width=int(input_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if filename=="sdl":
          #Here comes the tv screen, you have to build and install
          #gr-video-sdl for this (subproject of gnuradio, only in cvs
          #for now)
          try:
            video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0,
                                           show_width,height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename
          print "(Use the spacebar to advance to next frames)"
          file_sink=gr.file_sink(gr.sizeof_char, filename)
          self.dst =file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
            self.connect(self.src, self.head, self.agc)

        self.connect (self.agc, self.am_demod, self.invert_and_scale,
                      self.set_blacklevel, self.f2uc, self.dst)
Exemplo n.º 39
0
    def __init__(self,frame,panel,vbox,argv):
        stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)

        usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser=OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
                          help="set sample rate")
        parser.add_option("-f", "--freq", type="eng_float", default=519.25e6,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-o", "--out-filename", type="string", default="sdl",
                          help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat file in a loop")
        parser.add_option("", "--freq-min", type="eng_float", default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("", "--freq-max", type="eng_float", default=900.25e6,
                          help="Set a maximum frequency [default=%default]")

        (options, args) = parser.parse_args()
        if not ((len(args) == 1) or (len(args) == 0)):
            parser.print_help()
            sys.exit(1)
        
        if len(args) == 1:
          filename = args[0]
        else:
          filename = None

        self.frame = frame
        self.panel = panel
        
        self.contrast = options.contrast
        self.brightness = options.brightness
        self.state = "FREQ"
        self.freq = 0

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        # build graph
        self.u=None

        if not (options.out_filename=="sdl"):
          options.repeat=False

        usrp_rate = options.samp_rate

        if not ((filename is None) or (filename=="usrp")):
          # file is data source
          self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat)
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.src=self.istoc

          options.gain=0.0
          self.gain=0.0

        else: # use a UHD device
          self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))

          # Set the subdevice spec
          if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)
            
          # Set the antenna
          if(options.antenna):
            self.u.set_antenna(options.antenna, 0)

          self.u.set_samp_rate(usrp_rate)
          dev_rate = self.u.get_samp_rate()

          if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            options.gain = float(g.start()+g.stop())/2.0

          self.src=self.u

        self.gain = options.gain        

        f2uc=gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL

        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768

        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640

        width=int(usrp_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if (options.out_filename=="sdl"):
          #Here comes the tv screen, you have to build and install
          #gr-video-sdl for this (subproject of gnuradio, only in cvs
          #for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height, 0,
                                             show_width, height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) \
              + " gray:" + options.out_filename
          print "(Use the spacebar to advance to next frames)" 
          options.repeat=False
          file_sink=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink 

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0)

        # now wire it all together
        #sample_rate=options.width*options.height*options.framerate

        process_type='do_no_sync'
        if process_type=='do_no_sync':
          self.connect (self.src, self.agc,self.am_demod,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc,self.dst)
        elif process_type=='do_tv_sync_adv':
          #defaults: gr.tv_sync_adv (double sampling_freq, unsigned
          #int tv_format,bool output_active_video_only=false, bool
          #do_invert=false, double wanted_black_level=0.0, double
          #wanted_white_level=255.0, double avg_alpha=0.1, double
          #initial_gain=1.0, double initial_offset=0.0,bool
          #debug=false)

          #note, this block is not yet in cvs
          self.tv_sync_adv=gr.tv_sync_adv(usrp_rate, 0, False, False,
                                          0.0, 255.0, 0.01, 1.0, 0.0, False)
          self.connect (self.src, self.am_demod, self.invert_and_scale,
                        self.tv_sync_adv, s2f, f2uc, self.dst) 

        elif process_type=='do_nullsink':
          #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
          c2r=gr.complex_to_real()
          nullsink=gr.null_sink(gr.sizeof_float)
          self.connect (self.src, c2r,nullsink) #video_sink)
        elif process_type=='do_tv_sync_corr':
          frame_size=width*height #int(usrp_rate/25.0)
          nframes=10# 32
          search_window=20*nframes 
          debug=False
          video_alpha=0.3 #0.1
          corr_alpha=0.3
          
          #Note: this block is not yet in cvs
          tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window,
                                      video_alpha, corr_alpha,debug) 
          shift=gr.add_const_ff(-0.7)
          
          self.connect (self.src, self.agc, self.am_demod, tv_corr,
                        self.invert_and_scale, self.set_blacklevel,
                        f2uc, self.dst)
        else: # process_type=='do_test_image':
          src_vertical_bars = gr.sig_source_f (usrp_rate, gr.GR_SIN_WAVE,
                                               10.0 *usrp_rate/320, 255,128)
          self.connect(src_vertical_bars, f2uc, self.dst)

        self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate)
 

        frange = self.u.get_freq_range()
        if(frange.start() > self.tv_freq_max or frange.stop() <  self.tv_freq_min):
            sys.stderr.write("Radio does not support required frequency range.\n")
            sys.exit(1)
        if(options.freq < self.tv_freq_min or options.freq > self.tv_freq_max):
            sys.stderr.write("Requested frequency is outside of required frequency range.\n")
            sys.exit(1)

        # set initial values
        self.set_gain(options.gain)
        self.set_contrast(self.contrast)
        self.set_brightness(options.brightness)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 40
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        parser.add_option("-w", "--which", type="int", default=0,
                          help="select which MSDD (0, 1, ...) default is %default",
			  metavar="NUM")
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select MSDD Rx side A or B (default=first one with a daughterboard)")
        parser.add_option("-A", "--antenna", default=None,
                          help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option("-d", "--decim", type="int", default=16,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-W", "--waterfall", action="store_true", default=False,
                          help="Enable waterfall display")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
                          help="Enable oscilloscope display")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True
        
        # build the graph

        #self.u = MSDD.source_simo(which=options.which, decim_rate=options.decim)
        self.u = msdd.source_simple("192.168.1.200", 0)
        self.u.set_decim_rate(options.decim) #(16)

#        msdd_src = gr.file_source(gr.sizeof_gr_complex, 'msdd.dat')
#        thr = gr.throttle(gr.sizeof_gr_complex, 200000)
#        self.connect(msdd_src, thr)

#        if options.rx_subdev_spec is None:
#           options.rx_subdev_spec = pick_subdevice(self.u)
#        self.u.set_mux(MSDD.determine_rx_mux_value(self.u, options.rx_subdev_spec))

#        if options.width_8:
#            width = 8
#            shift = 8
#            format = self.u.make_format(width, shift)
#            print "format =", hex(format)
#            r = self.u.set_format(format)
#            print "set_format =", r
            
        # determine the daughterboard subdevice we're using
#        self.subdev = MSDD.selected_subdev(self.u, options.rx_subdev_spec)

#        print "Initial Freq", self.u.rx_freq(0), "deci: ", self.u.decim_rate()
#        input_rate = 50e6 / self.u.decim_rate()
        input_rate = 50e6 / options.decim;

        if options.waterfall:
            self.scope = \
              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
        elif options.oscilloscope:
            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
        else:
            self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate)

#        self.connect(self.u, self.scope)
               
        msdd_sink = gr.file_sink(gr.sizeof_gr_complex, 'schmen1.dat')
	
	self.conv = gr.interleaved_short_to_complex();
        self.connect(self.u, self.conv,  msdd_sink)
        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            #g = self.subdev.gain_range()
            self.gain_range = (20,70,.5);
	    options.gain = float(self.gain_range[0]+self.gain_range[1])/2

        if options.freq is None:
            # if no freq was specified, use the mid-point
            #r = self.subdev.freq_range()
	    r = (30e6,6e9,1e6)
            options.freq = float(r[0]+r[1])/2

        self.set_gain(options.gain)
#
#	if options.antenna is not None:
#            print "Selecting antenna %s" % (options.antenna,)
#            self.subdev.select_rx_antenna(options.antenna)

        if self.show_debug_info:
            #self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['decim'].set_value(options.decim)
 #           self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
 #           self.myform['dbname'].set_value(self.subdev.name())
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)

        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Exemplo n.º 41
0
	def __init__(self, deframer_insync_frames=2, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, deframer_sync_check=True, pll_alpha=0.005, freq=1691.02e6, gain=23, side="A", decim=25, symb_rate=(3500e3/3+3500e3)/2, frames_file=os.environ['HOME'] + '/MetOp-AHRPT_cadu_frames.cadu', clock_alpha=0.05, baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam', satellite='MetOp'):
		grc_wxgui.top_block_gui.__init__(self, title="MetOp AHRPT Receiver from baseband file")

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.viterbi_insync_frames = viterbi_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_sync_check = viterbi_sync_check
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.deframer_sync_check = deframer_sync_check
		self.pll_alpha = pll_alpha
		self.freq = freq
		self.gain = gain
		self.side = side
		self.decim = decim
		self.symb_rate = symb_rate
		self.frames_file = frames_file
		self.clock_alpha = clock_alpha
		self.baseband_file = baseband_file
		self.satellite = satellite

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.gain_tb = gain_tb = gain
		self.freq_tb = freq_tb = freq
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self._gain_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.gain_tb,
			callback=self.set_gain_tb,
			label="RX gain [dB]",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.cs2cf = gr.interleaved_short_to_complex()
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 4)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, True)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*2)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=5,
			y_divs=10,
			ref_level=-15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="QPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0, 0))
Exemplo n.º 42
0
    def __init__(self):
        gr.top_block.__init__(self)

        # Build an options parser to bring in information from the user on usage
        usage = "usage: %prog [options] host min_freq max_freq"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-g", "--gain", type="eng_float", default=32,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("", "--tune-delay", type="eng_float", default=5e-5, metavar="SECS",
                          help="time to delay (in seconds) after changing frequency [default=%default]")
        parser.add_option("", "--dwell-delay", type="eng_float", default=50e-5, metavar="SECS",
                          help="time to dwell (in seconds) at a given frequncy [default=%default]")
        parser.add_option("-F", "--fft-size", type="int", default=256,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("-d", "--decim", type="intx", default=16,
                          help="set decimation to DECIM [default=%default]")
        parser.add_option("", "--real-time", action="store_true", default=False,
                          help="Attempt to enable real-time scheduling")

        (options, args) = parser.parse_args()
        if len(args) != 3:
            parser.print_help()
            sys.exit(1)

        # get user-provided info on address of MSDD and frequency to sweep
        self.address  = args[0]
        self.min_freq = eng_notation.str_to_num(args[1])
        self.max_freq = eng_notation.str_to_num(args[2])

        self.decim = options.decim
        self.gain  = options.gain
        
        if self.min_freq > self.max_freq:
            self.min_freq, self.max_freq = self.max_freq, self.min_freq   # swap them

	self.fft_size = options.fft_size

        if not options.real_time:
            realtime = False
        else:
            # Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        # Sampling rate is hardcoded and cannot be read off device
        adc_rate = 102.4e6
        self.int_rate = adc_rate / self.decim
        print "Sampling rate: ", self.int_rate

        # build graph
        self.port = 10001   # required port for UDP packets
	
	#	which board,	op mode,	adx,	port
#        self.src = msdd.source_c(0, 1, self.address, self.port)  # build source object

	self.conv = gr.interleaved_short_to_complex();

	self.src = msdd.source_simple(self.address,self.port);
        self.src.set_decim_rate(self.decim)                      # set decimation rate
#        self.src.set_desired_packet_size(0, 1460)                # set packet size to collect

        self.set_gain(self.gain)                                 # set receiver's attenuation
        self.set_freq(self.min_freq)                             # set receiver's rx frequency
        
        # restructure into vector format for FFT input
	s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        # set up FFT processing block
        mywindow = window.blackmanharris(self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, mywindow, True)
        power = 0
        for tap in mywindow:
            power += tap*tap
        
        # calculate magnitude squared of output of FFT
        c2mag = gr.complex_to_mag_squared(self.fft_size)

        # FIXME the log10 primitive is dog slow
        log = gr.nlog10_ff(10, self.fft_size,
                           -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
		
        # Set the freq_step to % of the actual data throughput.
        # This allows us to discard the bins on both ends of the spectrum.
        self.percent = 0.4

        # Calculate the frequency steps to use in the collection over the whole bandwidth
        self.freq_step = self.percent * self.int_rate
        self.min_center_freq = self.min_freq + self.freq_step/2
        nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step)
        self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step)

        self.next_freq = self.min_center_freq
        
        # use these values to set receiver settling time between samples and sampling time
        # the default values provided seem to work well with the MSDD over 100 Mbps ethernet
        tune_delay  = max(0, int(round(options.tune_delay * self.int_rate / self.fft_size)))  # in fft_frames
        dwell_delay = max(1, int(round(options.dwell_delay * self.int_rate / self.fft_size))) # in fft_frames

        # set up message callback routine to get data from bin_statistics_f block
        self.msgq = gr.msg_queue(16)
        self._tune_callback = tune(self)        # hang on to this to keep it from being GC'd

        # FIXME this block doesn't like to work with negatives because of the "d_max[i]=0" on line
        # 151 of gr_bin_statistics_f.cc file. Set this to -10000 or something to get it to work.
        stats = gr.bin_statistics_f(self.fft_size, self.msgq,
                                    self._tune_callback, tune_delay, dwell_delay)

        # FIXME there's a concern over the speed of the log calculation
        # We can probably calculate the log inside the stats block
	self.connect(self.src, self.conv, s2v, fft, c2mag, log, stats)
Exemplo n.º 43
0
    def __init__(self):
        gr.top_block.__init__(self, "USRP HRPT Receiver")

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 4e6
        self.sps = sps = sample_rate / sym_rate
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self._pll_alpha_config = ConfigParser.ConfigParser()
        self._pll_alpha_config.read(config_filename)
        try:
            pll_alpha = self._pll_alpha_config.getfloat(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            pll_alpha = 0.01
        self.pll_alpha = pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self._gain_config = ConfigParser.ConfigParser()
        self._gain_config.read(config_filename)
        try:
            gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
        except:
            gain = 35
        self.gain = gain
        self._freq_config = ConfigParser.ConfigParser()
        self._freq_config.read(config_filename)
        try:
            freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
        except:
            freq = 1698e6
        self.freq = freq
        self._clock_alpha_config = ConfigParser.ConfigParser()
        self._clock_alpha_config.read(config_filename)
        try:
            clock_alpha = self._clock_alpha_config.getfloat(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            clock_alpha = 0.01
        self.clock_alpha = clock_alpha

        ##################################################
        # Blocks
        ##################################################
        self.throttle = gr.throttle(gr.sizeof_short * 1, 2 * sample_rate)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               "input_filename", False)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.frame_sink.set_unbuffered(False)
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.deframer = noaa.hrpt_deframer()
        self.decoder = noaa.hrpt_decoder(True, True)
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.throttle, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0), (self.deframer, 0))
Exemplo n.º 44
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage=("%prog: [options] output_filename.\nSpecial output_filename" + \
            "\"sdl\" will use video_sink_sdl as realtime output window. " + \
            "You then need to have gr-video-sdl installed.\n" +\
            "Make sure your input capture file containes interleaved " + \
            "shorts not complex floats")
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default=None,
                          help="Subdevice of UHD device where appropriate")
        parser.add_option("-A",
                          "--antenna",
                          type="string",
                          default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s",
                          "--samp-rate",
                          type="eng_float",
                          default=1e6,
                          help="set sample rate")
        parser.add_option("-c",
                          "--contrast",
                          type="eng_float",
                          default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b",
                          "--brightness",
                          type="eng_float",
                          default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be " + \
                            "interleaved shorts \n Use usrp_rx_file.py or " + \
                            "usrp_rx_cfile.py --output-shorts.\n Special " + \
                            "name \"usrp\" results in realtime capturing " + \
                            "and processing using usrp.\n" + \
                            "You then probably need a decimation factor of 64 or higher.")
        parser.add_option(
            "-f",
            "--freq",
            type="eng_float",
            default=519.25e6,
            help=
            "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel",
            metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p",
                          "--pal",
                          action="store_true",
                          default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n",
                          "--ntsc",
                          action="store_true",
                          default=False,
                          help="NTSC video format")
        parser.add_option("-r",
                          "--repeat",
                          action="store_false",
                          default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-N",
                          "--nframes",
                          type="eng_float",
                          default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("",
                          "--freq-min",
                          type="eng_float",
                          default=50.25e6,
                          help="Set a minimum frequency [default=%default]")
        parser.add_option("",
                          "--freq-max",
                          type="eng_float",
                          default=900.25e6,
                          help="Set a maximum frequency [default=%default]")
        (options, args) = parser.parse_args()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n')
            sys.exit(1)

        filename = args[0]

        self.tv_freq_min = options.freq_min
        self.tv_freq_max = options.freq_max

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write(
                'You must specify the input -i FILENAME or -i usrp\n')
            raise SystemExit, 1

        if not (filename == "sdl"):
            options.repeat = False

        input_rate = options.samp_rate
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        if not (options.in_filename == "usrp"):
            # file is data source, capture with usr_rx_csfile.py
            self.filesource = gr.file_source(gr.sizeof_short,
                                             options.in_filename,
                                             options.repeat)
            self.istoc = gr.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.src = self.istoc
        else:
            if options.freq is None:
                parser.print_help()
                sys.stderr.write(
                    'You must specify the frequency with -f FREQ\n')
                raise SystemExit, 1

            # build the graph
            self.u = uhd.usrp_source(device_addr=options.args,
                                     stream_args=uhd.stream_args('fc32'))

            # Set the subdevice spec
            if (options.spec):
                self.u.set_subdev_spec(options.spec, 0)

            # Set the antenna
            if (options.antenna):
                self.u.set_antenna(options.antenna, 0)

            self.u.set_samp_rate(input_rate)
            dev_rate = self.u.get_samp_rate()

            self.src = self.u

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.u.get_gain_range()
                options.gain = float(g.start() + g.stop()) / 2.0
            self.u.set_gain(options.gain)

            r = self.u.set_center_freq(options.freq)
            if not r:
                sys.stderr.write('Failed to set frequency\n')
                raise SystemExit, 1

        self.agc = gr.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = gr.complex_to_mag()
        self.set_blacklevel = gr.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = gr.multiply_const_ff(-options.contrast *
                                                     128.0 * 255.0 / (200.0))
        self.f2uc = gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
            options.pal = True  #set default to PAL
        if options.pal:
            lines_per_frame = 625.0
            frames_per_sec = 25.0
            show_width = 768
        elif options.ntsc:
            lines_per_frame = 525.0
            frames_per_sec = 29.97002997
            show_width = 640
        width = int(input_rate / (lines_per_frame * frames_per_sec))
        height = int(lines_per_frame)

        if filename == "sdl":
            #Here comes the tv screen, you have to build and install
            #gr-video-sdl for this (subproject of gnuradio, only in cvs
            #for now)
            try:
                video_sink = video_sdl.sink_uc(frames_per_sec, width, height,
                                               0, show_width, height)
            except:
                print "gr-video-sdl is not installed"
                print "realtime \"sdl\" video output window is not available"
                raise SystemExit, 1
            self.dst = video_sink
        else:
            print "You can use the imagemagick display tool to show the resulting imagesequence"
            print "use the following line to show the demodulated TV-signal:"
            print "display -depth 8 -size " + str(width) + "x" + str(
                height) + " gray:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = gr.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex,
                                int(options.nframes * width * height))
            self.connect(self.src, self.head, self.agc)

        self.connect(self.agc, self.am_demod, self.invert_and_scale,
                     self.set_blacklevel, self.f2uc, self.dst)
Exemplo n.º 45
0
	def __init__(self):
		gr.top_block.__init__ (self)

		parser=OptionParser(option_class=eng_option)
		parser.add_option("-H", "--hostname", type="string", default="localhost",
						  help="set hostname of generic sdr")
		parser.add_option("-P", "--portnum", type="int", default=None,
						  help="set portnum of generic sdr")
		parser.add_option("-W", "--wsportnum", type="int", default=None,
						  help="set portnum of audio websocket server")
		parser.add_option("-r", "--sdr_rate", type="eng_float", default=250e3,
						  help="set sample rate of generic sdr")
		parser.add_option("-V", "--volume", type="eng_float", default=None,
						  help="set volume (default is midpoint)")
		parser.add_option("-O", "--audio-output", type="string", default="plughw:0,0",
						  help="pcm device name (default is plughw:0,0)")

		# print help when called with wrong arguments
		(options, args) = parser.parse_args()
		if len(args) != 0:
			parser.print_help()
			sys.exit(1)

		self.vol = options.volume
		if self.vol is None:
			self.vol = 0.1

		# connect to generic SDR
		sdr_rate = options.sdr_rate
		audio_decim = 8
		audio_rate = int(sdr_rate/audio_decim)
		print "audio_rate = ", audio_rate
		self.interleaved_short_to_complex = gr.interleaved_short_to_complex()
		self.char_to_short = gr.char_to_short(1)
		self.sdr_source = grc_blks2.tcp_source(
			itemsize=gr.sizeof_char*1,
			addr=options.hostname,
			port=options.portnum,
			server=False
		)
#		self.sdr_source = gr.file_source(1, 'sdrs_baseband.dat')
#		self.throttle = gr.throttle(1, 500e3)
#		self.connect(self.sdr_source, self.file_sink)
		self.logger = gr.file_sink(1, 'log.out')
		self.connect(self.sdr_source, self.logger)


		# channel filter
		chan_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			80e3,			# passband cutoff
			35e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
#		print "# channel filter:", len(chan_filter_coeffs), "taps"

		# PLL-based WFM demod
		fm_alpha = 0.25 * 250e3 * math.pi / sdr_rate		# 0.767
		fm_beta = fm_alpha * fm_alpha / 4.0			# 0.147
		fm_max_freq = 2.0 * math.pi * 90e3 / sdr_rate		# 2.209
		self.fm_demod = gr.pll_freqdet_cf(
			1.0,				# Loop BW
			fm_max_freq,		# in radians/sample
			-fm_max_freq)
		self.fm_demod.set_alpha(fm_alpha)
		self.fm_demod.set_beta(fm_beta)
		self.connect(self.sdr_source, self.char_to_short)
		self.connect(self.char_to_short, self.interleaved_short_to_complex)
		self.connect(self.interleaved_short_to_complex, self.chan_filter, self.fm_demod)

		# L+R, pilot, L-R, RDS filters
		lpr_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			15e3,			# passband cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.lpr_filter = gr.fir_filter_fff(audio_decim, lpr_filter_coeffs)
		pilot_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			19e3-500,		# low cutoff
			19e3+500,		# high cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs)
		dsbsc_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			38e3-15e3/2,	# low cutoff
			38e3+15e3/2,	# high cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.dsbsc_filter = gr.fir_filter_fff(1, dsbsc_filter_coeffs)
		rds_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			57e3-3e3,		# low cutoff
			57e3+3e3,		# high cutoff
			3e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs)
#		print "# lpr filter:", len(lpr_filter_coeffs), "taps"
#		print "# pilot filter:", len(pilot_filter_coeffs), "taps"
#		print "# dsbsc filter:", len(dsbsc_filter_coeffs), "taps"
#		print "# rds filter:", len(rds_filter_coeffs), "taps"
		self.connect(self.fm_demod, self.lpr_filter)
		self.connect(self.fm_demod, self.pilot_filter)
		self.connect(self.fm_demod, self.dsbsc_filter)
		self.connect(self.fm_demod, self.rds_filter)

		# down-convert L-R, RDS
		self.stereo_baseband = gr.multiply_ff()
		self.connect(self.pilot_filter, (self.stereo_baseband, 0))
		self.connect(self.pilot_filter, (self.stereo_baseband, 1))
		self.connect(self.dsbsc_filter, (self.stereo_baseband, 2))
		self.rds_baseband = gr.multiply_ff()
		self.connect(self.pilot_filter, (self.rds_baseband, 0))
		self.connect(self.pilot_filter, (self.rds_baseband, 1))
		self.connect(self.pilot_filter, (self.rds_baseband, 2))
		self.connect(self.rds_filter, (self.rds_baseband, 3))

		# low-pass and downsample L-R
		lmr_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			15e3,			# passband cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.lmr_filter = gr.fir_filter_fff(audio_decim, lmr_filter_coeffs)
		self.connect(self.stereo_baseband, self.lmr_filter)

		# create L, R from L-R, L+R
		self.left = gr.add_ff()
		self.right = gr.sub_ff()
		self.connect(self.lpr_filter, (self.left, 0))
		self.connect(self.lmr_filter, (self.left, 1))
		self.connect(self.lpr_filter, (self.right, 0))
		self.connect(self.lmr_filter, (self.right, 1))

		# volume control, complex2flot, audio sink
		self.volume_control_l = gr.multiply_const_ff(self.vol)
		self.volume_control_r = gr.multiply_const_ff(self.vol)
		output_audio_rate = 48000
		self.resamp_L = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,)
		self.resamp_R = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,)
		self.connect(self.left,  self.volume_control_l, self.resamp_L)
		self.connect(self.right, self.volume_control_r, self.resamp_R)
#		self.audio_sink = audio.sink(int(output_audio_rate),
#							options.audio_output, False)
# 		self.connect(self.resamp_L, (self.audio_sink, 0))
#		self.connect(self.resamp_R, (self.audio_sink, 1))
#		self.file_sink1 = gr.file_sink(gr.sizeof_float, 'audioL.dat')
#		self.file_sink2 = gr.file_sink(gr.sizeof_float, 'audioR.dat')
#		self.file_sink3 = gr.file_sink(gr.sizeof_float, 'fmDemod.dat')
#       		self.connect(self.resamp_L, self.file_sink1)
#		self.connect(self.resamp_R, self.file_sink2)
#		self.connect(self.fm_demod, self.file_sink3)

		# Interleave both channels so that we can push over one websocket connection
		self.audio_interleaver = gr.float_to_complex(1)
		self.connect(self.resamp_L, (self.audio_interleaver, 0))
		self.connect(self.resamp_R, (self.audio_interleaver, 1))
		
		self.ws_audio_server = sdrportal.ws_sink_c(True, options.wsportnum, "FLOAT")
		self.connect(self.audio_interleaver, self.ws_audio_server)

		# low-pass the baseband RDS signal at 1.5kHz
		rds_bb_filter_coeffs = gr.firdes.low_pass(
			1,				# gain
			sdr_rate,		# sampling rate
			1.5e3,			# passband cutoff
			2e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_bb_filter = gr.fir_filter_fff(audio_decim, rds_bb_filter_coeffs)
#		print "# rds bb filter:", len(rds_bb_filter_coeffs), "taps"
		self.connect(self.rds_baseband, self.rds_bb_filter)

		# 1187.5bps = 19kHz/16
		self.clock_divider = rds.freq_divider(16)
		rds_clock_taps = gr.firdes.low_pass(
			1,				# gain
			sdr_rate,		# sampling rate
			1.2e3,			# passband cutoff
			1.5e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_clock = gr.fir_filter_fff(audio_decim, rds_clock_taps)
#		print "# rds clock filter:", len(rds_clock_taps), "taps"
		self.connect(self.pilot_filter, self.clock_divider, self.rds_clock)

		# bpsk_demod, diff_decoder, rds_decoder
		self.bpsk_demod = rds.bpsk_demod(audio_rate)
		self.differential_decoder = gr.diff_decoder_bb(2)
		self.msgq = gr.msg_queue()
		self.rds_decoder = rds.data_decoder(self.msgq)
		self.connect(self.rds_bb_filter, (self.bpsk_demod, 0))
		self.connect(self.rds_clock, (self.bpsk_demod, 1))
		self.connect(self.bpsk_demod, self.differential_decoder)
		self.connect(self.differential_decoder, self.rds_decoder)
Exemplo n.º 46
0
	def __init__(self, baseband_file=os.environ['HOME'] + '/NOAA-XX.dat', satellite='NOAA-XX', decim=32, frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', sync_check=False):
		gr.top_block.__init__(self, "NOAA HRPT Baseband To Frames")

		##################################################
		# Parameters
		##################################################
		self.baseband_file = baseband_file
		self.satellite = satellite
		self.decim = decim
		self.frames_file = frames_file
		self.sync_check = sync_check

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		self._saved_pll_alpha_config = ConfigParser.ConfigParser()
		self._saved_pll_alpha_config.read(config_filename)
		try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_clock_alpha_config = ConfigParser.ConfigParser()
		self._saved_clock_alpha_config.read(config_filename)
		try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.frame_sink, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
Exemplo n.º 47
0
	def __init__(self, frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', decim=32, satellite='NOAA-XX', baseband_file=os.environ['HOME'] + '/NOAA-XX.dat', sync_check=False):
		grc_wxgui.top_block_gui.__init__(self, title="NOAA HRPT Baseband To Frames")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.frames_file = frames_file
		self.decim = decim
		self.satellite = satellite
		self.baseband_file = baseband_file
		self.sync_check = sync_check

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		self.sps = sps = sample_rate/sym_rate
		self._saved_pll_alpha_config = ConfigParser.ConfigParser()
		self._saved_pll_alpha_config.read(config_filename)
		try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_clock_alpha_config = ConfigParser.ConfigParser()
		self._saved_clock_alpha_config.read(config_filename)
		try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.sync_check_txt = sync_check_txt = sync_check
		self.satname_txt = satname_txt = satellite
		self.pll_alpha = pll_alpha = saved_pll_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self.frames_file_txt = frames_file_txt = frames_file
		self.decim_txt = decim_txt = decim
		self.clock_alpha = clock_alpha = saved_clock_alpha
		self.baseband_file_txt = baseband_file_txt = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "NOAA HRPT Spectrum")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
		self.Add(self.displays)

		##################################################
		# Controls
		##################################################
		self._sync_check_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.sync_check_txt,
			callback=self.set_sync_check_txt,
			label="Sync check",
			converter=forms.int_converter(),
		)
		self.GridAdd(self._sync_check_txt_static_text, 0, 3, 1, 1)
		self._satname_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.satname_txt,
			callback=self.set_satname_txt,
			label="Satellite",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._satname_txt_static_text, 0, 0, 1, 1)
		_pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_pll_alpha_sizer,
			value=self.pll_alpha,
			callback=self.set_pll_alpha,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_pll_alpha_sizer,
			value=self.pll_alpha,
			callback=self.set_pll_alpha,
			minimum=0.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_pll_alpha_sizer, 1, 0, 1, 1)
		self._frames_file_txt_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.frames_file_txt,
			callback=self.set_frames_file_txt,
			label="Frames output filename",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._frames_file_txt_static_text, 2, 0, 1, 1)
		self._decim_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.decim_txt,
			callback=self.set_decim_txt,
			label="Decimation",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._decim_txt_static_text, 0, 1, 1, 1)
		_clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_clock_alpha_sizer,
			value=self.clock_alpha,
			callback=self.set_clock_alpha,
			label="Clock Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_clock_alpha_sizer,
			value=self.clock_alpha,
			callback=self.set_clock_alpha,
			minimum=0.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_clock_alpha_sizer, 1, 1, 1, 1)
		self._baseband_file_txt_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.baseband_file_txt,
			callback=self.set_baseband_file_txt,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._baseband_file_txt_static_text, 1, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, "/home/jerry/NOAA-XX.hrpt")
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, "/home/jerry/hrpt/baseband/NOAA-18/2011-01-07T132821-NOAA-18.dat", False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.rx_fft = fftsink2.fft_sink_c(
			self.displays.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=45,
			ref_scale=2.0,
			sample_rate=sample_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="NOAA HRPT Spectrum",
			peak_hold=False,
		)
		self.displays.GetPage(0).Add(self.rx_fft.win)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.agc, 0), (self.rx_fft, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.frame_sink, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
    def __init__(self, fg, master_serialno,decim,nchan=2,pga_gain=0.0,cordic_freq=0.0,mux=None,align_interval=-1):
        """
        Align multiple sources (usrps) using samplenumbers in the first channel.

        Takes two ore more sources producing interleaved shorts.
				produces nchan * nsources gr_complex output streams.

        @param nchan: number of interleaved channels in source
        @param align_interval: number of samples to minimally skip between alignments
				                       default = -1 which means align only once per work call.
        @param master_serial_no: serial number of the source which must be the master.


        Exported sub-blocks (attributes):
          master_source
          slave_source
          usrp_master
          usrp_slave
        """
        mode=usrp.FPGA_MODE_NORMAL
        mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT
        align=gr.align_on_samplenumbers_ss (nchan,align_interval) 
        self.usrp_master = None
        self.usrp_slave = None
        # um is master usrp
        # us is slave usrp
        if mux is None:
          mux=self.get_default_mux()  #Note that all channels have shifted left because of the added 32 bit counter channel
        
        u1 = usrp.source_s (1, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" )
        u0 = usrp.source_s (0, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" )
        print 'usrp[0] serial',u0.serial_number()
        print 'usrp[1] serial',u1.serial_number()
        #default, choose the second found usrp as master (which is usually the usrp which was first plugged in)
        um_index=1
        um=u1
        us_index=0
        us=u0
        if (not (master_serialno is None)): #((master_serialno>0) | (master_serialno <-2)):
          if (u0.serial_number() == master_serialno):
            um_index=0
            um=u0
            us_index=1
            us=u1
          elif (u1.serial_number() != master_serialno):              
              errorstring = 'Error. requested master_serialno ' + master_serialno +' not found\n'
              errorstring = errorstring + 'Available are:\n'
              errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number() +'\n' 
              errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number() +'\n'
              print errorstring
              raise ValueError, errorstring
          else: #default, just choose the first found usrp as master
            um_index=0
            um=u0
            us_index=1
            us=u1

        self.usrp_master=um
        self.usrp_slave=us
        print 'usrp_master=usrp[%i] serial_no = %s' % (um_index,self.usrp_master.serial_number() ,)
        print 'usrp_slave=usrp[%i] serial_no = %s' % (us_index,self.usrp_slave.serial_number() ,)
        self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0,0))
        self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1,0))
        self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0,0))
        self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1,0))
        #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate)
        if not (pga_gain is None):
          um.set_pga (0, pga_gain)
          um.set_pga (1, pga_gain)

          us.set_pga (0, pga_gain)
          us.set_pga (1, pga_gain)

        self.input_rate = um.adc_freq () / um.decim_rate ()
        deintm=gr.deinterleave(gr.sizeof_gr_complex) 
        deints=gr.deinterleave(gr.sizeof_gr_complex)
        nullsinkm=gr.null_sink(gr.sizeof_gr_complex)
        nullsinks=gr.null_sink(gr.sizeof_gr_complex)

        tocomplexm=gr.interleaved_short_to_complex()
        tocomplexs=gr.interleaved_short_to_complex()

        fg.connect(um,(align,0))
        fg.connect(us,(align,1))
        fg.connect((align,0),tocomplexm)
        fg.connect((align,1),tocomplexs)
        fg.connect(tocomplexm,deintm)
        fg.connect(tocomplexs,deints)
        fg.connect((deintm,0),nullsinkm) #The counters are not usefull for the user but must be connected to something
        fg.connect((deints,0),nullsinks) #The counters are not usefull for the user but must be connected to something
        if 4==nchan:
          nullsinkm3=gr.null_sink(gr.sizeof_gr_complex)
          nullsinks3=gr.null_sink(gr.sizeof_gr_complex)
          fg.connect((deintm,3), nullsinkm3) #channel 4 is not used but must be connected
          fg.connect((deints,3), nullsinks3) #channel 4 is not used but must be connected

        self.fg=fg
        self.master_source=deintm
        self.slave_source=deints

        if not (cordic_freq is None):
          um.set_rx_freq (1, cordic_freq)
          um.set_rx_freq (0, cordic_freq)
          us.set_rx_freq (1, cordic_freq)
          us.set_rx_freq (0, cordic_freq)

        self.enable_master_and_slave()
        # add an idle handler
        self.unsynced=True
Exemplo n.º 49
0
	def __init__(self):
		gr.top_block.__init__ (self)

		parser=OptionParser(option_class=eng_option)
		parser.add_option("-H", "--hostname", type="string", default="localhost",
						  help="set hostname of generic sdr")
		parser.add_option("-P", "--portnum", type="int", default=None,
						  help="set portnum of generic sdr")
		parser.add_option("-r", "--sdr_rate", type="eng_float", default=250e3,
						  help="set sample rate of generic sdr")
		parser.add_option("-V", "--volume", type="eng_float", default=None,
						  help="set volume (default is midpoint)")
		parser.add_option("-O", "--audio-output", type="string", default="plughw:0,0",
						  help="pcm device name (default is plughw:0,0)")

		# print help when called with wrong arguments
		(options, args) = parser.parse_args()
		if len(args) != 0:
			parser.print_help()
			sys.exit(1)

		self.vol = options.volume
		if self.vol is None:
			self.vol = 0.1

		# connect to generic SDR
		sdr_rate = options.sdr_rate
		audio_decim = 8
		audio_rate = int(sdr_rate/audio_decim)
		print "audio_rate = ", audio_rate
		self.interleaved_short_to_complex = gr.interleaved_short_to_complex()
		self.char_to_short = gr.char_to_short(1)
		self.sdr_source = grc_blks2.tcp_source(
			itemsize=gr.sizeof_char*1,
			addr=options.hostname,
			port=options.portnum,
			server=False
		)
#		self.sdr_source = gr.file_source(1, 'sdrs_baseband.dat')
#		self.throttle = gr.throttle(1, 500e3)
#		self.connect(self.sdr_source, self.file_sink)
		self.logger = gr.file_sink(1, 'log.out')
		self.connect(self.sdr_source, self.logger)


		# channel filter
		chan_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			80e3,			# passband cutoff
			35e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
#		print "# channel filter:", len(chan_filter_coeffs), "taps"

		# PLL-based WFM demod
		fm_alpha = 0.25 * 250e3 * math.pi / sdr_rate		# 0.767
		fm_beta = fm_alpha * fm_alpha / 4.0			# 0.147
		fm_max_freq = 2.0 * math.pi * 90e3 / sdr_rate		# 2.209
		self.fm_demod = gr.pll_freqdet_cf(
			1.0,				# Loop BW
			fm_max_freq,		# in radians/sample
			-fm_max_freq)
		self.fm_demod.set_alpha(fm_alpha)
		self.fm_demod.set_beta(fm_beta)
		self.connect(self.sdr_source, self.char_to_short)
		self.connect(self.char_to_short, self.interleaved_short_to_complex)
		self.connect(self.interleaved_short_to_complex, self.chan_filter, self.fm_demod)

		# L+R, pilot, L-R, RDS filters
		lpr_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			15e3,			# passband cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.lpr_filter = gr.fir_filter_fff(audio_decim, lpr_filter_coeffs)
		pilot_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			19e3-500,		# low cutoff
			19e3+500,		# high cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs)
		dsbsc_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			38e3-15e3/2,	# low cutoff
			38e3+15e3/2,	# high cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.dsbsc_filter = gr.fir_filter_fff(1, dsbsc_filter_coeffs)
		rds_filter_coeffs = gr.firdes.band_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			57e3-3e3,		# low cutoff
			57e3+3e3,		# high cutoff
			3e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs)
#		print "# lpr filter:", len(lpr_filter_coeffs), "taps"
#		print "# pilot filter:", len(pilot_filter_coeffs), "taps"
#		print "# dsbsc filter:", len(dsbsc_filter_coeffs), "taps"
#		print "# rds filter:", len(rds_filter_coeffs), "taps"
		self.connect(self.fm_demod, self.lpr_filter)
		self.connect(self.fm_demod, self.pilot_filter)
		self.connect(self.fm_demod, self.dsbsc_filter)
		self.connect(self.fm_demod, self.rds_filter)

		# down-convert L-R, RDS
		self.stereo_baseband = gr.multiply_ff()
		self.connect(self.pilot_filter, (self.stereo_baseband, 0))
		self.connect(self.pilot_filter, (self.stereo_baseband, 1))
		self.connect(self.dsbsc_filter, (self.stereo_baseband, 2))
		self.rds_baseband = gr.multiply_ff()
		self.connect(self.pilot_filter, (self.rds_baseband, 0))
		self.connect(self.pilot_filter, (self.rds_baseband, 1))
		self.connect(self.pilot_filter, (self.rds_baseband, 2))
		self.connect(self.rds_filter, (self.rds_baseband, 3))

		# low-pass and downsample L-R
		lmr_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			sdr_rate,		# sampling rate
			15e3,			# passband cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.lmr_filter = gr.fir_filter_fff(audio_decim, lmr_filter_coeffs)
		self.connect(self.stereo_baseband, self.lmr_filter)

		# create L, R from L-R, L+R
		self.left = gr.add_ff()
		self.right = gr.sub_ff()
		self.connect(self.lpr_filter, (self.left, 0))
		self.connect(self.lmr_filter, (self.left, 1))
		self.connect(self.lpr_filter, (self.right, 0))
		self.connect(self.lmr_filter, (self.right, 1))

		# volume control, complex2flot, audio sink
		self.volume_control_l = gr.multiply_const_ff(self.vol)
		self.volume_control_r = gr.multiply_const_ff(self.vol)
		output_audio_rate = 48000
		self.resamp_L = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,)
		self.resamp_R = blks2.rational_resampler_fff(interpolation=output_audio_rate,decimation=audio_rate,taps=None,fractional_bw=None,)
		self.connect(self.left,  self.volume_control_l, self.resamp_L)
		self.connect(self.right, self.volume_control_r, self.resamp_R)
#		self.audio_sink = audio.sink(int(output_audio_rate),
#							options.audio_output, False)
# 		self.connect(self.resamp_L, (self.audio_sink, 0))
#		self.connect(self.resamp_R, (self.audio_sink, 1))
		self.file_sink1 = gr.file_sink(gr.sizeof_float, 'audioL.dat')
		self.file_sink2 = gr.file_sink(gr.sizeof_float, 'audioR.dat')
		self.file_sink3 = gr.file_sink(gr.sizeof_float, 'fmDemod.dat')
       		self.connect(self.resamp_L, self.file_sink1)
		self.connect(self.resamp_R, self.file_sink2)
		self.connect(self.fm_demod, self.file_sink3)

		# low-pass the baseband RDS signal at 1.5kHz
		rds_bb_filter_coeffs = gr.firdes.low_pass(
			1,				# gain
			sdr_rate,		# sampling rate
			1.5e3,			# passband cutoff
			2e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_bb_filter = gr.fir_filter_fff(audio_decim, rds_bb_filter_coeffs)
#		print "# rds bb filter:", len(rds_bb_filter_coeffs), "taps"
		self.connect(self.rds_baseband, self.rds_bb_filter)

		# 1187.5bps = 19kHz/16
		self.clock_divider = rds.freq_divider(16)
		rds_clock_taps = gr.firdes.low_pass(
			1,				# gain
			sdr_rate,		# sampling rate
			1.2e3,			# passband cutoff
			1.5e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_clock = gr.fir_filter_fff(audio_decim, rds_clock_taps)
#		print "# rds clock filter:", len(rds_clock_taps), "taps"
		self.connect(self.pilot_filter, self.clock_divider, self.rds_clock)

		# bpsk_demod, diff_decoder, rds_decoder
		self.bpsk_demod = rds.bpsk_demod(audio_rate)
		self.differential_decoder = gr.diff_decoder_bb(2)
		self.msgq = gr.msg_queue()
		self.rds_decoder = rds.data_decoder(self.msgq)
		self.connect(self.rds_bb_filter, (self.bpsk_demod, 0))
		self.connect(self.rds_clock, (self.bpsk_demod, 1))
		self.connect(self.bpsk_demod, self.differential_decoder)
		self.connect(self.differential_decoder, self.rds_decoder)
	def __init__(self, sync_check=False, decim=32, freq=1698e6, gain=35, side="A", frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', satellite='NOAA-XX'):
		gr.top_block.__init__(self, "USRP NOAA HRPT Receiver")

		##################################################
		# Parameters
		##################################################
		self.sync_check = sync_check
		self.decim = decim
		self.freq = freq
		self.gain = gain
		self.side = side
		self.frames_file = frames_file
		self.satellite = satellite

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.samp_rate = samp_rate = 64e6/decim
		self.sps = sps = samp_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		self._saved_pll_alpha_config = ConfigParser.ConfigParser()
		self._saved_pll_alpha_config.read(config_filename)
		try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.005
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
		except: saved_gain = gain
		self.saved_gain = saved_gain
		self._saved_clock_alpha_config = ConfigParser.ConfigParser()
		self._saved_clock_alpha_config.read(config_filename)
		try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.001
		self.saved_clock_alpha = saved_clock_alpha
		self.max_clock_offset = max_clock_offset = 0.1
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source_x_0.set_decim_rate(decim)
		self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
		self.usrp_simple_source_x_0.set_gain(gain)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.usrp_simple_source_x_0, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
Exemplo n.º 51
0
			#self._send("HEADER", "OFF")	# Enhanced udp_source
			
			if sample_rate is not None:
				self._send_and_wait_for_ok("RATE", sample_rate)
			else:
				#sample_rate = self.adc_freq() / decim_rate
				if self.set_decim_rate(decim_rate) == False:
					raise Exception, "Invalid decimation: %s (sample rate: %s)" % (decim_rate, sample_rate)
		
		if self.udp_source is None:
			assert self.vec2stream is None and self.ishort2complex is None
			udp_interface = "0.0.0.0"	# MAGIC
			self.udp_source = baz.udp_source(gr.sizeof_short * 2, udp_interface, udp_port, self._packet_size, True, True, True)
			#print "--> UDP Source listening on port:", udp_port, "interface:", udp_interface, "MTU:", self._packet_size
			self.vec2stream = gr.vector_to_stream(gr.sizeof_short * 1, 2)
			self.ishort2complex = gr.interleaved_short_to_complex()
		
			self.connect(self.udp_source, self.vec2stream, self.ishort2complex, self)
		else:
			assert self.vec2stream is not None and self.ishort2complex is not None
		
		if self._listen_only == False:
			if self._last_antenna is not None:
				self.select_rx_antenna(self._last_antenna)
			if self._last_freq is not None:
				self.set_freq(self._last_freq)
			if self._last_gain is not None:
				self.set_gain(self._last_gain)
			
			self._send_and_wait_for_ok("GO")	# Will STOP on disconnect
			
Exemplo n.º 52
0
    def __init__(self,
                 side="A",
                 gain=35,
                 decim=32,
                 sync_check=False,
                 satellite='METEOR-M-1',
                 frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt',
                 freq=1700e6):
        grc_wxgui.top_block_gui.__init__(self, title="USRP NOAA HRPT Receiver")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.side = side
        self.gain = gain
        self.decim = decim
        self.sync_check = sync_check
        self.satellite = satellite
        self.frames_file = frames_file
        self.freq = freq

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.samp_rate = samp_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/mn1_hrpt.conf'
        self.sps = sps = samp_rate / sym_rate
        self._saved_pll_alpha_config = ConfigParser.ConfigParser()
        self._saved_pll_alpha_config.read(config_filename)
        try:
            saved_pll_alpha = self._saved_pll_alpha_config.getfloat(
                "satname", 'pll_alpha')
        except:
            saved_pll_alpha = 0.005
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_clock_alpha_config = ConfigParser.ConfigParser()
        self._saved_clock_alpha_config.read(config_filename)
        try:
            saved_clock_alpha = self._saved_clock_alpha_config.getfloat(
                "satname", 'clock_alpha')
        except:
            saved_clock_alpha = 0.001
        self.saved_clock_alpha = saved_clock_alpha
        self.sync_check_txt = sync_check_txt = sync_check
        self.side_text = side_text = side
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
        except:
            saved_gain = gain
        self.saved_gain = saved_gain
        self.satellite_text = satellite_text = satellite
        self.sample_rate_text = sample_rate_text = samp_rate
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self.max_clock_offset = max_clock_offset = 0.1
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / samp_rate
        self.hs = hs = int(sps / 2.0)
        self.gain_slider = gain_slider = gain
        self.freq_tb = freq_tb = freq
        self.frames_outfile_text = frames_outfile_text = frames_file
        self.decim_tb = decim_tb = decim
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha = clock_alpha = saved_clock_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays),
                              "RX Meteor M N1 HRPT")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
        self.Add(self.displays)

        ##################################################
        # Controls
        ##################################################
        self._sync_check_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.sync_check_txt,
            callback=self.set_sync_check_txt,
            label="Sync check",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._sync_check_txt_static_text, 0, 2, 1, 1)
        self._side_text_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.side_text,
            callback=self.set_side_text,
            label="USRP Side",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._side_text_static_text, 0, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Satellite",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._satellite_text_static_text, 0, 1, 1, 1)
        self._sample_rate_text_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.sample_rate_text,
            callback=self.set_sample_rate_text,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._sample_rate_text_static_text, 3,
                                         0, 1, 1)
        _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_pll_alpha_sizer,
            value=self.pll_alpha,
            callback=self.set_pll_alpha,
            minimum=0.005,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 2, 1, 1, 1)
        _gain_slider_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_slider_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_slider_sizer,
            value=self.gain_slider,
            callback=self.set_gain_slider,
            label="Gain",
            converter=forms.int_converter(),
            proportion=0,
        )
        self._gain_slider_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_slider_sizer,
            value=self.gain_slider,
            callback=self.set_gain_slider,
            minimum=0,
            maximum=100,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=int,
            proportion=1,
        )
        self.GridAdd(_gain_slider_sizer, 2, 0, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_outfile_text_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.frames_outfile_text,
            callback=self.set_frames_outfile_text,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._frames_outfile_text_static_text,
                                         4, 0, 1, 1)
        self._decim_tb_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.GridAdd(self._decim_tb_text_box, 1, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Acquisition start",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._datetime_text_static_text, 2, 0,
                                         1, 1)
        _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_clock_alpha_sizer,
            value=self.clock_alpha,
            callback=self.set_clock_alpha,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 2, 2, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-5, 1.0, 1.0 / 32768.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.gr_rms_xx_0 = gr.rms_cf(0.2)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(
            sync_check)
        self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0,
                                                               side=side,
                                                               rx_ant="RXA")
        self.usrp_simple_source_x_0.set_decim_rate(decim)
        self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
        self.usrp_simple_source_x_0.set_gain(gain)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=45,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Meteor M N1 HRPT FFT Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
            self.GetWin(),
            unit="Units",
            minval=0,
            maxval=5000,
            factor=1.0,
            decimal_places=4,
            ref_level=0,
            sample_rate=samp_rate,
            number_rate=15,
            average=True,
            avg_alpha=0.07,
            label="S-Meter",
            peak_hold=False,
            show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_mn1_hrpt_deframer_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.gr_rms_xx_0, 0))
        self.connect((self.gr_rms_xx_0, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self.poesweather_mn1_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
Exemplo n.º 53
0
#!/usr/bin/python

from pylab import *;
#from scipy.fftpack import fftshift;

import math;

from gnuradio import msdd,gr;


tb = gr.top_block();


src = msdd.source_simple("10.45.4.43",0);
convert = gr.interleaved_short_to_complex();
sink = gr.vector_sink_c();

gain = 40;

fc = 2.4e9;

src.set_decim_rate(8);
#src.set_rx_freq(0,3500000000);
src.set_rx_freq(0,fc);
src.set_pga(0,gain);


tb.connect(src, convert, sink);


tb.start();