summaryrefslogtreecommitdiff
path: root/usrp2/host/apps/gen_sine.py
blob: 6a44dd110bf1c7aa566742a760a53aa9eae24ebb (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
#!/usr/bin/env python
#
# Copyright 2007 Free Software Foundation, Inc.
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#

from gnuradio import gr, eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import sys

master_clock = 100e6

class my_top_block(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-f", "--freq", type="eng_float", default=1e6,
                          help="set waveform frequency to FREQ [default=%default]")
        parser.add_option ("-a", "--amplitude", type="eng_float", default=16e3,
                           help="set waveform amplitude to AMPLITUDE [default=%default]", metavar="AMPL")

        parser.add_option("-i", "--interp", type="int", default=32,
                          help="assume fgpa interpolation rate is INTERP [default=%default]")

        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        
        src0 = gr.sig_source_c(master_clock/options.interp,
                               gr.GR_SIN_WAVE,
                               options.freq,
                               options.amplitude)

        
        c2s = gr.complex_to_interleaved_short()

        stdout_sink = gr.file_descriptor_sink(gr.sizeof_short, 1)

        self.connect(src0, c2s, stdout_sink)

        
if __name__ == '__main__':
    try:
        my_top_block().run()
    except KeyboardInterrupt:
        pass