1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <example id="fm_demod_ex"><title>Broadcast FM Receiver</title>
6 from gnuradio import gr
7 from gnuradio import audio
8 from gnuradio import mc4020
11 def high_speed_adc (fg, input_rate):
12 # return gr.file_source (gr.sizeof_short, "dummy.dat", False)
13 return mc4020.source (input_rate, mc4020.MCC_CH3_EN | mc4020.MCC_ALL_1V)
16 # return a gr.flow_graph
18 def build_graph (freq1, freq2):
23 quad_rate = input_rate / cfir_decimation
24 audio_rate = quad_rate / audio_decimation
28 # use high speed ADC as input source
29 src = high_speed_adc (fg, input_rate)
31 # compute FIR filter taps for channel selection
33 gr.firdes.low_pass (1.0, # gain
34 input_rate, # sampling rate
35 250e3, # low pass cutoff freq
36 8*100e3, # width of trans. band
37 gr.firdes.WIN_HAMMING)
39 # input: short; output: complex
41 gr.freq_xlating_fir_filter_scf (cfir_decimation,
43 freq1, # 1st station freq
46 (head1, tail1) = build_pipeline (fg, quad_rate, audio_decimation)
48 # sound card as final sink
49 audio_sink = audio.sink (int (audio_rate))
51 # now wire it all together
52 fg.connect (src, chan_filter1)
53 fg.connect (chan_filter1, head1)
54 fg.connect (tail1, (audio_sink, 0))
58 def build_pipeline (fg, quad_rate, audio_decimation):
59 '''Given a flow_graph, fg, construct a pipeline
60 for demodulating a broadcast FM signal. The
61 input is the downconverted complex baseband
62 signal. The output is the demodulated audio.
64 build_pipeline returns a two element tuple
65 containing the input and output endpoints.
67 fm_demod_gain = 2200.0/32768.0
68 audio_rate = quad_rate / audio_decimation
71 # input: complex; output: float
72 fm_demod = gr.quadrature_demod_cf (volume*fm_demod_gain)
74 # compute FIR filter taps for audio filter
75 width_of_transition_band = audio_rate / 32
76 audio_coeffs = gr.firdes.low_pass (1.0, # gain
77 quad_rate, # sampling rate
78 audio_rate/2 - width_of_transition_band,
79 width_of_transition_band,
80 gr.firdes.WIN_HAMMING)
82 # input: float; output: float
83 audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs)
85 fg.connect (fm_demod, audio_filter)
86 return ((fm_demod, 0), (audio_filter, 0))
92 # get station frequency from command line
93 freq1 = float (args[0]) * 1e6
95 sys.stderr.write ('usage: fm_demod freq\n')
98 # connect to RF front end
99 rf_front_end = gr.microtune_4937_eval_board ()
100 if not rf_front_end.board_present_p ():
101 raise IOError, 'RF front end not found'
104 rf_front_end.set_AGC (300)
106 # determine the front end's "Intermediate Frequency"
107 IF_freq = rf_front_end.get_output_freq () # 5.75e6
109 # Tell the front end to tune to freq1.
110 # I.e., freq1 is translated down to the IF frequency
111 rf_front_end.set_RF_freq (freq1)
113 # build the flow graph
114 fg = build_graph (IF_freq, None)
116 fg.start () # fork thread(s) and return
117 raw_input ('Press Enter to quit: ')
120 if __name__ == '__main__':