Exemplo n.º 1
0
    def __init__(self):
        gr.top_block.__init__(self)

	usage = "%prog: [options] filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (48000)")
	parser.add_option("-N", "--samples", type="eng_float", default=None,
			  help="number of samples to record")
        (options, args) = parser.parse_args ()
        if len(args) != 1 or options.samples is None:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl)
	head0 = gr.head(gr.sizeof_float, int(options.samples))
	head1 = gr.head(gr.sizeof_float, int(options.samples))
	dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16)

        self.connect(src0, head0, (dst, 0))
        self.connect(src1, head1, (dst, 1))
Exemplo n.º 2
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r",
                          "--sample-rate",
                          type="eng_float",
                          default=48000,
                          help="set sample rate to RATE (48000)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 440, ampl)
        dst = audio.sink(sample_rate, options.audio_output)
        self.connect(src0, (dst, 0))
        self.connect(src1, (dst, 1))
Exemplo n.º 3
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm output device name")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=192000,
                          help="set sample rate to RATE (192000)")
        parser.add_option("-f", "--frequency", type="eng_float", default=1000)
        parser.add_option("-a", "--amplitude", type="eng_float", default=0.5)

        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = float(options.amplitude)
        pulse_freq = 1.0 # 1Hz
        pulse_dc = 0.1 # Low DC value to give high/low value rather than on/off
        if ampl > 1.0: ampl = 1.0

        osc = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, options.frequency, ampl)
        pulse =  gr.sig_source_f (sample_rate, gr.GR_SQR_WAVE, pulse_freq, .8, pulse_dc)
        mixer = gr.multiply_ff ()
        self.connect (osc, (mixer, 0))
        self.connect (pulse, (mixer, 1))
        dst = audio.sink (sample_rate, options.audio_output, True)
        self.connect (mixer, dst)
Exemplo n.º 4
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-r",
                          "--sample-rate",
                          type="eng_float",
                          default=48000,
                          help="set sample rate to RATE (48000)")
        parser.add_option("-N",
                          "--samples",
                          type="eng_float",
                          default=None,
                          help="number of samples to record")
        (options, args) = parser.parse_args()
        if len(args) != 1 or options.samples is None:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 440, ampl)
        head0 = gr.head(gr.sizeof_float, int(options.samples))
        head1 = gr.head(gr.sizeof_float, int(options.samples))
        dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16)

        self.connect(src0, head0, (dst, 0))
        self.connect(src1, head1, (dst, 1))
Exemplo n.º 5
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.variable_slider_0 = variable_slider_0 = 30
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		_variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL)
		self._variable_slider_0_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_variable_slider_0_sizer,
			value=self.variable_slider_0,
			callback=self.set_variable_slider_0,
			label='variable_slider_0',
			converter=forms.float_converter(),
			proportion=0,
		)
		self._variable_slider_0_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_variable_slider_0_sizer,
			value=self.variable_slider_0,
			callback=self.set_variable_slider_0,
			minimum=0,
			maximum=100,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_variable_slider_0_sizer)
		self.sbfan_0 = sbfan.sbfan(1,0,0)
		self.plot_sink_0 = plot_sink.plot_sink_f(
			self.GetWin(),
			title="Scope Plot",
			vlen=1,
			decim=1,
			gsz=1000,
			zoom=0,
		)
		self.Add(self.plot_sink_0.win)
		self.gr_sig_source_x_0 = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 30, 0)
		self.gr_delay_0 = gr.delay(gr.sizeof_float*1, 5)
		self.gr_add_const_vxx_0 = gr.add_const_vff((30, ))
		self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 40)

		##################################################
		# Connections
		##################################################
		self.connect((self.const_source_x_0, 0), (self.sbfan_0, 0))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_add_const_vxx_0, 0))
		self.connect((self.sbfan_0, 0), (self.plot_sink_0, 0))
		self.connect((self.gr_add_const_vxx_0, 0), (self.gr_delay_0, 0))
		self.connect((self.gr_delay_0, 0), (self.sbfan_0, 1))
Exemplo n.º 6
0
    def __init__(self, fd, M, sample_rate):
        gr.hier_block2.__init__(self, "Rayleigh Channel",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.M = M
        self.sample_rate = sample_rate
        n = range(1, M + 1)
        N = 4 * M + 2

        f_n = [fd * math.cos(2 * math.pi * x / N) for x in n]

        beta_n = [math.pi / M * x for x in n]

        a_n = [2 * math.cos(x) for x in beta_n]
        a_n.append(math.sqrt(2) * math.cos(math.pi / 4))
        a_n = [x * 2 / math.sqrt(N) for x in a_n]

        b_n = [2 * math.sin(x) for x in beta_n]
        b_n.append(math.sqrt(2) * math.sin(math.pi / 4))
        b_n = [x * 2 / math.sqrt(N) for x in b_n]

        f_n.append(fd)

        self.sin_real = [
            gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], a_n[i])
            for i in range(M + 1)
        ]
        self.sin_imag = [
            gr.sig_source_f(self.sample_rate, gr.GR_COS_WAVE, f_n[i], b_n[i])
            for i in range(M + 1)
        ]

        self.add_real = gr.add_ff(1)
        self.add_imag = gr.add_ff(1)

        for i in range(M + 1):
            self.connect(self.sin_real[i], (self.add_real, i))

        for i in range(M + 1):
            self.connect(self.sin_imag[i], (self.add_imag, i))

        self.ftoc = gr.float_to_complex(1)

        self.connect(self.add_real, (self.ftoc, 0))
        self.connect(self.add_imag, (self.ftoc, 1))
        self.mulc = gr.multiply_const_cc((0.5))

        #self.divide = gr.divide_cc(1)
        #self.connect(self,(self.divide,0))
        #self.connect(self.ftoc,(self.divide,1))
        #self.connect(self.divide, self)
        self.prod = gr.multiply_cc(1)
        self.connect(self, (self.prod, 0))
        self.connect(self.ftoc, self.mulc, (self.prod, 1))
        self.connect(self.prod, self)
Exemplo n.º 7
0
    def __init__(self):
        gr.top_block.__init__(self)

        sample_rate = 32000
        ampl = 0.1
        print('sample_rate =', sample_rate)

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl)
        dst = audio.sink (sample_rate, "")
        self.connect (src0, (dst, 0))
        self.connect (src1, (dst, 1))
