예제 #1
0
    def __init__(self, filename, lo_freq, audio_rate, if_rate):

        gr.hier_block2.__init__(self, "pipeline",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        try:
            src = gr.file_source (gr.sizeof_float, filename, True)
        except RuntimeError:
            sys.stderr.write(("\nError: Could not open file '%s'\n\n" % \
                                  filename))
            sys.exit(1)

        print audio_rate, if_rate
        fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6)

        # Local oscillator
        lo = gr.sig_source_c (if_rate,        # sample rate
                              gr.GR_SIN_WAVE, # waveform type
                              lo_freq,        #frequency
                              1.0,            # amplitude
                              0)              # DC Offset
        mixer = gr.multiply_cc ()

        self.connect (src, fmtx, (mixer, 0))
        self.connect (lo, (mixer, 1))
        self.connect (mixer, self)
예제 #2
0
    def __init__(self, filename, lo_freq, audio_rate, if_rate):

        gr.hier_block2.__init__(self, "pipeline",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        try:
            src = gr.file_source (gr.sizeof_float, filename, True)
        except RuntimeError:
            sys.stderr.write(("\nError: Could not open file '%s'\n\n" % \
                                  filename))
            sys.exit(1)
            
        print audio_rate, if_rate
        fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6)
        
        # Local oscillator
        lo = gr.sig_source_c (if_rate,        # sample rate
                              gr.GR_SIN_WAVE, # waveform type
                              lo_freq,        #frequency
                              1.0,            # amplitude
                              0)              # DC Offset
        mixer = gr.multiply_cc ()
    
        self.connect (src, fmtx, (mixer, 0))
        self.connect (lo, (mixer, 1))
        self.connect (mixer, self)
예제 #3
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self,
            "transmit_path",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt,
                     (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
예제 #4
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)  # Input signature
        )  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
예제 #5
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 500e3

        ##################################################
        # Blocks
        ##################################################
        self.blks2_nbfm_tx_0 = blks2.nbfm_tx(
            audio_rate=25000,
            quad_rate=100000,
            tau=75e-6,
            max_dev=5e3,
        )
        self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc(
            interpolation=5,
            decimation=1,
            taps=None,
            fractional_bw=None,
        )
        self.gr_multiply_xx_0 = gr.multiply_vcc(1)
        self.gr_sig_source_x_0 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,
                                                 6.9e3, 1, 0)
        self.gr_wavfile_source_0 = gr.wavfile_source("classical.wav", True)
        self.uhd_single_usrp_sink_0 = uhd.single_usrp_sink(
            device_addr="addr=192.168.10.2",
            io_type=uhd.io_type.COMPLEX_FLOAT32,
            num_channels=1,
        )
        self.uhd_single_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_single_usrp_sink_0.set_center_freq(462.5625e6, 0)
        self.uhd_single_usrp_sink_0.set_gain(30, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_wavfile_source_0, 0), (self.blks2_nbfm_tx_0, 0))
        self.connect((self.blks2_nbfm_tx_0, 0),
                     (self.blks2_rational_resampler_xxx_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.gr_multiply_xx_0, 0))
        self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 1))
        self.connect((self.gr_multiply_xx_0, 0),
                     (self.uhd_single_usrp_sink_0, 0))
예제 #6
0
    def __init__(self, lo_freq, audio_rate, if_rate):

        gr.hier_block2.__init__(self, "build_fm",
                                gr.io_signature(1, 1, gr.sizeof_float),      # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

        fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6)

        # Local oscillator
        lo = gr.sig_source_c (if_rate,        # sample rate
                              gr.GR_SIN_WAVE, # waveform type
                              lo_freq,        #frequency
                              1.0,            # amplitude
                              0)              # DC Offset
        mixer = gr.multiply_cc ()

        self.connect (self, fmtx, (mixer, 0))
        self.connect (lo, (mixer, 1))
        self.connect (mixer, self)
예제 #7
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 500e3

		##################################################
		# Blocks
		##################################################
		self.blks2_nbfm_tx_0 = blks2.nbfm_tx(
			audio_rate=25000,
			quad_rate=100000,
			tau=75e-6,
			max_dev=5e3,
		)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc(
			interpolation=5,
			decimation=1,
			taps=None,
			fractional_bw=None,
		)
		self.gr_multiply_xx_0 = gr.multiply_vcc(1)
		self.gr_sig_source_x_0 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 6.9e3, 1, 0)
		self.gr_wavfile_source_0 = gr.wavfile_source("classical.wav", True)
		self.uhd_single_usrp_sink_0 = uhd.single_usrp_sink(
			device_addr="addr=192.168.10.2",
			io_type=uhd.io_type.COMPLEX_FLOAT32,
			num_channels=1,
		)
		self.uhd_single_usrp_sink_0.set_samp_rate(samp_rate)
		self.uhd_single_usrp_sink_0.set_center_freq(462.5625e6, 0)
		self.uhd_single_usrp_sink_0.set_gain(30, 0)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_wavfile_source_0, 0), (self.blks2_nbfm_tx_0, 0))
		self.connect((self.blks2_nbfm_tx_0, 0), (self.blks2_rational_resampler_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_xx_0, 0))
		self.connect((self.gr_sig_source_x_0, 0), (self.gr_multiply_xx_0, 1))
		self.connect((self.gr_multiply_xx_0, 0), (self.uhd_single_usrp_sink_0, 0))
