summaryrefslogtreecommitdiff
path: root/gr-radar/src/python/gen_fm_signal.py
blob: dc4844bba84585419240e44021593cb89368090b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#
# Copyright 2005 Free Software Foundation, Inc.
# 
# This file is part of GNU Radio
# 
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gru, blks, eng_notation
from gnuradio import audio
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import sys
import math


class my_graph(gr.flow_graph):
    def __init__(self, output_filename, tx_gain, nsamples):
        gr.flow_graph.__init__(self)
        
        audio_rate = 31250
        baseband_rate = 250e3

        src = gr.noise_source_f(gr.GR_GAUSSIAN, 1.0)
        #src = gr.noise_source_f(gr.GR_GAUSSIAN, 0.5)
        guts = blks.wfm_tx(self, audio_rate, baseband_rate)
        amp = gr.multiply_const_cc(tx_gain)
        head = gr.head(gr.sizeof_gr_complex, nsamples)
        sink = gr.file_sink(gr.sizeof_gr_complex, output_filename)
        self.connect(src, guts, amp, head, sink)

def main ():
    usage = "usage: %prog [options] output_filename"
    parser = OptionParser (option_class=eng_option, usage=usage)
    parser.add_option("-N", "--nsamples", type="eng_float", default=250000,
                      help="specify number of output samples to generate[=250000]")
    parser.add_option("-g", "--tx-gain", type="eng_float", default=1.0,
                      help="specify transmitter gain[=1]")
    (options, args) = parser.parse_args ()

    if len (args) != 1:
        parser.print_help ()
        sys.exit (1)

    try:
        my_graph(args[0], options.tx_gain, int(options.nsamples)).run()
    except KeyboardInterrupt:
        pass
    

if __name__ == '__main__':
    main ()