Exemplo n.º 8
0
def build_graph ():
    sampling_freq=48000
    ampl=0.1

    fg=gr.top_block()
    src0=gr.sig_source_f(sampling_freq,gr.GR_SIN_WAVE,350,ampl)
    src1=gr.sig_source_f(sampling_freq,gr.GR_SIN_WAVE,440,ampl)
    dst=audio.sink(sampling_freq)
    fg.connect((src0,0),(dst,0))
    fg.connect((src1,0),(dst,1))

    return fg
Exemplo n.º 9
0
def build_graph ():
    sampling_freq = 32000
    ampl = 0.1

    tb = gr.top_block ()
    src0 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, 350, ampl)
    src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, 440, ampl)
    dst = audio.sink (sampling_freq)
    tb.connect (src0, (dst, 0))
    tb.connect (src1, (dst, 1))

    return tb
Exemplo n.º 10
0
def build_graph():
    sampling_freq = 32000
    ampl = 0.1

    tb = gr.top_block()
    src0 = gr.sig_source_f(sampling_freq, gr.GR_SIN_WAVE, 350, ampl)
    src1 = gr.sig_source_f(sampling_freq, gr.GR_SIN_WAVE, 440, ampl)
    dst = audio.sink(sampling_freq)
    tb.connect(src0, (dst, 0))
    tb.connect(src1, (dst, 1))

    return tb
Exemplo n.º 11
0
 def _get_gauss_rand_proc_c(self):
     """ Returns the Gaussian random process.
     """
     spec_getter = getattr(self.model, 'get_' + self.spec_type)
     if self.spec_type in self.model.specs_odd:
         from winelo.channel import spec2soc
         soc = spec2soc(spec_getter(), method=self.method, N=self.N)
         sources = []
         adder = gr.add_cc()
         for idx, (freq, ampl) in enumerate(soc.get_soc()):
             sources.append(gr.sig_source_c(self.sample_rate,
                                            gr.GR_COS_WAVE, freq, ampl))
             self.connect(sources[idx],
                          gr.skiphead(gr.sizeof_gr_complex,
                                      randint(low=0, high=self.sample_rate)),
                          (adder, idx))
         return adder
     elif self.spec_type in self.model.specs_even:
         from winelo.channel import spec2sos
         # real part of the gaussian random process
         sos_real = spec2sos(spec_getter(), method=self.method, N=self.N)
         sources_real = []
         adder_real = gr.add_ff()
         for idx, (freq, ampl) in enumerate(sos_real.get_sos()):
             sources_real.append(gr.sig_source_f(self.sample_rate,
                                                 gr.GR_COS_WAVE, freq,
                                                 ampl))
             self.connect(sources_real[idx],
                          gr.skiphead(gr.sizeof_float,
                                      randint(low=0, high=self.sample_rate)),
                          (adder_real, idx))
         # imaginary part of the gaussian random process
         sos_imaginary = spec2sos(spec_getter(), method=self.method,
                                  N=self.N + 1)
         sources_imag = []
         adder_imag = gr.add_ff()
         for idx, (freq, ampl) in enumerate(sos_imaginary.get_sos()):
             sources_imag.append(gr.sig_source_f(self.sample_rate,
                                                 gr.GR_COS_WAVE, freq,
                                                 ampl))
             self.connect(sources_imag[idx],
                          gr.skiphead(gr.sizeof_float,
                                      randint(low=0, high=self.sample_rate)),
                          (adder_imag, idx))
         float2complex = gr.float_to_complex()
         self.connect(adder_real, (float2complex, 0))
         self.connect(adder_imag, (float2complex, 1))
         return float2complex
     else:
         print 'You picked a non-existant Doppler spectrum'
         print 'Pick one of the following: ', \
               self.model.specs_even + self.model.specs_odd
         return None
Exemplo n.º 12
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        
        src1 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src  = gr.add_ff()
        thr = gr.throttle(gr.sizeof_float, 100*npts)
        noise = gr.noise_source_f(gr.GR_GAUSSIAN, 0.001)
        add = gr.add_ff()
        self.snk1 = qtgui.time_sink_f(npts, Rs,
                                      "Complex Time Example", 3)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, self.snk1)
        self.connect(src1, (self.snk1, 1))
        self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        # Example of using signal/slot to set the title of a curve
        pyWin.connect(pyWin, QtCore.SIGNAL("setTitle(int, QString)"),
                      pyWin, QtCore.SLOT("setTitle(int, QString)"))
        pyWin.emit(QtCore.SIGNAL("setTitle(int, QString)"), 0, "sum")
        self.snk1.set_title(1, "src1")
        self.snk1.set_title(2, "src2")

        # Can also set the color of a curve
        #self.snk1.set_color(5, "blue")

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Exemplo n.º 13
0
    def __init__(self):
        gr.top_block.__init__(self)

        sample_rate = 48000
        ampl = 0.1

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 200,  ampl)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 1000, ampl)

        dst = audio.sink (sample_rate, "")

        self.connect (src0, (dst, 0))
        self.connect (src1, (dst, 1))