예제 #8
0
파일: fmtest.py 프로젝트: pgoeser/gnuradio
    def __init__(self, lo_freq, audio_rate, if_rate):

        gr.hier_block2.__init__(self, "build_fm",
                                gr.io_signature(1, 1, gr.sizeof_float),      # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

        fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6)
        
        # Local oscillator
        lo = gr.sig_source_c (if_rate,        # sample rate
                              gr.GR_SIN_WAVE, # waveform type
                              lo_freq,        #frequency
                              1.0,            # amplitude
                              0)              # DC Offset
        mixer = gr.multiply_cc ()
    
        self.connect (self, fmtx, (mixer, 0))
        self.connect (lo, (mixer, 1))
        self.connect (mixer, self)
예제 #9
0
    def __init__(self, args, spec, antenna, gain, audio_input):
	gr.hier_block2.__init__(self, "transmit_path",
				gr.io_signature(0, 0, 0), # Input signature
				gr.io_signature(0, 0, 0)) # Output signature

        self.u = uhd.usrp_sink(device_addr=args, stream_args=uhd.stream_args('fc32'))

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

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

        self.if_rate = 320e3
        self.audio_rate = 32e3

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

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass (1,                  # gain
                                  self.audio_rate,    # sampling rate
                                  3800,               # low pass cutoff freq
                                  300,                # width of trans. band
                                  gr.firdes.WIN_HANN) # filter type

        hpf = gr.firdes.high_pass (1,                 # gain
                                  self.audio_rate,    # sampling rate
                                  325,                # low pass cutoff freq
                                  50,                 # width of trans. band
                                  gr.firdes.WIN_HANN) # filter type

        audio_taps = convolve(array(lpf),array(hpf))
        self.audio_filt = gr.fir_filter_fff(1,audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate,123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl,(self.add_pl,1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc (self.normal_gain)

        rrate = dev_rate / self.if_rate
        self.resamp = blks2.pfb_arb_resampler_ccf(rrate)

        self.connect(self.audio, self.audio_amp, self.audio_filt,
                     (self.add_pl,0), self.fmtx, self.amp,
                     self.resamp, self.u)

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

        self.set_gain(gain)

        self.set_enable(False)
예제 #10
0
def main():
    N = 1000000
    fs = 8000

    freqs = [100, 200, 300, 400, 500]
    nchans = 7

    sigs = list()
    fmtx = list()
    for fi in freqs:
        s = gr.sig_source_f(fs, gr.GR_SIN_WAVE, fi, 1)
        fm = blks2.nbfm_tx (fs, 4*fs, max_dev=10000, tau=75e-6)
        sigs.append(s)
        fmtx.append(fm)

    syntaps = gr.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100)
    print "Synthesis Num. Taps = %d (taps per filter = %d)" % (len(syntaps),
                                                               len(syntaps)/nchans)
    chtaps = gr.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100)
    print "Channelizer Num. Taps = %d (taps per filter = %d)" % (len(chtaps),
                                                                 len(chtaps)/nchans)
    filtbank = gr.pfb_synthesizer_ccf(nchans, syntaps)
    channelizer = blks2.pfb_channelizer_ccf(nchans, chtaps)

    noise_level = 0.01
    head = gr.head(gr.sizeof_gr_complex, N)
    noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level)
    addnoise = gr.add_cc()
    snk_synth = gr.vector_sink_c()

    tb = gr.top_block()

    tb.connect(noise, (addnoise,0))
    tb.connect(filtbank, head, (addnoise, 1))
    tb.connect(addnoise, channelizer)
    tb.connect(addnoise, snk_synth)

    snk = list()
    for i,si in enumerate(sigs):
        tb.connect(si, fmtx[i], (filtbank, i))

    for i in xrange(nchans):
        snk.append(gr.vector_sink_c())
        tb.connect((channelizer, i), snk[i])

    tb.run()

    if 1:
        channel = 1
        data = snk[channel].data()[1000:]

        f1 = pylab.figure(1)
        s1 = f1.add_subplot(1,1,1)
        s1.plot(data[10000:10200] )
        s1.set_title(("Output Signal from Channel %d" % channel))

        fftlen = 2048
        winfunc = scipy.blackman
        #winfunc = scipy.hamming

        f2 = pylab.figure(2)
        s2 = f2.add_subplot(1,1,1)
        s2.psd(data, NFFT=fftlen,
               Fs = nchans*fs,
               noverlap=fftlen/4,
               window = lambda d: d*winfunc(fftlen))
        s2.set_title(("Output PSD from Channel %d" % channel))

        f3 = pylab.figure(3)
        s3 = f3.add_subplot(1,1,1)
        s3.psd(snk_synth.data()[1000:], NFFT=fftlen,
               Fs = nchans*fs,
               noverlap=fftlen/4,
               window = lambda d: d*winfunc(fftlen))
        s3.set_title("Output of Synthesis Filter")

        pylab.show()