diff options
Diffstat (limited to 'docs/exploring-gnuradio')
-rwxr-xr-x | docs/exploring-gnuradio/dial_tone.py | 25 | ||||
-rw-r--r-- | docs/exploring-gnuradio/dial_tone_example.xml | 21 | ||||
-rw-r--r-- | docs/exploring-gnuradio/exploring-gnuradio.xml | 2 | ||||
-rwxr-xr-x | docs/exploring-gnuradio/fm_demod.py | 115 | ||||
-rw-r--r-- | docs/exploring-gnuradio/fm_demod_example.xml | 72 |
5 files changed, 120 insertions, 115 deletions
diff --git a/docs/exploring-gnuradio/dial_tone.py b/docs/exploring-gnuradio/dial_tone.py index cabfa0864d..ba43c43bfc 100755 --- a/docs/exploring-gnuradio/dial_tone.py +++ b/docs/exploring-gnuradio/dial_tone.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2004,2007 Free Software Foundation, Inc. +# Copyright 2004,2007,2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -22,22 +22,23 @@ from gnuradio import gr from gnuradio import audio +from gnuradio import analog -def build_graph (): +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)) + tb = gr.top_block() + src0 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, 350, ampl) + src1 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, 440, ampl) + dst = audio.sink(sampling_freq) + tb.connect(src0, (dst, 0)) + tb.connect(src1, (dst, 1)) return tb if __name__ == '__main__': - tb = build_graph () - tb.start () - raw_input ('Press Enter to quit: ') - tb.stop () + tb = build_graph() + tb.start() + raw_input('Press Enter to quit: ') + tb.stop() diff --git a/docs/exploring-gnuradio/dial_tone_example.xml b/docs/exploring-gnuradio/dial_tone_example.xml index 14ea68039e..5d193df776 100644 --- a/docs/exploring-gnuradio/dial_tone_example.xml +++ b/docs/exploring-gnuradio/dial_tone_example.xml @@ -5,24 +5,25 @@ from gnuradio import gr from gnuradio import audio +from gnuradio import analog def build_graph (): sampling_freq = 48000 ampl = 0.1 - fg = gr.flow_graph () - 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)) + fg = gr.flow_graph() + src0 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, 350, ampl) + src1 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, 440, ampl) + dst = audio.sink(sampling_freq) + fg.connect((src0, 0), (dst, 0)) + fg.connect((src1, 0), (dst, 1)) return fg if __name__ == '__main__': - fg = build_graph () - fg.start () - raw_input ('Press Enter to quit: ') - fg.stop () + fg = build_graph() + fg.start() + raw_input('Press Enter to quit: ') + fg.stop() </programlisting> </example> diff --git a/docs/exploring-gnuradio/exploring-gnuradio.xml b/docs/exploring-gnuradio/exploring-gnuradio.xml index 286ca86095..5b70d4d0bf 100644 --- a/docs/exploring-gnuradio/exploring-gnuradio.xml +++ b/docs/exploring-gnuradio/exploring-gnuradio.xml @@ -180,7 +180,7 @@ right.</para> <para>We start by creating a flow graph to hold the blocks and connections between them. The two sine waves are generated by the -gr.sig_source_f calls. The f suffix indicates that the source produces +analog.sig_source_f calls. The f suffix indicates that the source produces floats. One sine wave is at 350 Hz, and the other is at 440 Hz. Together, they sound like the US dial tone.</para> diff --git a/docs/exploring-gnuradio/fm_demod.py b/docs/exploring-gnuradio/fm_demod.py index 0071fd751e..7b19cd826a 100755 --- a/docs/exploring-gnuradio/fm_demod.py +++ b/docs/exploring-gnuradio/fm_demod.py @@ -1,18 +1,19 @@ #!/usr/bin/env python from gnuradio import gr +from gnuradio import analog from gnuradio import audio from gnuradio import mc4020 import sys -def high_speed_adc (fg, input_rate): +def high_speed_adc(fg, input_rate): # return gr.file_source (gr.sizeof_short, "dummy.dat", False) - return mc4020.source (input_rate, mc4020.MCC_CH3_EN | mc4020.MCC_ALL_1V) + return mc4020.source(input_rate, mc4020.MCC_CH3_EN | mc4020.MCC_ALL_1V) # # return a gr.flow_graph # -def build_graph (freq1, freq2): +def build_graph(freq1, freq2): input_rate = 20e6 cfir_decimation = 125 audio_decimation = 5 @@ -20,35 +21,35 @@ def build_graph (freq1, freq2): quad_rate = input_rate / cfir_decimation audio_rate = quad_rate / audio_decimation - fg = gr.flow_graph () + fg = gr.flow_graph() # use high speed ADC as input source - src = high_speed_adc (fg, input_rate) + src = high_speed_adc(fg, input_rate) # compute FIR filter taps for channel selection channel_coeffs = \ - gr.firdes.low_pass (1.0, # gain - input_rate, # sampling rate - 250e3, # low pass cutoff freq - 8*100e3, # width of trans. band - gr.firdes.WIN_HAMMING) + filter.firdes.low_pass(1.0, # gain + input_rate, # sampling rate + 250e3, # low pass cutoff freq + 8*100e3, # width of trans. band + filter.firdes.WIN_HAMMING) # input: short; output: complex chan_filter1 = \ - gr.freq_xlating_fir_filter_scf (cfir_decimation, - channel_coeffs, - freq1, # 1st station freq - input_rate) + filter.freq_xlating_fir_filter_scf(cfir_decimation, + channel_coeffs, + freq1, # 1st station freq + input_rate) - (head1, tail1) = build_pipeline (fg, quad_rate, audio_decimation) + (head1, tail1) = build_pipeline(fg, quad_rate, audio_decimation) # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) + audio_sink = audio.sink(int (audio_rate)) # now wire it all together - fg.connect (src, chan_filter1) - fg.connect (chan_filter1, head1) - fg.connect (tail1, (audio_sink, 0)) + fg.connect(src, chan_filter1) + fg.connect(chan_filter1, head1) + fg.connect(tail1, (audio_sink, 0)) # two stations at once? if freq2: @@ -57,20 +58,20 @@ def build_graph (freq1, freq2): # input: short; output: complex chan_filter2 = \ - gr.freq_xlating_fir_filter_scf (cfir_decimation, - channel_coeffs, - freq2, # 2nd station freq - input_rate) + filter.freq_xlating_fir_filter_scf(cfir_decimation, + channel_coeffs, + freq2, # 2nd station freq + input_rate) - (head2, tail2) = build_pipeline (fg, quad_rate, audio_decimation) + (head2, tail2) = build_pipeline(fg, quad_rate, audio_decimation) - fg.connect (src, chan_filter2) - fg.connect (chan_filter2, head2) - fg.connect (tail2, (audio_sink, 1)) + fg.connect(src, chan_filter2) + fg.connect(chan_filter2, head2) + fg.connect(tail2, (audio_sink, 1)) return fg -def build_pipeline (fg, quad_rate, audio_decimation): +def build_pipeline(fg, quad_rate, audio_decimation): '''Given a flow_graph, fg, construct a pipeline for demodulating a broadcast FM signal. The input is the downconverteed complex baseband @@ -84,67 +85,67 @@ def build_pipeline (fg, quad_rate, audio_decimation): volume = 1.0 # input: complex; output: float - fm_demod = gr.quadrature_demod_cf (volume*fm_demod_gain) + fm_demod = analog.quadrature_demod_cf(volume*fm_demod_gain) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0, # gain - quad_rate, # sampling rate - audio_rate/2 - width_of_transition_band, - width_of_transition_band, - gr.firdes.WIN_HAMMING) + audio_coeffs = filter.firdes.low_pass(1.0, # gain + quad_rate, # sampling rate + audio_rate/2 - width_of_transition_band, + width_of_transition_band, + filter.firdes.WIN_HAMMING) # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) + audio_filter = filter.fir_filter_fff(audio_decimation, audiocoeffs) - fg.connect (fm_demod, audio_filter) + fg.connect(fm_demod, audio_filter) return ((fm_demod, 0), (audio_filter, 0)) -def main (args): - nargs = len (args) +def main(args): + nargs = len(args) if nargs == 1: - freq1 = float (args[0]) * 1e6 + freq1 = float(args[0]) * 1e6 freq2 = None elif nargs == 2: - freq1 = float (args[0]) * 1e6 - freq2 = float (args[1]) * 1e6 + freq1 = float(args[0]) * 1e6 + freq2 = float(args[1]) * 1e6 else: - sys.stderr.write ('usage: fm_demod freq1 [freq2]\n') - sys.exit (1) + sys.stderr.write('usage: fm_demod freq1 [freq2]\n') + sys.exit(1) # connect to RF front end - rf_front_end = gr.microtune_4937_eval_board () - if not rf_front_end.board_present_p (): + rf_front_end = gr.microtune_4937_eval_board() + if not rf_front_end.board_present_p(): raise IOError, 'RF front end not found' # set front end gain - rf_front_end.set_AGC (300) - IF_freq = rf_front_end.get_output_freq () + rf_front_end.set_AGC(300) + IF_freq = rf_front_end.get_output_freq() IF_freq = 5.75e6 if not freq2: # one station - rf_front_end.set_RF_freq (freq1) - fg = build_graph (IF_freq, None) + rf_front_end.set_RF_freq(freq1) + fg = build_graph(IF_freq, None) else: # two stations - if abs (freq1 - freq2) > 5.5e6: + if abs(freq1 - freq2) > 5.5e6: raise IOError, 'freqs too far apart' target_freq = (freq1 + freq2) / 2 - actual_freq = rf_front_end.set_RF_freq (target_freq) + actual_freq = rf_front_end.set_RF_freq(target_freq) #actual_freq = target_freq - fg = build_graph (IF_freq + freq1 - actual_freq, - IF_freq + freq2 - actual_freq) + fg = build_graph(IF_freq + freq1 - actual_freq, + IF_freq + freq2 - actual_freq) - fg.start () # fork thread(s) and return - raw_input ('Press Enter to quit: ') - fg.stop () + fg.start() # fork thread(s) and return + raw_input('Press Enter to quit: ') + fg.stop() if __name__ == '__main__': - main (sys.argv[1:]) + main(sys.argv[1:]) diff --git a/docs/exploring-gnuradio/fm_demod_example.xml b/docs/exploring-gnuradio/fm_demod_example.xml index b417da0a81..05c2ee163b 100644 --- a/docs/exploring-gnuradio/fm_demod_example.xml +++ b/docs/exploring-gnuradio/fm_demod_example.xml @@ -4,6 +4,8 @@ #!/usr/bin/env python from gnuradio import gr +from gnuradio import filter +from gnuradio import analog from gnuradio import audio from gnuradio import mc4020 import sys @@ -30,28 +32,28 @@ def build_graph (freq1, freq2): # compute FIR filter taps for channel selection channel_coeffs = \ - gr.firdes.low_pass (1.0, # gain - input_rate, # sampling rate - 250e3, # low pass cutoff freq - 8*100e3, # width of trans. band - gr.firdes.WIN_HAMMING) + filter.firdes.low_pass(1.0, # gain + input_rate, # sampling rate + 250e3, # low pass cutoff freq + 8*100e3, # width of trans. band + filter.firdes.WIN_HAMMING) # input: short; output: complex chan_filter1 = \ - gr.freq_xlating_fir_filter_scf (cfir_decimation, - channel_coeffs, - freq1, # 1st station freq - input_rate) + filter.freq_xlating_fir_filter_scf(cfir_decimation, + channel_coeffs, + freq1, # 1st station freq + input_rate) - (head1, tail1) = build_pipeline (fg, quad_rate, audio_decimation) + (head1, tail1) = build_pipeline(fg, quad_rate, audio_decimation) # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) + audio_sink = audio.sink(int (audio_rate)) # now wire it all together - fg.connect (src, chan_filter1) - fg.connect (chan_filter1, head1) - fg.connect (tail1, (audio_sink, 0)) + fg.connect(src, chan_filter1) + fg.connect(chan_filter1, head1) + fg.connect(tail1, (audio_sink, 0)) return fg @@ -69,20 +71,20 @@ def build_pipeline (fg, quad_rate, audio_decimation): volume = 1.0 # input: complex; output: float - fm_demod = gr.quadrature_demod_cf (volume*fm_demod_gain) + fm_demod = analog.quadrature_demod_cf(volume*fm_demod_gain) # compute FIR filter taps for audio filter width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0, # gain - quad_rate, # sampling rate - audio_rate/2 - width_of_transition_band, - width_of_transition_band, - gr.firdes.WIN_HAMMING) + audio_coeffs = filter.firdes.low_pass(1.0, # gain + quad_rate, # sampling rate + audio_rate/2 - width_of_transition_band, + width_of_transition_band, + filter.firdes.WIN_HAMMING) # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) + audio_filter = filter.fir_filter_fff(audio_decimation, audio_coeffs) - fg.connect (fm_demod, audio_filter) + fg.connect(fm_demod, audio_filter) return ((fm_demod, 0), (audio_filter, 0)) @@ -90,34 +92,34 @@ def main (args): nargs = len (args) if nargs == 1: # get station frequency from command line - freq1 = float (args[0]) * 1e6 + freq1 = float(args[0]) * 1e6 else: - sys.stderr.write ('usage: fm_demod freq\n') - sys.exit (1) + sys.stderr.write('usage: fm_demod freq\n') + sys.exit(1) # connect to RF front end - rf_front_end = gr.microtune_4937_eval_board () - if not rf_front_end.board_present_p (): + rf_front_end = gr.microtune_4937_eval_board() + if not rf_front_end.board_present_p(): raise IOError, 'RF front end not found' # set front end gain - rf_front_end.set_AGC (300) + rf_front_end.set_AGC(300) # determine the front end's "Intermediate Frequency" - IF_freq = rf_front_end.get_output_freq () # 5.75e6 + IF_freq = rf_front_end.get_output_freq() # 5.75e6 # Tell the front end to tune to freq1. # I.e., freq1 is translated down to the IF frequency - rf_front_end.set_RF_freq (freq1) + rf_front_end.set_RF_freq(freq1) # build the flow graph - fg = build_graph (IF_freq, None) + fg = build_graph(IF_freq, None) - fg.start () # fork thread(s) and return - raw_input ('Press Enter to quit: ') - fg.stop () + fg.start() # fork thread(s) and return + raw_input('Press Enter to quit: ') + fg.stop() if __name__ == '__main__': - main (sys.argv[1:]) + main(sys.argv[1:]) </programlisting> </example> |