Exemplo n.º 14
0
   def __init__(self,fd,M,sample_rate):
       gr.hier_block2.__init__(self,"Rayleigh Channel",
                               gr.io_signature(1,1,gr.sizeof_gr_complex),
                               gr.io_signature(1,1,gr.sizeof_gr_complex))
       
       self.M = M
       self.sample_rate = sample_rate
       n=range(1,M+1)
       N = 4*M+2
       
       f_n= [fd*math.cos(2*math.pi*x/N) for x in n]
               
       beta_n = [math.pi/M*x for x in n]
       
       a_n = [2*math.cos(x) for x in beta_n]
       a_n.append(math.sqrt(2)*math.cos(math.pi/4))
       a_n = [x*2/math.sqrt(N) for x in a_n]
       
       
       b_n= [2*math.sin(x) for x in beta_n]
       b_n.append(math.sqrt(2)*math.sin(math.pi/4))
       b_n = [x*2/math.sqrt(N) for x in b_n]
       
       f_n.append(fd)
               
       self.sin_real = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],a_n[i]) for i in range(M+1)]
       self.sin_imag = [gr.sig_source_f(self.sample_rate,gr.GR_COS_WAVE,f_n[i],b_n[i]) for i in range(M+1)]
           
       self.add_real = gr.add_ff(1)
       self.add_imag = gr.add_ff(1)
       
       for i in range (M+1):
           self.connect(self.sin_real[i],(self.add_real,i))
 
       for i in range (M+1):
           self.connect(self.sin_imag[i],(self.add_imag,i))          
           
       self.ftoc = gr.float_to_complex(1)
       
       self.connect(self.add_real,(self.ftoc,0))
       self.connect(self.add_imag,(self.ftoc,1))
       self.mulc = gr.multiply_const_cc((0.5))
       
       #self.divide = gr.divide_cc(1)
       #self.connect(self,(self.divide,0))
       #self.connect(self.ftoc,(self.divide,1))
       #self.connect(self.divide, self)
       self.prod = gr.multiply_cc(1)
       self.connect(self,(self.prod,0))
       self.connect(self.ftoc,self.mulc,(self.prod,1))
       self.connect(self.prod, self)
Exemplo n.º 15
0
    def __init__(self, host, port, pkt_size, sample_rate, eof):
        gr.top_block.__init__(self, "dial_tone_source")

        amplitude = 0.3
        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude)
        add = gr.add_ff()

        # Throttle needed here to account for the other side's audio card sampling rate
	thr = gr.throttle(gr.sizeof_float, sample_rate)
	sink = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof)
	self.connect(src0, (add, 0))
	self.connect(src1, (add, 1))
	self.connect(add, thr, sink)
    def __init__(self, src, dst, port, pkt_size, sample_rate):
        gr.top_block.__init__(self, "dial_tone_source")

        amplitude = 0.3
        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude)
        add = gr.add_ff()

        # Throttle needed here to account for the other side's audio card sampling rate
	thr = gr.throttle(gr.sizeof_float, sample_rate)
	sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size)
	self.connect(src0, (add, 0))
	self.connect(src1, (add, 1))
	self.connect(add, thr, sink)
Exemplo n.º 17
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        # build our flow graph
        input_rate = 20.48e3

        # Generate a real and complex sinusoids
        src1 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)
        src2 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_float, input_rate)
        thr2 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = number_sink_f (panel, unit='V',label="Real Data", avg_alpha=0.001,
                            sample_rate=input_rate, minval=-1, maxval=1,
                            ref_level=0, decimal_places=3)
        vbox.Add (sink1.win, 1, wx.EXPAND)
        sink2 = number_sink_c (panel, unit='V',label="Complex Data", avg_alpha=0.001,
                            sample_rate=input_rate, minval=-1, maxval=1,
                            ref_level=0, decimal_places=3)
        vbox.Add (sink2.win, 1, wx.EXPAND)

        self.connect (src1, thr1, sink1)
        self.connect (src2, thr2, sink2)
Exemplo n.º 18
0
 def xInit(self, signals, noises, sinks):
 #   ------------------------------------------------------------------------
     self.sources = {}
     self.mutes = {}
     self.amps = {}
     
     #sources
     for signal in signals:
         self.sources[signal] = gr.sig_source_f(
             self.samprate, gr.GR_SIN_WAVE, 440, 0.25, 0)
         self.mutes[signal] = gr.mute_ff(True)
         self.amps[signal] = gr.multiply_const_ff(0.25)
     for noise in noises:
         self.sources[noise] = analog.noise_source_f(
             analog.GR_LAPLACIAN, 1, 0)
         self.mutes[noise] = gr.mute_ff(True)
         self.amps[noise] = gr.multiply_const_ff(0.25)
     #mixer
     if len(self.sources) > 1:
         self.adder = self.add = gr.add_vff(1)
     else:
         self.adder = gr.multiply_const_vff((1, ))
     self.level = gr.multiply_const_ff(1)
     
     #sinks
     self.sinks = sinks
         
     self.audiomute = gr.mute_ff(True)
     self.audio = audio.sink(self.samprate, "", True)
     self.udp = gr.null_sink(gr.sizeof_float)
     self.rawfile = gr.null_sink(gr.sizeof_float)
     self.wavefile = gr.null_sink(gr.sizeof_float)
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)

        #number_size = 256

        # build our flow graph
        input_rate = 20.48e3

        # Generate a complex sinusoid
        src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        #src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        #sink1 = number_sink_c (self, panel, label="Complex Data", number_size=number_size,
        #                    sample_rate=input_rate, base_value=100e3,
        #                    ref_level=0, decimal_places=3)
        #vbox.Add (sink1.win, 1, wx.EXPAND)
        #self.connect (src1, thr1, sink1)

        src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = number_sink_f (self, panel, unit='Hz',label="Real Data", avg_alpha=0.001,#number_size=number_size*2,
                            sample_rate=input_rate, base_value=100e3,
                            ref_level=0, decimal_places=3)
        vbox.Add (sink2.win, 1, wx.EXPAND)
        sink3 = number_sink_c (self, panel, unit='V',label="Complex Data", avg_alpha=0.001,#number_size=number_size*2,
                            sample_rate=input_rate, base_value=0,
                            ref_level=0, decimal_places=3)
        vbox.Add (sink3.win, 1, wx.EXPAND)
        self.connect (src2, thr2, sink2)
        self.connect (src1, thr1, sink3)
Exemplo n.º 20
0
    def __init__(self, app, samp_rate, at, filename, repeat, sine):
        '''
        in:
            - app = object of type RXApp
            - samp_rate = sample rate in Hertz
            - at = attenuation factor
            - filename = filename
            - repeat = if True them reads in a loop the file
            - sine
        '''
        gr.hier_block2.__init__(self, "RXData",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        
        
        # instance variables
        self.app = app
        
        if sine:
            self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 1.0)
        else:
            self.fileSrc = gr.file_source(gr.sizeof_float*1, filename, repeat)
#        self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 1.0)
#        self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_CONST_WAVE, 1000, 1.0)
        self.mulitplyCte = gr.multiply_const_vff((at, ))
        self.f2c = gr.float_to_complex(1)
        
        #EO instance variables
        
        self.__makeConnections()
