#!/usr/bin/env python #narrow band FM receiver - requires usrp board as input from gnuradio import gr,audio, eng_notation,usrp, optfir,blks from gnuradio.eng_option import eng_option from optparse import OptionParser from gnuradio.blks import fm_demod_cf class my_graph(gr.flow_graph): def __init__(self,frequency): gr.flow_graph.__init__(self) #Put flow graph stuff here #Create USRP data source u = usrp.source_c(decim_rate=250) #Tell USRP what daughter board to use and displays name #(0,0) means side A, 1st channel - picks daughterboard rx_subdev_spec = (0,0) u.set_mux(usrp.determine_rx_mux_value(u,rx_subdev_spec)) subdev = usrp.selected_subdev(u,rx_subdev_spec) print "Using daughterboard",subdev.name() #Tune it to supplied frequency u.tune(0,subdev,frequency) #creates a file to contain the usrp data and connects it #to usrp usrp_sink = gr.file_sink(gr.sizeof_gr_complex,"usrp.dat") self.connect(u,usrp_sink) #create the channel filter coefficients chan_taps = optfir.low_pass( 1.0, #Filter gain 256e3, #Sample Rate 8000, #one sided modulation BW (edge of passband) 9000, #one sided channel BW (edge of stopband) 0.1, #Passband ripple 60) #Stopband Attenuation print "Channel filter taps:", len(chan_taps) #creates the channel filter with the coef found above #offset adjusted for Sharlene's USRP chan = gr.freq_xlating_fir_filter_ccf( 8, #Decimation rate chan_taps, #coefficients -5000, #Offset frequency - could be used to shift 256e3) #incoming sample rate #creates a file for the output of the channel filter chan_sink = gr.file_sink(gr.sizeof_gr_complex,"chan.dat") self.connect(chan,chan_sink) #connect the usrp output to the channel filter input self.connect(u,chan) #create the FM demodulator demod = fm_demod_cf(self, 32e3, #Sample Rate at input 1, #Decimation 5000,#Deviation 3000, #edge of audio passband 4000) #edge of audio stopband #NOte: a decimation factor of 4 would have been used above #to reduce the sample rate to 8Ks/s - but audio board requires #at least 44.1Ks/s so 1 was used and resampler below was #added #add file to collect output of demodulator demod_sink = gr.file_sink(gr.sizeof_float,"demod.dat") self.connect(demod,demod_sink) #connect channel filter to demodulator self.connect(chan,demod) spkr = audio.sink(48000) #insert resampler to increase sample rate of 32K to 48K # mult by 3 and divide by 2 rsamp = blks.rational_resampler_fff(self,3,2) #add file to collect output of resampler rsamp_sink = gr.file_sink(gr.sizeof_float,"rsamp.dat") self.connect(rsamp,rsamp_sink) #connect demod to resampler and resampler to speaker self.connect(demod,rsamp) self.connect(rsamp,spkr) #The main function def main(): parser = OptionParser(option_class=eng_option) parser.add_option("-f","--freq",type="eng_float",default=350, help="set frequency to FREQ", metavar="FREQ") (options,args) = parser.parse_args() print "User defined frequency", options.freq fg = my_graph(options.freq) try: fg.run() except KeyboardInterrupt: pass main()