Houston, we have a trunk.
[debian/gnuradio] / gr-radar / src / python / gen_random_signal.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2005 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
21
22
23 from gnuradio import gr, gru, blks, eng_notation
24 from gnuradio import audio
25 from gnuradio.eng_option import eng_option
26 from optparse import OptionParser
27 import sys
28 import math
29
30
31 class my_graph(gr.flow_graph):
32     def __init__(self, output_filename, tx_gain, nsamples):
33         gr.flow_graph.__init__(self)
34         
35         audio_rate = 31250
36         baseband_rate = 250e3
37
38         src = gr.noise_source_c(gr.GR_GAUSSIAN, 1.0)
39         #src = gr.noise_source_f(gr.GR_GAUSSIAN, 0.5)
40         #guts = blks.wfm_tx(self, audio_rate, baseband_rate)
41         amp = gr.multiply_const_cc(tx_gain)
42         head = gr.head(gr.sizeof_gr_complex, nsamples)
43         sink = gr.file_sink(gr.sizeof_gr_complex, output_filename)
44         self.connect(src, amp, head, sink)
45
46 def main ():
47     usage = "usage: %prog [options] output_filename"
48     parser = OptionParser (option_class=eng_option, usage=usage)
49     parser.add_option("-N", "--nsamples", type="eng_float", default=250000,
50                       help="specify number of output samples to generate[=250000]")
51     parser.add_option("-g", "--tx-gain", type="eng_float", default=1.0,
52                       help="specify transmitter gain[=1]")
53     (options, args) = parser.parse_args ()
54
55     if len (args) != 1:
56         parser.print_help ()
57         sys.exit (1)
58
59     try:
60         my_graph(args[0], options.tx_gain, int(options.nsamples)).run()
61     except KeyboardInterrupt:
62         pass
63     
64
65 if __name__ == '__main__':
66     main ()