Exemplo n.º 21
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (48000)")
        parser.add_option("-D", "--dont-block", action="store_false", default=True,
                          dest="ok_to_block")

        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 650, ampl)

        dst = audio.sink (sample_rate,
                          options.audio_output,
                          options.ok_to_block)

        self.connect (src0, (dst, 0))
Exemplo n.º 22
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.plot_sink_0 = plot_sink.plot_sink_f(
			self.GetWin(),
			title="Scope Plot",
			vlen=1,
			decim=1,
		)
		self.Add(self.plot_sink_0.win)
		self.gr_vector_sink_x_0 = gr.vector_sink_f(1)
		self.gr_serial_0 = gr_ser.ser()
		self.gr_serial_0.set_parameters("/dev/ttyACM1", 9600, 8, "N", 1)
		    
		self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 1)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_serial_0, 0), (self.gr_vector_sink_x_0, 0))
		self.connect((self.gr_serial_0, 0), (self.plot_sink_0, 0))
		self.connect((self.const_source_x_0, 0), (self.gr_serial_0, 0))
    def test_fff_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        rrate = 1.123  # resampling rate

        nfilts = 32

        freq = 100
        signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_float, N)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = gr.vector_sink_f()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / (fs * rrate), xrange(L))

        phase = 0.53013
        expected_data = map(
            lambda x: math.sin(2. * math.pi * freq * x + phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:],
                                          dst_data[-Ntest:], 3)
Exemplo n.º 24
0
    def __init__(self, atten=0, fd=50, fadeMode=0):
        gr.top_block.__init__(self,
                              "Static RF or Single Path Rayleigh Faded RF")

        ##################################################
        # Parameters
        ##################################################
        self.atten = atten
        self.fd = fd
        self.fadeMode = fadeMode

        ##################################################
        # Variables
        ##################################################
        self.usrpRate = usrpRate = 250e3
        self.fdTs = fdTs = fd * (1.0 / usrpRate)
        self.centreFreq = centreFreq = 1e6
        self.baseband_multiplier = baseband_multiplier = 0.25

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(
            ("0.0.0.0", 1234), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.uhd_usrp_sink_0_0_0 = uhd.usrp_sink(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0_0_0.set_subdev_spec("A:AB", 0)
        self.uhd_usrp_sink_0_0_0.set_samp_rate(usrpRate)
        self.uhd_usrp_sink_0_0_0.set_center_freq(centreFreq, 0)
        self.uhd_usrp_sink_0_0_0.set_gain(0, 0)
        self.rccBlocks_channelModel_cc_0 = rccBlocks.channelModel_cc(
            randint(-10000, 0), fdTs, 1.0, False, bool(fadeMode))
        self.rccBlocks_VNXLabBrick_0 = rccBlocks.VNXLabBrick(atten)
        self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0,
                                                  1.0)
        self.const_source_x_0 = gr.sig_source_c(0, gr.GR_CONST_WAVE, 0, 0,
                                                1.0 + 1j)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, usrpRate)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc(
            (baseband_multiplier, ))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.const_source_x_0, 0),
                     (self.rccBlocks_channelModel_cc_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.uhd_usrp_sink_0_0_0, 0))
        self.connect((self.const_source_x_0_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.rccBlocks_VNXLabBrick_0, 0))
        self.connect((self.rccBlocks_channelModel_cc_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
Exemplo n.º 25
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-i", "--input-rate", type="eng_float", default=8000,
                          help="set input sample rate to RATE (%default)")
        parser.add_option("-o", "--output-rate", type="eng_float", default=48000,
                          help="set output sample rate to RATE (%default)")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        input_rate = int(options.input_rate)
        output_rate = int(options.output_rate)

        interp = gru.lcm(input_rate, output_rate) / input_rate
        decim = gru.lcm(input_rate, output_rate) / output_rate

        print "interp =", interp
        print "decim  =", decim

        ampl = 0.1
        src0 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 650, ampl)
        rr = blks2.rational_resampler_fff(interp, decim)
        dst = audio.sink (output_rate, options.audio_output)
        self.connect (src0, rr, (dst, 0))
Exemplo n.º 26
0
    def __init__(self, sample_rate, tone_freq):
	gr.hier_block2.__init__(self, "ctcss_gen_f",
				gr.io_signature(0, 0, 0),               # Input signature
				gr.io_signature(1, 1, gr.sizeof_float)) # Output signature

        self.plgen = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, tone_freq, 0.1, 0.0)
	self.connect(self.plgen, self)
    def test_001_ff(self):
        N = 10000        # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        freq = 10
        signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_float, N)
        op = filter.fractional_interpolator_ff(0, rrate)
        snk = gr.vector_sink_f()

        self.tb.connect(signal, head, op, snk)
        self.tb.run() 
        import time
        time.sleep(2)
        
        Ntest = 5000
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs/rrate), xrange(L))

        phase = 0.1884
        expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t)
        dst_data = snk.data()

        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
Exemplo n.º 28
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 20.000e3

        # Generate a complex sinusoid
        src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
        #src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = ra_fft_sink_c (panel, title="Complex Data", fft_size=fft_size,
                            sample_rate=input_rate, baseband_freq=100e3,
                            ref_level=60, y_per_div=10)
        vbox.Add (sink1.win, 1, wx.EXPAND)
        self.connect (src1, thr1, sink1)

        src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
        #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = ra_fft_sink_f (panel, title="Real Data", fft_size=fft_size*2,
                            sample_rate=input_rate, baseband_freq=100e3,
                            ref_level=60, y_per_div=10)
        vbox.Add (sink2.win, 1, wx.EXPAND)
        self.connect (src2, thr2, sink2)
Exemplo n.º 29
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.plot_sink_0 = plot_sink.plot_sink_f(
            self.GetWin(),
            title="Scope Plot",
            vlen=1,
            decim=1,
        )
        self.Add(self.plot_sink_0.win)
        self.gr_vector_sink_x_0 = gr.vector_sink_f(1)
        self.gr_serial_0 = gr_ser.ser()
        self.gr_serial_0.set_parameters("/dev/ttyACM1", 9600, 8, "N", 1)

        self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_serial_0, 0), (self.gr_vector_sink_x_0, 0))
        self.connect((self.gr_serial_0, 0), (self.plot_sink_0, 0))
        self.connect((self.const_source_x_0, 0), (self.gr_serial_0, 0))
