#!/usr/bin/env python from gnuradio import gr, eng_notation, blks from gnuradio import audio from gnuradio import usrp, optfir from gnuradio.eng_option import eng_option from optparse import OptionParser import sys import math from gnuradio.wxgui import stdgui, fftsink import wx class am_rx_graph (stdgui.gui_flow_graph): def __init__(self,frame,panel,vbox,argv): stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) # station is the frequency to be received station = parseargs(argv[1:]) adc_rate = 64e6 #output sample rate of the ADC, 64Ms/s usrp_decim = 250 usrp_rate = adc_rate /usrp_decim # output sample rate of the usrp, 256 ks/s lpf_decim = 4 lpf_rate = usrp_rate / lpf_decim # 64 kHz # usrp is data source # tells which usrp board is used and what the dec rate is src = usrp.source_c (0, usrp_decim) #Tell USRP what daughter board to use and displays name #(1,0) means side B, 1st channel - picks daughterboard rx_subdev_spec = (1,0) src.set_mux(usrp.determine_rx_mux_value(src,rx_subdev_spec)) subdev = usrp.selected_subdev(src,rx_subdev_spec) print "Using daughterboard",subdev.name() #sets the shift frequency of the ddc (on FPGA) src.set_rx_freq (0, station) # checks the actual shift frequency actual_shift_freq =src.rx_freq(0) print "Actual DDC shift frequency", actual_shift_freq # set gain on USRP src.set_pga(0,20) #defines a file to collect usrp output am_usrp_sink = gr.file_sink(gr.sizeof_gr_complex, "am_usrp.dat") self.connect(src, am_usrp_sink) # computes taps for LPF and creates channel filter with those taps channel_coeffs = optfir.low_pass ( 1.0, # gain usrp_rate, # sampling rate 4.5e3, # low pass cutoff freq 5e3, # width of trans. band 0.1, #passband ripple 60) #stopband attenuation chan_filter = gr.freq_xlating_fir_filter_ccf( lpf_decim,channel_coeffs, 0 ,usrp_rate) # define a file to collect channel filter output and connect chan_sink = gr.file_sink(gr.sizeof_gr_complex, "chan.dat") self.connect(chan_filter, chan_sink) # create a block to take the magnitude (envelope) of the AM Signal magblock = gr.complex_to_mag() # define and connect a sink of collect the output of the magnitude block mag_sink = gr.file_sink(gr.sizeof_float, "mag.dat") self.connect(magblock, mag_sink) #create a volume control and collect data into a file volumecontrol = gr.multiply_const_ff(.003) volcont_sink = gr.file_sink(gr.sizeof_float, "volcont.dat") self.connect(volumecontrol, volcont_sink) # compute FIR filter taps for audio filter audio_coeffs = optfir.low_pass ( 1.0, # gain lpf_rate, # sampling rate 4.5e3, # edge of passband 5e3, # edge of stopband, 0.1, #passband ripple 60) # stopband ripple # create audio filter and a file for its output audio_filter = gr.fir_filter_fff ( 1, audio_coeffs) audio_filt_sink = gr.file_sink(gr.sizeof_float, "audio_filt.dat") self.connect(audio_filter, audio_filt_sink) # create a resampler to bring 64ks/s rate to 48ks/s for audio card and data file rsamp=blks.rational_resampler_fff(self,3,4) rsamp_sink = gr.file_sink(gr.sizeof_float, "rsamp.dat") self.connect(rsamp, rsamp_sink) #create a sink representing the audio card audio_sink = audio.sink (int (48000)) # now wire it all together self.connect (src, chan_filter) self.connect (chan_filter, magblock) self.connect (magblock, volumecontrol) self.connect (volumecontrol,audio_filter) self.connect (audio_filter, rsamp) self.connect (rsamp, (audio_sink, 0)) if 1: pre_demod = fftsink.fft_sink_c (self, panel, title="Pre-Demodulation", fft_size=128, sample_rate=usrp_rate) self.connect (src, pre_demod) vbox.Add (pre_demod.win, 1, wx.EXPAND) if 1: post_demod = fftsink.fft_sink_c (self, panel, title="Post Channel Filter", fft_size=256, sample_rate=lpf_rate) self.connect (chan_filter, post_demod) vbox.Add (post_demod.win, 1, wx.EXPAND) if 1: post_filt = fftsink.fft_sink_f (self, panel, title="Post Envelope Detector", fft_size=512, sample_rate=lpf_rate) self.connect (magblock,post_filt) vbox.Add (post_filt.win, 1, wx.EXPAND) def parseargs (args): nargs = len (args) # multiplies the input frequency by 1000 to put in Hz if nargs == 1: freq1 = float (args[0]) * 1e3 else: sys.stderr.write ('usage: am_rcv freq1\n') sys.exit (1) return freq1 if __name__ == '__main__': app = stdgui.stdapp (am_rx_graph, "AM RX") app.MainLoop ()