Exemplo n.º 30
0
    def set_waveform(self, type):
        self.lock()
        self.disconnect_all()
        if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
            self._src = gr.sig_source_c(
                self[SAMP_RATE_KEY],  # Sample rate
                type,  # Waveform type
                self[WAVEFORM_FREQ_KEY],  # Waveform frequency
                self[AMPLITUDE_KEY],  # Waveform amplitude
                self[WAVEFORM_OFFSET_KEY])  # Waveform offset
        elif type == gr.GR_GAUSSIAN or type == gr.GR_UNIFORM:
            self._src = gr.noise_source_c(type, self[AMPLITUDE_KEY])
        elif type == "2tone":
            self._src1 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE,
                                         self[WAVEFORM_FREQ_KEY],
                                         self[AMPLITUDE_KEY] / 2.0, 0)
            if (self[WAVEFORM2_FREQ_KEY] is None):
                self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY]

            self._src2 = gr.sig_source_c(self[SAMP_RATE_KEY], gr.GR_SIN_WAVE,
                                         self[WAVEFORM2_FREQ_KEY],
                                         self[AMPLITUDE_KEY] / 2.0, 0)
            self._src = gr.add_cc()
            self.connect(self._src1, (self._src, 0))
            self.connect(self._src2, (self._src, 1))
        elif type == "sweep":
            # rf freq is center frequency
            # waveform_freq is total swept width
            # waveform2_freq is sweep rate
            # will sweep from (rf_freq-waveform_freq/2) to (rf_freq+waveform_freq/2)
            if self[WAVEFORM2_FREQ_KEY] is None:
                self[WAVEFORM2_FREQ_KEY] = 0.1

            self._src1 = gr.sig_source_f(self[SAMP_RATE_KEY], gr.GR_TRI_WAVE,
                                         self[WAVEFORM2_FREQ_KEY], 1.0, -0.5)
            self._src2 = gr.frequency_modulator_fc(
                self[WAVEFORM_FREQ_KEY] * 2 * math.pi / self[SAMP_RATE_KEY])
            self._src = gr.multiply_const_cc(self[AMPLITUDE_KEY])
            self.connect(self._src1, self._src2, self._src)
        else:
            raise RuntimeError("Unknown waveform type")

        self.connect(self._src, self._u)
        self.unlock()

        if self._verbose:
            print "Set baseband modulation to:", waveforms[type]
            if type == gr.GR_SIN_WAVE:
                print "Modulation frequency: %sHz" % (n2s(
                    self[WAVEFORM_FREQ_KEY]), )
                print "Initial phase:", self[WAVEFORM_OFFSET_KEY]
            elif type == "2tone":
                print "Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]), )
                print "Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), )
            elif type == "sweep":
                print "Sweeping across %sHz to %sHz" % (n2s(
                    -self[WAVEFORM_FREQ_KEY] /
                    2.0), n2s(self[WAVEFORM_FREQ_KEY] / 2.0))
                print "Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]), )
            print "TX amplitude:", self[AMPLITUDE_KEY]
    def test_fff_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        nfilts = 32

        freq = 100
        signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_float, N)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = gr.vector_sink_f()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run() 

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs*rrate), xrange(L))

        phase = 0.53013
        expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
Exemplo n.º 32
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block	.__init__ (self, frame, panel, vbox, argv)

        fac_size = 256

        # build our flow graph
        input_rate = 20.48e3

        # Generate a complex sinusoid
        #src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fac_sink_c (panel, title="Complex Data", fac_size=fac_size,
                            sample_rate=input_rate, baseband_freq=100e3,
                            ref_level=0, y_per_div=20)
        vbox.Add (sink1.win, 1, wx.EXPAND)
        self.connect (src1, thr1, sink1)

        #src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = fac_sink_f (panel, title="Real Data", fac_size=fac_size*2,
                            sample_rate=input_rate, baseband_freq=100e3,
                            ref_level=0, y_per_div=20)
        vbox.Add (sink2.win, 1, wx.EXPAND)
        self.connect (src2, thr2, sink2)
Exemplo n.º 33
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        fft_size = 512

        # build our flow graph
        input_rate = 20.000e3

        # Generate a complex sinusoid
        self.src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
        #src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        self.thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = waterfall_sink_c (panel, title="Complex Data", fft_size=fft_size,
                                  sample_rate=input_rate, baseband_freq=100e3)
	self.connect(self.src1, self.thr1, sink1)
        vbox.Add (sink1.win, 1, wx.EXPAND)

        # generate a real sinusoid
        self.src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
        self.thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = waterfall_sink_f (panel, title="Real Data", fft_size=fft_size,
                                  sample_rate=input_rate, baseband_freq=100e3)
	self.connect(self.src2, self.thr2, sink2)
        vbox.Add (sink2.win, 1, wx.EXPAND)
Exemplo n.º 34
0
	def __init__(self,ramp_slope, height_Offset, width_Offset):
		gr.hier_block2.__init__(self,"HierBlock",gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,2,gr.sizeof_float))
		#constant_block initialized
		self.constant_block = gr.sig_source_f(0,gr.GR_CONST_WAVE,0,0,1)
		#ramp_source block initialized
		self.ramp_source=gr_ramp_source.ramp()
		self.ramp_source.set_parameters(ramp_slope, height_Offset, width_Offset)
		self.connect(self,(self.constant_block,0),(self.ramp_source,0),self)
Exemplo n.º 35
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 2048.0e3

        # Generate some noise
        noise = gr.noise_source_c(gr.GR_UNIFORM, 1.0 / 10)

        # Generate a complex sinusoid
        # src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fft_sink_c(
            panel,
            title="Complex Data",
            fft_size=fft_size,
            sample_rate=input_rate,
            baseband_freq=100e3,
            ref_level=0,
            y_per_div=20,
            y_divs=10,
        )
        vbox.Add(sink1.win, 1, wx.EXPAND)

        combine1 = gr.add_cc()
        self.connect(src1, (combine1, 0))
        self.connect(noise, (combine1, 1))
        self.connect(combine1, thr1, sink1)

        # src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src2 = gr.sig_source_f(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = fft_sink_f(
            panel,
            title="Real Data",
            fft_size=fft_size * 2,
            sample_rate=input_rate,
            baseband_freq=100e3,
            ref_level=0,
            y_per_div=20,
            y_divs=10,
        )
        vbox.Add(sink2.win, 1, wx.EXPAND)

        combine2 = gr.add_ff()
        c2f2 = gr.complex_to_float()

        self.connect(src2, (combine2, 0))
        self.connect(noise, c2f2, (combine2, 1))
        self.connect(combine2, thr2, sink2)
Exemplo n.º 36
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="My First Block Fg")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
            self.GetWin(),
            unit="Units",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate,
            number_rate=15,
            average=False,
            avg_alpha=None,
            label="Number Plot",
            peak_hold=False,
            show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.my_first_python_block_0 = dt.my_first_python_block()
        self.gr_throttle_0 = gr.throttle(gr.sizeof_float * 1, samp_rate)
        self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0,
                                                  -22)
        self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 5)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.const_source_x_0, 0),
                     (self.my_first_python_block_0, 0))
        self.connect((self.const_source_x_0_0, 0),
                     (self.my_first_python_block_0, 1))
        self.connect((self.my_first_python_block_0, 0),
                     (self.gr_throttle_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.wxgui_numbersink2_0, 0))
Exemplo n.º 37
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._nsamples = 1000000
        self._audio_rate = 8000

        # Set up N channels with their own baseband and IF frequencies
        self._N = 5
        chspacing = 16000
        freq = [10, 20, 30, 40, 50]
        f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing]

        self._if_rate = 4*self._N*self._audio_rate

        # Create a signal source and frequency modulate it
        self.sum = gr.add_cc ()
        for n in xrange(self._N):
            sig = gr.sig_source_f(self._audio_rate, gr.GR_SIN_WAVE, freq[n], 0.5)
            fm = fmtx(f_lo[n], self._audio_rate, self._if_rate)
            self.connect(sig, fm)
            self.connect(fm, (self.sum, n))

        self.head = gr.head(gr.sizeof_gr_complex, self._nsamples)
        self.snk_tx = gr.vector_sink_c()
        self.channel = blks2.channel_model(0.1)

        self.connect(self.sum, self.head, self.channel, self.snk_tx)


        # Design the channlizer
        self._M = 10
        bw = chspacing/2.0
        t_bw = chspacing/10.0
        self._chan_rate = self._if_rate / self._M
        self._taps = gr.firdes.low_pass_2(1, self._if_rate, bw, t_bw, 
                                          attenuation_dB=100,
                                          window=gr.firdes.WIN_BLACKMAN_hARRIS)
        tpc = math.ceil(float(len(self._taps)) /  float(self._M))

        print "Number of taps:     ", len(self._taps)
        print "Number of channels: ", self._M
        print "Taps per channel:   ", tpc
        
        self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)
        
        self.connect(self.channel, self.pfb)
        
        # Create a file sink for each of M output channels of the filter and connect it
        self.fmdet = list()
        self.squelch = list()
        self.snks = list()
        for i in xrange(self._M):
            self.fmdet.append(blks2.nbfm_rx(self._audio_rate, self._chan_rate))
            self.squelch.append(blks2.standard_squelch(self._audio_rate*10))
            self.snks.append(gr.vector_sink_f())
            self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
Exemplo n.º 38
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._nsamples = 1000000
        self._audio_rate = 8000

        # Set up N channels with their own baseband and IF frequencies
        self._N = 5
        chspacing = 16000
        freq = [10, 20, 30, 40, 50]
        f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing]

        self._if_rate = 4*self._N*self._audio_rate

        # Create a signal source and frequency modulate it
        self.sum = gr.add_cc ()
        for n in xrange(self._N):
            sig = gr.sig_source_f(self._audio_rate, gr.GR_SIN_WAVE, freq[n], 0.5)
            fm = fmtx(f_lo[n], self._audio_rate, self._if_rate)
            self.connect(sig, fm)
            self.connect(fm, (self.sum, n))

        self.head = gr.head(gr.sizeof_gr_complex, self._nsamples)
        self.snk_tx = gr.vector_sink_c()
        self.channel = blks2.channel_model(0.1)

        self.connect(self.sum, self.head, self.channel, self.snk_tx)


        # Design the channlizer
        self._M = 10
        bw = chspacing/2.0
        t_bw = chspacing/10.0
        self._chan_rate = self._if_rate / self._M
        self._taps = gr.firdes.low_pass_2(1, self._if_rate, bw, t_bw,
                                          attenuation_dB=100,
                                          window=gr.firdes.WIN_BLACKMAN_hARRIS)
        tpc = math.ceil(float(len(self._taps)) /  float(self._M))

        print "Number of taps:     ", len(self._taps)
        print "Number of channels: ", self._M
        print "Taps per channel:   ", tpc

        self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)

        self.connect(self.channel, self.pfb)

        # Create a file sink for each of M output channels of the filter and connect it
        self.fmdet = list()
        self.squelch = list()
        self.snks = list()
        for i in xrange(self._M):
            self.fmdet.append(blks2.nbfm_rx(self._audio_rate, self._chan_rate))
            self.squelch.append(blks2.standard_squelch(self._audio_rate*10))
            self.snks.append(gr.vector_sink_f())
            self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
Exemplo n.º 39
0
    def __init__(self):
        gr.flow_graph.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-T",
            "--tx-subdev-spec",
            type="subdev",
            default=None,
            help=
            "select USRP Tx side A or B (default=first one with a daughterboard)"
        )
        parser.add_option("-c",
                          "--cordic-freq",
                          type="eng_float",
                          default=434845200,
                          help="set Tx cordic frequency to FREQ",
                          metavar="FREQ")

        (options, args) = parser.parse_args()
        print "cordic_freq = %s" % (eng_notation.num_to_str(
            options.cordic_freq))

        self.normal_gain = 8000
        self.u = usrp.sink_s()
        dac_rate = self.u.dac_rate()
        self._freq = 1000
        self._spb = 256
        self._interp = int(128e6 / self._spb / self._freq)
        self.fs = 128e6 / self._interp
        print "Interpolation:", self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(
            usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq)

        self.sin = gr.sig_source_f(self.fs, gr.GR_SIN_WAVE, self._freq, 1, 0)
        self.gain = gr.multiply_const_ff(self.normal_gain)
        self.ftos = gr.float_to_short()

        self.filesink = gr.file_sink(gr.sizeof_float, 'sin.dat')

        self.connect(self.sin, self.gain)
        self.connect(self.gain, self.ftos, self.u)
        #self.connect(self.gain, self.filesink)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Exemplo n.º 40
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        
        src1 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src  = gr.add_ff()
        thr = gr.throttle(gr.sizeof_float, 100*fftsize)
        noise = gr.noise_source_f(gr.GR_GAUSSIAN, 0.001)
        add = gr.add_ff()
        self.snk1 = qtgui.sink_f(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                 0, Rs,
                                 "Float Signal Example",
                                 True, True, True, False)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, self.snk1)

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)

        self.main_box.show()
Exemplo n.º 41
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        
        src1 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_f(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src  = gr.add_ff()
        thr = gr.throttle(gr.sizeof_float, 100*fftsize)
        noise = gr.noise_source_f(gr.GR_GAUSSIAN, 0.001)
        add = gr.add_ff()
        self.snk1 = qtgui.sink_f(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                 0, Rs,
                                 "Float Signal Example",
                                 True, True, True, False)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, self.snk1)

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)

        self.main_box.show()
Exemplo n.º 42
0
 def test_const_f (self):
     tb = self.tb
     expected_result = (1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5)
     src1 = gr.sig_source_f (1e6, gr.GR_CONST_WAVE, 0, 1.5)
     op = gr.head (gr.sizeof_float, 10)
     dst1 = gr.vector_sink_f ()
     tb.connect (src1, op)
     tb.connect (op, dst1)
     tb.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
Exemplo n.º 43
0
 def test_saw_f (self):
     tb = self.tb
     expected_result = (.5, .625, .75, .875, 0, .125, .25, .375, .5)
     src1 = gr.sig_source_f (8, gr.GR_SAW_WAVE, 1.0, 1.0)
     op = gr.head (gr.sizeof_float, 9)
     dst1 = gr.vector_sink_f ()
     tb.connect (src1, op)
     tb.connect (op, dst1)
     tb.run ()
     dst_data = dst1.data ()
     self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
Exemplo n.º 44
0
    def __init__(self):
        gr.flow_graph.__init__(self)

        #build flow graph
        #create two sinusoidal sources with a sample rate
        # of 48000s/s and frequencies of 350 and 440
        #amplitude of 0.1
        src0 = gr.sig_source_f(48000, gr.GR_SIN_WAVE, 350, 0.1)
        src1 = gr.sig_source_f(48000, gr.GR_SIN_WAVE, 440, 0.1)

        #create a destination sink
        dst = audio.sink(48000)

        #connect each of the sources to the sink
        self.connect(src0, (dst, 0))
        self.connect(src1, (dst, 1))

        #puts 350 Hz into a data file
        fs = gr.file_sink(gr.sizeof_float, "audio.dat")
        self.connect(src0, fs)
 def test_sqr_f (self):
     fg = self.fg
     expected_result = (0, 0, 0, 0, 1, 1, 1, 1, 0)
     src1 = gr.sig_source_f (8, gr.GR_SQR_WAVE, 1.0, 1.0)
     op = gr.head (gr.sizeof_float, 9)
     dst1 = gr.vector_sink_f ()
     fg.connect (src1, op)
     fg.connect (op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
 def test_saw_f (self):
     fg = self.fg
     expected_result = (.5, .625, .75, .875, 0, .125, .25, .375, .5)
     src1 = gr.sig_source_f (8, gr.GR_SAW_WAVE, 1.0, 1.0)
     op = gr.head (gr.sizeof_float, 9)
     dst1 = gr.vector_sink_f ()
     fg.connect (src1, op)
     fg.connect (op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
 def test_const_f (self):
     fg = self.fg
     expected_result = (1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5)
     src1 = gr.sig_source_f (1e6, gr.GR_CONST_WAVE, 0, 1.5)
     op = gr.head (gr.sizeof_float, 10)
     dst1 = gr.vector_sink_f ()
     fg.connect (src1, op)
     fg.connect (op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
Exemplo n.º 48
0
 def test_sqr_f (self):
     tb = self.tb
     expected_result = (0, 0, 0, 0, 1, 1, 1, 1, 0)
     src1 = gr.sig_source_f (8, gr.GR_SQR_WAVE, 1.0, 1.0)
     op = gr.head (gr.sizeof_float, 9)
     dst1 = gr.vector_sink_f ()
     tb.connect (src1, op)
     tb.connect (op, dst1)
     tb.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
Exemplo n.º 49
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._N = 200000  # number of samples to use
        self._fs = 9000  # initial sampling rate
        self._M = 9  # Number of channels to channelize

        # Create a set of taps for the PFB channelizer
        self._taps = gr.firdes.low_pass_2(1,
                                          self._fs,
                                          500,
                                          20,
                                          attenuation_dB=10,
                                          window=gr.firdes.WIN_BLACKMAN_hARRIS)

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

        repeated = True
        if (repeated):
            self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25,
                                             110)
        else:
            amp = 100
            data = scipy.arange(0, amp, amp / float(self._N))
            self.vco_input = gr.vector_source_f(data, False)

        # Build a VCO controlled by either the sinusoid or single chirp tone
        # Then convert this to a complex signal
        self.vco = gr.vco_f(self._fs, 225, 1)
        self.f2c = gr.float_to_complex()

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

        # Construct the channelizer filter
        self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)

        # Construct a vector sink for the input signal to the channelizer
        self.snk_i = gr.vector_sink_c()

        # Connect the blocks
        self.connect(self.vco_input, self.vco, self.f2c)
        self.connect(self.f2c, self.head, self.pfb)
        self.connect(self.f2c, self.snk_i)

        # Create a vector sink for each of M output channels of the filter and connect it
        self.snks = list()
        for i in xrange(self._M):
            self.snks.append(gr.vector_sink_c())
            self.connect((self.pfb, i), self.snks[i])
Exemplo n.º 50
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 2048.0e3

        #Generate some noise
        noise = gr.noise_source_c(gr.GR_UNIFORM, 1.0 / 10)

        # Generate a complex sinusoid
        #src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fft_sink_c(panel,
                           title="Complex Data",
                           fft_size=fft_size,
                           sample_rate=input_rate,
                           baseband_freq=100e3,
                           ref_level=0,
                           y_per_div=20,
                           y_divs=10)
        vbox.Add(sink1.win, 1, wx.EXPAND)

        combine1 = gr.add_cc()
        self.connect(src1, (combine1, 0))
        self.connect(noise, (combine1, 1))
        self.connect(combine1, thr1, sink1)

        #src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        src2 = gr.sig_source_f(input_rate, gr.GR_CONST_WAVE, 57.50e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = fft_sink_f(panel,
                           title="Real Data",
                           fft_size=fft_size * 2,
                           sample_rate=input_rate,
                           baseband_freq=100e3,
                           ref_level=0,
                           y_per_div=20,
                           y_divs=10)
        vbox.Add(sink2.win, 1, wx.EXPAND)

        combine2 = gr.add_ff()
        c2f2 = gr.complex_to_float()

        self.connect(src2, (combine2, 0))
        self.connect(noise, c2f2, (combine2, 1))
        self.connect(combine2, thr2, sink2)
Exemplo n.º 51
0
 def test_cosine_f (self):
     tb = self.tb
     sqrt2 = math.sqrt(2) / 2
     expected_result = (1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0, sqrt2, 1)
     src1 = gr.sig_source_f (8, gr.GR_COS_WAVE, 1.0, 1.0)
     op = gr.head (gr.sizeof_float, 9)
     dst1 = gr.vector_sink_f ()
     tb.connect (src1, op)
     tb.connect (op, dst1)
     tb.run ()
     dst_data = dst1.data ()
     self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
Exemplo n.º 52
0
    def __init__(self, step_size, H_Off, W_Off):
        gr.hier_block2.__init__(self, "HierBlock",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(1, 2, gr.sizeof_float))

        # constant_block initialized
        self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 1)
        # step_source block initialized
        self.step_source = gr_step_source.step()
        self.step_source.set_parameters(step_size, H_Off, W_Off)
        self.connect(self, (self.constant_block, 0), (self.step_source, 0),
                     self)
Exemplo n.º 53
0
 def __init__(self, ramp_slope, height_Offset, width_Offset):
     gr.hier_block2.__init__(self, "HierBlock",
                             gr.io_signature(1, 1, gr.sizeof_float),
                             gr.io_signature(1, 2, gr.sizeof_float))
     #constant_block initialized
     self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 1)
     #ramp_source block initialized
     self.ramp_source = gr_ramp_source.ramp()
     self.ramp_source.set_parameters(ramp_slope, height_Offset,
                                     width_Offset)
     self.connect(self, (self.constant_block, 0), (self.ramp_source, 0),
                  self)
Exemplo n.º 54
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        # build our flow graph
        input_rate = 20.48e3

        src2 = gr.sig_source_f(input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = histo_sink_f(panel, title="Data", num_bins=31, frame_size=1000)
        vbox.Add(sink2.win, 1, wx.EXPAND)

        self.connect(src2, thr2, sink2)
Exemplo n.º 55
0
    def __init__(self, seconds,history,output_multiple):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (48000)")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)

        nsamples=int(sample_rate * seconds) #1 seconds
        # gr.test (const std::string &name=std::string("gr_test"),
        # int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1,
        # int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1,
        # unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
        # bool fixed_rate=true,gr_consume_type_t cons_type=CONSUME_NOUTPUT_ITEMS, gr_produce_type_t prod_type=PRODUCE_NOUTPUT_ITEMS);
        name="gr_test"
        min_inputs=1
        max_inputs=1
        sizeof_input_item=gr.sizeof_float
        min_outputs=1
        max_outputs=1
        sizeof_output_item=gr.sizeof_float
        #history=1 # problems start at 8150
        #output_multiple=1 #problems start at 8000 in combination with large history
        relative_rate=1.0
        fixed_rate=True
        consume_type=gr.CONSUME_NOUTPUT_ITEMS
        produce_type=gr.PRODUCE_NOUTPUT_ITEMS
        test = gr.test(name, min_inputs,max_inputs,sizeof_input_item,
                                 min_outputs,max_outputs,sizeof_output_item,
                                 history,output_multiple,relative_rate,
                                 fixed_rate, consume_type,produce_type)
        #test = gr.test("gr_test",1,1,gr.sizeof_float,
        #                         1,1,gr.sizeof_float,
        #                         1,1,1.0,
        #                         True, gr.CONSUME_NOUTPUT_ITEMS,gr.PRODUCE_NOUTPUT_ITEMS)
        #unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
        #bool fixed_rate=false
        dst = audio.sink (sample_rate, options.audio_output)
        head= gr.head(gr.sizeof_float, nsamples)

        self.connect (src0,test,head,(dst, 0))
Exemplo n.º 56
0
def key_factory(index):
    print "FACTORY CALLED index = %d"%(index);
    r = es.es_pyhandler();
    src_L = gr.sig_source_f( 48e3, gr.GR_SIN_WAVE, 1440.0, 1.0, 0 );
    src_R = gr.sig_source_f( 48e3, gr.GR_SIN_WAVE, 480.0, 1.0, 0 );
    head_L = gr.head( gr.sizeof_float, evt_len );
    head_R = gr.head( gr.sizeof_float, evt_len );

    r.sink = es.vector_sink([gr.sizeof_float, gr.sizeof_float]);
    tb  = gr.top_block();
    tb.connect( (src_L,0), (head_L,0), (r.sink,0) );
    tb.connect( (src_R,0), (head_R,0), (r.sink,1) );

    # store blocks where we can get to them
    blocks = {};
    blocks["src_L"] = src_L;
    blocks["src_R"] = src_R;
    blocks["head_L"] = head_L;
    blocks["head_R"] = head_R;
    r.set_pyb2(blocks);
    
    r.tb = tb.to_top_block();
    return r;